예제 #1
0
 private void append(StringBuilder buffer, MojoExecution me) {
   buffer.append(me.getArtifactId()).append(':').append(me.getVersion());
   buffer.append(':').append(me.getGoal());
   if (me.getExecutionId() != null) {
     buffer.append(" (").append(me.getExecutionId()).append(')');
   }
 }
 @Override
 public org.apache.maven.plugin.MojoExecution newMojoExecution() {
   MojoExecution execution = super.newMojoExecution();
   Xpp3Dom compilerId = new Xpp3Dom("compilerId");
   compilerId.setValue("jdt");
   execution.getConfiguration().addChild(compilerId);
   return execution;
 };
 private MojoExecution getExecution(
     MavenExecutionPlan executionPlan, String artifactId, String goal) throws CoreException {
   for (MojoExecution execution : executionPlan.getMojoExecutions()) {
     if (artifactId.equals(execution.getArtifactId()) && goal.equals(execution.getGoal())) {
       return execution;
     }
   }
   return null;
 }
 public ClassRealm getPluginClassRealm(MavenSession session, MojoExecution mojoExecution)
     throws CoreException {
   IMaven mvn = MavenPlugin.getMaven();
   // call for side effect of ensuring that the realm is set in the
   // descriptor.
   mvn.getConfiguredMojo(session, mojoExecution, Mojo.class);
   MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
   return mojoDescriptor.getPluginDescriptor().getClassRealm();
 }
 protected MojoExecution findForkedExecution(
     MojoExecution primary, String groupId, String artifactId, String goal) {
   Map<String, List<MojoExecution>> forkedExecutions = primary.getForkedExecutions();
   MojoExecution goalExecution = null;
   for (List<MojoExecution> possibleExecutionList : forkedExecutions.values()) {
     for (MojoExecution possibleExecution : possibleExecutionList) {
       if (groupId.equals(possibleExecution.getGroupId())
           && artifactId.equals(possibleExecution.getArtifactId())
           && goal.equals(possibleExecution.getGoal())) {
         goalExecution = possibleExecution;
         break;
       }
     }
     if (goalExecution != null) {
       break;
     }
   }
   return goalExecution;
 }
  public Map<String, List<MojoExecution>> calculateLifecycleMappings(
      MavenSession session, MavenProject project, Lifecycle lifecycle, String lifecyclePhase)
      throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
          MojoNotFoundException, InvalidPluginDescriptorException {
    /*
     * Initialize mapping from lifecycle phase to bound mojos. The key set of this map denotes the phases the caller
     * is interested in, i.e. all phases up to and including the specified phase.
     */

    Map<String, Map<Integer, List<MojoExecution>>> mappings =
        new LinkedHashMap<String, Map<Integer, List<MojoExecution>>>();

    for (String phase : lifecycle.getPhases()) {
      Map<Integer, List<MojoExecution>> phaseBindings = new TreeMap<Integer, List<MojoExecution>>();

      mappings.put(phase, phaseBindings);

      if (phase.equals(lifecyclePhase)) {
        break;
      }
    }

    /*
     * Grab plugin executions that are bound to the selected lifecycle phases from project. The effective model of
     * the project already contains the plugin executions induced by the project's packaging type. Remember, all
     * phases of interest and only those are in the lifecyle mapping, if a phase has no value in the map, we are not
     * interested in any of the executions bound to it.
     */

    for (Plugin plugin : project.getBuild().getPlugins()) {
      for (PluginExecution execution : plugin.getExecutions()) {
        // if the phase is specified then I don't have to go fetch the plugin yet and pull it down
        // to examine the phase it is associated to.
        if (execution.getPhase() != null) {
          Map<Integer, List<MojoExecution>> phaseBindings = mappings.get(execution.getPhase());
          if (phaseBindings != null) {
            for (String goal : execution.getGoals()) {
              MojoExecution mojoExecution = new MojoExecution(plugin, goal, execution.getId());
              mojoExecution.setLifecyclePhase(execution.getPhase());
              addMojoExecution(phaseBindings, mojoExecution, execution.getPriority());
            }
          }
        }
        // if not then i need to grab the mojo descriptor and look at the phase that is specified
        else {
          for (String goal : execution.getGoals()) {
            MojoDescriptor mojoDescriptor =
                pluginManager.getMojoDescriptor(
                    plugin,
                    goal,
                    project.getRemotePluginRepositories(),
                    session.getRepositorySession());

            Map<Integer, List<MojoExecution>> phaseBindings =
                mappings.get(mojoDescriptor.getPhase());
            if (phaseBindings != null) {
              MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, execution.getId());
              mojoExecution.setLifecyclePhase(mojoDescriptor.getPhase());
              addMojoExecution(phaseBindings, mojoExecution, execution.getPriority());
            }
          }
        }
      }
    }

    Map<String, List<MojoExecution>> lifecycleMappings =
        new LinkedHashMap<String, List<MojoExecution>>();

    for (Map.Entry<String, Map<Integer, List<MojoExecution>>> entry : mappings.entrySet()) {
      List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();

      for (List<MojoExecution> executions : entry.getValue().values()) {
        mojoExecutions.addAll(executions);
      }

      lifecycleMappings.put(entry.getKey(), mojoExecutions);
    }

    return lifecycleMappings;
  }
예제 #7
0
 public ClassRealm getPluginRealm(MojoExecution mojoExecution)
     throws PluginManagerException, PluginResolutionException {
   return pluginManager.getPluginRealm(
       session, mojoExecution.getMojoDescriptor().getPluginDescriptor());
 }