Skip to content

Commit

Permalink
Workaround for apache#281
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Dec 21, 2020
1 parent 0d03956 commit a433df0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
4 changes: 4 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
<mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
<os.detected.name>${os.detected.name}</os.detected.name>
<os.detected.arch>${os.detected.arch}</os.detected.arch>
<mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo>
<surefire.version>${surefire.version}</surefire.version>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down Expand Up @@ -168,6 +170,8 @@
<mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
<os.detected.name>${os.detected.name}</os.detected.name>
<os.detected.arch>${os.detected.arch}</os.detected.arch>
<mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo>
<surefire.version>${surefire.version}</surefire.version>
</systemPropertyVariables>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.mvndaemon.mvnd.junit;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -191,8 +192,21 @@ public static MvndResource create(String className, String rawProjectDir, boolea
+ mvndHome);
}
final Path mvndPropertiesPath = testDir.resolve("mvnd.properties");

final Path localMavenRepository = deleteDir(testDir.resolve("local-maven-repo"));
final Path settingsPath = createSettings(testDir.resolve("settings.xml"));
String mrmRepoUrl = System.getProperty("mrm.repository.url");
if ("".equals(mrmRepoUrl)) {
mrmRepoUrl = null;
}
final Path settingsPath;
if (mrmRepoUrl == null) {
LOG.info("Building without mrm-maven-plugin");
settingsPath = null;
prefillLocalRepo(localMavenRepository);
} else {
LOG.info("Building with mrm-maven-plugin");
settingsPath = createSettings(testDir.resolve("settings.xml"), mrmRepoUrl);
}
final Path logback = Paths.get("src/test/resources/logback/logback.xml").toAbsolutePath();
final Path home = deleteDir(testDir.resolve("home"));
final TestParameters parameters = new TestParameters(
Expand All @@ -213,13 +227,28 @@ public static MvndResource create(String className, String rawProjectDir, boolea
return new MvndResource(parameters, registry, isNative, timeoutMs);
}

static Path createSettings(Path settingsPath) {
final String mrmRepoUrl = System.getProperty("mrm.repository.url");
if (mrmRepoUrl == null || mrmRepoUrl.isEmpty()) {
LOG.info("Building without mrm-maven-plugin");
return null;
}
LOG.info("Building with mrm-maven-plugin");
private static void prefillLocalRepo(final Path localMavenRepository) {
/* Workaround for https://github.com/mvndaemon/mvnd/issues/281 */
final String surefireVersion = System.getProperty("surefire.version");
final Path hostLocalMavenRepo = Paths.get(System.getProperty("mvnd.test.hostLocalMavenRepo"));
Stream.of(
"org/apache/maven/surefire/surefire-providers/" + surefireVersion + "/surefire-providers-"
+ surefireVersion + ".pom",
"org/apache/maven/surefire/surefire-providers/" + surefireVersion + "/surefire-providers-"
+ surefireVersion + ".pom.sha1")
.forEach(relPath -> {
final Path src = hostLocalMavenRepo.resolve(relPath);
final Path dest = localMavenRepository.resolve(relPath);
try {
Files.createDirectories(dest.getParent());
Files.copy(src, dest);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}

static Path createSettings(Path settingsPath, String mrmRepoUrl) {
final Path settingsTemplatePath = Paths.get("src/test/resources/settings-template.xml");
try {
final String template = Files.readString(settingsTemplatePath);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<mrm.version>1.2.0</mrm.version>
<surefire.version>3.0.0-M5</surefire.version>
<surefire.version>2.22.2</surefire.version>
<takari-lifecycle.version>1.13.9</takari-lifecycle.version>
<takari-provisio.version>1.0.15</takari-provisio.version>

Expand Down

0 comments on commit a433df0

Please sign in to comment.