@SuppressWarnings("unchecked")
  default T mergeIgnoringDuplicates(Archive<?> source, String base, Filter<ArchivePath> filter) {
    if (!base.startsWith("/")) {
      base = "/" + base;
    }
    // Get existing contents from source archive
    final Map<ArchivePath, Node> sourceContent = source.getContent();

    // Add each asset from the source archive
    for (final Map.Entry<ArchivePath, Node> contentEntry : sourceContent.entrySet()) {
      final Node node = contentEntry.getValue();
      ArchivePath nodePath = contentEntry.getKey();
      if (!nodePath.get().startsWith(base)) {
        continue;
      }
      if (!filter.include(nodePath)) {
        continue;
      }
      if (contains(nodePath)) {
        continue;
      }
      nodePath = new BasicPath(nodePath.get().replaceFirst(base, ""));
      // Delegate
      if (node.getAsset() == null) {
        addAsDirectory(nodePath);
      } else {
        add(node.getAsset(), nodePath);
      }
    }
    return (T) this;
  }
Exemplo n.º 2
0
  @Test
  public void manifestWithManifestSections() {
    // When
    final Archive<?> archive =
        ShrinkWrap.create(MavenImporter.class)
            .loadPomFromFile("src/it/jar-with-mf-sample/pom-e.xml")
            .importBuildOutput()
            .as(JavaArchive.class);

    // Then
    assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Title"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry("Specification-Vendor", "Arquillian"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry("MyFirstSection", "Foo", "bar"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry("MySecondSection", "Foo2", "bar2"));
  }
 /** removes test class from web archive (test class will be replaced by transformed assertions) */
 private void removeTestClassFromDeployment(Archive<?> archive, TestClass testClass) {
   for (ArchivePath archivePath : archive.getContent().keySet()) {
     String path = archivePath.get();
     String classPath = testClass.getName().replace(".", "/");
     // remove TestClass and its anonymous classes - do not remove static inner classes
     if (path.matches("/WEB-INF/classes/" + classPath + "(\\$[0-9]*)?\\.class")) {
       archive.delete(archivePath);
     }
   }
 }
  protected ZipExporterDelegate(final Archive<?> archive, final boolean compressed) {
    super(archive);
    this.compressed = compressed;

    // Precondition check
    if (archive.getContent().isEmpty()) {
      throw new IllegalArgumentException(
          "[SHRINKWRAP-93] Cannot use this JDK-based implementation to export as ZIP an archive with no content: "
              + archive.toString());
    }
  }
Exemplo n.º 5
0
  private Set<ArchivePath> getLibraries(Archive<?> archive) {
    return archive
        .getContent(
            new Filter<ArchivePath>() {

              public boolean include(ArchivePath arg0) {
                String path = arg0.get();
                return path.endsWith(".jar");
              }
            })
        .keySet();
  }
Exemplo n.º 6
0
  @Test
  public void manifestCreatedInWar() {
    // When
    final Archive<?> archive =
        ShrinkWrap.create(MavenImporter.class)
            .loadPomFromFile("src/it/war-sample/pom.xml")
            .importBuildOutput()
            .as(WebArchive.class);

    // Then
    assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver"));
  }
Exemplo n.º 7
0
  @Test
  public void suppliedManifestHasPrecedence() {
    // When
    final Archive<?> archive =
        ShrinkWrap.create(MavenImporter.class)
            .loadPomFromFile("src/it/jar-with-mf-sample/pom.xml")
            .importBuildOutput()
            .as(JavaArchive.class);

    // Then
    assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "User"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"));
  }
Exemplo n.º 8
0
  @Test
  public void manifestWithDefaultImplementationEntries() {
    // When
    final Archive<?> archive =
        ShrinkWrap.create(MavenImporter.class)
            .loadPomFromFile("src/it/jar-with-mf-sample/pom-b.xml")
            .importBuildOutput()
            .as(JavaArchive.class);

    // Then
    assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Implementation-Title"));
    assertThat(
        archive.get("META-INF/MANIFEST.MF").getAsset(),
        not(hasManifestEntry("Implementation-Vendor")));
  }