Search in sources :

Example 11 with Manifest

use of org.codehaus.plexus.archiver.jar.Manifest in project intellij-community by JetBrains.

the class ManifestBuilder method getDefaultManifest.

@NotNull
private Manifest getDefaultManifest(@NotNull Map<String, String> entries) throws ManifestException {
    Manifest finalManifest = new Manifest();
    addManifestAttribute(finalManifest, entries, "Created-By", ApplicationNamesInfo.getInstance().getFullProductName());
    addManifestAttribute(finalManifest, entries, "Built-By", System.getProperty("user.name"));
    if (!StringUtil.isEmpty(myJdkVersion)) {
        addManifestAttribute(finalManifest, entries, "Build-Jdk", myJdkVersion);
    }
    return finalManifest;
}
Also used : Manifest(org.codehaus.plexus.archiver.jar.Manifest) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with Manifest

use of org.codehaus.plexus.archiver.jar.Manifest in project maven-plugins by apache.

the class ManifestCreationFinalizer method finalizeArchiveCreation.

@Override
public void finalizeArchiveCreation(final Archiver archiver) {
    if (archiveConfiguration != null) {
        try {
            Manifest manifest;
            final File manifestFile = archiveConfiguration.getManifestFile();
            if (manifestFile != null) {
                Reader manifestFileReader = null;
                try {
                    manifestFileReader = new InputStreamReader(new FileInputStream(manifestFile), "UTF-8");
                    manifest = new Manifest(manifestFileReader);
                    manifestFileReader.close();
                    manifestFileReader = null;
                } catch (final FileNotFoundException e) {
                    throw new ArchiverException("Manifest not found: " + e.getMessage(), e);
                } catch (final IOException e) {
                    throw new ArchiverException("Error processing manifest: " + e.getMessage(), e);
                } finally {
                    IOUtil.close(manifestFileReader);
                }
            } else {
                manifest = mavenArchiver.getManifest(session, project, archiveConfiguration);
            }
            if ((manifest != null) && (archiver instanceof JarArchiver)) {
                final JarArchiver jarArchiver = (JarArchiver) archiver;
                jarArchiver.addConfiguredManifest(manifest);
            }
        } catch (final ManifestException e) {
            throw new ArchiverException("Error creating manifest: " + e.getMessage(), e);
        } catch (final DependencyResolutionRequiredException e) {
            throw new ArchiverException("Dependencies were not resolved: " + e.getMessage(), e);
        }
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) InputStreamReader(java.io.InputStreamReader) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Manifest(org.codehaus.plexus.archiver.jar.Manifest) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) FileInputStream(java.io.FileInputStream)

Example 13 with Manifest

use of org.codehaus.plexus.archiver.jar.Manifest in project cxf by apache.

the class AbstractCodeGeneratorMojo method runForked.

private void runForked(Set<URI> classPath, Class<?> cls, String[] args) throws MojoExecutionException {
    getLog().info("Running wadl2java in fork mode...");
    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(cls.getName());
        manifest.getMainSection().addConfiguredAttribute(attr);
        jar.addConfiguredManifest(manifest);
        jar.createArchive();
        cmd.createArg().setValue("-jar");
        cmd.createArg().setValue(file.getAbsolutePath());
    } catch (Exception e1) {
        throw new MojoExecutionException("Could not create runtime jar", e1);
    }
    cmd.addArguments(args);
    CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
    } catch (CommandLineException e) {
        getLog().debug(e);
        throw new MojoExecutionException(e.getMessage(), e);
    }
    String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();
    String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
    if (exitCode != 0) {
        if (StringUtils.isNotEmpty(output)) {
            getLog().info(output);
        }
        StringBuilder msg = new StringBuilder("\nExit code: ");
        msg.append(exitCode);
        if (StringUtils.isNotEmpty(err.getOutput())) {
            msg.append(" - ").append(err.getOutput());
        }
        msg.append('\n');
        msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
        throw new MojoExecutionException(msg.toString());
    }
    if (file != null) {
        file.delete();
    }
    if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("WADL2Java Error")) {
        StringBuilder msg = new StringBuilder();
        msg.append(err.getOutput());
        msg.append('\n');
        msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
        throw new MojoExecutionException(msg.toString());
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Attribute(org.codehaus.plexus.archiver.jar.Manifest.Attribute) IOException(java.io.IOException) Manifest(org.codehaus.plexus.archiver.jar.Manifest) URI(java.net.URI) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver)

Aggregations

Manifest (org.codehaus.plexus.archiver.jar.Manifest)13 File (java.io.File)6 IOException (java.io.IOException)5 Attribute (org.codehaus.plexus.archiver.jar.Manifest.Attribute)5 FileInputStream (java.io.FileInputStream)4 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)3 NotNull (org.jetbrains.annotations.NotNull)3 PrintWriter (java.io.PrintWriter)2 URI (java.net.URI)2 Map (java.util.Map)2 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 Commandline (org.codehaus.plexus.util.cli.Commandline)2 Element (org.jdom.Element)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1