use of org.codehaus.plexus.util.DirectoryScanner in project ph-schematron by phax.
the class SchematronValidationMojo method _performValidation.
private void _performValidation(@Nonnull final ISchematronResource aSch, @Nonnull final File aXMLDirectory, @Nullable final String sXMLIncludes, @Nullable final String sXMLExcludes, @Nullable final File aSVRLDirectory, final boolean bExpectSuccess) throws MojoExecutionException, MojoFailureException {
final DirectoryScanner aScanner = new DirectoryScanner();
aScanner.setBasedir(aXMLDirectory);
if (StringHelper.hasText(sXMLIncludes))
aScanner.setIncludes(new String[] { sXMLIncludes });
if (StringHelper.hasText(sXMLExcludes))
aScanner.setExcludes(new String[] { sXMLExcludes });
aScanner.setCaseSensitive(true);
aScanner.scan();
final String[] aXMLFilenames = aScanner.getIncludedFiles();
if (aXMLFilenames != null) {
for (final String sXMLFilename : aXMLFilenames) {
final File aXMLFile = new File(aXMLDirectory, sXMLFilename);
// Validate XML file
getLog().info("Validating XML file '" + aXMLFile.getPath() + "' against Schematron rules from '" + m_aSchematronFile + "' expecting " + (bExpectSuccess ? "success" : "failure"));
try {
final SchematronOutputType aSOT = aSch.applySchematronValidationToSVRL(TransformSourceFactory.create(aXMLFile));
if (aSVRLDirectory != null) {
// Save SVRL
final File aSVRLFile = new File(aSVRLDirectory, sXMLFilename + ".svrl");
if (!aSVRLFile.getParentFile().mkdirs())
getLog().error("Failed to create parent directory of '" + aSVRLFile.getAbsolutePath() + "'!");
if (new SVRLMarshaller().write(aSOT, aSVRLFile).isSuccess())
getLog().info("Successfully saved SVRL file '" + aSVRLFile.getPath() + "'");
else
getLog().error("Error saving SVRL file '" + aSVRLFile.getPath() + "'");
}
final ICommonsList<SVRLFailedAssert> aFailedAsserts = SVRLHelper.getAllFailedAssertions(aSOT);
if (bExpectSuccess) {
// No failed assertions expected
if (aFailedAsserts.isNotEmpty()) {
final String sMessage = aFailedAsserts.size() + " failed Schematron assertions for XML file '" + aXMLFile.getPath() + "'";
getLog().error(sMessage);
aFailedAsserts.forEach(x -> getLog().error(x.getAsResourceError(aXMLFile.getPath()).getAsString(Locale.US)));
throw new MojoFailureException(sMessage);
}
} else {
// At least one failed assertions expected
if (aFailedAsserts.isEmpty()) {
final String sMessage = "No failed Schematron assertions for erroneous XML file '" + aXMLFile.getPath() + "'";
getLog().error(sMessage);
throw new MojoFailureException(sMessage);
}
}
} catch (final MojoFailureException | MojoExecutionException up) {
throw up;
} catch (final Exception ex) {
final String sMessage = "Exception validating XML '" + aXMLFile.getPath() + "' against Schematron rules from '" + m_aSchematronFile + "'";
getLog().error(sMessage, ex);
throw new MojoExecutionException(sMessage, ex);
}
}
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project st-js by st-js.
the class AbstractSTJSMojo method accumulatePackages.
/**
* @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.
*/
private Collection<String> accumulatePackages(File sourceDir) throws MojoExecutionException {
final Collection<String> result = new HashSet<String>();
if (sourceDir == null || !sourceDir.exists()) {
return result;
}
DirectoryScanner ds = new DirectoryScanner();
ds.setFollowSymlinks(true);
ds.addDefaultExcludes();
ds.setBasedir(sourceDir);
ds.setIncludes(new String[] { "**/*.java" });
ds.scan();
for (String fileName : ds.getIncludedFiles()) {
File file = new File(fileName);
// Supports classes without packages
result.add(file.getParent() == null ? "" : file.getParent().replace(File.separatorChar, '.'));
}
/*
* // 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;
}
use of org.codehaus.plexus.util.DirectoryScanner in project scala-maven-plugin by davidB.
the class MainHelper method findFiles.
public static String[] findFiles(File dir, String[] includes, String[] excludes) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(dir);
scanner.setIncludes(includes);
scanner.setExcludes(excludes);
scanner.addDefaultExcludes();
scanner.scan();
return scanner.getIncludedFiles();
}
use of org.codehaus.plexus.util.DirectoryScanner in project evosuite by EvoSuite.
the class FileUtils method scan.
/**
* Scans a single directory
*
* @param root Directory to scan
* @param includes
* @param excludes
* @return
*/
public static List<File> scan(File root, String[] includes, String[] excludes) {
List<File> files = new ArrayList<File>();
if (!root.exists()) {
return files;
}
final DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setIncludes(includes);
directoryScanner.setExcludes(excludes);
directoryScanner.setBasedir(root);
directoryScanner.scan();
for (final String fileName : directoryScanner.getIncludedFiles()) {
files.add(new File(root, fileName));
}
return files;
}
use of org.codehaus.plexus.util.DirectoryScanner in project sts4 by spring-projects.
the class MavenProjectClasspath method resolveClasspathResources.
private ImmutableList<String> resolveClasspathResources(MavenProject project) {
if (project == null) {
return ImmutableList.of();
}
return ImmutableList.copyOf(project.getBuild().getResources().stream().filter(resource -> new File(resource.getDirectory()).exists()).flatMap(resource -> {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(resource.getDirectory());
if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) {
scanner.setIncludes(resource.getIncludes().toArray(new String[resource.getIncludes().size()]));
}
if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
scanner.setExcludes(resource.getExcludes().toArray(new String[resource.getExcludes().size()]));
}
scanner.setCaseSensitive(false);
scanner.scan();
return Arrays.stream(scanner.getIncludedFiles());
}).toArray(String[]::new));
}
Aggregations