Search in sources :

Example 1 with Component

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

the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo.

public void testMergeComponentWithAssembly_ShouldAddOneFileItemToExistingListOfTwo() {
    final Assembly assembly = new Assembly();
    FileItem fi = new FileItem();
    fi.setSource("file");
    assembly.addFile(fi);
    fi = new FileItem();
    fi.setSource("file2");
    assembly.addFile(fi);
    fi = new FileItem();
    fi.setSource("file3");
    final Component component = new Component();
    component.addFile(fi);
    new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
    final List<FileItem> fileItems = assembly.getFiles();
    assertNotNull(fileItems);
    assertEquals(3, fileItems.size());
    final FileItem rf1 = fileItems.get(0);
    assertEquals("file", rf1.getSource());
    final FileItem rf2 = fileItems.get(1);
    assertEquals("file2", rf2.getSource());
    final FileItem rf3 = fileItems.get(2);
    assertEquals("file3", rf3.getSource());
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) Component(org.apache.maven.plugins.assembly.model.Component) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 2 with Component

use of org.apache.maven.plugins.assembly.model.Component 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 3 with Component

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

the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo.

// FIXME: Deep merging should take place...
// public void
// testMergeComponentWithAssembly_ShouldMergeOneFileSetToOneOfExistingTwo()
// {
// Assembly assembly = new Assembly();
//
// FileSet fs = new FileSet();
// fs.setDirectory( "/dir" );
// fs.addInclude( "**/test.txt" );
//
// assembly.addFileSet( fs );
//
// fs = new FileSet();
// fs.setDirectory( "/other-dir" );
// assembly.addFileSet( fs );
//
// fs = new FileSet();
// fs.setDirectory( "/dir" );
// fs.addInclude( "**/components.txt" );
//
// Component component = new Component();
//
// component.addFileSet( fs );
//
// new DefaultAssemblyReader().mergeComponentWithAssembly( component,
// assembly );
//
// List<FileSet> fileSets = assembly.getFileSets();
//
// assertNotNull( fileSets );
// assertEquals( 2, fileSets.size() );
//
// FileSet rfs1 = (FileSet) fileSets.get( 0 );
// assertEquals( "/dir", rfs1.getDirectory() );
//
// List includes = rfs1.getIncludes();
//
// assertNotNull( includes );
// assertEquals( 2, includes.size() );
// assertTrue( includes.contains( "**/test.txt" ) );
// assertTrue( includes.contains( "**/components.txt" ) );
//
// FileSet rfs2 = (FileSet) fileSets.get( 1 );
// assertEquals( "/other-dir", rfs2.getDirectory() );
//
// }
public void testMergeComponentWithAssembly_ShouldAddOneContainerDescriptorHandlerToExistingListOfTwo() {
    final Assembly assembly = new Assembly();
    ContainerDescriptorHandlerConfig cfg = new ContainerDescriptorHandlerConfig();
    cfg.setHandlerName("one");
    assembly.addContainerDescriptorHandler(cfg);
    cfg = new ContainerDescriptorHandlerConfig();
    cfg.setHandlerName("two");
    assembly.addContainerDescriptorHandler(cfg);
    final Component component = new Component();
    cfg = new ContainerDescriptorHandlerConfig();
    cfg.setHandlerName("three");
    component.addContainerDescriptorHandler(cfg);
    new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
    final List<ContainerDescriptorHandlerConfig> result = assembly.getContainerDescriptorHandlers();
    assertNotNull(result);
    assertEquals(3, result.size());
    final Iterator<ContainerDescriptorHandlerConfig> it = result.iterator();
    assertEquals("one", it.next().getHandlerName());
    assertEquals("two", it.next().getHandlerName());
    assertEquals("three", it.next().getHandlerName());
}
Also used : ContainerDescriptorHandlerConfig(org.apache.maven.plugins.assembly.model.ContainerDescriptorHandlerConfig) Component(org.apache.maven.plugins.assembly.model.Component) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 4 with Component

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

the class DefaultAssemblyReader method mergeComponentsWithMainAssembly.

/**
     * Add the contents of all included components to main assembly
     *
     * @param assembly The assembly
     * @param assemblyDir The assembly directory
     * @param transformer The component interpolator
     * @throws AssemblyReadException .
     */
protected void mergeComponentsWithMainAssembly(final Assembly assembly, final File assemblyDir, final AssemblerConfigurationSource configSource, ComponentXpp3Reader.ContentTransformer transformer) throws AssemblyReadException {
    final Locator locator = new Locator();
    if (assemblyDir != null && assemblyDir.exists() && assemblyDir.isDirectory()) {
        locator.addStrategy(new RelativeFileLocatorStrategy(assemblyDir));
    }
    // allow absolute paths in componentDescriptor... MASSEMBLY-486
    locator.addStrategy(new RelativeFileLocatorStrategy(configSource.getBasedir()));
    locator.addStrategy(new FileLocatorStrategy());
    locator.addStrategy(new ClasspathResourceLocatorStrategy());
    final AssemblyExpressionEvaluator aee = new AssemblyExpressionEvaluator(configSource);
    final List<String> componentLocations = assembly.getComponentDescriptors();
    for (String location : componentLocations) {
        // allow expressions in path to component descriptor... MASSEMBLY-486
        try {
            location = aee.evaluate(location).toString();
        } catch (final Exception eee) {
            getLogger().error("Error interpolating componentDescriptor: " + location, eee);
        }
        final Location resolvedLocation = locator.resolve(location);
        if (resolvedLocation == null) {
            throw new AssemblyReadException("Failed to locate component descriptor: " + location);
        }
        Component component = null;
        Reader reader = null;
        try {
            reader = new InputStreamReader(resolvedLocation.getInputStream());
            component = new ComponentXpp3Reader(transformer).read(reader);
        } catch (final IOException e) {
            throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
        } catch (final XmlPullParserException e) {
            throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
        } finally {
            IOUtil.close(reader);
        }
        mergeComponentWithAssembly(component, assembly);
    }
}
Also used : AssemblyExpressionEvaluator(org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator) InputStreamReader(java.io.InputStreamReader) FileLocatorStrategy(org.apache.maven.shared.io.location.FileLocatorStrategy) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AssemblyXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Reader) IOException(java.io.IOException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) InvalidAssemblerConfigurationException(org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException) Locator(org.apache.maven.shared.io.location.Locator) ComponentXpp3Reader(org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Component(org.apache.maven.plugins.assembly.model.Component) ClasspathResourceLocatorStrategy(org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy) Location(org.apache.maven.shared.io.location.Location)

Example 5 with Component

use of org.apache.maven.plugins.assembly.model.Component 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)

Aggregations

Component (org.apache.maven.plugins.assembly.model.Component)9 Assembly (org.apache.maven.plugins.assembly.model.Assembly)8 FileSet (org.apache.maven.plugins.assembly.model.FileSet)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 StringWriter (java.io.StringWriter)3 Writer (java.io.Writer)3 AssemblyXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.AssemblyXpp3Writer)3 ComponentXpp3Writer (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer)3 MavenProject (org.apache.maven.project.MavenProject)3 StringReader (java.io.StringReader)2 Model (org.apache.maven.model.Model)2 ComponentXpp3Reader (org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Reader)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1 AssemblyExpressionEvaluator (org.apache.maven.plugins.assembly.interpolation.AssemblyExpressionEvaluator)1