Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENT] Make CI use split repo #2030

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ on:
pull_request:
branches: [ master ]

env:
MAVEN_ARGS: '-Daether.lrm.enhanced.split=true -Daether.lrm.enhanced.splitRemoteRepository=true'

# clear all permissions for GITHUB_TOKEN
permissions: {}

Expand All @@ -44,19 +47,19 @@ jobs:
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository/cached
key: maven-${{ runner.os }}-initial-${{ hashFiles('**/pom.xml') }}
path: ~/.m2/repository/cached/central
key: maven-cached-central-${{ hashFiles('**/pom.xml') }}-${{ github.sha }}
restore-keys: |
maven-${{ runner.os }}-initial-
maven-${{ runner.os }}-
maven-cached-central-${{ hashFiles('**/pom.xml') }}-
maven-cached-central-

- name: Set up Maven
shell: bash
run: mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=4.0.0-rc-1"
run: mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=4.0.0-rc-2"

- name: Build Maven distributions
shell: bash
run: ./mvnw verify -e -B -V -Dmaven.repo.local=$HOME/.m2/repository/cached
run: ./mvnw verify -e -B -V

- name: List contents of target directory
shell: bash
Expand Down Expand Up @@ -132,19 +135,19 @@ jobs:
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository/cached
key: maven-${{ runner.os }}-full-${{ hashFiles('**/pom.xml') }}
path: ~/.m2/repository/cached/central
key: maven-cached-central-${{ hashFiles('**/pom.xml') }}-${{ github.sha }}
restore-keys: |
maven-${{ runner.os }}-full-
maven-${{ runner.os }}-
maven-cached-central-${{ hashFiles('**/pom.xml') }}-
maven-cached-central-

- name: Build with downloaded Maven
shell: bash
run: mvn verify -e -B -V -Dmaven.repo.local=$HOME/.m2/repository/cached
run: mvn verify -e -B -V

- name: Build site with downloaded Maven
shell: bash
run: mvn site -e -B -V -Preporting -Dmaven.repo.local=$HOME/.m2/repository/cached
run: mvn site -e -B -V -Preporting

integration-tests:
needs: initial-build
Expand Down Expand Up @@ -196,22 +199,22 @@ jobs:
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository/cached
key: maven-${{ runner.os }}-its-${{ hashFiles('**/pom.xml') }}
path: ~/.m2/repository/cached/central
key: maven-cached-central-${{ hashFiles('**/pom.xml') }}-${{ github.sha }}
restore-keys: |
maven-${{ runner.os }}-its
maven-${{ runner.os }}-
maven-cached-central-${{ hashFiles('**/pom.xml') }}-
maven-cached-central-

# we use two steps so that we can cache artifacts downloaded from Maven Central repository
# without installing any local artifacts to not pollute the cache
- name: Build maven and ITs
shell: bash
run: mvn package -DskipTests -e -B -V -Prun-its -Dmaven.repo.local=$HOME/.m2/repository/cached
run: mvn package -DskipTests -e -B -V -Prun-its

# Now run tests and ITs using a separate local repo (using the previous filled repo as tail)
- name: Run integration tests
shell: bash
run: mvn install -e -B -V -Prun-its -Dmaven.repo.local=$HOME/.m2/repository/local -Dmaven.repo.local.tail=$HOME/.m2/repository/cached
run: mvn install -e -B -V -Prun-its

- name: Upload test artifacts
uses: actions/upload-artifact@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -108,6 +109,7 @@ public int hashCode() {
}

protected final boolean cacheContexts;
protected final boolean useMavenArgsEnv;
protected final AtomicBoolean closed;
protected final PrintStream originalStdout;
protected final PrintStream originalStderr;
Expand All @@ -116,11 +118,12 @@ public int hashCode() {
protected final ConcurrentHashMap<Key, Context> contexts;

public EmbeddedMavenExecutor() {
this(true);
this(true, true);
}

public EmbeddedMavenExecutor(boolean cacheContexts) {
public EmbeddedMavenExecutor(boolean cacheContexts, boolean useMavenArgsEnv) {
this.cacheContexts = cacheContexts;
this.useMavenArgsEnv = useMavenArgsEnv;
this.closed = new AtomicBoolean(false);
this.originalStdout = System.out;
this.originalStderr = System.err;
Expand Down Expand Up @@ -223,6 +226,14 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) {
"Installation directory does not point to Maven installation: " + mavenHome);
}

ArrayList<String> mavenArgs = new ArrayList<>();
String mavenArgsEnv = System.getenv("MAVEN_ARGS");
if (useMavenArgsEnv && mavenArgsEnv != null && !mavenArgsEnv.isEmpty()) {
Arrays.stream(mavenArgsEnv.split(" "))
.filter(s -> !s.trim().isEmpty())
.forEach(s -> mavenArgs.add(0, s));
}

Properties properties = prepareProperties(executorRequest);

System.setProperties(properties);
Expand Down Expand Up @@ -264,8 +275,10 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) {
exec = r -> {
System.setProperties(prepareProperties(r));
try {
ArrayList<String> args = new ArrayList<>(mavenArgs);
args.addAll(r.arguments());
return (int) doMain.invoke(mavenCli, new Object[] {
r.arguments().toArray(new String[0]), r.cwd().toString(), null, null
args.toArray(new String[0]), r.cwd().toString(), null, null
});
} catch (Exception e) {
throw new ExecutorException("Failed to execute", e);
Expand All @@ -285,7 +298,9 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) {
|| r.stderrConsumer().isPresent()) {
ansiConsoleInstalled.set(null, 1);
}
return (int) mainMethod.invoke(null, r.arguments().toArray(new String[0]), classWorld);
ArrayList<String> args = new ArrayList<>(mavenArgs);
args.addAll(r.arguments());
return (int) mainMethod.invoke(null, args.toArray(new String[0]), classWorld);
} finally {
if (r.stdoutConsumer().isPresent()
|| r.stderrConsumer().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ void artifactPath3(ExecutorHelper.Mode mode) {
EMBEDDED_MAVEN_EXECUTOR,
FORKED_MAVEN_EXECUTOR);
String path = helper.artifactPath(helper.executorRequest(), "aopalliance:aopalliance:1.0", "central");
assertEquals(
"aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator
+ "aopalliance-1.0.jar",
path);
// split repository: assert "ends with" as split may introduce prefixes
assertTrue(
path.endsWith("aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator
+ "aopalliance-1.0.jar"),
"path=" + path);
}

@ParameterizedTest
Expand All @@ -148,10 +149,11 @@ void artifactPath4(ExecutorHelper.Mode mode) {
EMBEDDED_MAVEN_EXECUTOR,
FORKED_MAVEN_EXECUTOR);
String path = helper.artifactPath(helper.executorRequest(), "aopalliance:aopalliance:1.0", "central");
assertEquals(
"aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator
+ "aopalliance-1.0.jar",
path);
// split repository: assert "ends with" as split may introduce prefixes
assertTrue(
path.endsWith("aopalliance" + File.separator + "aopalliance" + File.separator + "1.0" + File.separator
+ "aopalliance-1.0.jar"),
"path=" + path);
}

@ParameterizedTest
Expand All @@ -164,7 +166,8 @@ void metadataPath3(ExecutorHelper.Mode mode) {
EMBEDDED_MAVEN_EXECUTOR,
FORKED_MAVEN_EXECUTOR);
String path = helper.metadataPath(helper.executorRequest(), "aopalliance", "someremote");
assertEquals("aopalliance" + File.separator + "maven-metadata-someremote.xml", path);
// split repository: assert "ends with" as split may introduce prefixes
assertTrue(path.endsWith("aopalliance" + File.separator + "maven-metadata-someremote.xml"), "path=" + path);
}

@ParameterizedTest
Expand All @@ -177,6 +180,7 @@ void metadataPath4(ExecutorHelper.Mode mode) {
EMBEDDED_MAVEN_EXECUTOR,
FORKED_MAVEN_EXECUTOR);
String path = helper.metadataPath(helper.executorRequest(), "aopalliance", "someremote");
assertEquals("aopalliance" + File.separator + "maven-metadata-someremote.xml", path);
// split repository: assert "ends with" as split may introduce prefixes
assertTrue(path.endsWith("aopalliance" + File.separator + "maven-metadata-someremote.xml"), "path=" + path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testit0008() throws Exception {
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifact("org.apache.maven.its.plugins", "maven-it-plugin-touch", "1.0", "maven-plugin");
verifier.deleteArtifact("org.apache.maven.its.plugins", "maven-it-plugin-touch", "1.0", "maven-plugin", null);
verifier.addCliArgument("process-sources");
verifier.execute();
verifier.verifyFilePresent("target/touch.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ public void testit0010() throws Exception {
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.it0010");
verifier.deleteArtifacts("org.apache.maven.its.it0010", "maven-core-it");
verifier.filterFile("settings-template.xml", "settings.xml");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();

verifier.verifyArtifactPresent("org.apache.maven.its.it0010", "a", "0.1", "jar");
verifier.verifyArtifactPresent("org.apache.maven.its.it0010", "b", "0.2", "jar");
verifier.verifyArtifactPresent("org.apache.maven.its.it0010", "parent", "1.0", "pom");
verifier.verifyArtifactPresent("org.apache.maven.its.it0010", "a", "0.1", "jar", "maven-core-it");
verifier.verifyArtifactPresent("org.apache.maven.its.it0010", "b", "0.2", "jar", "maven-core-it");
verifier.verifyArtifactPresent("org.apache.maven.its.it0010", "parent", "1.0", "pom", "maven-core-it");

List<String> artifacts = verifier.loadLines("target/compile.txt");
assertTrue(artifacts.contains("org.apache.maven.its.it0010:a:jar:0.1"), artifacts.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testit0011() throws Exception {
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.it0011");
verifier.deleteArtifacts("org.apache.maven.its.it0011", "maven-core-it");
verifier.filterFile("settings-template.xml", "settings.xml");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public void testit0018() throws Exception {
File testDir = extractResources("/it0018");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteArtifacts("org.apache.maven.its.it0018");
verifier.deleteArtifacts("org.apache.maven.its.it0018", "maven-core-it");
verifier.filterFile("settings-template.xml", "settings.xml");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument(
"org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile");
verifier.execute();
verifier.verifyArtifactPresent("org.apache.maven.its.it0018", "managed-dep", "1.0.3", "jar");
verifier.verifyArtifactPresent("org.apache.maven.its.it0018", "managed-dep", "1.0.3", "jar", "maven-core-it");
verifier.verifyErrorFreeLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testit0021() throws Exception {

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteArtifacts("org.apache.maven.its.it0021");
verifier.deleteArtifacts("org.apache.maven.its.it0021", "maven-core-it");
verifier.getSystemProperties().setProperty("includeProfile", "true");
verifier.filterFile("settings-template.xml", "settings.xml");
verifier.addCliArgument("--settings");
Expand All @@ -49,7 +49,7 @@ public void testit0021() throws Exception {
verifier.execute();
verifier.verifyErrorFreeLog();

verifier.verifyArtifactPresent("org.apache.maven.its.it0021", "a", "0.1", "jar");
verifier.verifyArtifactPresent("org.apache.maven.its.it0021", "b", "0.1", "jar");
verifier.verifyArtifactPresent("org.apache.maven.its.it0021", "a", "0.1", "jar", "maven-core-it");
verifier.verifyArtifactPresent("org.apache.maven.its.it0021", "b", "0.1", "jar", "maven-core-it");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public MavenIT0030DepPomDepMgmtInheritanceTest() {
public void testit0030() throws Exception {
File testDir = extractResources("/it0030");
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030", "1.0-SNAPSHOT", "jar");
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030-child-hierarchy", "1.0-SNAPSHOT", "jar");
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030-child-project1", "1.0-SNAPSHOT", "jar");
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030-child-project2", "1.0-SNAPSHOT", "jar");
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030", "1.0-SNAPSHOT", "jar", null);
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030-child-hierarchy", "1.0-SNAPSHOT", "jar", null);
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030-child-project1", "1.0-SNAPSHOT", "jar", null);
verifier.deleteArtifact("org.apache.maven.it", "maven-it-it0030-child-project2", "1.0-SNAPSHOT", "jar", null);
verifier.addCliArgument("install");
verifier.execute();
verifier.verifyFilePresent("child-hierarchy/project2/target/classes/org/apache/maven/it0001/Person.class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public void testit0041() throws Exception {

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteArtifacts("org.apache.maven", "maven-core-it-support", "1.2");
verifier.deleteArtifacts("org.apache.maven", "maven-core-it-support", "1.2", "central");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();

verifier.verifyArtifactPresent("org.apache.maven", "maven-core-it-support", "1.2", "coreit-artifact");
verifier.verifyArtifactPresent("org.apache.maven", "maven-core-it-support", "1.2", "pom");
verifier.verifyArtifactPresent(
"org.apache.maven", "maven-core-it-support", "1.2", "coreit-artifact", "central");
verifier.verifyArtifactPresent("org.apache.maven", "maven-core-it-support", "1.2", "pom", "central");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testit0085() throws Exception {
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.it0085");
verifier.deleteArtifacts("org.apache.maven.its.it0085", "maven-core-it");
verifier.getSystemProperties().setProperty("test.home", testDir.getAbsolutePath());
verifier.filterFile("settings-template.xml", "settings.xml");
verifier.addCliArgument("--settings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testit0087() throws Exception {
Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.setAutoclean(false);
verifier.deleteDirectory("target");
verifier.deleteArtifacts("org.apache.maven.its.it0087");
verifier.deleteArtifacts("org.apache.maven.its.it0087", "maven-core-it");
verifier.filterFile("settings-template.xml", "settings.xml");
verifier.addCliArgument("--settings");
verifier.addCliArgument("settings.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected void setUp() throws Exception {
artifact.getParentFile().mkdirs();
Files.writeString(artifact.getAbsoluteFile().toPath(), "originalArtifact");

verifier.verifyArtifactNotPresent("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar");
verifier.verifyArtifactNotPresent(
"org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar", "it.snapshots");
}

@Test
Expand Down Expand Up @@ -207,19 +208,22 @@ private File getMetadataFile(String groupId, String artifactId, String version)
}

private void verifyArtifactContent(String s) throws IOException, VerificationException {
verifier.verifyArtifactPresent("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar");
verifier.verifyArtifactContent("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar", s);
verifier.verifyArtifactPresent(
"org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar", "it.snapshots");
verifier.verifyArtifactContent(
"org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar", "it.snapshots", s);
}

private static File deleteLocalArtifact(Verifier verifier, File localRepoFile) throws IOException {
verifier.deleteArtifact("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar");
verifier.deleteArtifact("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar", "it.snapshots");
// this is to delete metadata - TODO: incorporate into deleteArtifact in verifier
FileUtils.deleteDirectory(localRepoFile.getParentFile());
return localRepoFile;
}

private static File getLocalRepoFile(Verifier verifier) {
return new File(verifier.getArtifactPath("org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar"));
return new File(verifier.getArtifactPath(
"org.apache.maven", "maven-core-it-support", "1.0-SNAPSHOT", "jar", "it.snapshots"));
}

private static void recreateRemoteRepository(File repository) throws IOException {
Expand Down
Loading
Loading