Search in sources :

Example 1 with ZipEntry

use of org.codehaus.plexus.archiver.zip.ZipEntry in project aries by apache.

the class EbaMojoTest method getSizeOfExpectedFiles.

private int getSizeOfExpectedFiles(Enumeration entries, List expectedFiles) {
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (expectedFiles.contains(entry.getName())) {
            expectedFiles.remove(entry.getName());
            assertFalse(expectedFiles.contains(entry.getName()));
        } else {
            fail(entry.getName() + " is not included in the expected files");
        }
    }
    return expectedFiles.size();
}
Also used : ZipEntry(org.codehaus.plexus.archiver.zip.ZipEntry)

Example 2 with ZipEntry

use of org.codehaus.plexus.archiver.zip.ZipEntry in project aries by apache.

the class EsaMojoTest method testForHeader.

private void testForHeader(ZipFile esa, String header, String exactEntry) throws Exception {
    Enumeration entries = esa.getEntries();
    // Test Use-Bundle & Subsytem-Type inclusion
    ZipEntry entry = esa.getEntry("OSGI-INF/SUBSYSTEM.MF");
    BufferedReader br = new BufferedReader(new InputStreamReader(esa.getInputStream(entry)));
    Boolean foundHeader = false;
    String line;
    while ((line = br.readLine()) != null) {
        if (line.contains(header)) {
            assertEquals(exactEntry, line);
            foundHeader = true;
        }
    }
    assertTrue("Found " + header + ":", foundHeader);
}
Also used : Enumeration(java.util.Enumeration) InputStreamReader(java.io.InputStreamReader) ZipEntry(org.codehaus.plexus.archiver.zip.ZipEntry) BufferedReader(java.io.BufferedReader)

Example 3 with ZipEntry

use of org.codehaus.plexus.archiver.zip.ZipEntry in project jangaroo-tools by CoreMedia.

the class PackageApplicationMojo method includeJangarooModuleScript.

private void includeJangarooModuleScript(File scriptDirectory, Artifact artifact, Writer jangarooApplicationWriter, Writer jangarooApplicationAllWriter) throws IOException {
    ZipFile zipFile = new ZipFile(artifact.getFile());
    ZipEntry zipEntry = zipFile.getEntry(computeModuleJsFileName(artifact.getArtifactId()));
    ModuleSource jooModuleSource = zipEntry != null ? new ZipEntryModuleSource(zipFile, zipEntry) : null;
    writeJangarooModuleScript(scriptDirectory, artifact, jooModuleSource, jangarooApplicationWriter, jangarooApplicationAllWriter);
}
Also used : ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) ZipEntry(org.codehaus.plexus.archiver.zip.ZipEntry)

Example 4 with ZipEntry

use of org.codehaus.plexus.archiver.zip.ZipEntry in project aries by apache.

the class EbaMojoTest method testApplicationManifestGeneration.

public void testApplicationManifestGeneration() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-eba-without-manifest/plugin-config.xml");
    EbaMojo mojo = (EbaMojo) lookupMojo("eba", testPom);
    assertNotNull(mojo);
    String finalName = (String) getVariableValueFromObject(mojo, "finalName");
    String workDir = (String) getVariableValueFromObject(mojo, "workDirectory");
    String outputDir = (String) getVariableValueFromObject(mojo, "outputDirectory");
    mojo.execute();
    //check the generated eba file
    File ebaFile = new File(outputDir, finalName + ".eba");
    assertTrue(ebaFile.exists());
    //expected files/directories inside the eba file
    List expectedFiles = new ArrayList();
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-eba-test/pom.properties");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-eba-test/pom.xml");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-eba-test/");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/");
    expectedFiles.add("META-INF/maven/");
    expectedFiles.add("META-INF/APPLICATION.MF");
    expectedFiles.add("META-INF/");
    expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar");
    ZipFile eba = new ZipFile(ebaFile);
    Enumeration entries = eba.getEntries();
    assertTrue(entries.hasMoreElements());
    int missing = getSizeOfExpectedFiles(entries, expectedFiles);
    assertEquals("Missing files: " + expectedFiles, 0, missing);
    //Test Application-ImportService Application-ExportService and Use-Bundle inclusion
    ZipEntry entry = eba.getEntry("META-INF/APPLICATION.MF");
    BufferedReader br = new BufferedReader(new InputStreamReader(eba.getInputStream(entry)));
    String appServiceExport = new String("Application-ExportService: test.ExportService");
    String appServiceImport = new String("Application-ImportService: test.ImportService");
    String useBundle = new String("Use-Bundle: org.apache.aries.test.Bundle;version=1.0.0-SNAPSHOT");
    Boolean foundAppExport = false;
    Boolean foundAppImport = false;
    Boolean foundUseBundle = false;
    String line;
    while ((line = br.readLine()) != null) {
        if (line.contains(new String("Application-ExportService"))) {
            assertEquals(appServiceExport, line);
            foundAppExport = true;
        }
        if (line.contains(new String("Application-ImportService"))) {
            assertEquals(appServiceImport, line);
            foundAppImport = true;
        }
        if (line.contains(new String("Use-Bundle"))) {
            assertEquals(useBundle, line);
            foundUseBundle = true;
        }
    }
    assertTrue("Found Application-ExportService:", foundAppExport);
    assertTrue("Found Application-ImportService:", foundAppImport);
    assertTrue("Found Use-Bundle:", foundUseBundle);
}
Also used : Enumeration(java.util.Enumeration) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) InputStreamReader(java.io.InputStreamReader) ZipEntry(org.codehaus.plexus.archiver.zip.ZipEntry) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) List(java.util.List) ArrayList(java.util.ArrayList) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) File(java.io.File)

Example 5 with ZipEntry

use of org.codehaus.plexus.archiver.zip.ZipEntry in project aries by apache.

the class EsaMojoTest method getSizeOfExpectedFiles.

private int getSizeOfExpectedFiles(Enumeration entries, List expectedFiles) {
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (expectedFiles.contains(entry.getName())) {
            expectedFiles.remove(entry.getName());
            assertFalse(expectedFiles.contains(entry.getName()));
        } else {
            fail(entry.getName() + " is not included in the expected files");
        }
    }
    return expectedFiles.size();
}
Also used : ZipEntry(org.codehaus.plexus.archiver.zip.ZipEntry)

Aggregations

ZipEntry (org.codehaus.plexus.archiver.zip.ZipEntry)6 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 Enumeration (java.util.Enumeration)2 ZipFile (org.codehaus.plexus.archiver.zip.ZipFile)2 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Manifest (java.util.jar.Manifest)1