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

Upgrade to Maven 4.0.0-beta-1 #974

Merged
merged 4 commits into from
May 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion build/publish-on-sdkman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ RESPONSE="$(curl -s -X PUT \
-H "Consumer-Token: ${SDKMAN_CONSUMER_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"candidate": "mvnd", "version": "'${VERSION}-m39'"}' \
-d '{"candidate": "mvnd", "version": "'${VERSION}'"}' \
https://vendors.sdkman.io/default)"

node -pe "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.internal.CLibrary;
import org.jline.terminal.spi.SystemStream;
import org.jline.terminal.spi.TerminalExt;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
import org.mvndaemon.mvnd.common.DaemonException;
import org.mvndaemon.mvnd.common.DaemonInfo;
Expand All @@ -57,11 +58,10 @@
import org.mvndaemon.mvnd.common.TimeUtils;
import org.mvndaemon.mvnd.common.logging.ClientOutput;
import org.mvndaemon.mvnd.common.logging.TerminalOutput;
import org.mvndaemon.mvnd.logging.slf4j.MvndLoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.slf4j.impl.MvndLoggerFactory;
import org.slf4j.impl.StaticLoggerBinder;

import static org.mvndaemon.mvnd.client.DaemonParameters.LOG_EXTENSION;

Expand Down Expand Up @@ -94,19 +94,6 @@ public static void main(String[] argv) throws Exception {
final boolean batchMode = Environment.MAVEN_BATCH_MODE.hasCommandLineOption(args)
|| Environment.COMPLETION.hasCommandLineOption(args);

// Color
Color styleColor =
Color.of(Environment.MAVEN_COLOR.removeCommandLineOption(args)).orElse(Color.auto);
if (styleColor == Color.auto) {
/* Translate from auto to either always or never */
/* stdout is not a terminal e.g. when stdout is redirected to a file */
final boolean stdoutIsTerminal = CLibrary.isatty(1) != 0;
styleColor = (batchMode || logFile != null || !stdoutIsTerminal) ? Color.never : Color.always;
}
/* We cannot use Environment.addCommandLineOption() because that one would pass --color to the daemon
* and --color is not supported there yet. */
args.add("-D" + Environment.MAVEN_COLOR.getProperty() + "=" + styleColor.name());

String userJdkJavaOpts = System.getenv(Environment.JDK_JAVA_OPTIONS.getEnvironmentVariable());
if (userJdkJavaOpts != null) {
Environment.JDK_JAVA_OPTIONS.addCommandLineOption(args, userJdkJavaOpts);
Expand All @@ -115,8 +102,8 @@ public static void main(String[] argv) throws Exception {
// System properties
setSystemPropertiesFromCommandLine(args);

if (StaticLoggerBinder.getSingleton().getLoggerFactory() instanceof MvndLoggerFactory) {
((MvndLoggerFactory) StaticLoggerBinder.getSingleton().getLoggerFactory()).reconfigure();
if (LoggerFactory.getILoggerFactory() instanceof MvndLoggerFactory) {
((MvndLoggerFactory) LoggerFactory.getILoggerFactory()).reconfigure();
}

DaemonParameters parameters = new DaemonParameters();
Expand Down Expand Up @@ -158,6 +145,21 @@ public static void main(String[] argv) throws Exception {
boolean noBuffering = batchMode || parameters.noBuffering();
try (TerminalOutput output = new TerminalOutput(noBuffering, parameters.rollingWindowSize(), logFile)) {
try {
// Color
// We need to defer this part until the terminal is created
Color styleColor = Color.of(Environment.MAVEN_COLOR.removeCommandLineOption(args))
.orElse(Color.auto);
if (styleColor == Color.auto) {
/* Translate from auto to either always or never */
/* stdout is not a terminal e.g. when stdout is redirected to a file */
final boolean stdoutIsTerminal =
((TerminalExt) output.getTerminal()).getProvider().isSystemStream(SystemStream.Output);
styleColor = (batchMode || logFile != null || !stdoutIsTerminal) ? Color.never : Color.always;
}
/* We cannot use Environment.addCommandLineOption() because that one would pass --color to the daemon
* and --color is not supported there yet. */
args.add("-D" + Environment.MAVEN_COLOR.getProperty() + "=" + styleColor.name());

final ExecutionResult result = new DefaultClient(parameters).execute(output, args);
exitCode = result.getExitCode();
} catch (DaemonException.InterruptedException e) {
Expand Down Expand Up @@ -251,8 +253,12 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {
+ " (" + buildProperties.getRevision() + ")";

boolean isColored = !"never".equals(Environment.MAVEN_COLOR.getCommandLineOption(args));
final String v =
isColored ? Ansi.ansi().bold().a(mvndVersionString).reset().toString() : mvndVersionString;
final String v = isColored
? new AttributedStringBuilder()
.style(AttributedStyle.BOLD)
.append(mvndVersionString)
.toAnsi()
: mvndVersionString;
output.accept(Message.log(v));
// Print terminal information
output.describeTerminal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
import org.mvndaemon.mvnd.common.Os;
import org.mvndaemon.mvnd.common.SocketFamily;
import org.mvndaemon.mvnd.common.logging.ClientOutput;
import org.mvndaemon.mvnd.logging.slf4j.MvndBaseLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.SimpleLogger;

import static java.lang.Thread.sleep;
import static org.mvndaemon.mvnd.common.DaemonState.Canceled;
Expand Down Expand Up @@ -434,7 +434,7 @@ private Process startDaemonProcess(String daemonId, ClientOutput output) {
args.add("-Dmaven.conf=" + mvndHome.resolve("mvn").resolve("conf"));
args.add("-Dclassworlds.conf=" + mvndHome.resolve("bin").resolve("mvnd-daemon.conf"));

args.add("-D" + SimpleLogger.LOG_FILE_KEY + "="
args.add("-D" + MvndBaseLogger.LOG_FILE_KEY + "="
+ parameters.daemonStorage().resolve("daemon-" + daemonId + ".log"));

Environment.MVND_JAVA_HOME.addSystemProperty(
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jansi</artifactId>
<artifactId>jline-terminal-jni</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ public int getTerminalWidth() {
return terminal.getWidth();
}

public Terminal getTerminal() {
return terminal;
}

void readInputLoop() {
try {
while (!closing) {
Expand Down
6 changes: 6 additions & 0 deletions daemon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>6.0.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
22 changes: 18 additions & 4 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
*/
package org.apache.maven.cli;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -52,7 +55,6 @@
import org.apache.maven.cli.event.ExecutionEventLogger;
import org.apache.maven.cli.internal.BootstrapCoreExtensionManager;
import org.apache.maven.cli.internal.extension.model.CoreExtension;
import org.apache.maven.cli.jansi.MessageUtils;
import org.apache.maven.cli.logging.Slf4jConfiguration;
import org.apache.maven.cli.logging.Slf4jConfigurationFactory;
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
Expand All @@ -62,10 +64,12 @@
import org.apache.maven.exception.ExceptionHandler;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.*;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.extension.internal.CoreExports;
import org.apache.maven.extension.internal.CoreExportsProvider;
import org.apache.maven.extension.internal.CoreExtensionEntry;
import org.apache.maven.jline.MessageUtils;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.model.root.RootLocator;
Expand All @@ -74,6 +78,7 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifactsCache;
import org.apache.maven.properties.internal.SystemProperties;
import org.apache.maven.session.scope.internal.SessionScope;
import org.apache.maven.session.scope.internal.SessionScopeModule;
import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest;
import org.apache.maven.toolchain.building.ToolchainsBuilder;
Expand All @@ -90,21 +95,23 @@
import org.codehaus.plexus.interpolation.BasicInterpolator;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.eclipse.aether.transfer.TransferListener;
import org.jline.terminal.Terminal;
import org.jline.terminal.impl.ExternalTerminal;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingProjectArtifactsCache;
import org.mvndaemon.mvnd.cli.EnvHelper;
import org.mvndaemon.mvnd.common.Environment;
import org.mvndaemon.mvnd.common.Os;
import org.mvndaemon.mvnd.logging.internal.Slf4jLoggerManager;
import org.mvndaemon.mvnd.logging.slf4j.MvndSimpleLogger;
import org.mvndaemon.mvnd.logging.smart.BuildEventListener;
import org.mvndaemon.mvnd.logging.smart.LoggingExecutionListener;
import org.mvndaemon.mvnd.logging.smart.LoggingOutputStream;
import org.mvndaemon.mvnd.transfer.DaemonMavenTransferListener;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.MvndSimpleLogger;
import org.slf4j.spi.LocationAwareLogger;
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
Expand Down Expand Up @@ -204,6 +211,13 @@ public int main(
Map<String, String> clientEnv,
BuildEventListener buildEventListener)
throws Exception {
Terminal terminal = new ExternalTerminal(
"Maven",
"ansi",
new ByteArrayInputStream(new byte[0]),
new ByteArrayOutputStream(),
StandardCharsets.UTF_8);
MessageUtils.systemInstall(terminal);
this.buildEventListener = buildEventListener;
try {
CliRequest req = new CliRequest(null, null);
Expand Down Expand Up @@ -634,8 +648,8 @@ public Object getValue(String expression) {
for (CoreExtensionEntry extension : extensionsEntries) {
container.discoverComponents(
extension.getClassRealm(),
new SessionScopeModule(container),
new MojoExecutionScopeModule(container),
new SessionScopeModule(container.lookup(SessionScope.class)),
new MojoExecutionScopeModule(container.lookup(MojoExecutionScope.class)),
new ExtensionConfigurationModule(extension, extensionSource));
}
return container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import javax.inject.Singleton;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.cli.jansi.JansiMessageBuilderFactory;
import org.apache.maven.jline.JLineMessageBuilderFactory;
import org.mvndaemon.mvnd.common.Environment;

@Named
@Singleton
@Priority(10)
@Experimental
public class DaemonMessageBuilderFactory extends JansiMessageBuilderFactory {
public class DaemonMessageBuilderFactory extends JLineMessageBuilderFactory {

@Override
public int getTerminalWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.project;

import java.util.Objects;
import java.util.function.Supplier;

import org.apache.maven.building.Source;
import org.apache.maven.model.building.ModelCache;
Expand All @@ -33,22 +34,14 @@ public SnapshotModelCache(ModelCache globalCache, ModelCache reactorCache) {
this.reactorCache = Objects.requireNonNull(reactorCache);
}

public Object get(Source path, String tag) {
return reactorCache.get(path, tag);
}

public void put(Source path, String tag, Object data) {
reactorCache.put(path, tag, data);
}

@Override
public void put(String groupId, String artifactId, String version, String tag, Object data) {
getDelegate(version).put(groupId, artifactId, version, tag, data);
public <T> T computeIfAbsent(String groupId, String artifactId, String version, String tag, Supplier<T> data) {
return getDelegate(version).computeIfAbsent(groupId, artifactId, version, tag, data);
}

@Override
public Object get(String groupId, String artifactId, String version, String tag) {
return getDelegate(version).get(groupId, artifactId, version, tag);
public <T> T computeIfAbsent(Source path, String tag, Supplier<T> data) {
return reactorCache.computeIfAbsent(path, tag, data);
}

private ModelCache getDelegate(String version) {
Expand Down
30 changes: 0 additions & 30 deletions daemon/src/main/resources/META-INF/maven/extension.xml

This file was deleted.

14 changes: 12 additions & 2 deletions dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<name>Maven Daemon - Distribution</name>

<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>

<dependencies>
Expand All @@ -52,6 +52,16 @@
<groupId>org.apache.maven.daemon</groupId>
<artifactId>mvnd-daemon</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.daemon</groupId>
<artifactId>mvnd-logging</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading