Java Code Examples for org.eclipse.aether.repository.RemoteRepository

The following examples show how to use org.eclipse.aether.repository.RemoteRepository. These examples are extracted from open source projects. 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 Project: netbeans   Source File: NbPluginDependenciesResolver.java    License: 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 2
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 3
Source Project: start.spring.io   Source File: DependencyResolver.java    License: 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 4
Source Project: gcloud-maven-plugin   Source File: SdkResolver.java    License: 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 5
Source Project: start.spring.io   Source File: MetadataVerificationTests.java    License: 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 6
Source Project: quarkus   Source File: PomReposMirroredTest.java    License: 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 Project: yawp   Source File: DevServerMojo.java    License: 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 8
Source Project: galleon   Source File: MavenConfig.java    License: 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 9
@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 10
Source Project: netbeans   Source File: NbPluginDependenciesResolver.java    License: 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 11
Source Project: appengine-maven-plugin   Source File: SdkResolver.java    License: 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 12
Source Project: quarkus   Source File: BootstrapMavenContext.java    License: 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 13
@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 14
Source Project: furnace   Source File: MavenModelResolver.java    License: 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 15
/**
 * 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 16
Source Project: spring-cloud-deployer   Source File: MavenResourceTests.java    License: 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 17
Source Project: javafx-maven-plugin   Source File: MavenArtifactResolver.java    License: Apache License 2.0 5 votes vote down vote up
MavenArtifactResolver(List<Repository> repositories) {
    this.repositorySystem = createRepositorySystem();
    this.remoteRepositories = new LinkedList<>();
    repositories.forEach(r -> {
        RemoteRepository repository = new RemoteRepository
                .Builder(r.getId(), "default", r.getUrl())
                .build();
        remoteRepositories.add(repository);
    });
}
 
Example 18
Source Project: migration-tooling   Source File: DefaultModelResolver.java    License: Apache License 2.0 5 votes vote down vote up
/** Adds a user-specified repository to the list. */
public void addUserRepository(String url) {
  Repository repository = new Repository();
  repository.setUrl(url);
  repository.setId("user-defined repository");
  repository.setName("default");
  addRepository(repository);
  this.aether.addRemoteRepository(
      new RemoteRepository.Builder("user-defined repository", "default", url).build());
}
 
Example 19
public List<com.baidu.formula.launcher.model.Dependency> getArtifactsDependencies(
        MavenProject project, String scope)
        throws DependencyCollectionException, DependencyResolutionException {
    DefaultArtifact pomArtifact = new DefaultArtifact(project.getId());

    List<RemoteRepository> remoteRepos = project.getRemoteProjectRepositories();
    List<Dependency> ret = new ArrayList<Dependency>();

    Dependency dependency = new Dependency(pomArtifact, scope);

    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(dependency);
    collectRequest.setRepositories(remoteRepos);

    DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot();
    DependencyRequest projectDependencyRequest = new DependencyRequest(node, null);

    repositorySystem.resolveDependencies(session, projectDependencyRequest);

    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    node.accept(nlg);

    ret.addAll(nlg.getDependencies(true));
    return ret.stream().map(d -> {
        com.baidu.formula.launcher.model.Dependency dep = new com.baidu.formula.launcher.model.Dependency();
        dep.setArtifactId(d.getArtifact().getArtifactId());
        dep.setGroupId(d.getArtifact().getGroupId());
        dep.setVersion(d.getArtifact().getVersion());
        return dep;
    }).collect(Collectors.toList());
}
 
Example 20
Source Project: start.spring.io   Source File: DependencyResolver.java    License: Apache License 2.0 5 votes vote down vote up
static RemoteRepository createRemoteRepository(String id, String url, boolean snapshot) {
	Builder repositoryBuilder = new Builder(id, "default", url);
	if (snapshot) {
		repositoryBuilder.setSnapshotPolicy(repositoryPolicy);
	}
	else {
		repositoryBuilder.setReleasePolicy(repositoryPolicy);
	}
	return repositoryBuilder.build();
}
 
Example 21
Source Project: start.spring.io   Source File: DependencyResolver.java    License: Apache License 2.0 5 votes vote down vote up
private Stream<Dependency> getManagedDependencies(String groupId, String artifactId, String version,
		List<RemoteRepository> repositories) {
	String key = groupId + ":" + artifactId + ":" + version;
	List<org.eclipse.aether.graph.Dependency> managedDependencies = DependencyResolver.managedDependencies
			.computeIfAbsent(key,
					(coords) -> resolveManagedDependencies(groupId, artifactId, version, repositories));
	return managedDependencies.stream();
}
 
Example 22
Source Project: syndesis   Source File: RepackageExtensionMojo.java    License: Apache License 2.0 5 votes vote down vote up
private List<Dependency> obtainBomDependencies(final String urlLocation) {
    final Artifact artifact = downloadAndInstallArtifact(urlLocation).getArtifact();

    final Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME);

    final List<RemoteRepository> remoteRepositories = project.getRepositories().stream()
        .map(r -> new RemoteRepository.Builder(r.getId(), r.getLayout(), r.getUrl()).build())
        .collect(Collectors.toList());

    CollectResult result;
    try {
        final ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(artifact, remoteRepositories, null);
        final ArtifactDescriptorResult descriptor = repository.readArtifactDescriptor(session, descriptorRequest);

        final List<Dependency> dependencies = Stream.concat(
            descriptor.getDependencies().stream(),
            descriptor.getManagedDependencies().stream())
            .collect(Collectors.toList());

        final DefaultRepositorySystemSession sessionToUse = new DefaultRepositorySystemSession(session);
        sessionToUse.setDependencyGraphTransformer(new NoopDependencyGraphTransformer());

        final CollectRequest request = new CollectRequest(dependency, dependencies, remoteRepositories);
        result = repository.collectDependencies(sessionToUse, request);
    } catch (final DependencyCollectionException | ArtifactDescriptorException e) {
        throw new IllegalStateException("Unabele to obtain BOM dependencies for: " + urlLocation, e);
    }

    final DependencyNode root = result.getRoot();

    final PostorderNodeListGenerator visitor = new PostorderNodeListGenerator();
    root.accept(visitor);

    return visitor.getDependencies(true);
}
 
Example 23
Source Project: boost   Source File: RuntimeParams.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public RuntimeParams(List<AbstractBoosterConfig> boosterConfigs, Properties boostProperties, ExecutionEnvironment env, MavenProject project,
        Log log, RepositorySystem repoSystem, RepositorySystemSession repoSession,
        List<RemoteRepository> remoteRepos, Plugin mavenDepPlugin) {
    this.log = log;
    this.boosterConfigs = boosterConfigs;
    this.boostProperties = boostProperties;
    this.env = env;
    this.project = project;
    this.projectBuildDir = project.getBuild().getDirectory();
    this.repoSystem = repoSystem;
    this.repoSession = repoSession;
    this.remoteRepos = remoteRepos;
    this.mavenDepPlugin = mavenDepPlugin;
}
 
Example 24
@Inject
public ArtifactResolver(RepositorySystem repoSystem, RepositorySystemSession repoSession,
    @Named("projectRepositories") List<RemoteRepository> remoteProjectRepos, Logger log) {
  this.repoSession = repoSession;
  this.cache = CacheBuilder.newBuilder()
      .build(new ArtifactCacheLoader(repoSystem, repoSession, remoteProjectRepos, log));
}
 
Example 25
Source Project: takari-lifecycle   Source File: AetherUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static List<RemoteRepository> toRepos(List<ArtifactRepository> repos) {
  if (repos == null) {
    return null;
  }

  List<RemoteRepository> results = new ArrayList<RemoteRepository>(repos.size());
  for (ArtifactRepository repo : repos) {
    results.add(toRepo(repo));
  }
  return results;
}
 
Example 26
Source Project: netbeans   Source File: OfflineConnector.java    License: 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 27
/**
 * 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 28
Source Project: galleon   Source File: MvnSettingsTestCase.java    License: 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 29
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 30
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();
}