Search in sources :

Example 1 with SourceInclusionScanner

use of org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner in project antlr4 by tunnelvisionlabs.

the class Antlr4Mojo method getImportFiles.

private Set<File> getImportFiles(File sourceDirectory) throws InclusionScanException {
    if (!libDirectory.exists())
        return Collections.emptySet();
    Set<String> includes = new HashSet<String>();
    includes.add("*.g4");
    includes.add("*.tokens");
    SourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, Collections.<String>emptySet());
    scan.addSourceMapping(new SuffixMapping("G4", "g4"));
    return scan.getIncludedSources(libDirectory, null);
}
Also used : SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner) SuffixMapping(org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner) HashSet(java.util.HashSet)

Example 2 with SourceInclusionScanner

use of org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner in project maven-plugins by apache.

the class AbstractCompilerMojo method getCompileSources.

/**
 * @return all source files for the compiler
 */
private Set<File> getCompileSources(Compiler compiler, CompilerConfiguration compilerConfiguration) throws MojoExecutionException, CompilerException {
    String inputFileEnding = compiler.getInputFileEnding(compilerConfiguration);
    if (StringUtils.isEmpty(inputFileEnding)) {
        // see MCOMPILER-199 GroovyEclipseCompiler doesn't set inputFileEnding
        // so we can presume it's all files from the source directory
        inputFileEnding = ".*";
    }
    SourceInclusionScanner scanner = getSourceInclusionScanner(inputFileEnding);
    SourceMapping mapping = getSourceMapping(compilerConfiguration, compiler);
    scanner.addSourceMapping(mapping);
    Set<File> compileSources = new HashSet<File>();
    for (String sourceRoot : getCompileSourceRoots()) {
        File rootFile = new File(sourceRoot);
        if (!rootFile.isDirectory() || rootFile.getAbsoluteFile().equals(compilerConfiguration.getGeneratedSourcesDirectory())) {
            continue;
        }
        try {
            compileSources.addAll(scanner.getIncludedSources(rootFile, null));
        } catch (InclusionScanException e) {
            throw new MojoExecutionException("Error scanning source root: \'" + sourceRoot + "\' for stale files to recompile.", e);
        }
    }
    return compileSources;
}
Also used : InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) 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) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with SourceInclusionScanner

use of org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner in project maven-plugins by apache.

the class CompilerMojo method getSourceInclusionScanner.

protected SourceInclusionScanner getSourceInclusionScanner(String inputFileEnding) {
    SourceInclusionScanner scanner;
    // it's not defined if we get the ending with or without the dot '.'
    String defaultIncludePattern = "**/*" + (inputFileEnding.startsWith(".") ? "" : ".") + inputFileEnding;
    if (includes.isEmpty() && excludes.isEmpty()) {
        includes = Collections.singleton(defaultIncludePattern);
        scanner = new SimpleSourceInclusionScanner(includes, Collections.<String>emptySet());
    } else {
        if (includes.isEmpty()) {
            includes.add(defaultIncludePattern);
        }
        scanner = new SimpleSourceInclusionScanner(includes, excludes);
    }
    return scanner;
}
Also used : SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner)

Example 4 with SourceInclusionScanner

use of org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner in project maven-plugins by apache.

the class TestCompilerMojo method getSourceInclusionScanner.

protected SourceInclusionScanner getSourceInclusionScanner(String inputFileEnding) {
    SourceInclusionScanner scanner;
    // it's not defined if we get the ending with or without the dot '.'
    String defaultIncludePattern = "**/*" + (inputFileEnding.startsWith(".") ? "" : ".") + inputFileEnding;
    if (testIncludes.isEmpty() && testExcludes.isEmpty()) {
        testIncludes = Collections.singleton(defaultIncludePattern);
        scanner = new SimpleSourceInclusionScanner(testIncludes, Collections.<String>emptySet());
    } else {
        if (testIncludes.isEmpty()) {
            testIncludes.add(defaultIncludePattern);
        }
        scanner = new SimpleSourceInclusionScanner(testIncludes, testExcludes);
    }
    return scanner;
}
Also used : SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner) SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner)

Example 5 with SourceInclusionScanner

use of org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner in project antlr4 by antlr.

the class Antlr4Mojo method getGrammarFiles.

private Set<File> getGrammarFiles(File sourceDirectory) throws InclusionScanException {
    // Which files under the source set should we be looking for as grammar files
    SourceMapping mapping = new SuffixMapping("g4", Collections.<String>emptySet());
    // What are the sets of includes (defaulted or otherwise).
    Set<String> includes = getIncludesPatterns();
    // Now, to the excludes, we need to add the imports directory
    // as this is autoscanned for imported grammars and so is auto-excluded from the
    // set of grammar fields we should be analyzing.
    excludes.add("imports/**");
    SourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, excludes);
    scan.addSourceMapping(mapping);
    return scan.getIncludedSources(sourceDirectory, null);
}
Also used : SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner) SuffixMapping(org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping) SourceMapping(org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner)

Aggregations

SourceInclusionScanner (org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner)11 SimpleSourceInclusionScanner (org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner)9 SuffixMapping (org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping)5 File (java.io.File)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 InclusionScanException (org.codehaus.plexus.compiler.util.scan.InclusionScanException)3 SourceMapping (org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping)3 ArrayList (java.util.ArrayList)1 StaleSourceScanner (org.codehaus.plexus.compiler.util.scan.StaleSourceScanner)1 SingleTargetSourceMapping (org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping)1