Java Code Examples for org.eclipse.aether.RepositorySystem

The following examples show how to use org.eclipse.aether.RepositorySystem. 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: appengine-maven-plugin   Source File: SdkResolver.java    License: Apache License 2.0 6 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 2
Source Project: LicenseScout   Source File: ArtifactHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the set of transitive dependencies of the passed artifacts.
 * 
 * @param repositoryParameters
 * @param artifacts
 * @param artifactScope
 * @return a list of File locations where the JARs of the dependencies are located in the local file system
 * @throws DependencyResolutionException
 */
public static List<File> getDependencies(final IRepositoryParameters repositoryParameters,
                                         final List<ArtifactItem> artifacts, final ArtifactScope artifactScope)
        throws DependencyResolutionException {
    final RepositorySystem system = repositoryParameters.getRepositorySystem();
    final RepositorySystemSession session = repositoryParameters.getRepositorySystemSession();
    final DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(artifactScope.getScopeValue());
    final Set<File> artifactFiles = new HashSet<>();
    for (final ArtifactItem artifactItem : artifacts) {
        Artifact artifact = createDefaultArtifact(artifactItem);
        final CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot(new Dependency(artifact, artifactScope.getScopeValue()));
        collectRequest.setRepositories(repositoryParameters.getRemoteRepositories());
        final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
        final DependencyResult dependencyResult = system.resolveDependencies(session, dependencyRequest);
        final List<ArtifactResult> artifactResults = dependencyResult.getArtifactResults();
        for (final ArtifactResult artifactResult : artifactResults) {
            artifactFiles.add(artifactResult.getArtifact().getFile());
        }
    }
    return new ArrayList<>(artifactFiles);
}
 
Example 3
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 4
Source Project: start.spring.io   Source File: DependencyResolver.java    License: Apache License 2.0 6 votes vote down vote up
DependencyResolver() {
	try {
		ServiceLocator serviceLocator = createServiceLocator();
		DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
		session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(false, false));
		this.localRepositoryLocation = Files.createTempDirectory("metadata-validation-m2");
		LocalRepository localRepository = new LocalRepository(this.localRepositoryLocation.toFile());
		this.repositorySystem = serviceLocator.getService(RepositorySystem.class);
		session.setLocalRepositoryManager(
				this.repositorySystem.newLocalRepositoryManager(session, localRepository));
		session.setReadOnly();
		this.repositorySystemSession = session;
	}
	catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
Example 5
Source Project: bazel-deps   Source File: Maven.java    License: MIT License 6 votes vote down vote up
public static Set<Artifact> transitiveDependencies(Artifact artifact) {

    RepositorySystem system = newRepositorySystem();

    RepositorySystemSession session = newRepositorySystemSession(system);

    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.setRepositories(repositories());

    CollectResult collectResult = null;
    try {
      collectResult = system.collectDependencies(session, collectRequest);
    } catch (DependencyCollectionException e) {
      throw new RuntimeException(e);
    }

    PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
    collectResult.getRoot().accept(visitor);

    return ImmutableSet.copyOf(
      visitor.getNodes().stream()
        .filter(d -> !d.getDependency().isOptional())
        .map(DependencyNode::getArtifact)
        .collect(Collectors.toList()));
  }
 
Example 6
private RepositorySystem newRepositorySystem() {
	DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
	locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
	locator.addService(TransporterFactory.class, FileTransporterFactory.class);

	if (properties.isUseWagon()) {
		locator.addService(WagonProvider.class, StaticWagonProvider.class);
		locator.addService(WagonConfigurator.class, StaticWagonConfigurator.class);
		locator.addService(TransporterFactory.class, WagonTransporterFactory.class);
	} else {
		locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
	}

	locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler() {
		@Override
		public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
			throw new RuntimeException(exception);
		}
	});
	return locator.getService(RepositorySystem.class);
}
 
Example 7
Source Project: boost   Source File: LibertyFeatureVersionIT.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private String getLatestLibertyRuntimeVersion() {
    String libertyVersion = null;

    RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/")
            .build();
    RepositorySystem repoSystem = newRepositorySystem();
    RepositorySystemSession session = newSession(repoSystem);
    String version = "[19.0.0.6,)";
    Artifact artifact = new DefaultArtifact("io.openliberty:openliberty-runtime:" + version);
    VersionRangeRequest request = new VersionRangeRequest(artifact, Arrays.asList(central), null);
    try {
        VersionRangeResult versionResult = repoSystem.resolveVersionRange(session, request);
        libertyVersion = versionResult.getHighestVersion().toString();
    } catch (VersionRangeResolutionException e) {
        e.printStackTrace();
    }

    return libertyVersion;

}
 
Example 8
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 9
Source Project: yawp   Source File: SdkResolver.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
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("appengine-maven-plugin");
        }
    });

    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 10
/**
 * 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 11
Source Project: galleon   Source File: MvnSettingsTestCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testProxyNoRepo() throws Exception {
    RepositorySystem system = Util.newRepositorySystem();
    MavenConfig config = new MavenConfig();
    InputStream stream = MvnSettingsTestCase.class.getClassLoader().
            getResourceAsStream("settings_cli_test_proxy_no_repo.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);
    assertEquals(3, settings.getRepositories().size());
    for (RemoteRepository remote : settings.getRepositories()) {
        assertNotNull(remote.getProxy());
    }
}
 
Example 12
Source Project: packagedrone   Source File: MavenUtil.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static RepositorySystem newRepositorySystem ()
{
    final DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator ();
    locator.addService ( RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class );
    locator.addService ( TransporterFactory.class, FileTransporterFactory.class );
    locator.addService ( TransporterFactory.class, HttpTransporterFactory.class );

    locator.setErrorHandler ( new DefaultServiceLocator.ErrorHandler () {
        @Override
        public void serviceCreationFailed ( final Class<?> type, final Class<?> impl, final Throwable exception )
        {
            exception.printStackTrace ();
        }
    } );

    return locator.getService ( RepositorySystem.class );
}
 
Example 13
Source Project: scava   Source File: GithubImporter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private List<String> getMavenParentDependencies(String parent)
		throws DependencyResolutionException, ArtifactDescriptorException {
	List<String> dependencies = new ArrayList<>();
	DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
	RepositorySystem system = newRepositorySystem(locator);
	RepositorySystemSession session = newSession(system);

	RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/")
			.build();

	org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(parent);
	ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(artifact, Arrays.asList(central), null);
	try {
		ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request);
		for (org.eclipse.aether.graph.Dependency dependency : result.getManagedDependencies()) {
			dependencies.add(dependency.getArtifact().getGroupId() + ":" + dependency.getArtifact().getGroupId());
		}
	} catch (Exception e) {
		logger.error(e.getMessage());
	}
	return dependencies;

}
 
Example 14
Source Project: cloud-opensource-java   Source File: Bom.java    License: Apache License 2.0 6 votes vote down vote up
public static Bom readBom(Path pomFile) throws MavenRepositoryException {
  RepositorySystem system = RepositoryUtility.newRepositorySystem();
  RepositorySystemSession session = RepositoryUtility.newSession(system);

  MavenProject mavenProject = RepositoryUtility.createMavenProject(pomFile, session);
  String coordinates = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() 
      + ":" + mavenProject.getVersion();
  DependencyManagement dependencyManagement = mavenProject.getDependencyManagement();
  List<org.apache.maven.model.Dependency> dependencies = dependencyManagement.getDependencies();

  ArtifactTypeRegistry registry = session.getArtifactTypeRegistry();
  ImmutableList<Artifact> artifacts = dependencies.stream()
      .map(dependency -> RepositoryUtils.toDependency(dependency, registry))
      .map(Dependency::getArtifact)
      .filter(artifact -> !shouldSkipBomMember(artifact))
      .collect(ImmutableList.toImmutableList());
  
  Bom bom = new Bom(coordinates, artifacts);
  return bom;
}
 
Example 15
Source Project: cloud-opensource-java   Source File: RepositoryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static DefaultRepositorySystemSession newSession(
    RepositorySystem system, DependencySelector dependencySelector) {
  DefaultRepositorySystemSession session = createDefaultRepositorySystemSession(system);
  session.setDependencySelector(dependencySelector);

  // By default, Maven's MavenRepositorySystemUtils.newSession() returns a session with
  // ChainedDependencyGraphTransformer(ConflictResolver(...), JavaDependencyContextRefiner()).
  // Because the full dependency graph does not resolve conflicts of versions, this session does
  // not use ConflictResolver.
  session.setDependencyGraphTransformer(
      new ChainedDependencyGraphTransformer(
          new CycleBreakerGraphTransformer(), // Avoids StackOverflowError
          new JavaDependencyContextRefiner()));

  // No dependency management in the full dependency graph
  session.setDependencyManager(null);

  return session;
}
 
Example 16
Source Project: cloud-opensource-java   Source File: RepositoryUtility.java    License: Apache License 2.0 6 votes vote down vote up
private static VersionRangeResult findVersionRange(
    RepositorySystem repositorySystem,
    RepositorySystemSession session,
    String groupId,
    String artifactId)
    throws MavenRepositoryException {

  Artifact artifactWithVersionRange = new DefaultArtifact(groupId, artifactId, null, "(0,]");
  VersionRangeRequest request =
      new VersionRangeRequest(
          artifactWithVersionRange, ImmutableList.of(RepositoryUtility.CENTRAL), null);

  try {
    return repositorySystem.resolveVersionRange(session, request);
  } catch (VersionRangeResolutionException ex) {
    throw new MavenRepositoryException(ex);
  }
}
 
Example 17
public static RepositorySystem newRepositorySystem() {
	/*
	 * Aether's components implement org.eclipse.aether.spi.locator.Service
	 * to ease manual wiring and using the prepopulated
	 * DefaultServiceLocator, we only need to register the repository
	 * connector and transporter factories.
	 */
	DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
	locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
	locator.addService(TransporterFactory.class, FileTransporterFactory.class);
	locator.addService(TransporterFactory.class, HttpTransporterFactory.class);

	locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler() {
		@Override
		public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
			exception.printStackTrace();
		}
	});

	return locator.getService(RepositorySystem.class);
}
 
Example 18
Source Project: buck   Source File: Resolver.java    License: Apache License 2.0 5 votes vote down vote up
private static RepositorySystemSession newSession(
    RepositorySystem repoSys, LocalRepository localRepo) {
  DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

  session.setLocalRepositoryManager(repoSys.newLocalRepositoryManager(session, localRepo));
  session.setReadOnly();

  return session;
}
 
Example 19
Source Project: digdag   Source File: RemotePluginLoader.java    License: Apache License 2.0 5 votes vote down vote up
private static RepositorySystemSession newRepositorySystemSession(RepositorySystem system, Path localRepositoryPath)
{
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    LocalRepository localRepo = new LocalRepository(localRepositoryPath.toString());
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    //session.setTransferListener(new ConsoleTransferListener());
    //session.setRepositoryListener(new ConsoleRepositoryListener());

    return session;
}
 
Example 20
Source Project: LicenseScout   Source File: ArtifactHelperTest.java    License: Apache License 2.0 5 votes vote down vote up
private static RepositorySystem newRepositorySystem() {
    DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    locator.addService(TransporterFactory.class, FileTransporterFactory.class);
    locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    return locator.getService(RepositorySystem.class);
}
 
Example 21
Source Project: google-cloud-eclipse   Source File: MavenUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Perform some Maven-related action that may result in a change to the local Maven repositories,
 * ensuring that required {@link ISchedulingRule scheduling rules} are held.
 */
public static <T> T runOperation(IProgressMonitor monitor, MavenRepositoryOperation<T> operation)
    throws CoreException {
  SubMonitor progress = SubMonitor.convert(monitor, 10);
  ISchedulingRule rule = mavenResolvingRule();
  boolean acquireRule = Job.getJobManager().currentRule() == null;
  if (acquireRule) {
    Job.getJobManager().beginRule(rule, progress.split(2));
  }
  try {
    Verify.verify(
        Job.getJobManager().currentRule().contains(rule),
        "require holding superset of rule: " + rule);
    IMavenExecutionContext context = MavenPlugin.getMaven().createExecutionContext();
    return context.execute(
        (context2, monitor2) -> {
          // todo we'd prefer not to depend on m2e here
          RepositorySystem system = MavenPluginActivator.getDefault().getRepositorySystem();
          return operation.run(context2, system, SubMonitor.convert(monitor2));
        },
        progress.split(8));
  } finally {
    if (acquireRule) {
      Job.getJobManager().endRule(rule);
    }
  }
}
 
Example 22
public MavenArtifactResolvingHelper(ArtifactResolver resolver,
                                    RepositorySystem system,
                                    RepositorySystemSession session) {
    this.resolver = resolver;
    this.system = system;
    this.session = session;
    this.remoteRepositories.add(new RemoteRepository.Builder("jboss-public-repository-group", "default", "http://repository.jboss.org/nexus/content/groups/public/").build());
}
 
Example 23
private RepositorySystem newRepositorySystem() {
    DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    locator.addService(WagonConfigurator.class, PlexusWagonConfigurator.class);
    locator.addService(TransporterFactory.class, FileTransporterFactory.class);
    locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    return locator.getService(RepositorySystem.class);
}
 
Example 24
private RepositorySystemSession newSession(RepositorySystem system) {
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();

    String home = System.getenv("HOME");
    LocalRepository localRepo = new LocalRepository(new File(home, ".m2/repository"));
    session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));

    return session;
}
 
Example 25
Source Project: vertx-deploy-tools   Source File: DeployUtils.java    License: Apache License 2.0 5 votes vote down vote up
public DeployUtils(Log log, MavenProject project, List<RemoteRepository> remoteRepos, RepositorySystem repoSystem, RepositorySystemSession repoSession) {

        this.log = log;
        this.project = project;
        this.remoteRepos = remoteRepos;
        this.repoSystem = repoSystem;
        this.repoSession = repoSession;
    }
 
Example 26
Source Project: boost   Source File: LibertyFeatureVersionIT.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private RepositorySystem newRepositorySystem() {
    DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    locator.addService(TransporterFactory.class, FileTransporterFactory.class);
    locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    return locator.getService(RepositorySystem.class);
}
 
Example 27
Source Project: rug-cli   Source File: PublishCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void doWithRepositorySession(RepositorySystem system, RepositorySystemSession session,
        ArtifactSource source, Manifest manifest, Artifact zip, Artifact pom, Artifact metadata,
        CommandLine commandLine) {
    Set<String> ids = org.springframework.util.StringUtils
            .commaDelimitedListToSet(CommandLineOptions.getOptionValue("id").orElse(""));

    if (CommandLineOptions.hasOption("U")) {
        String group = manifest.group();
        String artifact = manifest.artifact();
        Version version = VersionUtils.parseVersion(manifest.version());

        SearchCommand search = new SearchCommand();
        Map<String, List<Operation>> operations = search.search(SettingsReader.read(), null,
                new Properties(), null);

        operations.values().stream().filter(ops -> ops.size() > 0).forEach(ops -> {
            Archive archive = ops.get(0).archive();
            if (archive.group().equals(group) && archive.artifact().equals(artifact)
                    && !"global".equals(archive.scope())) {
                if (version
                        .compareTo(VersionUtils.parseVersion(archive.version().value())) > 0) {
                    ids.add(archive.scope());
                }
            }
        });
    }

    List<org.eclipse.aether.repository.RemoteRepository> deployRepositorys = getDeployRepositories(
            ids);
    deployRepositorys.forEach(
            r -> publishToRepository(system, session, source, manifest, zip, pom, metadata, r));
}
 
Example 28
private VersionRangeResult getVersions(RepositorySystem system, Settings settings, RepositorySystemSession session,
         List<RemoteRepository> repositories,
         String addonName,
         String version)
{
   try
   {
      String[] split = addonName.split(",");
      if (split.length == 2)
      {
         version = split[1];
      }
      if (version == null || version.isEmpty())
      {
         version = "[,)";
      }
      else if (!version.matches("(\\(|\\[).*?(\\)|\\])"))
      {
         version = "[" + version + "]";
      }

      Artifact artifact = new DefaultArtifact(toMavenCoords(AddonId.from(addonName, version)));
      VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null);
      VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
      return rangeResult;
   }
   catch (Exception e)
   {
      throw new RuntimeException("Failed to look up versions for [" + addonName + "]", e);
   }
}
 
Example 29
Source Project: galleon   Source File: Util.java    License: Apache License 2.0 5 votes vote down vote up
public static RepositorySystemSession newRepositorySession(final RepositorySystem repoSystem,
        Path path, RepositoryListener listener, ProxySelector proxySelector, boolean offline) {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setRepositoryListener(listener);
    session.setOffline(offline);
    final LocalRepository localRepo = new LocalRepository(path.toString());
    session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
    if (proxySelector != null) {
        session.setProxySelector(proxySelector);
    }
    return session;
}
 
Example 30
private ArtifactDescriptorResult readArtifactDescriptor(AddonId addonId) throws ArtifactDescriptorException
{
   String coords = toMavenCoords(addonId);
   RepositorySystem system = container.getRepositorySystem();
   Settings settings = getSettings();
   DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
   ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
   request.setArtifact(new DefaultArtifact(coords));
   request.setRepositories(repositories);

   ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request);
   return result;
}