public static void main(String[] args) throws Exception {

    final String uri = "com.carrotgarden.osgi:carrot-osgi-anno-scr-make:jar:1.1.3";

    final Artifact artifact = new DefaultArtifact(uri);

    Dependency dependency = new Dependency(artifact, "compile");

    CollectRequest collectRequest = new CollectRequest(dependency, null);

    RepositorySystem system = UnitHelp.newSystem();

    MavenRepositorySystemSession session = UnitHelp.newSession(system);

    session.setOffline(true);

    Collection<String> scopeIncluded = new ArrayList<String>();
    Collection<String> scopeExcluded = new ArrayList<String>();

    scopeIncluded.add("provided");

    scopeExcluded.add("test");

    session.setDependencySelector( //
        new AndDependencySelector( //
            new OptionalDependencySelector(), //
            new ScopeDependencySelector(scopeIncluded, scopeExcluded), //
            new ExclusionDependencySelector()) //
        );

    CollectResult collectResult = system.collectDependencies(session, collectRequest);

    DependencyNode collectNode = collectResult.getRoot();

    final DependencyRequest dependencyRequest = new DependencyRequest(collectNode, null);

    final DependencyResult result = system.resolveDependencies(session, dependencyRequest);

    final DependencyNode resolveNode = result.getRoot();

    final PreorderNodeListGenerator generator = new PreorderNodeListGenerator();

    resolveNode.accept(generator);

    List<Artifact> list = generator.getArtifacts(true);

    for (Artifact item : list) {
      System.out.println("item = " + item);
    }
  }
  DependencyHelper newHelper() throws Exception {

    final List<RemoteRepository> remoteList = new ArrayList<RemoteRepository>();
    remoteList.add(UnitHelp.newRepoRemote());

    final List<RemoteRepository> pluginRepos = remoteList;
    final List<RemoteRepository> projectRepos = remoteList;
    final RepositorySystem system = UnitHelp.newSystem();
    final RepositorySystemSession session = UnitHelp.newSession(system);

    final DependencyHelper helper =
        new DependencyHelper(pluginRepos, projectRepos, session, system);

    return helper;
  }
  @Test
  public void dependency() throws Exception {

    final String uri = "com.carrotgarden.osgi:carrot-osgi-anno-scr-make:pom:1.1.3";

    final DependencyHelper helper = newHelper();

    final MavenProject project = UnitHelp.newProject(uri);

    Collection<String> included = null;
    Collection<String> excluded = null;

    helper.getDependencies(project, true);

    final String report = helper.getTreeListing();

    System.out.println("\n" + report);
  }
Example #4
0
 @Configuration
 public Option[] config() {
   return UnitHelp.config();
 }