use of org.codehaus.plexus.util.DirectoryScanner in project intellij-plugins by JetBrains.
the class ResourceCollector method getMavenResourcePaths.
private static String getMavenResourcePaths(@NotNull MavenProject currentProject) {
Set<String> pathSet = new LinkedHashSet<>();
for (MavenResource resource : getMavenResources(currentProject)) {
final String sourcePath = resource.getDirectory();
final String targetPath = resource.getTargetPath();
// ignore empty or non-local resources
if (new File(sourcePath).exists() && ((targetPath == null) || (!targetPath.contains("..")))) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(sourcePath);
if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) {
scanner.setIncludes(ArrayUtil.toStringArray(resource.getIncludes()));
} else {
scanner.setIncludes(DEFAULT_INCLUDES);
}
if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
scanner.setExcludes(ArrayUtil.toStringArray(resource.getExcludes()));
}
scanner.addDefaultExcludes();
scanner.scan();
List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
for (Object includedFile : includedFiles) {
String name = (String) includedFile;
String path = sourcePath + '/' + name;
// this is a workaround for a problem with bnd 0.0.189
if (File.separatorChar != '/') {
name = name.replace(File.separatorChar, '/');
path = path.replace(File.separatorChar, '/');
}
// copy to correct place
path = name + '=' + path;
if (targetPath != null) {
path = targetPath + '/' + path;
}
// use Bnd filtering?
if (resource.isFiltered()) {
path = '{' + path + '}';
}
pathSet.add(path);
}
}
}
StringBuilder resourcePaths = new StringBuilder();
for (Iterator<String> i = pathSet.iterator(); i.hasNext(); ) {
resourcePaths.append(i.next());
if (i.hasNext()) {
resourcePaths.append(',');
}
}
return resourcePaths.toString();
}
use of org.codehaus.plexus.util.DirectoryScanner in project webservices-axiom by apache.
the class PostProcessMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
DecorationModel decorationModel;
try {
decorationModel = siteTool.getDecorationModel(siteDirectory, siteTool.getSiteLocales(locales).get(0), project, reactorProjects, localRepository, repositories);
} catch (SiteToolException ex) {
throw new MojoExecutionException("SiteToolException: " + ex.getMessage(), ex);
}
String head = decorationModel.getBody().getHead();
DirectoryScanner ds = new DirectoryScanner();
ds.setIncludes(new String[] { "**/*.html" });
ds.setBasedir(javadocDirectory);
ds.scan();
for (String relativePath : ds.getIncludedFiles()) {
File file = new File(javadocDirectory, relativePath);
File tmpFile = new File(javadocDirectory, relativePath + ".tmp");
file.renameTo(tmpFile);
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(tmpFile), "UTF-8"));
try {
PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
try {
String line;
while ((line = in.readLine()) != null) {
if (line.equals("</head>")) {
out.println(head);
}
out.println(line);
}
} finally {
out.close();
}
} finally {
in.close();
}
} catch (IOException ex) {
throw new MojoExecutionException("Failed to process " + relativePath + ": " + ex.getMessage(), ex);
}
tmpFile.delete();
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project oap by oaplatform.
the class Files method copyContent.
public static void copyContent(Path basePath, Path destPath, List<String> includes, List<String> excludes, boolean filtering, Function<String, Object> mapper) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(basePath.toFile());
scanner.setIncludes(includes.toArray(new String[includes.size()]));
scanner.setExcludes(excludes.toArray(new String[excludes.size()]));
scanner.scan();
for (String included : scanner.getIncludedFiles()) {
Path src = basePath.resolve(included);
Path dst = destPath.resolve(included);
if (filtering)
Files.writeString(dst, Strings.substitute(Files.readString(src), mapper));
else
copy(src, Encoding.PLAIN, dst, Encoding.PLAIN);
if (!Resources.IS_WINDOWS)
setPosixPermissions(dst, getPosixPermissions(src));
}
}
use of org.codehaus.plexus.util.DirectoryScanner in project jbehave-core by jbehave.
the class StoryFinder method scanDirectory.
private List<String> scanDirectory(String basedir, List<String> includes, List<String> excludes) {
DirectoryScanner scanner = new DirectoryScanner();
if (!new File(basedir).exists()) {
return new ArrayList<>();
}
scanner.setBasedir(basedir);
if (includes != null) {
scanner.setIncludes(includes.toArray(new String[includes.size()]));
}
if (excludes != null) {
scanner.setExcludes(excludes.toArray(new String[excludes.size()]));
}
scanner.scan();
return asList(scanner.getIncludedFiles());
}
use of org.codehaus.plexus.util.DirectoryScanner in project appbundle-maven-plugin by federkasten.
the class CreateApplicationBundleMojo method scanFileSet.
/**
* Scan a fileset and get a list of files which it contains.
*
* @param fileset
* @return list of files contained within a fileset.
* @throws FileNotFoundException
*/
private List<String> scanFileSet(File sourceDirectory, FileSet fileSet) {
final String[] emptyStringArray = {};
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(sourceDirectory);
if (fileSet.getIncludes() != null && !fileSet.getIncludes().isEmpty()) {
scanner.setIncludes(fileSet.getIncludes().toArray(emptyStringArray));
} else {
scanner.setIncludes(DEFAULT_INCLUDES);
}
if (fileSet.getExcludes() != null && !fileSet.getExcludes().isEmpty()) {
scanner.setExcludes(fileSet.getExcludes().toArray(emptyStringArray));
}
if (fileSet.isUseDefaultExcludes()) {
scanner.addDefaultExcludes();
}
scanner.scan();
return Arrays.asList(scanner.getIncludedFiles());
}
Aggregations