Package org.codehaus.plexus.compiler

Examples of org.codehaus.plexus.compiler.CompilerException


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

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


                urls[ i++ ] = new File( (String) it.next() ).toURL();
            }
        }
        catch ( MalformedURLException e )
        {
            throw new CompilerException( "Error while converting the classpath entries to URLs.", e );
        }

        ClassLoader classLoader = new URLClassLoader( urls );

        SourceCodeLocator sourceCodeLocator = new SourceCodeLocator( config.getSourceLocations() );
View Full Code Here

            return new CompilerResult( result, compilerMsgs );
        }
        catch ( Exception e )
        {
            throw new CompilerException( e.getMessage(), e );
        }
        finally
        {
            releaseJavaCompiler( compiler, config );
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
        {
            // Combined classloader with no parent/child relationship, so classes in our classloader
            // can reference classes in tools.jar
            URL[] originalUrls = ((URLClassLoader) JavacCompiler.class.getClassLoader()).getURLs();
            URL[] urls = new URL[originalUrls.length + 1];
            urls[0] = toolsJar.toURI().toURL();
            System.arraycopy(originalUrls, 0, urls, 1, originalUrls.length);
            ClassLoader javacClassLoader = new URLClassLoader(urls);

            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

            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

            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 new CompilerResult( !shouldFail,
            Collections.singletonList( new CompilerMessage( "message 1", CompilerMessage.Kind.OTHER ) ) );
    }
View Full Code Here

            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

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.