org.eclipse.aether.RepositoryException Java Examples
The following examples show how to use
org.eclipse.aether.RepositoryException.
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: DashboardMain.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
private static void generateAllVersions(String versionlessCoordinates) throws IOException, TemplateException, RepositoryException, URISyntaxException, MavenRepositoryException { List<String> elements = Splitter.on(':').splitToList(versionlessCoordinates); checkArgument( elements.size() == 2, "The versionless coordinates should have one colon character: " + versionlessCoordinates); String groupId = elements.get(0); String artifactId = elements.get(1); RepositorySystem repositorySystem = RepositoryUtility.newRepositorySystem(); ImmutableList<String> versions = RepositoryUtility.findVersions(repositorySystem, groupId, artifactId); for (String version : versions) { generate(String.format("%s:%s:%s", groupId, artifactId, version)); } generateVersionIndex(groupId, artifactId, versions); }
Example #2
Source File: ClassPathBuilderTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
/** Test that BOM members come before the transitive dependencies. */ @Test public void testBomToPaths_firstElementsAreBomMembers() throws RepositoryException { List<Artifact> managedDependencies = Bom.readBom("com.google.cloud:google-cloud-bom:0.81.0-alpha") .getManagedDependencies(); ImmutableList<ClassPathEntry> classPath = classPathBuilder.resolve(managedDependencies).getClassPath(); ImmutableList<ClassPathEntry> entries = ImmutableList.copyOf(classPath); Truth.assertThat(entries.get(0).toString()) .isEqualTo("com.google.api:api-common:1.7.0"); // first element in the BOM int bomSize = managedDependencies.size(); String lastFileName = entries.get(bomSize - 1).toString(); Truth.assertThat(lastFileName) .isEqualTo("com.google.api:gax-httpjson:0.57.0"); // last element in BOM }
Example #3
Source File: LinkageCheckerArguments.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
/** * Returns a list of artifacts specified in the option of BOM or coordinates list. If the argument * is not specified, returns an empty list. */ ImmutableList<Artifact> getArtifacts() throws RepositoryException { if (cachedArtifacts != null) { return cachedArtifacts; } if (commandLine.hasOption("b")) { String bomCoordinates = commandLine.getOptionValue("b"); return cachedArtifacts = Bom.readBom(bomCoordinates, getMavenRepositoryUrls()) .getManagedDependencies(); } else if (commandLine.hasOption("a")) { // option 'a' String[] mavenCoordinatesOption = commandLine.getOptionValues("a"); return cachedArtifacts = Arrays.stream(mavenCoordinatesOption) .map(DefaultArtifact::new) .collect(toImmutableList()); } else { return ImmutableList.of(); } }
Example #4
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 #5
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testArtifactTransferError() throws RepositoryException, DependencyResolutionException { DependencyNode graph = createResolvedDependencyGraph("org.apache.maven:maven-core:jar:3.5.2"); DependencyResolutionResult resolutionResult = mock(DependencyResolutionResult.class); when(resolutionResult.getDependencyGraph()).thenReturn(graph); DependencyResolutionException exception = createDummyResolutionException( new DefaultArtifact("aopalliance:aopalliance:1.0"), resolutionResult); when(mockProjectDependenciesResolver.resolve(any())).thenThrow(exception); try { rule.execute(mockRuleHelper); fail("The rule should throw EnforcerRuleException upon dependency resolution exception"); } catch (EnforcerRuleException expected) { verify(mockLog) .warn( "aopalliance:aopalliance:jar:1.0 was not resolved. " + "Dependency path: a:b:jar:0.1 > " + "org.apache.maven:maven-core:jar:3.5.2 (compile) > " + "com.google.inject:guice:jar:no_aop:4.0 (compile) > " + "aopalliance:aopalliance:jar:1.0 (compile)"); } }
Example #6
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testExecute_shouldFilterExclusionRule() throws RepositoryException, URISyntaxException { try { // This artifact is known to contain classes missing dependencies setupMockDependencyResolution("com.google.appengine:appengine-api-1.0-sdk:1.9.64"); String exclusionFileLocation = Paths.get(ClassLoader.getSystemResource("appengine-exclusion.xml").toURI()) .toAbsolutePath() .toString(); rule.setExclusionFile(exclusionFileLocation); rule.execute(mockRuleHelper); Assert.fail( "The rule should raise an EnforcerRuleException for artifacts missing dependencies"); } catch (EnforcerRuleException ex) { // pass. // The number of errors was 112 in testExecute_shouldFailForBadProjectWithBundlePackaging verify(mockLog).error(ArgumentMatchers.startsWith("Linkage Checker rule found 93 errors.")); assertEquals("Failed while checking class path. See above error report.", ex.getMessage()); } }
Example #7
Source File: LinkageCheckerMainIntegrationTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testWriteLinkageErrorsAsExclusionFile() throws IOException, RepositoryException, TransformerException, XMLStreamException, LinkageCheckResultException { Path exclusionFile = Files.createTempFile("exclusion-file", ".xml"); exclusionFile.toFile().deleteOnExit(); // When --output-exclusion-file is specified, the tool should not return failure (non-zero) // status upon finding linkage errors. LinkageCheckerMain.main( new String[] { "-a", "com.google.cloud:google-cloud-firestore:0.65.0-beta", "-o", exclusionFile.toString() }); String output = readCapturedStdout(); assertEquals( "Wrote the linkage errors as exclusion file: " + exclusionFile + System.lineSeparator(), output); }
Example #8
Source File: LinkageCheckerTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testGenerateInputClasspathFromLinkageCheckOption_mavenBom() throws RepositoryException, ParseException, IOException { String bomCoordinates = "com.google.cloud:google-cloud-bom:0.81.0-alpha"; LinkageCheckerArguments parsedArguments = LinkageCheckerArguments.readCommandLine("-b", bomCoordinates); ImmutableList<ClassPathEntry> inputClasspath = classPathBuilder.resolve(parsedArguments.getArtifacts()).getClassPath(); Truth.assertThat(inputClasspath).isNotEmpty(); // The first artifacts Truth.assertThat(inputClasspath) .comparingElementsUsing(COORDINATES) .containsAtLeast( "com.google.api:api-common:1.7.0", "com.google.api.grpc:proto-google-common-protos:1.14.0", "com.google.api.grpc:grpc-google-common-protos:1.14.0"); // gax-bom, containing com.google.api:gax:1.42.0, is in the BOM with scope:import assertTrue( inputClasspath.stream() .anyMatch(entry -> entry.getJar().toString().contains("gax-1.40.0.jar"))); }
Example #9
Source File: LinkageCheckerTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testGenerateInputClasspath_mavenCoordinates() throws RepositoryException, ParseException, IOException { String mavenCoordinates = "com.google.cloud:google-cloud-compute:jar:0.67.0-alpha," + "com.google.cloud:google-cloud-bigtable:jar:0.66.0-alpha"; LinkageCheckerArguments parsedArguments = LinkageCheckerArguments.readCommandLine("--artifacts", mavenCoordinates); List<ClassPathEntry> inputClasspath = classPathBuilder.resolve(parsedArguments.getArtifacts()).getClassPath(); Truth.assertWithMessage( "The first 2 items in the classpath should be the 2 artifacts in the input") .that(inputClasspath.subList(0, 2)) .comparingElementsUsing(COORDINATES) .containsExactly( "com.google.cloud:google-cloud-compute:0.67.0-alpha", "com.google.cloud:google-cloud-bigtable:0.66.0-alpha") .inOrder(); Truth.assertWithMessage("The dependencies of the 2 artifacts should also be included") .that(inputClasspath.subList(2, inputClasspath.size())) .isNotEmpty(); }
Example #10
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testExecute_shouldFailForBadProject_reachableErrors() throws RepositoryException { try { // This pair of artifacts contains linkage errors on grpc-core's use of Verify. Because // grpc-core is included in entry point jars, the errors are reachable. setupMockDependencyResolution( "com.google.api-client:google-api-client:1.27.0", "io.grpc:grpc-core:1.17.1"); rule.setReportOnlyReachable(true); rule.execute(mockRuleHelper); Assert.fail( "The rule should raise an EnforcerRuleException for artifacts with reachable errors"); } catch (EnforcerRuleException ex) { // pass verify(mockLog) .error(ArgumentMatchers.startsWith("Linkage Checker rule found 1 reachable error.")); assertEquals( "Failed while checking class path. See above error report.", ex.getMessage()); } }
Example #11
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testExecute_shouldFailForBadProject() throws RepositoryException { try { // This artifact is known to contain classes missing dependencies setupMockDependencyResolution("com.google.appengine:appengine-api-1.0-sdk:1.9.64"); rule.execute(mockRuleHelper); Assert.fail( "The rule should raise an EnforcerRuleException for artifacts missing dependencies"); } catch (EnforcerRuleException ex) { // pass ArgumentCaptor<String> errorMessageCaptor = ArgumentCaptor.forClass(String.class); verify(mockLog, times(2)).error(errorMessageCaptor.capture()); List<String> errorMessages = errorMessageCaptor.getAllValues(); Truth.assertThat(errorMessages.get(0)).startsWith("Linkage Checker rule found 112 errors."); Truth.assertThat(errorMessages.get(1)) .startsWith( "Problematic artifacts in the dependency tree:\n" + "com.google.appengine:appengine-api-1.0-sdk:1.9.64 is at:\n" + " a:b:jar:0.1 / com.google.appengine:appengine-api-1.0-sdk:1.9.64 (compile)"); assertEquals("Failed while checking class path. See above error report.", ex.getMessage()); } }
Example #12
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testExecute_shouldPassGoodProject_sessionProperties() throws EnforcerRuleException, RepositoryException, DependencyResolutionException { setupMockDependencyResolution("com.google.guava:guava:27.0.1-jre"); rule.execute(mockRuleHelper); ArgumentCaptor<DependencyResolutionRequest> argumentCaptor = ArgumentCaptor.forClass(DependencyResolutionRequest.class); verify(mockProjectDependenciesResolver).resolve(argumentCaptor.capture()); Map<String, String> propertiesUsedInSession = argumentCaptor.getValue().getRepositorySession().getSystemProperties(); Truth.assertWithMessage( "RepositorySystemSession should have variables such as os.detected.classifier") .that(propertiesUsedInSession) .containsAtLeastEntriesIn(OsProperties.detectOsProperties()); // There was a problem in resolving profiles because original properties were missing (#817) Truth.assertWithMessage("RepositorySystemSession should have original properties") .that(propertiesUsedInSession) .containsAtLeastEntriesIn(repositorySystemSession.getSystemProperties()); }
Example #13
Source File: LinkageCheckerTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testGenerateInputClasspathFromLinkageCheckOption_mavenCoordinates_missingDependency() throws RepositoryException, ParseException, IOException { // guava-gwt has missing transitive dependency: // com.google.guava:guava-gwt:jar:20.0 // com.google.gwt:gwt-dev:jar:2.8.0 (provided) // org.eclipse.jetty:apache-jsp:jar:9.2.14.v20151106 (compile) // org.mortbay.jasper:apache-jsp:jar:8.0.9.M3 (compile) // org.apache.tomcat:tomcat-jasper:jar:8.0.9 (compile, optional:true) // org.eclipse.jdt.core.compiler:ecj:jar:4.4RC4 (not found in Maven central) // Because such case is possible, LinkageChecker should not abort execution when // the unavailable dependency is under certain condition LinkageCheckerArguments parsedArguments = LinkageCheckerArguments.readCommandLine("--artifacts", "com.google.guava:guava-gwt:20.0"); ImmutableList<ClassPathEntry> inputClasspath = classPathBuilder.resolve(parsedArguments.getArtifacts()).getClassPath(); Truth.assertThat(inputClasspath) .comparingElementsUsing(COORDINATES) .contains("org.mortbay.jasper:apache-jsp:8.0.9.M3"); }
Example #14
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
private void setupMockDependencyResolution(String... coordinates) throws RepositoryException { // The root node is Maven artifact "a:b:0.1" that has dependencies specified as `coordinates`. DependencyNode rootNode = createResolvedDependencyGraph(coordinates); Traverser<DependencyNode> traverser = Traverser.forGraph(node -> node.getChildren()); // DependencyResolutionResult.getDependencies returns depth-first order ImmutableList<Dependency> dummyDependencies = ImmutableList.copyOf(traverser.depthFirstPreOrder(rootNode)).stream() .map(DependencyNode::getDependency) .filter(Objects::nonNull) .collect(toImmutableList()); when(mockDependencyResolutionResult.getDependencies()).thenReturn(dummyDependencies); when(mockDependencyResolutionResult.getResolvedDependencies()) .thenReturn( ImmutableList.copyOf(traverser.breadthFirst(rootNode.getChildren())).stream() .map(DependencyNode::getDependency) .filter(Objects::nonNull) .collect(toImmutableList())); when(mockDependencyResolutionResult.getDependencyGraph()).thenReturn(rootNode); when(mockProject.getDependencies()) .thenReturn( dummyDependencies.subList(0, coordinates.length).stream() .map(LinkageCheckerRuleTest::toDependency) .collect(Collectors.toList())); }
Example #15
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
/** * Returns a dependency graph node resolved from {@code coordinates}. */ private DependencyNode createResolvedDependencyGraph(String... coordinates) throws RepositoryException { CollectRequest collectRequest = new CollectRequest(); collectRequest.setRootArtifact(dummyArtifactWithFile); collectRequest.setRepositories(ImmutableList.of(RepositoryUtility.CENTRAL)); collectRequest.setDependencies( Arrays.stream(coordinates) .map(DefaultArtifact::new) .map(artifact -> new Dependency(artifact, "compile")) .collect(toImmutableList())); DependencyNode dependencyNode = repositorySystem.collectDependencies(repositorySystemSession, collectRequest).getRoot(); DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setRoot(dependencyNode); DependencyResult dependencyResult = repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest); return dependencyResult.getRoot(); }
Example #16
Source File: ArtifactResolverTest.java From revapi with Apache License 2.0 | 6 votes |
@Test public void testResolvesCompileAndTransitiveProvidedScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(true, true); CollectionResult res = resolver.collectTransitiveDeps("used-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(6, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-provided"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("provided"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-provided-compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-provided-provided"::equals).count()); }
Example #17
Source File: LinkageMonitor.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
public static void main(String[] arguments) throws RepositoryException, IOException, MavenRepositoryException, ModelBuildingException { if (arguments.length < 1 || arguments[0].split(":").length != 2) { logger.severe( "Please specify BOM coordinates without version. Example:" + " com.google.cloud:libraries-bom"); System.exit(1); } String bomCoordinates = arguments[0]; List<String> coordinatesElements = Splitter.on(':').splitToList(bomCoordinates); Set<SymbolProblem> newSymbolProblems = new LinkageMonitor().run(coordinatesElements.get(0), coordinatesElements.get(1)); int errorSize = newSymbolProblems.size(); if (errorSize > 0) { logger.severe( String.format("Found %d new linkage error%s", errorSize, errorSize > 1 ? "s" : "")); logger.info( "For the details of the linkage errors, see " + "https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/Linkage-Checker-Messages"); System.exit(1); // notify CI tools of the failure } else { logger.info("No new problem found"); } }
Example #18
Source File: LinkageCheckerTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testGenerateInputClasspathFromLinkageCheckOption_recordMissingDependency() throws ParseException, RepositoryException, IOException { // tomcat-jasper has missing dependency (not optional): // org.apache.tomcat:tomcat-jasper:jar:8.0.9 // org.eclipse.jdt.core.compiler:ecj:jar:4.4RC4 (not found in Maven central) LinkageCheckerArguments parsedArguments = LinkageCheckerArguments.readCommandLine( "--artifacts", "org.apache.tomcat:tomcat-jasper:8.0.9"); ImmutableList<UnresolvableArtifactProblem> artifactProblems = classPathBuilder.resolve(parsedArguments.getArtifacts()).getArtifactProblems(); Truth.assertThat(artifactProblems) .comparingElementsUsing( Correspondence.transforming( (UnresolvableArtifactProblem problem) -> problem.getArtifact().toString(), "problem with Maven coordinate")) .contains("org.eclipse.jdt.core.compiler:ecj:jar:4.4RC4"); }
Example #19
Source File: ExclusionFilesIntegrationTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testExclusion() throws IOException, RepositoryException, TransformerException, XMLStreamException, LinkageCheckResultException { Artifact artifact = new DefaultArtifact("org.apache.beam:beam-runners-google-cloud-dataflow-java:2.19.0"); LinkageCheckerMain.main( new String[] {"-a", Artifacts.toCoordinates(artifact), "-o", exclusionFile.toString()}); ClassPathBuilder classPathBuilder = new ClassPathBuilder(); ClassPathResult classPathResult = classPathBuilder.resolve(ImmutableList.of(artifact)); LinkageChecker linkagechecker = LinkageChecker.create(classPathResult.getClassPath(), ImmutableList.of(), exclusionFile); ImmutableSetMultimap<SymbolProblem, ClassFile> symbolProblems = linkagechecker.findSymbolProblems(); Truth.assertThat(symbolProblems).isEmpty(); }
Example #20
Source File: Resolver.java From buck with Apache License 2.0 | 6 votes |
private ImmutableMap<String, Artifact> getRunTimeTransitiveDeps(Iterable<Dependency> mavenCoords) throws RepositoryException { CollectRequest collectRequest = new CollectRequest(); collectRequest.setRequestContext(JavaScopes.RUNTIME); collectRequest.setRepositories(repos); for (Dependency dep : mavenCoords) { collectRequest.addDependency(dep); } DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter); DependencyResult dependencyResult = repoSys.resolveDependencies(session, dependencyRequest); ImmutableSortedMap.Builder<String, Artifact> knownDeps = ImmutableSortedMap.naturalOrder(); for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) { Artifact node = artifactResult.getArtifact(); knownDeps.put(buildKey(node), node); } return knownDeps.build(); }
Example #21
Source File: ResolverIntegrationTest.java From buck with Apache License 2.0 | 5 votes |
private void resolveWithArtifacts(String... artifacts) throws URISyntaxException, IOException, RepositoryException, ExecutionException, InterruptedException { ArtifactConfig config = newConfig(); config.repositories.add(new Repository(httpd.getUri("/").toString())); config.artifacts.addAll(Arrays.asList(artifacts)); config.visibility.add("PUBLIC"); new Resolver(config).resolve(config.artifacts); }
Example #22
Source File: LinkageCheckerArgumentsTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@Test public void testReadCommandLine_multipleArtifacts() throws ParseException, RepositoryException { LinkageCheckerArguments parsedArguments = LinkageCheckerArguments.readCommandLine( "--artifacts", "com.google.guava:guava:26.0,io.grpc:grpc-core:1.17.1"); Truth.assertThat(parsedArguments.getArtifacts()).hasSize(2); }
Example #23
Source File: DependencyResolver.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static Collection<Dependency> _getManagedDependencies( IMavenExecutionContext context, RepositorySystem system, String groupId, String artifactId, String version, SubMonitor monitor) throws CoreException { ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(); String coords = groupId + ":" + artifactId + ":" + version; Artifact artifact = new DefaultArtifact(coords); request.setArtifact(artifact); request.setRepositories(centralRepository(system)); // ensure checksum errors result in failure DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(context.getRepositorySession()); session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL); try { List<Dependency> managedDependencies = system.readArtifactDescriptor(session, request).getManagedDependencies(); return managedDependencies; } catch (RepositoryException ex) { IStatus status = StatusUtil.error(DependencyResolver.class, ex.getMessage(), ex); throw new CoreException(status); } }
Example #24
Source File: NewestVersionSelector.java From wildfly-swarm with Apache License 2.0 | 5 votes |
@Override public void selectVersion(ConflictResolver.ConflictContext context) throws RepositoryException { ConflictGroup group = new ConflictGroup(); for (ConflictResolver.ConflictItem item : context.getItems()) { DependencyNode node = item.getNode(); VersionConstraint constraint = node.getVersionConstraint(); boolean backtrack = false; boolean hardConstraint = constraint.getRange() != null; if (hardConstraint) { if (group.constraints.add(constraint)) { if (group.winner != null && !constraint.containsVersion(group.winner.getNode().getVersion())) { backtrack = true; } } } if (isAcceptable(group, node.getVersion())) { group.candidates.add(item); if (backtrack) { backtrack(group, context); } else if (group.winner == null || isNewer(item, group.winner)) { group.winner = item; } } else if (backtrack) { backtrack(group, context); } } context.setWinner(group.winner); }
Example #25
Source File: AetherImporter.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
/** * Prepare an import with dependencies * <p> * This method does resolve even transient dependencies and also adds the * sources if requested * </p> */ public static AetherResult prepareDependencies ( final Path tmpDir, final ImportConfiguration cfg ) throws RepositoryException { Objects.requireNonNull ( tmpDir ); Objects.requireNonNull ( cfg ); final RepositoryContext ctx = new RepositoryContext ( tmpDir, cfg.getRepositoryUrl (), cfg.isAllOptional () ); // add all coordinates final CollectRequest cr = new CollectRequest (); cr.setRepositories ( ctx.getRepositories () ); for ( final MavenCoordinates coords : cfg.getCoordinates () ) { final Dependency dep = new Dependency ( new DefaultArtifact ( coords.toString () ), COMPILE ); cr.addDependency ( dep ); } final DependencyFilter filter = DependencyFilterUtils.classpathFilter ( COMPILE ); final DependencyRequest deps = new DependencyRequest ( cr, filter ); // resolve final DependencyResult dr = ctx.getSystem ().resolveDependencies ( ctx.getSession (), deps ); final List<ArtifactResult> arts = dr.getArtifactResults (); if ( !cfg.isIncludeSources () ) { // we are already done here return asResult ( arts, cfg, of ( dr ) ); } // resolve sources final List<ArtifactRequest> requests = extendRequests ( arts.stream ().map ( ArtifactResult::getRequest ), ctx, cfg ); return asResult ( resolve ( ctx, requests ), cfg, of ( dr ) ); }
Example #26
Source File: Analyzer.java From revapi with Apache License 2.0 | 5 votes |
private Set<MavenArchive> collectDeps(String depDescription, ArtifactResolver resolver, String... gavs) { try { if (gavs == null) { return Collections.emptySet(); } ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gavs); return collectDeps(depDescription, res); } catch (RepositoryException e) { return handleResolutionError(e, depDescription, null); } }
Example #27
Source File: Main.java From revapi with Apache License 2.0 | 5 votes |
private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix, File localRepo, List<RemoteRepository> remoteRepositories) { RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem(); DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem, new LocalRepository(localRepo)); session.setDependencySelector(getRevapiDependencySelector(true, false)); session.setDependencyTraverser(getRevapiDependencyTraverser(true, false)); ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories); List<FileArchive> archives = new ArrayList<>(); List<FileArchive> supplementaryArchives = new ArrayList<>(); for (String gav : gavs) { try { archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile())); ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav); res.getResolvedArtifacts(). forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile()))); if (!res.getFailures().isEmpty()) { LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString()); } } catch (RepositoryException e) { throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage()); } } return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives); }
Example #28
Source File: ArtifactResolver.java From revapi with Apache License 2.0 | 5 votes |
public CollectionResult collectTransitiveDeps(String... gavs) throws RepositoryException { Set<Artifact> artifacts = new HashSet<>(); Set<Exception> failures = new HashSet<>(); for (String gav : gavs) { LOG.debug("Artifact resolution for {}", gav); collectTransitiveDeps(gav, artifacts, failures); } return new CollectionResult(failures, artifacts); }
Example #29
Source File: ArtifactResolverTest.java From revapi with Apache License 2.0 | 5 votes |
@Test public void testResolvesCompileScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(false, false); CollectionResult res = resolver.collectTransitiveDeps("used-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(2, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-compile"::equals).count()); }
Example #30
Source File: ArtifactResolverTest.java From revapi with Apache License 2.0 | 5 votes |
@Test public void testResolvesCompileAndTopLevelProvidedScopes() throws RepositoryException { ArtifactResolver resolver = getResolver(true, false); CollectionResult res = resolver.collectTransitiveDeps("used-scopes:root:0"); assertTrue(res.getFailures().isEmpty()); Set<Artifact> artifacts = res.getResolvedArtifacts(); assertEquals(4, artifacts.size()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-compile-compile"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("provided"::equals).count()); assertEquals(1, artifacts.stream().map(Artifact::getArtifactId).filter("deep-provided-compile"::equals).count()); }