use of org.codehaus.plexus.archiver.jar.Manifest in project maven-plugins by apache.
the class EarMavenArchiver method getManifest.
/** {@inheritDoc} */
public Manifest getManifest(MavenSession session, MavenProject project, MavenArchiveConfiguration config) throws ManifestException, DependencyResolutionRequiredException {
final Manifest manifest = super.getManifest(session, project, config);
if (config.getManifest().isAddClasspath()) {
String earManifestClassPathEntry = generateClassPathEntry(config.getManifest().getClasspathPrefix());
// Class-path can be customized. Let's make sure we don't overwrite this
// with our custom change!
final String userSuppliedClassPathEntry = getUserSuppliedClassPathEntry(config);
if (userSuppliedClassPathEntry != null) {
earManifestClassPathEntry = userSuppliedClassPathEntry + " " + earManifestClassPathEntry;
}
// Overwrite the existing one, if any
final Manifest.Attribute classPathAttr = manifest.getMainSection().getAttribute(CLASS_PATH_KEY);
if (classPathAttr != null) {
classPathAttr.setValue(earManifestClassPathEntry);
} else {
final Manifest.Attribute attr = new Manifest.Attribute(CLASS_PATH_KEY, earManifestClassPathEntry);
manifest.addConfiguredAttribute(attr);
}
}
return manifest;
}
use of org.codehaus.plexus.archiver.jar.Manifest in project sling by apache.
the class JarArchiverHelper method createManifest.
/**
* Create a manifest
*/
private void createManifest(final java.util.jar.Manifest manifest) throws MojoExecutionException {
// create a new manifest
final Manifest outManifest = new Manifest();
try {
boolean hasMain = false;
// copy entries from existing manifest
if (manifest != null) {
final Map<Object, Object> attrs = manifest.getMainAttributes();
for (final Map.Entry<Object, Object> entry : attrs.entrySet()) {
final String key = entry.getKey().toString();
if (!BuildConstants.ATTRS_EXCLUDES.contains(key)) {
final Attribute a = new Attribute(key, entry.getValue().toString());
outManifest.addConfiguredAttribute(a);
}
if (key.equals(BuildConstants.ATTR_MAIN_CLASS)) {
hasMain = true;
}
}
}
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_BUILD, project.getVersion()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VERSION, project.getVersion()));
String organizationName = project.getOrganization() != null ? project.getOrganization().getName() : null;
if (organizationName != null) {
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_CREATED_BY, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_BUILT_BY, organizationName));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VENDOR, organizationName));
}
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR_ID, project.getGroupId()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_TITLE, project.getName()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_TITLE, project.getName()));
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VERSION, project.getVersion()));
if (archiver.getDestFile().getName().endsWith(".jar") && !hasMain) {
outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_MAIN_CLASS, BuildConstants.ATTR_VALUE_MAIN_CLASS));
}
archiver.addConfiguredManifest(outManifest);
} catch (final ManifestException e) {
throw new MojoExecutionException("Unable to create manifest for " + this.archiver.getDestFile(), e);
}
}
use of org.codehaus.plexus.archiver.jar.Manifest in project cxf by apache.
the class AbstractCodegenMoho method runForked.
protected void runForked(Set<URI> classPath, String mainClassName, String[] args) throws MojoExecutionException {
getLog().info("Running code generation in fork mode...");
getLog().debug("Running code generation in fork mode with args " + Arrays.asList(args));
Commandline cmd = new Commandline();
// for JVM args
cmd.getShell().setQuotedArgumentsEnabled(true);
cmd.setWorkingDirectory(project.getBuild().getDirectory());
try {
cmd.setExecutable(getJavaExecutable().getAbsolutePath());
} catch (IOException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
cmd.createArg().setLine(additionalJvmArgs);
File file = null;
try {
// file = new File("/tmp/test.jar");
file = FileUtils.createTempFile("cxf-codegen", ".jar");
JarArchiver jar = new JarArchiver();
jar.setDestFile(file.getAbsoluteFile());
Manifest manifest = new Manifest();
Attribute attr = new Attribute();
attr.setName("Class-Path");
StringBuilder b = new StringBuilder(8000);
for (URI cp : classPath) {
b.append(cp.toURL().toExternalForm()).append(' ');
}
attr.setValue(b.toString());
manifest.getMainSection().addConfiguredAttribute(attr);
attr = new Attribute();
attr.setName("Main-Class");
attr.setValue(mainClassName);
manifest.getMainSection().addConfiguredAttribute(attr);
jar.addConfiguredManifest(manifest);
jar.createArchive();
cmd.createArg().setValue("-jar");
String tmpFilePath = file.getAbsolutePath();
if (tmpFilePath.contains(" ")) {
// ensure the path is in double quotation marks if the path contain space
tmpFilePath = "\"" + tmpFilePath + "\"";
}
cmd.createArg().setValue(tmpFilePath);
} catch (Exception e1) {
throw new MojoExecutionException("Could not create runtime jar", e1);
}
cmd.addArguments(args);
StreamConsumer out = new StreamConsumer() {
public void consumeLine(String line) {
getLog().info(line);
}
};
final StringBuilder b = new StringBuilder();
StreamConsumer err = new StreamConsumer() {
public void consumeLine(String line) {
b.append(line);
b.append("\n");
getLog().warn(line);
}
};
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
} catch (CommandLineException e) {
getLog().debug(e);
throw new MojoExecutionException(e.getMessage(), e);
}
String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
if (exitCode != 0) {
StringBuilder msg = new StringBuilder("\nExit code: ");
msg.append(exitCode);
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
file.delete();
if (b.toString().contains("WSDL2Java Error")) {
StringBuilder msg = new StringBuilder();
msg.append(b.toString());
msg.append('\n');
msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
throw new MojoExecutionException(msg.toString());
}
}
use of org.codehaus.plexus.archiver.jar.Manifest in project tomee by apache.
the class ExecMojo method createExecutableJar.
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);
}
use of org.codehaus.plexus.archiver.jar.Manifest in project intellij-community by JetBrains.
the class ManifestBuilder method getUserSuppliedManifest.
@Nullable
private Manifest getUserSuppliedManifest(@Nullable Element mavenArchiveConfiguration) {
Manifest manifest = null;
String manifestPath = MavenJDOMUtil.findChildValueByPath(mavenArchiveConfiguration, "manifestFile");
if (manifestPath != null) {
File manifestFile = new File(manifestPath);
if (!manifestFile.isAbsolute()) {
manifestFile = new File(myMavenProject.getDirectory(), manifestPath);
}
if (manifestFile.isFile()) {
FileInputStream fis = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
fis = new FileInputStream(manifestFile);
manifest = new Manifest(fis);
} catch (IOException ignore) {
} finally {
StreamUtil.closeStream(fis);
}
}
}
return manifest;
}
Aggregations