Search in sources :

Example 71 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project drools by kiegroup.

the class MavenRepository method resolveVersion.

public Version resolveVersion(String artifactName) {
    Artifact artifact = new DefaultArtifact(artifactName);
    VersionRangeRequest versionRequest = new VersionRangeRequest();
    versionRequest.setArtifact(artifact);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        versionRequest.addRepository(repo);
    }
    try {
        VersionRangeResult versionRangeResult = aether.getSystem().resolveVersionRange(aether.getSession(), versionRequest);
        return versionRangeResult.getHighestVersion();
    } catch (VersionRangeResolutionException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unable to resolve version range for artifact: " + artifactName, e);
        } else {
            log.warn("Unable to resolve version range for artifact: " + artifactName);
        }
        return null;
    }
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 72 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project drools by kiegroup.

the class MavenRepository method deployArtifact.

/**
 * Deploys a jar on a remote repository.
 *
 * @param repository The remote repository where the kjar will be deployed
 * @param releaseId The releaseId with which the deployment will be made
 * @param jar The jar to be deployed
 * @param pomfile The pom file to be deployed together with the kjar
 */
public void deployArtifact(RemoteRepository repository, ReleaseId releaseId, File jar, File pomfile) {
    Artifact jarArtifact = new DefaultArtifact(releaseId.getGroupId(), releaseId.getArtifactId(), "jar", releaseId.getVersion());
    jarArtifact = jarArtifact.setFile(jar);
    Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom");
    pomArtifact = pomArtifact.setFile(pomfile);
    DeployRequest deployRequest = new DeployRequest();
    deployRequest.addArtifact(jarArtifact).addArtifact(pomArtifact).setRepository(repository);
    try {
        aether.getSystem().deploy(aether.getSession(), deployRequest);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
Also used : SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DeployRequest(org.eclipse.aether.deployment.DeployRequest) DeploymentException(org.eclipse.aether.deployment.DeploymentException) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 73 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project drools by kiegroup.

the class MavenRepository method getArtifactDependecies.

public List<DependencyDescriptor> getArtifactDependecies(String artifactName) {
    Artifact artifact = new DefaultArtifact(artifactName);
    CollectRequest collectRequest = new CollectRequest();
    Dependency root = new Dependency(artifact, "");
    collectRequest.setRoot(root);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        collectRequest.addRepository(repo);
    }
    CollectResult collectResult;
    try {
        collectResult = aether.getSystem().collectDependencies(aether.getSession(), collectRequest);
    } catch (DependencyCollectionException e) {
        throw new RuntimeException(e);
    }
    CollectDependencyVisitor visitor = new CollectDependencyVisitor();
    collectResult.getRoot().accept(visitor);
    List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>();
    for (DependencyNode node : visitor.getDependencies()) {
        // skip root to not add artifact as dependency
        if (node.getDependency().equals(root)) {
            continue;
        }
        descriptors.add(new DependencyDescriptor(node.getDependency().getArtifact()));
    }
    return descriptors;
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 74 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project drools by kiegroup.

the class MavenRepository method deployPomArtifact.

public void deployPomArtifact(String groupId, String artifactId, String version, File pomfile) {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
    pomArtifact = pomArtifact.setFile(pomfile);
    DeployRequest deployRequest = new DeployRequest();
    deployRequest.addArtifact(pomArtifact).setRepository(aether.getLocalRepository());
    try {
        aether.getSystem().deploy(aether.getSession(), deployRequest);
    } catch (DeploymentException e) {
        throw new RuntimeException(e);
    }
}
Also used : DeployRequest(org.eclipse.aether.deployment.DeployRequest) DeploymentException(org.eclipse.aether.deployment.DeploymentException) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 75 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project kie-wb-common by kiegroup.

the class MavenDependencyConfigExecutorTest method installArtifactLocally.

private void installArtifactLocally(final String groupId, final String artifactId, final String version) throws Exception {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
    final Path pom = getPom(groupId, artifactId, version);
    pomArtifact = pomArtifact.setFile(pom.toFile());
    final InstallRequest installRequest = new InstallRequest();
    installRequest.addArtifact(pomArtifact);
    final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    RepositorySystem system = locator.getService(RepositorySystem.class);
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    final LocalRepository localRepo = new LocalRepository(m2Folder);
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
    system.install(session, installRequest);
}
Also used : Path(java.nio.file.Path) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InstallRequest(org.eclipse.aether.installation.InstallRequest) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)110 Artifact (org.eclipse.aether.artifact.Artifact)70 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)42 File (java.io.File)39 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)34 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)29 IOException (java.io.IOException)24 Dependency (org.eclipse.aether.graph.Dependency)23 ArrayList (java.util.ArrayList)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)13 CollectRequest (org.eclipse.aether.collection.CollectRequest)12 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)12 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)12 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)12 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)12 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)11 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)10 Version (org.eclipse.aether.version.Version)10 Model (org.apache.maven.model.Model)9 RepositorySystem (org.eclipse.aether.RepositorySystem)9