Search in sources :

Example 1 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException in project st-js by st-js.

the class AbstractSTJSMojo method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    GenerationDirectory gendir = getGeneratedSourcesDirectory();
    long t1 = System.currentTimeMillis();
    getLog().info("Generating JavaScript files to " + gendir.getGeneratedSourcesAbsolutePath());
    ClassLoader builtProjectClassLoader = getBuiltProjectClassLoader();
    GeneratorConfigurationBuilder configBuilder = new GeneratorConfigurationBuilder();
    configBuilder.generateArrayHasOwnProperty(generateArrayHasOwnProperty);
    configBuilder.generateSourceMap(generateSourceMap);
    if (sourceEncoding != null) {
        configBuilder.sourceEncoding(sourceEncoding);
    }
    // configBuilder.allowedPackage("org.stjs.javascript");
    configBuilder.allowedPackage("org.junit");
    if (allowedPackages != null) {
        configBuilder.allowedPackages(allowedPackages);
    }
    if (annotations != null) {
        configBuilder.annotations(annotations);
    }
    // scan all the packages
    for (String sourceRoot : getCompileSourceRoots()) {
        File sourceDir = new File(sourceRoot);
        Collection<String> packages = accumulatePackages(sourceDir);
        configBuilder.allowedPackages(packages);
    }
    configBuilder.stjsClassLoader(builtProjectClassLoader);
    configBuilder.targetFolder(getBuildOutputDirectory());
    configBuilder.generationFolder(gendir);
    GeneratorConfiguration configuration = configBuilder.build();
    Generator generator = new Generator(configuration);
    int generatedFiles = 0;
    boolean hasFailures = false;
    // scan the modified sources
    for (String sourceRoot : getCompileSourceRoots()) {
        File sourceDir = new File(sourceRoot);
        SourceMapping mapping = new SuffixMapping(".java", ".js");
        SourceMapping stjsMapping = new SuffixMapping(".java", ".stjs");
        List<File> sources = accumulateSources(gendir, sourceDir, mapping, stjsMapping, staleMillis);
        for (File source : sources) {
            if (source.getName().equals(PACKAGE_INFO_JAVA)) {
                getLog().debug("Skipping " + source);
                continue;
            }
            File absoluteSource = new File(sourceDir, source.getPath());
            try {
                File absoluteTarget = (File) mapping.getTargetFiles(gendir.getGeneratedSourcesAbsolutePath(), source.getPath()).iterator().next();
                if (getLog().isDebugEnabled()) {
                    getLog().debug("Generating " + absoluteTarget);
                }
                buildContext.removeMessages(absoluteSource);
                if (!absoluteTarget.getParentFile().exists() && !absoluteTarget.getParentFile().mkdirs()) {
                    getLog().error("Cannot create output directory:" + absoluteTarget.getParentFile());
                    continue;
                }
                String className = getClassNameForSource(source.getPath());
                ClassWithJavascript stjsClass = generator.generateJavascript(className, sourceDir);
                if (!(stjsClass instanceof BridgeClass)) {
                    ++generatedFiles;
                }
            } catch (InclusionScanException e) {
                throw new MojoExecutionException("Cannot scan the source directory:" + e, e);
            } catch (MultipleFileGenerationException e) {
                for (JavascriptFileGenerationException jse : e.getExceptions()) {
                    buildContext.addMessage(jse.getSourcePosition().getFile(), jse.getSourcePosition().getLine(), jse.getSourcePosition().getColumn(), jse.getMessage(), BuildContext.SEVERITY_ERROR, null);
                }
                hasFailures = true;
            // continue with the next file
            } catch (JavascriptFileGenerationException e) {
                buildContext.addMessage(e.getSourcePosition().getFile(), e.getSourcePosition().getLine(), e.getSourcePosition().getColumn(), e.getMessage(), BuildContext.SEVERITY_ERROR, null);
                hasFailures = true;
            // continue with the next file
            } catch (Exception e) {
                // TODO - maybe should filter more here
                buildContext.addMessage(absoluteSource, 1, 1, e.toString(), BuildContext.SEVERITY_ERROR, e);
                hasFailures = true;
            // throw new MojoExecutionException("Error generating javascript:" + e, e);
            }
        }
    }
    generator.close();
    long t2 = System.currentTimeMillis();
    getLog().info("Generated " + generatedFiles + " JavaScript files in " + (t2 - t1) + " ms");
    if (generatedFiles > 0) {
        filesGenerated(generator, gendir);
    }
    if (hasFailures) {
        throw new MojoFailureException("Errors generating JavaScript");
    }
}
Also used : BridgeClass(org.stjs.generator.BridgeClass) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) GenerationDirectory(org.stjs.generator.GenerationDirectory) SuffixMapping(org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping) JavascriptFileGenerationException(org.stjs.generator.JavascriptFileGenerationException) MultipleFileGenerationException(org.stjs.generator.MultipleFileGenerationException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) JavascriptFileGenerationException(org.stjs.generator.JavascriptFileGenerationException) IOException(java.io.IOException) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) MultipleFileGenerationException(org.stjs.generator.MultipleFileGenerationException) URLClassLoader(java.net.URLClassLoader) ClassWithJavascript(org.stjs.generator.ClassWithJavascript) GeneratorConfiguration(org.stjs.generator.GeneratorConfiguration) GeneratorConfigurationBuilder(org.stjs.generator.GeneratorConfigurationBuilder) File(java.io.File) SourceMapping(org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping) Generator(org.stjs.generator.Generator)

Example 2 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException 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 3 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException 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 4 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException in project jangaroo-tools by CoreMedia.

the class MavenPluginHelper method computeStaleSources.

public List<File> computeStaleSources(List<File> compileSourceRoots, Set<String> includes, Set<String> excludes, File outputDirectory, String inputFileSuffix, String outputFileSuffix, int staleMillis) throws MojoExecutionException {
    SourceInclusionScanner scanner = createSourceInclusionScanner(includes, excludes, inputFileSuffix, staleMillis);
    scanner.addSourceMapping(new SuffixMapping(inputFileSuffix, outputFileSuffix));
    log.debug("Searching for");
    Set<File> staleSources = new LinkedHashSet<File>();
    for (File rootFile : compileSourceRoots) {
        if (!rootFile.isDirectory()) {
            continue;
        }
        try {
            log.debug("scanner.getIncludedSources(" + rootFile + ", " + outputDirectory + ")");
            // noinspection unchecked
            staleSources.addAll(scanner.getIncludedSources(rootFile, outputDirectory));
        } catch (InclusionScanException e) {
            throw new MojoExecutionException("Error scanning source root: \'" + rootFile.getAbsolutePath() + "\' " + "for stale files to recompile.", e);
        }
    }
    return Collections.unmodifiableList(new ArrayList<File>(staleSources));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SimpleSourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SimpleSourceInclusionScanner) SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) SuffixMapping(org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping) File(java.io.File)

Example 5 with InclusionScanException

use of org.codehaus.plexus.compiler.util.scan.InclusionScanException in project st-js by st-js.

the class AbstractSTJSMojo method accumulateSources.

/**
 * @return the list of Java source files to processed (those which are older than the corresponding Javascript
 *         file). The returned files are relative to the given source directory.
 */
@SuppressWarnings("unchecked")
private List<File> accumulateSources(GenerationDirectory gendir, File sourceDir, SourceMapping jsMapping, SourceMapping stjsMapping, int stale) throws MojoExecutionException {
    final List<File> result = new ArrayList<File>();
    if (sourceDir == null || !sourceDir.exists()) {
        return result;
    }
    SourceInclusionScanner jsScanner = getSourceInclusionScanner(stale);
    jsScanner.addSourceMapping(jsMapping);
    SourceInclusionScanner stjsScanner = getSourceInclusionScanner(stale);
    stjsScanner.addSourceMapping(stjsMapping);
    final Set<File> staleFiles = new LinkedHashSet<File>();
    for (File f : sourceDir.listFiles()) {
        if (!f.isDirectory()) {
            continue;
        }
        try {
            staleFiles.addAll(jsScanner.getIncludedSources(f.getParentFile(), gendir.getGeneratedSourcesAbsolutePath()));
            staleFiles.addAll(stjsScanner.getIncludedSources(f.getParentFile(), getBuildOutputDirectory()));
        } catch (InclusionScanException e) {
            throw new MojoExecutionException("Error scanning source root: \'" + sourceDir.getPath() + "\' " + "for stale files to recompile.", e);
        }
    }
    // Trim root path from file paths
    for (File file : staleFiles) {
        String filePath = file.getPath();
        String basePath = sourceDir.getAbsoluteFile().toString();
        result.add(new File(filePath.substring(basePath.length() + 1)));
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SourceInclusionScanner(org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner) ArrayList(java.util.ArrayList) File(java.io.File)

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