Search in sources :

Example 36 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.

the class DefaultRepositoryService method lookupBundle.

@Override
public File lookupBundle(BundleDependency bundleDependency) {
    try {
        if (remoteRepositories.isEmpty()) {
            throw new RepositoryServiceDisabledException("Repository service has not been configured so it's disabled. " + "To enable it you must configure the set of repositories to use using the system property: " + MULE_REMOTE_REPOSITORIES_PROPERTY);
        }
        DefaultArtifact artifact = toArtifact(bundleDependency);
        ArtifactRequest getArtifactRequest = new ArtifactRequest();
        getArtifactRequest.setRepositories(remoteRepositories);
        getArtifactRequest.setArtifact(artifact);
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, getArtifactRequest);
        return artifactResult.getArtifact().getFile();
    } catch (ArtifactResolutionException e) {
        if (e.getCause() instanceof ArtifactNotFoundException) {
            throw new BundleNotFoundException(e);
        } else {
            throw new RepositoryConnectionException("There was a problem connecting to one of the repositories", e);
        }
    }
}
Also used : RepositoryConnectionException(org.mule.runtime.module.repository.api.RepositoryConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RepositoryServiceDisabledException(org.mule.runtime.module.repository.api.RepositoryServiceDisabledException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) BundleNotFoundException(org.mule.runtime.module.repository.api.BundleNotFoundException)

Example 37 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.

the class ExtensionModelLoaderFinder method findLoaderByProperty.

/**
 * Searches in the plugin pom.xml for the {@code testExtensionModelLoaderId} property which specifies with which loader the
 * extension must be loaded. The main use of this is for Test Extensions that don't generate a mule-artifact.json.
 */
public Optional<ExtensionModelLoader> findLoaderByProperty(Artifact plugin, DependencyResolver dependencyResolver, List<RemoteRepository> rootArtifactRemoteRepositories) {
    DefaultArtifact artifact = new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), "pom", plugin.getVersion());
    try {
        ArtifactResult artifactResult = dependencyResolver.resolveArtifact(artifact, rootArtifactRemoteRepositories);
        File pomFile = artifactResult.getArtifact().getFile();
        Model mavenProject = MavenModelFactory.createMavenProject(pomFile);
        String id = mavenProject.getProperties().getProperty("testExtensionModelLoaderId");
        return id != null ? Optional.ofNullable(getLoaderById(id)) : Optional.empty();
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Cannot load extension, the artifact: [" + plugin.toString() + "] cannot be resolved", e);
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Model(org.apache.maven.model.Model) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 38 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.

the class AetherClassPathClassifierTestCase method before.

@Before
public void before() throws Exception {
    String muleVersion = getMuleVersion();
    this.rootArtifact = new DefaultArtifact("org.foo:foo-root:1.0-SNAPSHOT");
    this.loggingDep = new Dependency(new DefaultArtifact("org.mule.runtime:mule-module-logging:" + muleVersion), COMPILE);
    this.fooCoreDep = new Dependency(new DefaultArtifact("org.foo:foo-core:1.0-SNAPSHOT"), PROVIDED);
    this.fooToolsArtifactDep = new Dependency(new DefaultArtifact("org.foo.tools:foo-artifact:1.0-SNAPSHOT"), PROVIDED);
    this.fooTestsSupportDep = new Dependency(new DefaultArtifact("org.foo.tests:foo-tests-support:1.0-SNAPSHOT"), TEST);
    this.derbyDriverDep = new Dependency(new DefaultArtifact("org.apache.derby:derby:10.11.1.1"), TEST);
    this.guavaDep = new Dependency(new DefaultArtifact("org.google:guava:18.0"), COMPILE);
    serviceArtifact = new DefaultArtifact("org.foo:foo-service:jar:mule-service:1.0-SNAPSHOT");
    this.fooServiceDep = new Dependency(serviceArtifact, PROVIDED);
    this.dependencyResolver = mock(DependencyResolver.class);
    this.context = mock(ClassPathClassifierContext.class);
    this.artifactClassificationTypeResolver = mock(ArtifactClassificationTypeResolver.class);
    this.classifier = new AetherClassPathClassifier(dependencyResolver, artifactClassificationTypeResolver);
    when(context.getRootArtifact()).thenReturn(rootArtifact);
    this.directDependencies = newArrayList(fooCoreDep, fooToolsArtifactDep, fooTestsSupportDep, derbyDriverDep, guavaDep);
    when(dependencyResolver.getDirectDependencies(rootArtifact)).thenReturn(directDependencies);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 39 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.

the class DefaultWorkspaceReaderTestCase method before.

@Before
public void before() throws Exception {
    artifact = new DefaultArtifact(ORG_FOO_GROUP_ID, BAR, JAR, VERSION);
    bar = new File(temporaryFolder.newFolder(ORG_FOO_FOLDER), BAR);
    if (!bar.exists()) {
        assertThat(bar.mkdir(), is(true));
    }
    setUpTargetClassesFolder();
}
Also used : File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 40 with DefaultArtifact

use of org.eclipse.aether.artifact.DefaultArtifact in project mule by mulesoft.

the class ArtifactIsolatedClassLoaderBuilder method getRootArtifact.

/**
 * Gets the Maven artifact located at the given by reading the {@value #POM_XML} file two levels up from target/classes.
 *
 * @param rootArtifactClassesFolder {@link File} the rootArtifactClassesFolder
 * @return {@link Artifact} that represents the rootArtifact
 */
private Artifact getRootArtifact(File rootArtifactClassesFolder) {
    File pomFile = new File(rootArtifactClassesFolder.getParentFile().getParentFile(), POM_XML);
    logger.debug("Reading rootArtifact from pom file: {}", pomFile);
    Model model = MavenModelFactory.createMavenProject(pomFile);
    return new DefaultArtifact(model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId(), model.getArtifactId(), model.getPackaging(), model.getVersion() != null ? model.getVersion() : model.getParent().getVersion());
}
Also used : Model(org.apache.maven.model.Model) File(java.io.File) 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