@Test public void testTransitiveDependency() { try { Dependency dependency = resolver.resolve("org.apache.maven", "maven-artifact", mavenArtifactVersion, true); String jarPath = Utils.getJarPath(targetRepo, dependency.getDepedencies().get(0)); Assert.assertTrue(new File(jarPath).exists()); } catch (MavenResolverException e) { Assert.fail(e.getMessage()); } }
public org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version, boolean resolveTransitiveDependencies) throws MavenResolverException { Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version); if (resolveTransitiveDependencies) { try { DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE)); collectRequest.setRepositories(repositories); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); system.resolveDependencies(session, dependencyRequest); CollectResult collectResult = system.collectDependencies(session, collectRequest); DependencyNode node = collectResult.getRoot(); node.accept(new TreeDependencyVisitor(new DependencyVisitor() { int level = 0; @Override public boolean visitEnter(DependencyNode dependencyNode) { org.ballerinalang.maven.Dependency currentNode = convertDependency(dependencyNode); if (level == 0) { rootNode = currentNode; } else { org.ballerinalang.maven.Dependency parent = rootNode; for (int i = 0; i < level; i++) { if (level > 1) { parent = rootNode.getDepedencies().get(rootNode.getDepedencies().size() - 1); } } parent.addDependency(currentNode); } level += 1; return true; } @Override public boolean visitLeave(DependencyNode dependencyNode) { level -= 1; return true; } })); } catch (DependencyResolutionException | DependencyCollectionException e) { throw new MavenResolverException(e.getMessage()); } } else { try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(repositories); system.resolveArtifact(session, artifactRequest); rootNode = new org.ballerinalang.maven.Dependency(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } catch (ArtifactResolutionException e) { throw new MavenResolverException(e.getMessage()); } } return rootNode; }
MavenResolver { public org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version, boolean resolveTransitiveDependencies) throws MavenResolverException { Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version); if (resolveTransitiveDependencies) { try { DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE)); collectRequest.setRepositories(repositories); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); system.resolveDependencies(session, dependencyRequest); CollectResult collectResult = system.collectDependencies(session, collectRequest); DependencyNode node = collectResult.getRoot(); node.accept(new TreeDependencyVisitor(new DependencyVisitor() { int level = 0; @Override public boolean visitEnter(DependencyNode dependencyNode) { org.ballerinalang.maven.Dependency currentNode = convertDependency(dependencyNode); if (level == 0) { rootNode = currentNode; } else { org.ballerinalang.maven.Dependency parent = rootNode; for (int i = 0; i < level; i++) { if (level > 1) { parent = rootNode.getDepedencies().get(rootNode.getDepedencies().size() - 1); } } parent.addDependency(currentNode); } level += 1; return true; } @Override public boolean visitLeave(DependencyNode dependencyNode) { level -= 1; return true; } })); } catch (DependencyResolutionException | DependencyCollectionException e) { throw new MavenResolverException(e.getMessage()); } } else { try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(repositories); system.resolveArtifact(session, artifactRequest); rootNode = new org.ballerinalang.maven.Dependency(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } catch (ArtifactResolutionException e) { throw new MavenResolverException(e.getMessage()); } } return rootNode; } }
MavenResolver { public org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version, boolean resolveTransitiveDependencies) throws MavenResolverException { Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version); if (resolveTransitiveDependencies) { try { DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE)); collectRequest.setRepositories(repositories); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); system.resolveDependencies(session, dependencyRequest); CollectResult collectResult = system.collectDependencies(session, collectRequest); DependencyNode node = collectResult.getRoot(); node.accept(new TreeDependencyVisitor(new DependencyVisitor() { int level = 0; @Override public boolean visitEnter(DependencyNode dependencyNode) { org.ballerinalang.maven.Dependency currentNode = convertDependency(dependencyNode); if (level == 0) { rootNode = currentNode; } else { org.ballerinalang.maven.Dependency parent = rootNode; for (int i = 0; i < level; i++) { if (level > 1) { parent = rootNode.getDepedencies().get(rootNode.getDepedencies().size() - 1); } } parent.addDependency(currentNode); } level += 1; return true; } @Override public boolean visitLeave(DependencyNode dependencyNode) { level -= 1; return true; } })); } catch (DependencyResolutionException | DependencyCollectionException e) { throw new MavenResolverException(e.getMessage()); } } else { try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(repositories); system.resolveArtifact(session, artifactRequest); rootNode = new org.ballerinalang.maven.Dependency(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } catch (ArtifactResolutionException e) { throw new MavenResolverException(e.getMessage()); } } return rootNode; } MavenResolver(String targetLocation); }
MavenResolver { public org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version, boolean resolveTransitiveDependencies) throws MavenResolverException { Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version); if (resolveTransitiveDependencies) { try { DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE)); collectRequest.setRepositories(repositories); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); system.resolveDependencies(session, dependencyRequest); CollectResult collectResult = system.collectDependencies(session, collectRequest); DependencyNode node = collectResult.getRoot(); node.accept(new TreeDependencyVisitor(new DependencyVisitor() { int level = 0; @Override public boolean visitEnter(DependencyNode dependencyNode) { org.ballerinalang.maven.Dependency currentNode = convertDependency(dependencyNode); if (level == 0) { rootNode = currentNode; } else { org.ballerinalang.maven.Dependency parent = rootNode; for (int i = 0; i < level; i++) { if (level > 1) { parent = rootNode.getDepedencies().get(rootNode.getDepedencies().size() - 1); } } parent.addDependency(currentNode); } level += 1; return true; } @Override public boolean visitLeave(DependencyNode dependencyNode) { level -= 1; return true; } })); } catch (DependencyResolutionException | DependencyCollectionException e) { throw new MavenResolverException(e.getMessage()); } } else { try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(repositories); system.resolveArtifact(session, artifactRequest); rootNode = new org.ballerinalang.maven.Dependency(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } catch (ArtifactResolutionException e) { throw new MavenResolverException(e.getMessage()); } } return rootNode; } MavenResolver(String targetLocation); void addRepository(String id, String url); void addRepository(String id, String url, String username, String password); org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version,
                                                      boolean resolveTransitiveDependencies); }
MavenResolver { public org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version, boolean resolveTransitiveDependencies) throws MavenResolverException { Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":" + version); if (resolveTransitiveDependencies) { try { DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE)); collectRequest.setRepositories(repositories); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); system.resolveDependencies(session, dependencyRequest); CollectResult collectResult = system.collectDependencies(session, collectRequest); DependencyNode node = collectResult.getRoot(); node.accept(new TreeDependencyVisitor(new DependencyVisitor() { int level = 0; @Override public boolean visitEnter(DependencyNode dependencyNode) { org.ballerinalang.maven.Dependency currentNode = convertDependency(dependencyNode); if (level == 0) { rootNode = currentNode; } else { org.ballerinalang.maven.Dependency parent = rootNode; for (int i = 0; i < level; i++) { if (level > 1) { parent = rootNode.getDepedencies().get(rootNode.getDepedencies().size() - 1); } } parent.addDependency(currentNode); } level += 1; return true; } @Override public boolean visitLeave(DependencyNode dependencyNode) { level -= 1; return true; } })); } catch (DependencyResolutionException | DependencyCollectionException e) { throw new MavenResolverException(e.getMessage()); } } else { try { ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(repositories); system.resolveArtifact(session, artifactRequest); rootNode = new org.ballerinalang.maven.Dependency(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); } catch (ArtifactResolutionException e) { throw new MavenResolverException(e.getMessage()); } } return rootNode; } MavenResolver(String targetLocation); void addRepository(String id, String url); void addRepository(String id, String url, String username, String password); org.ballerinalang.maven.Dependency resolve(String groupId, String artifactId, String version,
                                                      boolean resolveTransitiveDependencies);  }