Search in sources :

Example 31 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project xwiki-commons by xwiki.

the class AetherExtensionRepository method downloadPom.

private Artifact downloadPom(Artifact artifact, RepositorySystemSession session) throws VersionResolutionException, ArtifactResolutionException {
    List<RemoteRepository> repositories = newResolutionRepositories(session);
    Artifact pomArtifact = resolveVersion(artifact, repositories, session);
    // Download pom file
    ArtifactRequest resolveRequest = new ArtifactRequest(pomArtifact, repositories, "");
    ArtifactResult resolveResult = this.artifactResolver.resolveArtifact(session, resolveRequest);
    pomArtifact = resolveResult.getArtifact();
    return pomArtifact;
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 32 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project xwiki-commons by xwiki.

the class AetherExtensionRepository method createModel.

private Model createModel(File pomFile, RepositorySystemSession session) throws ModelBuildingException {
    // Search for parent pom in all available Aether repositories
    List<RemoteRepository> repositories = newResolutionRepositories(session, true);
    ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest();
    modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    modelRequest.setProcessPlugins(false);
    modelRequest.setTwoPhaseBuilding(false);
    modelRequest.setSystemProperties(toProperties(session.getUserProperties(), session.getSystemProperties()));
    modelRequest.setModelResolver(new ProjectModelResolver(session, null, this.repositorySystem, this.remoteRepositoryManager, repositories, RepositoryMerging.POM_DOMINANT, null));
    modelRequest.setPomFile(pomFile);
    modelRequest.setActiveProfileIds(Arrays.asList("legacy"));
    return this.modelBuilder.build(modelRequest).getEffectiveModel();
}
Also used : ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ProjectModelResolver(org.apache.maven.project.ProjectModelResolver) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 33 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project xwiki-commons by xwiki.

the class MavenBuildExtensionRepository method openStream.

/**
 * {@inheritDoc}
 * <p>
 * Override standard {@link #openStream(org.eclipse.aether.artifact.Artifact)} to reuse running Maven session which
 * is much faster.
 *
 * @see org.xwiki.extension.repository.aether.internal.AetherExtensionRepository#openStream(org.eclipse.aether.artifact.Artifact)
 */
@Override
public InputStream openStream(org.eclipse.aether.artifact.Artifact artifact) throws IOException {
    XWikiRepositorySystemSession session = createRepositorySystemSession();
    List<RemoteRepository> repositories = newResolutionRepositories(session);
    // /////////////////////////////////////////////////////////////////////////////:
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setRepositories(repositories);
    ArtifactType artifactType = XWikiRepositorySystemSession.TYPE_MAPPING.get(artifact.getExtension());
    if (artifactType == null) {
        artifactRequest.setArtifact(artifact);
    } else {
        artifactRequest.setArtifact(new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifactType.getExtension(), artifact.getVersion()));
    }
    ArtifactResult artifactResult;
    try {
        RepositorySystem repositorySystem = getRepositorySystem();
        artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
    } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
        throw new IOException("Failed to resolve artifact", e);
    }
    File aetherFile = artifactResult.getArtifact().getFile();
    return new AetherExtensionFileInputStream(aetherFile, false);
}
Also used : RemoteRepository(org.eclipse.aether.repository.RemoteRepository) IOException(java.io.IOException) XWikiRepositorySystemSession(org.xwiki.extension.repository.aether.internal.XWikiRepositorySystemSession) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactType(org.eclipse.aether.artifact.ArtifactType) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 34 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project resteasy by resteasy.

the class MavenUtil method createMavenGavFile.

public File createMavenGavFile(String artifactGav) throws MalformedURLException {
    Artifact artifact = new DefaultArtifact(artifactGav);
    if (artifact.getVersion() == null) {
        throw new IllegalArgumentException("Null version");
    }
    VersionScheme versionScheme = new GenericVersionScheme();
    try {
        versionScheme.parseVersion(artifact.getVersion());
    } catch (InvalidVersionSpecificationException e) {
        throw new IllegalArgumentException(e);
    }
    try {
        versionScheme.parseVersionRange(artifact.getVersion());
        throw new IllegalArgumentException(artifact.getVersion() + " is a version range. A specific version is needed");
    } catch (InvalidVersionSpecificationException expected) {
    }
    RepositorySystemSession session = newRepositorySystemSession();
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    for (RemoteRepository remoteRepo : remoteRepositories) {
        artifactRequest.addRepository(remoteRepo);
    }
    ArtifactResult artifactResult;
    try {
        artifactResult = REPOSITORY_SYSTEM.resolveArtifact(session, artifactRequest);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(e);
    }
    File file = artifactResult.getArtifact().getFile().getAbsoluteFile();
    return file;
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) VersionScheme(org.eclipse.aether.version.VersionScheme) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 35 with RemoteRepository

use of org.eclipse.aether.repository.RemoteRepository in project resteasy by resteasy.

the class MavenUtil method createRemoteRepositories.

private static List<RemoteRepository> createRemoteRepositories(boolean useEapRepository) {
    // prepare proxy
    String httpProxyHost = System.getProperty(String.format("%s%s", PROXY_HTTP_PREFIX, PROXY_HOST));
    String httpsProxyHost = System.getProperty(String.format("%s%s", PROXY_HTTPS_PREFIX, PROXY_HOST));
    Integer httpProxyPort = getProxyPort(String.format("%s%s", PROXY_HTTP_PREFIX, PROXY_PORT));
    Integer httpsProxyPort = getProxyPort(String.format("%s%s", PROXY_HTTPS_PREFIX, PROXY_PORT));
    Proxy httpProxy = null;
    Proxy httpsProxy = null;
    if (httpProxyHost != null && httpProxyPort != null && !httpProxyHost.isEmpty()) {
        httpProxy = new Proxy(Proxy.TYPE_HTTP, httpProxyHost, httpProxyPort);
    }
    if (httpsProxyHost != null && httpsProxyPort != null && !httpsProxyHost.isEmpty()) {
        httpsProxy = new Proxy(Proxy.TYPE_HTTPS, httpsProxyHost, httpsProxyPort);
    }
    List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();
    if (useEapRepository) {
        RemoteRepository.Builder repository = new RemoteRepository.Builder("product-repository", "default", "https://maven.repository.redhat.com/nexus/content/groups/product-techpreview/");
        if (httpsProxy != null) {
            repository.setProxy(httpsProxy);
        }
        remoteRepositories.add(repository.build());
    }
    // always add jboss developer repository
    RemoteRepository.Builder repository = new RemoteRepository.Builder("jboss-developer", "default", "http://repository.jboss.org/nexus/content/groups/developer/");
    if (httpProxy != null) {
        repository.setProxy(httpProxy);
    }
    remoteRepositories.add(repository.build());
    // always add default maven repository
    RemoteRepository.Builder repository2 = new RemoteRepository.Builder("maven-default", "default", "https://repo.maven.apache.org/maven2/");
    if (httpProxy != null) {
        repository2.setProxy(httpProxy);
    }
    remoteRepositories.add(repository2.build());
    return remoteRepositories;
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Aggregations

RemoteRepository (org.eclipse.aether.repository.RemoteRepository)258 File (java.io.File)69 ArrayList (java.util.ArrayList)66 Artifact (org.eclipse.aether.artifact.Artifact)59 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)59 Test (org.junit.Test)52 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)46 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)43 RepositorySystem (org.eclipse.aether.RepositorySystem)40 IOException (java.io.IOException)36 Dependency (org.eclipse.aether.graph.Dependency)36 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)36 RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)29 Proxy (org.eclipse.aether.repository.Proxy)28 AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)27 CollectRequest (org.eclipse.aether.collection.CollectRequest)26 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)26 List (java.util.List)25 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)24 Map (java.util.Map)22