/**
   * Loads the dependency tree for the project via {@link #loadDependencyTree(MavenProject)} and
   * then uses the {@link DependencyNodeVisitor} to load the license data. If {@link #aggregating}
   * is enabled the method recurses on each child module.
   */
  @SuppressWarnings("unchecked")
  protected void parseProject(MavenProject project, DependencyNodeVisitor visitor)
      throws MojoExecutionException, MojoFailureException {
    final Log logger = this.getLog();
    logger.info("Parsing Dependencies for: " + project.getName());

    // Load and parse immediate dependencies
    final DependencyNode tree = this.loadDependencyTree(project);
    tree.accept(visitor);

    // If not including child deps don't recurse on modules
    if (!this.includeChildDependencies) {
      return;
    }

    // No child modules, return
    final List<MavenProject> collectedProjects = project.getCollectedProjects();
    if (collectedProjects == null) {
      return;
    }

    // Find all sub-modules for the project
    for (final MavenProject moduleProject : collectedProjects) {
      if (this.isExcluded(moduleProject, project.getArtifactId())) {
        continue;
      }

      this.parseProject(moduleProject, visitor);
    }
  }
  /*
   * Determine list of exports by bundles that have been marked provided in the pom
   * //TODO: we probably want to figure this out somewhere from the Karaf build itself instead of putting the burden on the user
   */
  private void readProvidedBundles() throws Exception {
    DependencyNode tree =
        dependencyTreeBuilder.buildDependencyTree(
            project,
            localRepo,
            factory,
            artifactMetadataSource,
            new ArtifactFilter() {

              public boolean include(Artifact artifact) {
                return true;
              }
            },
            collector);
    tree.accept(
        new DependencyNodeVisitor() {
          public boolean endVisit(DependencyNode node) {
            // we want the next sibling too
            return true;
          }

          public boolean visit(DependencyNode node) {
            if (node.getState() != DependencyNode.OMITTED_FOR_CONFLICT) {
              Artifact artifact = node.getArtifact();
              info("    scanning %s for exports", artifact);
              if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
                  && !artifact.getType().equals("pom")) {
                try {
                  for (Clause clause : ManifestUtils.getExports(getManifest("", artifact))) {
                    getLog()
                        .debug(" adding " + clause.getName() + " to list of available packages");
                    systemExports.add(clause.getName());
                  }
                } catch (ArtifactResolutionException e) {
                  error("Unable to find bundle exports for %s: %s", e, artifact, e.getMessage());
                } catch (ArtifactNotFoundException e) {
                  error("Unable to find bundle exports for %s: %s", e, artifact, e.getMessage());
                } catch (IOException e) {
                  error("Unable to find bundle exports for %s: %s", e, artifact, e.getMessage());
                }
              }
            }
            // we want the children too
            return true;
          }
        });
  }
 public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
   if (log == null) {
     log = helper.getLog();
   }
   try {
     if (i18n == null) {
       i18n = (I18N) helper.getComponent(I18N.class);
     }
     DependencyNode node = getNode(helper);
     RequireUpperBoundDepsVisitor visitor = new RequireUpperBoundDepsVisitor();
     node.accept(visitor);
     List<String> errorMessages = buildErrorMessages(visitor.getConflicts());
     if (errorMessages.size() > 0) {
       throw new EnforcerRuleException(
           "Failed while enforcing RequireUpperBoundDeps. The error(s) are " + errorMessages);
     }
   } catch (ComponentLookupException e) {
     throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e);
   } catch (Exception e) {
     throw new EnforcerRuleException(e.getLocalizedMessage(), e);
   }
 }
  /**
   * Create classpath URLs list.
   *
   * @return classpath URL list
   * @throws MojoFailureException error creating URLs list
   */
  @SuppressWarnings("unchecked")
  private List<URL> createClasspathURLsList() throws MojoFailureException {
    List<URL> urls = new LinkedList<URL>();

    // 1. Get all project dependencies
    DependencyNode rootNode = null;
    try {
      ArtifactFilter artifactFilter = new ScopeArtifactFilter(null);
      rootNode =
          treeBuilder.buildDependencyTree(
              project,
              localRepository,
              artifactFactory,
              artifactMetadataSource,
              artifactFilter,
              artifactCollector);
    } catch (DependencyTreeBuilderException e) {
      throw new MojoFailureException(e.getMessage());
    }

    CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();

    rootNode.accept(visitor);
    List<DependencyNode> nodes = visitor.getNodes();

    // 2. Get all URL dependencies
    Set<Artifact> artifacts = new HashSet<Artifact>();
    for (DependencyNode dependencyNode : nodes) {
      // Initialize artifact
      Artifact artifact = dependencyNode.getArtifact();
      if (artifacts.contains(artifact)) {
        // Artifact already parsed
        continue;
      }
      artifacts.add(artifact);

      // Skip non jar type
      if (!EXTENSION_JAR.equalsIgnoreCase(artifact.getType())) {
        continue;
      }

      if (artifact.getArtifactId().equals(project.getArtifactId())) {
        getLog().info("Skip artifact: " + artifact);
        continue;
      }

      // Other scope
      try {
        URL url = extractArtifactUrl(artifact);
        urls.add(url);
      } catch (IOException e) {
        getLog().warn("Can't get URL object for artifact: " + artifact);
        continue;
      }
    }

    /*
          try {
    	urls.add(new File(project.getBasedir(), "target/classes").toURI().toURL());
    } catch (MalformedURLException e) {
    	getLog().warn("Can't add the target/classes of current maven project to classpath. Error: " + e);
    }
          */

    return urls;
  }