Exemplo n.º 1
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);
 }