Search in sources :

Example 71 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method getJenkinsWar.

/**
 * Get the file with Jenkins to run.
 *
 * The file will exist on machine where tests run.
 */
@Provides
@Named("jenkins.war")
public File getJenkinsWar(RepositorySystem repositorySystem, RepositorySystemSession repositorySystemSession) {
    try {
        return IOUtil.firstExisting(false, System.getenv("JENKINS_WAR"));
    } catch (IOException ex) {
    }
    String version = System.getenv("JENKINS_VERSION");
    if (version != null && !version.isEmpty()) {
        ArtifactResolverUtil resolverUtil = new ArtifactResolverUtil(repositorySystem, repositorySystemSession);
        ArtifactResult resolvedArtifact = resolverUtil.resolve(new DefaultArtifact("org.jenkins-ci.main", "jenkins-war", "war", version));
        return resolvedArtifact.getArtifact().getFile();
    }
    try {
        // Lowest priority of all
        return IOUtil.firstExisting(false, System.getenv("JENKINS_WAR"), getWorkspace() + "/jenkins.war", "./jenkins.war");
    } catch (IOException ex) {
        throw new Error("Could not find jenkins.war, use JENKINS_WAR or JENKINS_VERSION to specify it.", ex);
    }
}
Also used : IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResolverUtil(org.jenkinsci.test.acceptance.utils.aether.ArtifactResolverUtil) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Named(javax.inject.Named) Provides(com.google.inject.Provides)

Example 72 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method getFormElementsPathFile.

/**
 * Provides the path to the form elements plug-in. Uses the Maven repository to obtain the plugin.
 *
 * @return the path to the form elements plug-in
 */
@Named("form-element-path.hpi")
@Provides
public File getFormElementsPathFile(RepositorySystem repositorySystem, RepositorySystemSession repositorySystemSession) {
    ArtifactResolverUtil resolverUtil = new ArtifactResolverUtil(repositorySystem, repositorySystemSession);
    String version = System.getenv("FORM_ELEMENT_PATH_VERSION");
    version = version == null ? "1.12" : version;
    ArtifactResult resolvedArtifact = resolverUtil.resolve(new DefaultArtifact("org.jenkins-ci.plugins", "form-element-path", "hpi", version));
    return resolvedArtifact.getArtifact().getFile();
}
Also used : DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResolverUtil(org.jenkinsci.test.acceptance.utils.aether.ArtifactResolverUtil) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Named(javax.inject.Named) Provides(com.google.inject.Provides)

Example 73 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project acceptance-test-harness by jenkinsci.

the class ArtifactResolverUtil method resolve.

/**
 * @param artifact The artifact to be resolved
 *
 * @return artifact resolution result
 */
public ArtifactResult resolve(DefaultArtifact artifact) {
    Builder repoBuilder = new RemoteRepository.Builder("repo.jenkins-ci.org", "default", "https://repo.jenkins-ci.org/public/");
    DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
    File userHome = new File(System.getProperty("user.home"));
    File userSettingsFile = new File(new File(userHome, ".m2"), "settings.xml");
    request.setUserSettingsFile(userSettingsFile);
    if (userSettingsFile.exists()) {
        LOGGER.config("Found maven settings file - " + userSettingsFile.getAbsolutePath());
        SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
        try {
            Settings settings = settingsBuilder.build(request).getEffectiveSettings();
            org.apache.maven.settings.Proxy mavenActiveproxy = settings.getActiveProxy();
            if (mavenActiveproxy != null) {
                LOGGER.config("Found maven proxy settings. Will use for artifact resolution");
                repoBuilder.setProxy(asProxy(mavenActiveproxy));
            } else {
                LOGGER.config("Did not find an active proxy in maven settings xml file");
            }
        } catch (SettingsBuildingException e) {
            LOGGER.log(Level.WARNING, "Could not find or load settings.xml to attempt to user proxy settings.", e);
        }
    }
    RemoteRepository repo = repoBuilder.build();
    ArtifactResult r;
    try {
        r = repoSystem.resolveArtifact(repoSystemSession, new ArtifactRequest(artifact, Arrays.asList(repo), null));
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve " + artifact + " from Maven repository", e);
    }
    LOGGER.config("Found " + r);
    return r;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Builder(org.eclipse.aether.repository.RemoteRepository.Builder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Example 74 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project acceptance-test-harness by jenkinsci.

the class PluginMetadata method resolve.

public File resolve(Injector i, String version) {
    DefaultArtifact artifact = getDefaultArtifact();
    if (version != null) {
        artifact.setVersion(version);
    }
    ArtifactResolverUtil resolverUtil = i.getInstance(ArtifactResolverUtil.class);
    ArtifactResult r = resolverUtil.resolve(artifact);
    return r.getArtifact().getFile();
}
Also used : DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResolverUtil(org.jenkinsci.test.acceptance.utils.aether.ArtifactResolverUtil) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 75 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getLatestVersionString.

public String getLatestVersionString() {
    Artifact lastArt = new DefaultArtifact(groupId, artifactId, "jar", "LATEST");
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(lastArt);
    request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    try {
        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
        return resolveArtifact.getArtifact().getVersion();
    } catch (ArtifactResolutionException e1) {
        e1.printStackTrace();
    }
    return null;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)83 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)53 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)51 Artifact (org.eclipse.aether.artifact.Artifact)41 File (java.io.File)37 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)37 IOException (java.io.IOException)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)16 ArrayList (java.util.ArrayList)15 Dependency (org.eclipse.aether.graph.Dependency)15 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)13 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 CollectRequest (org.eclipse.aether.collection.CollectRequest)11 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)10 FileNotFoundException (java.io.FileNotFoundException)9 RepositorySystem (org.eclipse.aether.RepositorySystem)8 Test (org.junit.Test)8 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)7