Example usage for org.apache.maven.project MavenProject getBuildPlugins

List of usage examples for org.apache.maven.project MavenProject getBuildPlugins

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getBuildPlugins.

Prototype

public List<Plugin> getBuildPlugins() 

Source Link

Usage

From source file:io.fabric8.vertx.maven.plugin.utils.MojoUtils.java

License:Apache License

/**
 * @param project/*w  ww .  j ava  2s  . co  m*/
 * @param mavenSession
 * @param buildPluginManager
 * @throws Exception
 */
public void compile(MavenProject project, MavenSession mavenSession, BuildPluginManager buildPluginManager)
        throws Exception {

    Optional<Plugin> mvnCompilerPlugin = project.getBuildPlugins().stream()
            .filter(plugin -> A_MAVEN_COMPILER_PLUGIN.equals(plugin.getArtifactId())).findFirst();

    String pluginVersion = properties.getProperty(V_MAVEN_COMPILER_PLUGIN);

    if (mvnCompilerPlugin.isPresent()) {
        pluginVersion = mvnCompilerPlugin.get().getVersion();
    }

    Optional<Xpp3Dom> optConfiguration = buildConfiguration(project, A_MAVEN_COMPILER_PLUGIN, GOAL_COMPILE);

    if (optConfiguration.isPresent()) {

        Xpp3Dom configuration = optConfiguration.get();

        executeMojo(plugin(G_MAVEN_COMPILER_PLUGIN, A_MAVEN_COMPILER_PLUGIN, pluginVersion), goal(GOAL_COMPILE),
                configuration, executionEnvironment(project, mavenSession, buildPluginManager));
    }
}

From source file:io.fabric8.vertx.maven.plugin.utils.MojoUtils.java

License:Apache License

/**
 * @param project//from   w  w  w .j a  v  a2 s . co  m
 * @param artifactId
 * @param goal
 * @return
 */
public Optional<Xpp3Dom> buildConfiguration(MavenProject project, String artifactId, String goal) {

    Optional<Plugin> pluginOptional = project.getBuildPlugins().stream()
            .filter(plugin -> artifactId.equals(plugin.getArtifactId())).findFirst();

    Plugin plugin;

    if (pluginOptional.isPresent()) {

        plugin = pluginOptional.get();

        //Goal Level Configuration
        List<String> goals = (List<String>) plugin.getGoals();

        if (goals != null && goals.contains(goal)) {
            return Optional.ofNullable((Xpp3Dom) plugin.getConfiguration());
        }

        //Execution Configuration
        Optional<PluginExecution> executionOptional = plugin.getExecutions().stream()
                .filter(e -> e.getGoals().contains(goal)).findFirst();

        if (executionOptional.isPresent()) {
            Optional.ofNullable((Xpp3Dom) executionOptional.get().getConfiguration());
        }

    } else {
        return Optional.empty();
    }

    //Global Configuration
    return Optional.ofNullable((Xpp3Dom) plugin.getConfiguration());
}

From source file:io.reactiverse.vertx.maven.plugin.utils.MojoUtils.java

License:Apache License

/**
 * Checks whether or not the given project has a plugin with the given key. The key is given using the
 * "groupId:artifactId" syntax./*from w w w  . ja  va 2s  . c  o  m*/
 *
 * @param project   the project
 * @param pluginKey the plugin
 * @return an Optional completed if the plugin is found.
 */
public static Optional<Plugin> hasPlugin(MavenProject project, String pluginKey) {
    Optional<Plugin> optPlugin = project.getBuildPlugins().stream()
            .filter(plugin -> pluginKey.equals(plugin.getKey())).findFirst();

    if (!optPlugin.isPresent() && project.getPluginManagement() != null) {
        optPlugin = project.getPluginManagement().getPlugins().stream()
                .filter(plugin -> pluginKey.equals(plugin.getKey())).findFirst();
    }
    return optPlugin;
}

From source file:io.reactiverse.vertx.maven.plugin.utils.MojoUtils.java

License:Apache License

/**
 * Execute the Maven Compiler Plugin to compile java sources.
 *
 * @param project            the project
 * @param mavenSession       the session
 * @param buildPluginManager the build plugin manager
 * @throws Exception if the compilation fails for any reason
 *///from   ww w. j  a v  a  2s .c o  m
public static void compile(MavenProject project, MavenSession mavenSession,
        BuildPluginManager buildPluginManager) throws Exception {

    Optional<Plugin> mvnCompilerPlugin = project.getBuildPlugins().stream()
            .filter(plugin -> A_MAVEN_COMPILER_PLUGIN.equals(plugin.getArtifactId())).findFirst();

    String pluginVersion = properties.getProperty(V_MAVEN_COMPILER_PLUGIN);

    if (mvnCompilerPlugin.isPresent()) {
        pluginVersion = mvnCompilerPlugin.get().getVersion();
    }

    Optional<Xpp3Dom> optConfiguration = buildConfiguration(project, A_MAVEN_COMPILER_PLUGIN, GOAL_COMPILE);

    if (optConfiguration.isPresent()) {

        Xpp3Dom configuration = optConfiguration.get();

        executeMojo(plugin(G_MAVEN_COMPILER_PLUGIN, A_MAVEN_COMPILER_PLUGIN, pluginVersion), goal(GOAL_COMPILE),
                configuration, executionEnvironment(project, mavenSession, buildPluginManager));
    }
}

From source file:io.reactiverse.vertx.maven.plugin.utils.MojoUtils.java

License:Apache License

/**
 * @param project//w w  w  . ja v a  2s .  c o m
 * @param artifactId
 * @param goal
 * @return
 */
public static Optional<Xpp3Dom> buildConfiguration(MavenProject project, String artifactId, String goal) {

    Optional<Plugin> pluginOptional = project.getBuildPlugins().stream()
            .filter(plugin -> artifactId.equals(plugin.getArtifactId())).findFirst();

    Plugin plugin;

    if (pluginOptional.isPresent()) {

        plugin = pluginOptional.get();

        //Goal Level Configuration
        List<String> goals = goals(plugin.getGoals());

        if (goals != null && goals.contains(goal)) {
            return Optional.ofNullable((Xpp3Dom) plugin.getConfiguration());
        }

        //Execution Configuration
        Optional<PluginExecution> executionOptional = plugin.getExecutions().stream()
                .filter(e -> e.getGoals().contains(goal)).findFirst();

        executionOptional.ifPresent(
                pluginExecution -> Optional.ofNullable((Xpp3Dom) pluginExecution.getConfiguration()));

    } else {
        return Optional.empty();
    }

    //Global Configuration
    return Optional.ofNullable((Xpp3Dom) plugin.getConfiguration());
}

From source file:me.gladwell.eclipse.m2e.android.configuration.MavenAndroidClasspathConfigurer.java

License:Open Source License

/**
 * Ignore any optional warning in the "gen" folder, iff the Maven plugin configuration
 * contains the correct flag 'ignoreOptionalWarningsInGenFolder'.
 * //from ww  w  . j a  v a  2 s.  co  m
 * @param project
 * @param classpathDescriptor
 */
private static void ignoreOptionalWarningsOnSourceFolder(AndroidProject project,
        IClasspathEntryDescriptor classpathDescriptor) {
    String warningAttribute = null;
    // Test if the Eclipse IDE is able to change the "warning" flag (only since Indigo)
    try {
        Field field = IClasspathAttribute.class.getField("IGNORE_OPTIONAL_PROBLEMS"); //$NON-NLS-1$
        assert (field != null);
        warningAttribute = field.get(null).toString();
    } catch (Throwable _) {
        // The Eclipse platform does not provide the feature to change the warning flag.
        return;
    }

    assert (warningAttribute != null);

    if (classpathDescriptor != null && project instanceof MavenAndroidProject) {
        MavenAndroidProject mavenAndroidProject = (MavenAndroidProject) project;
        MavenProject mavenProject = mavenAndroidProject.getMavenProject();
        if (mavenProject != null && mavenProject.getBuildPlugins() != null) {
            List<Plugin> plugins = mavenProject.getBuildPlugins();
            Iterator<Plugin> pluginIterator = plugins.iterator();
            Xpp3Dom configuration = null;
            while (configuration == null && pluginIterator.hasNext()) {
                Plugin plugin = pluginIterator.next();
                if (ANDROID_MAVEN_PLUGIN_GROUP_ID.equals(plugin.getGroupId())
                        && ANDROID_MAVEN_PLUGIN_ARTIFACT_ID.equals(plugin.getArtifactId())) {
                    configuration = (Xpp3Dom) plugin.getConfiguration();
                }
            }

            if (configuration != null) {
                configuration = configuration.getChild(IGNORE_WARNING_CONFIGURATION_NAME);
                if (configuration != null) {
                    String value = configuration.getValue();
                    if (value != null && !value.isEmpty()) {
                        Boolean b = Boolean.parseBoolean(value.trim());
                        if (b != null) {
                            classpathDescriptor.setClasspathAttribute(warningAttribute, b.toString());
                        }
                    }
                }
            }
        }
    }
}

From source file:me.gladwell.eclipse.m2e.android.project.MavenAndroidProjectFactory.java

License:Open Source License

public MavenAndroidProject createAndroidProject(MavenProject mavenProject) {
    if (findJaywayAndroidPlugin(mavenProject.getBuildPlugins()) != null) {
        return new JaywayMavenAndroidProject(mavenProject);
    }//from  w  w w.  j  a v a 2 s. co m

    throw new AndroidMavenException("un-recognised maven-android project type");
}

From source file:net.oneandone.maven.rules.ForbidOverridingManagedPluginsRule.java

License:Apache License

private void checkPluginManagementDiffs(MavenProject project, Log log) {
    if (project.getParent() != null) {
        List<Plugin> projectPlugins = project.getBuildPlugins();
        if (project.getPluginManagement() != null) {
            projectPlugins.addAll(project.getPluginManagement().getPlugins());
        }/*from w  w  w  .  j  av  a2 s.  c  o m*/
        Map<String, Plugin> parentProjectPlugins = project.getParent().getPluginManagement().getPluginsAsMap();

        for (Plugin plugin : projectPlugins) {
            final Plugin parentPlugin = parentProjectPlugins.get(plugin.getKey());
            if (parentPlugin != null && !plugin.getVersion().equals(parentPlugin.getVersion())
                    && !isExcluded(plugin.getKey())) {
                logHeader(log, "plugin management");
                log.warn("Difference for: " + plugin.getKey());
                log.warn("Project: " + plugin.getVersion());
                log.warn("Parent:  " + parentPlugin.getVersion());
                log.warn("----------------------------------------");
                failureDetected = true;
            }
        }
    }
}

From source file:org.apache.isis.tool.mavenplugin.util.MavenProjects.java

License:Apache License

public static Plugin lookupPlugin(MavenProject mavenProject, String key) {

    @SuppressWarnings("unchecked")
    List<Plugin> plugins = mavenProject.getBuildPlugins();

    for (Plugin plugin : plugins) {
        if (key.equalsIgnoreCase(plugin.getKey())) {
            return plugin;
        }//  ww  w  .j av a 2  s.c om
    }
    return null;
}

From source file:org.codehaus.groovy.m2eclipse.GroovyProjectConfigurator.java

License:Open Source License

private boolean compilerPluginUsesGroovyEclipseAdapter(MavenProject mavenProject) {
    for (Plugin buildPlugin : mavenProject.getBuildPlugins()) {
        if ("maven-compiler-plugin".equals(buildPlugin.getArtifactId())
                && "org.apache.maven.plugins".equals(buildPlugin.getGroupId())) {
            for (Dependency dependency : buildPlugin.getDependencies()) {
                if ("groovy-eclipse-compiler".equals(dependency.getArtifactId())
                        && "org.codehaus.groovy".equals(dependency.getGroupId())) {
                    return true;
                }/*from ww  w .  jav a  2  s  .  co m*/
            }
        }
    }
    return false;
}