Search in sources :

Example 1 with ComponentXpp3Writer

use of org.apache.maven.plugins.assembly.model.io.xpp3.ComponentXpp3Writer 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 2 with ComponentXpp3Writer

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

Example 3 with ComponentXpp3Writer

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

Aggregations

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 Assembly (org.apache.maven.plugins.assembly.model.Assembly)3 Component (org.apache.maven.plugins.assembly.model.Component)3 FileSet (org.apache.maven.plugins.assembly.model.FileSet)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)1 InterpolationState (org.codehaus.plexus.interpolation.fixed.InterpolationState)1 ConsoleLogger (org.codehaus.plexus.logging.console.ConsoleLogger)1