Search in sources :

Example 6 with DirectoryScanner

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();
}
Also used : MavenResource(org.jetbrains.idea.maven.model.MavenResource) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File)

Example 7 with DirectoryScanner

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();
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SiteToolException(org.apache.maven.doxia.tools.SiteToolException) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 8 with DirectoryScanner

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));
    }
}
Also used : Path(java.nio.file.Path) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner)

Example 9 with DirectoryScanner

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());
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 10 with DirectoryScanner

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());
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner)

Aggregations

DirectoryScanner (org.codehaus.plexus.util.DirectoryScanner)46 File (java.io.File)31 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)12 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)7 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 Path (java.nio.file.Path)4 LinkedHashSet (java.util.LinkedHashSet)4 HashSet (java.util.HashSet)3 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 UncheckedIOException (java.io.UncheckedIOException)2 Arrays (java.util.Arrays)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Properties (java.util.Properties)2