List of usage examples for java.util.jar Manifest Manifest
public Manifest(Manifest man)
From source file:UnpackedJarFile.java
public Manifest getManifest() throws IOException { if (!manifestLoaded) { File manifestFile = getFile("META-INF/MANIFEST.MF"); if (manifestFile != null && manifestFile.isFile()) { FileInputStream in = null; try { in = new FileInputStream(manifestFile); manifest = new Manifest(in); } finally { if (in != null) { try { in.close();/*from www . j ava 2 s. c o m*/ } catch (IOException e) { // ignore } } } } manifestLoaded = true; } return manifest; }
From source file:org.gatein.integration.jboss.as7.deployment.PortletBridgeDependencyProcessor.java
private static String getPortletBridgeVersion() { try {/* w w w . j ava 2 s . co m*/ Module module = Module.getBootModuleLoader().loadModule(PORTLETBRIDGE_IMPL); Manifest mf = new Manifest(module.getClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF")); return mf.getMainAttributes().getValue("Implementation-Version"); } catch (Exception e) { return ""; } }
From source file:com.obergner.hzserver.ServerInfo.java
private Manifest loadServerManifest() throws MalformedURLException, IOException { final Class<?> clazz = getClass(); final String className = clazz.getSimpleName() + ".class"; final String classPath = clazz.getResource(className).toString(); if (!classPath.startsWith("jar")) { // Class not from JAR -> probably running in a unit test context return new Manifest(getClass().getClassLoader().getResourceAsStream("META-INF/MANIFEST.MF")); }/* w ww . ja va 2 s . c om*/ final String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; return new Manifest(new URL(manifestPath).openStream()); }
From source file:org.sonar.batch.internal.PluginsManager.java
private void unzip(File file, String name) throws Exception { File toDir = new File(workDir, name); ZipUtils.unzip(file, toDir);//from w w w. j a v a2 s .c o m File manifestFile = new File(toDir, "META-INF/MANIFEST.MF"); InputStream manifestStream = FileUtils.openInputStream(manifestFile); manifests.put(manifestFile, new Manifest(manifestStream)); IOUtils.closeQuietly(manifestStream); }
From source file:ch.ivyteam.ivy.maven.util.ClasspathJar.java
public String getClasspathUrlEntries() { try (ZipInputStream is = new ZipInputStream(new FileInputStream(jar))) { Manifest manifest = new Manifest(getInputStream(is, MANIFEST_MF)); return manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH); } catch (IOException ex) { return null; }/*from w w w .j a v a 2 s .c o m*/ }
From source file:org.onehippo.repository.bootstrap.Extension.java
String getModuleVersion() { String extensionURLString = extensionURL.toString(); if (extensionURLString.contains(EXTENSION_FILE_NAME)) { String manifestUrlString = StringUtils.substringBefore(extensionURLString, EXTENSION_FILE_NAME) + "META-INF/MANIFEST.MF"; try {//from w w w . ja v a 2 s .c om final Manifest manifest = new Manifest(new URL(manifestUrlString).openStream()); return manifest.getMainAttributes().getValue(new Attributes.Name("Implementation-Build")); } catch (IOException ignore) { } } return null; }
From source file:com.npower.dm.msm.JADCreator.java
public Manifest getJADManufest(File file, String jarURL) throws IOException { //JarInputStream jarIn = new JarInputStream(in); JarFile jar = new JarFile(file); Manifest srcManifest = jar.getManifest(); /*// w ww . j a v a 2s.c o m { Attributes attrs = srcManifest.getMainAttributes(); for (Object akey: attrs.keySet()) { Object ov = attrs.get(akey); System.out.println(akey + ": " + ov); } } */ Manifest manifest = new Manifest(srcManifest); manifest.getMainAttributes().put(new Attributes.Name("MIDlet-Jar-URL"), jarURL); manifest.getMainAttributes().put(new Attributes.Name("MIDlet-Jar-Size"), Long.toString(file.length())); return manifest; }
From source file:org.lamport.tla.toolbox.jcloud.PayloadHelper.java
public static Payload appendModel2Jar(final Path modelPath, String mainClass, Properties properties, IProgressMonitor monitor) throws IOException { /*// ww w . j a v a2 s . co m * Get the standard tla2tools.jar from the classpath as a blueprint. * It's located in the org.lamport.tla.toolbox.jclouds bundle in the * files/ directory. It uses OSGi functionality to read files/tla2tools.jar * from the .jclouds bundle. * The copy of the blueprint will contain the spec & model and * additional metadata (properties, amended manifest). */ final Bundle bundle = FrameworkUtil.getBundle(PayloadHelper.class); final URL toolsURL = bundle.getEntry("files/tla2tools.jar"); if (toolsURL == null) { throw new RuntimeException("No tlatools.jar and/or spec to deploy"); } /* * Copy the tla2tools.jar blueprint to a temporary location on * disk to append model files below. */ final File tempFile = File.createTempFile("tla2tools", ".jar"); tempFile.deleteOnExit(); try (FileOutputStream out = new FileOutputStream(tempFile)) { IOUtils.copy(toolsURL.openStream(), out); } /* * Create a virtual filesystem in jar format. */ final Map<String, String> env = new HashMap<>(); env.put("create", "true"); final URI uri = URI.create("jar:" + tempFile.toURI()); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { /* * Copy the spec and model into the jar's model/ folder. * Also copy any module override (.class file) into the jar. */ try (DirectoryStream<Path> modelDirectoryStream = Files.newDirectoryStream(modelPath, "*.{cfg,tla,class}")) { for (final Path file : modelDirectoryStream) { final Path to = fs.getPath("/model/" + file.getFileName()); Files.copy(file, to, StandardCopyOption.REPLACE_EXISTING); } } /* * Add given class as Main-Class statement to jar's manifest. This * causes Java to launch this class when no other Main class is * given on the command line. Thus, it shortens the command line * for us. */ final Path manifestPath = fs.getPath("/META-INF/", "MANIFEST.MF"); final Manifest manifest = new Manifest(Files.newInputStream(manifestPath)); manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, mainClass); final PipedOutputStream ps = new PipedOutputStream(); final PipedInputStream is = new PipedInputStream(ps); manifest.write(ps); ps.close(); Files.copy(is, manifestPath, StandardCopyOption.REPLACE_EXISTING); /* * Add properties file to archive. The property file contains the * result email address... from where TLC eventually reads it. */ // On Windows 7 and above the file has to be created in the system's // temp folder. Otherwise except file creation to fail with a // AccessDeniedException final File f = File.createTempFile("generated", "properties"); OutputStream out = new FileOutputStream(f); // Append all entries in "properties" to the temp file f properties.store(out, "This is an optional header comment string"); // Copy the temp file f into the jar with path /model/generated.properties. final Path to = fs.getPath("/model/generated.properties"); Files.copy(f.toPath(), to, StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e1) { throw new RuntimeException("No model directory found to deploy", e1); } /* * Compress archive with pack200 to achieve a much higher compression rate. We * are going to send the file on the wire after all: * * effort: take more time choosing codings for better compression segment: use * largest-possible archive segments (>10% better compression) mod time: smear * modification times to a single value deflate: ignore all JAR deflation hints * in original archive */ final Packer packer = Pack200.newPacker(); final Map<String, String> p = packer.properties(); p.put(Packer.EFFORT, "9"); p.put(Packer.SEGMENT_LIMIT, "-1"); p.put(Packer.MODIFICATION_TIME, Packer.LATEST); p.put(Packer.DEFLATE_HINT, Packer.FALSE); // Do not reorder which changes package names. Pkg name changes e.g. break // SimpleFilenameToStream. p.put(Packer.KEEP_FILE_ORDER, Packer.TRUE); // Throw an error if any of the above attributes is unrecognized. p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR); final File packTempFile = File.createTempFile("tla2tools", ".pack.gz"); try (final JarFile jarFile = new JarFile(tempFile); final GZIPOutputStream fos = new GZIPOutputStream(new FileOutputStream(packTempFile));) { packer.pack(jarFile, fos); } catch (IOException ioe) { throw new RuntimeException("Failed to pack200 the tla2tools.jar file", ioe); } /* * Convert the customized tla2tools.jar into a jClouds payload object. This is * the format it will be transfered on the wire. This is handled by jClouds * though. */ Payload jarPayLoad = null; try { final InputStream openStream = new FileInputStream(packTempFile); jarPayLoad = Payloads.newInputStreamPayload(openStream); // manually set length of content to prevent a NPE bug jarPayLoad.getContentMetadata().setContentLength(Long.valueOf(openStream.available())); } catch (final IOException e1) { throw new RuntimeException("No tlatools.jar to deploy", e1); } finally { monitor.worked(5); } return jarPayLoad; }
From source file:org.thiesen.ant.git.ExtractGitInfo.java
private String loadVersion() { try {//from www . j a v a 2s .c o m final Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { final Manifest manifest = new Manifest(resources.nextElement().openStream()); final Attributes mainAttributes = manifest.getMainAttributes(); if ("gitant".equalsIgnoreCase(mainAttributes.getValue("Project-Name"))) { return mainAttributes.getValue("Project-Version"); } } } catch (final IOException E) { // do nothing } return "unknown version"; }
From source file:org.jenkinsci.plugins.pipeline.utility.steps.conf.mf.ReadManifestStepExecution.java
private SimpleManifest parseFile(String file) throws IOException, InterruptedException { FilePath path = ws.child(file);//from w w w . jav a 2 s. c o m if (!path.exists()) { throw new FileNotFoundException(path.getRemote() + " does not exist."); } else if (path.isDirectory()) { throw new FileNotFoundException(path.getRemote() + " is a directory."); } String lcName = path.getName().toLowerCase(); if (lcName.endsWith(".jar") || lcName.endsWith(".war") || lcName.endsWith(".ear")) { Map<String, String> mf = path .act(new UnZipStepExecution.UnZipFileCallable(listener, ws, "META-INF/MANIFEST.MF", true)); String text = mf.get("META-INF/MANIFEST.MF"); if (isBlank(text)) { throw new FileNotFoundException(path.getRemote() + " does not seem to contain a manifest."); } else { return parseText(text); } } else { Manifest manifest = new Manifest(path.read()); return new SimpleManifest(manifest); } }