Search in sources :

Example 1 with ZipArchiver

use of org.codehaus.plexus.archiver.zip.ZipArchiver in project maven-plugins by apache.

the class ComponentsXmlArchiverFileFilterTest method testAddToArchive_ShouldWriteTwoComponentToArchivedFile.

public void testAddToArchive_ShouldWriteTwoComponentToArchivedFile() throws IOException, ArchiverException, JDOMException {
    filter.components = new LinkedHashMap<String, Xpp3Dom>();
    final Xpp3Dom dom = createComponentDom(new ComponentDef("role", "hint", "impl"));
    filter.components.put("rolehint", dom);
    final Xpp3Dom dom2 = createComponentDom(new ComponentDef("role", "hint2", "impl"));
    filter.components.put("rolehint2", dom2);
    final ZipArchiver archiver = new ZipArchiver();
    final File archiveFile = fileManager.createTempFile();
    archiver.setDestFile(archiveFile);
    final File descriptorFile = fileManager.createTempFile();
    archiver.setArchiveFinalizers(Collections.<ArchiveFinalizer>singletonList(filter));
    archiver.createArchive();
    ZipFile zf = null;
    FileOutputStream out = null;
    try {
        zf = new ZipFile(archiveFile);
        final ZipEntry ze = zf.getEntry(ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH);
        assertNotNull(ze);
        out = new FileOutputStream(descriptorFile);
        IOUtil.copy(zf.getInputStream(ze), out);
        out.close();
        out = null;
        zf.close();
        zf = null;
    } finally {
        IOUtil.close(out);
        try {
            if (zf != null) {
                zf.close();
            }
        } catch (final IOException e) {
        // Suppressed.
        }
    }
    final SAXBuilder builder = new SAXBuilder(false);
    final Document doc = builder.build(descriptorFile);
    final XPath role = XPath.newInstance("//component[position()=1]/role/text()");
    final XPath hint = XPath.newInstance("//component[position()=1]/role-hint/text()");
    final XPath implementation = XPath.newInstance("//component[position()=1]/implementation/text()");
    assertEquals("role", ((Text) role.selectSingleNode(doc)).getText());
    assertEquals("hint", ((Text) hint.selectSingleNode(doc)).getText());
    assertEquals("impl", ((Text) implementation.selectSingleNode(doc)).getText());
    final XPath role2 = XPath.newInstance("//component[position()=2]/role/text()");
    final XPath hint2 = XPath.newInstance("//component[position()=2]/role-hint/text()");
    final XPath implementation2 = XPath.newInstance("//component[position()=2]/implementation/text()");
    assertEquals("role", ((Text) role2.selectSingleNode(doc)).getText());
    assertEquals("hint2", ((Text) hint2.selectSingleNode(doc)).getText());
    assertEquals("impl", ((Text) implementation2.selectSingleNode(doc)).getText());
}
Also used : XPath(org.jdom.xpath.XPath) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) SAXBuilder(org.jdom.input.SAXBuilder) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) Document(org.jdom.Document) ZipFile(java.util.zip.ZipFile) ZipArchiver(org.codehaus.plexus.archiver.zip.ZipArchiver) FileOutputStream(java.io.FileOutputStream) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 2 with ZipArchiver

use of org.codehaus.plexus.archiver.zip.ZipArchiver in project maven-plugins by apache.

the class DefaultAssemblyArchiverTest method testCreateArchiver_ShouldCreateZipArchiver.

@Test
public void testCreateArchiver_ShouldCreateZipArchiver() throws NoSuchArchiverException, ArchiverException {
    final EasyMockSupport mm = new EasyMockSupport();
    final ZipArchiver archiver = new ZipArchiver();
    final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
    macArchiverManager.expectGetArchiver("zip", archiver);
    final AssemblerConfigurationSource configSource = mm.createMock(AssemblerConfigurationSource.class);
    expect(configSource.isDryRun()).andReturn(false).anyTimes();
    expect(configSource.getArchiverConfig()).andReturn(null).anyTimes();
    expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
    expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
    expect(configSource.getJarArchiveConfiguration()).andReturn(null).anyTimes();
    expect(configSource.isIgnorePermissions()).andReturn(true).anyTimes();
    mm.replayAll();
    final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
    subject.createArchiver("zip", false, null, configSource, null, false, null);
}
Also used : EasyMockSupport(org.easymock.classextension.EasyMockSupport) ZipArchiver(org.codehaus.plexus.archiver.zip.ZipArchiver) AssemblerConfigurationSource(org.apache.maven.plugins.assembly.AssemblerConfigurationSource) File(java.io.File) AssemblyArchiverPhase(org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase) Test(org.junit.Test)

Aggregations

File (java.io.File)2 ZipArchiver (org.codehaus.plexus.archiver.zip.ZipArchiver)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 AssemblerConfigurationSource (org.apache.maven.plugins.assembly.AssemblerConfigurationSource)1 AssemblyArchiverPhase (org.apache.maven.plugins.assembly.archive.phase.AssemblyArchiverPhase)1 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)1 EasyMockSupport (org.easymock.classextension.EasyMockSupport)1 Document (org.jdom.Document)1 SAXBuilder (org.jdom.input.SAXBuilder)1 XPath (org.jdom.xpath.XPath)1 Test (org.junit.Test)1