private void configureJarPlugin(MavenProject project) throws MavenExecutionException { Plugin jarPlugin = getPlugin(project, "org.apache.maven.plugins:maven-jar-plugin"); if (jarPlugin != null) { StringBuilder jarConfig = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") // .append("<configuration>") // .append(" <archive>\n") // .append(" <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>\n") // .append(" </archive>") // .append(" <annotationProcessorPaths>") // .append(" <annotationProcessorPath>") // .append(" <groupId>com.commsen.em</groupId>") // .append(" <artifactId>em.annotation.processors</artifactId>") // .append(" <version>").append(Constants.VAL_EXTENSION_VERSION).append("</version>") // .append(" </annotationProcessorPath>") // .append(" </annotationProcessorPaths>") // .append("</configuration>"); configurePlugin(jarPlugin, "default-jar", jarConfig.toString()); } }
protected Plugin createPlugin(String groupId, String artifactId, String version, String configuration, String executionId, String goal, String phase) throws MavenExecutionException { Plugin plugin = new Plugin(); plugin.setGroupId(groupId); plugin.setArtifactId(artifactId); plugin.setVersion(version); PluginExecution execution = new PluginExecution(); execution.setId(executionId); execution.addGoal(goal); if (phase != null) { execution.setPhase(phase); } if (configuration != null) { execution.setConfiguration(mavenConfig.asXpp3Dom(configuration)); } plugin.addExecution(execution); return plugin; }
public void addToPomForIndexingTmpBundles(MavenProject project) throws MavenExecutionException { Path genertedModules; try { genertedModules = Constants.getGeneratedModulesFolder(project); } catch (IOException e) { throw new MavenExecutionException(e.getMessage(), e); } String configuration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" // + "<configuration>" // + " <inputDir>" // + genertedModules // + " </inputDir>" // + " <outputFile>${project.build.directory}/index/index.xml</outputFile>" // + "</configuration>"; // Plugin plugin = createPlugin("biz.aQute.bnd", "bnd-indexer-maven-plugin", VAL_BND_VERSION, configuration, "index", "local-index", null); project.getBuild().getPlugins().add(0, plugin); logger.info("Added `bnd-indexer-maven-plugin` to genrate an index of detected modules!"); }
private String findVersion(String groupId, String artifactId) { String key = groupId + ":" + artifactId; List<Plugin> plugins = new ArrayList<Plugin>(); if (project != null) { List<Plugin> bld = project.getOriginalMavenProject().getBuildPlugins(); if (bld != null) { plugins.addAll(bld); } if (project.getOriginalMavenProject().getPluginManagement() != null) { List<Plugin> pm = project.getOriginalMavenProject().getPluginManagement().getPlugins(); if (pm != null) { plugins.addAll(pm); } } } for (Plugin plg : plugins) { if (key.equals(plg.getKey())) { return plg.getVersion(); } } return null; }
/** @see org.apache.maven.lifecycle.internal.DefaultLifecycleExecutionPlanCalculator */ private static @NonNull List<PluginExecution> getPluginExecutions(@NonNull Plugin plug, @NullAllowed String goal) { if (goal == null) { return Collections.emptyList(); } List<PluginExecution> exes = new ArrayList<PluginExecution>(); for (PluginExecution exe : plug.getExecutions()) { if (exe.getGoals().contains(goal) || /* #179328: Maven 2.2.0+ */ ("default-" + goal).equals(exe.getId())) { exes.add(exe); } } Collections.sort(exes, new Comparator<PluginExecution>() { @Override public int compare(PluginExecution e1, PluginExecution e2) { return e2.getPriority() - e1.getPriority(); } }); return exes; }
private void writePluginManagement(PluginManagement pluginManagement, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); flush(serializer); StringBuffer b = b(serializer); int start = b.length(); if ((pluginManagement.getPlugins() != null) && (pluginManagement.getPlugins().size() > 0)) { serializer.startTag(NAMESPACE, "plugins"); for (Iterator iter = pluginManagement.getPlugins().iterator(); iter.hasNext();) { Plugin o = (Plugin) iter.next(); writePlugin(o, "plugin", serializer); } serializer.endTag(NAMESPACE, "plugins"); } serializer.endTag(NAMESPACE, tagName).flush(); logLocation(pluginManagement, "", start, b.length()); }
@Override public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException { WorkspaceReader wr = session.getWorkspaceReader(); NbWorkspaceReader nbwr = null; if (wr instanceof NbWorkspaceReader) { nbwr = (NbWorkspaceReader)wr; //this only works reliably because the NbWorkspaceReader is part of the session, not a component nbwr.silence(); } try { return super.resolve(plugin, repositories, session); } finally { if (nbwr != null) { nbwr.normal(); } } }
@Override public DependencyNode resolve(Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException { WorkspaceReader wr = session.getWorkspaceReader(); NbWorkspaceReader nbwr = null; if (wr instanceof NbWorkspaceReader) { nbwr = (NbWorkspaceReader)wr; //this only works reliably because the NbWorkspaceReader is part of the session, not a component nbwr.silence(); } try { return super.resolve(plugin, pluginArtifact, dependencyFilter, repositories, session); } finally { if (nbwr != null) { nbwr.normal(); } } }
@Test public void addPluginWithVersionTest() throws IOException, XmlPullParserException { Model pomModelBeforeChange = getOriginalPomModel("pom.xml"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 1); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin"); PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin", "2.10.4").relative("pom.xml"); TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); Model pomModelAfterChange = getTransformedPomModel("pom.xml"); assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 2); Plugin plugin = new Plugin(); plugin.setGroupId("org.apache.maven.plugins"); plugin.setArtifactId("maven-javadoc-plugin"); assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin)); assertEquals(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion(), "2.10.4"); }
@Test public void addPluginWithoutVersionTest() throws IOException, XmlPullParserException { Model pomModelBeforeChange = getOriginalPomModel("pom.xml"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().size(), 1); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getGroupId(), "org.codehaus.mojo"); assertEquals(pomModelBeforeChange.getBuild().getPlugins().get(0).getArtifactId(), "cobertura-maven-plugin"); PomAddPlugin pomAddPlugin = new PomAddPlugin("org.apache.maven.plugins", "maven-javadoc-plugin").relative("pom.xml"); TOExecutionResult executionResult = pomAddPlugin.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); Model pomModelAfterChange = getTransformedPomModel("pom.xml"); assertEquals(pomModelAfterChange.getBuild().getPlugins().size(), 2); Plugin plugin = new Plugin(); plugin.setGroupId("org.apache.maven.plugins"); plugin.setArtifactId("maven-javadoc-plugin"); assertTrue(pomModelAfterChange.getBuild().getPlugins().contains(plugin)); assertNull(pomModelAfterChange.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-javadoc-plugin").getVersion()); }
private List<String> getNonFilteredFileExtensions(List<Plugin> plugins) { for (Plugin plugin : plugins) { if (MAVEN_RESOURCES_PLUGIN.equals(plugin.getArtifactId())) { final Object configuration = plugin.getConfiguration(); if (configuration != null) { Xpp3Dom xpp3Dom = (Xpp3Dom) configuration; final Xpp3Dom nonFilteredFileExtensions = xpp3Dom.getChild(NON_FILTERED_FILE_EXTENSIONS); List<String> nonFilteredFileExtensionsList = new ArrayList<>(); final Xpp3Dom[] children = nonFilteredFileExtensions.getChildren(); for (Xpp3Dom child : children) { nonFilteredFileExtensionsList.add(child.getValue()); } return nonFilteredFileExtensionsList; } } } return null; }
boolean configureTestRunner(Model model) { final List<Plugin> effectiveTestRunnerPluginConfigurations = getEffectivePlugins(model); if (!effectiveTestRunnerPluginConfigurations.isEmpty()) { logger.debug("Enabling Smart Testing %s for plugin %s in %s module", ExtensionVersion.version().toString(), effectiveTestRunnerPluginConfigurations.stream() .map(Plugin::getArtifactId) .collect(Collectors.toList()).toString(), model.getArtifactId()); dependencyResolver.addRequiredDependencies(model); effectiveTestRunnerPluginConfigurations .forEach(plugin -> { dependencyResolver.removeAndRegisterFirstCustomProvider(model, plugin); dependencyResolver.addAsPluginDependency(plugin); }); return true; } else { logger.debug("Disabling Smart Testing %s in %s module. Reason: No executable test plugin is set.", ExtensionVersion.version().toString(), model.getArtifactId()); return false; } }
@Test public void should_remove_custom_provider_dependency_and_create_info_file_when_set_in_config() { // given Configuration config = ConfigurationLoader.load(tmpFolder); config.setCustomProviders(new String[] {"org.foo.provider:my-custom-provider=org.foo.impl.SurefireProvider"}); DependencyResolver dependencyResolver = new DependencyResolver(config); Dependency customDep = createDependency("org.foo.provider", "my-custom-provider", "1.2.3"); Model model = Mockito.mock(Model.class); Plugin plugin = prepareModelWithPluginDep(model, customDep); // when dependencyResolver.removeAndRegisterFirstCustomProvider(model, plugin); // then verifyDependencyIsRemovedAndFileCreated(plugin, customDep, "org.foo.impl.SurefireProvider"); }
public void merge( MavenProject project, Plugin mergePlugin) { if (mergePlugin.getArtifactId() == null || mergePlugin.getArtifactId().isEmpty()) { return; } List<Plugin> plugins = project.getBuild().getPlugins(); Plugin foundPlugin = null; for (Plugin plugin : plugins) { if (mergePlugin.getGroupId().equals(plugin.getGroupId()) && mergePlugin.getArtifactId().equals(plugin.getArtifactId())) { foundPlugin = plugin; break; } } if (foundPlugin == null) { plugins.add(mergePlugin); } else { mergeExecutions(foundPlugin.getExecutions(), mergePlugin.getExecutions()); } }
public Plugin getEnforcerPlugin(MavenProject project) throws MavenExecutionException { StringBuilder configString = new StringBuilder() .append("<configuration><rules>") .append("<requireReleaseDeps><message>No Snapshots Allowed!</message><excludes><exclude>"+project.getGroupId()+":*</exclude></excludes></requireReleaseDeps>") .append("</rules></configuration>"); Xpp3Dom config = null; try { config = Xpp3DomBuilder.build(new StringReader(configString.toString())); } catch (XmlPullParserException | IOException ex) { throw new MavenExecutionException("Issue creating cofig for enforcer plugin", ex); } PluginExecution execution = new PluginExecution(); execution.setId("no-snapshot-deps"); execution.addGoal("enforce"); execution.setConfiguration(config); Plugin result = new Plugin(); result.setArtifactId("maven-enforcer-plugin"); result.setVersion("1.4.1"); result.addExecution(execution); return result; }
@Test public void testMerge_pluginFoundWithNoExecutions() { Plugin buildPlugin = new Plugin(); buildPlugin.setArtifactId("merge-artifact"); List<Plugin> plugins = project.getBuild().getPlugins(); plugins.addAll(dummyPlugins); plugins.add(buildPlugin); PluginExecution exec = new PluginExecution(); exec.setId("merge-execution-id"); exec.setGoals(Arrays.asList("some-goal")); exec.setPhase("random-phase"); exec.setPriority(1); Plugin mergePlugin = new Plugin(); mergePlugin.setArtifactId("merge-artifact"); mergePlugin.getExecutions().add(exec); item.merge(project, mergePlugin); Assert.assertEquals("Plugins.Size", dummyPlugins.size() + 1, project.getBuildPlugins().size()); for (int i = 0; i < dummyPlugins.size(); i++) { Assert.assertThat("Plugins["+i+"]", project.getBuildPlugins().get(i), Matchers.sameBeanAs(dummyPlugins.get(i))); } Assert.assertThat("Plugins["+dummyPlugins.size()+"]", project.getBuildPlugins().get(dummyPlugins.size()), Matchers.sameBeanAs(mergePlugin)); }
@Test public void testGetEnforcerPlugin() throws MavenExecutionException, XmlPullParserException, IOException { Plugin result = item.getEnforcerPlugin(); Assert.assertEquals("GroupId", "org.apache.maven.plugins", result.getGroupId()); Assert.assertEquals("ArtifactId", "maven-enforcer-plugin", result.getArtifactId()); Assert.assertEquals("Version", "1.4.1", result.getVersion()); Assert.assertEquals("Executions.Size", 1, result.getExecutions().size()); PluginExecution execution = result.getExecutions().get(0); Assert.assertEquals("Executions[0].Id", "no-snapshot-deps", execution.getId()); Assert.assertEquals("Executions[0].Goals.Size", 1, execution.getGoals().size()); Assert.assertEquals("Executions[0].Goals[0]", "enforce", execution.getGoals().get(0)); Assert.assertEquals("Executions[0].Configuration", Xpp3DomBuilder.build(new StringReader("<configuration><rules><requireReleaseDeps><message>No Snapshots Allowed!</message></requireReleaseDeps></rules></configuration>")), execution.getConfiguration()); }
@Test public void testGetVersionFixPlugin() throws MavenExecutionException, XmlPullParserException, IOException { Plugin result = item.getVersionFixPlugin(); Assert.assertEquals("GroupId", "com.iggroup.maven.cdversion", result.getGroupId()); Assert.assertEquals("ArtifactId", "versionfix-maven-plugin", result.getArtifactId()); Assert.assertEquals("Version", "1.0.0-SNAPSHOT", result.getVersion()); Assert.assertEquals("Executions.Size", 1, result.getExecutions().size()); PluginExecution execution = result.getExecutions().get(0); Assert.assertEquals("Executions[0].Id", "versionfix", execution.getId()); Assert.assertEquals("Executions[0].Goals.Size", 1, execution.getGoals().size()); Assert.assertEquals("Executions[0].Goals[0]", "versionfix", execution.getGoals().get(0)); }
/** * Method updatePlugin * * @param value * @param element * @param counter * @param xmlTag */ protected void updatePlugin( Plugin value, String xmlTag, Counter counter, Element element ) { Element root = element; Counter innerCount = new Counter( counter.getDepth() + 1 ); findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" ); findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null ); findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null ); findAndReplaceSimpleElement( innerCount, root, "extensions", !value.isExtensions() ? null : String.valueOf( value.isExtensions() ), "false" ); iteratePluginExecution( innerCount, root, value.getExecutions(), "executions", "execution" ); iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" ); findAndReplaceXpp3DOM( innerCount, root, "goals", (Xpp3Dom) value.getGoals() ); findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null ); findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() ); }
private static Plugin getOrCreateResourcesPlugin(Model mavenModel) { Build build = getOrCreateBuild(mavenModel); // Locate the plugin and returns if exists for (Iterator<Plugin> iterator = build.getPlugins().iterator(); iterator.hasNext();) { Plugin next = iterator.next(); if ("maven-resources-plugin".equals(next.getArtifactId())) { return next; } } // Creates if couldn't be found. Plugin resourcesPlugin = new Plugin(); resourcesPlugin.setGroupId("org.apache.maven.plugins"); resourcesPlugin.setArtifactId("maven-resources-plugin"); resourcesPlugin.setVersion("${maven.resources.plugin.version}"); build.getPlugins().add(resourcesPlugin); return resourcesPlugin; }
private static Plugin getJavadocPlugin() { final Plugin javadocPlugin = new Plugin(); javadocPlugin.setGroupId("org.apache.maven.plugins"); javadocPlugin.setArtifactId("maven-javadoc-plugin"); //javadocPlugin.setVersion("2.10.4"); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId("javadoc"); List<String> goals = new ArrayList<>(); goals.add("jar"); pluginExecution.setGoals(goals); pluginExecution.setPhase("package"); List<PluginExecution> pluginExecutions = new ArrayList<>(); pluginExecutions.add(pluginExecution); javadocPlugin.setExecutions(pluginExecutions); final Xpp3Dom javadocConfig = new Xpp3Dom("configuration"); final Xpp3Dom quiet = new Xpp3Dom("quiet"); quiet.setValue("true"); javadocConfig.addChild(quiet); javadocPlugin.setConfiguration(javadocConfig); return javadocPlugin; }
private static Plugin getSourcePlugin() { final Plugin sourcePlugin = new Plugin(); sourcePlugin.setGroupId("org.apache.maven.plugins"); sourcePlugin.setArtifactId("maven-source-plugin"); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId("attach-sources"); List<String> goals = new ArrayList<>(); goals.add("jar"); pluginExecution.setGoals(goals); pluginExecution.setPhase("package"); List<PluginExecution> pluginExecutions = new ArrayList<>(); pluginExecutions.add(pluginExecution); sourcePlugin.setExecutions(pluginExecutions); return sourcePlugin; }
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); Build build = project.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { for (Plugin plugin : pluginManagement.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } } return result; }
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshots(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking direct plugin references"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); Build build = project.getBuild(); if (build != null) { for (Plugin plugin : build.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } return result; }
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromManagement(Profile profile, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins of profile '" + profile.getId() + "'"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); BuildBase build = profile.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { for (Plugin plugin : pluginManagement.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } } return result; }
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshots(Profile profile, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking direct plugin references of profile '" + profile.getId() + "'"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); BuildBase build = profile.getBuild(); if (build != null) { for (Plugin plugin : build.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } return result; }
/** * Determines the Java compiler target version by inspecting the project's maven-compiler-plugin * configuration. * * @return The Java compiler target version. */ public String getCompileTargetVersion() { // 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; }
private void executePluginDef(InputStream is) throws Exception { Xpp3Dom pluginDef = Xpp3DomBuilder.build(is, "utf-8"); Plugin plugin = loadPlugin(pluginDef); Xpp3Dom config = pluginDef.getChild("configuration"); PluginDescriptor pluginDesc = pluginManager.loadPlugin(plugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession()); Xpp3Dom executions = pluginDef.getChild("executions"); for ( Xpp3Dom execution : executions.getChildren()) { Xpp3Dom goals = execution.getChild("goals"); for (Xpp3Dom goal : goals.getChildren()) { MojoDescriptor desc = pluginDesc.getMojo(goal.getValue()); pluginManager.executeMojo(mavenSession, new MojoExecution(desc, config)); } } }
private void addPluginArtifacts( final Set<Artifact> artifacts ) { final Map<String, Artifact> dependencyArtifactMap = this.pluginDescriptor.getArtifactMap(); // We should always have FitNesse itself on the FitNesse classpath! artifacts.addAll( resolveDependencyKey( FitNesseMavenCoordinate.artifactKey, dependencyArtifactMap ) ); // We check plugin for null to allow use in standalone mode final Plugin fitnessePlugin = this.project.getPlugin( this.pluginDescriptor.getPluginLookupKey() ); if( fitnessePlugin == null ){ getLog().info( "Running standalone - launching vanilla FitNesse" ); }else{ final List<Dependency> dependecies = fitnessePlugin.getDependencies(); if( dependecies != null && !dependecies.isEmpty() ){ getLog().info( "Using dependencies specified in plugin config" ); for( Dependency dependency : dependecies ){ final String key = dependency.getGroupId() + ":" + dependency.getArtifactId(); artifacts.addAll( resolveDependencyKey( key, dependencyArtifactMap ) ); } } } }
@SuppressWarnings( "unchecked" ) void setupArtifact( String groupId, String artifactId, String goal, String type ) throws DuplicateMojoDescriptorException, PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException { DefaultArtifact artifact = new DefaultArtifact( groupId, artifactId, "DUMMY", "compile", type, "", null ); MojoDescriptor mojoDescriptor = new MojoDescriptor(); mojoDescriptor.setGoal( goal ); PluginDescriptor pluginDescriptor = new PluginDescriptor(); pluginDescriptor.addMojo( mojoDescriptor ); Plugin plugin = new Plugin(); plugin.setGroupId( groupId ); plugin.setArtifactId( artifactId ); when( this.mojo.pluginManager.loadPlugin( eq( plugin ), anyList(), any( RepositorySystemSession.class ) ) ).thenReturn( pluginDescriptor ); this.mojo.pluginDescriptor.getArtifactMap().put( String.format( "%s:%s", groupId, artifactId ), artifact ); }
private void visitBuildPluginManagement( ModelVisitor visitor, PluginManagement pluginManagement ) { List<Plugin> plugins = pluginManagement.getPlugins(); if ( plugins != null ) { ListIterator<Plugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { Plugin plugin = pluginIterator.next(); visitor.visitBuildPluginManagementPlugin( plugin ); visitBuildPluginManagementPlugin( visitor, plugin ); plugin = visitor.replaceBuildPluginManagementPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
private void visitProfileBuildPluginManagement( ModelVisitor visitor, PluginManagement pluginManagement ) { List<Plugin> plugins = pluginManagement.getPlugins(); if ( plugins != null ) { ListIterator<Plugin> pluginIterator = plugins.listIterator(); while ( pluginIterator.hasNext() ) { Plugin plugin = pluginIterator.next(); visitor.visitProfileBuildPluginManagementPlugin( plugin ); visitProfileBuildPluginManagementPlugin( visitor, plugin ); plugin = visitor.replaceProfileBuildPluginManagementPlugin( plugin ); if ( plugin == null ) pluginIterator.remove(); else pluginIterator.set( plugin ); } } }
@Override public void visitBuildPlugin( Plugin plugin ) { if ( isExternal( plugin.getLocation( "" ) ) ) return; String groupId = plugin.getGroupId(); String artifactId = plugin.getArtifactId(); String version = plugin.getVersion(); if ( StringUtils.isEmpty( groupId ) ) groupId = "org.apache.maven.plugins"; if ( StringUtils.isEmpty( version ) ) version = Artifact.DEFAULT_VERSION; Artifact pluginArtifact = new DefaultArtifact( groupId, artifactId, version ); artifacts.add( pluginArtifact ); }
void customizeModel( Model model ) { BuildSettings settings = configurator.getConfiguration().getBuildSettings(); Build build = model.getBuild() != null ? model.getBuild() : new Build(); List<Dependency> dependencies = model.getDependencies(); List<Extension> extensions = build.getExtensions(); List<Plugin> plugins = build.getPlugins(); if ( settings.isSkipTests() ) dependencies.removeIf( d -> StringUtils.equals( d.getScope(), "test" ) ); dependencies.forEach( d -> d.setVersion( replaceVersion( d.getGroupId(), d.getArtifactId(), d.getVersion() ) ) ); extensions.forEach( e -> e.setVersion( replaceVersion( e.getGroupId(), e.getArtifactId(), e.getVersion() ) ) ); plugins.forEach( p -> p.setVersion( replaceVersion( p.getGroupId(), p.getArtifactId(), p.getVersion() ) ) ); plugins.stream().filter( p -> p.getGroupId().equals( "org.apache.maven.plugins" ) && p.getArtifactId().equals( "maven-compiler-plugin" ) ).forEach( p -> configureCompiler( p ) ); }
@Test public void getActualPluginVersionNoMatchingSubstitution() { final Plugin originalPlugin = mock(Plugin.class); when(originalPlugin.getGroupId()).thenReturn(ANY_GROUP_ID); when(originalPlugin.getArtifactId()).thenReturn(ANY_ARTIFACT_ID); when(originalPlugin.getVersion()).thenReturn(ANY_VERSION_PROPERTY); final Plugin substitutedPlugins = mock(Plugin.class); when(substitutedPlugins.getGroupId()).thenReturn(EXPECTED_GROUP_ID); when(substitutedPlugins.getArtifactId()).thenReturn(EXPECTED_ARTIFACT_ID); when(substitutedPlugins.getVersion()).thenReturn(EXPECTED_VERSION); when(project.getBuildPlugins()).thenReturn(asList(substitutedPlugins)); assertNull(substitution.getActualVersionOrNull(project, originalPlugin)); }
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()); } 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; } } } }
/** * Returns the rule configurations from the <tt>pluginManagement</tt> as well * as the <tt>plugins</tt> section. * * @param build the build to inspect. * @return configuration of the rules, may be an empty list. */ final List<Xpp3Dom> getRuleConfigurations( final Build build ) { @SuppressWarnings( "unchecked" ) final Map<String, Plugin> plugins = build.getPluginsAsMap(); final List<Xpp3Dom> ruleConfigurationsForPlugins = getRuleConfigurations( plugins ); final PluginManagement pluginManagement = build.getPluginManagement(); if ( pluginManagement != null ) { @SuppressWarnings( "unchecked" ) final Map<String, Plugin> pluginsFromManagementAsMap = pluginManagement.getPluginsAsMap(); List<Xpp3Dom> ruleConfigurationsFromManagement = getRuleConfigurations( pluginsFromManagementAsMap ); ruleConfigurationsForPlugins.addAll( ruleConfigurationsFromManagement ); } return ruleConfigurationsForPlugins; }
/** * 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(); } }
/** * Test of execute method, of class RequirePropertyDiverges. */ @Test public void testExecuteInParentWithConfigurationInPluginManagement() throws EnforcerRuleException { RequirePropertyDiverges mockInstance = createMockRule(); final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); // create pluginManagement final Plugin pluginInManagement = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); final Xpp3Dom configuration = createPluginConfiguration(); pluginInManagement.setConfiguration( configuration ); final PluginManagement pluginManagement = new PluginManagement(); pluginManagement.addPlugin( pluginInManagement ); build.setPluginManagement( pluginManagement ); // create plugins final Plugin pluginInPlugins = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); build.addPlugin( pluginInPlugins ); // add build project.getOriginalModel().setBuild( build ); //project.getOriginalModel().setBuild( build ); setUpHelper( project, "parentValue" ); mockInstance.execute( helper ); }
/** * Test of execute method, of class RequirePropertyDiverges. */ @Test public void testExecuteInParentWithConfigurationInExecution() throws EnforcerRuleException { RequirePropertyDiverges mockInstance = createMockRule(); final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); build.setPluginManagement( new PluginManagement() ); final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0" ); final Xpp3Dom configuration = createPluginConfiguration(); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setConfiguration( configuration ); plugin.addExecution( pluginExecution ); build.addPlugin( plugin ); project.getOriginalModel().setBuild( build ); setUpHelper(project, "parentValue"); mockInstance.execute( helper ); }