Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[FIXED JENKINS-2657] Let maven modules take precedence over ant modules.
  • Loading branch information
uhafner committed Aug 30, 2011
1 parent 20aa7ed commit 0077608e2333ba247dfdcb34917673c470529b12
@@ -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
@@ -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)) {
@@ -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;
}
@@ -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
@@ -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");
@@ -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");
}

@@ -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.