List of usage examples for java.util.jar Attributes getValue
public String getValue(Name name)
From source file:org.kepler.kar.KARFile.java
public String getVersion() { try {//ww w. j a v a 2 s. c o m Attributes atts = getManifest().getMainAttributes(); String karVersion = atts.getValue(KAR_VERSION); return karVersion; } catch (IOException e) { return null; } }
From source file:org.kepler.kar.KARFile.java
public boolean isOpenable() { try {/*w w w .j a v a2s. c o m*/ Attributes atts = getManifest().getMainAttributes(); String openable = atts.getValue(OPENABLE); if (openable != null) { openable = openable.trim(); if (openable.equalsIgnoreCase("false")) { return false; } } } catch (IOException e) { e.printStackTrace(); } Vector<String> moduleDependencies = getModuleDependencies(); if (ModuleDependencyUtil.checkIfModuleDependenciesSatisfied(moduleDependencies)) { return true; } return false; }
From source file:com.aimluck.eip.project.ProjectTaskSelectData.java
/** * ????//w w w . j ava2 s. c o m * * @param crt * @return */ protected String getOrderBy(RunData rundata, Context context) { String sort = ALEipUtils.getTemp(rundata, context, LIST_SORT_STR); String sort_type = ALEipUtils.getTemp(rundata, context, LIST_SORT_TYPE_STR); String crt_key = null; Attributes map = getColumnMap(); if (sort != null && sort.length() > 0) { crt_key = map.getValue(sort); } current_sort = sort; current_sort_type = sort_type; if (crt_key != null && crt_key.length() > 0) { // ? indentFlg = false; if (sort_type != null && ALEipConstants.LIST_SORT_TYPE_DESC.equals(sort_type)) { return " ORDER BY " + crt_key + " DESC"; } else { return " ORDER BY " + crt_key; } } else { return " ORDER BY order_no"; } }
From source file:org.kepler.kar.KARFile.java
/** * Read the type attribute from the given entry and return it as a string. * /*from w ww . j a va 2 s .com*/ * @param entry * @return * @throws IOException */ private String getEntryType(JarEntry entry) throws IOException { Attributes atts = entry.getAttributes(); if (atts == null) { return null; } String type = atts.getValue(KAREntry.TYPE); return type; }
From source file:org.kepler.kar.KARFile.java
/** * Read the LSID from the attributes of the given entry and return it as a * KeplerLSID.//from w w w . j a va 2 s .c o m * * @param entry * @return * @throws IOException */ private KeplerLSID getEntryLSID(JarEntry entry) throws IOException { Attributes atts = entry.getAttributes(); if (atts == null) { return null; } String lsidStr = atts.getValue(KAREntry.LSID); if (lsidStr == null) { log.error("KAREntries must have an LSID and a type."); return null; } KeplerLSID lsid = null; try { lsid = new KeplerLSID(lsidStr); } catch (Exception e) { log.warn(lsidStr + " is not a properly formatted KeplerLSID"); return null; } return lsid; }
From source file:dalma.container.ClassLoaderImpl.java
/** * Define the package information when the class comes from a * jar with a manifest/* w w w . ja v a 2s . c om*/ * * @param container the jar file containing the manifest * @param packageName the name of the package being defined. * @param manifest the jar's manifest */ protected void definePackage(File container, String packageName, Manifest manifest) { String sectionName = packageName.replace('.', '/') + "/"; String specificationTitle = null; String specificationVendor = null; String specificationVersion = null; String implementationTitle = null; String implementationVendor = null; String implementationVersion = null; String sealedString = null; URL sealBase = null; Attributes sectionAttributes = manifest.getAttributes(sectionName); if (sectionAttributes != null) { specificationTitle = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE); specificationVendor = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR); specificationVersion = sectionAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION); implementationTitle = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE); implementationVendor = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); implementationVersion = sectionAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); sealedString = sectionAttributes.getValue(Attributes.Name.SEALED); } Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes != null) { if (specificationTitle == null) { specificationTitle = mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE); } if (specificationVendor == null) { specificationVendor = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VENDOR); } if (specificationVersion == null) { specificationVersion = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION); } if (implementationTitle == null) { implementationTitle = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE); } if (implementationVendor == null) { implementationVendor = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); } if (implementationVersion == null) { implementationVersion = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); } if (sealedString == null) { sealedString = mainAttributes.getValue(Attributes.Name.SEALED); } } if (sealedString != null && sealedString.equalsIgnoreCase("true")) { try { sealBase = new URL("file:" + container.getPath()); } catch (MalformedURLException e) { // ignore } } definePackage(packageName, specificationTitle, specificationVersion, specificationVendor, implementationTitle, implementationVersion, implementationVendor, sealBase); }
From source file:org.jahia.utils.maven.plugin.osgi.DependenciesMojo.java
private boolean processJarManifest(File jarFile, ParsingContext parsingContext, JarInputStream jarInputStream) throws IOException { boolean processedBundleHeadersSuccessfully = false; Manifest jarManifest = jarInputStream.getManifest(); if (jarManifest != null && jarManifest.getMainAttributes() != null) { Attributes mainAttributes = jarManifest.getMainAttributes(); String bundleSymbolicName = mainAttributes.getValue("Bundle-SymbolicName"); if (bundleSymbolicName != null) { String bundleVersion = mainAttributes.getValue("Bundle-Version"); String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath"); if (bundleClassPath != null && !".".equals(bundleClassPath.trim())) { String[] bundleClassPathEntries = bundleClassPath.split(","); for (String bundleClassPathEntry : bundleClassPathEntries) { parsingContext.getBundleClassPath().add(bundleClassPathEntry.trim()); }/*from w ww . j a va 2 s .c om*/ } getLog().debug("OSGi bundle detected with symbolic name=" + bundleSymbolicName + " version=" + bundleVersion); parsingContext.setOsgiBundle(true); parsingContext.setVersion(bundleVersion); String importPackageHeaderValue = mainAttributes.getValue("Import-Package"); String exportPackageHeaderValue = mainAttributes.getValue("Export-Package"); String ignorePackageHeaderValue = mainAttributes.getValue("Ignore-Package"); if (importPackageHeaderValue != null) { List<ManifestValueClause> importPackageClauses = BundleUtils.getHeaderClauses("Import-Package", importPackageHeaderValue); for (ManifestValueClause importPackageClause : importPackageClauses) { for (String importPackagePath : importPackageClause.getPaths()) { String clauseVersion = importPackageClause.getAttributes().get("version"); String clauseResolution = importPackageClause.getDirectives().get("resolution"); boolean optionalClause = false; if ("optional".equals(clauseResolution)) { optionalClause = true; } PackageInfo importPackageInfo = new PackageInfo(importPackagePath, clauseVersion, optionalClause, jarFile.getPath(), parsingContext); parsingContext.addPackageImport(importPackageInfo); } } } if (exportPackageHeaderValue != null) { List<ManifestValueClause> exportPackageClauses = BundleUtils.getHeaderClauses("Export-Package", exportPackageHeaderValue); for (ManifestValueClause exportPackageClause : exportPackageClauses) { for (String importPackagePath : exportPackageClause.getPaths()) { String clauseVersion = exportPackageClause.getAttributes().get("version"); PackageInfo exportPackageInfo = new PackageInfo(importPackagePath, clauseVersion, false, jarFile.getPath(), parsingContext); parsingContext.addPackageExport(exportPackageInfo); } } } if (ignorePackageHeaderValue != null) { List<ManifestValueClause> ignorePackageClauses = BundleUtils.getHeaderClauses("Ignore-Package", ignorePackageHeaderValue); for (ManifestValueClause ignorePackageClause : ignorePackageClauses) { for (String importPackagePath : ignorePackageClause.getPaths()) { String clauseVersion = ignorePackageClause.getAttributes().get("version"); boolean optionalClause = true; PackageInfo ignorePackageInfo = new PackageInfo(importPackagePath, clauseVersion, optionalClause, jarFile.getPath(), parsingContext); parsingContext.addPackageImport(ignorePackageInfo); } } } processedBundleHeadersSuccessfully = true; } } return processedBundleHeadersSuccessfully; }
From source file:org.jahia.modules.modulemanager.flow.ModuleManagementFlowHandler.java
private void handlePackage(JarFile jarFile, Attributes manifestAttributes, String originalFilename, boolean forceUpdate, boolean autoStart, MessageContext context) throws IOException, BundleException { // check package name validity String jahiaPackageName = manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_PACKAGE_NAME); if (jahiaPackageName != null && jahiaPackageName.trim().length() == 0) { context.addMessage(new MessageBuilder().source("moduleFile") .code("serverSettings.manageModules.install.package.name.error").error().build()); return;//from w w w . j a va 2 s . c o m } //Check license String licenseFeature = manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_PACKAGE_LICENSE); if (licenseFeature != null && !LicenseCheckerService.Stub.isAllowed(licenseFeature)) { context.addMessage(new MessageBuilder().source("moduleFile") .code("serverSettings.manageModules.install.package.missing.license") .args(originalFilename, licenseFeature).build()); return; } ModulesPackage pack = ModulesPackage.create(jarFile); try { List<String> providedBundles = new ArrayList<String>(pack.getModules().keySet()); Map<Bundle, MessageResolver> collectedResolutionErrors = new LinkedHashMap<>(); List<ModuleInstallationResult> installationResults = new LinkedList<>(); for (ModulesPackage.PackagedModule entry : pack.getModules().values()) { ModuleInstallationResult installationResult = installModule(entry.getModuleFile(), context, providedBundles, collectedResolutionErrors, forceUpdate, autoStart); if (installationResult != null) { installationResults.add(installationResult); } } if (!collectedResolutionErrors.isEmpty()) { // double-check the resolution issues after all bundles were installed for (Iterator<Map.Entry<Bundle, MessageResolver>> resolutionErrorIterator = collectedResolutionErrors .entrySet().iterator(); resolutionErrorIterator.hasNext();) { Entry<Bundle, MessageResolver> resolutionErrorEntry = resolutionErrorIterator.next(); if (resolutionErrorEntry.getKey().getState() >= Bundle.RESOLVED) { // the bundle is successfully resolved now resolutionErrorIterator.remove(); } else { // the bundle still has resolution issue -> add error message context.addMessage(resolutionErrorEntry.getValue()); } } } // add info about installed bundles for (ModuleInstallationResult installationResult : installationResults) { if (!collectedResolutionErrors.containsKey(installationResult)) { addModuleInstallationMessage(installationResult, context); } } } finally { // delete temporary created files of the package for (ModulesPackage.PackagedModule entry : pack.getModules().values()) { FileUtils.deleteQuietly(entry.getModuleFile()); } } }
From source file:com.izforge.izpack.installer.unpacker.UnpackerBase.java
private void logIntro() { final String startMessage = messages.get("installer.started"); char[] chars = new char[startMessage.length()]; Arrays.fill(chars, '='); logger.info(new String(chars)); logger.info(startMessage);/*w w w . j a v a2s . co m*/ URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); InputStream is = null; try { URL url = cl.findResource("META-INF/MANIFEST.MF"); is = url.openStream(); Manifest manifest = new Manifest(is); Attributes attr = manifest.getMainAttributes(); logger.info(messages.get("installer.version", attr.getValue("Created-By"))); } catch (IOException e) { logger.log(Level.WARNING, "IzPack version not found in manifest", e); } finally { IOUtils.closeQuietly(is); } logger.info(messages.get("installer.platform", matcher.getCurrentPlatform())); }
From source file:hudson.ClassicPluginStrategy.java
@Override public PluginWrapper createPluginWrapper(File archive) throws IOException { final Manifest manifest; URL baseResourceURL = null;/* w w w . j a va2s.co m*/ File expandDir = null; // if .hpi, this is the directory where war is expanded boolean isLinked = isLinked(archive); if (isLinked) { manifest = loadLinkedManifest(archive); } else { if (archive.isDirectory()) {// already expanded expandDir = archive; } else { expandDir = new File(archive.getParentFile(), getBaseName(archive.getName())); explode(archive, expandDir); } File manifestFile = new File(expandDir, PluginWrapper.MANIFEST_FILENAME); if (!manifestFile.exists()) { throw new IOException("Plugin installation failed. No manifest at " + manifestFile); } FileInputStream fin = new FileInputStream(manifestFile); try { manifest = new Manifest(fin); } finally { fin.close(); } } final Attributes atts = manifest.getMainAttributes(); // TODO: define a mechanism to hide classes // String export = manifest.getMainAttributes().getValue("Export"); List<File> paths = new ArrayList<File>(); if (isLinked) { parseClassPath(manifest, archive, paths, "Libraries", ","); parseClassPath(manifest, archive, paths, "Class-Path", " +"); // backward compatibility baseResourceURL = resolve(archive, atts.getValue("Resource-Path")).toURI().toURL(); } else { File classes = new File(expandDir, "WEB-INF/classes"); if (classes.exists()) paths.add(classes); File lib = new File(expandDir, "WEB-INF/lib"); File[] libs = lib.listFiles(JAR_FILTER); if (libs != null) paths.addAll(Arrays.asList(libs)); try { Class pathJDK7 = Class.forName("java.nio.file.Path"); Object toPath = File.class.getMethod("toPath").invoke(expandDir); URI uri = (URI) pathJDK7.getMethod("toUri").invoke(toPath); baseResourceURL = uri.toURL(); } catch (NoSuchMethodException e) { throw new Error(e); } catch (ClassNotFoundException e) { baseResourceURL = expandDir.toURI().toURL(); } catch (InvocationTargetException e) { throw new Error(e); } catch (IllegalAccessException e) { throw new Error(e); } } File disableFile = new File(archive.getPath() + ".disabled"); if (disableFile.exists()) { LOGGER.info("Plugin " + archive.getName() + " is disabled"); } // compute dependencies List<PluginWrapper.Dependency> dependencies = new ArrayList<PluginWrapper.Dependency>(); List<PluginWrapper.Dependency> optionalDependencies = new ArrayList<PluginWrapper.Dependency>(); String v = atts.getValue("Plugin-Dependencies"); if (v != null) { for (String s : v.split(",")) { PluginWrapper.Dependency d = new PluginWrapper.Dependency(s); if (d.optional) { optionalDependencies.add(d); } else { dependencies.add(d); } } } for (DetachedPlugin detached : DETACHED_LIST) detached.fix(atts, optionalDependencies); // Register global classpath mask. This is useful for hiding JavaEE APIs that you might see from the container, // such as database plugin for JPA support. The Mask-Classes attribute is insufficient because those classes // also need to be masked by all the other plugins that depend on the database plugin. String masked = atts.getValue("Global-Mask-Classes"); if (masked != null) { for (String pkg : masked.trim().split("[ \t\r\n]+")) coreClassLoader.add(pkg); } ClassLoader dependencyLoader = new DependencyClassLoader(coreClassLoader, archive, Util.join(dependencies, optionalDependencies)); dependencyLoader = getBaseClassLoader(atts, dependencyLoader); return new PluginWrapper(pluginManager, archive, manifest, baseResourceURL, createClassLoader(paths, dependencyLoader, atts), disableFile, dependencies, optionalDependencies); }