Search in sources :

Example 1 with DefaultFileSet

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

the class AssemblyProxyArchiverTest method addFileSet_SkipWhenSourceIsAssemblyWorkDir.

@Test(timeout = 5000)
public void addFileSet_SkipWhenSourceIsAssemblyWorkDir() throws IOException, ArchiverException {
    final File sources = fileManager.createTempDir();
    final File workdir = new File(sources, "workdir");
    final TrackingArchiver tracker = new TrackingArchiver();
    final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", tracker, null, null, null, workdir, logger);
    archiver.setForced(true);
    final DefaultFileSet fs = new DefaultFileSet();
    fs.setDirectory(workdir);
    archiver.addFileSet(fs);
    assertTrue(tracker.added.isEmpty());
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) File(java.io.File) TrackingArchiver(org.codehaus.plexus.archiver.diags.TrackingArchiver) Test(org.junit.Test)

Example 2 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) {
    inPublicApi.set(Boolean.TRUE);
    try {
        final DefaultFileSet fs = new DefaultFileSet();
        fs.setDirectory(directory);
        fs.setPrefix(rootPrefix);
        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 3 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[] 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);
        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 4 with DefaultFileSet

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

the class AddArtifactTask method unpacked.

private void unpacked(Archiver archiver, String destDirectory) throws ArchiveCreationException {
    String outputLocation = destDirectory;
    if ((outputLocation.length() > 0) && !outputLocation.endsWith("/")) {
        outputLocation += "/";
    }
    String[] includesArray = TypeConversionUtils.toStringArray(includes);
    if (includesArray == null) {
        includesArray = DEFAULT_INCLUDES_ARRAY;
    }
    final String[] excludesArray = TypeConversionUtils.toStringArray(excludes);
    try {
        final File artifactFile = artifact.getFile();
        if (artifactFile == null) {
            logger.warn("Skipping artifact: " + artifact.getId() + "; it does not have an associated file or directory.");
        } else if (artifactFile.isDirectory()) {
            logger.debug("Adding artifact directory contents for: " + artifact + " to: " + outputLocation);
            DefaultFileSet fs = DefaultFileSet.fileSet(artifactFile);
            fs.setIncludes(includesArray);
            fs.setExcludes(excludesArray);
            fs.setPrefix(outputLocation);
            fs.setStreamTransformer(transformer);
            archiver.addFileSet(fs);
        } else {
            logger.debug("Unpacking artifact contents for: " + artifact + " to: " + outputLocation);
            logger.debug("includes:\n" + StringUtils.join(includesArray, "\n") + "\n");
            logger.debug("excludes:\n" + (excludesArray == null ? "none" : StringUtils.join(excludesArray, "\n")) + "\n");
            DefaultArchivedFileSet afs = DefaultArchivedFileSet.archivedFileSet(artifactFile);
            afs.setIncludes(includesArray);
            afs.setExcludes(excludesArray);
            afs.setPrefix(outputLocation);
            afs.setStreamTransformer(transformer);
            archiver.addArchivedFileSet(afs, encoding);
        }
    } catch (final ArchiverException e) {
        throw new ArchiveCreationException("Error adding file-set for '" + artifact.getId() + "' to archive: " + e.getMessage(), e);
    }
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) DefaultArchivedFileSet(org.codehaus.plexus.archiver.util.DefaultArchivedFileSet) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) File(java.io.File)

Example 5 with DefaultFileSet

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

the class AssemblyProxyArchiverTest method addFileSet_addExcludeWhenSourceContainsAssemblyWorkDir.

@Test(timeout = 5000)
public void addFileSet_addExcludeWhenSourceContainsAssemblyWorkDir() throws IOException, ArchiverException {
    final File sources = fileManager.createTempDir();
    final File workdir = new File(sources, "workdir");
    workdir.mkdir();
    fileManager.createFile(sources, "test-included.txt", "This is included");
    fileManager.createFile(workdir, "test-excluded.txt", "This is excluded");
    final TrackingArchiver tracker = new TrackingArchiver();
    final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", tracker, null, null, null, workdir, logger);
    archiver.setForced(true);
    final DefaultFileSet fs = new DefaultFileSet();
    fs.setDirectory(sources);
    archiver.addFileSet(fs);
    assertEquals(1, tracker.added.size());
    final TrackingArchiver.Addition addition = tracker.added.get(0);
    assertNotNull(addition.excludes);
    assertEquals(1, addition.excludes.length);
    assertEquals(workdir.getName(), addition.excludes[0]);
}
Also used : DefaultFileSet(org.codehaus.plexus.archiver.util.DefaultFileSet) File(java.io.File) TrackingArchiver(org.codehaus.plexus.archiver.diags.TrackingArchiver) Test(org.junit.Test)

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