Search in sources :

Example 1 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class EjbMojo method generateEjbClient.

private File generateEjbClient() throws MojoExecutionException {
    File clientJarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClientClassifier());
    getLog().info("Building EJB client " + clientJarFile.getPath());
    MavenArchiver clientArchiver = new MavenArchiver();
    clientArchiver.setArchiver(clientJarArchiver);
    clientArchiver.setOutputFile(clientJarFile);
    try {
        List<String> defaultExcludes = DEFAULT_CLIENT_EXCLUDES_LIST;
        List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
        IncludesExcludes ie = new IncludesExcludes(clientIncludes, clientExcludes, defaultIncludes, defaultExcludes);
        clientArchiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
        clientArchiver.createArchive(session, project, archive);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem creating the EJB client archive: " + e.getMessage(), e);
    }
    return clientJarFile;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 2 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class AcrMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
    if (getLog().isInfoEnabled()) {
        getLog().info("Building JavaEE Application client: " + jarName);
    }
    File jarFile = getAppClientJarFile(basedir, jarName);
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(jarFile);
    try {
        String[] mainJarExcludes = DEFAULT_EXCLUDES;
        if (excludes != null && !excludes.isEmpty()) {
            excludes.add(APP_CLIENT_XML);
            mainJarExcludes = excludes.toArray(new String[excludes.size()]);
        }
        if (outputDirectory.exists()) {
            archiver.getArchiver().addDirectory(outputDirectory, DEFAULT_INCLUDES, mainJarExcludes);
        } else {
            // CHECKSTYLE_OFF: LineLength
            getLog().info("JAR will only contain the META-INF/application-client.xml as no content was marked for inclusion");
        // CHECKSTYLE_ON: LineLength
        }
        File deploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML);
        if (deploymentDescriptor.exists()) {
            if (filterDeploymentDescriptor) {
                getLog().debug("Filtering deployment descriptor.");
                MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
                mavenResourcesExecution.setEscapeString(escapeString);
                List<FilterWrapper> filterWrappers = mavenFileFilter.getDefaultFilterWrappers(project, filters, escapeBackslashesInFilePath, this.session, mavenResourcesExecution);
                // Create a temporary file that we can copy-and-filter
                File unfilteredDeploymentDescriptor = new File(outputDirectory, APP_CLIENT_XML + ".unfiltered");
                FileUtils.copyFile(deploymentDescriptor, unfilteredDeploymentDescriptor);
                mavenFileFilter.copyFile(unfilteredDeploymentDescriptor, deploymentDescriptor, true, filterWrappers, getEncoding(unfilteredDeploymentDescriptor));
                // Remove the temporary file
                FileUtils.forceDelete(unfilteredDeploymentDescriptor);
            }
            archiver.getArchiver().addFile(deploymentDescriptor, APP_CLIENT_XML);
        }
        // create archive
        archiver.createArchive(session, project, archive);
    // CHECKSTYLE_OFF: LineLength
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the JavaEE Application Client  archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem reading / creating the manifest for the JavaEE Application Client  archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a I/O problem creating the JavaEE Application Client archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem resolving dependencies while creating the JavaEE Application Client archive: " + e.getMessage(), e);
    } catch (MavenFilteringException e) {
        throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
    }
    project.getArtifact().setFile(jarFile);
// CHECKSTYLE_ON: LineLength
}
Also used : MavenResourcesExecution(org.apache.maven.shared.filtering.MavenResourcesExecution) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) FilterWrapper(org.apache.maven.shared.utils.io.FileUtils.FilterWrapper) File(java.io.File)

Example 3 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class JavadocJar method generateArchive.

// ----------------------------------------------------------------------
// private methods
// ----------------------------------------------------------------------
/**
     * Method that creates the jar file
     *
     * @param javadocFiles the directory where the generated jar file will be put
     * @param jarFileName the filename of the generated jar file
     * @return a File object that contains the generated jar file
     * @throws ArchiverException {@link ArchiverException}
     * @throws IOException {@link IOException}
     */
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
    File javadocJar = new File(jarOutputDirectory, jarFileName);
    if (javadocJar.exists()) {
        javadocJar.delete();
    }
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(javadocJar);
    File contentDirectory = javadocFiles;
    if (!contentDirectory.exists()) {
        getLog().warn("JAR will be empty - no content was marked for inclusion!");
    } else {
        archiver.getArchiver().addDirectory(contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES);
    }
    List<Resource> resources = project.getBuild().getResources();
    for (Resource r : resources) {
        if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
            archiver.getArchiver().addDirectory(new File(r.getDirectory()));
        }
    }
    if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
        getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
        archive.setManifestFile(defaultManifestFile);
    }
    try {
        archiver.createArchive(session, project, archive);
    } catch (ManifestException e) {
        throw new ArchiverException("ManifestException: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
    }
    return javadocJar;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Resource(org.apache.maven.model.Resource) MavenArchiver(org.apache.maven.archiver.MavenArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 4 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class RarMojo method execute.

public void execute() throws MojoExecutionException {
    if (skip) {
        getLog().info("Skipping rar generation.");
        return;
    }
    // Check if jar file is there and if requested, copy it
    try {
        if (includeJar) {
            File generatedJarFile = new File(outputDirectory, finalName + ".jar");
            if (generatedJarFile.exists()) {
                getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
                FileUtils.copyFileToDirectory(generatedJarFile, getBuildDir());
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying generated Jar file", e);
    }
    // Copy dependencies
    try {
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact artifact : artifacts) {
            ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
            if (!artifact.isOptional() && filter.include(artifact) && artifact.getArtifactHandler().isAddedToClasspath()) {
                getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
                FileUtils.copyFileToDirectory(artifact.getFile(), getBuildDir());
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying RAR dependencies", e);
    }
    resourceHandling();
    // Include custom manifest if necessary
    try {
        includeCustomRaXmlFile();
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying ra.xml file", e);
    }
    // Check if connector deployment descriptor is there
    File ddFile = new File(getBuildDir(), RA_XML_URI);
    if (!ddFile.exists() && warnOnMissingRaXml) {
        getLog().warn("Connector deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
    }
    File rarFile = getRarFile(outputDirectory, finalName, classifier);
    try {
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(rarFile);
        // Include custom manifest if necessary
        includeCustomManifestFile();
        archiver.getArchiver().addDirectory(getBuildDir());
        archiver.createArchive(session, project, archive);
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling RAR", e);
    }
    if (classifier != null) {
        projectHelper.attachArtifact(project, "rar", classifier, rarFile);
    } else {
        project.getArtifact().setFile(rarFile);
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 5 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class AbstractSourceJarMojo method packageSources.

/**
     * @param theProjects {@link MavenProject}
     * @throws MojoExecutionException in case of an error.
     */
protected void packageSources(List<MavenProject> theProjects) throws MojoExecutionException {
    if (project.getArtifact().getClassifier() != null) {
        getLog().warn("NOT adding sources to artifacts with classifier as Maven only supports one classifier " + "per artifact. Current artifact [" + project.getArtifact().getId() + "] has a [" + project.getArtifact().getClassifier() + "] classifier.");
        return;
    }
    MavenArchiver archiver = createArchiver();
    for (MavenProject pItem : theProjects) {
        MavenProject subProject = getProject(pItem);
        if ("pom".equals(subProject.getPackaging())) {
            continue;
        }
        archiveProjectContent(subProject, archiver.getArchiver());
    }
    if (archiver.getArchiver().getResources().hasNext() || forceCreation) {
        if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
            getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
            archive.setManifestFile(defaultManifestFile);
        }
        File outputFile = new File(outputDirectory, finalName + "-" + getClassifier() + getExtension());
        try {
            archiver.setOutputFile(outputFile);
            archive.setForced(forceCreation);
            archiver.createArchive(session, project, archive);
        } catch (IOException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        } catch (ArchiverException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        } catch (DependencyResolutionRequiredException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        } catch (ManifestException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        }
        if (attach) {
            projectHelper.attachArtifact(project, getType(), getClassifier(), outputFile);
        } else {
            getLog().info("NOT adding java-sources to attached artifacts list.");
        }
    } else {
        getLog().info("No sources in project. Archive not created.");
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Aggregations

MavenArchiver (org.apache.maven.archiver.MavenArchiver)14 File (java.io.File)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 IOException (java.io.IOException)8 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)8 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)8 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)6 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)4 Artifact (org.apache.maven.artifact.Artifact)3 Resource (org.apache.maven.model.Resource)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Date (java.util.Date)1 ZipException (java.util.zip.ZipException)1 MavenArchiveConfiguration (org.apache.maven.archiver.MavenArchiveConfiguration)1 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)1 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)1 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)1 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)1 SnapshotVersion (org.apache.maven.artifact.repository.metadata.SnapshotVersion)1 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)1