Skip to content

Commit

Permalink
cleaner: fix NPE when processing plugins without versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kdgregory committed Nov 14, 2012
1 parent 23560f3 commit 26e98c2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@

import org.apache.log4j.Logger;

import net.sf.kdgcommons.lang.StringUtil;
import net.sf.practicalxml.DomUtil;

import com.kdgregory.pomutil.cleaner.Options;
Expand Down Expand Up @@ -142,6 +143,8 @@ private Set<String> updateDependencies(List<Element> dependencies, Map<String,St
for (Element dependency : dependencies)
{
String currentVersion = pom.selectValue(dependency, "mvn:version");
if (StringUtil.isBlank(currentVersion))
continue;
if (currentVersion.startsWith("${"))
continue;

Expand Down
Expand Up @@ -266,6 +266,26 @@ public void testReplaceExistingPluginVersionProperties() throws Exception
}


@Test
public void testIgnorePluginsWithoutVersions() throws Exception
{
new ReplaceExplicitVersionsWithProperties(loadPom("cleaner/VersionProps10.xml")).transform();

// note: there's only one plugin defined
assertEquals("plugin group", "com.example",
newXPath("/mvn:project/mvn:build/mvn:pluginManagement/mvn:plugins/mvn:plugin/mvn:groupId")
.evaluateAsString(dom()));
assertEquals("plugin artifact", "example-plugin",
newXPath("/mvn:project/mvn:build/mvn:pluginManagement/mvn:plugins/mvn:plugin/mvn:artifactId")
.evaluateAsString(dom()));
assertEquals("plugin version", "",
newXPath("/mvn:project/mvn:build/mvn:pluginManagement/mvn:plugins/mvn:plugin/mvn:version")
.evaluateAsString(dom()));

}



@Test
public void testDisabled() throws Exception
{
Expand Down
27 changes: 27 additions & 0 deletions app-cleaner/src/test/resources/cleaner/VersionProps10.xml
@@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example.pom</groupId>
<artifactId>VersionProps7</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<description>
Tests plugins that do not have a version. These should be left alone (they were
throwing NPE).
</description>


<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>example-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>

0 comments on commit 26e98c2

Please sign in to comment.