Search in sources :

Example 1 with ZipFile

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

the class EsaMojoTest method testArchiveContentConfigurationSubsystemContentBundles.

public void testArchiveContentConfigurationSubsystemContentBundles() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-esa-content-bundles-only/plugin-config.xml");
    EsaMojo mojo = (EsaMojo) lookupMojo("esa", 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 esa file
    File esaFile = new File(outputDir, finalName + ".esa");
    assertTrue(esaFile.exists());
    //expected files/directories inside the esa file
    List expectedFiles = new ArrayList();
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-esa-test/pom.properties");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-esa-test/pom.xml");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-esa-test/");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/");
    expectedFiles.add("META-INF/maven/");
    expectedFiles.add("META-INF/");
    expectedFiles.add("OSGI-INF/SUBSYSTEM.MF");
    expectedFiles.add("OSGI-INF/");
    expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar");
    ZipFile esa = new ZipFile(esaFile);
    Enumeration entries = esa.getEntries();
    assertTrue(entries.hasMoreElements());
    int missing = getSizeOfExpectedFiles(entries, expectedFiles);
    assertEquals("Missing files: " + expectedFiles, 0, missing);
}
Also used : Enumeration(java.util.Enumeration) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) File(java.io.File)

Example 2 with ZipFile

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

the class EsaMojoTest method testSubsystemContentType.

public void testSubsystemContentType() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-esa-content-type/plugin-config.xml");
    EsaMojo mojo = (EsaMojo) lookupMojo("esa", 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 esa file
    File esaFile = new File(outputDir, finalName + ".esa");
    assertTrue(esaFile.exists());
    // expected files/directories inside the esa file
    List expectedFiles = new ArrayList();
    expectedFiles.add("OSGI-INF/SUBSYSTEM.MF");
    expectedFiles.add("OSGI-INF/");
    expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-artifact03-1.1-SNAPSHOT.jar");
    ZipFile esa = new ZipFile(esaFile);
    Enumeration entries = esa.getEntries();
    assertTrue(entries.hasMoreElements());
    int missing = getSizeOfExpectedFiles(entries, expectedFiles);
    assertEquals("Missing files: " + expectedFiles, 0, missing);
    Manifest mf = getSubsystemManifest(esa);
    Map<String, Map<String, String>> header = getHeader(mf, "Subsystem-Content");
    Map<String, String> attributes = null;
    attributes = header.get("maven-artifact01-1.0-SNAPSHOT");
    assertNotNull(attributes);
    assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version"));
    assertNull(attributes.get("type"));
    attributes = header.get("maven-artifact02-1.0-SNAPSHOT");
    assertNotNull(attributes);
    assertEquals("[1.3,2.5)", attributes.get("version"));
    assertNull(attributes.get("type"));
    attributes = header.get("maven-artifact03");
    assertNotNull(attributes);
    assertEquals("[1.1.0.SNAPSHOT.NNN,1.1.0.SNAPSHOT.NNN]", attributes.get("version"));
    assertEquals("osgi.fragment", attributes.get("type"));
    attributes = header.get("maven-artifact04");
    assertNotNull(attributes);
    assertEquals("[1.2.0.SNAPSHOT,1.2.0.SNAPSHOT]", attributes.get("version"));
    assertEquals("feature", attributes.get("type"));
}
Also used : Enumeration(java.util.Enumeration) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Manifest(java.util.jar.Manifest) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) File(java.io.File) Map(java.util.Map)

Example 3 with ZipFile

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

the class EsaMojoTest method testSubsystemManifestGeneration.

public void testSubsystemManifestGeneration() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-esa-without-manifest/plugin-config.xml");
    EsaMojo mojo = (EsaMojo) lookupMojo("esa", 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 esa file
    File esaFile = new File(outputDir, finalName + ".esa");
    assertTrue(esaFile.exists());
    //expected files/directories inside the esa file
    List expectedFiles = new ArrayList();
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-esa-test/pom.properties");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-esa-test/pom.xml");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/maven-esa-test/");
    expectedFiles.add("META-INF/maven/org.apache.maven.test/");
    expectedFiles.add("META-INF/maven/");
    expectedFiles.add("META-INF/");
    expectedFiles.add("OSGI-INF/SUBSYSTEM.MF");
    expectedFiles.add("OSGI-INF/");
    expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar");
    ZipFile esa = new ZipFile(esaFile);
    Enumeration entries = esa.getEntries();
    assertTrue(entries.hasMoreElements());
    int missing = getSizeOfExpectedFiles(entries, expectedFiles);
    assertEquals("Missing files: " + expectedFiles, 0, missing);
    // Test for the Use-Bundle header
    testForHeader(esa, "Use-Bundle", "Use-Bundle: org.apache.aries.test.Bundle;version=1.0.0-SNAPSHOT");
    // Test for the Subsystem-Type header
    testForHeader(esa, "Subsystem-Type", "Subsystem-Type: feature");
}
Also used : Enumeration(java.util.Enumeration) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) File(java.io.File)

Example 4 with ZipFile

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

the class EsaMojoTest method testCustomInstructions.

public void testCustomInstructions() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-esa-custom-instructions/plugin-config.xml");
    EsaMojo mojo = (EsaMojo) lookupMojo("esa", 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 esa file
    File esaFile = new File(outputDir, finalName + ".esa");
    assertTrue(esaFile.exists());
    //expected files/directories inside the esa file
    List expectedFiles = new ArrayList();
    expectedFiles.add("OSGI-INF/SUBSYSTEM.MF");
    expectedFiles.add("OSGI-INF/");
    expectedFiles.add("maven-artifact01-1.0-SNAPSHOT.jar");
    expectedFiles.add("maven-artifact02-1.0-SNAPSHOT.jar");
    ZipFile esa = new ZipFile(esaFile);
    Enumeration entries = esa.getEntries();
    assertTrue(entries.hasMoreElements());
    int missing = getSizeOfExpectedFiles(entries, expectedFiles);
    assertEquals("Missing files: " + expectedFiles, 0, missing);
    // Test for the Foo header
    testForHeader(esa, "Foo", "Foo: bar");
    // Test for the MyHeader header
    testForHeader(esa, "MyHeader", "MyHeader: myValue");
    // Test for the Subsystem-Name header
    testForHeader(esa, "Subsystem-Name", "Subsystem-Name: myName");
}
Also used : Enumeration(java.util.Enumeration) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) File(java.io.File)

Example 5 with ZipFile

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

the class EsaMojoTest method testManifestSubsystemContentContainsOnlyDirectContent.

public void testManifestSubsystemContentContainsOnlyDirectContent() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/basic-esa-content-type-bundles-only/plugin-config.xml");
    EsaMojo mojo = (EsaMojo) lookupMojo("esa", 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 esa file
    File esaFile = new File(outputDir, finalName + ".esa");
    assertTrue(esaFile.exists());
    ZipFile esa = new ZipFile(esaFile);
    Manifest mf = getSubsystemManifest(esa);
    Map<String, Map<String, String>> header = getHeader(mf, "Subsystem-Content");
    Map<String, String> attributes = null;
    attributes = header.get("maven-artifact01-1.0-SNAPSHOT");
    assertNotNull(attributes);
    assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version"));
    assertNull(attributes.get("type"));
    attributes = header.get("maven-artifact02-1.0-SNAPSHOT");
    assertNotNull(attributes);
    assertEquals("[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]", attributes.get("version"));
    assertNull(attributes.get("type"));
    assertEquals(2, header.size());
}
Also used : ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) Manifest(java.util.jar.Manifest) ZipFile(org.codehaus.plexus.archiver.zip.ZipFile) File(java.io.File) Map(java.util.Map)

Aggregations

ZipFile (org.codehaus.plexus.archiver.zip.ZipFile)21 File (java.io.File)20 ArrayList (java.util.ArrayList)18 Enumeration (java.util.Enumeration)18 List (java.util.List)18 Map (java.util.Map)4 Manifest (java.util.jar.Manifest)4 ZipEntry (org.codehaus.plexus.archiver.zip.ZipEntry)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1