Package org.codehaus.plexus.compiler

Examples of org.codehaus.plexus.compiler.CompilerException


        try {
            for (String entry : (List<String>)configuration.getClasspathEntries()) {
                urls.add(new File(entry).toURI().toURL());
            }
        } catch (MalformedURLException e) {
            throw new CompilerException(e.getMessage(), e);
        }

        ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));

        // Determine compiler configuration
View Full Code Here


    if (config.isFork()) {
      return compileOutOfProcess(config.getWorkingDirectory(), config
          .getBuildDirectory(), findExecutable(config), args);
    } else {
      throw new CompilerException(
          "This compiler doesn't support in-process compilation.");
    }
  }
View Full Code Here

        System.out.println("arg: " + arg);
        output.println(arg);
      }
    } catch (IOException e) {
      throw new CompilerException("Error writing arguments file.", e);
    } finally {
      IOUtil.close(output);
    }

    // ----------------------------------------------------------------------
    // Execute!
    // ----------------------------------------------------------------------

    Commandline cli = new Commandline();

    cli.setWorkingDirectory(workingDirectory.getAbsolutePath());

    cli.setExecutable(executable);

    cli.createArg().setValue("@" + file.getAbsolutePath());

    Writer stringWriter = new StringWriter();

    StreamConsumer out = new WriterStreamConsumer(stringWriter);

    StreamConsumer err = new WriterStreamConsumer(stringWriter);

    int returnCode;

    List messages;

    try {
      returnCode = CommandLineUtils.executeCommandLine(cli, out, err);

      messages = parseCompilerOutput(new BufferedReader(new StringReader(
          stringWriter.toString())));
    } catch (CommandLineException e) {
      throw new CompilerException(
          "Error while executing the external compiler.", e);
    } catch (IOException e) {
      throw new CompilerException(
          "Error while executing the external compiler.", e);
    }

    if (returnCode != 0 && messages.isEmpty()) {
      // TODO: exception?
View Full Code Here

    if (type.equals("library") || type.equals("module")) {
      return "dll";
    }

    throw new CompilerException("Unrecognized type '" + type + "'.");
  }
View Full Code Here

                        new MetainfServiceGenerator(),
                        new AnnotationProcessorFactoryImpl(),
                        loadAdditionalAnnotationProcessors()
                    ), new PrintWriter(System.out,true),args);
                if(r!=0)
                    throw new CompilerException("APT failed: "+r);

                // TODO: should I try to parse the output?
                return Collections.emptyList();
            }
        });
View Full Code Here

                    metadataSource, new ScopeArtifactFilter("runtime"));
            for( Artifact a : (Set<Artifact>)result.getArtifacts()) {
                classpaths.add(a.getFile().toURL());
            }
        } catch (AbstractArtifactResolutionException e) {
            throw new CompilerException("Failed to resolve annotation processors",e);
        } catch (MalformedURLException e) {
            throw new CompilerException("Failed to resolve annotation processors",e);
        }

        // load them into the classloader
        ClassLoader cl = new URLClassLoader(classpaths.toArray(new URL[classpaths.size()]),getClass().getClassLoader());
View Full Code Here

                }
            }
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error creating file with javac arguments", e );
        }

        CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();

        int returnCode;

        List<CompilerMessage> messages;

        if ( ( getLogger() != null ) && getLogger().isDebugEnabled() )
        {
            File commandLineFile =
                new File( config.getOutputLocation(), "javac." + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? "bat" : "sh" ) );
            try
            {
                FileUtils.fileWrite( commandLineFile.getAbsolutePath(), cli.toString().replaceAll( "'", "" ) );

                if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
                {
                    Runtime.getRuntime().exec( new String[]{ "chmod", "a+x", commandLineFile.getAbsolutePath() } );
                }
            }
            catch ( IOException e )
            {
                if ( ( getLogger() != null ) && getLogger().isWarnEnabled() )
                {
                    getLogger().warn( "Unable to write '" + commandLineFile.getName() + "' debug script file", e );
                }
            }
        }

        try
        {
            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );

            messages = parseModernStream( returnCode, new BufferedReader( new StringReader( err.getOutput() ) ) );
        }
        catch ( CommandLineException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }

        boolean success = returnCode == 0;
        return new CompilerResult( success, messages );
    }
View Full Code Here

            messages = parseModernStream( ok.intValue(), new BufferedReader( new StringReader( out.toString() ) ) );
        }
        catch ( NoSuchMethodException e )
        {
            throw new CompilerException( "Error while executing the compiler.", e );
        }
        catch ( IllegalAccessException e )
        {
            throw new CompilerException( "Error while executing the compiler.", e );
        }
        catch ( InvocationTargetException e )
        {
            throw new CompilerException( "Error while executing the compiler.", e );
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error while executing the compiler.", e );
        }

        boolean success = ok.intValue() == 0;
        return new CompilerResult( success, messages );
    }
View Full Code Here

        }

        final File toolsJar = new File( System.getProperty( "java.home" ), "../lib/tools.jar" );
        if ( !toolsJar.exists() )
        {
            throw new CompilerException( "tools.jar not found: " + toolsJar );
        }

        try
        {
            final ClassLoader javacClassLoader =
                new URLClassLoader( new URL[]{ toolsJar.toURI().toURL() }, JavacCompiler.class.getClassLoader() );

            final Thread thread = Thread.currentThread();
            final ClassLoader contextClassLoader = thread.getContextClassLoader();
            thread.setContextClassLoader( javacClassLoader );
            try
            {
                //return Class.forName( JavacCompiler.JAVAC_CLASSNAME, true, javacClassLoader );
                return javacClassLoader.loadClass( JavacCompiler.JAVAC_CLASSNAME );
            }
            finally
            {
                thread.setContextClassLoader( contextClassLoader );
            }
        }
        catch ( MalformedURLException ex )
        {
            throw new CompilerException(
                "Could not convert the file reference to tools.jar to a URL, path to tools.jar: '"
                    + toolsJar.getAbsolutePath() + "'.", ex );
        }
        catch ( ClassNotFoundException ex )
        {
            throw new CompilerException( "Unable to locate the Javac Compiler in:" + EOL + "  " + toolsJar + EOL
                                             + "Please ensure you are using JDK 1.4 or above and" + EOL
                                             + "not a JRE (the com.sun.tools.javac.Main class is required)." + EOL
                                             + "In most cases you can change the location of your Java" + EOL
                                             + "installation by setting the JAVA_HOME environment variable.", ex );
        }
View Full Code Here

                }
            }
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error creating file with javac arguments", e );
        }

        CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();

        int returnCode;

        List messages;

        if ( ( getLogger() != null ) && getLogger().isDebugEnabled() )
        {
            File commandLineFile =
                new File( config.getOutputLocation(), "javac." + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? "bat" : "sh" ) );
            try
            {
                FileUtils.fileWrite( commandLineFile.getAbsolutePath(), cli.toString().replaceAll( "'", "" ) );

                if ( !Os.isFamily( Os.FAMILY_WINDOWS ) )
                {
                    Runtime.getRuntime().exec( new String[]{ "chmod", "a+x", commandLineFile.getAbsolutePath() } );
                }
            }
            catch ( IOException e )
            {
                if ( ( getLogger() != null ) && getLogger().isWarnEnabled() )
                {
                    getLogger().warn( "Unable to write '" + commandLineFile.getName() + "' debug script file", e );
                }
            }
        }

        try
        {
            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );

            messages = parseModernStream( returnCode, new BufferedReader( new StringReader( err.getOutput() ) ) );
        }
        catch ( CommandLineException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error while executing the external compiler.", e );
        }

        if ( ( returnCode != 0 ) && messages.isEmpty() )
        {
            if ( err.getOutput().length() == 0 )
            {
                throw new CompilerException(
                    "Unknown error trying to execute the external compiler: " + EOL + cli.toString() );
            }
            else
            {
                messages.add( new CompilerError(
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.compiler.CompilerException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.