Exemplo n.º 1
0
  private static void mergePluginExecutionDefinitions(
      PluginExecution child, PluginExecution parent) {
    if (child.getPhase() == null) {
      child.setPhase(parent.getPhase());
    }

    List parentGoals = parent.getGoals();
    List childGoals = child.getGoals();

    List goals = new ArrayList();

    if ((childGoals != null) && !childGoals.isEmpty()) {
      goals.addAll(childGoals);
    }

    if (parentGoals != null) {
      for (Iterator goalIterator = parentGoals.iterator(); goalIterator.hasNext(); ) {
        String goal = (String) goalIterator.next();

        if (!goals.contains(goal)) {
          goals.add(goal);
        }
      }
    }

    child.setGoals(goals);

    Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
    Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();

    childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration, parentConfiguration);

    child.setConfiguration(childConfiguration);
  }
Exemplo n.º 2
0
 /**
  * Find and configure a mojor.
  *
  * @param coords Maven coordinates, e.g. "com.qulice:maven-qulice-plugin:1.0"
  * @param goal Maven plugin goal to execute
  * @param config The configuration to set
  * @throws ValidationException If something is wrong inside
  */
 public void execute(final String coords, final String goal, final Properties config)
     throws ValidationException {
   final Plugin plugin = new Plugin();
   final String[] sectors = StringUtils.split(coords, ':');
   plugin.setGroupId(sectors[0]);
   plugin.setArtifactId(sectors[1]);
   plugin.setVersion(sectors[2]);
   final MojoDescriptor descriptor = this.descriptor(plugin, goal);
   try {
     this.helper.setupPluginRealm(
         descriptor.getPluginDescriptor(),
         this.session,
         Thread.currentThread().getContextClassLoader(),
         new LinkedList<String>(),
         new LinkedList<String>());
   } catch (final PluginResolutionException ex) {
     throw new IllegalStateException("Plugin resolution problem", ex);
   } catch (final PluginContainerException ex) {
     throw new IllegalStateException("Can't setup realm", ex);
   }
   final Xpp3Dom xpp =
       Xpp3Dom.mergeXpp3Dom(
           this.toXppDom(config, "configuration"),
           this.toXppDom(descriptor.getMojoConfiguration()));
   final MojoExecution execution = new MojoExecution(descriptor, xpp);
   final Mojo mojo = this.mojo(execution);
   Logger.info(this, "Calling %s:%s...", coords, goal);
   try {
     mojo.execute();
   } catch (final MojoExecutionException ex) {
     throw new IllegalArgumentException(ex);
   } catch (final MojoFailureException ex) {
     throw new ValidationException(ex);
   }
   this.manager.releaseMojo(mojo, execution);
 }
Exemplo n.º 3
0
  public static void mergePluginDefinitions(
      Plugin child, Plugin parent, boolean handleAsInheritance) {
    if ((child == null) || (parent == null)) {
      // nothing to do.
      return;
    }

    if (parent.isExtensions()) {
      child.setExtensions(true);
    }

    if ((child.getVersion() == null) && (parent.getVersion() != null)) {
      child.setVersion(parent.getVersion());
    }

    Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
    Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();

    childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration, parentConfiguration);

    child.setConfiguration(childConfiguration);

    child.setDependencies(mergeDependencyList(child.getDependencies(), parent.getDependencies()));

    // from here to the end of the method is dealing with merging of the <executions/> section.
    String parentInherited = parent.getInherited();

    boolean parentIsInherited =
        (parentInherited == null) || Boolean.valueOf(parentInherited).booleanValue();

    List parentExecutions = parent.getExecutions();

    if ((parentExecutions != null) && !parentExecutions.isEmpty()) {
      List mergedExecutions = new ArrayList();

      Map assembledExecutions = new TreeMap();

      Map childExecutions = child.getExecutionsAsMap();

      for (Iterator it = parentExecutions.iterator(); it.hasNext(); ) {
        PluginExecution parentExecution = (PluginExecution) it.next();

        String inherited = parentExecution.getInherited();

        boolean parentExecInherited =
            parentIsInherited && ((inherited == null) || Boolean.valueOf(inherited).booleanValue());

        if (!handleAsInheritance || parentExecInherited) {
          PluginExecution assembled = parentExecution;

          PluginExecution childExecution =
              (PluginExecution) childExecutions.get(parentExecution.getId());

          if (childExecution != null) {
            mergePluginExecutionDefinitions(childExecution, parentExecution);

            assembled = childExecution;
          } else if (handleAsInheritance && (parentInherited == null)) {
            parentExecution.unsetInheritanceApplied();
          }

          assembledExecutions.put(assembled.getId(), assembled);
          mergedExecutions.add(assembled);
        }
      }

      for (Iterator it = child.getExecutions().iterator(); it.hasNext(); ) {
        PluginExecution childExecution = (PluginExecution) it.next();

        if (!assembledExecutions.containsKey(childExecution.getId())) {
          mergedExecutions.add(childExecution);
        }
      }

      child.setExecutions(mergedExecutions);

      child.flushExecutionMap();
    }
  }