Search in sources :

Example 1 with SourceMapping

use of org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping 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)

Example 2 with SourceMapping

use of org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping 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 SourceMapping

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

the class AbstractCompilerMojo method computeStaleSources.

private Set<File> computeStaleSources(CompilerConfiguration compilerConfiguration, Compiler compiler, SourceInclusionScanner scanner) throws MojoExecutionException, CompilerException {
    SourceMapping mapping = getSourceMapping(compilerConfiguration, compiler);
    File outputDirectory;
    CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle();
    if (outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES) {
        outputDirectory = buildDirectory;
    } else {
        outputDirectory = getOutputDirectory();
    }
    scanner.addSourceMapping(mapping);
    Set<File> staleSources = new HashSet<File>();
    for (String sourceRoot : getCompileSourceRoots()) {
        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) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CompilerOutputStyle(org.codehaus.plexus.compiler.CompilerOutputStyle) 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 4 with SourceMapping

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

the class AbstractCompilerMojo method getSourceMapping.

private SourceMapping getSourceMapping(CompilerConfiguration compilerConfiguration, Compiler compiler) throws CompilerException, MojoExecutionException {
    CompilerOutputStyle outputStyle = compiler.getCompilerOutputStyle();
    SourceMapping mapping;
    if (outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE) {
        mapping = new SuffixMapping(compiler.getInputFileEnding(compilerConfiguration), compiler.getOutputFileEnding(compilerConfiguration));
    } else if (outputStyle == CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES) {
        mapping = new SingleTargetSourceMapping(compiler.getInputFileEnding(compilerConfiguration), compiler.getOutputFile(compilerConfiguration));
    } else {
        throw new MojoExecutionException("Unknown compiler output style: '" + outputStyle + "'.");
    }
    return mapping;
}
Also used : SingleTargetSourceMapping(org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CompilerOutputStyle(org.codehaus.plexus.compiler.CompilerOutputStyle) 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)

Aggregations

SourceMapping (org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 SingleTargetSourceMapping (org.codehaus.plexus.compiler.util.scan.mapping.SingleTargetSourceMapping)3 File (java.io.File)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 CompilerOutputStyle (org.codehaus.plexus.compiler.CompilerOutputStyle)2 InclusionScanException (org.codehaus.plexus.compiler.util.scan.InclusionScanException)2 SourceInclusionScanner (org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner)2 SuffixMapping (org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping)2 SimpleSourceInclusionScanner (org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner)1