org.eclipse.aether.RepositorySystem Java Examples
The following examples show how to use
org.eclipse.aether.RepositorySystem.
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: MvnSettingsTestCase.java From galleon with Apache License 2.0 | 6 votes |
@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 #2
Source File: ArtifactHelper.java From LicenseScout with Apache License 2.0 | 6 votes |
/** * 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
Source File: RemotePluginRepository.java From BIMserver with GNU Affero General Public License v3.0 | 6 votes |
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 #4
Source File: SdkResolver.java From appengine-maven-plugin with Apache License 2.0 | 6 votes |
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 #5
Source File: Maven.java From bazel-deps with MIT License | 6 votes |
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
Source File: MavenDependencyResolver.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
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 #7
Source File: DependencyResolver.java From start.spring.io with Apache License 2.0 | 6 votes |
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 #8
Source File: MavenArtifactResolver.java From spring-cloud-deployer with Apache License 2.0 | 6 votes |
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 #9
Source File: LibertyFeatureVersionIT.java From boost with Eclipse Public License 1.0 | 6 votes |
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 #10
Source File: SdkResolver.java From appengine-maven-plugin with Apache License 2.0 | 6 votes |
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 #11
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
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 #12
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
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 #13
Source File: SdkResolver.java From yawp with MIT License | 6 votes |
@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 #14
Source File: Bom.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
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 File: GithubImporter.java From scava with Eclipse Public License 2.0 | 6 votes |
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 #16
Source File: AetherStubDownloader.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
/** * 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 #17
Source File: MavenUtil.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
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 #18
Source File: MavenArtifactResolvingHelper.java From wildfly-swarm with Apache License 2.0 | 5 votes |
public MavenArtifactResolvingHelper(ArtifactResolver resolver, RepositorySystem system, RepositorySystemSession session, Proxy proxy) { this.resolver = resolver; this.system = system; this.session = session; this.proxy = proxy; this.remoteRepositories.add(buildRemoteRepository("jboss-public-repository-group", "http://repository.jboss.org/nexus/content/groups/public/", null, this.proxy)); }
Example #19
Source File: MavenResolverDependencyManagementVersionResolver.java From initializr with Apache License 2.0 | 5 votes |
MavenResolverDependencyManagementVersionResolver(Path cacheLocation) { ServiceLocator serviceLocator = createServiceLocator(); DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(false, false)); LocalRepository localRepository = new LocalRepository(cacheLocation.toFile()); this.repositorySystem = serviceLocator.getService(RepositorySystem.class); session.setLocalRepositoryManager(this.repositorySystem.newLocalRepositoryManager(session, localRepository)); session.setReadOnly(); this.repositorySystemSession = session; }
Example #20
Source File: Cadfael.java From Poseidon with Apache License 2.0 | 5 votes |
private RepositorySystemSession newSession(RepositorySystem system) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepo = new LocalRepository("target/local-repo"); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); // set possible proxies and mirrors // session.setProxySelector(new DefaultProxySelector().add(new Proxy(Proxy.TYPE_HTTP, "host", 3625), Arrays.asList("localhost", "127.0.0.1"))); // session.setMirrorSelector(new DefaultMirrorSelector().add("my-mirror", "http://mirror", "default", false, "external:*", null)); return session; }
Example #21
Source File: SdkResolver.java From yawp with MIT License | 5 votes |
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 #22
Source File: ArtifactResolverTest.java From revapi with Apache License 2.0 | 5 votes |
public 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); locator.setErrorHandler(new DefaultServiceLocator.ErrorHandler() { @Override public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) { exception.printStackTrace(); } }); return locator.getService(RepositorySystem.class); }
Example #23
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
/** * Open a new Maven repository session for full dependency graph resolution. * * @see {@link DependencyGraphBuilder} */ static DefaultRepositorySystemSession newSessionForFullDependency(RepositorySystem system) { // This combination of DependencySelector comes from the default specified in // `MavenRepositorySystemUtils.newSession`. // LinkageChecker needs to include 'provided'-scope and optional dependencies. DependencySelector dependencySelector = new AndDependencySelector( // ScopeDependencySelector takes exclusions. 'Provided' scope is not here to avoid // false positive in LinkageChecker. new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new FilteringZipDependencySelector()); return newSession(system, dependencySelector); }
Example #24
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@VisibleForTesting static DefaultRepositorySystemSession createDefaultRepositorySystemSession( RepositorySystem system) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepository = new LocalRepository(findLocalRepository()); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepository)); return session; }
Example #25
Source File: Maven3DependencyTreeBuilder.java From archiva with Apache License 2.0 | 5 votes |
private void resolve( ResolveRequest resolveRequest ) { RepositorySystem system = mavenSystemManager.getRepositorySystem(); RepositorySystemSession session = MavenSystemManager.newRepositorySystemSession( resolveRequest.localRepoDir ); org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact( resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version ); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( new Dependency( artifact, "" ) ); // add remote repositories for ( RemoteRepository remoteRepository : resolveRequest.remoteRepositories ) { org.eclipse.aether.repository.RemoteRepository repo = new org.eclipse.aether.repository.RemoteRepository.Builder( remoteRepository.getId( ), "default", remoteRepository.getLocation( ).toString() ).build( ); collectRequest.addRepository(repo); } collectRequest.setRequestContext( "project" ); //collectRequest.addRepository( repo ); try { CollectResult collectResult = system.collectDependencies( session, collectRequest ); collectResult.getRoot().accept( resolveRequest.dependencyVisitor ); log.debug("Collected dependency results for resolve"); } catch ( DependencyCollectionException e ) { log.error( "Error while collecting dependencies (resolve): {}", e.getMessage(), e ); } }
Example #26
Source File: ArtifactDownload.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
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 #27
Source File: MavenUtilTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testRepositorySystemDirect() { DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.setErrorHandler(new MavenUtil.MyErrorHandler()); RepositorySystem repoSys = locator.getService(RepositorySystem.class); Assert.assertNotNull(repoSys); }
Example #28
Source File: ArtifactDownload.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
/** * This method fetches the artifact from the remote server using aether library * * @param groupId group ID of the artifact * @param artifactId artifact ID of the artifact * @param version artifact version to be downloaded * @param classifier classifier of the artifact * @param packaging packaging of the artifact * @param localRepository destination path * @return location of the downloaded artifact in the local system * @throws IOException */ public static File getArtifactByAether(String groupId, String artifactId, String version, String classifier, String packaging, File localRepository) throws IOException { RepositorySystem repositorySystem = newRepositorySystem(); RepositorySystemSession session = newSession(repositorySystem, localRepository); Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, packaging, version); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); List<RemoteRepository> repositories = new ArrayList<>(); Section ini = Utils.getConfig().get(Constants.INI_URL_HEADER); RemoteRepository remoteRepository = new RemoteRepository.Builder("public", "default", ini.get(Constants.INI_NEXUS_SOOT_RELEASE)).build(); repositories.add(remoteRepository); artifactRequest.setRepositories(repositories); File result = null; try { ArtifactResult artifactResult = repositorySystem.resolveArtifact(session, artifactRequest); artifact = artifactResult.getArtifact(); if (artifact != null) { result = artifact.getFile(); } } catch (ArtifactResolutionException e) { throw new IOException("Artifact " + groupId + ":" + artifactId + ":" + version + " could not be downloaded due to " + e.getMessage()); } return result; }
Example #29
Source File: SimpleMavenCache.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
public void cacheArtifact(Artifact artifact) throws IOException, SettingsBuildingException, DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException, ModelBuildingException { // setup a maven resolution hierarchy that uses the main local repo as // a remote repo and then cache into a new local repo List<RemoteRepository> repos = Utils.getRepositoryList(); RepositorySystem repoSystem = Utils.getRepositorySystem(); DefaultRepositorySystemSession repoSession = Utils.getRepositorySession(repoSystem, null); // treat the usual local repository as if it were a remote, ignoring checksum // failures as the local repo doesn't have checksums as a rule RemoteRepository localAsRemote = new RemoteRepository.Builder("localAsRemote", "default", repoSession.getLocalRepository().getBasedir().toURI().toString()) .setPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_IGNORE)) .build(); repos.add(0, localAsRemote); repoSession.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager( repoSession, new LocalRepository(head.getAbsolutePath()))); Dependency dependency = new Dependency(artifact, "runtime"); CollectRequest collectRequest = new CollectRequest(dependency, repos); DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot(); DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setRoot(node); repoSystem.resolveDependencies(repoSession, dependencyRequest); }
Example #30
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
static DefaultRepositorySystemSession newSessionForVerboseDependency(RepositorySystem system) { DependencySelector dependencySelector = new AndDependencySelector( // ScopeDependencySelector takes exclusions. 'Provided' scope is not here to avoid // false positive in LinkageChecker. new ScopeDependencySelector("test"), new OptionalDependencySelector(), new ExclusionDependencySelector(), new FilteringZipDependencySelector()); return newSession(system, dependencySelector); }