Search in sources :

Example 21 with DirectoryScanner

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

the class EsaMojo method copyEsaSourceFiles.

/**
 * Copies source files to the esa
 *
 * @throws MojoExecutionException
 */
private void copyEsaSourceFiles() throws MojoExecutionException {
    try {
        File esaSourceDir = esaSourceDirectory;
        if (esaSourceDir.exists()) {
            getLog().info("Copy esa resources to " + getBuildDir().getAbsolutePath());
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(esaSourceDir.getAbsolutePath());
            scanner.setIncludes(DEFAULT_INCLUDES);
            scanner.addDefaultExcludes();
            scanner.scan();
            String[] dirs = scanner.getIncludedDirectories();
            for (int j = 0; j < dirs.length; j++) {
                new File(getBuildDir(), dirs[j]).mkdirs();
            }
            String[] files = scanner.getIncludedFiles();
            for (int j = 0; j < files.length; j++) {
                File targetFile = new File(getBuildDir(), files[j]);
                targetFile.getParentFile().mkdirs();
                File file = new File(esaSourceDir, files[j]);
                FileUtils.copyFileToDirectory(file, targetFile.getParentFile());
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error copying esa resources", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException)

Example 22 with DirectoryScanner

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

the class SchemagenMojo method matchFileNames.

/**
     * Return a list of the file names to be processed by schemagen. These are
     * determined by processing the Ant style paths given in the <code>includes</code>
     * and <code>excludes</code> parameters.
     *
     * @return Non-null but possibly empty list of files to process, sorted into lexical order
     */
protected List<String> matchFileNames() {
    DirectoryScanner ds = new DirectoryScanner();
    ds.setExcludes(excludes);
    ds.setIncludes(includes);
    ds.setBasedir(getBaseDir());
    ds.scan();
    List<String> files = new ArrayList<>(Arrays.asList(ds.getIncludedFiles()));
    Collections.sort(files);
    //add http includes
    for (String include : includes) {
        if (include.startsWith("http:") || include.startsWith("https:")) {
            files.add(include);
        }
    }
    return files;
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) ArrayList(java.util.ArrayList)

Example 23 with DirectoryScanner

use of org.codehaus.plexus.util.DirectoryScanner in project maven-plugins by apache.

the class JavadocUtil method addFilesFromSource.

/**
     * Convenience method that gets the files to be included in the javadoc.
     *
     * @param sourceDirectory the directory where the source files are located
     * @param files the variable that contains the appended filenames of the files to be included in the javadoc
     * @param excludePackages the packages to be excluded in the javadocs
     * @param sourceFileIncludes files to include.
     * @param sourceFileExcludes files to exclude.
     */
protected static void addFilesFromSource(List<String> files, File sourceDirectory, List<String> sourceFileIncludes, List<String> sourceFileExcludes, String[] excludePackages) {
    DirectoryScanner ds = new DirectoryScanner();
    if (sourceFileIncludes == null) {
        sourceFileIncludes = Collections.singletonList("**/*.java");
    }
    ds.setIncludes(sourceFileIncludes.toArray(new String[sourceFileIncludes.size()]));
    if (sourceFileExcludes != null && sourceFileExcludes.size() > 0) {
        ds.setExcludes(sourceFileExcludes.toArray(new String[sourceFileExcludes.size()]));
    }
    ds.setBasedir(sourceDirectory);
    ds.scan();
    String[] fileList = ds.getIncludedFiles();
    String[] pathList = new String[fileList.length];
    for (int x = 0; x < fileList.length; x++) {
        pathList[x] = new File(sourceDirectory, fileList[x]).getAbsolutePath();
    }
    if (pathList.length != 0) {
        List<String> tmpFiles = getIncludedFiles(sourceDirectory, pathList, excludePackages);
        files.addAll(tmpFiles);
    }
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) File(java.io.File)

Example 24 with DirectoryScanner

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

the class ValidationMojo method execute.

/**
     * @see org.apache.maven.plugin.AbstractMojo#execute()
     */
public void execute() throws MojoExecutionException {
    if (this.skip) {
        getLog().info("Validation is skipped.");
        return;
    }
    final Iterator<Resource> rsrcIterator = this.project.getResources().iterator();
    while (rsrcIterator.hasNext()) {
        final Resource rsrc = rsrcIterator.next();
        final File directory = new File(rsrc.getDirectory());
        if (directory.exists()) {
            getLog().debug("Scanning " + rsrc.getDirectory());
            final DirectoryScanner scanner = new DirectoryScanner();
            scanner.setBasedir(directory);
            if (rsrc.getExcludes() != null && rsrc.getExcludes().size() > 0) {
                scanner.setExcludes((String[]) rsrc.getExcludes().toArray(new String[rsrc.getExcludes().size()]));
            }
            scanner.addDefaultExcludes();
            if (rsrc.getIncludes() != null && rsrc.getIncludes().size() > 0) {
                scanner.setIncludes((String[]) rsrc.getIncludes().toArray(new String[rsrc.getIncludes().size()]));
            }
            scanner.scan();
            final String[] files = scanner.getIncludedFiles();
            if (files != null) {
                for (int m = 0; m < files.length; m++) {
                    this.validate(directory, files[m]);
                }
            }
        }
    }
}
Also used : DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) Resource(org.apache.maven.model.Resource) File(java.io.File)

Example 25 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 {
    if (!classesDir.exists()) {
        return;
    }
    DirectoryScanner ds = new DirectoryScanner();
    ds.setIncludes(new String[] { "**/*.class" });
    ds.setBasedir(classesDir);
    ds.scan();
    for (String relativePath : ds.getIncludedFiles()) {
        File file = new File(classesDir, relativePath);
        ClassWriter classWriter;
        try {
            InputStream in = new FileInputStream(file);
            try {
                ClassReader classReader = new ClassReader(in);
                classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
                ClassVisitor classVisitor = classWriter;
                if (relativePath.equals("org/apache/axiom/om/OMText.class")) {
                    classVisitor = new GetDataHandlerBridgeMethodInjector(classVisitor);
                }
                classVisitor = new AspectJCodeRemover(classVisitor);
                classReader.accept(classVisitor, 0);
            } finally {
                in.close();
            }
        } catch (IOException ex) {
            throw new MojoExecutionException("Failed to read " + relativePath + ": " + ex.getMessage(), ex);
        }
        try {
            OutputStream out = new FileOutputStream(file);
            try {
                out.write(classWriter.toByteArray());
            } finally {
                out.close();
            }
        } catch (IOException ex) {
            throw new MojoExecutionException("Failed to write " + relativePath + ": " + ex.getMessage(), ex);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ClassVisitor(org.objectweb.asm.ClassVisitor) IOException(java.io.IOException) ClassWriter(org.objectweb.asm.ClassWriter) FileInputStream(java.io.FileInputStream) DirectoryScanner(org.codehaus.plexus.util.DirectoryScanner) FileOutputStream(java.io.FileOutputStream) ClassReader(org.objectweb.asm.ClassReader) File(java.io.File)

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