public void execute() throws MojoExecutionException, MojoFailureException { SourceInclusionScanner scanner = includeStale ? new StaleSourceScanner(1024, Collections.singleton("**/*." + extension), Collections.<String>emptySet()) : new SimpleSourceInclusionScanner(Collections.singleton("**/*." + extension), Collections.<String>emptySet()); scanner.addSourceMapping(new SuffixMapping("." + extension, "." + extension)); MustacheFactory mustacheFactory = new DefaultMustacheFactory(); try { Set<File> files = scanner.getIncludedSources(sourceDirectory, outputDirectory); for (File file : files) { try { mustacheFactory.compile(new FileReader(file), file.getAbsolutePath()); } catch (MustacheException e) { throw new MojoFailureException(e.getMessage(), e); } } } catch (InclusionScanException | FileNotFoundException e) { throw new MojoExecutionException(e.getMessage()); } } }
public void testShouldNotReturnClassFileWhenSourceFileHasWrongSuffix() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); SuffixMapping mapping = new SuffixMapping( ".java", ".class" ); Set results = mapping.getTargetFiles( basedir, base + ".xml" ); assertTrue( "Returned wrong number of target files.", results.isEmpty() ); }
public void testShouldReturnSingleClassFileForSingleJavaFile() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); SuffixMapping mapping = new SuffixMapping( ".java", ".class" ); Set results = mapping.getTargetFiles( basedir, base + ".java" ); assertEquals( "Returned wrong number of target files.", 1, results.size() ); assertEquals( "Target file is wrong.", new File( basedir, base + ".class" ), results.iterator().next() ); }
/** * Gets the set of user-specified {@code Node.java} files. If none are found, {@code jjtree} * will generate automatically a default one. This method search only in the package defined in * the {@link #nodePackage} attribute. */ private Set searchNodeFiles() throws MojoExecutionException { final SuffixMapping mapping = new SuffixMapping(".java", ".java"); final SuffixMapping mappingCAP = new SuffixMapping(".JAVA", ".JAVA"); final SourceInclusionScanner scanner = new StaleSourceScanner(staleMillis); scanner.addSourceMapping(mapping); scanner.addSourceMapping(mappingCAP); File directory = new File(nodeDirectory); if (nodePackage != null && nodePackage.trim().length() != 0) { directory = new File(directory, nodePackage.replace('.', '/')); } if (!directory.isDirectory()) { return Collections.EMPTY_SET; } final File outDir = new File(timestampDirectory); try { return scanner.getIncludedSources(directory, outDir); } catch (InclusionScanException e) { throw new MojoExecutionException( "Error scanning \"" + directory.getPath() + "\" for Node.java to copy.", e); } }
public void testShouldReturnNoTargetFilesWhenSourceFileHasWrongSuffix() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); Set targets = new HashSet(); targets.add( ".class" ); targets.add( ".xml" ); SuffixMapping mapping = new SuffixMapping( ".java", targets ); Set results = mapping.getTargetFiles( basedir, base + ".apt" ); assertTrue( "Returned wrong number of target files.", results.isEmpty() ); }
/** * Gets the set of {@code .jjt} or {@code .jj} files to reprocess. * * @param sourceDir The source directory. * @param ext The extension to search of ({@code .jjt} or {@code .jj}). */ private Set searchStaleGrammars(final File sourceDir, final String ext) throws MojoExecutionException { final String extCAP = ext.toUpperCase(); final SuffixMapping mapping = new SuffixMapping(ext, ext); final SuffixMapping mappingCAP = new SuffixMapping(extCAP, extCAP); final SourceInclusionScanner scanner = new StaleSourceScanner(staleMillis); scanner.addSourceMapping(mapping); scanner.addSourceMapping(mappingCAP); final File outDir = new File(timestampDirectory); try { return scanner.getIncludedSources(sourceDir, outDir); } catch (InclusionScanException e) { throw new MojoExecutionException( "Error scanning source root \"" + sourceDir.getPath() + "\" for stale grammars to reprocess.", e); } }
public void testShouldReturnOneClassFileAndOneXmlFileForSingleJavaFile() throws InclusionScanException { String base = "path/to/file"; File basedir = new File( "." ); Set targets = new HashSet(); targets.add( ".class" ); targets.add( ".xml" ); SuffixMapping mapping = new SuffixMapping( ".java", targets ); Set results = mapping.getTargetFiles( basedir, base + ".java" ); assertEquals( "Returned wrong number of target files.", 2, results.size() ); assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".class" ) ) ); assertTrue( "Targets do not contain class target.", results.contains( new File( basedir, base + ".xml" ) ) ); }
public List<File> computeStaleSources(List<File> compileSourceRoots, Set<String> includes, Set<String> excludes, File outputDirectory, String inputFileSuffix, String outputFileSuffix, int staleMillis) throws MojoExecutionException { return computeStaleSources(compileSourceRoots, includes, excludes, outputDirectory, inputFileSuffix, new SuffixMapping(inputFileSuffix, outputFileSuffix), staleMillis); }
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); }
public List<NamespaceInFile> discoverNamespacesIn(File basePath) throws MojoExecutionException { if (!basePath.exists()) return Collections.EMPTY_LIST; SourceInclusionScanner scanner = getSourceInclusionScanner(includeStale); scanner.addSourceMapping(new SuffixMapping(".clj", new HashSet(Arrays.asList(".clj", "__init.class")))); scanner.addSourceMapping(new SuffixMapping(".cljc", new HashSet(Arrays.asList(".cljc", "__init.class")))); final Set<File> sourceFiles; try { sourceFiles = scanner.getIncludedSources(basePath, targetPath); } catch (InclusionScanException e) { throw new MojoExecutionException("Error scanning source path: \'" + basePath.getPath() + "\' " + "for files to recompile.", e); } List<NamespaceInFile> namespaces = new ArrayList<NamespaceInFile>(); for (File file : sourceFiles) { if (!file.getName().matches(TEMPORARY_FILES_REGEXP)) { namespaces.addAll(findNamespaceInFile(basePath, file)); } } return namespaces; }
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)); }
/** * @return a Plexus scanner object that scans a source root and filters files according to inclusion and * exclusion patterns. In our case at hand we include only Java sources as these are the only files we want * to instrument. */ private SourceInclusionScanner getScanner() { SourceInclusionScanner scanner = null; if ( includes.isEmpty() && excludes.isEmpty() ) { includes = Collections.singleton( "**/*.java" ); scanner = new SimpleSourceInclusionScanner( includes, Collections.EMPTY_SET ); } else { if ( includes.isEmpty() ) { includes.add( "**/*.java" ); } scanner = new SimpleSourceInclusionScanner( includes, excludes ); } // Note: we shouldn't have to do this but this is a limitation of the Plexus SimpleSourceInclusionScanner scanner.addSourceMapping( new SuffixMapping( "dummy", "dummy" ) ); return scanner; }
private SourceInclusionScanner getExcludesScanner() { SourceInclusionScanner scanner = null; if ( excludes.isEmpty() ) { scanner = new SimpleSourceInclusionScanner( Collections.EMPTY_SET, Collections.EMPTY_SET ); } else { scanner = new SimpleSourceInclusionScanner( excludes, Collections.EMPTY_SET ); } // Note: we shouldn't have to do this but this is a limitation of the Plexus SimpleSourceInclusionScanner scanner.addSourceMapping( new SuffixMapping( "dummy", "dummy" ) ); return scanner; }
private List<File> accumulateSources(File templateSourceDir) throws MojoExecutionException { if (!templateSourceDir.exists()) { throw new MojoExecutionException( "templateSourceDir " + templateSourceDir + " does not exist"); } if (!templateSourceDir.isDirectory()) { throw new MojoExecutionException( "templateSourceDir " + templateSourceDir + " is not a directory"); } SourceInclusionScanner scanner = getSourceInclusionScanner(staleMillis); scanner.addSourceMapping(new SuffixMapping(".jamon", ".java")); scanner.addSourceMapping(new SuffixMapping(".jamon", "Impl.java")); final Set<File> staleFiles = new LinkedHashSet<File>(); if (templateSourceDir.isDirectory()) { try { @SuppressWarnings("unchecked") Set<File> includedSources = scanner.getIncludedSources(templateSourceDir, getTemplateOutputDir()); staleFiles.addAll(includedSources); } catch (InclusionScanException e) { throw new MojoExecutionException( "Error scanning source root: \'" + templateSourceDir.getPath() + "\' for stale files to recompile.", e); } } return relativizeFiles(staleFiles); }
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); }
private Set<File> computeStaleSources(final Set<File> packageRoots, final SourceInclusionScanner scanner) throws MojoExecutionException { final SourceMapping mapping = new SuffixMapping("dart", "dart.js"); scanner.addSourceMapping(mapping); final Set<File> staleSources = new HashSet<>(); for (final File packageRoot : packageRoots) { try { final File packageOutputDirectory = getPackageOutputDirectory(packageRoot); staleSources.addAll(scanner.getIncludedSources(packageRoot, packageOutputDirectory)); } catch (final InclusionScanException e) { throw new MojoExecutionException( "Error scanning source root: \'" + relativePath(packageRoot) + "\' for stale files to recompile.", e); } } return staleSources; }
private Set<File> collectIncludedSourceGrammars() throws MojoExecutionException { SourceMapping mapping = new SuffixMapping( "g", Collections.<String>emptySet() ); SourceInclusionScanner scan = new SimpleSourceInclusionScanner( getIncludePatterns(), getExcludePatterns() ); scan.addSourceMapping( mapping ); try { return scan.getIncludedSources( sourceDirectory, null ); } catch ( InclusionScanException e ) { throw new MojoExecutionException( "Error determining gUnit sources", e ); } }
SourceMapping mapping = new SuffixMapping(sourceFileExt, outputFileExt); Set<File> sources = jrxmlFilesToCompile(mapping); if (sources.isEmpty()) {
public void execute() throws MojoExecutionException { SuffixMapping mapping = new SuffixMapping("jbg", Collections.<String>emptySet()); SimpleSourceInclusionScanner scan = new SimpleSourceInclusionScanner(includes, excludes); scan.addSourceMapping(mapping); try { Set<File> candidates = scan.getIncludedSources(directory, null); for(File candidate : candidates) { try { AnnotateClass.processFile(candidate, annotation); } catch(AnnotateClass.AnnotateClassDeleteException e) { throw new MojoExecutionException(e.getMessage()); } catch(AnnotateClass.AnnotateClassRenameException e) { throw new MojoExecutionException(e.getMessage()); } } } catch (InclusionScanException e) { throw new MojoExecutionException("Error scanning files to be processed.", e); } } }
SourceMapping mapping = new SuffixMapping( ".xsd", ".xsd" );