Search in sources :

Example 11 with JarArchiver

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

the class AbstractWarMojoTest method createArchive.

protected void createArchive(final File directory, final File destinationFile) {
    try {
        // WarArchiver archiver = new WarArchiver();
        Archiver archiver = new JarArchiver();
        archiver.setUseJvmChmod(true);
        archiver.setDestFile(destinationFile);
        archiver.addDirectory(directory);
        // archiver.setWebxml( new File(directory, "WEB-INF/web.xml"));
        // create archive
        archiver.createArchive();
    } catch (ArchiverException e) {
        e.printStackTrace();
        fail("Failed to create overlay archive " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected exception " + e.getMessage());
    }
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) IOException(java.io.IOException) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver)

Example 12 with JarArchiver

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

the class AssemblyProxyArchiverTest method addDirectory_NoPerms_CallAcceptFilesOnlyOnce.

@Test
public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce() throws IOException, ArchiverException {
    final Archiver delegate = new JarArchiver();
    final File output = fileManager.createTempFile();
    delegate.setDestFile(output);
    final CounterSelector counter = new CounterSelector(true);
    final List<FileSelector> selectors = new ArrayList<FileSelector>();
    selectors.add(counter);
    final AssemblyProxyArchiver archiver = new AssemblyProxyArchiver("", delegate, null, selectors, null, new File("."), new ConsoleLogger(Logger.LEVEL_DEBUG, "test"));
    archiver.setForced(true);
    final File dir = fileManager.createTempDir();
    FileUtils.cleanDirectory(dir);
    fileManager.createFile(dir, "file.txt", "This is a test.");
    archiver.addDirectory(dir);
    archiver.createArchive();
    assertEquals(1, counter.getCount());
}
Also used : ConsoleLogger(org.codehaus.plexus.logging.console.ConsoleLogger) FileSelector(org.codehaus.plexus.components.io.fileselectors.FileSelector) ArrayList(java.util.ArrayList) TrackingArchiver(org.codehaus.plexus.archiver.diags.TrackingArchiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) File(java.io.File) Test(org.junit.Test)

Example 13 with JarArchiver

use of org.codehaus.plexus.archiver.jar.JarArchiver in project tycho by eclipse.

the class PackageFeatureMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    outputDirectory.mkdirs();
    Feature feature = Feature.loadFeature(basedir);
    File licenseFeature = licenseFeatureHelper.getLicenseFeature(feature, project);
    updateLicenseProperties(feature, licenseFeature);
    File featureXml = new File(outputDirectory, Feature.FEATURE_XML);
    try {
        expandVersionQualifiers(feature);
        Feature.write(feature, featureXml);
    } catch (IOException e) {
        throw new MojoExecutionException("Error updating feature.xml", e);
    }
    BuildProperties buildProperties = buildPropertiesParser.parse(project.getBasedir());
    checkBinIncludesExist(buildProperties);
    File featureProperties = getFeatureProperties(licenseFeature, buildProperties);
    File outputJar = new File(outputDirectory, finalName + ".jar");
    outputJar.getParentFile().mkdirs();
    MavenArchiver archiver = new MavenArchiver();
    JarArchiver jarArchiver = getJarArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(outputJar);
    jarArchiver.setDestFile(outputJar);
    try {
        archiver.getArchiver().addFileSet(getManuallyIncludedFiles(buildProperties));
        if (licenseFeature != null) {
            archiver.getArchiver().addArchivedFileSet(licenseFeatureHelper.getLicenseFeatureFileSet(licenseFeature));
        }
        archiver.getArchiver().addFile(featureXml, Feature.FEATURE_XML);
        if (featureProperties != null) {
            archiver.getArchiver().addFile(featureProperties, FEATURE_PROPERTIES);
        }
        if (archive == null) {
            archive = new MavenArchiveConfiguration();
            archive.setAddMavenDescriptor(false);
        }
        archiver.createArchive(session, project, archive);
    } catch (Exception e) {
        throw new MojoExecutionException("Error creating feature package", e);
    }
    project.getArtifact().setFile(outputJar);
    if (deployableFeature) {
        assembleDeployableFeature();
    }
}
Also used : BuildProperties(org.eclipse.tycho.core.shared.BuildProperties) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) MavenArchiveConfiguration(org.apache.maven.archiver.MavenArchiveConfiguration) Feature(org.eclipse.tycho.model.Feature) ZipFile(java.util.zip.ZipFile) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 14 with JarArchiver

use of org.codehaus.plexus.archiver.jar.JarArchiver 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);
    final File file;
    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

JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)14 File (java.io.File)11 IOException (java.io.IOException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)5 Manifest (org.codehaus.plexus.archiver.jar.Manifest)5 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)4 InputStreamReader (java.io.InputStreamReader)3 URI (java.net.URI)3 MavenArchiveConfiguration (org.apache.maven.archiver.MavenArchiveConfiguration)3 Archiver (org.codehaus.plexus.archiver.Archiver)3 Attribute (org.codehaus.plexus.archiver.jar.Manifest.Attribute)3 BufferedReader (java.io.BufferedReader)2 StringWriter (java.io.StringWriter)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 MavenArchiver (org.apache.maven.archiver.MavenArchiver)2 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)2 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)2 Model (org.apache.maven.model.Model)2