Example usage for org.apache.maven.artifact.factory ArtifactFactory createBuildArtifact

List of usage examples for org.apache.maven.artifact.factory ArtifactFactory createBuildArtifact

Introduction

In this page you can find the example usage for org.apache.maven.artifact.factory ArtifactFactory createBuildArtifact.

Prototype

Artifact createBuildArtifact(String groupId, String artifactId, String version, String packaging);

Source Link

Usage

From source file:cn.wanghaomiao.maven.plugin.seimi.packaging.ClassesPackagingTask.java

License:Apache License

/**
 * @param context The warPackingContext.
 * @throws MojoExecutionException In casae of an error.
 *///from www.ja  v  a2s  .c o m
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.");
    }
}

From source file:com.github.terma.gigaspacewebconsole.plugin.ConsoleMojo.java

License:Apache License

private Artifact resolveArtifact(ArtifactFactory artifactFactory, String groupId, String artifactId,
        String version, String packaging) throws MojoExecutionException {
    final Artifact artifact = artifactFactory.createBuildArtifact(groupId, artifactId, version, packaging);
    resolveArtifact(artifact);//from   ww w.j  a  v a 2s .co m
    return artifact;
}

From source file:com.kamomileware.maven.plugin.opencms.packaging.ClassesPackagingTask.java

License:Apache License

protected void generateJarArchive(ModulePackagingContext context) throws MojoExecutionException {
    MavenProject project = context.getProject();
    ArtifactFactory factory = context.getArtifactFactory();
    Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(),
            project.getVersion(), "jar");
    String archiveName = null;//from w  w w .j  av a2 s  .c o  m
    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.getModuleStructure().registerFile("currentBuild", targetFilename)) {
        File base = context.getModuleSourceTargetDirectory() == null ? context.getModuleDirectory()
                : new File(context.getModuleDirectory(), context.getModuleSourceTargetDirectory());

        final File libDirectory = new File(base, LIB_PATH);
        final File jarFile = new File(libDirectory, archiveName);
        final ClassesPackager packager = new ClassesPackager();
        packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), project,
                context.getArchive());

    } else {
        context.getLog().warn(
                "Could not generate archive classes file[" + targetFilename + "] has already been copied.");
    }
}

From source file:fr.imag.adele.cadse.platform.DependenciesTask.java

License:Apache License

/**
 * Main task execution.  Called by parent execute().
 *///  w  w  w .  j  a va  2 s.co m
protected void doExecute() {

    if (useScope != null && scopes != null) {
        throw new BuildException("You cannot specify both useScope and scopes in the dependencies task.");
    }

    if (getPom() != null && !this.dependencies.isEmpty()) {
        throw new BuildException("You cannot specify both dependencies and a pom in the dependencies task");
    }

    // Try to load dependency refs from an exsiting Ant cache file
    if (isCacheDependencyRefs()) {
        if (getDependencyRefsBuildFile() == null) {
            setDependencyRefsBuildFile(DEFAULT_ANT_BUILD_FILE);
        }
        if (checkCachedDependencies()) {
            log("Dependency refs loaded from file: " + getDependencyRefsBuildFile(), Project.MSG_VERBOSE);
            return;
        }
    }

    ArtifactRepository localRepo = createLocalArtifactRepository();
    log("Using local repository: " + localRepo.getBasedir(), Project.MSG_VERBOSE);

    // Look up required resources from the plexus container
    ArtifactResolver resolver = (ArtifactResolver) lookup(ArtifactResolver.ROLE);
    ArtifactFactory artifactFactory = (ArtifactFactory) lookup(ArtifactFactory.ROLE);
    MavenMetadataSource metadataSource = (MavenMetadataSource) lookup(ArtifactMetadataSource.ROLE);

    Pom pom = initializePom(localRepo);
    if (pom != null) {
        dependencies = pom.getDependencies();
    } else {
        // we have to have some sort of Pom object in order to satisfy the requirements for building the
        // originating Artifact below...
        pom = createDummyPom(localRepo);
    }

    if (dependencies.isEmpty()) {
        log("There were no dependencies specified", Project.MSG_WARN);
    }

    log("Resolving dependencies...", Project.MSG_VERBOSE);

    Set artifacts;

    List remoteArtifactRepositories = createRemoteArtifactRepositories(pom.getRepositories());

    try {
        artifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, null, null, null);

        Artifact pomArtifact = artifactFactory.createBuildArtifact(pom.getGroupId(), pom.getArtifactId(),
                pom.getVersion(), pom.getPackaging());

        List listeners = Collections.singletonList(new AntResolutionListener(getProject()));

        ArtifactFilter filter = null;
        if (useScope != null) {
            filter = new ScopeArtifactFilter(useScope);
        }
        if (scopes != null) {
            filter = new SpecificScopesArtifactFilter(scopes);
        }
        if (type != null) {
            ArtifactFilter typeArtifactFilter = new TypesArtifactFilter(type);
            if (filter != null) {
                AndArtifactFilter andFilter = new AndArtifactFilter();
                andFilter.add(filter);
                andFilter.add(typeArtifactFilter);
                filter = andFilter;
            } else {
                filter = typeArtifactFilter;
            }
        }
        for (Object o : artifacts) {
            resolver.resolve((Artifact) o, remoteArtifactRepositories, localRepo);
        }

    } catch (ArtifactResolutionException e) {
        throw new BuildException("Unable to resolve artifact: " + e.getMessage(), e);
    } catch (ArtifactNotFoundException e) {
        throw new BuildException("Dependency not found: " + e.getMessage(), e);
    } catch (InvalidDependencyVersionException e) {
        throw new BuildException("Invalid dependency version: " + e.getMessage(), e);
    }

    FileSet dependencyFileSet = createFileSet();

    FileSet sourcesFileSet = createFileSet();

    FileSet javadocsFileSet = createFileSet();

    Path dependencyPath = new Path(getProject());

    Set versions = new HashSet();

    for (Object o : artifacts) {
        Artifact artifact = (Artifact) o;

        addArtifactToResult(localRepo, artifact, dependencyFileSet, dependencyPath);

        versions.add(artifact.getVersion());

        if (sourcesFilesetId != null) {
            resolveSource(artifactFactory, resolver, remoteArtifactRepositories, localRepo, artifact, "sources",
                    sourcesFileSet);
        }

        if (javadocFilesetId != null) {
            resolveSource(artifactFactory, resolver, remoteArtifactRepositories, localRepo, artifact, "javadoc",
                    javadocsFileSet);
        }

    }

    defineFilesetReference(filesetId, dependencyFileSet);

    defineFilesetReference(sourcesFilesetId, sourcesFileSet);

    defineFilesetReference(javadocFilesetId, javadocsFileSet);

    if (pathId != null) {
        getProject().addReference(pathId, dependencyPath);
    }

    if (versionsId != null) {
        String versionsValue = StringUtils.join(versions.iterator(), File.pathSeparator);
        getProject().setNewProperty(versionsId, versionsValue);
    }
}

From source file:hudson.maven.artifact.AbstractArtifactComponentTestCase.java

License:Apache License

protected Artifact createArtifact(String groupId, String artifactId, String version, String type)
        throws Exception {
    ArtifactFactory artifactFactory = (ArtifactFactory) lookup(ArtifactFactory.ROLE);

    return artifactFactory.createBuildArtifact(groupId, artifactId, version, type);
}

From source file:org.piraso.maven.packaging.ClassesPackagingTask.java

License:Apache License

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 = null;//from  w  w  w .  ja va2  s  .c o  m
    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.");
    }
}