/**
   * Execute this Mojo.
   *
   * @throws MojoExecutionException if execution failed
   * @throws MojoFailureException if execution failed
   */
  public final void execute() throws MojoExecutionException, MojoFailureException {
    final ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler();
    if (!"java".equals(artifactHandler.getLanguage())) {
      getLog().info("Not executing EMMA, as the project is not a Java classpath-capable package");
      return;
    }

    checkParameters();
    doExecute();
  }
  /**
   * Mojo main entry
   *
   * @throws MojoExecutionException
   * @throws MojoFailureException
   */
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (skipMojo()) {
      return;
    }

    ArtifactHandler artifactHandler = getProject().getArtifact().getArtifactHandler();
    if (!"java".equals(artifactHandler.getLanguage())) {
      getLog()
          .info(
              "Not executing cobertura:instrument as the project is not a Java classpath-capable package");
    } else {
      if (!getDataFile().exists()) {
        getLog().info("Cannot perform check, instrumentation not performed - skipping.");
      } else {
        CheckTask task = new CheckTask();
        setTaskDefaults(task);
        task.setConfig(check);
        task.setDataFile(getDataFile().getAbsolutePath());

        task.execute();
      }
    }
  }
  @SuppressWarnings("unchecked")
  public void execute() throws MojoExecutionException {
    ArtifactVersion currentVersion = ri.getApplicationVersion();
    ArtifactVersion maxUsageVersion = new DefaultArtifactVersion("2.2.0");

    if (maxUsageVersion.compareTo(currentVersion) < 0) {
      getLog()
          .debug(
              "This version of Maven does not require injection of custom ArtifactHandlers using this code. Skipping.");
      return;
    }

    Map<String, ?> handlerDescriptors =
        session.getContainer().getComponentDescriptorMap(ArtifactHandler.ROLE);
    if (handlerDescriptors != null) {
      getLog().debug("Registering all unregistered ArtifactHandlers...");

      if (artifactHandlerManager instanceof DefaultArtifactHandlerManager) {
        Set<String> existingHints =
            ((DefaultArtifactHandlerManager) artifactHandlerManager).getHandlerTypes();
        if (existingHints != null) {
          for (String hint : existingHints) {
            handlerDescriptors.remove(hint);
          }
        }
      }

      if (handlerDescriptors.isEmpty()) {
        getLog().debug("All ArtifactHandlers are registered. Continuing...");
      } else {
        Map<String, ArtifactHandler> unregisteredHandlers =
            new HashMap<String, ArtifactHandler>(handlerDescriptors.size());

        for (String hint : handlerDescriptors.keySet()) {
          try {
            unregisteredHandlers.put(
                hint, (ArtifactHandler) session.lookup(ArtifactHandler.ROLE, hint));
            getLog().info("Adding ArtifactHandler for: " + hint);
          } catch (ComponentLookupException e) {
            getLog()
                .warn(
                    "Failed to lookup ArtifactHandler with hint: "
                        + hint
                        + ". Reason: "
                        + e.getMessage(),
                    e);
          }
        }

        artifactHandlerManager.addHandlers(unregisteredHandlers);
      }
    }

    getLog()
        .debug("...done.\nSetting ArtifactHandler on project-artifact: " + project.getId() + "...");

    Set<Artifact> artifacts = new HashSet<Artifact>();
    artifacts.add(project.getArtifact());

    Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    if (dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) {
      artifacts.addAll(dependencyArtifacts);
    }

    for (Artifact artifact : artifacts) {
      String type = artifact.getType();
      ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(type);

      getLog()
          .debug(
              "Artifact: "
                  + artifact.getId()
                  + "\nType: "
                  + type
                  + "\nArtifactHandler extension: "
                  + handler.getExtension());

      artifact.setArtifactHandler(handler);
    }

    getLog().debug("...done.");
  }