use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.
the class FileSetAssemblyPhaseTest method testShouldAddOneFileSet.
public void testShouldAddOneFileSet() throws ArchiveCreationException, AssemblyFormattingException {
final Assembly assembly = new Assembly();
assembly.setId("test");
assembly.setIncludeBaseDirectory(false);
final FileSet fs = new FileSet();
fs.setOutputDirectory("/out");
fs.setDirectory("/input");
fs.setFileMode("777");
fs.setDirectoryMode("777");
assembly.addFileSet(fs);
final MockAndControlForLogger macLogger = new MockAndControlForLogger();
final MockAndControlForAddFileSetsTask macTask = new MockAndControlForAddFileSetsTask(mm, fileManager);
macTask.expectGetArchiveBaseDirectory();
final MavenProject project = new MavenProject(new Model());
macLogger.expectError(true, true);
final int dirMode = Integer.parseInt("777", 8);
final int fileMode = Integer.parseInt("777", 8);
final int[] modes = { -1, -1, dirMode, fileMode };
macTask.expectAdditionOfSingleFileSet(project, "final-name", false, modes, 1, true);
DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
mm.replayAll();
createPhase(macLogger).execute(assembly, macTask.archiver, macTask.configSource);
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.
the class ModuleSetAssemblyPhaseTest method testCreateFileSet_ShouldPrependModuleDirWhenOutDirIsProvided.
public void testCreateFileSet_ShouldPrependModuleDirWhenOutDirIsProvided() throws AssemblyFormattingException {
final EasyMockSupport mm = new EasyMockSupport();
final Model model = new Model();
model.setArtifactId("artifact");
final MavenProject project = new MavenProject(model);
final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, project);
macTask.expectGetFinalName(null);
final FileSet fs = new FileSet();
fs.setOutputDirectory("out");
final ModuleSources sources = new ModuleSources();
sources.setIncludeModuleDirectory(true);
final MavenProject artifactProject = new MavenProject(new Model());
final File basedir = fileManager.createTempDir();
artifactProject.setFile(new File(basedir, "pom.xml"));
final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", false);
artifactProject.setArtifact(artifactMock.getArtifact());
DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
mm.replayAll();
final FileSet result = createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).createFileSet(fs, sources, artifactProject, macTask.configSource);
assertEquals("artifact/out/", result.getOutputDirectory());
mm.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.
the class ModuleSetAssemblyPhase method createFileSet.
@Nonnull
FileSet createFileSet(@Nonnull final FileSet fileSet, @Nonnull final ModuleSources sources, @Nonnull final MavenProject moduleProject, @Nonnull final AssemblerConfigurationSource configSource) throws AssemblyFormattingException {
final FileSet fs = new FileSet();
String sourcePath = fileSet.getDirectory();
final File moduleBasedir = moduleProject.getBasedir();
if (sourcePath != null) {
final File sourceDir = new File(sourcePath);
if (!sourceDir.isAbsolute()) {
sourcePath = new File(moduleBasedir, sourcePath).getAbsolutePath();
}
} else {
sourcePath = moduleBasedir.getAbsolutePath();
}
fs.setDirectory(sourcePath);
fs.setDirectoryMode(fileSet.getDirectoryMode());
final List<String> excludes = new ArrayList<String>();
final List<String> originalExcludes = fileSet.getExcludes();
if ((originalExcludes != null) && !originalExcludes.isEmpty()) {
excludes.addAll(originalExcludes);
}
if (sources.isExcludeSubModuleDirectories()) {
final List<String> modules = moduleProject.getModules();
for (final String moduleSubPath : modules) {
excludes.add(moduleSubPath + "/**");
}
}
fs.setExcludes(excludes);
fs.setFiltered(fileSet.isFiltered());
fs.setFileMode(fileSet.getFileMode());
fs.setIncludes(fileSet.getIncludes());
fs.setLineEnding(fileSet.getLineEnding());
FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(moduleProject);
String destPathPrefix = "";
if (sources.isIncludeModuleDirectory()) {
destPathPrefix = AssemblyFormatUtils.evaluateFileNameMapping(sources.getOutputDirectoryMapping(), moduleProject.getArtifact(), configSource.getProject(), moduleProject.getArtifact(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
if (!destPathPrefix.endsWith("/")) {
destPathPrefix += "/";
}
}
String destPath = fileSet.getOutputDirectory();
if (destPath == null) {
destPath = destPathPrefix;
} else {
destPath = destPathPrefix + destPath;
}
destPath = AssemblyFormatUtils.getOutputDirectory(destPath, configSource.getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
fs.setOutputDirectory(destPath);
getLogger().debug("module source directory is: " + sourcePath);
getLogger().debug("module dest directory is: " + destPath + " (assembly basedir may be prepended)");
return fs;
}
use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.
the class AddFileSetsTaskTest method testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNotADirectory.
public void testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNotADirectory() throws AssemblyFormattingException, IOException {
macTask.archiveBaseDir = fileManager.createTempFile();
macTask.expectGetArchiveBaseDirectory();
mockManager.replayAll();
final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
try {
task.execute(macTask.archiver, macTask.configSource);
fail("Should throw exception due to non-directory archiveBasedir location that was provided.");
} catch (final ArchiveCreationException e) {
// should do this, because it cannot use the provide archiveBasedir.
}
mockManager.verifyAll();
}
use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.
the class AddFileSetsTaskTest method testGetFileSetDirectory_ShouldReturnBasedir.
public void testGetFileSetDirectory_ShouldReturnBasedir() throws ArchiveCreationException, AssemblyFormattingException {
final File dir = fileManager.createTempDir();
final FileSet fs = new FileSet();
final File result = new AddFileSetsTask(new ArrayList<FileSet>()).getFileSetDirectory(fs, dir, null);
assertEquals(dir.getAbsolutePath(), result.getAbsolutePath());
}
Aggregations