org.eclipse.aether.RepositorySystemSession Java Examples
The following examples show how to use
org.eclipse.aether.RepositorySystemSession.
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: NbPluginDependenciesResolver.java From netbeans with Apache License 2.0 | 6 votes |
@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
Source File: StagerMojo.java From helidon-build-tools with Apache License 2.0 | 6 votes |
StagingContextImpl(File baseDir, File outputDir, Log log, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> remoteRepos, ArchiverManager archiverManager) { this.baseDir = baseDir; this.outputDir = outputDir; this.log = log; this.repoSystem = repoSystem; this.repoSession = repoSession; this.remoteRepos = remoteRepos; this.archiverManager = Objects.requireNonNull(archiverManager, "archiverManager is null"); }
Example #3
Source File: ResolveMojoTest.java From roboconf-platform with Apache License 2.0 | 6 votes |
private RepositorySystem newRepositorySystem() { RepositorySystem repoSystem = new DefaultRepositorySystem() { @Override public ArtifactResult resolveArtifact( RepositorySystemSession session, ArtifactRequest request ) throws ArtifactResolutionException { ArtifactResult res = new ArtifactResult( request ); Artifact mavenArtifact = ResolveMojoTest.this.artifactIdToArtifact.get( request.getArtifact().getArtifactId()); if( mavenArtifact == null ) throw new ArtifactResolutionException( new ArrayList<ArtifactResult>( 0 ), "Error in test wrapper and settings." ); org.eclipse.aether.artifact.DefaultArtifact art = new org.eclipse.aether.artifact.DefaultArtifact( "groupId", "artifactId", "classifier", "extension", "version", null, mavenArtifact.getFile()); res.setArtifact( art ); return res; } }; return repoSystem; }
Example #4
Source File: MavenGraphAdapterTest.java From depgraph-maven-plugin with Apache License 2.0 | 6 votes |
@BeforeEach void before() throws Exception { Artifact projectArtifact = mock(Artifact.class); this.mavenProject = new MavenProject(); this.mavenProject.setArtifact(projectArtifact); ProjectBuildingRequest projectBuildingRequest = mock(ProjectBuildingRequest.class); when(projectBuildingRequest.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class)); //noinspection deprecation this.mavenProject.setProjectBuildingRequest(projectBuildingRequest); this.globalFilter = mock(ArtifactFilter.class); ArtifactFilter transitiveIncludeExcludeFilter = mock(ArtifactFilter.class); ArtifactFilter targetFilter = mock(ArtifactFilter.class); this.graphBuilder = GraphBuilder.create(ToStringNodeIdRenderer.INSTANCE); this.dependenciesResolver = mock(ProjectDependenciesResolver.class); DependencyResolutionResult dependencyResolutionResult = mock(DependencyResolutionResult.class); when(dependencyResolutionResult.getDependencyGraph()).thenReturn(mock(org.eclipse.aether.graph.DependencyNode.class)); when(this.dependenciesResolver.resolve(any(DependencyResolutionRequest.class))).thenReturn(dependencyResolutionResult); this.graphAdapter = new MavenGraphAdapter(this.dependenciesResolver, transitiveIncludeExcludeFilter, targetFilter, EnumSet.of(INCLUDED)); }
Example #5
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 #6
Source File: AggregatingGraphFactoryTest.java From depgraph-maven-plugin with Apache License 2.0 | 6 votes |
private MavenProject createMavenProject(String artifactId) { MavenProject project = new MavenProject(); project.setArtifactId(artifactId); // Make sure that we can modify the list later. project.setCollectedProjects(new ArrayList<>()); DefaultArtifact artifact = new DefaultArtifact("groupId", artifactId, "version", "compile", "jar", "", null); project.setArtifact(artifact); RepositorySystemSession repositorySession = mock(RepositorySystemSession.class); ProjectBuildingRequest projectBuildingRequest = mock(ProjectBuildingRequest.class); when(projectBuildingRequest.getRepositorySession()).thenReturn(repositorySession); //noinspection deprecation project.setProjectBuildingRequest(projectBuildingRequest); return project; }
Example #7
Source File: ParentPOMPropagatingArtifactDescriptorReaderDelegate.java From mvn2nix-maven-plugin with MIT License | 6 votes |
@Override public void populateResult(RepositorySystemSession session, ArtifactDescriptorResult result, Model model) { super.populateResult(session, result, model); Parent parent = model.getParent(); if (parent != null) { DefaultArtifact art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom", parent.getVersion()); Dependency dep = new Dependency(art, "compile"); result.addDependency(dep); } }
Example #8
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 #9
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 #10
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 #11
Source File: EclipseAetherArtifactResolver.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
@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 #12
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 #13
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 #14
Source File: NbRepositorySystem.java From netbeans with Apache License 2.0 | 6 votes |
@Override public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) throws DependencyCollectionException { DefaultRepositorySystemSession cloned = new DefaultRepositorySystemSession(session); DependencyGraphTransformer transformer = session.getDependencyGraphTransformer(); //need to reset the transformer to prevent the transformation to happen and to it below separately. cloned.setDependencyGraphTransformer(null); CollectResult res = super.collectDependencies(cloned, request); CloningDependencyVisitor vis = new CloningDependencyVisitor(); res.getRoot().accept(vis); //this part copied from DefaultDependencyCollector try { DefaultDependencyGraphTransformationContext context = new DefaultDependencyGraphTransformationContext(session); res.setRoot(transformer.transformGraph(res.getRoot(), context)); } catch (RepositoryException e) { res.addException(e); } if (!res.getExceptions().isEmpty()) { throw new DependencyCollectionException(res); } res.getRoot().setData("NB_TEST", vis.getRootNode()); return res; }
Example #15
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 #16
Source File: NbPluginDependenciesResolver.java From netbeans with Apache License 2.0 | 6 votes |
@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 #17
Source File: RemoteStubRunner.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
public BatchStubRunner run(StubRunnerOptions options, RepositorySystemSession repositorySystemSession) { StubDownloader stubDownloader = this.aetherStubDownloaderFactory .build(repositorySystemSession).build(options); try { if (log.isDebugEnabled()) { log.debug("Launching StubRunner with args: " + options); } BatchStubRunner stubRunner = new BatchStubRunnerFactory(options, stubDownloader).buildBatchStubRunner(); RunningStubs runningCollaborators = stubRunner.runStubs(); log.info(runningCollaborators.toString()); return stubRunner; } catch (Exception e) { log.error("An exception occurred while trying to execute the stubs: " + e.getMessage()); throw e; } }
Example #18
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 #19
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 #20
Source File: Aether.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Aether and its components are designed to be stateless. All configurations and state * are provided through the RepositorySystemSession. * * TODO(petros): Separate this out into its own class. * This is the most intricate element of Aether. * There are various settings that are useful to us. * Specifically, these are the (1) LocalRepositoryManager, (2) DependencyManager, * (3) DependencyGraphTransformer, (4) TransferListener, (5) ProxySelector */ static RepositorySystemSession newRepositorySession(RepositorySystem system) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); // TODO(petros): Decide on where to cache things. LocalRepository localRepository = new LocalRepository("target/local-repo"); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepository)); session.setDependencyManager(new ClassicDependencyManager()); return session; }
Example #21
Source File: MavenAddonDependencyResolver.java From furnace with Eclipse Public License 1.0 | 5 votes |
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 #22
Source File: MavenArtifactResolvingHelperTest.java From thorntail with Apache License 2.0 | 5 votes |
public MavenArtifactResolvingHelperTest() { sessionMock = Mockito.mock(RepositorySystemSession.class); MirrorSelector mirrorSelectorMock = Mockito.mock(MirrorSelector.class); Mockito.when(sessionMock.getMirrorSelector()).thenReturn(mirrorSelectorMock); ProxySelector proxySelectorMock = Mockito.mock(ProxySelector.class); Mockito.when(sessionMock.getProxySelector()).thenReturn(proxySelectorMock); localRepositoryManager = Mockito.mock(LocalRepositoryManager.class); Mockito.when(sessionMock.getLocalRepositoryManager()).thenReturn(localRepositoryManager); resolver = Mockito.mock(ArtifactResolver.class); system = Mockito.mock(RepositorySystem.class); }
Example #23
Source File: MavenLocalRepositoryManager.java From quarkus with Apache License 2.0 | 5 votes |
@Override public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) { final LocalMetadataResult result = delegate.find(session, request); if (result.getFile() != null && result.getFile().exists()) { return result; } final Metadata metadata = request.getMetadata(); final Path userRepoPath = getMetadataPath(userLocalRepo, metadata.getGroupId(), metadata.getArtifactId(), metadata.getType(), metadata.getVersion()); if (!Files.exists(userRepoPath)) { return result; } if (relinkResolvedArtifacts) { final Path creatorRepoPath = getMetadataPath(appCreatorRepo, metadata.getGroupId(), metadata.getArtifactId(), metadata.getType(), metadata.getVersion()); try { IoUtils.copy(userRepoPath, creatorRepoPath); } catch (IOException e) { throw new IllegalStateException("Failed to copy " + userRepoPath + " to a staging repo", e); } result.setFile(creatorRepoPath.toFile()); } else { result.setFile(userRepoPath.toFile()); } metadata.setFile(result.getFile()); return result; }
Example #24
Source File: OfflineConnector.java From netbeans with Apache License 2.0 | 5 votes |
@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 #25
Source File: ArtifactResolver.java From revapi with Apache License 2.0 | 5 votes |
/** * Tries to find the newest version of the artifact that matches given regular expression. * The found version will be older than the {@code upToVersion} or newest available if {@code upToVersion} is null. * * @param gav the coordinates of the artifact. The version part is ignored * @param upToVersion the version up to which the versions will be matched * @param versionMatcher the matcher to match the version * @param remoteOnly true if only remotely available artifacts should be considered * @param upToInclusive whether the {@code upToVersion} should be considered inclusive or exclusive * @return the resolved artifact */ public Artifact resolveNewestMatching(String gav, @Nullable String upToVersion, Pattern versionMatcher, boolean remoteOnly, boolean upToInclusive) throws VersionRangeResolutionException, ArtifactResolutionException { Artifact artifact = new DefaultArtifact(gav); artifact = artifact.setVersion(upToVersion == null ? "[,)" : "[," + upToVersion + (upToInclusive ? "]" : ")")); VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null); RepositorySystemSession session = remoteOnly ? makeRemoteOnly(this.session) : this.session; VersionRangeResult result = repositorySystem.resolveVersionRange(session, rangeRequest); List<Version> versions = new ArrayList<>(result.getVersions()); Collections.reverse(versions); for(Version v : versions) { if (versionMatcher.matcher(v.toString()).matches()) { return resolveArtifact(artifact.setVersion(v.toString()), session); } } throw new VersionRangeResolutionException(result) { @Override public String getMessage() { return "Failed to find a version of artifact '" + gav + "' that would correspond to an expression '" + versionMatcher + "'. The versions found were: " + versions; } }; }
Example #26
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 #27
Source File: DependencyResolver.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public Object get(RepositorySystemSession session, Object key) { final Object result = delegate.get(session, key); if (result == null) { logger.info("cache-get-miss-" + miss.incrementAndGet() + ":" + session + " " + key); } else { logger.info("cache-get-hit-" + hit.incrementAndGet() + ":" + session + " " + key + " result:" + result); } return result; }
Example #28
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
/** * Returns the latest Maven coordinates for {@code groupId:artifactId} in {@code * repositorySystem}. */ public static String findLatestCoordinates( RepositorySystem repositorySystem, String groupId, String artifactId) throws MavenRepositoryException { RepositorySystemSession session = RepositoryUtility.newSession(repositorySystem); String highestVersion = findHighestVersion(repositorySystem, session, groupId, artifactId); return String.format("%s:%s:%s", groupId, artifactId, highestVersion); }
Example #29
Source File: ByteBuddyMojoTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { when(repositorySystem.collectDependencies(Mockito.<RepositorySystemSession>any(), Mockito.<CollectRequest>any())).thenReturn(new CollectResult(new CollectRequest()).setRoot(root)); project = File.createTempFile(FOO, TEMP); assertThat(project.delete(), is(true)); assertThat(project.mkdir(), is(true)); }
Example #30
Source File: ManagedDependencyLister.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws ArtifactDescriptorException { DefaultArtifact artifact = new DefaultArtifact("com.google.cloud:libraries-bom:pom:1.0.0"); RepositorySystemSession session = RepositoryUtility.newSession(system); ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(); request.addRepository(RepositoryUtility.CENTRAL); request.setArtifact(artifact); ArtifactDescriptorResult resolved = system.readArtifactDescriptor(session, request); for (Dependency dependency : resolved.getManagedDependencies()) { System.out.println(dependency); } }