Search in sources :

Example 26 with DefaultArtifact

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

the class ResourceResolver method createResourceArtifact.

private Artifact createResourceArtifact(final Artifact artifact, final String classifier, final SourceResolverConfig config) {
    final DefaultArtifact a = (DefaultArtifact) artifactFactory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "jar", classifier);
    a.setRepository(artifact.getRepository());
    return a;
}
Also used : DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 27 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project asterixdb by apache.

the class SourcePointerResolver method ensureCDDLSourcesPointer.

private void ensureCDDLSourcesPointer(Collection<Project> projects, ArtifactRepository central, ArtifactResolutionRequest request) throws ProjectBuildingException, IOException {
    for (Project p : projects) {
        if (p.getSourcePointer() != null) {
            continue;
        }
        mojo.getLog().debug("finding sources for artifact: " + p);
        Artifact sourcesArtifact = new DefaultArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), Artifact.SCOPE_COMPILE, "jar", "sources", null);
        MavenProject mavenProject = mojo.resolveDependency(sourcesArtifact);
        sourcesArtifact.setArtifactHandler(mavenProject.getArtifact().getArtifactHandler());
        final ArtifactRepository localRepo = mojo.getSession().getLocalRepository();
        final File marker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".oncentral");
        final File antimarker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".nocentral");
        boolean onCentral;
        if (marker.exists() || antimarker.exists()) {
            onCentral = marker.exists();
        } else {
            request.setArtifact(sourcesArtifact);
            ArtifactResolutionResult result = mojo.getArtifactResolver().resolve(request);
            mojo.getLog().debug("result: " + result);
            onCentral = result.isSuccess();
            if (onCentral) {
                FileUtils.touch(marker);
            } else {
                FileUtils.touch(antimarker);
            }
        }
        StringBuilder noticeBuilder = new StringBuilder("You may obtain ");
        noticeBuilder.append(p.getName()).append(" in Source Code form code here:\n");
        if (onCentral) {
            noticeBuilder.append(central.getUrl()).append("/").append(central.pathOf(sourcesArtifact));
        } else {
            mojo.getLog().warn("Unable to find sources in 'central' for " + p + ", falling back to project url: " + p.getUrl());
            noticeBuilder.append(p.getUrl() != null ? p.getUrl() : "MISSING SOURCE POINTER");
        }
        p.setSourcePointer(noticeBuilder.toString());
    }
}
Also used : Project(org.apache.hyracks.maven.license.project.Project) MavenProject(org.apache.maven.project.MavenProject) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 28 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project sling by apache.

the class ModelUtils method getArtifact.

/**
     * Get a resolved Artifact from the coordinates provided
     *
     * @return the artifact, which has been resolved.
     * @throws MojoExecutionException
     */
public static Artifact getArtifact(final MavenProject project, final MavenSession session, final ArtifactHandlerManager artifactHandlerManager, final ArtifactResolver resolver, final String groupId, final String artifactId, final String version, final String type, final String classifier) throws MojoExecutionException {
    final Set<Artifact> artifacts = project.getDependencyArtifacts();
    for (final Artifact artifact : artifacts) {
        if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type) && ((classifier == null && artifact.getClassifier() == null) || (classifier != null && classifier.equals(artifact.getClassifier())))) {
            return artifact;
        }
    }
    final Artifact prjArtifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version), Artifact.SCOPE_PROVIDED, type, classifier, artifactHandlerManager.getArtifactHandler(type));
    try {
        resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
    } catch (final ArtifactResolutionException e) {
        throw new MojoExecutionException("Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
    } catch (final ArtifactNotFoundException e) {
        throw new MojoExecutionException("Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
    }
    return prjArtifact;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 29 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project bnd by bndtools.

the class IndexerMojo method attach.

private void attach(File file, String type, String extension) {
    DefaultArtifactHandler handler = new DefaultArtifactHandler(type);
    handler.setExtension(extension);
    DefaultArtifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, type, null, handler);
    artifact.setFile(file);
    project.addAttachedArtifact(artifact);
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 30 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project sling by apache.

the class PreparePackageMojoTest method getMavenArtifact.

private org.apache.maven.artifact.Artifact getMavenArtifact(File repoRoot, ArtifactHandler ah, String gid, String aid, String ver, String classifier) {
    DefaultArtifact art = new DefaultArtifact(gid, aid, ver, "compile", "jar", classifier, ah);
    art.setFile(getMavenArtifactFile(repoRoot, gid, aid, ver));
    return art;
}
Also used : DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)51 Artifact (org.apache.maven.artifact.Artifact)35 File (java.io.File)26 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)26 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)22 VersionRange (org.apache.maven.artifact.versioning.VersionRange)17 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)10 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)10 MavenProject (org.apache.maven.project.MavenProject)9 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 InputStream (java.io.InputStream)3 List (java.util.List)3 Map (java.util.Map)3 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2