Search in sources :

Example 6 with FileSet

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

the class AddFileSetsTaskTest method testAddFileSet_ShouldNotAddDirectoryWhenSourceDirNonExistent.

public void testAddFileSet_ShouldNotAddDirectoryWhenSourceDirNonExistent() throws ArchiveCreationException, AssemblyFormattingException {
    final FileSet fs = new FileSet();
    final String dirname = "dir";
    fs.setDirectory(dirname);
    final File archiveBaseDir = fileManager.createTempDir();
    macTask.expectGetFinalName("finalName");
    //macTask.expectGetProject( null );
    expect(macTask.archiver.getOverrideDirectoryMode()).andReturn(-1);
    expect(macTask.archiver.getOverrideFileMode()).andReturn(-1);
    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)

Example 7 with FileSet

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

the class AddFileSetsTaskTest method testGetFileSetDirectory_ShouldReturnDirFromArchiveBasedirAndSourceDir.

public void testGetFileSetDirectory_ShouldReturnDirFromArchiveBasedirAndSourceDir() throws ArchiveCreationException, AssemblyFormattingException {
    final File dir = fileManager.createTempDir();
    final String srcPath = "source";
    final File srcDir = new File(dir, srcPath);
    final FileSet fs = new FileSet();
    fs.setDirectory(srcPath);
    final File result = new AddFileSetsTask(new ArrayList<FileSet>()).getFileSetDirectory(fs, null, dir);
    assertEquals(srcDir.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)

Example 8 with FileSet

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

the class DefaultAssemblyReaderTest method testIncludeSiteInAssembly_ShouldAddSiteDirFileSetWhenDirExists.

// public void testReadComponent_ShouldReadComponentFromXml()
// throws IOException, AssemblyReadException
// {
// Component component = new Component();
//
// FileSet fileSet = new FileSet();
// fileSet.setDirectory( "/dir" );
//
// component.addFileSet( fileSet );
//
// StringWriter sw = new StringWriter();
//
// ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
//
// componentWriter.write( sw, component );
//
// Component result = new DefaultAssemblyReader().readComponent( new StringReader( sw.toString() ) );
//
// List<FileSet> fileSets = result.getFileSets();
//
// assertNotNull( fileSets );
// assertEquals( 1, fileSets.size() );
//
// FileSet fs = (FileSet) fileSets.get( 0 );
//
// assertEquals( "/dir", fs.getDirectory() );
// }
//
// public void testGetComponentFromFile_ShouldReadComponent()
// throws IOException, AssemblyReadException
// {
// Component component = new Component();
//
// FileSet fileSet = new FileSet();
// fileSet.setDirectory( "/dir" );
//
// component.addFileSet( fileSet );
//
// File componentFile = fileManager.createTempFile();
//
// FileWriter writer = null;
//
// try
// {
// writer = new FileWriter( componentFile );
//
// ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
//
// componentWriter.write( writer, component );
// }
// finally
// {
// IOUtil.close( writer );
// }
//
// File basedir = componentFile.getParentFile();
// String filename = componentFile.getName();
//
// configSource.getBasedir();
// configSourceControl.setReturnValue( basedir );
//
// mockManager.replayAll();
//
// Component result = new DefaultAssemblyReader().getComponentFromFile( filename, configSource );
//
// List<FileSet> fileSets = result.getFileSets();
//
// assertNotNull( fileSets );
// assertEquals( 1, fileSets.size() );
//
// FileSet fs = (FileSet) fileSets.get( 0 );
//
// assertEquals( "/dir", fs.getDirectory() );
//
// mockManager.verifyAll();
// }
public void testIncludeSiteInAssembly_ShouldAddSiteDirFileSetWhenDirExists() throws IOException, InvalidAssemblerConfigurationException {
    final File siteDir = fileManager.createTempDir();
    expect(configSource.getSiteDirectory()).andReturn(siteDir).anyTimes();
    final Assembly assembly = new Assembly();
    mockManager.replayAll();
    new DefaultAssemblyReader().includeSiteInAssembly(assembly, configSource);
    final List<FileSet> fileSets = assembly.getFileSets();
    assertNotNull(fileSets);
    assertEquals(1, fileSets.size());
    final FileSet fs = fileSets.get(0);
    assertEquals(siteDir.getPath(), fs.getDirectory());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 9 with FileSet

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

the class DefaultAssemblyReaderTest method testGetAssemblyFromDescriptorFile_ShouldReadAssembly.

public void testGetAssemblyFromDescriptorFile_ShouldReadAssembly() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    final FileSet fs = new FileSet();
    fs.setDirectory("/dir");
    assembly.addFileSet(fs);
    final File assemblyFile = fileManager.createTempFile();
    final File basedir = assemblyFile.getParentFile();
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    expect(configSource.getProject()).andReturn(new MavenProject(new Model())).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(assemblyFile), "UTF-8");
        new AssemblyXpp3Writer().write(writer, assembly);
        writer.close();
        writer = null;
    } finally {
        IOUtil.close(writer);
    }
    mockManager.replayAll();
    final Assembly result = new DefaultAssemblyReader().getAssemblyFromDescriptorFile(assemblyFile, configSource);
    assertEquals(assembly.getId(), result.getId());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) AssemblyXpp3Writer(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer) FileOutputStream(java.io.FileOutputStream) Model(org.apache.maven.model.Model) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) 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)

Example 10 with FileSet

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

the class DefaultAssemblyReaderTest method testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation.

public void testReadAssembly_ShouldReadAssemblyWithSiteDirInclusionFromAssemblyWithoutComponentsOrInterpolation() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final Assembly assembly = new Assembly();
    assembly.setId("test");
    assembly.setIncludeSiteDirectory(true);
    final StringReader sr = writeToStringReader(assembly);
    final File siteDir = fileManager.createTempDir();
    expect(configSource.getSiteDirectory()).andReturn(siteDir).anyTimes();
    final File basedir = fileManager.createTempDir();
    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("/site", fileSets.get(0).getOutputDirectory());
    mockManager.verifyAll();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.maven.plugins.assembly.model.FileSet) StringReader(java.io.StringReader) Model(org.apache.maven.model.Model) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

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