Search in sources :

Example 66 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository 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 67 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project sling by apache.

the class BundleInstallFileMojo method resolveBundleFileFromArtifact.

@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private String resolveBundleFileFromArtifact() throws MojoExecutionException {
    if (artifactId == null && artifact == null) {
        return null;
    }
    if (artifactId == null) {
        String[] tokens = StringUtils.split(artifact, ":");
        if (tokens.length != 3 && tokens.length != 4 && tokens.length != 5) {
            throw new MojoExecutionException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
        }
        groupId = tokens[0];
        artifactId = tokens[1];
        version = tokens[2];
        if (tokens.length >= 4)
            packaging = tokens[3];
        if (tokens.length == 5)
            classifier = tokens[4];
    }
    Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
    if (pomRemoteRepositories == null) {
        pomRemoteRepositories = new ArrayList();
    }
    List repoList = new ArrayList(pomRemoteRepositories);
    if (repositoryUrl != null) {
        ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
        ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl, repositoryLayout, policy, policy);
        repoList.add(remoteRepo);
    }
    try {
        artifactResolver.resolve(packageArtifact, repoList, localRepository);
        getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
    } catch (AbstractArtifactResolutionException e) {
        throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
    }
    return packageArtifact.getFile().getAbsolutePath();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 68 with ArtifactRepository

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

the class DependencyResolver method resolve.

public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
    if (resolvedDependencies != null) {
        return resolvedDependencies;
    }
    DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
    request.setResolutionFilter(new DependencyFilter() {

        @Override
        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            if (node.getDependency() != null) {
                return scopes.contains(node.getDependency().getScope());
            }
            return false;
        }
    });
    DependencyResolutionResult result;
    try {
        result = resolver.resolve(request);
    } catch (DependencyResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    Map<File, ArtifactResult> dependencies = new HashMap<>();
    DependencyNode dependencyGraph = result.getDependencyGraph();
    if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
        List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
        ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
        if (deployRepo != null) {
            remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
        }
        discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
    }
    return resolvedDependencies = dependencies;
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) File(java.io.File)

Example 69 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project sling by apache.

the class MavenSourceReferenceResolver method resolve.

@Override
public IRuntimeClasspathEntry resolve(SourceReference reference) throws CoreException {
    if (reference == null || reference.getType() != SourceReference.Type.MAVEN) {
        return null;
    }
    MavenSourceReference sr = (MavenSourceReference) reference;
    List<ArtifactRepository> repos = MavenPlugin.getMaven().getArtifactRepositories();
    Artifact jarArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "", repos, new NullProgressMonitor());
    Artifact sourcesArtifact = MavenPlugin.getMaven().resolve(sr.getGroupId(), sr.getArtifactId(), sr.getVersion(), "jar", "sources", repos, new NullProgressMonitor());
    IPath jarPath = Path.fromOSString(jarArtifact.getFile().getAbsolutePath());
    IPath sourcePath = Path.fromOSString(sourcesArtifact.getFile().getAbsolutePath());
    IRuntimeClasspathEntry mavenEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jarPath);
    mavenEntry.setSourceAttachmentPath(sourcePath);
    return mavenEntry;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) MavenSourceReference(org.apache.sling.ide.osgi.MavenSourceReference) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry)

Example 70 with ArtifactRepository

use of org.apache.maven.artifact.repository.ArtifactRepository in project felix by apache.

the class AbstractBundlePluginTest method getMavenProjectStub.

protected MavenProjectStub getMavenProjectStub() {
    MavenProjectStub project = new MavenProjectStub();
    project.setGroupId("group");
    project.setArtifactId("project");
    project.setVersion("1.2.3.4");
    VersionRange versionRange = VersionRange.createFromVersion(project.getVersion());
    ArtifactHandler artifactHandler = new DefaultArtifactHandler("pom");
    Artifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), versionRange, null, "pom", null, artifactHandler);
    artifact.setResolved(true);
    project.setArtifact(artifact);
    ProjectBuilderConfiguration projectBuilderConfiguration = new DefaultProjectBuilderConfiguration();
    ArtifactRepositoryLayout layout = new LegacyRepositoryLayout();
    ArtifactRepository artifactRepository = new DefaultArtifactRepository("scratch", new File(getBasedir(), "target" + File.separatorChar + "scratch").toURI().toString(), layout);
    projectBuilderConfiguration.setLocalRepository(artifactRepository);
    project.setProjectBuilderConfiguration(projectBuilderConfiguration);
    return project;
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultProjectBuilderConfiguration(org.apache.maven.project.DefaultProjectBuilderConfiguration) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) LegacyRepositoryLayout(org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout) VersionRange(org.apache.maven.artifact.versioning.VersionRange) DefaultArtifactRepository(org.apache.maven.artifact.repository.DefaultArtifactRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) ProjectBuilderConfiguration(org.apache.maven.project.ProjectBuilderConfiguration) DefaultProjectBuilderConfiguration(org.apache.maven.project.DefaultProjectBuilderConfiguration) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)108 File (java.io.File)46 Artifact (org.apache.maven.artifact.Artifact)26 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)26 ArrayList (java.util.ArrayList)23 MavenProject (org.apache.maven.project.MavenProject)20 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 IOException (java.io.IOException)13 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)13 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)11 Properties (java.util.Properties)10 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)9 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)9 Model (org.apache.maven.model.Model)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)8 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7