use of org.codehaus.plexus.components.io.fileselectors.FileSelector in project maven-plugins by apache.
the class AssemblyProxyArchiverTest method addFile_NoPerms_CallAcceptFilesOnlyOnce.
@Test
public void addFile_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
EasyMockSupport mm = new EasyMockSupport();
final Archiver delegate = mm.createMock(Archiver.class);
delegate.addFile((File) anyObject(), (String) anyObject());
EasyMock.expectLastCall().anyTimes();
delegate.setForced(true);
EasyMock.expectLastCall().anyTimes();
final CounterSelector counter = new CounterSelector(true);
final List<FileSelector> selectors = new ArrayList<FileSelector>();
selectors.add(counter);
mm.replayAll();
final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
archiver.setForced(true);
final File inputFile = fileManager.createTempFile();
archiver.addFile(inputFile, "file.txt");
assertEquals(1, counter.getCount());
mm.verifyAll();
}
use of org.codehaus.plexus.components.io.fileselectors.FileSelector in project maven-plugins by apache.
the class AssemblyProxyArchiverTest method addDirectory_NoPerms_CallAcceptFilesOnlyOnce.
@Test
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
final Archiver delegate = new JarArchiver();
final File output = fileManager.createTempFile();
delegate.setDestFile(output);
final CounterSelector counter = new CounterSelector(true);
final List<FileSelector> selectors = new ArrayList<FileSelector>();
selectors.add(counter);
final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
archiver.setForced(true);
final File dir = fileManager.createTempDir();
FileUtils.cleanDirectory(dir);
fileManager.createFile(dir, "file.txt", "This is a test.");
archiver.addDirectory(dir);
archiver.createArchive();
assertEquals(1, counter.getCount());
}
use of org.codehaus.plexus.components.io.fileselectors.FileSelector in project maven-plugins by apache.
the class DefaultAssemblyArchiver method createArchiver.
/**
* Creates the necessary archiver to build the distribution file.
*
* @param format Archive format
* @param includeBaseDir the base directory for include.
* @param finalName The final name.
* @param configSource {@link AssemblerConfigurationSource}
* @param containerHandlers The list of {@link ContainerDescriptorHandler}
* @param recompressZippedFiles recompress zipped files.
* @param mergeManifestMode how to handle already existing Manifest files
* @return archiver Archiver generated
* @throws org.codehaus.plexus.archiver.ArchiverException
* @throws org.codehaus.plexus.archiver.manager.NoSuchArchiverException
*/
protected Archiver createArchiver(final String format, final boolean includeBaseDir, final String finalName, final AssemblerConfigurationSource configSource, final List<ContainerDescriptorHandler> containerHandlers, boolean recompressZippedFiles, String mergeManifestMode) throws NoSuchArchiverException {
Archiver archiver;
if ("txz".equals(format) || "tgz".equals(format) || "tbz2".equals(format) || format.startsWith("tar")) {
archiver = createTarArchiver(format, TarLongFileMode.valueOf(configSource.getTarLongFileMode()));
} else if ("war".equals(format)) {
archiver = createWarArchiver();
} else {
archiver = archiverManager.getArchiver(format);
}
if (archiver instanceof AbstractZipArchiver) {
((AbstractZipArchiver) archiver).setRecompressAddedZips(recompressZippedFiles);
}
final List<FileSelector> extraSelectors = new ArrayList<FileSelector>();
final List<ArchiveFinalizer> extraFinalizers = new ArrayList<ArchiveFinalizer>();
if (archiver instanceof JarArchiver) {
if (mergeManifestMode != null) {
((JarArchiver) archiver).setFilesetmanifest(JarArchiver.FilesetManifestConfig.valueOf(mergeManifestMode));
}
extraSelectors.add(new JarSecurityFileSelector());
extraFinalizers.add(new ManifestCreationFinalizer(configSource.getMavenSession(), configSource.getProject(), configSource.getJarArchiveConfiguration()));
}
if (configSource.getArchiverConfig() != null) {
configureArchiver(archiver, configSource);
}
String prefix = "";
if (includeBaseDir) {
prefix = finalName;
}
archiver = new AssemblyProxyArchiver(prefix, archiver, containerHandlers, extraSelectors, extraFinalizers, configSource.getWorkingDirectory(), getLogger());
if (configSource.isDryRun()) {
archiver = new DryRunArchiver(archiver, getLogger());
}
archiver.setUseJvmChmod(configSource.isUpdateOnly());
archiver.setIgnorePermissions(configSource.isIgnorePermissions());
archiver.setForced(!configSource.isUpdateOnly());
return archiver;
}
Aggregations