Search in sources :

Example 6 with Component

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

the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneRepositoryToExistingListOfTwo.

public void testMergeComponentWithAssembly_ShouldAddOneRepositoryToExistingListOfTwo() {
    final Assembly assembly = new Assembly();
    Repository repo = new Repository();
    repo.setScope(Artifact.SCOPE_RUNTIME);
    assembly.addRepository(repo);
    repo = new Repository();
    repo.setScope(Artifact.SCOPE_COMPILE);
    assembly.addRepository(repo);
    final Component component = new Component();
    repo = new Repository();
    repo.setScope(Artifact.SCOPE_SYSTEM);
    component.addRepository(repo);
    new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
    final List<Repository> depSets = assembly.getRepositories();
    assertNotNull(depSets);
    assertEquals(3, depSets.size());
    assertEquals(Artifact.SCOPE_RUNTIME, depSets.get(0).getScope());
    assertEquals(Artifact.SCOPE_COMPILE, depSets.get(1).getScope());
    assertEquals(Artifact.SCOPE_SYSTEM, depSets.get(2).getScope());
}
Also used : ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Repository(org.apache.maven.plugins.assembly.model.Repository) Component(org.apache.maven.plugins.assembly.model.Component) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 7 with Component

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

the class DefaultAssemblyReaderTest method testReadAssembly_ShouldReadAssemblyWithComponentInterpolationWithoutSiteDirInclusionOrAssemblyInterpolation.

public void testReadAssembly_ShouldReadAssemblyWithComponentInterpolationWithoutSiteDirInclusionOrAssemblyInterpolation() 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("${groupId}-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).atLeastOnce();
    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).atLeastOnce();
    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("group-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 8 with Component

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

the class DefaultAssemblyReaderTest method testMergeComponentWithAssembly_ShouldAddOneDependencySetToExistingListOfTwo.

public void testMergeComponentWithAssembly_ShouldAddOneDependencySetToExistingListOfTwo() {
    final Assembly assembly = new Assembly();
    DependencySet ds = new DependencySet();
    ds.setScope(Artifact.SCOPE_RUNTIME);
    assembly.addDependencySet(ds);
    ds = new DependencySet();
    ds.setScope(Artifact.SCOPE_COMPILE);
    assembly.addDependencySet(ds);
    final Component component = new Component();
    ds = new DependencySet();
    ds.setScope(Artifact.SCOPE_SYSTEM);
    component.addDependencySet(ds);
    new DefaultAssemblyReader().mergeComponentWithAssembly(component, assembly);
    final List<DependencySet> depSets = assembly.getDependencySets();
    assertNotNull(depSets);
    assertEquals(3, depSets.size());
    assertEquals(Artifact.SCOPE_RUNTIME, depSets.get(0).getScope());
    assertEquals(Artifact.SCOPE_COMPILE, depSets.get(1).getScope());
    assertEquals(Artifact.SCOPE_SYSTEM, depSets.get(2).getScope());
}
Also used : DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) Component(org.apache.maven.plugins.assembly.model.Component) Assembly(org.apache.maven.plugins.assembly.model.Assembly)

Example 9 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)

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