List of usage examples for java.util.jar Manifest getMainAttributes
public Attributes getMainAttributes()
From source file:org.energyos.espi.datacustodian.web.VersionRESTController.java
/** * Handling GET request to retrieve details from MANIFEST.MF file * //from w w w . j a v a 2 s .co m * @return implementation details */ @RequestMapping(value = "/about-version", method = RequestMethod.GET) public String getBuildNumber(HttpServletRequest request, ModelMap model) throws IOException { ServletContext context = request.getSession().getServletContext(); InputStream manifestStream = context.getResourceAsStream("/META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(manifestStream); Map<String, String> aboutInfo = new HashMap<>(); aboutInfo.put("Implementation-Vendor", manifest.getMainAttributes().getValue("Implementation-Vendor")); aboutInfo.put("Implementation-Title", manifest.getMainAttributes().getValue("Implementation-Title")); aboutInfo.put("Implementation-Version", manifest.getMainAttributes().getValue("Implementation-Version")); aboutInfo.put("Implementation-Jdk", manifest.getMainAttributes().getValue("Build-Jdk")); aboutInfo.put("Implementation-Build", manifest.getMainAttributes().getValue("Implementation-Build")); aboutInfo.put("Implementation-Build-Time", manifest.getMainAttributes().getValue("Implementation-Build-Time")); model.put("aboutInfo", aboutInfo); return "/about"; }
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 . jav a2s . c om { 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.springframework.boot.ManifestReader.java
public Map<String, String> getVersions() { Map<String, String> result = new TreeMap<String, String>(); try {//from ww w .j a v a 2s .co m Enumeration<URL> resources = getClass().getClassLoader().getResources(META_INF_MANIFEST_MF); while (resources.hasMoreElements()) { String urlName = null; try { URL url = resources.nextElement(); urlName = url.toString(); if (!urlName.contains("org/springframework/")) { continue; } if (urlName.contains("org/springframework/boot/")) { // skipping since starter versions are usually same (as SpringBoot) continue; } Manifest manifest = new Manifest(url.openStream()); String title = manifest.getMainAttributes().getValue(IMPLEMENTATION_TITLE); if (title == null) { title = parseLibraryNameFromUrl(urlName); if (title == null) { // when version is not even in the URL if (log.isTraceEnabled()) { log.trace(String.format("Version is not parsable from this URL: ", urlName)); } continue; } result.put(title, title); } else { String version = manifest.getMainAttributes().getValue(IMPLEMENTATION_VERSION); result.put(title, String.format("%s %s", title, getValue(version))); } } catch (IOException ioEx) { log.warn(String.format("Manifest is not readable (%s)!", urlName)); } } } catch (IOException ex) { log.error("MANIFEST.MF reading error: " + ex.getMessage()); return result; } return result; }
From source file:org.apache.cxf.dosgi.systests.common.AbstractDosgiSystemTest.java
protected Manifest getManifest() { // let the testing framework create/load the manifest Manifest mf = super.getManifest(); String importP = mf.getMainAttributes().getValue(Constants.IMPORT_PACKAGE); mf.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, importP); mf.getMainAttributes().putValue(Constants.DYNAMICIMPORT_PACKAGE, "*"); return mf;// ww w . jav a2 s.c o m }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.Main.java
/** * Read version from jar manifest, if it fails the exception is swallow and * empty string is returned// ww w. j a v a2 s. com */ private String getImplementationVersion() { try { URLClassLoader cl = (URLClassLoader) Main.class.getClassLoader(); URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); Attributes mainAttribs = manifest.getMainAttributes(); String version = mainAttribs.getValue("Implementation-Version"); if (version != null) { return version; } } catch (Exception e) { logger.trace("Unable to read a manifest version of this program.", e); } return "X.X.X.X"; }
From source file:org.cleverbus.core.common.version.impl.ManifestVersionInfoSource.java
private VersionInfo createVersionInfo(Manifest manifest) { Attributes attrs = manifest.getMainAttributes(); return new VersionInfo(getTitle(attrs), getVendorId(attrs), getVersion(attrs), attrs.getValue(ATTR_REVISION), attrs.getValue(ATTR_TIMESTAMP)); }
From source file:com.ikanow.aleph2.analytics.spark.services.SparkCompilerService.java
/** Compiles a scala class * @param script/*from w w w. ja va2 s . com*/ * @param clazz_name * @return * @throws IOException * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException */ public Tuple2<ClassLoader, Object> buildClass(final String script, final String clazz_name, final Optional<IBucketLogger> logger) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { final String relative_dir = "./script_classpath/"; new File(relative_dir).mkdirs(); final File source_file = new File(relative_dir + clazz_name + ".scala"); FileUtils.writeStringToFile(source_file, script); final String this_path = LiveInjector.findPathJar(this.getClass(), "./dummy.jar"); final File f = new File(this_path); final File fp = new File(f.getParent()); final String classpath = Arrays.stream(fp.listFiles()).map(ff -> ff.toString()) .filter(ff -> ff.endsWith(".jar")).collect(Collectors.joining(":")); // Need this to make the URL classloader be used, not the system classloader (which doesn't know about Aleph2..) final Settings s = new Settings(); s.classpath().value_$eq(System.getProperty("java.class.path") + classpath); s.usejavacp().scala$tools$nsc$settings$AbsSettings$AbsSetting$$internalSetting_$eq(true); final StoreReporter reporter = new StoreReporter(); final Global g = new Global(s, reporter); final Run r = g.new Run(); r.compile(JavaConverters.asScalaBufferConverter(Arrays.<String>asList(source_file.toString())).asScala() .toList()); if (reporter.hasErrors() || reporter.hasWarnings()) { final String errors = "Compiler: Errors/warnings (**to get to user script line substract 22**): " + JavaConverters.asJavaSetConverter(reporter.infos()).asJava().stream() .map(info -> info.toString()).collect(Collectors.joining(" ;; ")); logger.ifPresent(l -> l.log(reporter.hasErrors() ? Level.ERROR : Level.DEBUG, false, () -> errors, () -> "SparkScalaInterpreterTopology", () -> "compile")); //ERROR: if (reporter.hasErrors()) { System.err.println(errors); } } // Move any class files (eg including sub-classes) Arrays.stream(fp.listFiles()).filter(ff -> ff.toString().endsWith(".class")) .forEach(Lambdas.wrap_consumer_u(ff -> { FileUtils.moveFile(ff, new File(relative_dir + ff.getName())); })); // Create a JAR file... Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); final JarOutputStream target = new JarOutputStream(new FileOutputStream("./script_classpath.jar"), manifest); Arrays.stream(new File(relative_dir).listFiles()).forEach(Lambdas.wrap_consumer_i(ff -> { JarEntry entry = new JarEntry(ff.getName()); target.putNextEntry(entry); try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(ff))) { byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) break; target.write(buffer, 0, count); } target.closeEntry(); } })); target.close(); final String created = "Created = " + new File("./script_classpath.jar").toURI().toURL() + " ... " + Arrays.stream(new File(relative_dir).listFiles()).map(ff -> ff.toString()) .collect(Collectors.joining(";")); logger.ifPresent(l -> l.log(Level.DEBUG, true, () -> created, () -> "SparkScalaInterpreterTopology", () -> "compile")); final Tuple2<ClassLoader, Object> o = Lambdas.get(Lambdas.wrap_u(() -> { _cl.set(new java.net.URLClassLoader( Arrays.asList(new File("./script_classpath.jar").toURI().toURL()).toArray(new URL[0]), Thread.currentThread().getContextClassLoader())); Object o_ = _cl.get().loadClass("ScriptRunner").newInstance(); return Tuples._2T(_cl.get(), o_); })); return o; }
From source file:com.kaylerrenslow.armaDialogCreator.updater.tasks.AdcVersionCheckTask.java
private String getCurrentJarVersion() throws Exception { setStatusText("Updater.getting_current_version"); if (!adcJarSave.exists()) { return ""; }/*from w ww . java 2s . com*/ Manifest m = new JarFile(adcJarSave).getManifest(); Attributes manifestAttributes = m.getMainAttributes(); return manifestAttributes.getValue("Specification-Version"); }
From source file:interactivespaces.resource.analysis.OsgiResourceAnalyzer.java
@Override public NamedVersionedResourceCollection<NamedVersionedResourceWithData<String>> getResourceCollection( File baseDir) {//from w w w .j av a 2 s . co m NamedVersionedResourceCollection<NamedVersionedResourceWithData<String>> resources = NamedVersionedResourceCollection .newNamedVersionedResourceCollection(); File[] files = baseDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(".jar"); } }); if (files != null) { for (File file : files) { JarFile jarFile = null; try { jarFile = new JarFile(file); Manifest manifest = jarFile.getManifest(); Attributes attributes = manifest.getMainAttributes(); String name = attributes.getValue(OSGI_HEADER_SYMBOLIC_NAME); String version = attributes.getValue(OSGI_HEADER_VERSION); if (name != null && version != null) { NamedVersionedResourceWithData<String> resource = new NamedVersionedResourceWithData<String>( name, Version.parseVersion(version), file.getAbsolutePath()); resources.addResource(resource.getName(), resource.getVersion(), resource); } else { log.warn(String.format( "Resource %s is not a proper OSGi bundle (missing symbolic name and/or version) and is being ignored.", file.getAbsolutePath())); } } catch (IOException e) { log.error(String.format("Could not open resource file jar manifest for %s", file.getAbsolutePath()), e); } finally { // For some reason Closeables does not work with JarFile despite it // claiming it is Closeable in the Javadoc. if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { // Don't care. } } } } } return resources; }
From source file:net.hillsdon.reviki.wiki.plugin.PluginClassLoader.java
public PluginClassLoader(final URL jarUrl, final ClassLoader parent) throws InvalidPluginException { super(new URL[] { jarUrl }, parent); InputStream manifestInputStream = null; try {/*w w w . j a va2s . c o m*/ final URL manifestUrl = getManifestURL(jarUrl); try { manifestInputStream = manifestUrl.openStream(); } catch (IOException ex) { throw new InvalidPluginException("Could not open META-INF/MANIFEST.MF in plugin jar."); } final Manifest manifest = new Manifest(manifestInputStream); final Attributes attrs = manifest.getMainAttributes(); String classPath = attrs.getValue("Class-Path"); if (classPath != null && classPath.length() > 0) { cacheClassPathEntries(jarUrl, classPath); } String pluginContributions = attrs.getValue("Plugin-Contributions"); if (pluginContributions != null && pluginContributions.length() > 0) { _contributedClasses = unmodifiableList(loadPluginContributionClasses(pluginContributions)); } else { _contributedClasses = Collections.emptyList(); } } catch (URISyntaxException ex) { throw new InvalidPluginException(ex); } catch (IOException ex) { throw new InvalidPluginException(ex); } catch (ClassNotFoundException ex) { throw new InvalidPluginException(ex); } finally { IOUtils.closeQuietly(manifestInputStream); } }