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

Maven ITs use maven-executor #1940

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d60ff92
Maven ITs use maven-executor
cstamas Nov 27, 2024
3ac1f83
Undo this change, is move to other PR
cstamas Nov 28, 2024
1140a87
WIP
cstamas Nov 28, 2024
199f404
Merge remote-tracking branch 'upstream/master' into it-maven-executir
cstamas Nov 28, 2024
c79b98d
WIP
cstamas Nov 28, 2024
1c2c3fc
WIP
cstamas Nov 28, 2024
d92d7d8
Hack out rogue AnsiConsole
cstamas Nov 28, 2024
3230486
WIP
cstamas Nov 28, 2024
e839ef2
Fix UT
cstamas Nov 28, 2024
548e1d3
Undo rename, causes huge PR
cstamas Nov 28, 2024
f668773
Hack when needed only
cstamas Nov 28, 2024
d84b8e1
Log full request
cstamas Nov 28, 2024
6cc20de
Logging was missed
cstamas Nov 28, 2024
743aa38
Add diag dump in case of failure
cstamas Nov 29, 2024
7a07b49
Fix
cstamas Nov 29, 2024
fe4c27b
More fixes
cstamas Nov 29, 2024
c52f027
Return to AUTO and fix stupid mistake
cstamas Nov 29, 2024
3ac45f2
Ability to cache context
cstamas Nov 29, 2024
033c824
Small fixes
cstamas Nov 29, 2024
31ee7ff
Push all the logic to single place
cstamas Nov 29, 2024
d25fbc0
Merge remote-tracking branch 'upstream/master' into it-maven-executir
cstamas Nov 30, 2024
9a03eed
Reformat
cstamas Nov 30, 2024
485f68f
Return caching
cstamas Nov 30, 2024
858be1b
Simplify
cstamas Nov 30, 2024
82fd978
Merge remote-tracking branch 'upstream/master' into it-maven-executir
cstamas Dec 2, 2024
d32840b
Embedded executor should dispose runtime added realms
cstamas Dec 2, 2024
f403b14
Fix embedded CWD
cstamas Dec 2, 2024
1203013
Cleanup
cstamas Dec 2, 2024
eb76a1e
Update gh CI and drop unsupported stuff
cstamas Dec 2, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- 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-beta-4"
run: mvn --errors --batch-mode --show-version org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper "-Dmaven=4.0.0-rc-1"

- name: Build Maven distributions
shell: bash
Expand Down
7 changes: 6 additions & 1 deletion impl/maven-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ under the License.

<properties>
<maven3version>3.9.9</maven3version>
<maven4version>4.0.0-beta-5</maven4version>
<maven4version>4.0.0-rc-1</maven4version>
</properties>

<dependencies>
Expand All @@ -50,6 +50,11 @@ under the License.
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
package org.apache.maven.api.cli;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.maven.api.annotations.Experimental;
Expand All @@ -43,6 +46,11 @@
@Immutable
@Experimental
public interface ExecutorRequest {
/**
* The Maven command.
*/
String MVN = "mvn";

/**
* The command to execute, ie "mvn".
*/
Expand Down Expand Up @@ -82,16 +90,51 @@ public interface ExecutorRequest {
@Nonnull
Path userHomeDirectory();

/**
* Returns the map of Java System Properties to set before executing process.
*
* @return an Optional containing the map of Java System Properties, or empty if not specified
*/
@Nonnull
Optional<Map<String, String>> jvmSystemProperties();

/**
* Returns the map of environment variables to set before executing process.
* This property is used ONLY by executors that spawn a new JVM.
*
* @return an Optional containing the map of environment variables, or empty if not specified
*/
@Nonnull
Optional<Map<String, String>> environmentVariables();

/**
* Returns the list of extra JVM arguments to be passed to the forked process.
* These arguments allow for customization of the JVM environment in which tool will run.
* This property is used ONLY by executors and invokers that spawn a new JVM.
* This property is used ONLY by executors that spawn a new JVM.
*
* @return an Optional containing the list of extra JVM arguments, or empty if not specified
*/
@Nonnull
Optional<List<String>> jvmArguments();

/**
* Optional consumer for STD out of the Maven. If given, this consumer will get all output from the std out of
* Maven. Note: whether consumer gets to consume anything depends on invocation arguments passed in
* {@link #arguments()}, as if log file is set, not much will go to stdout.
*
* @return an Optional containing the stdout consumer, or empty if not specified.
*/
Optional<OutputStream> stdoutConsumer();

/**
* Optional consumer for STD err of the Maven. If given, this consumer will get all output from the std err of
* Maven. Note: whether consumer gets to consume anything depends on invocation arguments passed in
* {@link #arguments()}, as if log file is set, not much will go to stderr.
*
* @return an Optional containing the stderr consumer, or empty if not specified.
*/
Optional<OutputStream> stderrConsumer();

/**
* Returns {@link Builder} for this instance.
*/
Expand All @@ -103,15 +146,11 @@ default Builder toBuilder() {
cwd(),
installationDirectory(),
userHomeDirectory(),
jvmArguments().orElse(null));
}

/**
* Returns new empty builder.
*/
@Nonnull
static Builder empyBuilder() {
return new Builder();
jvmSystemProperties().orElse(null),
environmentVariables().orElse(null),
jvmArguments().orElse(null),
stdoutConsumer().orElse(null),
stderrConsumer().orElse(null));
}

/**
Expand All @@ -120,11 +159,15 @@ static Builder empyBuilder() {
@Nonnull
static Builder mavenBuilder(@Nullable Path installationDirectory) {
return new Builder(
"mvn",
MVN,
null,
getCanonicalPath(Paths.get(System.getProperty("user.dir"))),
installationDirectory != null ? getCanonicalPath(installationDirectory) : discoverMavenHome(),
getCanonicalPath(Paths.get(System.getProperty("user.home"))),
null,
null,
null,
null,
null);
}

Expand All @@ -134,23 +177,36 @@ class Builder {
private Path cwd;
private Path installationDirectory;
private Path userHomeDirectory;
private Map<String, String> jvmSystemProperties;
private Map<String, String> environmentVariables;
private List<String> jvmArguments;
private OutputStream stdoutConsumer;
private OutputStream stderrConsumer;

private Builder() {}

@SuppressWarnings("ParameterNumber")
private Builder(
String command,
List<String> arguments,
Path cwd,
Path installationDirectory,
Path userHomeDirectory,
List<String> jvmArguments) {
Map<String, String> jvmSystemProperties,
Map<String, String> environmentVariables,
List<String> jvmArguments,
OutputStream stdoutConsumer,
OutputStream stderrConsumer) {
this.command = command;
this.arguments = arguments;
this.cwd = cwd;
this.installationDirectory = installationDirectory;
this.userHomeDirectory = userHomeDirectory;
this.jvmSystemProperties = jvmSystemProperties;
this.environmentVariables = environmentVariables;
this.jvmArguments = jvmArguments;
this.stdoutConsumer = stdoutConsumer;
this.stderrConsumer = stderrConsumer;
}

@Nonnull
Expand Down Expand Up @@ -192,6 +248,40 @@ public Builder userHomeDirectory(Path userHomeDirectory) {
return this;
}

@Nonnull
public Builder jvmSystemProperties(Map<String, String> jvmSystemProperties) {
this.jvmSystemProperties = jvmSystemProperties;
return this;
}

@Nonnull
public Builder jvmSystemProperty(String key, String value) {
requireNonNull(key, "env key");
requireNonNull(value, "env value");
if (jvmSystemProperties == null) {
this.jvmSystemProperties = new HashMap<>();
}
this.jvmSystemProperties.put(key, value);
return this;
}

@Nonnull
public Builder environmentVariables(Map<String, String> environmentVariables) {
this.environmentVariables = environmentVariables;
return this;
}

@Nonnull
public Builder environmentVariable(String key, String value) {
requireNonNull(key, "env key");
requireNonNull(value, "env value");
if (environmentVariables == null) {
this.environmentVariables = new HashMap<>();
}
this.environmentVariables.put(key, value);
return this;
}

@Nonnull
public Builder jvmArguments(List<String> jvmArguments) {
this.jvmArguments = jvmArguments;
Expand All @@ -207,9 +297,31 @@ public Builder jvmArgument(String jvmArgument) {
return this;
}

@Nonnull
public Builder stdoutConsumer(OutputStream stdoutConsumer) {
this.stdoutConsumer = stdoutConsumer;
return this;
}

@Nonnull
public Builder stderrConsumer(OutputStream stderrConsumer) {
this.stderrConsumer = stderrConsumer;
return this;
}

@Nonnull
public ExecutorRequest build() {
return new Impl(command, arguments, cwd, installationDirectory, userHomeDirectory, jvmArguments);
return new Impl(
command,
arguments,
cwd,
installationDirectory,
userHomeDirectory,
jvmSystemProperties,
environmentVariables,
jvmArguments,
stdoutConsumer,
stderrConsumer);
}

private static class Impl implements ExecutorRequest {
Expand All @@ -218,21 +330,34 @@ private static class Impl implements ExecutorRequest {
private final Path cwd;
private final Path installationDirectory;
private final Path userHomeDirectory;
private final Map<String, String> jvmSystemProperties;
private final Map<String, String> environmentVariables;
private final List<String> jvmArguments;
private final OutputStream stdoutConsumer;
private final OutputStream stderrConsumer;

@SuppressWarnings("ParameterNumber")
private Impl(
String command,
List<String> arguments,
Path cwd,
Path installationDirectory,
Path userHomeDirectory,
List<String> jvmArguments) {
Map<String, String> jvmSystemProperties,
Map<String, String> environmentVariables,
List<String> jvmArguments,
OutputStream stdoutConsumer,
OutputStream stderrConsumer) {
this.command = requireNonNull(command);
this.arguments = arguments == null ? List.of() : List.copyOf(arguments);
this.cwd = requireNonNull(cwd);
this.installationDirectory = requireNonNull(installationDirectory);
this.userHomeDirectory = requireNonNull(userHomeDirectory);
this.jvmSystemProperties = jvmSystemProperties != null ? Map.copyOf(jvmSystemProperties) : null;
this.environmentVariables = environmentVariables != null ? Map.copyOf(environmentVariables) : null;
this.jvmArguments = jvmArguments != null ? List.copyOf(jvmArguments) : null;
this.stdoutConsumer = stdoutConsumer;
this.stderrConsumer = stderrConsumer;
}

@Override
Expand Down Expand Up @@ -260,20 +385,44 @@ public Path userHomeDirectory() {
return userHomeDirectory;
}

@Override
public Optional<Map<String, String>> jvmSystemProperties() {
return Optional.ofNullable(jvmSystemProperties);
}

@Override
public Optional<Map<String, String>> environmentVariables() {
return Optional.ofNullable(environmentVariables);
}

@Override
public Optional<List<String>> jvmArguments() {
return Optional.ofNullable(jvmArguments);
}

@Override
public Optional<OutputStream> stdoutConsumer() {
return Optional.ofNullable(stdoutConsumer);
}

@Override
public Optional<OutputStream> stderrConsumer() {
return Optional.ofNullable(stderrConsumer);
}

@Override
public String toString() {
return "ExecutionRequest{" + "command='"
return "Impl{" + "command='"
+ command + '\'' + ", arguments="
+ arguments + ", cwd="
+ cwd + ", installationDirectory="
+ installationDirectory + ", userHomeDirectory="
+ userHomeDirectory + ", jvmArguments="
+ jvmArguments + '}';
+ userHomeDirectory + ", jvmSystemProperties="
+ jvmSystemProperties + ", environmentVariables="
+ environmentVariables + ", jvmArguments="
+ jvmArguments + ", stdoutConsumer="
+ stdoutConsumer + ", stderrConsumer="
+ stderrConsumer + '}';
}
}
}
Expand Down
Loading
Loading