Search in sources :

Example 1 with PluginExecution

use of org.apache.maven.model.PluginExecution in project maven-plugins by apache.

the class MavenJDOMWriter method iteratePluginExecution.

// -- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
     * Method iteratePluginExecution
     *
     * @param counter
     * @param childTag
     * @param parentTag
     * @param list
     * @param parent
     */
protected void iteratePluginExecution(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
    boolean shouldExist = list != null && list.size() > 0;
    Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        Counter innerCount = new Counter(counter.getDepth() + 1);
        while (it.hasNext()) {
            PluginExecution value = (PluginExecution) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updatePluginExecution(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Element(org.jdom.Element) Iterator(java.util.Iterator)

Example 2 with PluginExecution

use of org.apache.maven.model.PluginExecution in project felix by apache.

the class MavenJDOMWriter method iteratePluginExecution.

// -- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
 * Method iteratePluginExecution
 *
 * @param counter
 * @param childTag
 * @param parentTag
 * @param list
 * @param parent
 */
protected void iteratePluginExecution(Counter counter, Element parent, Collection list, String parentTag, String childTag) {
    boolean shouldExist = list != null && list.size() > 0;
    Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        Counter innerCount = new Counter(counter.getDepth() + 1);
        while (it.hasNext()) {
            PluginExecution value = (PluginExecution) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updatePluginExecution(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Element(org.jdom.Element) Iterator(java.util.Iterator)

Example 3 with PluginExecution

use of org.apache.maven.model.PluginExecution in project intellij-plugins by JetBrains.

the class Maven method createMojoExecution.

public MojoExecution createMojoExecution(Plugin plugin, String goal, MavenProject project) throws Exception {
    if (plugin.getVersion() == null) {
        plugin.setVersion(plexusContainer.lookup(PluginVersionResolver.class).resolve(new DefaultPluginVersionRequest(plugin, session)).getVersion());
    }
    MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor(plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
    List<PluginExecution> executions = plugin.getExecutions();
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, executions.isEmpty() ? null : executions.get(executions.size() - 1).getId(), MojoExecution.Source.CLI);
    plexusContainer.lookup(LifecycleExecutionPlanCalculator.class).setupMojoExecution(session, project, mojoExecution);
    return mojoExecution;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) MojoExecution(org.apache.maven.plugin.MojoExecution) DefaultPluginVersionRequest(org.apache.maven.plugin.version.DefaultPluginVersionRequest) LifecycleExecutionPlanCalculator(org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator)

Example 4 with PluginExecution

use of org.apache.maven.model.PluginExecution in project fabric8 by jboss-fuse.

the class CreateProfileZipMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        if (isIgnoreProject())
            return;
        generateZip();
        if (reactorProjects != null) {
            List<MavenProject> pomZipProjects = new ArrayList<>();
            List<MavenProject> fabricZipGoalProjects = new ArrayList<>();
            List<MavenProject> fabricHasParentZipGoalProject = new ArrayList<MavenProject>();
            for (MavenProject reactorProject : reactorProjects) {
                if ("pom".equals(reactorProject.getPackaging())) {
                    pomZipProjects.add(reactorProject);
                }
                List<Plugin> buildPlugins = reactorProject.getBuildPlugins();
                for (Plugin buildPlugin : buildPlugins) {
                    String artifactId = buildPlugin.getArtifactId();
                    // TODO I guess we could try find if the "zip" goal is being invoked?
                    if ("fabric8-maven-plugin".equals(artifactId)) {
                        // TODO should we only consider reactorProjects which have a fabric8:zip goal?
                        Object goals = buildPlugin.getGoals();
                        boolean hasZipGoal = goals != null && goals.toString().contains("zip");
                        List<PluginExecution> executions = buildPlugin.getExecutions();
                        for (PluginExecution execution : executions) {
                            List<String> execGoals = execution.getGoals();
                            if (execGoals.contains("zip")) {
                                hasZipGoal = true;
                            }
                        }
                        getLog().debug("project " + reactorProject.getArtifactId() + " has zip goal: " + hasZipGoal);
                        fabricZipGoalProjects.add(reactorProject);
                    }
                }
            }
            // as that helps us detect the 'last' project when we do a full build from the entire project
            for (MavenProject project : fabricZipGoalProjects) {
                if (fabricZipGoalProjects.contains(project.getParent())) {
                    fabricHasParentZipGoalProject.add(project);
                }
            }
            // are we the last project?
            boolean last = reactorProjects.size() > 1 && project == reactorProjects.get(reactorProjects.size() - 1);
            if (!last) {
                // are we the last project with the zip goal, part of a group as they have a parent?
                // TODO: there can be multiple groups, so when we switch to a new group we should aggregate
                last = fabricHasParentZipGoalProject.size() > 1 && project == fabricHasParentZipGoalProject.get(fabricHasParentZipGoalProject.size() - 1);
            }
            if (!last) {
                // are we the last project with the zip goal?
                last = fabricZipGoalProjects.size() > 1 && project == fabricZipGoalProjects.get(fabricZipGoalProjects.size() - 1);
            }
            // which we can aggregate
            if (last) {
                getLog().info("");
                getLog().info("Creating aggregated profile zip");
                getLog().info("built the last fabric8:zip project so generating a combined zip for all " + fabricZipGoalProjects.size() + " projects with a fabric8:zip goal");
                // favor root project as the 1st project with fabric8:zip goal
                MavenProject rootProject = fabricZipGoalProjects.size() > 0 ? fabricZipGoalProjects.get(0) : reactorProjects.get(0);
                // we got the root project, now filter out pom projects which has the rootProject as one of their parents
                List<MavenProject> ourPomZipProjects = new ArrayList<MavenProject>();
                // include the root project if its a zip as well
                if (pomZipProjects.contains(rootProject)) {
                    ourPomZipProjects.add(rootProject);
                }
                ourPomZipProjects.add(rootProject);
                for (MavenProject zip : pomZipProjects) {
                    if (hasParent(zip, rootProject, true)) {
                        ourPomZipProjects.add(zip);
                    }
                }
                getLog().info("Choosing root project " + rootProject.getArtifactId() + " for generation of aggregated zip");
                generateAggregatedZip(rootProject, fabricZipGoalProjects, ourPomZipProjects);
            }
        }
    } catch (MojoFailureException e) {
        throw e;
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing", e);
    }
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyTreeBuilderException(org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) MavenProject(org.apache.maven.project.MavenProject) Plugin(org.apache.maven.model.Plugin)

Example 5 with PluginExecution

use of org.apache.maven.model.PluginExecution in project fabric8-maven-plugin by fabric8io.

the class SpringBootGenerator method isSpringBootRepackage.

private boolean isSpringBootRepackage() {
    MavenProject project = getProject();
    Plugin plugin = project.getPlugin(SPRING_BOOT_MAVEN_PLUGIN_GA);
    if (plugin != null) {
        Map<String, PluginExecution> executionsAsMap = plugin.getExecutionsAsMap();
        if (executionsAsMap != null) {
            for (PluginExecution execution : executionsAsMap.values()) {
                List<String> goals = execution.getGoals();
                if (goals.contains("repackage")) {
                    log.verbose("Using fat jar packaging as the spring boot plugin is using `repackage` goal execution");
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) MavenProject(org.apache.maven.project.MavenProject) Plugin(org.apache.maven.model.Plugin)

Aggregations

PluginExecution (org.apache.maven.model.PluginExecution)32 Plugin (org.apache.maven.model.Plugin)22 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)18 ArrayList (java.util.ArrayList)8 Build (org.apache.maven.model.Build)6 Dependency (org.apache.maven.model.Dependency)6 Model (org.apache.maven.model.Model)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Element (org.jdom.Element)4 Iterator (java.util.Iterator)3 MavenProject (org.apache.maven.project.MavenProject)3 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)3 File (java.io.File)2 ConfigurationContainer (org.apache.maven.model.ConfigurationContainer)2 Repository (org.apache.maven.model.Repository)2 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)2 Project (org.commonjava.maven.ext.common.model.Project)2 CorePlugin (org.talend.core.CorePlugin)2