List of usage examples for java.util.jar Manifest getMainAttributes
public Attributes getMainAttributes()
From source file:Main.java
private static Manifest getSurrogateManifest(Dictionary compositeManifest, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports) { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$ // Ignore the manifest version from the map // always use bundle manifest version 2 attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$ // Ignore the Equinox composite bundle header attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.SURROGATE_BUNDLE); if (compositeDesc != null && matchingExports != null) { // convert the exports from the composite into imports addImports(attributes, compositeDesc, matchingExports); // convert the matchingExports from the composite into exports addExports(attributes, compositeDesc, matchingExports); }//from w w w . j ava 2 s. c om // add the rest for (Enumeration keys = compositeManifest.keys(); keys.hasMoreElements();) { Object header = keys.nextElement(); if (Constants.BUNDLE_MANIFESTVERSION.equals(header) || BaseStorageHook.COMPOSITE_HEADER.equals(header) || Constants.IMPORT_PACKAGE.equals(header) || Constants.EXPORT_PACKAGE.equals(header)) continue; if (header instanceof String && compositeManifest.get(header) instanceof String) attributes.putValue((String) header, (String) compositeManifest.get(header)); } return manifest; }
From source file:io.dstream.tez.utils.ClassPathUtils.java
/** * Will create a JAR file from base dir//w w w .j a v a 2 s .co m * * @param sourceDir * @param jarName * @return */ public static File toJar(File sourceDir, String jarName) { if (!sourceDir.isAbsolute()) { throw new IllegalArgumentException("Source must be expressed through absolute path"); } Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); File jarFile = new File(jarName); try { JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest); add(sourceDir, sourceDir.getAbsolutePath().length(), target); target.close(); } catch (Exception e) { throw new IllegalStateException( "Failed to create JAR file '" + jarName + "' from " + sourceDir.getAbsolutePath(), e); } return jarFile; }
From source file:oz.tez.deployment.utils.ClassPathUtils.java
/** * /*from w w w .ja v a2 s .c om*/ * @param source * @return */ public static byte[] toJarBytes(File source) { if (!source.isAbsolute()) { throw new IllegalArgumentException("Source must be expressed through absolute path"); } Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { JarOutputStream target = new JarOutputStream(bos, manifest); add(source, source.getAbsolutePath().length(), target); target.close(); } catch (Exception e) { throw new IllegalStateException("Failed to generate JAR bytes from " + source.getAbsolutePath(), e); } return bos.toByteArray(); }
From source file:org.talend.commons.utils.resource.BundleFileUtil.java
public static String getBundleVersion(Manifest manifest) { if (manifest == null) { return null; }/*w w w . j av a2s . c om*/ Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes == null) { return null; } return mainAttributes.getValue("Bundle-Version"); //$NON-NLS-1$ }
From source file:oz.tez.deployment.utils.ClassPathUtils.java
/** * Will create a JAR file frombase dir/*from w ww . j a v a 2 s . c om*/ * * @param source * @param jarName * @return */ public static File toJar(File source, String jarName) { if (!source.isAbsolute()) { throw new IllegalArgumentException("Source must be expressed through absolute path"); } Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); File jarFile = new File(jarName); try { JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest); add(source, source.getAbsolutePath().length(), target); target.close(); } catch (Exception e) { throw new IllegalStateException( "Failed to create JAR file '" + jarName + "' from " + source.getAbsolutePath(), e); } return jarFile; }
From source file:com.ericsson.eiffel.remrem.generate.EiffelRemremControllerIntegrationTest.java
public static String getMessagingVersion() { Enumeration resEnum;//w ww .ja v a 2 s.co m try { resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); while (resEnum.hasMoreElements()) { try { URL url = (URL) resEnum.nextElement(); if (url.getPath().contains("eiffel-remrem-semantics")) { InputStream is = url.openStream(); if (is != null) { Manifest manifest = new Manifest(is); Attributes mainAttribs = manifest.getMainAttributes(); String version = mainAttribs.getValue("semanticsVersion"); if (version != null) { return version; } } } } catch (Exception e) { // Silently ignore wrong manifests on classpath? } } } catch (IOException e1) { // Silently ignore wrong manifests on classpath? } return null; }
From source file:org.talend.commons.utils.resource.BundleFileUtil.java
public static String getBundleSymbolicName(Manifest manifest) { if (manifest == null) { return null; }/*from www .ja v a 2 s . c o m*/ Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes == null) { return null; } String name = mainAttributes.getValue("Bundle-SymbolicName"); //$NON-NLS-1$ if (name == null) { return null; } final int indexOf = name.indexOf(';'); if (indexOf > 0) name = name.substring(0, indexOf); return name; }
From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.ManifestUtils.java
/** * Determine the Import-Package value based on the Export-Package entries in * the jars given as Resources.// w w w .j ava 2s .c o m * @param resources * @return */ public static String[] determineImportPackages(Resource[] resources) { Set collection = new LinkedHashSet(); // for each resource for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; Manifest man = JarUtils.getManifest(resource); if (man != null) { // read the manifest // get the Export-Package Attributes attrs = man.getMainAttributes(); String exportedPackages = attrs.getValue(Constants.EXPORT_PACKAGE); // add it to the StringBuilder if (StringUtils.hasText(exportedPackages)) { collection.addAll(StringUtils.commaDelimitedListToSet(exportedPackages)); } } } // return the result as string String[] array = (String[]) collection.toArray(new String[collection.size()]); // clean whitespace just in case for (int i = 0; i < array.length; i++) { array[i] = StringUtils.trimWhitespace(array[i]); } return array; }
From source file:org.apache.sling.ide.eclipse.core.internal.BundleStateHelper.java
private static Object doRecalcDecorationState(IServer server, IProject project) { try {//w ww .jav a 2 s .co m if (!ProjectHelper.isBundleProject(project)) { return EMPTY_STATE; } IJavaProject javaProject = ProjectHelper.asJavaProject(project); String hostname = server.getHost(); int launchpadPort = server.getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080); if (project.exists() && !javaProject.exists()) { // then it's not a java project.. return EMPTY_STATE; } IPath outputLocation = javaProject.getOutputLocation(); outputLocation = outputLocation.removeFirstSegments(1); IPath manifestFilePath = outputLocation.append("META-INF/MANIFEST.MF"); IFile manifestFile = project.getFile(manifestFilePath); String bundlename; if (manifestFile.exists()) { Manifest manifest = new Manifest(manifestFile.getContents()); bundlename = manifest.getMainAttributes().getValue("Bundle-SymbolicName"); } else { String groupId = ProjectHelper.getMavenProperty(project, "groupId"); String artifactId = ProjectHelper.getMavenProperty(project, "artifactId"); if (groupId == null || groupId.isEmpty()) { bundlename = artifactId; } else { bundlename = groupId + "." + artifactId; } } String username = server.getAttribute(ISlingLaunchpadServer.PROP_USERNAME, "admin"); String password = server.getAttribute(ISlingLaunchpadServer.PROP_PASSWORD, "admin"); GetMethod method = new GetMethod( "http://" + hostname + ":" + launchpadPort + "/system/console/bundles/" + bundlename + ".json"); int resultCode = getHttpClient(username, password).executeMethod(method); if (resultCode != HttpStatus.SC_OK) { return " [" + resultCode + "]"; } String responseBodyAsString = method.getResponseBodyAsString(16 * 1024); // relevant data is in first 1k anyway JSONObject result = new JSONObject(responseBodyAsString); JSONArray dataArray = (JSONArray) result.get("data"); JSONObject firstElement = (JSONObject) dataArray.get(0); return " [" + firstElement.get("state") + "]"; } catch (Exception e) { e.printStackTrace(); return e.getMessage(); } }
From source file:org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.java
private static Class<?> getStartClass(List<URL> list) { logger.info("Searching manifests: " + list); for (URL url : list) { try {/* www . j av a2 s . co m*/ logger.info("Searching manifest: " + url); InputStream inputStream = url.openStream(); try { Manifest manifest = new Manifest(inputStream); String startClass = manifest.getMainAttributes().getValue("Start-Class"); if (startClass != null) { return ClassUtils.forName(startClass, SpringFunctionInitializer.class.getClassLoader()); } } finally { inputStream.close(); } } catch (Exception ex) { } } return null; }