Search in sources :

Example 11 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class DefaultAssemblyReaderTest method testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation.

public void testReadAssembly_ShouldReadAssemblyWithComponentWithoutSiteDirInclusionOrInterpolation() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final File componentsFile = fileManager.createTempFile();
    final File basedir = componentsFile.getParentFile();
    final String componentsFilename = componentsFile.getName();
    final Component component = new Component();
    final FileSet fs = new FileSet();
    fs.setDirectory("/dir");
    component.addFileSet(fs);
    Writer fw = null;
    try {
        fw = new OutputStreamWriter(new FileOutputStream(componentsFile), "UTF-8");
        new ComponentXpp3Writer().write(fw, component);
        fw.close();
        fw = null;
    } finally {
        IOUtil.close(fw);
    }
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.addComponentDescriptor(componentsFilename);
    final StringReader sr = writeToStringReader(assembly);
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    final Model model = new Model();
    model.setGroupId("group");
    model.setArtifactId("artifact");
    model.setVersion("version");
    final MavenProject project = new MavenProject(model);
    expect(configSource.getProject()).andReturn(project).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    mockManager.replayAll();
    final Assembly result = new DefaultAssemblyReader().readAssembly(sr, "testLocation", null, configSource);
    assertEquals(assembly.getId(), result.getId());
    final List<FileSet> fileSets = result.getFileSets();
    assertEquals(1, fileSets.size());
    assertEquals("/dir", fileSets.get(0).getDirectory());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader) Model(org.apache.maven.model.Model) ComponentXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer) OutputStreamWriter(java.io.OutputStreamWriter) Component(org.apache.maven.plugins.assembly.model.Component) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) AssemblyXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer) Writer(java.io.Writer) ComponentXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 12 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class ModuleSetAssemblyPhaseTest method testCreateFileSet_ShouldAddExcludesForSubModulesWhenExcludeSubModDirsIsTrue.

public void testCreateFileSet_ShouldAddExcludesForSubModulesWhenExcludeSubModDirsIsTrue() throws AssemblyFormattingException {
    final EasyMockSupport mm = new EasyMockSupport();
    final MockAndControlForAddArtifactTask macTask = new MockAndControlForAddArtifactTask(mm, null);
    macTask.expectGetFinalName(null);
    final FileSet fs = new FileSet();
    final ModuleSources sources = new ModuleSources();
    sources.setExcludeSubModuleDirectories(true);
    final Model model = new Model();
    model.setArtifactId("artifact");
    model.addModule("submodule");
    final MavenProject project = new MavenProject(model);
    final File basedir = fileManager.createTempDir();
    project.setFile(new File(basedir, "pom.xml"));
    final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "artifact", "version", "jar", false);
    project.setArtifact(artifactMock.getArtifact());
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mm.replayAll();
    final FileSet result = createPhase(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"), null).createFileSet(fs, sources, project, macTask.configSource);
    assertEquals(1, result.getExcludes().size());
    assertEquals("submodule/**", result.getExcludes().get(0));
    mm.verifyAll();
}
Also used : MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) EasyMockSupport(org.easymock.classextension.EasyMockSupport) FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) 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 13 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class AddFileSetsTaskTest method testAddFileSet_ShouldAddDirectory.

public void testAddFileSet_ShouldAddDirectory() throws ArchiveCreationException, AssemblyFormattingException {
    final FileSet fs = new FileSet();
    final String dirname = "dir";
    fs.setDirectory(dirname);
    fs.setOutputDirectory("dir2");
    // ensure this exists, so the directory addition will proceed.
    final File srcDir = new File(macTask.archiveBaseDir, dirname);
    srcDir.mkdirs();
    final int[] modes = { -1, -1, -1, -1 };
    macTask.expectAdditionOfSingleFileSet(null, null, true, modes, 1, true, false);
    //        macTask.expectGetProject( null );
    final MavenProject project = new MavenProject(new Model());
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mockManager.replayAll();
    final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
    task.setLogger(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    task.setProject(project);
    task.addFileSet(fs, macTask.archiver, macTask.configSource, macTask.archiveBaseDir);
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) MockAndControlForAddFileSetsTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddFileSetsTask) File(java.io.File)

Example 14 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class AddFileSetsTaskTest method testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNonExistent.

public void testExecute_ShouldThrowExceptionIfArchiveBasedirProvidedIsNonExistent() throws AssemblyFormattingException {
    macTask.archiveBaseDir.delete();
    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-existent 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 15 with FileSet

use of org.apache.maven.plugins.assembly.model.FileSet in project maven-plugins by apache.

the class AddFileSetsTaskTest method testAddFileSet_ShouldAddDirectoryUsingSourceDirNameForDestDir.

public void testAddFileSet_ShouldAddDirectoryUsingSourceDirNameForDestDir() throws ArchiveCreationException, AssemblyFormattingException {
    final FileSet fs = new FileSet();
    final String dirname = "dir";
    fs.setDirectory(dirname);
    final File archiveBaseDir = fileManager.createTempDir();
    // ensure this exists, so the directory addition will proceed.
    final File srcDir = new File(archiveBaseDir, dirname);
    srcDir.mkdirs();
    final int[] modes = { -1, -1, -1, -1 };
    macTask.expectAdditionOfSingleFileSet(null, null, true, modes, 1, true, false);
    //macTask.expectGetProject( null );
    final MavenProject project = new MavenProject(new Model());
    DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
    mockManager.replayAll();
    final AddFileSetsTask task = new AddFileSetsTask(new ArrayList<FileSet>());
    task.setLogger(new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    task.setProject(project);
    task.addFileSet(fs, macTask.archiver, macTask.configSource, archiveBaseDir);
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) Model(org.apache.maven.model.Model) 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