List of usage examples for java.util.jar Manifest Manifest
public Manifest(Manifest man)
From source file:gov.llnl.lc.smt.command.about.SmtAbout.java
protected static ArrayList<SmtAboutRecord> getRecordsFromFile(Object obj, String fileName) { ArrayList<SmtAboutRecord> records = new ArrayList<SmtAboutRecord>(); try {//from w w w . ja va 2s . c o m Enumeration<URL> resources = obj.getClass().getClassLoader().getResources(fileName); while (resources.hasMoreElements()) { Manifest man = new Manifest(resources.nextElement().openStream()); SmtAboutRecord r = new SmtAboutRecord(man); if ((r != null) && r.isValid()) records.add(r); } } catch (IOException E) { // handle } return records; }
From source file:org.eclipse.licensing.eclipse_licensing_plugin.InjectLicensingMojo.java
private void updateManifest() throws IOException { File manifestFile = new File(project.getBasedir(), "META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(new FileInputStream(manifestFile)); String[] requiredBundles = manifest.getMainAttributes().getValue("Require-Bundle").split(","); List<String> requiredList = new ArrayList<String>(Arrays.asList(requiredBundles)); requiredList.remove("org.eclipse.licensing.base"); requiredList.add("org.apache.commons.codec"); requiredList.add("org.eclipse.osgi"); String newRequiredBundles = StringUtils.join(requiredList.toArray(), ","); manifest.getMainAttributes().putValue("Require-Bundle", newRequiredBundles); manifest.write(new FileOutputStream(manifestFile)); }
From source file:org.apache.sling.ide.eclipse.core.internal.BundleStateHelper.java
private static Object doRecalcDecorationState(IServer server, IProject project) { try {//from www . j a v a2 s. c om 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:de.romankreisel.faktotum.FaktotumContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { try (InputStream is = sce.getServletContext() .getResourceAsStream(FaktotumContextListener.RELATIVE_MANIFEST_PATH)) { Manifest manifest = new Manifest(is); Attributes attributes = manifest.getMainAttributes(); String buildTimeString = attributes.getValue("Build-Time"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (StringUtils.isNotBlank(buildTimeString)) { FaktotumContextListener.buildTime = simpleDateFormat.parse(buildTimeString); }/* ww w . j a v a 2s . c om*/ FaktotumContextListener.version = attributes.getValue("Implementation-Version"); this.getLogger().info("Faktotum initialized"); this.getLogger().info("Version: " + FaktotumContextListener.getVersion()); this.getLogger().info("Build-Time: " + simpleDateFormat.format(FaktotumContextListener.getBuildTime())); this.getLogger().fine("Removing old sessions..."); this.authenticationBean.removeOldSessions(); } catch (IOException e) { this.getLogger().log(Level.WARNING, "Error reading build time from manifest", e); } catch (ParseException e) { this.getLogger().log(Level.WARNING, "Error parsing build time from manifest", e); } catch (Exception e) { this.getLogger().log(Level.SEVERE, "Error reading build time", e); throw e; } }
From source file:adalid.util.info.JavaInfo.java
public static void printManifestInfo(String extension, boolean details, File file) throws IOException { // String absolutePath = file.getAbsolutePath(); // String canonicalPath = file.getCanonicalPath(); String path = StringUtils.removeEndIgnoreCase(file.getPath(), FILE_SEP + MANIFEST_NAME); String name = StringUtils.substringAfterLast(path, FILE_SEP); InputStream stream = new FileInputStream(file); Manifest manifest = new Manifest(stream); if (!extensionNameMatches(manifest, extension)) { return;// w w w . j a v a 2 s .c om } // out.println(absolutePath); // out.println(canonicalPath); printManifestInfo(path, name, details, manifest); }
From source file:de.micromata.mgc.application.ManifestMgcApplicationInfo.java
public Manifest findManifest() { try {// w ww. java2s . c om Enumeration<URL> resources = application.getClass().getClassLoader() .getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { try { URL url = resources.nextElement(); Manifest manifest = new Manifest(url.openStream()); // check that this is your manifest and do what you need or get the next one Attributes attrs = manifest.getMainAttributes(); String val = attrs.getValue(MgcAppName); if (StringUtils.isNotBlank(val) == true) { return manifest; } } catch (IOException E) { // handle } } return null; } catch (IOException ex) { return null; } }
From source file:org.gatein.integration.jboss.as7.deployment.PortletBridgeDependencyProcessor.java
private static String getCdiPortletIntegrationVersion() { try {/* w w w .j a v a 2 s.c om*/ Module module = Module.getBootModuleLoader().loadModule(CDI_PORTLET_INTEGRATION); Manifest mf = new Manifest(module.getClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF")); return mf.getMainAttributes().getValue("Implementation-Version"); } catch (Exception e) { return ""; } }
From source file:org.dita.dost.util.DitaUtil.java
public static ILaunch publish(IFile ditaMapFile, String antTargets, String ditavalFileName) throws IOException, CoreException, URISyntaxException { IProject ditaProject = ditaMapFile.getProject(); IFolder ditaFolder = ditaProject.getFolder(new Path("dita")); IFile ditaValFile = ditaFolder.getFile(ditavalFileName); StringBuffer jvmArguments = new StringBuffer(); for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { if (arg.startsWith("-X")) { jvmArguments.append(arg);/*from w w w . j a v a 2 s .c o m*/ jvmArguments.append(" "); } } jvmArguments.append("-Dfile.encoding=UTF-8 "); String[] segments = ditaMapFile.getName().split("\\."); String ditaMapFileRoot = segments[0]; Bundle bundle = Platform.getBundle("org.dita.dost"); Path path = new Path("META-INF/MANIFEST.MF"); URL fileURL = FileLocator.find(bundle, path, null); Path ditadirPath = new Path("DITA-OT"); URL ditadirURL = FileLocator.find(bundle, ditadirPath, null); ditadirURL = FileLocator.toFileURL(ditadirURL); InputStream in = fileURL.openStream(); Manifest ditaPluginManifest = new Manifest(in); Attributes attributes = ditaPluginManifest.getMainAttributes(); String ditaClassPath = attributes.getValue("Bundle-ClassPath"); List<String> classpath = new ArrayList<String>(); String ditaRequiredBundles = attributes.getValue("Require-Bundle"); for (String requiredBundleSymbolicName : ditaRequiredBundles.split(",")) { // get before ; Bundle requiredBundle = Platform.getBundle(requiredBundleSymbolicName.split(";")[0]); // Assume the bundle is optional if null if (requiredBundle != null) { File file = FileLocator.getBundleFile(requiredBundle); IRuntimeClasspathEntry requiredBundleEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(file.getPath())); requiredBundleEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classpath.add(requiredBundleEntry.getMemento()); } } for (String classPath : ditaClassPath.split(",")) { if (".".equals(classPath)) { URL url = FileLocator.find(bundle, new Path(""), null); url = FileLocator.toFileURL(url); IRuntimeClasspathEntry pluginEntry = JavaRuntime.newRuntimeContainerClasspathEntry( new Path(url.getPath()), IRuntimeClasspathEntry.USER_CLASSES); classpath.add(pluginEntry.getMemento()); } else { URL url = FileLocator.find(bundle, new Path(classPath), null); url = FileLocator.toFileURL(url); IRuntimeClasspathEntry toolsEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(url.getPath())); toolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classpath.add(toolsEntry.getMemento()); } } ContributedClasspathEntriesEntry ccee = new ContributedClasspathEntriesEntry(); AntHomeClasspathEntry ace = new AntHomeClasspathEntry(); classpath.add(ace.getMemento()); classpath.add(ccee.getMemento()); ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = launchManager .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); URL ditaPublishBuildFileURL = fileURL = FileLocator.find(bundle, new Path("dita-publish.xml"), null); ditaPublishBuildFileURL = FileLocator.toFileURL(ditaPublishBuildFileURL); String name = launchManager.generateLaunchConfigurationName("Publish DITA"); ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name); workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", ditaPublishBuildFileURL.getPath()); IVMInstall jre = JavaRuntime.getDefaultVMInstall(); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jre.getName()); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "-Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl"); Map<String, String> antProperties = new HashMap<String, String>(); antProperties.put("dita.dir", ditadirURL.getPath()); antProperties.put("ditaMapFile", ditaMapFile.getLocation().toOSString()); if (ditaValFile != null) { antProperties.put("args.filter", ditaValFile.getLocation().toOSString()); } antProperties.put("ditaMapFileName", ditaMapFile.getName().substring(0, ditaMapFile.getName().length() - ditaMapFile.getFileExtension().length())); // antProperties.put("outputLocation", ditaProject.getLocation().toOSString()); antProperties.put("dita.output", ditaProject.getLocation().append(antTargets).toOSString()); antProperties.put("ditaMapFileRoot", ditaMapFileRoot); String fileName = getFileNameFromMap(ditaMapFile.getLocation().toOSString()); if (StringUtils.isEmpty(fileName)) { fileName = ditaMapFile.getName().replace("." + ditaMapFile.getFileExtension(), ""); } antProperties.put("fileName", fileName); antProperties.put("args.debug", "no"); antProperties.put("ditaFilePath", ditaFolder.getLocation().toOSString()); antProperties.put("tempFilePath", org.dita.dost.internal.Activator.getDefault().getStateLocation().append("temp").toOSString()); antProperties.put("docProject", ditaProject.getLocation().toOSString()); String pdfFileLocation = ditaMapFile.getName(); pdfFileLocation = pdfFileLocation.replaceFirst(".ditamap", ".pdf"); antProperties.put("pdflocation", pdfFileLocation); workingCopy.setAttribute("process_factory_id", "org.eclipse.ant.ui.remoteAntProcessFactory"); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"); workingCopy.setAttribute( org.eclipse.core.externaltools.internal.IExternalToolConstants.ATTR_WORKING_DIRECTORY, ditaProject.getLocation().toOSString()); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jvmArguments.toString()); workingCopy.setAttribute(org.eclipse.ant.launching.IAntLaunchConstants.ATTR_ANT_TARGETS, antTargets); workingCopy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, antProperties); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); workingCopy.setAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS, false); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); workingCopy.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8"); workingCopy.migrate(); return workingCopy.launch(ILaunchManager.RUN_MODE, null, false, true); }
From source file:JarBuilder.java
/** Creates an empty jar file with the given manifest * * @param jar the file to write the jar to * @param manifest the file that is the manifest for the archive * @throws IOException thrown if either file cannot be opened for reading *///ww w .j av a 2 s .c o m public JarBuilder(File jar, File manifest) throws IOException { _output = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jar)), new Manifest(new FileInputStream(manifest))); }
From source file:com.asual.summer.onejar.OneJarMojo.java
public void execute() throws MojoExecutionException { JarOutputStream out = null;/* w w w . j a v a 2 s . c o m*/ JarInputStream in = null; try { File jarFile = new File(buildDirectory, jarName); File warFile = new File(buildDirectory, warName); Manifest manifest = new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\n".getBytes("UTF-8"))); manifest.getMainAttributes().putValue("Main-Class", JAR_MAIN_CLASS); manifest.getMainAttributes().putValue("One-Jar-Main-Class", ONE_JAR_MAIN_CLASS); out = new JarOutputStream(new FileOutputStream(jarFile, false), manifest); in = new JarInputStream(getClass().getClassLoader().getResourceAsStream(ONE_JAR_DIST)); putEntry(out, new FileInputStream(warFile), new ZipEntry(JAR_CLASSPATH + warFile.getName())); for (Artifact artifact : pluginArtifacts) { if (artifact.getArtifactId().equalsIgnoreCase("summer-onejar")) { artifact.updateVersion(artifact.getVersion(), localRepository); putEntry(out, new FileInputStream(artifact.getFile()), new ZipEntry(JAR_CLASSPATH + artifact.getFile().getName())); MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories, localRepository); List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { if (!"provided".equals(dependency.getScope())) { Artifact dependencyArtifact = artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType()); dependencyArtifact.updateVersion(dependencyArtifact.getVersion(), localRepository); putEntry(out, new FileInputStream(dependencyArtifact.getFile()), new ZipEntry(JAR_CLASSPATH + dependencyArtifact.getFile().getName())); } } } } while (true) { ZipEntry entry = in.getNextEntry(); if (entry != null) { putEntry(out, in, entry); } else { break; } } projectHelper.attachArtifact(project, "jar", jarFile); } catch (Exception e) { getLog().error(e.getMessage(), e); throw new MojoExecutionException(e.getMessage(), e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } }