Search in sources :

Example 1 with FileSet

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();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 2 with FileSet

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();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.maven.plugins.assembly.model.FileSet) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) ModuleSources(org.apache.maven.plugins.assembly.model.ModuleSources) File(java.io.File)

Example 3 with FileSet

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;
}
Also used : FixedStringSearchInterpolator(org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator) FileSet(org.apache.maven.plugins.assembly.model.FileSet) ArrayList(java.util.ArrayList) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 4 with FileSet

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();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)

Example 5 with FileSet

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());
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) ArrayList(java.util.ArrayList) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask) File(java.io.File)

Aggregations

FileSet (org.apache.maven.plugins.assembly.model.FileSet)27 File (java.io.File)19 MavenProject (org.apache.maven.project.MavenProject)14 Model (org.apache.maven.model.Model)11 MockAndControlForAddFileSetsTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask)11 Assembly (org.apache.maven.plugins.assembly.model.Assembly)9 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)8 ArrayList (java.util.ArrayList)6 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 ArtifactMock (org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock)4 Component (org.apache.maven.plugins.assembly.model.Component)4 ModuleSources (org.apache.maven.plugins.assembly.model.ModuleSources)4 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)4 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)4 EasyMockSupport (org.easymock.classextension.EasyMockSupport)4 StringReader (java.io.StringReader)3 MockAndControlForAddArtifactTask (org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask)3