org.codehaus.plexus.archiver.jar.Manifest Java Examples
The following examples show how to use
org.codehaus.plexus.archiver.jar.Manifest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManifestCreator.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
public static Manifest createManifest(MavenProject project) throws ManifestException { Manifest manifest = new Manifest(); Plugin verifierMavenPlugin = findMavenPlugin(project.getBuildPlugins()); if (verifierMavenPlugin != null) { manifest.addConfiguredAttribute( new Manifest.Attribute("Spring-Cloud-Contract-Maven-Plugin-Version", verifierMavenPlugin.getVersion())); } if (verifierMavenPlugin != null && !verifierMavenPlugin.getDependencies().isEmpty()) { Dependency verifierDependency = findVerifierDependency( verifierMavenPlugin.getDependencies()); if (verifierDependency != null) { String verifierVersion = verifierDependency.getVersion(); manifest.addConfiguredAttribute(new Manifest.Attribute( "Spring-Cloud-Contract-Verifier-Version", verifierVersion)); } } return manifest; }
Example #2
Source File: WebJarPackager.java From wisdom with Apache License 2.0 | 5 votes |
private File process() throws IOException, ManifestException { getLog().info("Building webjar for " + project.getArtifactId()); File output = new File(buildDirectory, webjar.getOutputFileName()); FileUtils.deleteQuietly(output); // Compute the set of selected files: Collection<File> selected = webjar.getSelectedFiles(); if (selected.isEmpty()) { getLog().warn("No file selected in the webjar - skipping creation"); return null; } String root = computeRoot(); FileUtils.deleteQuietly(output); // Web jar are jar file, so use the Plexus Archiver. JarArchiver archiver = new JarArchiver(); archiver.enableLogging(new PlexusLoggerWrapper(getLog())); String base = webjar.getFileset().getDirectory(); for (File file : selected) { final String destFileName = root + "/" + file.getAbsolutePath().substring(base.length() + 1); getLog().debug(file.getName() + " => " + destFileName); archiver.addFile(file, destFileName); } // Extend the manifest with webjar data - this is not required by the webjar specification Manifest manifest = Manifest.getDefaultManifest(); manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Webjar-Name", webjar.getName())); manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Webjar-Version", webjar.getVersion())); manifest.getMainSection().addConfiguredAttribute(new Manifest.Attribute("Created-By", "Wisdom Framework " + BuildConstants.get("WISDOM_PLUGIN_VERSION"))); archiver.addConfiguredManifest(manifest); archiver.setDestFile(output); archiver.createArchive(); return output; }
Example #3
Source File: ExecMojo.java From tomee with Apache License 2.0 | 4 votes |
private void createExecutableJar() throws Exception { mkdirs(execFile.getParentFile()); final Properties config = new Properties(); config.put("distribution", distributionName); config.put("workingDir", runtimeWorkingDir); config.put("command", DEFAULT_SCRIPT.equals(script) ? (skipArchiveRootFolder ? "" : catalinaBase.getName() + "/") + DEFAULT_SCRIPT : script); final List<String> jvmArgs = generateJVMArgs(); final String catalinaOpts = toString(jvmArgs, " "); config.put("catalinaOpts", catalinaOpts); config.put("timestamp", Long.toString(System.currentTimeMillis())); // java only final String cp = getAdditionalClasspath(); if (cp != null) { config.put("additionalClasspath", cp); } config.put("shutdownCommand", tomeeShutdownCommand); int i = 0; boolean encodingSet = catalinaOpts.contains("-Dfile.encoding"); for (final String jvmArg : jvmArgs) { config.put("jvmArg." + i++, jvmArg); encodingSet = encodingSet || jvmArg.contains("-Dfile.encoding"); } if (!encodingSet) { // forcing encoding for launched process to be able to read conf files config.put("jvmArg." + i, "-Dfile.encoding=UTF-8"); } if (preTasks != null) { config.put("preTasks", toString(preTasks, ",")); } if (postTasks != null) { config.put("postTasks", toString(postTasks, ",")); } config.put("waitFor", Boolean.toString(waitFor)); // create an executable jar with main runner and zipFile final FileOutputStream fileOutputStream = new FileOutputStream(execFile); final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR, fileOutputStream); { // distrib os.putArchiveEntry(new JarArchiveEntry(distributionName)); final FileInputStream in = new FileInputStream(zipFile); try { IOUtils.copy(in, os); os.closeArchiveEntry(); } finally { IOUtil.close(in); } } { // config os.putArchiveEntry(new JarArchiveEntry("configuration.properties")); final StringWriter writer = new StringWriter(); config.store(writer, ""); IOUtils.copy(new ByteArrayInputStream(writer.toString().getBytes("UTF-8")), os); os.closeArchiveEntry(); } { // Manifest final Manifest manifest = new Manifest(); final Manifest.Attribute mainClassAtt = new Manifest.Attribute(); mainClassAtt.setName("Main-Class"); mainClassAtt.setValue(runnerClass); manifest.addConfiguredAttribute(mainClassAtt); final ByteArrayOutputStream baos = new ByteArrayOutputStream(512); manifest.write(baos); os.putArchiveEntry(new JarArchiveEntry("META-INF/MANIFEST.MF")); IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), os); os.closeArchiveEntry(); } { // Main + utility for (final Class<?> clazz : asList( ExecRunner.class, Files.class, Files.PatternFileFilter.class, Files.DeleteThread.class, Files.FileRuntimeException.class, Files.FileDoesNotExistException.class, Files.NoopOutputStream.class, LoaderRuntimeException.class, Pipe.class, IO.class, Zips.class, JarLocation.class, RemoteServer.class, RemoteServer.CleanUpThread.class, OpenEJBRuntimeException.class, Join.class, QuickServerXmlParser.class, Options.class, Options.NullLog.class, Options.TomEEPropertyAdapter.class, Options.NullOptions.class, Options.Log.class, JavaSecurityManagers.class)) { addToJar(os, clazz); } } addClasses(additionalClasses, os); addClasses(preTasks, os); addClasses(postTasks, os); IOUtil.close(os); IOUtil.close(fileOutputStream); }