Search in sources :

Example 6 with ArtifactFactory

use of org.apache.maven.artifact.factory.ArtifactFactory in project maven-plugins by apache.

the class ClassesPackagingTask method generateJarArchive.

/**
     * @param context The warPackingContext.
     * @throws MojoExecutionException In casae of an error.
     */
protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException {
    MavenProject project = context.getProject();
    ArtifactFactory factory = context.getArtifactFactory();
    Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar");
    String archiveName;
    try {
        archiveName = getArtifactFinalName(context, artifact);
    } catch (InterpolationException e) {
        throw new MojoExecutionException("Could not get the final name of the artifact [" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e);
    }
    final String targetFilename = LIB_PATH + archiveName;
    if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) {
        final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH);
        final File jarFile = new File(libDirectory, archiveName);
        final ClassesPackager packager = new ClassesPackager();
        packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), context.getSession(), project, context.getArchive());
    } else {
        context.getLog().warn("Could not generate archive classes file [" + targetFilename + "] has already been copied.");
    }
}
Also used : ClassesPackager(org.apache.maven.plugins.war.util.ClassesPackager) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)6 File (java.io.File)3 Artifact (org.apache.maven.artifact.Artifact)3 RemoteException (java.rmi.RemoteException)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 RepositoryMetadataManager (org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 MavenProject (org.apache.maven.project.MavenProject)2 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 ContextException (org.codehaus.plexus.context.ContextException)2 InitializationException (org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 DefaultArtifactFactory (org.apache.maven.artifact.factory.DefaultArtifactFactory)1 ArtifactHandlerManager (org.apache.maven.artifact.handler.manager.ArtifactHandlerManager)1 DefaultArtifactHandlerManager (org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager)1 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)1