Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-12853] Always use findbugsXml.xml when
findbugs-maven-plugin version >= 2.4.0 is used.
  • Loading branch information
uhafner committed Mar 5, 2012
1 parent 565d3a6 commit 2d80d62
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
24 changes: 24 additions & 0 deletions plugin/src/main/java/hudson/plugins/findbugs/FindBugsPlugin.java
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;

import org.apache.commons.lang.StringUtils;
import org.xml.sax.SAXException;

/**
Expand All @@ -21,4 +22,27 @@ public void start() throws IOException, SAXException {
DetailFactory.addDetailBuilder(FindBugsResultAction.class, detailBuilder);
DetailFactory.addDetailBuilder(FindBugsMavenResultAction.class, detailBuilder);
}

/**
* Returns whether the specified maven findbugs plug-in uses a FindBugs
* release 2.0.0 or newer.
*
* @param version
* the maven version ID
* @return <code>true</code> if FindBugs 2.0.0 or newer is used
*/
public static boolean isFindBugs2x(final String version) {
try {
String[] versions = StringUtils.split(version, ".");
if (versions.length > 1) {
int major = Integer.parseInt(versions[0]);
int minor = Integer.parseInt(versions[1]);
return major > 2 || (major == 2 && minor >= 4);
}
}
catch (NumberFormatException exception) {
// ignore and return false
}
return false;
}
}
Expand Up @@ -182,21 +182,25 @@ protected MavenAggregatedReport createMavenAggregatedReport(final MavenBuild bui
/**
* Determines the filename of the FindBugs results.
*
* @param mojo the mojo containing the FindBugs configuration
* @param mojo
* the mojo containing the FindBugs configuration
* @return filename of the FindBugs results
*/
private String determineFileName(final MojoInfo mojo) {
String fileName = FINDBUGS_XML_FILE;
try {
if (FindBugsPlugin.isFindBugs2x(mojo.mojoExecution.getVersion())) {
return MAVEN_FINDBUGS_XML_FILE;
}

Boolean isNativeFormat = mojo.getConfigurationValue("findbugsXmlOutput", Boolean.class);
if (Boolean.FALSE.equals(isNativeFormat)) {
fileName = MAVEN_FINDBUGS_XML_FILE;
return MAVEN_FINDBUGS_XML_FILE;
}
}
catch (ComponentConfigurationException exception) {
// ignore and assume new format
}
return fileName;
return FINDBUGS_XML_FILE;
}

@Override
Expand Down
@@ -0,0 +1,34 @@
package hudson.plugins.findbugs;

import static org.junit.Assert.*;

import org.junit.Test;

/**
* Tests the class {@link FindBugsPlugin}.
*
* @author Ulli Hafner
*/
public class FindBugsPluginTest {
private static final String WRONG_MAVEN_DETECTION = "Wrong maven detection";

/**
* Verifies mapping of maven versions to FindBugs versions.
*/
@Test
public void testFindBugsVersion() {
assertTrue(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("2.4.0-SNAPSHOT"));
assertTrue(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("2.4.0"));
assertTrue(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("2.4.1"));
assertTrue(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("2.5"));
assertTrue(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("3.0.1"));
assertTrue(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("3.0"));

assertFalse(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("2.3.4"));
assertFalse(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("1.3.4"));

assertFalse(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("2"));
assertFalse(WRONG_MAVEN_DETECTION, FindBugsPlugin.isFindBugs2x("Nothing"));
}
}

0 comments on commit 2d80d62

Please sign in to comment.