Search in sources :

Example 1 with Scanner

use of org.codehaus.plexus.util.Scanner in project frontend-maven-plugin by eirslett.

the class MojoUtils method shouldExecute.

static boolean shouldExecute(BuildContext buildContext, List<File> triggerfiles, File srcdir) {
    // If there is no buildContext, or this is not an incremental build, always execute.
    if (buildContext == null || !buildContext.isIncremental()) {
        return true;
    }
    if (triggerfiles != null) {
        for (File triggerfile : triggerfiles) {
            if (buildContext.hasDelta(triggerfile)) {
                return true;
            }
        }
    }
    if (srcdir == null) {
        return true;
    }
    // Check for changes in the srcdir
    Scanner scanner = buildContext.newScanner(srcdir);
    scanner.scan();
    String[] includedFiles = scanner.getIncludedFiles();
    return (includedFiles != null && includedFiles.length > 0);
}
Also used : Scanner(org.codehaus.plexus.util.Scanner) File(java.io.File)

Example 2 with Scanner

use of org.codehaus.plexus.util.Scanner in project querydsl by querydsl.

the class CompileMojo method getJavaFiles.

private Set<File> getJavaFiles(File directory) {
    String[] filters = ALL_JAVA_FILES_FILTER;
    Set<File> files = new HashSet<File>();
    // support for incremental build in m2e context
    Scanner scanner = buildContext.newScanner(directory);
    scanner.setIncludes(filters);
    scanner.scan();
    String[] includedFiles = scanner.getIncludedFiles();
    if (includedFiles != null) {
        for (String includedFile : includedFiles) {
            files.add(new File(scanner.getBasedir(), includedFile));
        }
    }
    return files;
}
Also used : Scanner(org.codehaus.plexus.util.Scanner) File(java.io.File)

Example 3 with Scanner

use of org.codehaus.plexus.util.Scanner in project gora by apache.

the class AbstractGoraMojo method compile.

protected void compile() throws IOException {
    File sourceDirectory = getSourcesDirectory();
    File outputDirectory = getOutputDirectory();
    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();
    }
    Scanner fileScanner = context.newScanner(sourceDirectory, true);
    fileScanner.setIncludes(includes);
    fileScanner.setExcludes(excludes);
    fileScanner.scan();
    File basedir = fileScanner.getBasedir();
    List<File> changedFiles = new ArrayList<File>();
    for (String fileName : fileScanner.getIncludedFiles()) {
        File file = new File(basedir, fileName);
        changedFiles.add(file);
        context.removeMessages(file);
    }
    if (!changedFiles.isEmpty()) {
        try {
            File[] schemaFile = changedFiles.toArray(new File[changedFiles.size()]);
            GoraCompiler.compileSchema(schemaFile, outputDirectory);
        } catch (SchemaParseException e) {
            if (e.getCause() != null && e.getCause() instanceof JsonParseException) {
                attachErrorMessage((JsonParseException) e.getCause());
            } else {
                throw e;
            }
        }
    }
    context.refresh(outputDirectory);
}
Also used : Scanner(org.codehaus.plexus.util.Scanner) SchemaParseException(org.apache.avro.SchemaParseException) ArrayList(java.util.ArrayList) JsonParseException(org.codehaus.jackson.JsonParseException) File(java.io.File)

Example 4 with Scanner

use of org.codehaus.plexus.util.Scanner in project sling by apache.

the class ValidateMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping validation.");
        return;
    }
    long start = System.currentTimeMillis();
    if (!sourceDirectory.isAbsolute()) {
        sourceDirectory = new File(project.getBasedir(), sourceDirectory.getPath());
    }
    if (!sourceDirectory.exists()) {
        getLog().info("Source directory does not exist, skipping.");
        return;
    }
    if (!sourceDirectory.isDirectory()) {
        throw new MojoExecutionException(String.format("Configured sourceDirectory={%s} is not a directory.", sourceDirectory.getAbsolutePath()));
    }
    if (!buildContext.hasDelta(sourceDirectory)) {
        getLog().info("No files found to validate, skipping.");
        return;
    }
    // don't fail execution in Eclipse as it generates an error marker in the POM file, which is not desired
    boolean mayFailExecution = !buildContext.getClass().getName().startsWith("org.eclipse.m2e");
    sourceDirectoryLength = sourceDirectory.getAbsolutePath().length();
    processedIncludes = processIncludes();
    processedExcludes = processExcludes();
    try {
        SightlyCompiler compiler = new SightlyCompiler();
        Scanner scanner = buildContext.newScanner(sourceDirectory);
        scanner.setExcludes(new String[] { processedExcludes });
        scanner.setIncludes(new String[] { processedIncludes });
        scanner.scan();
        String[] includedFiles = scanner.getIncludedFiles();
        processedFiles = new ArrayList<>(includedFiles.length);
        for (String includedFile : includedFiles) {
            processedFiles.add(new File(sourceDirectory, includedFile));
        }
        Map<File, CompilationResult> compilationResults = new HashMap<>();
        for (File script : processedFiles) {
            compilationResults.put(script, compiler.compile(getCompilationUnit(script)));
        }
        for (Map.Entry<File, CompilationResult> entry : compilationResults.entrySet()) {
            File script = entry.getKey();
            CompilationResult result = entry.getValue();
            buildContext.removeMessages(script);
            if (result.getWarnings().size() > 0) {
                for (CompilerMessage message : result.getWarnings()) {
                    buildContext.addMessage(script, message.getLine(), message.getColumn(), message.getMessage(), BuildContext.SEVERITY_WARNING, null);
                }
                hasWarnings = true;
            }
            if (result.getErrors().size() > 0) {
                for (CompilerMessage message : result.getErrors()) {
                    String messageString = message.getMessage().replaceAll(System.lineSeparator(), "");
                    buildContext.addMessage(script, message.getLine(), message.getColumn(), messageString, BuildContext.SEVERITY_ERROR, null);
                }
                hasErrors = true;
            }
        }
        getLog().info("Processed " + processedFiles.size() + " files in " + (System.currentTimeMillis() - start) + " milliseconds");
        if (mayFailExecution && hasWarnings && failOnWarnings) {
            throw new MojoFailureException("Compilation warnings were configured to fail the build.");
        }
        if (mayFailExecution && hasErrors) {
            throw new MojoFailureException("Please check the reported syntax errors.");
        }
    } catch (IOException e) {
        throw new MojoExecutionException(String.format("Cannot filter files from {%s} with includes {%s} and excludes {%s}.", sourceDirectory.getAbsolutePath(), processedIncludes, processedExcludes), e);
    }
}
Also used : Scanner(org.codehaus.plexus.util.Scanner) CompilerMessage(org.apache.sling.scripting.sightly.compiler.CompilerMessage) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) SightlyCompiler(org.apache.sling.scripting.sightly.compiler.SightlyCompiler) CompilationResult(org.apache.sling.scripting.sightly.compiler.CompilationResult) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

File (java.io.File)4 Scanner (org.codehaus.plexus.util.Scanner)4 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SchemaParseException (org.apache.avro.SchemaParseException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 CompilationResult (org.apache.sling.scripting.sightly.compiler.CompilationResult)1 CompilerMessage (org.apache.sling.scripting.sightly.compiler.CompilerMessage)1 SightlyCompiler (org.apache.sling.scripting.sightly.compiler.SightlyCompiler)1 JsonParseException (org.codehaus.jackson.JsonParseException)1