Package org.codehaus.plexus.compiler.javac

Examples of org.codehaus.plexus.compiler.javac.JavacCompiler


        for ( int i = 0; i < getClasspath().size(); i++ )
        {
            classPathElements.add( getClasspath().get( i ).getAbsolutePath() );
        }

        org.codehaus.plexus.compiler.Compiler compiler = new JavacCompiler();

        CompilerConfiguration configuration = new CompilerConfiguration();
        configuration.setClasspathEntries( classPathElements );
        configuration.setSourceLocations(
            Arrays.asList( getTestPath( "src/test/verifiers/" + getName() ), generatedSources.getAbsolutePath() ) );
        configuration.setOutputLocation( getOutputClasses().getAbsolutePath() );// destinationDirectory.getAbsolutePath() );
        configuration.setDebug( true );
        configuration.setSourceVersion( "1.5" );
        configuration.setTargetVersion( "1.5" );

        List<CompilerMessage> messages = compiler.performCompile( configuration ).getCompilerMessages();

        int error = 0;

        for ( CompilerMessage message : messages )
        {
View Full Code Here


        Validate.notNullAndNoNullValues(scopes, "Cannot compile sources, there were no scopes defined");
        Validate.notNull(inputDirectory, "Directory with sources to be compiled must not be null");
        Validate.notNull(outputDirectory, "Target directory for compiled sources must not be null");

        JavacCompiler compiler = new JavacCompiler();
        CompilerConfiguration configuration = getCompilerConfiguration();

        if (log.isLoggable(Level.FINE)) {
            log.log(Level.FINE, "Compiling sources from {0} directory into {1}",
                new Object[] { inputDirectory, outputDirectory });
        }

        // in order to compile sources, we need to resolve dependencies first
        // so we have a classpath available
        new AddScopedDependenciesTask(ScopeType.values()).execute(session);
        final MavenResolutionStrategy scopeStrategy = new AcceptScopesStrategy(scopes);
        final Collection<MavenResolvedArtifact> artifactResults = session.resolveDependencies(scopeStrategy);

        for (MavenResolvedArtifact artifact : artifactResults) {
            String classpathEntry = artifact.asFile().getAbsolutePath();
            configuration.addClasspathEntry(classpathEntry);
            if (log.isLoggable(Level.FINER)) {
                log.log(Level.FINER, "Adding {0} to compilation classpath", classpathEntry);
            }
        }

        configuration.addSourceLocation(inputDirectory.getPath());
        configuration.setOutputLocation(outputDirectory.getPath());
        try {
            CompilerResult result = compiler.performCompile(configuration);
            if (!result.isSuccess()) {
                // try to fork compilation process if it wasn't set to fork already
                if (!configuration.isFork()) {
                    log.log(Level.WARNING,
                        "MavenImporter was not able to identify javac compiler, probably JAVA_HOME points to JRE instead of JDK. MavenImporter will try to fork and use javac from $PATH");
                    configuration.setFork(true);
                    CompilerResult result2 = compiler.performCompile(configuration);
                    if (!result2.isSuccess()) {
                        log.log(Level.WARNING,
                            "Unable to compile project with neither forked nor embedded compiler. Returning original exception message");
                        // throw original exception
                        throw constructCompilationException(result, inputDirectory);
View Full Code Here

        config.setSourceVersion(source);
        config.setTargetVersion(target);
        config.setClasspathEntries(Arrays.asList(projectClasspath));

        try {
            JavacCompiler javac = new JavacCompiler();
            getLog().debug("Compiling event interface using: " + Arrays.toString(javac.createCommandLine(config)));
            List<CompilerError> messages = javac.compile(config);
            checkForCompilerErrors(messages, classToCompile);
        } catch (CompilerException e) {
            throw new MojoExecutionException("Cannot compile event interface: " + classToCompile, e);
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.compiler.javac.JavacCompiler

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.