Search in sources :

Example 31 with Assembly

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

the class AssemblyInterpolator2Test method testDependencyOutputFileNameMappingsAreNotInterpolated.

public void testDependencyOutputFileNameMappingsAreNotInterpolated() throws IOException, AssemblyInterpolationException {
    AssemblyInterpolator interpolator = new AssemblyInterpolator();
    Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    Assembly assembly = new Assembly();
    DependencySet set = new DependencySet();
    set.setOutputFileNameMapping("${artifact.artifactId}.${artifact.extension}");
    assembly.addDependencySet(set);
    Assembly outputAssembly = interpolator.interpolate(assembly, model, Collections.EMPTY_MAP, DefaultAssemblyReader.create(model));
    List outputDependencySets = outputAssembly.getDependencySets();
    assertEquals(1, outputDependencySets.size());
    DependencySet outputSet = (DependencySet) outputDependencySets.get(0);
    assertEquals(set.getOutputFileNameMapping(), outputSet.getOutputFileNameMapping());
}
Also used : AssemblyInterpolator(org.apache.maven.plugins.assembly.interpolation.AssemblyInterpolator) Model(org.apache.maven.model.Model) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) List(java.util.List) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 32 with Assembly

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

the class AssemblyInterpolatorTest method testDependencySetOutputDirectoryIsNotInterpolated.

public void testDependencySetOutputDirectoryIsNotInterpolated() throws IOException, AssemblyInterpolationException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final Model model = new Model();
    model.setArtifactId("artifact-id");
    model.setGroupId("group.id");
    model.setVersion("1");
    model.setPackaging("jar");
    final Assembly assembly = new Assembly();
    final String outputDirectory = "${artifactId}.${packaging}";
    final DependencySet set = new DependencySet();
    set.setOutputDirectory(outputDirectory);
    assembly.addDependencySet(set);
    final PojoConfigSource configSourceStub = new PojoConfigSource();
    configSourceStub.setRootInterpolator(FixedStringSearchInterpolator.create());
    configSourceStub.setEnvironmentInterpolator(FixedStringSearchInterpolator.create());
    final MavenProject project = new MavenProject(model);
    configSourceStub.setMavenProject(project);
    final Assembly outputAssembly = roundTripInterpolation(assembly, configSourceStub);
    final List<DependencySet> outputDependencySets = outputAssembly.getDependencySets();
    assertEquals(1, outputDependencySets.size());
    final DependencySet outputSet = outputDependencySets.get(0);
    assertEquals("${artifactId}.${packaging}", outputSet.getOutputDirectory());
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Model(org.apache.maven.model.Model) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) PojoConfigSource(org.apache.maven.plugins.assembly.testutils.PojoConfigSource) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 33 with Assembly

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

the class DefaultAssemblyReaderTest method testReadAssemblies_ShouldGetAssemblyDescriptorFromMultipleRefs.

public void testReadAssemblies_ShouldGetAssemblyDescriptorFromMultipleRefs() throws IOException, AssemblyReadException, InvalidAssemblerConfigurationException {
    final File basedir = fileManager.createTempDir();
    final List<Assembly> assemblies = performReadAssemblies(basedir, null, new String[] { "bin", "src" }, null);
    assertNotNull(assemblies);
    assertEquals(2, assemblies.size());
    final Assembly result = assemblies.get(0);
    assertEquals("bin", result.getId());
    final Assembly result2 = assemblies.get(1);
    assertEquals("src", result2.getId());
}
Also used : File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 34 with Assembly

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

the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo.

public void testMergeComponentWithAssembly_ShouldAddOneFileSetToExistingListOfTwo() {
    final Assembly assembly = new Assembly();
    FileSet fs = new FileSet();
    fs.setDirectory("/dir");
    assembly.addFileSet(fs);
    fs = new FileSet();
    fs.setDirectory("/other-dir");
    assembly.addFileSet(fs);
    fs = new FileSet();
    fs.setDirectory("/third-dir");
    final Component component = new Component();
    component.addFileSet(fs);
    new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
    final List<FileSet> fileSets = assembly.getFileSets();
    assertNotNull(fileSets);
    assertEquals(3, fileSets.size());
    final FileSet rfs1 = fileSets.get(0);
    assertEquals("/dir", rfs1.getDirectory());
    final FileSet rfs2 = fileSets.get(1);
    assertEquals("/other-dir", rfs2.getDirectory());
    final FileSet rfs3 = fileSets.get(2);
    assertEquals("/third-dir", rfs3.getDirectory());
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) Component(org.apache.maven.plugins.assembly.model.Component) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 35 with Assembly

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

the class DefaultAssemblyReaderTest method testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly.

public void testMergeComponentsWithMainAssembly_ShouldAddOneFileSetToAssembly() throws IOException, AssemblyReadException {
    final Component component = new Component();
    final FileSet fileSet = new FileSet();
    fileSet.setDirectory("/dir");
    component.addFileSet(fileSet);
    final File componentFile = fileManager.createTempFile();
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(componentFile), "UTF-8");
        final ComponentXpp3Writer componentWriter = new ComponentXpp3Writer();
        componentWriter.write(writer, component);
        writer.close();
        writer = null;
    } finally {
        IOUtil.close(writer);
    }
    final String filename = componentFile.getName();
    final Assembly assembly = new Assembly();
    assembly.addComponentDescriptor(filename);
    final File basedir = componentFile.getParentFile();
    final MavenProject project = new MavenProject();
    expect(configSource.getProject()).andReturn(project).anyTimes();
    expect(configSource.getBasedir()).andReturn(basedir).anyTimes();
    DefaultAssemblyArchiverTest.setupInterpolators(configSource);
    InterpolationState is = new InterpolationState();
    ComponentXpp3Reader.ContentTransformer componentIp = AssemblyInterpolator.componentInterpolator(FixedStringSearchInterpolator.create(), is, new ConsoleLogger(Logger.LEVEL_DEBUG, "console"));
    mockManager.replayAll();
    new DefaultAssemblyReader().mergeComponentsWithMainAssembly(assembly, null, configSource, componentIp);
    final List<FileSet> fileSets = assembly.getFileSets();
    assertNotNull(fileSets);
    assertEquals(1, fileSets.size());
    final FileSet fs = fileSets.get(0);
    assertEquals("/dir", fs.getDirectory());
    mockManager.verifyAll();
}
Also used : FileSet(org.apache.maven.plugins.assembly.model.FileSet) MavenProject(org.apache.maven.project.MavenProject) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) InterpolationState(org.codehaus.plexus.interpolation.fixed.InterpolationState) ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) FileOutputStream(java.io.FileOutputStream) 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)

Aggregations

Assembly (org.apache.maven.plugins.assembly.model.Assembly)56 File (java.io.File)29 MavenProject (org.apache.maven.project.MavenProject)28 Model (org.apache.maven.model.Model)21 EasyMockSupport (org.easymock.classextension.EasyMockSupport)13 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)12 FileSet (org.apache.maven.plugins.assembly.model.FileSet)9 ArrayList (java.util.ArrayList)8 Component (org.apache.maven.plugins.assembly.model.Component)8 DependencySet (org.apache.maven.plugins.assembly.model.DependencySet)7 PojoConfigSource (org.apache.maven.plugins.assembly.testutils.PojoConfigSource)7 FileItem (org.apache.maven.plugins.assembly.model.FileItem)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 OutputStreamWriter (java.io.OutputStreamWriter)5 StringWriter (java.io.StringWriter)5 Writer (java.io.Writer)5 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)5 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)5 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)5