List of usage examples for org.apache.maven.project MavenProject getPlugin
public Plugin getPlugin(String pluginKey)
From source file:io.fabric8.vertx.maven.plugin.Verify.java
License:Apache License
public static void verifySetup(File pomFile) throws Exception { assertNotNull("Unable to find pom.xml", pomFile); MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(new FileInputStream(pomFile)); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent());/*from w w w .ja v a 2 s. c o m*/ //Check if the properties have been set correctly Properties properties = model.getProperties(); assertThat(properties.containsKey("vertx.projectVersion")).isTrue(); assertThat(properties.getProperty("vertx.projectVersion")) .isEqualTo(MojoUtils.getVersion("vertx-core-version")); assertThat(properties.containsKey("fabric8-vertx-maven-plugin.projectVersion")).isTrue(); assertThat(properties.getProperty("fabric8-vertx-maven-plugin.projectVersion")) .isEqualTo(MojoUtils.getVersion("vertx-maven-plugin-version")); //Check if the dependencies has been set correctly DependencyManagement dependencyManagement = model.getDependencyManagement(); assertThat(dependencyManagement).isNotNull(); assertThat(dependencyManagement.getDependencies().isEmpty()).isFalse(); //Check Vert.x dependencies BOM Optional<Dependency> vertxDeps = dependencyManagement.getDependencies().stream() .filter(d -> d.getArtifactId().equals("vertx-dependencies") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxDeps.isPresent()).isTrue(); assertThat(vertxDeps.get().getVersion()).isEqualTo("${vertx.projectVersion}"); //Check Vert.x core dependency Optional<Dependency> vertxCoreDep = model.getDependencies().stream() .filter(d -> d.getArtifactId().equals("vertx-core") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxCoreDep.isPresent()).isTrue(); assertThat(vertxCoreDep.get().getVersion()).isNull(); //Check Redeploy Configuration Plugin vmp = project.getPlugin("io.fabric8:vertx-maven-plugin"); Assert.assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); Assert.assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); Assert.assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
From source file:io.reactiverse.vertx.maven.plugin.Verify.java
License:Apache License
public static void verifySetup(File pomFile) throws Exception { assertNotNull("Unable to find pom.xml", pomFile); MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(new FileInputStream(pomFile)); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent());// w ww. ja v a 2 s.com //Check if the properties have been set correctly Properties properties = model.getProperties(); assertThat(properties.containsKey("vertx.projectVersion")).isTrue(); assertThat(properties.getProperty("vertx.projectVersion")) .isEqualTo(MojoUtils.getVersion("vertx-core-version")); assertThat(properties.containsKey("reactiverse-vertx-maven-plugin.projectVersion")).isTrue(); assertThat(properties.getProperty("reactiverse-vertx-maven-plugin.projectVersion")) .isEqualTo(MojoUtils.getVersion("vertx-maven-plugin-version")); //Check if the dependencies has been set correctly DependencyManagement dependencyManagement = model.getDependencyManagement(); assertThat(dependencyManagement).isNotNull(); assertThat(dependencyManagement.getDependencies().isEmpty()).isFalse(); //Check Vert.x dependencies BOM Optional<Dependency> vertxDeps = dependencyManagement.getDependencies().stream() .filter(d -> d.getArtifactId().equals("vertx-dependencies") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxDeps.isPresent()).isTrue(); assertThat(vertxDeps.get().getVersion()).isEqualTo("${vertx.projectVersion}"); //Check Vert.x core dependency Optional<Dependency> vertxCoreDep = model.getDependencies().stream() .filter(d -> d.getArtifactId().equals("vertx-core") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxCoreDep.isPresent()).isTrue(); assertThat(vertxCoreDep.get().getVersion()).isNull(); //Check Redeploy Configuration Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); Assert.assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); Assert.assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); Assert.assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
@Override public Mojo lookupConfiguredMojo(MavenSession session, MojoExecution execution) throws Exception { MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); Mojo mojo = container.lookup(Mojo.class, mojoDescriptor.getRoleHint()); ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution); Xpp3Dom configuration = null;/*from ww w. ja v a 2 s . co m*/ Plugin plugin = project.getPlugin(mojoDescriptor.getPluginDescriptor().getPluginLookupKey()); if (plugin != null) { configuration = (Xpp3Dom) plugin.getConfiguration(); } if (configuration == null) { configuration = new Xpp3Dom("configuration"); } configuration = Xpp3Dom.mergeXpp3Dom(configuration, execution.getConfiguration()); execution.setConfiguration(configuration); finalizeMojoConfiguration(execution); PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration(execution.getConfiguration()); String configuratorHint = "basic"; if (mojoDescriptor.getComponentConfigurator() != null) { configuratorHint = mojoDescriptor.getComponentConfigurator(); } ComponentConfigurator configurator = container.lookup(ComponentConfigurator.class, configuratorHint); configurator.configureComponent(mojo, pluginConfiguration, evaluator, container.getContainerRealm()); return mojo; }
From source file:io.wcm.devops.conga.tooling.maven.plugin.util.VersionInfoUtil.java
License:Apache License
/** * Detects versions from maven-conga-plugin and additional CONGA plugins used. * @return Properties with versions/*from ww w .j a v a2s. c om*/ */ public static Properties getVersionInfoProperties(MavenProject project) { Properties props = new Properties(); // add version info about the conga-maven-plugin itself, and direct plugin dependencies (assumed conga plugins) Plugin congaPlugin = project.getPlugin(BuildConstants.CONGA_MAVEN_PLUGIN_KEY); if (congaPlugin != null) { props.put(congaPlugin.getKey(), congaPlugin.getVersion()); congaPlugin.getDependencies().stream() .forEach(dependency -> props.put( Plugin.constructKey(dependency.getGroupId(), dependency.getArtifactId()), dependency.getVersion())); } return props; }
From source file:org.codehaus.groovy.m2eclipse.GroovyProjectConfigurator.java
License:Open Source License
private Plugin getGMavenPlugin(MavenProject mavenProject) { Plugin p = mavenProject.getPlugin("org.codehaus.gmaven:gmaven-plugin"); //$NON-NLS-1$ if (p == null) { // try the old (pre-1.1) version of the plugin p = mavenProject.getPlugin("org.codehaus.groovy.maven:gmaven-plugin"); //$NON-NLS-1$ }//w w w .j a v a 2 s .c om return p; }
From source file:org.codehaus.mojo.xml.test.AbstractXmlMojoTestCase.java
License:Apache License
@Override //In maven-plugin-testing-harnes 2.1, this method had a simple error in it which resulted in //the configuration being incorrectly generated. In later versions, the error has been corrected. //The error is annotated in the comments below. This method should be removed when upgrading to later //versions. protected Mojo lookupConfiguredMojo(MavenSession session, MojoExecution execution) throws Exception, ComponentConfigurationException { MavenProject project = session.getCurrentProject(); MojoDescriptor mojoDescriptor = execution.getMojoDescriptor(); Mojo mojo = (Mojo) lookup(mojoDescriptor.getRole(), mojoDescriptor.getRoleHint()); ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution); Xpp3Dom configuration = null;//from ww w . j a v a 2 s. c om Plugin plugin = project.getPlugin(mojoDescriptor.getPluginDescriptor().getPluginLookupKey()); if (plugin != null) { configuration = (Xpp3Dom) plugin.getConfiguration(); } if (configuration == null) { configuration = new Xpp3Dom("configuration"); } //FIX: the parameters were in the wrong order on this call - they have been reversed configuration = Xpp3Dom.mergeXpp3Dom(configuration, execution.getConfiguration()); //END FIX PlexusConfiguration pluginConfiguration = new XmlPlexusConfiguration(configuration); getContainer().lookup(ComponentConfigurator.class, "basic").configureComponent(mojo, pluginConfiguration, evaluator, getContainer().getContainerRealm()); return mojo; }
From source file:org.eclipse.m2e.core.internal.markers.SourceLocationHelper.java
License:Open Source License
public static SourceLocation findLocation(MavenProject mavenProject, MojoExecutionKey mojoExecutionKey) { Plugin plugin = mavenProject .getPlugin(mojoExecutionKey.getGroupId() + ":" + mojoExecutionKey.getArtifactId()); InputLocation inputLocation = plugin.getLocation(SELF); if (inputLocation == null) { // Plugin is specified in the maven lifecycle definition, not explicit in current pom or parent pom inputLocation = mavenProject.getModel().getLocation(PACKAGING); if (inputLocation != null) { return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PACKAGING.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); }// w w w . ja v a 2s . c o m inputLocation = mavenProject.getModel().getLocation(SELF); return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PROJECT.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } String elementName; InputLocation executionInputLocation = findExecutionLocation(plugin, mojoExecutionKey.getExecutionId()); if (executionInputLocation != null) { inputLocation = executionInputLocation; elementName = EXECUTION; } else { elementName = PLUGIN; } File pomFile = mavenProject.getFile(); if (pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) { // Plugin/execution is specified in current pom return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - elementName.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } // Plugin/execution is specified in some parent pom SourceLocation causeLocation = new SourceLocation(inputLocation.getSource().getLocation(), inputLocation.getSource().getModelId(), inputLocation.getLineNumber(), inputLocation.getColumnNumber() - elementName.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); inputLocation = mavenProject.getModel().getParent().getLocation(SELF); return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PARENT.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET, causeLocation); }
From source file:org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingDialog.java
License:Open Source License
private MavenProject locatePlugin() { MavenProject project = facade.getMavenProject(); // if we got here, facade.getMavenProject cannot be null Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId); if (plugin == null) { return null; // can't really happy }//from w w w . j a va 2 s.c om InputLocation location = plugin.getLocation(""); if (location == null || location.getSource() == null || location.getSource().getLocation() == null) { // that's odd. where does this come from??? return null; } File basedir = new File(location.getSource().getLocation()).getParentFile(); // should be canonical file already for (MavenProject other : pomComposite.getHierarchy()) { if (basedir.equals(other.getBasedir())) { return other; } } return null; }
From source file:org.eclipse.m2e.wtp.AcrPluginConfiguration.java
License:Open Source License
public AcrPluginConfiguration(IMavenProjectFacade facade) { MavenProject mavenProject = facade.getMavenProject(); if (JEEPackaging.APP_CLIENT != JEEPackaging.getValue(mavenProject.getPackaging())) throw new IllegalArgumentException("Maven project must have app-client packaging"); this.mavenProjectFacade = facade; Plugin plugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-acr-plugin"); if (plugin != null) { setConfiguration((Xpp3Dom) plugin.getConfiguration()); }//from w w w. ja v a 2 s .com }
From source file:org.eclipse.m2e.wtp.EjbPluginConfiguration.java
License:Open Source License
public EjbPluginConfiguration(MavenProject mavenProject) { if (JEEPackaging.EJB != JEEPackaging.getValue(mavenProject.getPackaging())) throw new IllegalArgumentException("Maven project must have ejb packaging"); this.ejbProject = mavenProject; this.plugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-ejb-plugin"); }