Search in sources :

Example 6 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException in project tycho by eclipse.

the class AbstractCompilerMojo method computeStaleSources.

private Set<File> computeStaleSources(CompilerConfiguration compilerConfiguration, Compiler compiler, SourceInclusionScanner scanner) throws MojoExecutionException, CompilerException {
    CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle();
    SourceMapping mapping;
    File outputDirectory;
    if (outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE) {
        mapping = new SuffixMapping(compiler.getInputFileEnding(compilerConfiguration), compiler.getOutputFileEnding(compilerConfiguration));
        outputDirectory = getOutputDirectory();
    } else if (outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES) {
        mapping = new SingleTargetSourceMapping(compiler.getInputFileEnding(compilerConfiguration), compiler.getOutputFile(compilerConfiguration));
        outputDirectory = buildDirectory;
    } else {
        throw new MojoExecutionException("Unknown compiler output style: '" + outputStyle + "'.");
    }
    scanner.addSourceMapping(mapping);
    Set<File> staleSources = new HashSet<>();
    for (Iterator it = getCompileSourceRoots().iterator(); it.hasNext(); ) {
        String sourceRoot = (String) it.next();
        File rootFile = new File(sourceRoot);
        if (!rootFile.isDirectory()) {
            continue;
        }
        try {
            staleSources.addAll(scanner.getIncludedSources(rootFile, outputDirectory));
        } catch (InclusionScanException e) {
            throw new MojoExecutionException("Error scanning source root: \'" + sourceRoot + "\' " + "for stale files to recompile.", e);
        }
    }
    return staleSources;
}
Also used : InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) SingleTargetSourceMapping(org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CompilerOutputStyle(org.codehaus.plexus.compiler.CompilerOutputStyle) Iterator(java.util.Iterator) SuffixMapping(org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping) SingleTargetSourceMapping(org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping) SourceMapping(org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping) File(java.io.File) HashSet(java.util.HashSet)

Example 7 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException in project tycho by eclipse.

the class AbstractOsgiCompilerMojo method doCopyResources.

/*
     * mimics the behavior of the PDE incremental builder which by default copies all (non-java)
     * resource files in source directories into the target folder
     */
private void doCopyResources() throws MojoExecutionException {
    if (!copyResources) {
        return;
    }
    for (String sourceRoot : getCompileSourceRoots()) {
        // StaleSourceScanner.getIncludedSources throws IllegalStateException
        // if directory doesnt't exist
        File sourceRootFile = new File(sourceRoot);
        if (!sourceRootFile.isDirectory()) {
            getLog().warn("Source directory " + sourceRoot + " does not exist");
            continue;
        }
        Set<String> excludes = new HashSet<>();
        excludes.addAll(excludeResources);
        excludes.addAll(getEclipsePluginProject().getBuildProperties().getBinExcludes());
        excludes.add("**/*.java");
        StaleSourceScanner scanner = new StaleSourceScanner(0L, MATCH_ALL, excludes);
        CopyMapping copyMapping = new CopyMapping();
        scanner.addSourceMapping(copyMapping);
        try {
            scanner.getIncludedSources(sourceRootFile, this.outputJar.getOutputDirectory());
            for (CopyMapping.SourceTargetPair sourceTargetPair : copyMapping.getSourceTargetPairs()) {
                FileUtils.copyFile(new File(sourceRoot, sourceTargetPair.source), sourceTargetPair.target);
            }
        } catch (InclusionScanException e) {
            throw new MojoExecutionException("Exception while scanning for resource files in " + sourceRoot, e);
        } catch (IOException e) {
            throw new MojoExecutionException("Exception copying resource files from " + sourceRoot + " to " + this.outputJar.getOutputDirectory(), e);
        }
    }
}
Also used : InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) StaleSourceScanner(org.codehaus.plexus.compiler.util.scan.StaleSourceScanner) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 InclusionScanException (org.codehaus.plexus.compiler.util.scan.InclusionScanException)7 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 SourceMapping (org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping)4 SourceInclusionScanner (org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner)3 SingleTargetSourceMapping (org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping)3 SuffixMapping (org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping)3 IOException (java.io.IOException)2 CompilerOutputStyle (org.codehaus.plexus.compiler.CompilerOutputStyle)2 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 SimpleSourceInclusionScanner (org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner)1 StaleSourceScanner (org.codehaus.plexus.compiler.util.scan.StaleSourceScanner)1 BridgeClass (org.stjs.generator.BridgeClass)1 ClassWithJavascript (org.stjs.generator.ClassWithJavascript)1