Ejemplo n.º 1
0
  public void execute() throws MojoExecutionException, MojoFailureException {
    List<Artifact> dependencies = (List<Artifact>) project.getRuntimeArtifacts();
    List<Artifact> excludes = new ArrayList<Artifact>(dependencies.size());

    for (Artifact artifact : dependencies) {
      // Rather than simply outputting all dependencies as excludes, we only want to output
      // an exclude for the direct children of the allowed artifact, because the other ones
      // will be disabled recursively by Maven.
      int allowedParentPos = getAllowedParentPostion(artifact.getDependencyTrail());
      if (allowedParentPos != -1 && allowedParentPos == artifact.getDependencyTrail().size() - 2) {
        excludes.add(artifact);
      }
    }

    if (excludes.size() > 0) {
      System.out.println();
      System.out.println();
      System.out.println();
      System.out.println("Please add these excludes to the lily-hbase-client pom:");
      System.out.println();
      for (Artifact artifact : excludes) {
        System.out.println("<exclusion>");
        System.out.println("  <groupId>" + artifact.getGroupId() + "</groupId>");
        System.out.println("  <artifactId>" + artifact.getArtifactId() + "</artifactId>");
        System.out.println("</exclusion>");
      }
      System.out.println();
      System.out.println();
      System.out.println();

      throw new MojoExecutionException("lily-hbase-client is missing some excludes, please adjust");
    }
  }
  /** put the dependencies that we are interested in using into the runtime object */
  private void prepareRuntimeDependencies(Runtime runtime, MavenProject project) {
    List artifactList = project.getRuntimeArtifacts();
    List dependencies = runtime.getJar().getDependencies();

    for (Iterator i = artifactList.iterator(); i.hasNext(); ) {
      Artifact artifact = (Artifact) i.next();

      String dependency =
          artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();

      // let preexisting dependencies take precedence
      if (!dependencies.contains(dependency)) {
        runtime.getJar().addDependency(dependency);
      }
    }
  }