Example usage for org.apache.maven.artifact DefaultArtifact DefaultArtifact

List of usage examples for org.apache.maven.artifact DefaultArtifact DefaultArtifact

Introduction

In this page you can find the example usage for org.apache.maven.artifact DefaultArtifact DefaultArtifact.

Prototype

@SuppressWarnings("checkstyle:parameternumber")
    public DefaultArtifact(String groupId, String artifactId, VersionRange versionRange, String scope, String type,
            String classifier, ArtifactHandler artifactHandler, boolean optional) 

Source Link

Usage

From source file:com.googlecode.t7mp.steps.deployment.AbstractDeploymentStep.java

License:Apache License

protected List<AbstractArtifact> resolveArtifacts(List<? extends AbstractArtifact> artifacts) {
    List<AbstractArtifact> resolvedArtifacts = Lists.newArrayList();
    for (AbstractArtifact abstractArtifact : artifacts) {
        context.getLog().debug("Resolve artifact for " + abstractArtifact.toString());
        if (!abstractArtifact.getGroupId().equals("local")) {
            Artifact artifact;//from  w ww.j a v a  2 s .co  m
            try {
                artifact = myArtifactResolver.resolve(abstractArtifact.getGroupId(),
                        abstractArtifact.getArtifactId(), abstractArtifact.getVersion(),
                        abstractArtifact.getClassifier(), abstractArtifact.getType(), Artifact.SCOPE_COMPILE);
            } catch (MojoExecutionException e) {
                throw new TomcatSetupException(e.getMessage(), e);
            }
            abstractArtifact.setArtifact(artifact);
            resolvedArtifacts.add(abstractArtifact);
        } else {
            Artifact artifact = new DefaultArtifact(abstractArtifact.getGroupId(),
                    abstractArtifact.getArtifactId(),
                    VersionRange.createFromVersion(abstractArtifact.getVersion()), Artifact.SCOPE_COMPILE,
                    abstractArtifact.getType(), null, new DefaultArtifactHandler("jar"), false);
            String resourceName = "/com/googlecode/t7mp/repo/" + abstractArtifact.getArtifactId() + "/"
                    + abstractArtifact.getVersion() + "/" + abstractArtifact.getArtifactId() + "-"
                    + abstractArtifact.getVersion() + ".jar";
            BufferedInputStream bis = new BufferedInputStream(getClass().getResourceAsStream(resourceName));
            File tempFile;
            try {
                tempFile = File.createTempFile("local_Artifact", ".maven.tmp");
                tempFile.deleteOnExit();
                IOUtils.copy(bis, new FileOutputStream(tempFile));
                artifact.setFile(tempFile);
                abstractArtifact.setArtifact(artifact);
                resolvedArtifacts.add(abstractArtifact);
            } catch (FileNotFoundException e) {
                throw new TomcatSetupException(e.getMessage(), e);
            } catch (IOException e) {
                throw new TomcatSetupException(e.getMessage(), e);
            }
        }
    }
    return resolvedArtifacts;
}

From source file:org.apache.cactus.integration.maven2.test.CactifyMavenProjectStub.java

License:Apache License

/**
 * @return a set of dependency artifacts.
 *///from   ww  w .  ja va  2 s  .  c  o  m
public Set getDependencyArtifacts() {
    return Collections.singleton(
            new DefaultArtifact("cactify", "dependency-artifact", VersionRange.createFromVersion("1.0"),
                    Artifact.SCOPE_COMPILE, "jar", null, new DefaultArtifactHandler("jar"), false));
}

From source file:org.basepom.mojo.duplicatefinder.artifact.ArtifactFileResolver.java

License:Apache License

@VisibleForTesting
static DefaultArtifact canonicalizeArtifact(final Artifact artifact) {
    final VersionRange versionRange = artifact.getVersionRange() == null
            ? VersionRange.createFromVersion(artifact.getVersion())
            : artifact.getVersionRange();
    String type = MoreObjects.firstNonNull(artifact.getType(), "jar");
    String classifier = artifact.getClassifier();

    if ("test-jar".equals(type) && (classifier == null || "tests".equals(classifier))) {
        type = "jar";
        classifier = "tests";
    }//from   w w w.  j ava 2  s .  co  m

    final DefaultArtifact canonicalizedArtifact = new DefaultArtifact(artifact.getGroupId(),
            artifact.getArtifactId(), versionRange, artifact.getScope(), type, classifier,
            artifact.getArtifactHandler(), artifact.isOptional());

    return canonicalizedArtifact;
}

From source file:org.codehaus.mojo.antlr.stubs.DependencyProjectStub.java

License:Apache License

public Artifact getArtifact() {
    if (artifact == null) {
        ArtifactHandler ah = new DefaultArtifactHandlerStub("jar", null);

        VersionRange vr = VersionRange.createFromVersion("1.0");
        Artifact art = new DefaultArtifact("group", "artifact", vr, Artifact.SCOPE_COMPILE, "jar", null, ah,
                false);//from w w  w .  j a v  a  2s.  c om
        setArtifact(art);
    }
    return artifact;
}

From source file:org.codehaus.mojo.natives.plugin.NativeLinkMojo.java

License:Open Source License

/**
 * //from  w w w  .ja  va2s  . c  om
 */
private void attachPrimaryArtifact() {
    Artifact artifact = this.project.getArtifact();

    if (null == this.classifier) {
        artifact.setFile(new File(this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName()
                + "." + this.project.getArtifact().getArtifactHandler().getExtension()));
    } else {
        //install primary artifact as a classifier

        DefaultArtifact clone = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
                artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier,
                artifact.getArtifactHandler(), artifact.isOptional());

        clone.setRelease(artifact.isRelease());
        clone.setResolvedVersion(artifact.getVersion());
        clone.setResolved(artifact.isResolved());
        clone.setFile(artifact.getFile());

        if (artifact.getAvailableVersions() != null) {
            clone.setAvailableVersions(new ArrayList(artifact.getAvailableVersions()));
        }

        clone.setBaseVersion(artifact.getBaseVersion());
        clone.setDependencyFilter(artifact.getDependencyFilter());

        if (artifact.getDependencyTrail() != null) {
            clone.setDependencyTrail(new ArrayList(artifact.getDependencyTrail()));
        }

        clone.setDownloadUrl(artifact.getDownloadUrl());
        clone.setRepository(artifact.getRepository());

        clone.setFile(new File(this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "."
                + this.project.getArtifact().getArtifactHandler().getExtension()));

        project.setArtifact(clone);
    }
}

From source file:org.codehaus.mojo.versions.UseLatestReleasesMojo.java

License:Apache License

private ArtifactVersion[] filterVersionsWithIncludes(ArtifactVersion[] newer, Artifact artifact) {
    List filteredNewer = new ArrayList(newer.length);
    for (int j = 0; j < newer.length; j++) {
        ArtifactVersion artifactVersion = newer[j];
        Artifact artefactWithNewVersion = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
                VersionRange.createFromVersion(artifactVersion.toString()), artifact.getScope(),
                artifact.getType(), null, new DefaultArtifactHandler(), false);
        if (isIncluded(artefactWithNewVersion)) {
            filteredNewer.add(artifactVersion);
        }/*from w  w  w.  j a va  2 s  .  c o m*/
    }
    return (ArtifactVersion[]) filteredNewer.toArray(new ArtifactVersion[filteredNewer.size()]);
}

From source file:org.jasig.maven.legal.stubs.BasicProjectStub.java

License:Apache License

/** {@inheritDoc} */
@Override/*from  www.  j a  v  a  2s . co  m*/
public Set<Artifact> getDependencyArtifacts() {
    Artifact artifact1 = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.1"),
            Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);

    Artifact artifact2 = new DefaultArtifact("org.apache.maven", "maven-project",
            VersionRange.createFromVersion("2.2.0"), Artifact.SCOPE_COMPILE, "jar", null,
            new DefaultArtifactHandler("jar"), false);

    final List<Artifact> artifacts = Arrays.asList(artifact1, artifact2);
    return Collections.unmodifiableSet(new LinkedHashSet<Artifact>(artifacts));
}

From source file:org.lqjacklee.maven.plugins.file.utils.AbstractCompilerMojo.java

License:Apache License

private List<String> resolveProcessorPathEntries() throws MojoExecutionException {
    if (annotationProcessorPaths == null || annotationProcessorPaths.isEmpty()) {
        return null;
    }//from w  w  w .  jav a2  s  . com

    try {
        Set<Artifact> requiredArtifacts = new LinkedHashSet<Artifact>();

        for (DependencyCoordinate coord : annotationProcessorPaths) {
            ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(coord.getType());

            Artifact artifact = new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(),
                    VersionRange.createFromVersionSpec(coord.getVersion()), Artifact.SCOPE_RUNTIME,
                    coord.getType(), coord.getClassifier(), handler, false);

            requiredArtifacts.add(artifact);
        }

        ArtifactResolutionRequest request = new ArtifactResolutionRequest()
                .setArtifact(requiredArtifacts.iterator().next()).setResolveRoot(true)
                .setResolveTransitively(true).setArtifactDependencies(requiredArtifacts)
                .setLocalRepository(session.getLocalRepository())
                .setRemoteRepositories(project.getRemoteArtifactRepositories());

        ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request);

        resolutionErrorHandler.throwErrors(request, resolutionResult);

        List<String> elements = new ArrayList<String>(resolutionResult.getArtifacts().size());

        for (Object resolved : resolutionResult.getArtifacts()) {
            elements.add(((Artifact) resolved).getFile().getAbsolutePath());
        }

        return elements;
    } catch (Exception e) {
        throw new MojoExecutionException(
                "Resolution of annotationProcessorPath dependencies failed: " + e.getLocalizedMessage(), e);
    }
}

From source file:uk.ac.ox.oucs.plugins.CustomArtifactFactory.java

License:Apache License

private Artifact createArtifact(String groupId, String artifactId, VersionRange versionRange, String type,
        String classifier, String scope, String inheritedScope, boolean optional) {
    // TODO: can refactor - inherited scope calculation belongs in the collector, use scope handler
    //System.out.println(groupId+":"+artifactId+":"+scope + " inheerited "+inheritedScope);
    String desiredScope = Artifact.SCOPE_RUNTIME;
    if (inheritedScope == null) {
        desiredScope = scope;//from w ww . j  av a2 s . c  o m
    } else if (Artifact.SCOPE_TEST.equals(scope)) {
        return null;
    }
    // This is the change.
    else if (Artifact.SCOPE_PROVIDED.equals(scope)) {
        // If we walk all provided deps we get too many artifacts not found...
        if (groupId.startsWith("org.sakaiproject")) {
            desiredScope = Artifact.SCOPE_PROVIDED;
        } else {
            return null;
        }
    } else if (Artifact.SCOPE_COMPILE.equals(scope) && Artifact.SCOPE_COMPILE.equals(inheritedScope)) {
        // added to retain compile scope. Remove if you want compile inherited as runtime
        desiredScope = Artifact.SCOPE_COMPILE;
    } else if (Artifact.SCOPE_SYSTEM.equals(scope)) {
        // system scopes come through unchanged...
        desiredScope = Artifact.SCOPE_SYSTEM;
    }

    if (Artifact.SCOPE_TEST.equals(inheritedScope)) {
        desiredScope = Artifact.SCOPE_TEST;
    }

    if (Artifact.SCOPE_PROVIDED.equals(inheritedScope)) {
        desiredScope = Artifact.SCOPE_PROVIDED;
    }

    ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(type);

    return new DefaultArtifact(groupId, artifactId, versionRange, desiredScope, type, classifier, handler,
            optional);
}