Search in sources :

Example 21 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult 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 22 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.

the class TychoOsgiRuntimeLocator method resolveDependency.

public Artifact resolveDependency(MavenSession session, Dependency dependency) throws MavenExecutionException {
    Artifact artifact = repositorySystem.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getType());
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setLocalRepository(session.getLocalRepository());
    request.setRemoteRepositories(getPluginRepositories(session));
    request.setCache(session.getRepositoryCache());
    request.setOffline(session.isOffline());
    request.setProxies(session.getSettings().getProxies());
    request.setForceUpdate(session.getRequest().isUpdateSnapshots());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    try {
        resolutionErrorHandler.throwErrors(request, result);
    } catch (ArtifactResolutionException e) {
        throw new MavenExecutionException("Could not resolve artifact for Tycho's OSGi runtime", e);
    }
    return artifact;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Example 23 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.

the class TestMojo method getFrameworkExtensions.

private List<File> getFrameworkExtensions() throws MojoExecutionException {
    List<File> files = new ArrayList<>();
    if (frameworkExtensions != null) {
        for (Dependency frameworkExtension : frameworkExtensions) {
            Artifact artifact = repositorySystem.createDependencyArtifact(frameworkExtension);
            ArtifactResolutionRequest request = new ArtifactResolutionRequest();
            request.setArtifact(artifact);
            request.setResolveRoot(true).setResolveTransitively(false);
            request.setLocalRepository(session.getLocalRepository());
            // XXX wrong repositories -- these are user artifacts, not plugin artifacts
            request.setRemoteRepositories(project.getPluginArtifactRepositories());
            request.setOffline(session.isOffline());
            request.setForceUpdate(session.getRequest().isUpdateSnapshots());
            ArtifactResolutionResult result = repositorySystem.resolve(request);
            try {
                resolutionErrorHandler.throwErrors(request, result);
            } catch (ArtifactResolutionException e) {
                throw new MojoExecutionException("Failed to resolve framework extension " + frameworkExtension.getManagementKey(), e);
            }
            files.add(artifact.getFile());
        }
    }
    return files;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 24 with ArtifactResolutionResult

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

the class AbstractCompilerMojo method resolveProcessorPathEntries.

private List<String> resolveProcessorPathEntries() throws MojoExecutionException {
    if (annotationProcessorPaths == null || annotationProcessorPaths.isEmpty()) {
        return null;
    }
    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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) CompilerException(org.codehaus.plexus.compiler.CompilerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompilerNotImplementedException(org.codehaus.plexus.compiler.CompilerNotImplementedException) NoSuchCompilerException(org.codehaus.plexus.compiler.manager.NoSuchCompilerException) IOException(java.io.IOException) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 25 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.

the class AbstractOsgiCompilerMojo method getClasspath.

@Override
public List<ClasspathEntry> getClasspath() throws MojoExecutionException {
    TychoProject projectType = getBundleProject();
    ArrayList<ClasspathEntry> classpath = new ArrayList<>(((BundleProject) projectType).getClasspath(project));
    if (extraClasspathElements != null) {
        ArtifactRepository localRepository = session.getLocalRepository();
        List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
        for (Dependency extraDependency : extraClasspathElements) {
            Artifact artifact = repositorySystem.createDependencyArtifact(extraDependency);
            ArtifactResolutionRequest request = new ArtifactResolutionRequest();
            request.setArtifact(artifact);
            request.setLocalRepository(localRepository);
            request.setRemoteRepositories(remoteRepositories);
            request.setResolveRoot(true);
            request.setResolveTransitively(true);
            ArtifactResolutionResult result = repositorySystem.resolve(request);
            if (result.hasExceptions()) {
                throw new MojoExecutionException("Could not resolve extra classpath entry", result.getExceptions().get(0));
            }
            for (Artifact b : result.getArtifacts()) {
                MavenProject bProject = null;
                if (b instanceof ProjectArtifact) {
                    bProject = ((ProjectArtifact) b).getProject();
                }
                ArrayList<File> bLocations = new ArrayList<>();
                // TODO properly handle multiple project locations maybe
                bLocations.add(b.getFile());
                classpath.add(new DefaultClasspathEntry(DefaultReactorProject.adapt(bProject), null, bLocations, null));
            }
        }
    }
    return classpath;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact) ProjectArtifact(org.apache.maven.project.artifact.ProjectArtifact) DefaultClasspathEntry(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry) MavenProject(org.apache.maven.project.MavenProject) TychoProject(org.eclipse.tycho.core.TychoProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ProjectArtifact(org.apache.maven.project.artifact.ProjectArtifact) DefaultClasspathEntry(org.eclipse.tycho.core.osgitools.DefaultClasspathEntry) ClasspathEntry(org.eclipse.tycho.classpath.ClasspathEntry) File(java.io.File)

Aggregations

ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)26 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)20 Artifact (org.apache.maven.artifact.Artifact)19 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 MavenProject (org.apache.maven.project.MavenProject)9 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)5 LinkedHashSet (java.util.LinkedHashSet)4 Dependency (org.apache.maven.model.Dependency)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 MavenExecutionException (org.apache.maven.MavenExecutionException)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2