org.eclipse.aether.repository.RemoteRepository Java Examples

The following examples show how to use org.eclipse.aether.repository.RemoteRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenConfig.java    From galleon with Apache License 2.0 6 votes vote down vote up
public RemoteRepository buildRemoteRepository(MavenRemoteRepository repo, MavenProxySelector selector, Proxy proxy) throws ArtifactException {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(repo.getName(),
            repo.getType(), repo.getUrl());
    builder.setSnapshotPolicy(new org.eclipse.aether.repository.RepositoryPolicy(repo.getEnableSnapshot() == null ? isSnapshotEnabled() : repo.getEnableSnapshot(),
            repo.getSnapshotUpdatePolicy() == null ? getDefaultSnapshotPolicy() : repo.getSnapshotUpdatePolicy(),
            CHECKSUM_POLICY_WARN));
    builder.setReleasePolicy(new org.eclipse.aether.repository.RepositoryPolicy(repo.getEnableRelease() == null ? isReleaseEnabled() : repo.getEnableRelease(),
            repo.getReleaseUpdatePolicy() == null ? getDefaultReleasePolicy() : repo.getReleaseUpdatePolicy(),
            CHECKSUM_POLICY_WARN));
    try {
        if (selector != null && selector.proxyFor(new URL(repo.getUrl()).getHost())) {
            builder.setProxy(proxy);
        }
    } catch (MalformedURLException ex) {
        throw new ArtifactException(ex.getMessage(), ex);
    }
    return builder.build();
}
 
Example #2
Source File: MavenResourceTests.java    From spring-cloud-deployer with Apache License 2.0 6 votes vote down vote up
@Test
public void localResolutionSucceedsIfCached() throws Exception {
	String coordinates = "org.springframework.cloud.task.app:timestamp-task:jar:1.0.0.BUILD-SNAPSHOT";
	MavenProperties properties1 = new MavenProperties();
	String tempLocalRepo = System.getProperty("java.io.tmpdir") + File.separator + ".m2-test3";
	new File(tempLocalRepo).deleteOnExit();
	properties1.setLocalRepository(tempLocalRepo);
	Map<String, MavenProperties.RemoteRepository> remoteRepositoryMap = new HashMap<>();
	remoteRepositoryMap.put("default",
			new MavenProperties.RemoteRepository("https://repo.spring.io/libs-snapshot-local"));
	properties1.setRemoteRepositories(remoteRepositoryMap);
	MavenResource resource = MavenResource.parse(coordinates, properties1);
	resource.getFile();

	// no remotes; should not fail anymore
	MavenProperties properties2 = new MavenProperties();
	properties2.setLocalRepository(tempLocalRepo);
	properties2.setOffline(true);
	resource = new MavenResource.Builder(properties2)
			.artifactId("timestamp-task")
			.groupId("org.springframework.cloud.task.app")
			.version("1.0.0.BUILD-SNAPSHOT")
			.build();
	resource.getFile();
}
 
Example #3
Source File: EclipseAetherArtifactResolver.java    From wildfly-maven-plugin with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Path resolve(final RepositorySystemSession session, final List<RemoteRepository> repositories, final ArtifactName name) {
    final ArtifactResult result;
    try {
        final ArtifactRequest request = new ArtifactRequest();
        final Artifact defaultArtifact = new DefaultArtifact(name.getGroupId(), name.getArtifactId(), name.getClassifier(), name.getPackaging(), name.getVersion());
        request.setArtifact(defaultArtifact);
        request.setRepositories(repositories);
        result = repoSystem.resolveArtifact(session, request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    if (!result.isResolved()) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    final Artifact artifact = result.getArtifact();
    final File artifactFile;
    if (artifact == null || (artifactFile = artifact.getFile()) == null) {
        throw new RuntimeException("Failed to resolve artifact " + name);
    }
    return artifactFile.toPath();
}
 
Example #4
Source File: MetadataVerificationTests.java    From start.spring.io with Apache License 2.0 6 votes vote down vote up
private List<RemoteRepository> getRepositories(Dependency dependency, Version bootVersion,
		List<BillOfMaterials> boms) {
	Map<String, RemoteRepository> repositories = new HashMap<>();
	repositories.put("central", DependencyResolver.mavenCentral);
	String dependencyRepository = dependency.getRepository();
	if (dependencyRepository != null) {
		repositories.computeIfAbsent(dependencyRepository, this::repositoryForId);
	}
	for (BillOfMaterials bom : boms) {
		for (String repository : bom.getRepositories()) {
			repositories.computeIfAbsent(repository, this::repositoryForId);
		}
	}
	if (!bootVersion.getQualifier().getId().equals("RELEASE")) {
		repositories.computeIfAbsent("spring-milestones", this::repositoryForId);
		if (bootVersion.getQualifier().getId().contains("SNAPSHOT")) {
			repositories.computeIfAbsent("spring-snapshots", this::repositoryForId);
		}
	}
	return new ArrayList<>(repositories.values());
}
 
Example #5
Source File: AetherStubDownloader.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
/**
 * Used by the Maven Plugin.
 * @param repositorySystem Maven repository system
 * @param remoteRepositories remote artifact repositories
 * @param session repository system session
 */
public AetherStubDownloader(RepositorySystem repositorySystem,
		List<RemoteRepository> remoteRepositories, RepositorySystemSession session,
		Settings settings) {
	this.deleteStubsAfterTest = true;
	this.remoteRepos = remoteRepositories;
	this.settings = settings;
	this.repositorySystem = repositorySystem;
	this.session = session;
	if (remoteReposMissing()) {
		log.error(
				"Remote repositories for stubs are not specified and work offline flag wasn't passed");
	}
	this.workOffline = false;
	registerShutdownHook();
}
 
Example #6
Source File: PomReposMirroredTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void basicPomRepos() throws Exception {
    final BootstrapMavenContext mvn = bootstrapMavenContextWithSettings("custom-settings/pom-repos-mirrored");

    final List<RemoteRepository> repos = mvn.getRemoteRepositories();
    assertEquals(1, repos.size());

    RemoteRepository repo = repos.get(0);
    assertEquals("private-repo", repo.getId());
    assertNull(repo.getProxy());
    assertNotNull(repo.getAuthentication());

    List<RemoteRepository> mirroredRepos = repo.getMirroredRepositories();
    assertNotNull(mirroredRepos);
    assertEquals(MIRRORED.size(), mirroredRepos.size());
    for (RemoteRepository r : mirroredRepos) {
        assertTrue(MIRRORED.containsKey(r.getId()));
        assertEquals(MIRRORED.get(r.getId()), r.getUrl());
    }
}
 
Example #7
Source File: MavenArtifactResolvingHelperTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Test
// SWARM-1173: swarm-plugin trying to download SNAPSHOTs from Maven Central
public void propagateRepositoryPolicies() {
    MavenArtifactResolvingHelper artifactResolverHelper = new MavenArtifactResolvingHelper(null, null, sessionMock, null);
    ArtifactRepositoryPolicy testSnapshotPolicy = new ArtifactRepositoryPolicy(false, "hourly", "warn");
    ArtifactRepositoryPolicy testReleasesPolicy = new ArtifactRepositoryPolicy(true, "never", "warn");
    ArtifactRepository testingRepo = new MavenArtifactRepository("testing-repo", "http://testing-repo.org", new DefaultRepositoryLayout(), testSnapshotPolicy, testReleasesPolicy);
    artifactResolverHelper.remoteRepository(testingRepo);

    List<RemoteRepository> remoteRepos = artifactResolverHelper.getRemoteRepositories();

    Assert.assertTrue("Remote repositories " + remoteRepos + " do not contain expected testing repo " + testingRepo,
                      remoteRepos.stream().anyMatch(
                              remoteRepo -> {
                                  RepositoryPolicy snapshotsPolicy = remoteRepo.getPolicy(true);
                                  RepositoryPolicy releasesPolicy = remoteRepo.getPolicy(false);
                                  return remoteRepo.getId().equals(testingRepo.getId()) &&
                                          !snapshotsPolicy.isEnabled() &&
                                          snapshotsPolicy.getUpdatePolicy().equals(testSnapshotPolicy.getUpdatePolicy()) &&
                                          snapshotsPolicy.getChecksumPolicy().equals(testSnapshotPolicy.getChecksumPolicy()) &&
                                          releasesPolicy.isEnabled() &&
                                          releasesPolicy.getUpdatePolicy().equals(testReleasesPolicy.getUpdatePolicy()) &&
                                          releasesPolicy.getChecksumPolicy().equals(testReleasesPolicy.getChecksumPolicy());
                              })
    );
}
 
Example #8
Source File: DevServerMojo.java    From yawp with MIT License 6 votes vote down vote up
public String resolveDevServerJar() {
    String version = getYawpVersion();
    List<RemoteRepository> allRepos = ImmutableList.copyOf(Iterables.concat(getProjectRepos()));

    ArtifactRequest request = new ArtifactRequest(new DefaultArtifact(YAWP_GROUP_ID, YAWP_DEVSERVER_ARTIFACT_ID, "jar", version), allRepos,
            null);

    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new RuntimeException("Could not resolve DevServer artifact in Maven.");
    }

    return result.getArtifact().getFile().getPath();
}
 
Example #9
Source File: SdkResolver.java    From gcloud-maven-plugin with Apache License 2.0 6 votes vote down vote up
public static File getSdk(MavenProject project, RepositorySystem repoSystem,
    RepositorySystemSession repoSession, List<RemoteRepository>... repos)
    throws MojoExecutionException {
  Artifact artifact = find(project.getPluginArtifacts(), new Predicate<Artifact>() {
    @Override
    public boolean apply(Artifact artifact1) {
      return artifact1.getArtifactId().equals("gcloud-maven-plugin");
    }
  });

  String version = artifact.getVersion();

  if (version.endsWith("-SNAPSHOT")) {
    String newestVersion = determineNewestVersion(repoSystem, repoSession, repos);
    return getSdk(newestVersion, repoSystem, repoSession, repos);
  }

  return getSdk("1.9.42", repoSystem, repoSession, repos);
}
 
Example #10
Source File: DependencyResolver.java    From start.spring.io with Apache License 2.0 6 votes vote down vote up
static List<String> resolveDependencies(String groupId, String artifactId, String version,
		List<BillOfMaterials> boms, List<RemoteRepository> repositories) {
	DependencyResolver instance = instanceForThread.get();
	List<Dependency> managedDependencies = instance.getManagedDependencies(boms, repositories);
	Dependency aetherDependency = new Dependency(new DefaultArtifact(groupId, artifactId, "pom",
			instance.getVersion(groupId, artifactId, version, managedDependencies)), "compile");
	CollectRequest collectRequest = new CollectRequest((org.eclipse.aether.graph.Dependency) null,
			Collections.singletonList(aetherDependency), repositories);
	collectRequest.setManagedDependencies(managedDependencies);
	DependencyRequest dependencyRequest = new DependencyRequest(collectRequest,
			DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME));
	try {
		return instance.resolveDependencies(dependencyRequest).getArtifactResults().stream()
				.map(ArtifactResult::getArtifact)
				.map((artifact) -> artifact.getGroupId() + ":" + artifact.getArtifactId())
				.collect(Collectors.toList());
	}
	catch (DependencyResolutionException ex) {
		throw new RuntimeException(ex);
	}
}
 
Example #11
Source File: MavenDependencyResolver.java    From spring-cloud-formula with Apache License 2.0 6 votes vote down vote up
public List<Version> getAllVersions(String groupId, String artifactId) {
    String repositoryUrl = "http://maven.repo/nexus/content/groups/public";
    RepositorySystem repoSystem = newRepositorySystem();

    RepositorySystemSession session = newSession(repoSystem);
    RemoteRepository central = null;
    central = new RemoteRepository.Builder("central", "default", repositoryUrl).build();

    Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.addRepository(central);
    VersionRangeResult rangeResult;
    try {
        rangeResult = repoSystem.resolveVersionRange(session, rangeRequest);
    } catch (VersionRangeResolutionException e) {
        throw new RuntimeException(e);
    }
    List<Version> versions = rangeResult.getVersions().stream()
            .filter(v -> !v.toString().toLowerCase().endsWith("-snapshot"))
            .filter(v -> !groupId.contains("org.springframework") || v.toString().equals("2.0.0.RELEASE"))
            .collect(Collectors.toList());
    logger.info("artifact: {}, Available versions: {}", artifact, versions);
    return versions;
}
 
Example #12
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void addRepository(final Repository repository, boolean replace) throws InvalidRepositoryException
{
   if (session.isIgnoreArtifactDescriptorRepositories())
   {
      return;
   }

   if (!repositoryIds.add(repository.getId()))
   {
      if (!replace)
      {
         return;
      }

      removeMatchingRepository(repository.getId());
   }
   repositories.add(new RemoteRepository.Builder(repository.getId(), repository.getName(), repository.getUrl())
            .build());
}
 
Example #13
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void addProfileRepos(final org.apache.maven.model.Profile profile, final List<RemoteRepository> all) {
    final List<org.apache.maven.model.Repository> repositories = profile.getRepositories();
    for (org.apache.maven.model.Repository repo : repositories) {
        final RemoteRepository.Builder repoBuilder = new RemoteRepository.Builder(repo.getId(), repo.getLayout(),
                repo.getUrl());
        org.apache.maven.model.RepositoryPolicy policy = repo.getReleases();
        if (policy != null) {
            repoBuilder.setReleasePolicy(toAetherRepoPolicy(policy));
        }
        policy = repo.getSnapshots();
        if (policy != null) {
            repoBuilder.setSnapshotPolicy(toAetherRepoPolicy(policy));
        }
        all.add(repoBuilder.build());
    }
}
 
Example #14
Source File: NbPluginDependenciesResolver.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public DependencyNode resolve(Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
    
    WorkspaceReader wr = session.getWorkspaceReader();
    NbWorkspaceReader nbwr = null;
    if (wr instanceof NbWorkspaceReader) {
        nbwr = (NbWorkspaceReader)wr;
        //this only works reliably because the NbWorkspaceReader is part of the session, not a component
        nbwr.silence();
    }
    try {
        return super.resolve(plugin, pluginArtifact, dependencyFilter, repositories, session);
    } finally {
        if (nbwr != null) {
            nbwr.normal();
        }
    }
}
 
Example #15
Source File: NbPluginDependenciesResolver.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
    WorkspaceReader wr = session.getWorkspaceReader();
    NbWorkspaceReader nbwr = null;
    if (wr instanceof NbWorkspaceReader) {
        nbwr = (NbWorkspaceReader)wr;
        //this only works reliably because the NbWorkspaceReader is part of the session, not a component
        nbwr.silence();
    }
    try {
        return super.resolve(plugin, repositories, session);
    } finally {
        if (nbwr != null) {
            nbwr.normal();
        }
    }
}
 
Example #16
Source File: SdkResolver.java    From appengine-maven-plugin with Apache License 2.0 6 votes vote down vote up
public static File getSdk(MavenProject project, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository>... repos)
        throws MojoExecutionException {
  Artifact artifact = (Artifact) find(project.getPluginArtifacts(), new Predicate<Artifact>() {
    @Override
    public boolean apply(Artifact artifact1) {
      return (artifact1.getArtifactId().equals("appengine-maven-plugin")
              && artifact1.getGroupId().equals("com.google.appengine"));
    }
  });

  String version = artifact.getVersion();
  
  if(version.endsWith("-SNAPSHOT")) {
    String newestVersion = determineNewestVersion(repoSystem, repoSession, repos);
    return getSdk(newestVersion, repoSystem, repoSession, repos);
  }

  return getSdk(version, repoSystem, repoSession, repos);
}
 
Example #17
Source File: MvnSettingsTestCase.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxy() throws Exception {
    RepositorySystem system = Util.newRepositorySystem();
    MavenConfig config = new MavenConfig();
    InputStream stream = MvnSettingsTestCase.class.getClassLoader().
            getResourceAsStream("settings_cli_test_proxy.xml");
    File tmp = File.createTempFile("cli_mvn_test", null);
    tmp.deleteOnExit();
    Files.copy(stream, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
    config.setSettings(tmp.toPath());
    MavenMvnSettings settings = new MavenMvnSettings(config, system, null);
    ProxySelector proxy = settings.getSession().getProxySelector();
    assertEquals(6, settings.getRepositories().size());
    for (RemoteRepository remote : settings.getRepositories()) {
        if (remote.getId().equals("repo1")) {
            assertNull(proxy.getProxy(remote));
            assertNull(remote.getProxy());
        }
        if (remote.getId().equals("repo2")) {
            assertNull(proxy.getProxy(remote));
            assertNull(remote.getProxy());
        }
        if (remote.getId().equals("repo3")) {
            Proxy p = proxy.getProxy(remote);
            assertEquals("proxy1", p.getHost());
            assertNotNull(remote.getProxy());
        }
    }
}
 
Example #18
Source File: VersionSubstitutingModelResolver.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
VersionSubstitutingModelResolver(
    RepositorySystemSession session,
    RequestTrace trace,
    RepositorySystem resolver,
    RemoteRepositoryManager remoteRepositoryManager,
    List<RemoteRepository> repositories,
    Map<String, String> versionSubstitution) {
  super(session, trace, resolver, remoteRepositoryManager, repositories, null, null);
  this.session = session;
  this.trace = trace;
  this.resolver = resolver;
  this.remoteRepositoryManager = remoteRepositoryManager;
  this.repositories = ImmutableList.copyOf(repositories);
  this.versionSubstitution = ImmutableMap.copyOf(versionSubstitution);
}
 
Example #19
Source File: MavenInitializer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public static RemoteRepository buildRemoteRepository(final RepositorySystemSession session,
                                                     final String id, final String url, final String username, final String password) {
    RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
    if (username != null) {
        builder.setAuthentication(new AuthenticationBuilder()
                .addUsername(username)
                .addPassword(password).build());
    }

    RemoteRepository repository = builder.build();

    final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);

    if (mirror != null) {
        final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector()
                .getAuthentication(mirror);
        RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror)
                .setId(repository.getId());
        if (mirrorAuth != null) {
            mirrorBuilder.setAuthentication(mirrorAuth);
        }
        repository = mirrorBuilder.build();
    }

    Proxy proxy = session.getProxySelector().getProxy(repository);

    if (proxy != null) {
        repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
    }

    return repository;
}
 
Example #20
Source File: ExternalBomResolver.java    From sundrio with Apache License 2.0 5 votes vote down vote up
public ExternalBomResolver(MavenSession mavenSession, ArtifactHandler artifactHandler, RepositorySystem system, RepositorySystemSession session, List<RemoteRepository> remoteRepositories, Log
        logger) {
    this.mavenSession = mavenSession;
    this.artifactHandler = artifactHandler;
    this.system = system;
    this.session = session;
    this.remoteRepositories = remoteRepositories;
    this.logger = logger;
}
 
Example #21
Source File: RepositoryDirectiveProcessor.java    From gyro with Apache License 2.0 5 votes vote down vote up
@Override
public void process(RootScope scope, DirectiveNode node) {
    validateArguments(node, 1, 1);

    String url = getArgument(scope, node, String.class, 0);

    scope.getSettings(RepositorySettings.class)
        .getRepositories()
        .add(new RemoteRepository.Builder(url, "default", url).build());
}
 
Example #22
Source File: SdkResolver.java    From yawp with MIT License 5 votes vote down vote up
private static String determineNewestVersion(RepositorySystem repoSystem, RepositorySystemSession repoSession,
                                             List<RemoteRepository>[] repos) throws MojoExecutionException {
    String version;
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)"));
    for (List<RemoteRepository> repoList : repos) {
        for (RemoteRepository repo : repoList) {
            rangeRequest.addRepository(repo);
        }
    }

    VersionRangeResult rangeResult;
    try {
        rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest);
    } catch (VersionRangeResolutionException e) {
        throw new MojoExecutionException("Could not resolve latest version of the App Engine Java SDK", e);
    }

    List<Version> versions = rangeResult.getVersions();

    Collections.sort(versions);

    Version newest = Iterables.getLast(versions);

    version = newest.toString();
    return version;
}
 
Example #23
Source File: MavenResourceTests.java    From spring-cloud-deployer with Apache License 2.0 5 votes vote down vote up
@Test
public void mavenResourceRetrievedFromNonDefaultRemoteRepository() throws Exception {
	String coordinates = "org.springframework.cloud.task.app:timestamp-task:jar:1.0.0.BUILD-SNAPSHOT";
	MavenProperties properties = new MavenProperties();
	String tempLocalRepo = System.getProperty("java.io.tmpdir") + File.separator + ".m2-test1";
	new File(tempLocalRepo).deleteOnExit();
	properties.setLocalRepository(tempLocalRepo);
	Map<String, MavenProperties.RemoteRepository> remoteRepositoryMap = new HashMap<>();
	remoteRepositoryMap.put("default",
			new MavenProperties.RemoteRepository("https://repo.spring.io/libs-snapshot-local"));
	properties.setRemoteRepositories(remoteRepositoryMap);
	MavenResource resource = MavenResource.parse(coordinates, properties);
	assertEquals("getFilename() doesn't match the expected filename",
			"timestamp-task-1.0.0.BUILD-SNAPSHOT.jar", resource.getFilename());
}
 
Example #24
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void addRepository(Repository repository) throws InvalidRepositoryException
{
   if (repositoryIds.contains(repository.getId()))
   {
      return;
   }

   repositoryIds.add(repository.getId());
   repositories.add(new RemoteRepository.Builder(repository.getId(), repository.getName(), repository.getUrl())
            .build());
}
 
Example #25
Source File: RepositorySettings.java    From gyro with Apache License 2.0 5 votes vote down vote up
public List<RemoteRepository> getRepositories() {
    if (repositories == null) {
        repositories = new ArrayList<>();

        repositories.add(CENTRAL);
        repositories.add(RELEASE);
    }

    return repositories;
}
 
Example #26
Source File: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private DependencyNode resolveCompileTimeDependencies(
    List<DependencyNode> dependencyNodes, DefaultRepositorySystemSession session)
    throws DependencyResolutionException {

  ImmutableList.Builder<Dependency> dependenciesBuilder = ImmutableList.builder();
  for (DependencyNode dependencyNode : dependencyNodes) {
    Dependency dependency = dependencyNode.getDependency();
    if (dependency == null) {
      // Root DependencyNode has null dependency field.
      dependenciesBuilder.add(new Dependency(dependencyNode.getArtifact(), "compile"));
    } else {
      // The dependency field carries exclusions
      dependenciesBuilder.add(dependency.setScope("compile"));
    }
  }
  ImmutableList<Dependency> dependencyList = dependenciesBuilder.build();
          
  if (localRepository != null) {
    LocalRepository local = new LocalRepository(localRepository.toAbsolutePath().toString());
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, local));
  }

  CollectRequest collectRequest = new CollectRequest();
  if (dependencyList.size() == 1) {
    // With setRoot, the result includes dependencies with `optional:true` or `provided`
    collectRequest.setRoot(dependencyList.get(0));
  } else {
    collectRequest.setDependencies(dependencyList);
  }
  for (RemoteRepository repository : repositories) {
    collectRequest.addRepository(repository);
  }
  DependencyRequest dependencyRequest = new DependencyRequest();
  dependencyRequest.setCollectRequest(collectRequest);

  // resolveDependencies equals to calling both collectDependencies (build dependency tree) and
  // resolveArtifacts (download JAR files).
  DependencyResult dependencyResult = system.resolveDependencies(session, dependencyRequest);
  return dependencyResult.getRoot();
}
 
Example #27
Source File: SdkResolver.java    From gcloud-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static String determineNewestVersion(RepositorySystem repoSystem,
    RepositorySystemSession repoSession, List<RemoteRepository>[] repos)
    throws MojoExecutionException {
  String version;
  VersionRangeRequest rangeRequest = new VersionRangeRequest();
  rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)"));
  for (List<RemoteRepository> repoList : repos) {
    for (RemoteRepository repo : repoList) {
      rangeRequest.addRepository(repo);
    }
  }

  VersionRangeResult rangeResult;
  try {
    rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest);
  } catch (VersionRangeResolutionException e) {
    throw new MojoExecutionException(
        "Could not resolve latest version of the App Engine Java SDK", e);
  }

  List<Version> versions = rangeResult.getVersions();

  Collections.sort(versions);

  Version newest = Iterables.getLast(versions);

  version = newest.toString();
  return version;
}
 
Example #28
Source File: ArtifactDeployer.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deploys the given artifacts to the configured remote Maven repositories.
 *
 * @param artifacts the artifacts to deploy.
 * @return the artifacts that have been deployed successfully.
 * @throws DeploymentException if anything goes wrong during the deployment process.
 */
public Collection<Artifact> deployArtifacts(Collection<Artifact> artifacts) throws DeploymentException {
  Collection<Artifact> result = deploy(artifacts, this.metadata.getDeploymentRepository());
  for (RemoteRepository repo : this.additonalDeploymentRepositories) {
    deploy(artifacts, repo);
  }
  return result;
}
 
Example #29
Source File: OfflineConnector.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public RepositoryConnector newInstance(RepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException {
    // Throwing NoRepositoryConnectorException is ineffective because DefaultRemoteRepositoryManager will just skip to WagonRepositoryConnectorFactory.
    // (No apparent way to suppress WRCF from the Plexus container; using "wagon" as the role hint does not work.)
    // Could also return a no-op RepositoryConnector which would perform no downloads.
    // But we anyway want to ensure that related code is consistently setting the offline flag on all Maven structures that require it.
    // Throwing NoRepositoryConnectorException is ineffective because DefaultRemoteRepositoryManager will just skip to WagonRepositoryConnectorFactory.
    // (No apparent way to suppress WRCF from the Plexus container; using "wagon" as the role hint does not work.)
    // Could also return a no-op RepositoryConnector which would perform no downloads.
    // But we anyway want to ensure that related code is consistently setting the offline flag on all Maven structures that require it.
    throw new AssertionError();
}
 
Example #30
Source File: MavenModelResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private void removeMatchingRepository(final String id)
{
   Iterator<RemoteRepository> iterator = repositories.iterator();
   while (iterator.hasNext())
   {
      RemoteRepository remoteRepository = iterator.next();
      if (remoteRepository.getId().equals(id))
      {
         iterator.remove();
      }
   }
}