/* * Copyright 2015 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 <a href="kabir.khan@jboss.com">Kabir Khan</a> */ 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); } } }