List of usage examples for org.apache.maven.project MavenProject getPluginManagement
public PluginManagement getPluginManagement()
From source file:org.codehaus.griffon.maven.plugin.tools.DefaultGriffonServices.java
License:Apache License
public MavenProject createPOM(String groupId, GriffonProject griffonProjectDescriptor, String mtgGroupId, String griffonPluginArtifactId, String mtgVersion, boolean addEclipseSettings) { MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }//from ww w . j a va 2 s . c o m PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("griffon-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("griffonHome", "${env.GRIFFON_HOME}"); pom.getModel().getProperties().setProperty("griffonVersion", griffonProjectDescriptor.getAppGriffonVersion()); // Add our own plugin Plugin griffonPlugin = new Plugin(); griffonPlugin.setGroupId(mtgGroupId); griffonPlugin.setArtifactId(griffonPluginArtifactId); griffonPlugin.setVersion(mtgVersion); griffonPlugin.setExtensions(true); pom.addPlugin(griffonPlugin); // Add compiler plugin settings Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); Xpp3Dom configuration = new Xpp3Dom("configuration"); Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("zip"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(griffonProjectDescriptor.getAppName()); pom.setName(griffonProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(griffonProjectDescriptor.getAppVersion()); if (!griffonProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + griffonProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + griffonProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.eclipse.m2e.editor.xml.internal.MarkerLocationService.java
License:Open Source License
private static void checkManagedPlugins(IMavenMarkerManager mavenMarkerManager, Element root, IResource pomFile, MavenProject mavenproject, String type, IStructuredDocument document) throws CoreException { List<Element> candidates = new ArrayList<Element>(); Element build = findChild(root, PomEdits.BUILD); if (build == null) { return;/*from w w w .j a va2s . c o m*/ } Element plugins = findChild(build, PomEdits.PLUGINS); if (plugins != null) { for (Element el : findChilds(plugins, PomEdits.PLUGIN)) { Element version = findChild(el, PomEdits.VERSION); if (version != null) { candidates.add(el); } } } //we should also consider <plugins> section in the profiles, but profile are optional and so is their // pluginManagement section.. that makes handling our markers more complex. // see MavenProject.getInjectedProfileIds() for a list of currently active profiles in effective pom String currentProjectKey = mavenproject.getGroupId() + ":" + mavenproject.getArtifactId() + ":" //$NON-NLS-1$//$NON-NLS-2$ + mavenproject.getVersion(); List<String> activeprofiles = mavenproject.getInjectedProfileIds().get(currentProjectKey); //remember what profile we found the dependency in. Map<Element, String> candidateProfile = new HashMap<Element, String>(); Element profiles = findChild(root, PomEdits.PROFILES); if (profiles != null) { for (Element profile : findChilds(profiles, PomEdits.PROFILE)) { String idString = getTextValue(findChild(profile, PomEdits.ID)); if (idString != null && activeprofiles.contains(idString)) { build = findChild(profile, PomEdits.BUILD); if (build == null) { continue; } plugins = findChild(build, PomEdits.PLUGINS); if (plugins != null) { for (Element el : findChilds(plugins, PomEdits.PLUGIN)) { Element version = findChild(el, PomEdits.VERSION); if (version != null) { candidates.add(el); candidateProfile.put(el, idString); } } } } } } //collect the managed plugin ids Map<String, String> managed = new HashMap<String, String>(); PluginManagement pm = mavenproject.getPluginManagement(); if (pm != null) { List<Plugin> plgs = pm.getPlugins(); if (plgs != null) { for (Plugin plg : plgs) { InputLocation loc = plg.getLocation("version"); //#350203 skip plugins defined in the superpom if (loc != null) { managed.put(plg.getKey(), plg.getVersion()); } } } } //now we have all the candidates, match them against the effective managed set for (Element dep : candidates) { String grpString = getTextValue(findChild(dep, PomEdits.GROUP_ID)); //$NON-NLS-1$ if (grpString == null) { grpString = "org.apache.maven.plugins"; //$NON-NLS-1$ } String artString = getTextValue(findChild(dep, PomEdits.ARTIFACT_ID)); //$NON-NLS-1$ Element version = findChild(dep, PomEdits.VERSION); //$NON-NLS-1$ String versionString = getTextValue(version); if (artString != null && versionString != null) { String id = Plugin.constructKey(grpString, artString); if (managed.containsKey(id)) { String managedVersion = managed.get(id); if (version instanceof IndexedRegion) { IndexedRegion off = (IndexedRegion) version; if (lookForIgnoreMarker(document, version, off, IMavenConstants.MARKER_IGNORE_MANAGED)) { continue; } IMarker mark = mavenMarkerManager.addMarker(pomFile, type, NLS.bind(org.eclipse.m2e.core.internal.Messages.MavenMarkerManager_managed_title, managedVersion, artString), document.getLineOfOffset(off.getStartOffset()) + 1, IMarker.SEVERITY_WARNING); mark.setAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, IMavenConstants.EDITOR_HINT_MANAGED_PLUGIN_OVERRIDE); mark.setAttribute(IMarker.CHAR_START, off.getStartOffset()); mark.setAttribute(IMarker.CHAR_END, off.getEndOffset()); mark.setAttribute("problemType", "pomhint"); //only imporant in case we enable the generic xml quick fixes //$NON-NLS-1$ //$NON-NLS-2$ //add these attributes to easily and deterministicaly find the declaration in question mark.setAttribute("groupId", grpString); //$NON-NLS-1$ mark.setAttribute("artifactId", artString); //$NON-NLS-1$ String profile = candidateProfile.get(dep); if (profile != null) { mark.setAttribute("profile", profile); //$NON-NLS-1$ } } } } } }
From source file:org.eclipse.m2e.editor.xml.PomTemplateContext.java
License:Open Source License
static String searchPM(MavenProject project, String groupId, String artifactId) { if (project == null) { return null; }/*w ww.j a va 2 s.com*/ String version = null; String id = Plugin.constructKey(groupId, artifactId); PluginManagement pm = project.getPluginManagement(); if (pm != null) { for (Plugin pl : pm.getPlugins()) { if (id.equals(pl.getKey())) { version = pl.getVersion(); break; } } } return version; }
From source file:org.ensime.maven.plugins.ensime.EnsimeConfigGenerator.java
License:Apache License
/** * Get the scalacOptions for this project. * @return A list containing the scalacOptions * @author amanjpro//from w ww . j a v a 2 s. com */ private List<String> getScalacOptions(final MavenProject project) { Map<String, Plugin> plugins = project.getPluginManagement().getPluginsAsMap(); Plugin scalacPlugin = plugins.get(SCALA_MAVEN_PLUGIN); Optional<List<String>> options = Optional.ofNullable(scalacPlugin).map(s -> s.getConfiguration()) .flatMap(obj -> { if (obj instanceof Xpp3Dom) { Xpp3Dom config = (Xpp3Dom) obj; return Optional.ofNullable(config.getChild("args")).map( ch -> Arrays.stream(ch.getChildren()).map(c -> c.getValue()).collect(toList())); } else return Optional.empty(); }); if (options.isPresent()) { List<String> providedOptions = options.get(); providedOptions.addAll(ensimeSuggestedOptions()); return providedOptions.stream().distinct().collect(toList()); } else { return ensimeSuggestedOptions(); } }
From source file:org.ensime.maven.plugins.ensime.EnsimeConfigGenerator.java
License:Apache License
/** * Get the javacOptions for this project. * @return A list containing the javacOptions * @author amanjpro/*from ww w. j a v a 2s. co m*/ */ private List<String> getJavacOptions(final MavenProject project) { Map<String, Plugin> plugins = project.getPluginManagement().getPluginsAsMap(); Plugin javacPlugin = plugins.get(JAVA_MAVEN_PLUGIN); Plugin scalacPlugin = plugins.get(SCALA_MAVEN_PLUGIN); Optional<List<String>> javacOptions = Optional.ofNullable(javacPlugin).map(p -> p.getConfiguration()) .flatMap(obj -> { if (obj instanceof Xpp3Dom) { Xpp3Dom config = (Xpp3Dom) obj; return Optional.ofNullable(config.getChild("compilerArgs")) .map(s -> Arrays.stream(s.getChildren()).map(v -> v.getValue()).collect(toList())); } else return Optional.empty(); }); Optional<List<String>> jvmOptions = Optional.ofNullable(scalacPlugin).map(p -> p.getConfiguration()) .flatMap(obj -> { if (obj instanceof Xpp3Dom) { Xpp3Dom config = (Xpp3Dom) obj; return Optional.ofNullable(config.getChild("jvmArgs")) .map(s -> Arrays.stream(s.getChildren()).map(v -> v.getValue()).collect(toList())); } else return Optional.empty(); }); List<String> options = new ArrayList(); javacOptions.ifPresent(opts -> options.addAll(opts)); jvmOptions.ifPresent(opts -> options.addAll(opts)); return options; }
From source file:org.grails.maven.plugin.tools.DefaultGrailsServices.java
License:Apache License
public MavenProject createPOM(final String groupId, final GrailsProject grailsProjectDescriptor, final String mtgGroupId, final String grailsPluginArtifactId, final String mtgVersion, final boolean addEclipseSettings) { final MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }// w ww . j a v a 2s . com final PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("grails-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("grailsHome", "${env.GRAILS_HOME}"); pom.getModel().getProperties().setProperty("grailsVersion", grailsProjectDescriptor.getAppGrailsVersion()); // Add our own plugin final Plugin grailsPlugin = new Plugin(); grailsPlugin.setGroupId(mtgGroupId); grailsPlugin.setArtifactId(grailsPluginArtifactId); grailsPlugin.setVersion(mtgVersion); grailsPlugin.setExtensions(true); pom.addPlugin(grailsPlugin); // Add compiler plugin settings final Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); final Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); final Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); final Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { final Plugin warPlugin = new Plugin(); warPlugin.setGroupId("org.apache.maven.plugins"); warPlugin.setArtifactId("maven-war-plugin"); final Xpp3Dom warConfig = new Xpp3Dom("configuration"); final Xpp3Dom warSourceDirectory = new Xpp3Dom("warSourceDirectory"); warSourceDirectory.setValue("web-app"); warConfig.addChild(warSourceDirectory); warPlugin.setConfiguration(warConfig); pluginMgt.addPlugin(warPlugin); final Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); final Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); final Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); final Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); // Xpp3Dom additionalProjectFacets = new Xpp3Dom( // "additionalProjectFacets"); // Xpp3Dom jstWeb = new Xpp3Dom("jst.web"); // jstWeb.setValue("2.5"); // additionalProjectFacets.addChild(jstWeb); // configuration.addChild(additionalProjectFacets); final Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("war"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(grailsProjectDescriptor.getAppName()); pom.setName(grailsProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(grailsProjectDescriptor.getAppVersion()); if (!grailsProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + grailsProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + grailsProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.robovm.maven.plugin.AbstractRoboVMMojo.java
License:Apache License
public Config buildArchive(OS os, Arch arch, TargetType targetType) throws MojoExecutionException, MojoFailureException { getLog().info("Building RoboVM app for: " + os + " (" + arch + ")"); Config.Builder builder;/* ww w.j ava 2 s. co m*/ try { builder = new Config.Builder(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } // load config base file if it exists (and properties) if (propertiesFile != null) { if (!propertiesFile.exists()) { throw new MojoExecutionException( "Invalid 'propertiesFile' specified for RoboVM compile: " + propertiesFile); } try { getLog().debug( "Including properties file in RoboVM compiler config: " + propertiesFile.getAbsolutePath()); builder.addProperties(propertiesFile); } catch (IOException e) { throw new MojoExecutionException( "Failed to add properties file to RoboVM config: " + propertiesFile); } } else { File file = new File(project.getBasedir(), "robovm.properties"); if (file.exists()) { getLog().debug("Using default properties file: " + file.getAbsolutePath()); try { builder.addProperties(file); } catch (IOException e) { throw new MojoExecutionException("Failed to add properties file to RoboVM config: " + file, e); } } } if (configFile != null) { if (!configFile.exists()) { throw new MojoExecutionException( "Invalid 'configFile' specified for RoboVM compile: " + configFile); } try { getLog().debug("Loading config file for RoboVM compiler: " + configFile.getAbsolutePath()); builder.read(configFile); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config file: " + configFile); } } else { File file = new File(project.getBasedir(), "robovm.xml"); if (file.exists()) { getLog().debug("Using default config file: " + file.getAbsolutePath()); try { builder.read(file); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config file: " + file, e); } } } // Read embedded RoboVM <config> if there is one Plugin plugin = project.getPlugin("org.robovm:robovm-maven-plugin"); MavenProject p = project; while (p != null && plugin == null) { plugin = p.getPluginManagement().getPluginsAsMap().get("org.robovm:robovm-maven-plugin"); p = p.getParent(); } if (plugin != null) { getLog().debug("Reading RoboVM plugin configuration from " + p.getFile().getAbsolutePath()); Xpp3Dom configDom = (Xpp3Dom) plugin.getConfiguration(); if (configDom != null && configDom.getChild("config") != null) { StringWriter sw = new StringWriter(); XMLWriter xmlWriter = new PrettyPrintXMLWriter(sw, "UTF-8", null); Xpp3DomWriter.write(xmlWriter, configDom.getChild("config")); try { builder.read(new StringReader(sw.toString()), project.getBasedir()); } catch (Exception e) { throw new MojoExecutionException("Failed to read RoboVM config embedded in POM", e); } } } File tmpDir = new File(new File(installDir, os.name()), arch.name()); try { FileUtils.deleteDirectory(tmpDir); } catch (IOException e) { throw new MojoExecutionException("Failed to clean output dir " + tmpDir, e); } tmpDir.mkdirs(); builder.home(new Config.Home(unpackRoboVMDist())).logger(getRoboVMLogger()).tmpDir(tmpDir) .targetType(targetType).skipInstall(true).installDir(installDir).os(os).arch(arch); if (iosSkipSigning) { builder.iosSkipSigning(true); } else { if (iosSignIdentity != null) { getLog().debug("Using explicit iOS Signing identity: " + iosSignIdentity); builder.iosSignIdentity(SigningIdentity.find(SigningIdentity.list(), iosSignIdentity)); } if (iosProvisioningProfile != null) { getLog().debug("Using explicit iOS provisioning profile: " + iosProvisioningProfile); builder.iosProvisioningProfile( ProvisioningProfile.find(ProvisioningProfile.list(), iosProvisioningProfile)); } } builder.clearClasspathEntries(); // add JavaFX if needed if (includeJFX) { getLog().info("Including JavaFX Runtime in build"); // add jfxrt.jar from 78 backport to classpath File jfxJar = resolveJavaFXBackportRuntimeArtifact(); getLog().debug("JavaFX backport runtime JAR found at: " + jfxJar); builder.addClasspathEntry(jfxJar); // add backport compatibility additions to classpath File jfxCompatJar = resolveJavaFXBackportCompatibilityArtifact(); getLog().debug("JavaFX backport compatibilty JAR found at: " + jfxCompatJar); builder.addClasspathEntry(jfxCompatJar); // include native files as resources File iosNativesBaseDir = unpackJavaFXNativeIOSArtifact(); // builder.addLib(new File(iosNativesBaseDir, "libdecora-sse-" + // arch.getClangName() + ".a").getAbsolutePath()); builder.addLib(new Lib( new File(iosNativesBaseDir, "libglass-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libjavafx-font-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libjavafx-iio-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libprism-common-" + arch.getClangName() + ".a").getAbsolutePath(), true)); builder.addLib(new Lib( new File(iosNativesBaseDir, "libprism-es2-" + arch.getClangName() + ".a").getAbsolutePath(), true)); // builder.addLib(new File(iosNativesBaseDir, "libprism-sw-" + // arch.getClangName() + ".a").getAbsolutePath()); // add default 'roots' needed for JFX to work builder.addForceLinkClass("com.sun.javafx.tk.quantum.QuantumToolkit"); builder.addForceLinkClass("com.sun.prism.es2.ES2Pipeline"); builder.addForceLinkClass("com.sun.prism.es2.IOSGLFactory"); builder.addForceLinkClass("com.sun.glass.ui.ios.**.*"); builder.addForceLinkClass("javafx.scene.CssStyleHelper"); builder.addForceLinkClass("com.sun.prism.shader.**.*"); builder.addForceLinkClass("com.sun.scenario.effect.impl.es2.ES2ShaderSource"); builder.addForceLinkClass("com.sun.javafx.font.coretext.CTFactory"); builder.addForceLinkClass("sun.util.logging.PlatformLogger"); // add default 'frameworks' needed for JFX to work builder.addFramework("UIKit"); builder.addFramework("OpenGLES"); builder.addFramework("QuartzCore"); builder.addFramework("CoreGraphics"); builder.addFramework("CoreText"); builder.addFramework("ImageIO"); builder.addFramework("MobileCoreServices"); // todo do we need to exclude built-in JFX from JDK classpath? } // configure the runtime classpath try { for (Object object : project.getRuntimeClasspathElements()) { String path = (String) object; if (getLog().isDebugEnabled()) { getLog().debug("Including classpath element for RoboVM app: " + path); } builder.addClasspathEntry(new File(path)); } } catch (DependencyResolutionRequiredException e) { throw new MojoExecutionException("Error resolving application classpath for RoboVM build", e); } // execute the RoboVM build try { getLog().info("Compiling RoboVM app, this could take a while, especially the first time round"); Config config = configure(builder); AppCompiler compiler = new AppCompiler(config); compiler.compile(); return config; } catch (IOException e) { throw new MojoExecutionException("Error building RoboVM executable for app", e); } }
From source file:org.sonar.api.batch.maven.MavenPlugin.java
License:Open Source License
/** * Returns a plugin from a pom based on its group id and artifact id * <p/>/* ww w. j a va 2 s . c om*/ * <p>It searches in the build section, then the reporting section and finally the pluginManagement section</p> * * @param pom the project pom * @param groupId the plugin group id * @param artifactId the plugin artifact id * @return the plugin if it exists, null otherwise */ public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) { if (pom == null) { return null; } // look for plugin in <build> section Plugin plugin = null; if (pom.getBuildPlugins() != null) { plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId); } // look for plugin in <report> section if (plugin == null && pom.getReportPlugins() != null) { plugin = getReportPlugin(pom.getReportPlugins(), groupId, artifactId); } // look for plugin in <pluginManagement> section if (pom.getPluginManagement() != null) { Plugin pluginManagement = getPlugin(pom.getPluginManagement().getPlugins(), groupId, artifactId); if (plugin == null) { plugin = pluginManagement; } else if (pluginManagement != null) { if (pluginManagement.getConfiguration() != null) { if (plugin.getConfiguration() == null) { plugin.setConfiguration(pluginManagement.getConfiguration()); } else { Xpp3Dom.mergeXpp3Dom((Xpp3Dom) plugin.getConfiguration(), (Xpp3Dom) pluginManagement.getConfiguration()); } } if (plugin.getDependencies() == null && pluginManagement.getDependencies() != null) { plugin.setDependencies(pluginManagement.getDependencies()); } if (plugin.getVersion() == null) { plugin.setVersion(pluginManagement.getVersion()); } } } if (plugin != null) { return new MavenPlugin(plugin); } return null; }
From source file:org.sonar.api.batch.maven.MavenPlugin.java
License:Open Source License
private static void unregisterPlugin(MavenProject pom, String groupId, String artifactId) { if (pom.getPluginManagement() != null && pom.getPluginManagement().getPlugins() != null) { unregisterPlugin(pom.getPluginManagement().getPlugins(), groupId, artifactId); }/* ww w.java 2 s . c o m*/ List plugins = pom.getBuildPlugins(); if (plugins != null) { unregisterPlugin(plugins, groupId, artifactId); } plugins = pom.getReportPlugins(); if (plugins != null) { unregisterReportPlugin(plugins, groupId, artifactId); } }
From source file:org.sonarsource.scanner.maven.bootstrap.MavenPlugin.java
License:Open Source License
/** * Returns a plugin from a pom based on its group id and artifact id * <p>/* w w w .ja va 2 s . c om*/ * It searches in the build section, then the reporting section and finally the pluginManagement section * </p> * * @param pom the project pom * @param groupId the plugin group id * @param artifactId the plugin artifact id * @return the plugin if it exists, null otherwise */ @CheckForNull public static MavenPlugin getPlugin(MavenProject pom, String groupId, String artifactId) { Object pluginConfiguration = null; // look for plugin in <build> section Plugin plugin = getPlugin(pom.getBuildPlugins(), groupId, artifactId); if (plugin != null) { pluginConfiguration = plugin.getConfiguration(); } else { // look for plugin in reporting Reporting reporting = pom.getModel().getReporting(); if (reporting != null) { ReportPlugin reportPlugin = getReportPlugin(reporting.getPlugins(), groupId, artifactId); if (reportPlugin != null) { pluginConfiguration = reportPlugin.getConfiguration(); } } } // look for plugin in <pluginManagement> section PluginManagement pluginManagement = pom.getPluginManagement(); if (pluginManagement != null) { Plugin pluginFromManagement = getPlugin(pluginManagement.getPlugins(), groupId, artifactId); if (pluginFromManagement != null) { Object pluginConfigFromManagement = pluginFromManagement.getConfiguration(); if (pluginConfiguration == null) { pluginConfiguration = pluginConfigFromManagement; } else if (pluginConfigFromManagement != null) { Xpp3Dom.mergeXpp3Dom((Xpp3Dom) pluginConfiguration, (Xpp3Dom) pluginConfigFromManagement); } } } if (pluginConfiguration != null) { return new MavenPlugin(pluginConfiguration); } return null; }