Java Code Examples for org.apache.maven.model.Plugin#getExecutions()

The following examples show how to use org.apache.maven.model.Plugin#getExecutions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginPropertyUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** @see org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator */
private static @NonNull List<PluginExecution> getPluginExecutions(@NonNull Plugin plug, @NullAllowed String goal) {
    if (goal == null) {
        return Collections.emptyList();
    }
    List<PluginExecution> exes = new ArrayList<PluginExecution>();
    for (PluginExecution exe : plug.getExecutions()) {
        if (exe.getGoals().contains(goal) || /* #179328: Maven 2.2.0+ */ ("default-" + goal).equals(exe.getId())) {
            exes.add(exe);
        }
    }
    Collections.sort(exes, new Comparator<PluginExecution>() {
        @Override public int compare(PluginExecution e1, PluginExecution e2) {
            return e2.getPriority() - e1.getPriority();
        }
    });
    return exes;
}
 
Example 2
Source File: RequirePropertyDiverges.java    From extra-enforcer-rules with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of <tt>requirePropertyDiverges</tt> configurations from the map of plugins.
 *
 * @param plugins
 * @return list of requirePropertyDiverges configurations.
 */
List<Xpp3Dom> getRuleConfigurations( final Map<String, Plugin> plugins )
{
    if ( plugins.containsKey( MAVEN_ENFORCER_PLUGIN ) )
    {
        final List<Xpp3Dom> ruleConfigurations = new ArrayList<Xpp3Dom>();

        final Plugin enforcer = plugins.get( MAVEN_ENFORCER_PLUGIN );
        final Xpp3Dom configuration = ( Xpp3Dom ) enforcer.getConfiguration();

        // add rules from plugin configuration
        addRules( configuration, ruleConfigurations );

        // add rules from all plugin execution configurations
        for ( Object execution : enforcer.getExecutions() )
        {
            addRules( ( Xpp3Dom ) ( ( PluginExecution ) execution ).getConfiguration(), ruleConfigurations );
        }

        return ruleConfigurations;
    }
    else
    {
        return new ArrayList();
    }
}
 
Example 3
Source File: PluginExtractor.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the configuration for a specific goal of the given plugin from the Maven Project.
 *
 * @param mojo   the mojo
 * @param plugin the artifact id of the plugin
 * @param goal   the goal
 * @return the configuration, {@code null} if not found
 */
public static Xpp3Dom getBuildPluginConfigurationForGoal(AbstractWisdomMojo mojo, String plugin, String goal) {
    List<Plugin> plugins = mojo.project.getBuildPlugins();
    for (Plugin plug : plugins) {
        if (plug.getArtifactId().equals(plugin)) {
            // Check main execution
            List<String> globalGoals = (List<String>) plug.getGoals();
            if (globalGoals != null && globalGoals.contains(goal)) {
                return (Xpp3Dom) plug.getConfiguration();
            }
            // Check executions
            for (PluginExecution execution : plug.getExecutions()) {
                if (execution.getGoals().contains(goal)) {
                    return (Xpp3Dom) execution.getConfiguration();
                }
            }
        }
    }
    // Not found.
    return null;
}
 
Example 4
Source File: MavenUtil.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link PluginExecution} in the {@code mojoExecution}, if a
 * plugin is currently being executed.
 *
 * @param execution The {@link MojoExecution}.
 * @return The {@link PluginExecution} in the {@code mojoExecution}, if a
 *         plugin is currently being executed.
 * @throws NullPointerException If {@code execution} is null.
 */
public static PluginExecution getPluginExecution(final MojoExecution execution) {
  final Plugin plugin = execution.getPlugin();
  plugin.flushExecutionMap();
  for (final PluginExecution pluginExecution : plugin.getExecutions())
    if (pluginExecution.getId().equals(execution.getExecutionId()))
      return pluginExecution;

  return null;
}
 
Example 5
Source File: MojoUtils.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static Plugin checkProjectForMavenBuildPlugin(MavenProject project) {
    for (Plugin plugin : project.getBuildPlugins()) {
        if (plugin.getGroupId().equals("io.quarkus")
                && plugin.getArtifactId().equals("quarkus-maven-plugin")) {
            for (PluginExecution pluginExecution : plugin.getExecutions()) {
                if (pluginExecution.getGoals().contains("build")) {
                    return plugin;
                }
            }
        }
    }

    return null;
}
 
Example 6
Source File: RequiredMavenVersionFinder.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion getEnforcerMavenVersion() {
    List<Plugin> buildPlugins = mavenProject.getBuildPlugins();
    if (null == buildPlugins) {
        return null;
    }

    Plugin mavenEnforcerPlugin = getMavenEnforcerPlugin(buildPlugins);
    if (null == mavenEnforcerPlugin) {
        return null;
    }

    List<PluginExecution> pluginExecutions = mavenEnforcerPlugin.getExecutions();
    if (null == pluginExecutions) {
        return null;
    }

    List<PluginExecution> pluginExecutionsWithEnforceGoal = getPluginExecutionsWithEnforceGoal(pluginExecutions);
    if (pluginExecutionsWithEnforceGoal.isEmpty()) {
        return null;
    }
    
    Xpp3Dom requireMavenVersionTag = getRequireMavenVersionTag(pluginExecutionsWithEnforceGoal);
    if (null == requireMavenVersionTag) {
        return null;
    }

    Xpp3Dom versionTag = requireMavenVersionTag.getChild("version");
    if (null == versionTag) {
        return null;
    }

    String versionTagValue = versionTag.getValue();
    if (null == versionTagValue || "".equals(versionTagValue)) {
        return null;
    }

    return processMavenVersionRange(versionTagValue);
}
 
Example 7
Source File: RelocationManipulator.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private Map<ConfigurationContainer, String> findConfigurations( final Plugin plugin )
{
    if ( plugin == null )
    {
        return Collections.emptyMap();
    }

    final Map<ConfigurationContainer, String> configs = new LinkedHashMap<>();
    final Object pluginConfiguration = plugin.getConfiguration();

    if ( pluginConfiguration != null )
    {
        configs.put( plugin, pluginConfiguration.toString() );
    }

    final List<PluginExecution> executions = plugin.getExecutions();

    if ( executions != null )
    {
        for ( PluginExecution execution : executions )
        {
            final Object executionConfiguration = execution.getConfiguration();

            if ( executionConfiguration != null )
            {
                configs.put( execution, executionConfiguration.toString() );
            }
        }
    }

    return configs;
}
 
Example 8
Source File: ProjectHelper.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if this model is a single-project addon
 */
public boolean isAddon(Model model)
{
   boolean result = false;
   Build build = model.getBuild();
   if (build != null)
   {
      PLUGIN_LOOP: for (Plugin plugin : build.getPlugins())
      {
         if ("maven-jar-plugin".equals(plugin.getArtifactId()))
         {
            for (PluginExecution execution : plugin.getExecutions())
            {
               Xpp3Dom config = (Xpp3Dom) execution.getConfiguration();
               if (config != null)
               {
                  Xpp3Dom classifierNode = config.getChild("classifier");
                  if (classifierNode != null
                           && MavenAddonDependencyResolver.FORGE_ADDON_CLASSIFIER.equals(classifierNode.getValue()))
                  {
                     result = true;
                     break PLUGIN_LOOP;
                  }
               }
            }
         }
      }
   }
   return result;
}
 
Example 9
Source File: PluginExtractor.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the main configuration of the given plugin from the Maven Project.
 *
 * @param mojo       the mojo
 * @param artifactId the artifact id of the plugin
 * @param goal       an optional goal. If set if first check for a specific configuration executing this
 *                   goal, if not found, it returns the global configuration
 * @return the configuration, {@code null} if not found
 */
public static Xpp3Dom getBuildPluginConfiguration(AbstractWisdomMojo mojo, String artifactId, String goal) {
    List<Plugin> plugins = mojo.project.getBuildPlugins();

    Plugin plugin = null;
    for (Plugin plug : plugins) {
        if (plug.getArtifactId().equals(artifactId)) {
            plugin = plug;
        }
    }

    if (plugin == null) {
        // Not found
        return null;
    }

    if (goal != null) {
        // Check main execution
        List<String> globalGoals = (List<String>) plugin.getGoals();
        if (globalGoals != null && globalGoals.contains(goal)) {
            return (Xpp3Dom) plugin.getConfiguration();
        }
        // Check executions
        for (PluginExecution execution : plugin.getExecutions()) {
            if (execution.getGoals().contains(goal)) {
                return (Xpp3Dom) execution.getConfiguration();
            }
        }
    }
    // Global configuration.
    return (Xpp3Dom) plugin.getConfiguration();
}
 
Example 10
Source File: MavenProjectUtil.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
/**
 * Get an execution of a plugin
 * @param plugin
 * @param goal
 * @return the execution object
 * @throws PluginScenarioException
 */
public static PluginExecution getPluginGoalExecution(Plugin plugin, String goal) throws PluginScenarioException {
    List<PluginExecution> executions = plugin.getExecutions();
    
    for(Iterator<PluginExecution> iterator = executions.iterator(); iterator.hasNext();) {
        PluginExecution execution = (PluginExecution) iterator.next();
        if(execution.getGoals().contains(goal)) {
            return execution;
        }
    }
    throw new PluginScenarioException("Could not find goal " + goal + " on plugin " + plugin.getKey());
}
 
Example 11
Source File: DistributionEnforcingManipulator.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
/**
 * Go through the plugin / plugin-execution configurations and find references to the <code>skip</code> parameter for the given Maven plugin
 * instance.
 */
private List<SkipReference> findSkipRefs( final Plugin plugin, final Project project )
    throws ManipulationException
{
    if ( plugin == null )
    {
        return Collections.emptyList();
    }

    final Map<ConfigurationContainer, String> configs = new LinkedHashMap<>();
    Object configuration = plugin.getConfiguration();
    if ( configuration != null )
    {
        configs.put( plugin, configuration.toString() );
    }

    final List<PluginExecution> executions = plugin.getExecutions();
    if ( executions != null )
    {
        for ( final PluginExecution execution : executions )
        {
            configuration = execution.getConfiguration();
            if ( configuration != null )
            {
                configs.put( execution, configuration.toString() );
            }
        }
    }

    final List<SkipReference> result = new ArrayList<>();
    for ( final Map.Entry<ConfigurationContainer, String> entry : configs.entrySet() )
    {
        try
        {
            final Document doc = galleyWrapper.parseXml( entry.getValue() );
            final NodeList children = doc.getDocumentElement()
                                         .getChildNodes();
            if ( children != null )
            {
                for ( int i = 0; i < children.getLength(); i++ )
                {
                    final Node n = children.item( i );
                    if ( n.getNodeName()
                          .equals( SKIP_NODE ) )
                    {
                        result.add( new SkipReference( entry.getKey(), n ) );
                    }
                }
            }
        }
        catch ( final GalleyMavenXMLException e )
        {
            throw new ManipulationException( "Unable to parse config for plugin {} in {}", plugin.getId(), project.getKey(), e );
        }
    }

    return result;
}