Search in sources :

Example 11 with Plugin

use of org.apache.maven.model.Plugin in project kie-wb-common by kiegroup.

the class DefaultPomEditor method updatePom.

protected PluginPresents updatePom(Model model) {
    Build build = model.getBuild();
    if (build == null) {
        // pom without build tag
        model.setBuild(new Build());
        build = model.getBuild();
    }
    Boolean defaultCompilerPluginPresent = Boolean.FALSE;
    Boolean alternativeCompilerPluginPresent = Boolean.FALSE;
    Boolean kiePluginPresent = Boolean.FALSE;
    int alternativeCompilerPosition = 0;
    int defaultMavenCompilerPosition = 0;
    int kieMavenPluginPosition = 0;
    if (model.getPackaging().equals(KJAR_EXT)) {
        kiePluginPresent = Boolean.TRUE;
    }
    int i = 0;
    for (Plugin plugin : build.getPlugins()) {
        // check if is present the default maven compiler
        if (plugin.getGroupId().equals(conf.get(ConfigurationKey.MAVEN_PLUGINS)) && plugin.getArtifactId().equals(conf.get(ConfigurationKey.MAVEN_COMPILER_PLUGIN))) {
            defaultCompilerPluginPresent = Boolean.TRUE;
            defaultMavenCompilerPosition = i;
        }
        // check if is present the alternative maven compiler
        if (plugin.getGroupId().equals(conf.get(ConfigurationKey.ALTERNATIVE_COMPILER_PLUGINS)) && plugin.getArtifactId().equals(conf.get(ConfigurationKey.ALTERNATIVE_COMPILER_PLUGIN))) {
            alternativeCompilerPluginPresent = Boolean.TRUE;
            alternativeCompilerPosition = i;
        }
        // check if is present the kie maven plugin
        if (plugin.getGroupId().equals(conf.get(ConfigurationKey.KIE_MAVEN_PLUGINS)) && plugin.getArtifactId().equals(conf.get(ConfigurationKey.KIE_MAVEN_PLUGIN))) {
            kiePluginPresent = Boolean.TRUE;
            kieMavenPluginPosition = i;
        }
        i++;
    }
    Boolean overwritePOM = updatePOMModel(build, defaultCompilerPluginPresent, alternativeCompilerPluginPresent, kiePluginPresent, defaultMavenCompilerPosition, alternativeCompilerPosition, kieMavenPluginPosition);
    return new DefaultPluginPresents(defaultCompilerPluginPresent, alternativeCompilerPluginPresent, kiePluginPresent, overwritePOM);
}
Also used : Build(org.apache.maven.model.Build) Plugin(org.apache.maven.model.Plugin)

Example 12 with Plugin

use of org.apache.maven.model.Plugin 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 13 with Plugin

use of org.apache.maven.model.Plugin in project liferay-ide by liferay.

the class MavenUtil method getPlugin.

public static Plugin getPlugin(IMavenProjectFacade facade, String pluginKey, IProgressMonitor monitor) throws CoreException {
    Plugin retval = null;
    boolean loadedParent = false;
    MavenProject mavenProject = facade.getMavenProject(monitor);
    if (mavenProject != null) {
        retval = mavenProject.getPlugin(pluginKey);
    }
    if (retval == null) {
        // look through all parents to find if the plugin has been declared
        MavenProject parent = mavenProject.getParent();
        if (parent == null) {
            try {
                if (loadParentHierarchy(facade, monitor)) {
                    loadedParent = true;
                }
            } catch (CoreException ce) {
                LiferayMavenCore.logError("Error loading parent hierarchy", ce);
            }
        }
        while ((parent != null) && (retval == null)) {
            retval = parent.getPlugin(pluginKey);
            parent = parent.getParent();
        }
    }
    if (loadedParent) {
        mavenProject.setParent(null);
    }
    return retval;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) Plugin(org.apache.maven.model.Plugin) MavenPlugin(org.eclipse.m2e.core.MavenPlugin)

Example 14 with Plugin

use of org.apache.maven.model.Plugin in project liferay-ide by liferay.

the class MavenConfigProblemMarkerResolutionGenerator method correctMarker.

@Override
protected boolean correctMarker(IMarker marker) {
    boolean retval = false;
    IProject project = marker.getResource().getProject();
    if (FileUtil.notExists(project)) {
        return false;
    }
    IMavenProjectFacade projectFacade = MavenPlugin.getMavenProjectRegistry().getProject(marker.getResource().getProject());
    if (projectFacade != null) {
        MavenProject mavenProject = null;
        IProgressMonitor npm = new NullProgressMonitor();
        try {
            mavenProject = projectFacade.getMavenProject(npm);
        } catch (CoreException ce) {
        }
        if (mavenProject != null) {
            try {
                Plugin liferayMavenPlugin = MavenUtil.getPlugin(projectFacade, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, npm);
                if (liferayMavenPlugin != null) {
                    retval = true;
                }
            } catch (CoreException ce) {
            }
        }
    }
    return retval;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IProject(org.eclipse.core.resources.IProject) Plugin(org.apache.maven.model.Plugin) MavenPlugin(org.eclipse.m2e.core.MavenPlugin)

Example 15 with Plugin

use of org.apache.maven.model.Plugin in project liferay-ide by liferay.

the class LiferayMavenProjectConfigurator method _installNewLiferayFacet.

// Copied from
// org.eclipse.m2e.wtp.AbstractProjectConfiguratorDelegate#configureDeployedName()
private MavenProblemInfo _installNewLiferayFacet(IFacetedProject facetedProject, ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    MavenProblemInfo retval = null;
    String pluginType = MavenUtil.getLiferayMavenPluginType(request.getMavenProject());
    if (pluginType == null) {
        pluginType = ILiferayMavenConstants.DEFAULT_PLUGIN_TYPE;
    }
    Plugin liferayMavenPlugin = MavenUtil.getPlugin(request.getMavenProjectFacade(), ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
    Action action = _getNewLiferayFacetInstallAction(pluginType);
    if (action != null) {
        try {
            facetedProject.modify(Collections.singleton(action), monitor);
        } catch (Exception e) {
            try {
                SourceLocation location = SourceLocationHelper.findLocation(liferayMavenPlugin, SourceLocationHelper.CONFIGURATION);
                String problemMsg = NLS.bind(Msgs.facetInstallError, pluginType, e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
                retval = new MavenProblemInfo(location, e);
                retval.setMessage(problemMsg);
            } catch (Exception e1) {
            }
            LiferayMavenCore.logError("Unable to install liferay facet " + action.getProjectFacetVersion(), e.getCause());
        }
    }
    return retval;
}
Also used : SourceLocation(org.eclipse.m2e.core.internal.markers.SourceLocation) Action(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action) CoreException(org.eclipse.core.runtime.CoreException) MavenProblemInfo(org.eclipse.m2e.core.internal.markers.MavenProblemInfo) Plugin(org.apache.maven.model.Plugin)

Aggregations

Plugin (org.apache.maven.model.Plugin)140 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)39 MavenProject (org.apache.maven.project.MavenProject)26 Build (org.apache.maven.model.Build)22 PluginExecution (org.apache.maven.model.PluginExecution)22 ArrayList (java.util.ArrayList)20 Dependency (org.apache.maven.model.Dependency)17 File (java.io.File)15 Model (org.apache.maven.model.Model)15 HashMap (java.util.HashMap)12 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)12 CoreException (org.eclipse.core.runtime.CoreException)11 IOException (java.io.IOException)9 List (java.util.List)8 PluginManagement (org.apache.maven.model.PluginManagement)8 Map (java.util.Map)7 MavenSession (org.apache.maven.execution.MavenSession)7 ReportPlugin (org.apache.maven.model.ReportPlugin)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6