Search in sources :

Example 6 with DefaultFileSet

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

the class AddDirectoryTask method execute.

public void execute(final Archiver archiver) throws ArchiveCreationException {
    if (".".equals(outputDirectory)) {
        outputDirectory = "";
    } else if ("..".equals(outputDirectory)) {
        throw new ArchiveCreationException("Cannot add source directory: " + directory + " to archive-path: " + outputDirectory + ". All paths must be within the archive root directory.");
    }
    final int oldDirMode = archiver.getOverrideDirectoryMode();
    final int oldFileMode = archiver.getOverrideFileMode();
    boolean fileModeSet = false;
    boolean dirModeSet = false;
    try {
        if (directoryMode != -1) {
            archiver.setDirectoryMode(directoryMode);
            dirModeSet = true;
        }
        if (fileMode != -1) {
            archiver.setFileMode(fileMode);
            fileModeSet = true;
        }
        if (directory.exists()) {
            List<String> directoryExcludes;
            if (excludes != null && !excludes.isEmpty()) {
                directoryExcludes = new ArrayList<String>(excludes);
            } else {
                directoryExcludes = new ArrayList<String>();
            }
            try {
                String[] includesArray = null;
                if (includes != null && !includes.isEmpty()) {
                    includesArray = new String[includes.size()];
                    int i = 0;
                    for (String include : includes) {
                        includesArray[i++] = normalize(include);
                    }
                }
                // this one is guaranteed to be non-null by code above.
                final String[] excludesArray = new String[directoryExcludes.size()];
                int i = 0;
                for (String directoryExclude : directoryExcludes) {
                    excludesArray[i++] = normalize(directoryExclude);
                }
                final DefaultFileSet fs = new DefaultFileSet();
                fs.setUsingDefaultExcludes(useDefaultExcludes);
                fs.setPrefix(outputDirectory);
                fs.setDirectory(directory);
                fs.setIncludes(includesArray);
                fs.setExcludes(excludesArray);
                if (transformer != null) {
                    fs.setStreamTransformer(transformer);
                }
                archiver.addFileSet(fs);
            } catch (final ArchiverException e) {
                throw new ArchiveCreationException("Error adding directory to archive: " + e.getMessage(), e);
            }
        }
    } finally {
        if (dirModeSet) {
            archiver.setDirectoryMode(oldDirMode);
        }
        if (fileModeSet) {
            archiver.setFileMode(oldFileMode);
        }
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException)

Example 7 with DefaultFileSet

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

the class AssemblyProxyArchiver method addDirectory.

/**
     * {@inheritDoc}
     */
@Override
public void addDirectory(@Nonnull final File directory, final String prefix, final String[] includes, final String[] excludes) {
    inPublicApi.set(Boolean.TRUE);
    try {
        final DefaultFileSet fs = new DefaultFileSet();
        fs.setDirectory(directory);
        fs.setIncludes(includes);
        fs.setExcludes(excludes);
        fs.setPrefix(rootPrefix + prefix);
        fs.setFileSelectors(selectors);
        debug("Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix());
        doAddFileSet(fs);
    } finally {
        inPublicApi.set(null);
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet)

Example 8 with DefaultFileSet

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

the class AssemblyProxyArchiver method addDirectory.

/**
     * {@inheritDoc}
     */
@Override
public void addDirectory(@Nonnull final File directory, final String prefix) {
    inPublicApi.set(Boolean.TRUE);
    try {
        final DefaultFileSet fs = new DefaultFileSet();
        fs.setDirectory(directory);
        fs.setPrefix(rootPrefix + prefix);
        fs.setFileSelectors(selectors);
        debug("Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix());
        doAddFileSet(fs);
    } finally {
        inPublicApi.set(null);
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet)

Aggregations

DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)8 File (java.io.File)3 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 TrackingArchiver (org.codehaus.plexus.archiver.diags.TrackingArchiver)2 Test (org.junit.Test)2 DefaultArchivedFileSet (org.codehaus.plexus.archiver.util.DefaultArchivedFileSet)1