List of usage examples for java.util.jar Manifest Manifest
public Manifest(Manifest man)
From source file:org.hippoecm.repository.util.RepoUtils.java
/** * * @param clazz the class object for which to obtain the manifest * @return the manifest object, or {@code null} if it could not be obtained * @throws IOException if something went wrong while reading the manifest *//*from ww w. j a v a2 s . c o m*/ public static Manifest getManifest(Class clazz) throws IOException { final URL url = getManifestURL(clazz); if (url != null) { final InputStream is = url.openStream(); try { return new Manifest(is); } finally { IOUtils.closeQuietly(is); } } return null; }
From source file:org.alfresco.web.scripts.ShareManifest.java
/** * Read the manifest file that was specified in the constructor. *//* w ww.ja va 2 s . co m*/ public void readManifest() { try (InputStream is = resource.getInputStream()) { manifest = new Manifest(is); } catch (IOException e) { throw new RuntimeException("Error reading manifest.", e); } }
From source file:org.sourcepit.tools.shared.resources.harness.SharedResourcesCopier.java
public void copy(String resourcePath, File targetDir) throws IOException { final Collection<String> resourceLocations = new LinkedHashSet<String>(); final Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { final InputStream inputStream = resources.nextElement().openStream(); try {/*from w w w .j ava 2s. c o m*/ final String _resourceLocations = new Manifest(inputStream).getMainAttributes() .getValue(manifestHeader); if (_resourceLocations != null) { for (String resourceLocation : _resourceLocations.split(",")) { resourceLocations.add(resourceLocation.trim()); } } } finally { IOUtils.closeQuietly(inputStream); } } final IFilteredCopier copier = isFilter() ? newCopier() : null; final List<IOException> ioException = new ArrayList<IOException>(); for (String resourceLocation : resourceLocations) { try { SharedResourcesUtils.copy(classLoader, resourceLocation, resourcePath, targetDir, false, copier, getFilterStrategy()); return; } catch (IOException e) { ioException.add(e); } } if (!ioException.isEmpty()) { throw ioException.get(0); } throw new FileNotFoundException(resourcePath); }
From source file:org.lnicholls.galleon.app.AppDescriptor.java
public AppDescriptor(File jar) throws IOException, AppException { mJar = jar;/*from w w w . jav a2s .c o m*/ JarFile zipFile = new JarFile(jar); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String name = entry.getName(); if (name.toUpperCase().equals(JarFile.MANIFEST_NAME)) { InputStream in = null; try { in = zipFile.getInputStream(entry); Manifest manifest = new Manifest(in); Attributes attributes = manifest.getMainAttributes(); if (attributes.getValue("Main-Class") != null) { mClassName = (String) attributes.getValue("Main-Class"); if (attributes.getValue("HME-Arguments") != null) mArguments = (String) attributes.getValue("HME-Arguments"); if (attributes.getValue(TITLE) != null) mTitle = (String) attributes.getValue(TITLE); if (attributes.getValue(RELEASE_DATE) != null) mReleaseDate = (String) attributes.getValue(RELEASE_DATE); if (attributes.getValue(DESCRIPTION) != null) mDescription = (String) attributes.getValue(DESCRIPTION); if (attributes.getValue(DOCUMENTATION) != null) mDocumentation = (String) attributes.getValue(DOCUMENTATION); if (attributes.getValue(AUTHOR_NAME) != null) mAuthorName = (String) attributes.getValue(AUTHOR_NAME); if (attributes.getValue(AUTHOR_EMAIL) != null) mAuthorEmail = (String) attributes.getValue(AUTHOR_EMAIL); if (attributes.getValue(AUTHOR_HOMEPAGE) != null) mAuthorHomepage = (String) attributes.getValue(AUTHOR_HOMEPAGE); if (attributes.getValue(VERSION) != null) mVersion = (String) attributes.getValue(VERSION); if (attributes.getValue(CONFIGURATION) != null) mConfiguration = (String) attributes.getValue(CONFIGURATION); if (attributes.getValue(CONFIGURATION_PANEL) != null) mConfigurationPanel = (String) attributes.getValue(CONFIGURATION_PANEL); if (attributes.getValue(TAGS) != null) mTags = (String) attributes.getValue(TAGS); } if (mTitle == null) { mTitle = jar.getName().substring(0, jar.getName().indexOf('.')); } } catch (Exception ex) { Tools.logException(AppDescriptor.class, ex, "Cannot get descriptor: " + jar.getAbsolutePath()); } finally { if (in != null) { try { in.close(); in = null; } catch (Exception ex) { } } } break; } } zipFile.close(); }
From source file:gov.redhawk.rap.internal.PluginProviderServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final Path path = new Path(req.getRequestURI()); String pluginId = path.lastSegment(); if (pluginId.endsWith(".jar")) { pluginId = pluginId.substring(0, pluginId.length() - 4); }/*w ww. ja v a 2 s. co m*/ final Bundle b = Platform.getBundle(pluginId); if (b == null) { final String protocol = req.getProtocol(); final String msg = "Plugin does not exist: " + pluginId; if (protocol.endsWith("1.1")) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); } return; } final File file = FileLocator.getBundleFile(b); resp.setContentType("application/octet-stream"); if (file.isFile()) { final String contentDisposition = "attachment; filename=\"" + file.getName() + "\""; resp.setHeader("Content-Disposition", contentDisposition); resp.setContentLength((int) file.length()); final FileInputStream istream = new FileInputStream(file); try { IOUtils.copy(istream, resp.getOutputStream()); } finally { istream.close(); } resp.flushBuffer(); } else { final String contentDisposition = "attachment; filename=\"" + file.getName() + ".jar\""; resp.setHeader("Content-Disposition", contentDisposition); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final Manifest man = new Manifest(new FileInputStream(new File(file, "META-INF/MANIFEST.MF"))); final JarOutputStream out = new JarOutputStream(outputStream, man); final File binDir = new File(file, "bin"); if (binDir.exists()) { addFiles(out, Path.ROOT, binDir.listFiles()); for (final File f : file.listFiles()) { if (!f.getName().equals("bin")) { addFiles(out, Path.ROOT, f); } } } else { addFiles(out, Path.ROOT, file.listFiles()); } out.close(); outputStream.close(); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); resp.setContentLength(outputStream.size()); try { IOUtils.copy(inputStream, resp.getOutputStream()); } finally { inputStream.close(); } resp.flushBuffer(); } }
From source file:com.tesora.dve.common.PELogUtils.java
private static Attributes readManifestFile() throws PEException { try {/*from ww w.ja v a2 s .c o m*/ Enumeration<URL> resources = PELogUtils.class.getClassLoader().getResources(MANIFEST_FILE_NAME); Attributes attrs = new Attributes(); while (resources.hasMoreElements()) { URL url = resources.nextElement(); if (url.toString().contains(CORE_PROJECT_NAME)) { Manifest manifest = new Manifest(url.openStream()); attrs = manifest.getMainAttributes(); break; } } return attrs; } catch (Exception e) { throw new PEException("Error retrieving build manifest", e); } }
From source file:org.jenkinsci.plugins.pipeline.utility.steps.conf.mf.ReadManifestStepExecution.java
private SimpleManifest parseText(String text) throws IOException { Manifest manifest = new Manifest(new ByteArrayInputStream(text.getBytes("UTF-8"))); return new SimpleManifest(manifest); }
From source file:org.apache.sling.maven.slingstart.PackageMojo.java
private void packageStandaloneApp(final Map<String, File> globalContentsMap) throws MojoExecutionException { this.getLog().info("Packaging standalone jar..."); final File buildDirectory = new File(this.project.getBuild().getDirectory()); @SuppressWarnings("unchecked") final Map<String, File> contentsMap = (Map<String, File>) this.project .getContextValue(BuildConstants.CONTEXT_STANDALONE); final File buildOutputDirectory = this.getStandaloneOutputDirectory(); final File manifestFile = new File(buildOutputDirectory, "META-INF/MANIFEST.MF"); FileInputStream fis = null;/*from w ww .j ava2 s . c om*/ try { fis = new FileInputStream(manifestFile); final Manifest mf = new Manifest(fis); final File outputFile = new File(buildDirectory, this.project.getArtifactId() + "-" + this.project.getVersion() + ".jar"); final JarArchiverHelper helper = new JarArchiverHelper(jarArchiver, this.project, outputFile, mf); helper.addDirectory(buildOutputDirectory, null, EXCLUDES_MANIFEST); helper.addArtifacts(globalContentsMap, ""); helper.addArtifacts(contentsMap, ""); helper.createArchive(); if (BuildConstants.PACKAGING_SLINGSTART.equals(project.getPackaging())) { project.getArtifact().setFile(outputFile); } else { projectHelper.attachArtifact(project, BuildConstants.TYPE_JAR, BuildConstants.CLASSIFIER_APP, outputFile); } } catch (final IOException ioe) { throw new MojoExecutionException("Unable to create standalone jar", ioe); } finally { IOUtils.closeQuietly(fis); } }
From source file:ubicrypt.UbiCrypt.java
public static String getVersion() { String version = null;// ww w.j a v a 2 s . co m // try to load from maven properties first try { try (final InputStream is = UbiCrypt.class.getResourceAsStream("META-INF/MANIFEST.MF")) { if (is != null) { Manifest manifest = new Manifest(is); version = manifest.getMainAttributes().getValue("Implementation-Version"); } } } catch (final Exception e) { // ignore } // fallback to using Java API if (version == null) { final Package aPackage = UbiCrypt.class.getPackage(); if (aPackage != null) { version = aPackage.getImplementationVersion(); if (version == null) { version = aPackage.getSpecificationVersion(); } } } if (version == null) { // we could not compute the version so use a blank version = ""; } return version; }
From source file:org.apache.sling.scripting.sightly.impl.engine.SightlyEngineConfiguration.java
protected void activate(ComponentContext componentContext) { InputStream ins = null;//from w ww .ja v a2s . c o m try { ins = getClass().getResourceAsStream("/META-INF/MANIFEST.MF"); if (ins != null) { Manifest manifest = new Manifest(ins); Attributes attrs = manifest.getMainAttributes(); String version = attrs.getValue("ScriptEngine-Version"); if (version != null) { engineVersion = version; } String symbolicName = attrs.getValue("Bundle-SymbolicName"); if (StringUtils.isNotEmpty(symbolicName)) { bundleSymbolicName = symbolicName; } } } catch (IOException ioe) { } finally { if (ins != null) { try { ins.close(); } catch (IOException ignore) { } } } Dictionary properties = componentContext.getProperties(); keepGenerated = PropertiesUtil.toBoolean(properties.get(SCR_PROP_NAME_KEEPGENERATED), SCR_PROP_DEFAULT_KEEPGENERATED); }