From bdd8580882295177900855572e41ce891ab9cfaf Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Thu, 31 Jan 2013 21:05:55 +0100 Subject: [PATCH] Regression test and changelog for [JENKINS-16573] --- changelog.html | 3 ++ .../src/main/java/hudson/maven/MojoInfo.java | 7 ++-- .../java/hudson/maven/reporters/TestMojo.java | 9 +++-- .../hudson/maven/reporters/TestMojoTest.java | 36 +++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 maven-plugin/src/test/java/hudson/maven/reporters/TestMojoTest.java diff --git a/changelog.html b/changelog.html index ed7279ff70..862188aa35 100644 --- a/changelog.html +++ b/changelog.html @@ -58,6 +58,9 @@ Upcoming changes
  • Reverted change in 1.500 causing serious regression in HTTPS reverse proxy setups. (issue 16368) +
  • + Getting test results from custom test mojos failed build. + (issue 16573)
  • Bogus “Build Record Root Directory” inadequately diagnosed. (issue 16457) diff --git a/maven-plugin/src/main/java/hudson/maven/MojoInfo.java b/maven-plugin/src/main/java/hudson/maven/MojoInfo.java index 59dffc0670..3c7a4eca03 100644 --- a/maven-plugin/src/main/java/hudson/maven/MojoInfo.java +++ b/maven-plugin/src/main/java/hudson/maven/MojoInfo.java @@ -45,6 +45,8 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; import java.lang.reflect.Method; +import javax.annotation.CheckForNull; + import hudson.util.InvocationInterceptor; import hudson.util.ReflectionUtils; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; @@ -145,13 +147,14 @@ public class MojoInfo { * * @return * The configuration value either specified in POM, or inherited from - * parent POM, or default value if one is specified in mojo. + * parent POM, or default value if one is specified in mojo, + * or null if no such configuration value exists. * * @throws ComponentConfigurationException * Not sure when exactly this is thrown, but it's probably when * the configuration in POM is syntactically incorrect. */ - public T getConfigurationValue(String configName, Class type) throws ComponentConfigurationException { + @CheckForNull public T getConfigurationValue(String configName, Class type) throws ComponentConfigurationException { PlexusConfiguration child = configuration.getChild(configName,false); if(child==null) return null; // no such config diff --git a/maven-plugin/src/main/java/hudson/maven/reporters/TestMojo.java b/maven-plugin/src/main/java/hudson/maven/reporters/TestMojo.java index db6cbea6c7..70d16ef825 100644 --- a/maven-plugin/src/main/java/hudson/maven/reporters/TestMojo.java +++ b/maven-plugin/src/main/java/hudson/maven/reporters/TestMojo.java @@ -8,6 +8,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import javax.annotation.CheckForNull; + import org.apache.maven.project.MavenProject; import org.apache.tools.ant.types.FileSet; import org.codehaus.plexus.component.configurator.ComponentConfigurationException; @@ -60,7 +62,10 @@ enum TestMojo { File reportsDir = mojo.getConfigurationValue("jasmineTargetDir", File.class); String junitFileName = mojo.getConfigurationValue("junitXmlReportFileName", String.class); - return Collections.singleton(new File(reportsDir,junitFileName)); + if (reportsDir != null && junitFileName != null) { + return Collections.singleton(new File(reportsDir,junitFileName)); + } + return null; } }, TOOLKIT_RESOLVER_PLUGIN("org.terracotta.maven.plugins", "toolkit-resolver-plugin", "toolkit-resolve-test","reportsDirectory"); @@ -98,7 +103,7 @@ enum TestMojo { return mojo.pluginName.version.compareTo(this.minimalRequiredVersion) >= 0; } - public Iterable getReportFiles(MavenProject pom, MojoInfo mojo) throws ComponentConfigurationException { + @CheckForNull public Iterable getReportFiles(MavenProject pom, MojoInfo mojo) throws ComponentConfigurationException { if (this.reportDirectoryConfigKey != null) { File reportsDir = mojo.getConfigurationValue(this.reportDirectoryConfigKey, File.class); if (reportsDir != null && reportsDir.exists()) { diff --git a/maven-plugin/src/test/java/hudson/maven/reporters/TestMojoTest.java b/maven-plugin/src/test/java/hudson/maven/reporters/TestMojoTest.java new file mode 100644 index 0000000000..a847ac46d0 --- /dev/null +++ b/maven-plugin/src/test/java/hudson/maven/reporters/TestMojoTest.java @@ -0,0 +1,36 @@ +package hudson.maven.reporters; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import hudson.maven.MojoInfo; +import hudson.maven.MojoInfoBuilder; + +import java.io.File; + +import org.apache.maven.model.Build; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.component.configurator.ComponentConfigurationException; +import org.junit.Test; +import org.jvnet.hudson.test.Bug; + +public class TestMojoTest { + + @Test + @Bug(16573) + public void testGetReportFilesThrowsNoException() throws ComponentConfigurationException { + // no 'reportsDirectory' or so config value set: + MojoInfo mojoInfo = MojoInfoBuilder.mojoBuilder("com.some", "testMojo", "test").build(); + + MavenProject pom = mock(MavenProject.class); + when(pom.getBasedir()).thenReturn(new File("foo")); + + Build build = mock(Build.class); + when(build.getDirectory()).thenReturn("bar"); + when(pom.getBuild()).thenReturn(build); + + for (TestMojo testMojo : TestMojo.values()) { + testMojo.getReportFiles(pom, mojoInfo); + } + } + +} -- GitLab