Search in sources :

Example 26 with DirectoryScanner

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

the class CreateBundleJarMojo method getFilesToCopy.

/**
     * Returns a list of filenames that should be copied over to the destination
     * directory.
     *
     * @param resource
     *            the resource to be scanned
     * @return the array of filenames, relative to the sourceDir
     */
private static String[] getFilesToCopy(Resource 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()]));
    } else {
        scanner.setIncludes(DEFAULT_INCLUDES);
    }
    if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
        scanner.setExcludes(resource.getExcludes().toArray(new String[resource.getExcludes().size()]));
    }
    scanner.addDefaultExcludes();
    scanner.scan();
    return scanner.getIncludedFiles();
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner)

Example 27 with DirectoryScanner

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

the class JspcMojo method scanFiles.

/**
     * Locate all jsp files in the webapp. Used if no explicit jsps are
     * specified.
     */
private void scanFiles(File base) {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(base);
    scanner.setIncludes(includes);
    scanner.setExcludes(excludes);
    scanner.scan();
    Collections.addAll(pages, scanner.getIncludedFiles());
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner)

Example 28 with DirectoryScanner

use of org.codehaus.plexus.util.DirectoryScanner in project felix by apache.

the class BundlePlugin method getMavenResourcePaths.

protected static String getMavenResourcePaths(MavenProject currentProject, boolean test) {
    final String basePath = currentProject.getBasedir().getAbsolutePath();
    Set<String> pathSet = new LinkedHashSet<String>();
    for (Iterator<Resource> i = getMavenResources(currentProject, test).iterator(); i.hasNext(); ) {
        Resource resource = i.next();
        final String sourcePath = resource.getDirectory();
        final String targetPath = resource.getTargetPath();
        // ignore empty or non-local resources
        if (new File(sourcePath).exists() && ((targetPath == null) || (targetPath.indexOf("..") < 0))) {
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(sourcePath);
            if (resource.getIncludes() != null && !resource.getIncludes().isEmpty()) {
                scanner.setIncludes(resource.getIncludes().toArray(EMPTY_STRING_ARRAY));
            } else {
                scanner.setIncludes(DEFAULT_INCLUDES);
            }
            if (resource.getExcludes() != null && !resource.getExcludes().isEmpty()) {
                scanner.setExcludes(resource.getExcludes().toArray(EMPTY_STRING_ARRAY));
            }
            scanner.addDefaultExcludes();
            scanner.scan();
            List<String> includedFiles = Arrays.asList(scanner.getIncludedFiles());
            for (Iterator<String> j = includedFiles.iterator(); j.hasNext(); ) {
                String name = j.next();
                String path = sourcePath + '/' + name;
                // make relative to project
                if (path.startsWith(basePath)) {
                    if (path.length() == basePath.length()) {
                        path = ".";
                    } else {
                        path = path.substring(basePath.length() + 1);
                    }
                }
                // 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.isFiltering()) {
                    path = '{' + path + '}';
                }
                pathSet.add(path);
            }
        }
    }
    StringBuffer resourcePaths = new StringBuffer();
    for (Iterator<String> i = pathSet.iterator(); i.hasNext(); ) {
        resourcePaths.append(i.next());
        if (i.hasNext()) {
            resourcePaths.append(',');
        }
    }
    return resourcePaths.toString();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(org.apache.maven.model.Resource) FileResource(aQute.bnd.osgi.FileResource) File(java.io.File)

Example 29 with DirectoryScanner

use of org.codehaus.plexus.util.DirectoryScanner in project fabric8 by jboss-fuse.

the class AddSwaggerAnnotationMojo method scan.

/**
 * Scans a single directory.
 *
 * @param root Directory to scan
 * @throws MojoExecutionException in case of IO errors
 */
private void scan(File root) throws MojoExecutionException {
    if (!root.exists()) {
        return;
    }
    final DirectoryScanner directoryScanner = new DirectoryScanner();
    directoryScanner.setIncludes(includes);
    directoryScanner.setExcludes(excludes);
    directoryScanner.setBasedir(root);
    directoryScanner.scan();
    for (String fileName : directoryScanner.getIncludedFiles()) {
        final File file = new File(root, fileName);
        try {
            processJavaFile(file);
        } catch (Exception e) {
            throw new MojoExecutionException("io error while rewriting source file", e);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File) JavaModelException(org.eclipse.jdt.core.JavaModelException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException)

Example 30 with DirectoryScanner

use of org.codehaus.plexus.util.DirectoryScanner in project liferay-ide by liferay.

the class LiferayMavenProjectConfigurator method _shouldConfigure.

/**
 * IDE-1489 when no liferay maven plugin is found the project will be scanned
 * for liferay specific files
 */
private boolean _shouldConfigure(Plugin liferayMavenPlugin, ProjectConfigurationRequest request) {
    IProject project = request.getProject();
    MavenProject mavenProject = request.getMavenProject();
    boolean configureAsLiferayPlugin = false;
    if (liferayMavenPlugin != null) {
        configureAsLiferayPlugin = true;
    }
    IFolder warSourceDir = _warSourceDirectory(project, mavenProject);
    if (!configureAsLiferayPlugin && (warSourceDir != null)) {
        IPath baseDir = warSourceDir.getRawLocation();
        String[] includes = { "**/liferay*.xml", "**/liferay*.properties" };
        DirectoryScanner dirScanner = new DirectoryScanner();
        dirScanner.setBasedir(baseDir.toFile());
        dirScanner.setIncludes(includes);
        dirScanner.scan();
        String[] liferayProjectFiles = dirScanner.getIncludedFiles();
        configureAsLiferayPlugin = ListUtil.isNotEmpty(liferayProjectFiles);
    }
    return configureAsLiferayPlugin;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) IPath(org.eclipse.core.runtime.IPath) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

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