org.jboss.as.arquillian.protocol.jmx.ManifestUtils Maven / Gradle / Ivy
The newest version!
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.jboss.as.arquillian.protocol.jmx;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Node;
/**
*
* @author Kabir Khan
*/
class ManifestUtils {
public static Manifest getManifest(Archive> archive, boolean create) {
Manifest manifest = null;
try {
Node node = archive.get(JarFile.MANIFEST_NAME);
if (node == null) {
manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
} else if (create) {
manifest = new Manifest(node.getAsset().openStream());
}
return manifest;
} catch (Exception ex) {
throw new IllegalStateException("Cannot obtain manifest", ex);
}
}
public static Manifest getOrCreateManifest(Archive> archive) {
Manifest manifest;
try {
Node node = archive.get(JarFile.MANIFEST_NAME);
if (node == null) {
manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
} else {
manifest = new Manifest(node.getAsset().openStream());
}
return manifest;
} catch (Exception ex) {
throw new IllegalStateException("Cannot obtain manifest", ex);
}
}
}