Navigation Menu

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

Commit

Permalink
[FIXED JENKINS-2657] Let maven modules take precedence over ant modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 30, 2011
1 parent 20aa7ed commit 0077608
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .settings/org.eclipse.core.resources.prefs
@@ -1,6 +1,6 @@
#Thu Jul 14 15:03:14 CEST 2011
#Mon Aug 29 16:17:48 CEST 2011
eclipse.preferences.version=1
encoding//src/main/java=ISO-8859-1
encoding//src/main/resources=ISO-8859-1
encoding//src/test/java=ISO-8859-1
encoding//src/test/resources=ISO-8859-1
encoding/<project>=ISO-8859-1
15 changes: 11 additions & 4 deletions src/main/java/hudson/plugins/analysis/util/ModuleDetector.java
Expand Up @@ -96,13 +96,15 @@ private Map<String, String> createFilesToModuleMapping(final File workspace) {
Map<String, String> mapping = new HashMap<String, String>();

String[] projects = find(workspace);
for (String fileName : projects) {
if (fileName.endsWith(ANT_PROJECT)) {
addMapping(mapping, fileName, ANT_PROJECT, parseBuildXml(fileName));
}
}
for (String fileName : projects) {
if (fileName.endsWith(MAVEN_POM)) {
addMapping(mapping, fileName, MAVEN_POM, parsePom(fileName));
}
else if (fileName.endsWith(ANT_PROJECT)) {
addMapping(mapping, fileName, ANT_PROJECT, parseBuildXml(fileName));
}
}
for (String fileName : projects) {
if (fileName.endsWith(OSGI_BUNDLE)) {
Expand Down Expand Up @@ -156,6 +158,9 @@ private String[] find(final File path) {
String absoluteName = absolutePath + SLASH + relativeFileNames[file];
absoluteFileNames[file] = absoluteName.replace(BACK_SLASH, SLASH);
}
else {
absoluteFileNames[file] = relativeFileNames[file];
}
}
return absoluteFileNames;
}
Expand Down Expand Up @@ -280,7 +285,9 @@ private void readProperties(final String path, final Properties properties, fina
InputStream file = null;
try {
file = factory.create(path + SLASH + fileName);
properties.load(file);
if (file != null) {
properties.load(file);
}
}
catch (IOException exception) {
// ignore if properties are not present or not readable
Expand Down
70 changes: 67 additions & 3 deletions src/test/java/hudson/plugins/analysis/util/ModuleDetectorTest.java
Expand Up @@ -18,6 +18,7 @@
*/
@SuppressWarnings("DMI")
public class ModuleDetectorTest {
private static final String EXPECTED_OSGI_MODULE = "de.faktorlogik.prototyp";
private static final String MANIFEST = "MANIFEST.MF";
private static final String MANIFEST_NAME = "MANIFEST-NAME.MF";
private static final File ROOT = new File("/tmp");
Expand Down Expand Up @@ -61,9 +62,8 @@ public void testOsgiModules() throws FileNotFoundException {
ModuleDetector detector = createDetectorUnderTest(MANIFEST,
new String[] {PATH_PREFIX_OSGI + ModuleDetector.OSGI_BUNDLE});

String expectedName = "de.faktorlogik.prototyp";
verifyModuleName(detector, expectedName, PATH_PREFIX_OSGI + "/something.txt");
verifyModuleName(detector, expectedName, PATH_PREFIX_OSGI + "/in/between/something.txt");
verifyModuleName(detector, EXPECTED_OSGI_MODULE, PATH_PREFIX_OSGI + "/something.txt");
verifyModuleName(detector, EXPECTED_OSGI_MODULE, PATH_PREFIX_OSGI + "/in/between/something.txt");
verifyModuleName(detector, StringUtils.EMPTY, "/path/to/something.txt");
}

Expand Down Expand Up @@ -182,4 +182,68 @@ public void testMoreEntries() throws FileNotFoundException {
verifyModuleName(detector, EXPECTED_ANT_MODULE, PATH_PREFIX_ANT + "/something.txt");
verifyModuleName(detector, EXPECTED_MAVEN_MODULE, PATH_PREFIX_MAVEN + "/something.txt");
}

/**
* Checks whether maven has precedence over ant.
*
* @throws FileNotFoundException
* should never happen
*/
@Test
public void testMavenHasPrecedenceOverAnt() throws FileNotFoundException {
String prefix = "/prefix/";
String ant = prefix + ModuleDetector.ANT_PROJECT;
String maven = prefix + ModuleDetector.MAVEN_POM;

verifyOrder(prefix, ant, maven, new String[] {ant, maven});
verifyOrder(prefix, ant, maven, new String[] {maven, ant});
}

private void verifyOrder(final String prefix, final String ant, final String maven, final String[] foundFiles)
throws FileNotFoundException {
FileInputStreamFactory factory = mock(FileInputStreamFactory.class);
when(factory.create(ant)).thenReturn(read(ModuleDetector.ANT_PROJECT));
when(factory.create(maven)).thenReturn(read(ModuleDetector.MAVEN_POM));

when(factory.find((File)anyObject(), anyString())).thenReturn(foundFiles);
ModuleDetector detector = createDetectorUnderTest(factory);

assertEquals("Wrong module guessed", EXPECTED_MAVEN_MODULE,
detector.guessModuleName(prefix + "/something.txt"));
}

/**
* Checks whether OSGi has precedence over maven and ant.
*
* @throws FileNotFoundException
* should never happen
*/
@Test
public void testOsgiHasPrecedenceOvermavenAndAnt() throws FileNotFoundException {
String prefix = "/prefix/";
String ant = prefix + ModuleDetector.ANT_PROJECT;
String maven = prefix + ModuleDetector.MAVEN_POM;
String osgi = prefix + ModuleDetector.OSGI_BUNDLE;

verifyOrder(prefix, ant, maven, osgi, new String[] {ant, maven, osgi});
verifyOrder(prefix, ant, maven, osgi, new String[] {ant, osgi, maven});
verifyOrder(prefix, ant, maven, osgi, new String[] {maven, ant, osgi});
verifyOrder(prefix, ant, maven, osgi, new String[] {maven, osgi, ant});
verifyOrder(prefix, ant, maven, osgi, new String[] {osgi, ant, maven});
verifyOrder(prefix, ant, maven, osgi, new String[] {osgi, maven, osgi});
}

private void verifyOrder(final String prefix, final String ant, final String maven, final String osgi, final String[] foundFiles)
throws FileNotFoundException {
FileInputStreamFactory factory = mock(FileInputStreamFactory.class);
when(factory.create(ant)).thenReturn(read(ModuleDetector.ANT_PROJECT));
when(factory.create(maven)).thenReturn(read(ModuleDetector.MAVEN_POM));
when(factory.create(osgi)).thenReturn(read(MANIFEST));

when(factory.find((File)anyObject(), anyString())).thenReturn(foundFiles);
ModuleDetector detector = createDetectorUnderTest(factory);

assertEquals("Wrong module guessed", EXPECTED_OSGI_MODULE,
detector.guessModuleName(prefix + "/something.txt"));
}
}

0 comments on commit 0077608

Please sign in to comment.