Package org.codehaus.plexus.compiler

Examples of org.codehaus.plexus.compiler.CompilerException


            return messages;
        }
        catch ( IOException e )
        {
            throw new CompilerException( "Error while compiling.", e );
        }
        catch ( InterruptedException e )
        {
            throw new CompilerException( "Error while compiling.", e );
        }
    }
View Full Code Here


                fw.flush();
                tempFile.deleteOnExit();
            }
            catch ( IOException e )
            {
                throw new CompilerException( "Could not create temporary file " + tempFileName, e );
            }
            finally
            {
                IOUtil.close( fw );
            }
View Full Code Here

                cli.addArguments( new String[] { "-J-Xms" + config.getMeminitial() } );
            }
        }
        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( 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( "Failure executing javac,  but could not parse the error:" + EOL
View Full Code Here

            {
                cl.addURL( toolsJar.toURI().toURL() );
            }
            catch ( MalformedURLException e )
            {
                throw new CompilerException( "Could not convert the file reference to tools.jar to a URL, path to tools.jar: '" + toolsJar.getAbsolutePath() + "'." );
            }
        }

        Class c;

        try
        {
            c = cl.loadClass( "com.sun.tools.javac.Main" );
        }
        catch ( ClassNotFoundException e )
        {
            String message = "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.";
            return Collections.singletonList( new CompilerError( message, true ) );
        }

        StringWriter out = new StringWriter();

        Integer ok;

        List messages;

        try
        {
            Method compile = c.getMethod( "compile", new Class[] { String[].class, PrintWriter.class } );

            ok = (Integer) compile.invoke( null, new Object[] { args, new PrintWriter( out ) } );

            messages = parseModernStream( 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 );
        }

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

                cli.addArguments( new String[] { "-J-Xms" + config.getMeminitial() } );
            }
        }
        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( "Failure executing javac,  but could not parse the error:" + EOL
View Full Code Here

            {
                cl.addURL( toolsJar.toURI().toURL() );
            }
            catch ( MalformedURLException e )
            {
                throw new CompilerException( "Could not convert the file reference to tools.jar to a URL, path to tools.jar: '" + toolsJar.getAbsolutePath() + "'." );
            }
        }

        Class c;

        try
        {
            c = cl.loadClass( "com.sun.tools.javac.Main" );
        }
        catch ( ClassNotFoundException e )
        {
            String message = "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.";
            return Collections.singletonList( new CompilerError( message, true ) );
        }

        StringWriter out = new StringWriter();

        Integer ok;

        List messages;

        try
        {
            Method compile = c.getMethod( "compile", new Class[] { String[].class, PrintWriter.class } );

            ok = (Integer) compile.invoke( null, new Object[] { args, new PrintWriter( out ) } );

            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 );
        }

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

            outputDir.mkdirs();

            File outputFile = new File( outputDir, "compiled.class" );
            if ( !outputFile.exists() && !outputFile.createNewFile() )
            {
                throw new CompilerException( "could not create output file: " + outputFile.getAbsolutePath() );
            }
        }
        catch ( IOException e )
        {
            throw new CompilerException( "An exception occurred while creating output file", e );
        }

        return Collections.singletonList( new CompilerError( "message 1", shouldFail ) );
    }
View Full Code Here

            messages = compileOutOfProcess( config.getWorkingDirectory(), config.getBuildDirectory(),
                                            findExecutable( config ), args );
        }
        else
        {
            throw new CompilerException( "This compiler doesn't support in-process compilation." );
        }

        return messages;
    }
View Full Code Here

                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.createArgument().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

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.