Java Code Examples for org.apache.maven.model.Plugin#getConfiguration()
The following examples show how to use
org.apache.maven.model.Plugin#getConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractGcloudMojo.java From gcloud-maven-plugin with Apache License 2.0 | 6 votes |
/** * @return the java version used the pom (target) and 1.7 if not present. */ protected String getJavaVersion() { String javaVersion = "1.7"; Plugin p = maven_project.getPlugin("org.apache.maven.plugins:maven-compiler-plugin"); if (p != null) { Xpp3Dom config = (Xpp3Dom) p.getConfiguration(); if (config == null) { return javaVersion; } Xpp3Dom domVersion = config.getChild("target"); if (domVersion != null) { javaVersion = domVersion.getValue(); } } return javaVersion; }
Example 2
Source File: PluginExtractor.java From wisdom with Apache License 2.0 | 6 votes |
/** * Retrieves the configuration for a specific goal of the given plugin from the Maven Project. * * @param mojo the mojo * @param plugin the artifact id of the plugin * @param goal the goal * @return the configuration, {@code null} if not found */ public static Xpp3Dom getBuildPluginConfigurationForGoal(AbstractWisdomMojo mojo, String plugin, String goal) { List<Plugin> plugins = mojo.project.getBuildPlugins(); for (Plugin plug : plugins) { if (plug.getArtifactId().equals(plugin)) { // Check main execution List<String> globalGoals = (List<String>) plug.getGoals(); if (globalGoals != null && globalGoals.contains(goal)) { return (Xpp3Dom) plug.getConfiguration(); } // Check executions for (PluginExecution execution : plug.getExecutions()) { if (execution.getGoals().contains(goal)) { return (Xpp3Dom) execution.getConfiguration(); } } } } // Not found. return null; }
Example 3
Source File: AbstracMavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Searches the Maven pom.xml for the given project nature. * * @param mavenProject a description of the Maven project * @param natureId the nature to check * @return {@code true} if the project */ protected boolean hasProjectNature(MavenProject mavenProject, String natureId) { if (natureId == GWTNature.NATURE_ID || getGwtMavenPlugin(mavenProject) != null) { return true; } // The use of the maven-eclipse-plugin is deprecated. The following code is // only for backward compatibility. Plugin plugin = getEclipsePlugin(mavenProject); if (plugin != null) { Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); if (configuration != null) { Xpp3Dom additionalBuildCommands = configuration.getChild("additionalProjectnatures"); if (additionalBuildCommands != null) { for (Xpp3Dom projectNature : additionalBuildCommands.getChildren("projectnature")) { if (projectNature != null && natureId.equals(projectNature.getValue())) { return true; } } } } } return false; }
Example 4
Source File: MavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Get the GWT Maven plugin 2 <moduleShort=Name/>. * * @param mavenProject * @return the moduleName from configuration */ private String getGwtModuleShortName(MavenProject mavenProject) { if (!isGwtMavenPlugin2(mavenProject)) { return null; } Plugin gwtPlugin2 = getGwtMavenPlugin2(mavenProject); if (gwtPlugin2 == null) { return null; } Xpp3Dom gwtPluginConfig = (Xpp3Dom) gwtPlugin2.getConfiguration(); if (gwtPluginConfig == null) { return null; } String moduleName = null; for (Xpp3Dom child : gwtPluginConfig.getChildren()) { if (child != null && GWT_MAVEN_MODULESHORTNAME.equals(child.getName())) { moduleName = child.getValue().trim(); } } return moduleName; }
Example 5
Source File: MavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Get the GWT Maven plugin 2 <moduleName/>. * * @param mavenProject * @return the moduleName from configuration */ private String getGwtModuleName(MavenProject mavenProject) { if (!isGwtMavenPlugin2(mavenProject)) { return null; } Plugin gwtPlugin2 = getGwtMavenPlugin2(mavenProject); if (gwtPlugin2 == null) { return null; } Xpp3Dom gwtPluginConfig = (Xpp3Dom) gwtPlugin2.getConfiguration(); if (gwtPluginConfig == null) { return null; } String moduleName = null; for (Xpp3Dom child : gwtPluginConfig.getChildren()) { if (child != null && GWT_MAVEN_MODULENAME.equals(child.getName())) { moduleName = child.getValue().trim(); } } return moduleName; }
Example 6
Source File: RequirePropertyDiverges.java From extra-enforcer-rules with Apache License 2.0 | 6 votes |
/** * Returns the list of <tt>requirePropertyDiverges</tt> configurations from the map of plugins. * * @param plugins * @return list of requirePropertyDiverges configurations. */ List<Xpp3Dom> getRuleConfigurations( final Map<String, Plugin> plugins ) { if ( plugins.containsKey( MAVEN_ENFORCER_PLUGIN ) ) { final List<Xpp3Dom> ruleConfigurations = new ArrayList<Xpp3Dom>(); final Plugin enforcer = plugins.get( MAVEN_ENFORCER_PLUGIN ); final Xpp3Dom configuration = ( Xpp3Dom ) enforcer.getConfiguration(); // add rules from plugin configuration addRules( configuration, ruleConfigurations ); // add rules from all plugin execution configurations for ( Object execution : enforcer.getExecutions() ) { addRules( ( Xpp3Dom ) ( ( PluginExecution ) execution ).getConfiguration(), ruleConfigurations ); } return ruleConfigurations; } else { return new ArrayList(); } }
Example 7
Source File: DevMojo.java From quarkus with Apache License 2.0 | 5 votes |
private Xpp3Dom getPluginConfig(Plugin plugin) { Xpp3Dom configuration = MojoExecutor.configuration(); Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration(); if (pluginConfiguration != null) { //Filter out `test*` configurations for (Xpp3Dom child : pluginConfiguration.getChildren()) { if (!child.getName().startsWith("test")) { configuration.addChild(child); } } } return configuration; }
Example 8
Source File: RelocationManipulator.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
private Map<ConfigurationContainer, String> findConfigurations( final Plugin plugin ) { if ( plugin == null ) { return Collections.emptyMap(); } final Map<ConfigurationContainer, String> configs = new LinkedHashMap<>(); final Object pluginConfiguration = plugin.getConfiguration(); if ( pluginConfiguration != null ) { configs.put( plugin, pluginConfiguration.toString() ); } final List<PluginExecution> executions = plugin.getExecutions(); if ( executions != null ) { for ( PluginExecution execution : executions ) { final Object executionConfiguration = execution.getConfiguration(); if ( executionConfiguration != null ) { configs.put( execution, executionConfiguration.toString() ); } } } return configs; }
Example 9
Source File: MavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
@Override protected void doConfigure(final MavenProject mavenProject, IProject project, ProjectConfigurationRequest unused, final IProgressMonitor monitor) throws CoreException { Activator.log("MavenProjectConfigurator.doConfigure() invoked"); // configure the GWT Nature boolean hasGwtNature = configureNature(project, mavenProject, GWTNature.NATURE_ID, true, new NatureCallback() { @Override protected void beforeAddingNature() { configureGwtProject(mavenProject, monitor); } }, monitor); // retrieve gwt-maven-plugin configuration if it exists Plugin gwtMavenPlugin = getGwtMavenPlugin(mavenProject); Xpp3Dom mavenConfig = gwtMavenPlugin == null ? null : (Xpp3Dom) gwtMavenPlugin.getConfiguration(); // Persist GWT nature settings if (!hasGwtNature) { Activator.log("MavenProjectConfigurator: Skipping Maven configuration because GWT nature is false. hasGWTNature=" + hasGwtNature); // Exit no maven plugin found return; } try { persistGwtNatureSettings(project, mavenProject, mavenConfig); } catch (BackingStoreException exception) { Activator.logError("MavenProjectConfigurator: Problem configuring maven project.", exception); } }
Example 10
Source File: CloudSdkMojo.java From app-maven-plugin with Apache License 2.0 | 5 votes |
/** * Determines the Java compiler target version by inspecting the project's maven-compiler-plugin * configuration. * * @return The Java compiler target version. */ public String getCompileTargetVersion() { // TODO: Add support for maven.compiler.release // maven-plugin-compiler default is 1.5 String javaVersion = "1.5"; if (mavenProject != null) { // check the maven.compiler.target property first String mavenCompilerTargetProperty = mavenProject.getProperties().getProperty("maven.compiler.target"); if (mavenCompilerTargetProperty != null) { javaVersion = mavenCompilerTargetProperty; } else { Plugin compilerPlugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-compiler-plugin"); if (compilerPlugin != null) { Xpp3Dom config = (Xpp3Dom) compilerPlugin.getConfiguration(); if (config != null) { Xpp3Dom domVersion = config.getChild("target"); if (domVersion != null) { javaVersion = domVersion.getValue(); } } } } } return javaVersion; }
Example 11
Source File: PluginExtractor.java From wisdom with Apache License 2.0 | 5 votes |
/** * Retrieves the main configuration of the given plugin from the Maven Project. * * @param mojo the mojo * @param artifactId the artifact id of the plugin * @param goal an optional goal. If set if first check for a specific configuration executing this * goal, if not found, it returns the global configuration * @return the configuration, {@code null} if not found */ public static Xpp3Dom getBuildPluginConfiguration(AbstractWisdomMojo mojo, String artifactId, String goal) { List<Plugin> plugins = mojo.project.getBuildPlugins(); Plugin plugin = null; for (Plugin plug : plugins) { if (plug.getArtifactId().equals(artifactId)) { plugin = plug; } } if (plugin == null) { // Not found return null; } if (goal != null) { // Check main execution List<String> globalGoals = (List<String>) plugin.getGoals(); if (globalGoals != null && globalGoals.contains(goal)) { return (Xpp3Dom) plugin.getConfiguration(); } // Check executions for (PluginExecution execution : plugin.getExecutions()) { if (execution.getGoals().contains(goal)) { return (Xpp3Dom) execution.getConfiguration(); } } } // Global configuration. return (Xpp3Dom) plugin.getConfiguration(); }
Example 12
Source File: PomUpdater.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
private Boolean skipFromConfiguration(Plugin plugin) { if (!(plugin.getConfiguration() instanceof Xpp3Dom)) { return false; } Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); Xpp3Dom skip = configuration.getChild("skip"); return skip != null && Boolean.parseBoolean(skip.getValue()); }
Example 13
Source File: IteratorMojo.java From iterator-maven-plugin with Apache License 2.0 | 5 votes |
private Xpp3Dom handlePluginConfigurationFromPluginManagement( PluginExecutor pluginExecutor, Plugin executePlugin ) { Xpp3Dom resultConfiguration = toXpp3Dom( pluginExecutor.getConfiguration() ); getLog().debug( "Configuration: " + resultConfiguration.toString() ); if ( executePlugin.getConfiguration() != null ) { Xpp3Dom x = (Xpp3Dom) executePlugin.getConfiguration(); resultConfiguration = Xpp3DomUtils.mergeXpp3Dom( toXpp3Dom( pluginExecutor.getConfiguration() ), x ); getLog().debug( "ConfigurationExecutePlugin: " + executePlugin.getConfiguration().toString() ); } return resultConfiguration; }
Example 14
Source File: TomeeServer.java From microprofile-starter with Apache License 2.0 | 5 votes |
private void adjustPOM(Model pomFile, JessieModel model, boolean mainProject) { Profile profile = pomFile.getProfiles().get(0);// We assume there is only 1 profile. Plugin mavenPlugin = findMavenPlugin(profile.getBuild().getPlugins()); Xpp3Dom configuration = (Xpp3Dom) mavenPlugin.getConfiguration(); Xpp3Dom httpPort = new Xpp3Dom("tomeeHttpPort"); httpPort.setValue( mainProject ? SupportedServer.TOMEE.getPortServiceA() : SupportedServer.TOMEE.getPortServiceB() ); configuration.addChild(httpPort); Xpp3Dom shutdownPort = new Xpp3Dom("tomeeShutdownPort"); shutdownPort.setValue( mainProject ? "8005" : "8105" ); configuration.addChild(shutdownPort); Xpp3Dom ajpPort = new Xpp3Dom("tomeeAjpPort"); ajpPort.setValue( mainProject ? "8009" : "8109" ); configuration.addChild(ajpPort); List<MicroprofileSpec> microprofileSpecs = model.getParameter(JessieModel.Parameter.MICROPROFILESPECS); if (microprofileSpecs.contains(MicroprofileSpec.JWT_AUTH) && !mainProject) { Xpp3Dom systemVariables = new Xpp3Dom("systemVariables"); Xpp3Dom publicKeyLocation = new Xpp3Dom("mp.jwt.verify.publickey.location"); publicKeyLocation.setValue("/publicKey.pem"); systemVariables.addChild(publicKeyLocation); configuration.addChild(systemVariables); } }
Example 15
Source File: DevMojo.java From quarkus with Apache License 2.0 | 5 votes |
private Optional<Xpp3Dom> findCompilerPluginConfiguration() { for (final Plugin plugin : project.getBuildPlugins()) { if (!plugin.getKey().equals("org.apache.maven.plugins:maven-compiler-plugin")) { continue; } final Xpp3Dom compilerPluginConfiguration = (Xpp3Dom) plugin.getConfiguration(); if (compilerPluginConfiguration != null) { return Optional.of(compilerPluginConfiguration); } } return Optional.empty(); }
Example 16
Source File: ExternalVersionExtension.java From maven-external-version with Apache License 2.0 | 4 votes |
private void createNewVersionPom( MavenProject mavenProject, Map<String, String> gavVersionMap ) throws IOException, XmlPullParserException { Reader fileReader = null; Writer fileWriter = null; try { fileReader = new FileReader( mavenProject.getFile() ); Model model = new MavenXpp3Reader().read( fileReader ); model.setVersion( mavenProject.getVersion() ); // TODO: this needs to be restructured when other references are updated (dependencies, dep-management, plugins, etc) if ( model.getParent() != null ) { String key = buildGavKey( model.getParent().getGroupId(), model.getParent().getArtifactId(), model.getParent().getVersion() ); String newVersionForParent = gavVersionMap.get( key ); if ( newVersionForParent != null ) { model.getParent().setVersion( newVersionForParent ); } } Plugin plugin = mavenProject.getPlugin( "org.apache.maven.plugins:maven-external-version-plugin" ); // now we are going to wedge in the config Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration(); File newPom = createFileFromConfiguration( mavenProject, pluginConfiguration ); logger.debug( ExternalVersionExtension.class.getSimpleName() + ": using new pom file => " + newPom ); fileWriter = new FileWriter( newPom ); new MavenXpp3Writer().write( fileWriter, model ); mavenProject.setFile( newPom ); } finally { IOUtil.close( fileReader ); IOUtil.close( fileWriter ); } }
Example 17
Source File: ReportAggregateMojo.java From revapi with Apache License 2.0 | 4 votes |
private Analyzer prepareAnalyzer(Revapi revapi, MavenProject project, Locale locale, ProjectVersions storedVersions) { Plugin runPluginConfig = findRevapi(project); if (runPluginConfig == null) { return null; } Xpp3Dom runConfig = (Xpp3Dom) runPluginConfig.getConfiguration(); Artifact[] oldArtifacts = storedVersions.oldGavs; Artifact[] newArtifacts = storedVersions.newGavs; if (oldArtifacts == null || oldArtifacts.length == 0 || newArtifacts == null || newArtifacts.length == 0) { return null; } String versionRegex = getValueOfChild(runConfig, "versionFormat"); AnalyzerBuilder bld = AnalyzerBuilder.forArtifacts(oldArtifacts, newArtifacts) .withAlwaysCheckForReleasedVersion(this.alwaysCheckForReleaseVersion) .withPipelineConfiguration(this.pipelineConfiguration) .withAnalysisConfiguration(this.analysisConfiguration) .withAnalysisConfigurationFiles(this.analysisConfigurationFiles) .withCheckDependencies(this.checkDependencies) .withResolveProvidedDependencies(this.resolveProvidedDependencies) .withResolveTransitiveProvidedDependencies(this.resolveTransitiveProvidedDependencies) .withDisallowedExtensions(disallowedExtensions) .withFailOnMissingConfigurationFiles(this.failOnMissingConfigurationFiles) .withFailOnUnresolvedArtifacts(this.failOnUnresolvedArtifacts) .withFailOnUnresolvedDependencies(this.failOnUnresolvedDependencies) .withLocale(locale) .withLog(getLog()) .withProject(project) .withRepositorySystem(repositorySystem) .withRepositorySystemSession(repositorySystemSession) .withSkip(skip) .withVersionFormat(versionRegex); if (revapi == null) { bld = bld.withReporter(ReportTimeReporter.class); } else { bld = bld.withRevapiInstance(revapi); } Map<String, Object> contextData = new HashMap<>(1); contextData.put(ReportTimeReporter.MIN_SEVERITY_KEY, reportSeverity.asDifferenceSeverity()); bld.withContextData(contextData); return bld.build().analyzer; }
Example 18
Source File: DevMojo.java From quarkus with Apache License 2.0 | 4 votes |
private void setKotlinSpecificFlags(DevModeContext devModeContext) { Plugin kotlinMavenPlugin = null; for (Plugin plugin : project.getBuildPlugins()) { if (plugin.getKey().equals(KOTLIN_MAVEN_PLUGIN_GA)) { kotlinMavenPlugin = plugin; break; } } if (kotlinMavenPlugin == null) { return; } getLog().debug("Kotlin Maven plugin detected"); List<String> compilerPluginArtifacts = new ArrayList<>(); List<Dependency> dependencies = kotlinMavenPlugin.getDependencies(); for (Dependency dependency : dependencies) { try { ArtifactResult resolvedArtifact = repoSystem.resolveArtifact(repoSession, new ArtifactRequest() .setArtifact(new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getType(), dependency.getVersion())) .setRepositories(repos)); compilerPluginArtifacts.add(resolvedArtifact.getArtifact().getFile().toPath().toAbsolutePath().toString()); } catch (ArtifactResolutionException e) { getLog().warn("Unable to properly setup dev-mode for Kotlin", e); return; } } devModeContext.setCompilerPluginArtifacts(compilerPluginArtifacts); List<String> options = new ArrayList<>(); Xpp3Dom compilerPluginConfiguration = (Xpp3Dom) kotlinMavenPlugin.getConfiguration(); if (compilerPluginConfiguration != null) { Xpp3Dom compilerPluginArgsConfiguration = compilerPluginConfiguration.getChild("pluginOptions"); if (compilerPluginArgsConfiguration != null) { for (Xpp3Dom argConfiguration : compilerPluginArgsConfiguration.getChildren()) { options.add(argConfiguration.getValue()); } } } devModeContext.setCompilerPluginsOptions(options); }
Example 19
Source File: DistributionEnforcingManipulator.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
/** * Go through the plugin / plugin-execution configurations and find references to the <code>skip</code> parameter for the given Maven plugin * instance. */ private List<SkipReference> findSkipRefs( final Plugin plugin, final Project project ) throws ManipulationException { if ( plugin == null ) { return Collections.emptyList(); } final Map<ConfigurationContainer, String> configs = new LinkedHashMap<>(); Object configuration = plugin.getConfiguration(); if ( configuration != null ) { configs.put( plugin, configuration.toString() ); } final List<PluginExecution> executions = plugin.getExecutions(); if ( executions != null ) { for ( final PluginExecution execution : executions ) { configuration = execution.getConfiguration(); if ( configuration != null ) { configs.put( execution, configuration.toString() ); } } } final List<SkipReference> result = new ArrayList<>(); for ( final Map.Entry<ConfigurationContainer, String> entry : configs.entrySet() ) { try { final Document doc = galleyWrapper.parseXml( entry.getValue() ); final NodeList children = doc.getDocumentElement() .getChildNodes(); if ( children != null ) { for ( int i = 0; i < children.getLength(); i++ ) { final Node n = children.item( i ); if ( n.getNodeName() .equals( SKIP_NODE ) ) { result.add( new SkipReference( entry.getKey(), n ) ); } } } } catch ( final GalleyMavenXMLException e ) { throw new ManipulationException( "Unable to parse config for plugin {} in {}", plugin.getId(), project.getKey(), e ); } } return result; }
Example 20
Source File: Verify.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
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()); //Check if the properties have been set correctly Properties properties = model.getProperties(); assertThat(properties.containsKey("vertx.version")).isTrue(); assertThat(properties.getProperty("vertx.version")) .isEqualTo(MojoUtils.getVersion("vertx-core-version")); assertThat(properties.containsKey("vertx-maven-plugin.version")).isTrue(); assertThat(properties.getProperty("vertx-maven-plugin.version")) .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-stack-depchain") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxDeps.isPresent()).isTrue(); assertThat(vertxDeps.get().getVersion()).isEqualTo("${vertx.version}"); //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"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }