mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-15 15:59:17 +00:00
Maven Daemon CLIng (#1158)
Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
This commit is contained in:
2
.github/workflows/early-access.yaml
vendored
2
.github/workflows/early-access.yaml
vendored
@@ -55,6 +55,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: daemon-test-logs-default-build
|
name: daemon-test-logs-default-build
|
||||||
path: integration-tests/target/mvnd-tests/**/daemon*.log
|
path: integration-tests/target/mvnd-tests/**/daemon*.log
|
||||||
|
include-hidden-files: 'true'
|
||||||
|
|
||||||
native-build:
|
native-build:
|
||||||
name: 'Build with GraalVM on ${{ matrix.os }}'
|
name: 'Build with GraalVM on ${{ matrix.os }}'
|
||||||
@@ -141,6 +142,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: daemon-test-logs-${{ env.OS }}-${{ env.ARCH }}
|
name: daemon-test-logs-${{ env.OS }}-${{ env.ARCH }}
|
||||||
path: integration-tests/target/mvnd-tests/**/daemon*.log
|
path: integration-tests/target/mvnd-tests/**/daemon*.log
|
||||||
|
include-hidden-files: 'true'
|
||||||
|
|
||||||
- name: 'Upload artifact'
|
- name: 'Upload artifact'
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
@@ -43,10 +43,6 @@
|
|||||||
<groupId>org.apache.maven.daemon</groupId>
|
<groupId>org.apache.maven.daemon</groupId>
|
||||||
<artifactId>mvnd-logging</artifactId>
|
<artifactId>mvnd-logging</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.maven</groupId>
|
|
||||||
<artifactId>maven-embedder</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>jul-to-slf4j</artifactId>
|
<artifactId>jul-to-slf4j</artifactId>
|
||||||
|
@@ -45,8 +45,8 @@ import java.util.function.Supplier;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.apache.maven.api.cli.extensions.CoreExtension;
|
||||||
import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader;
|
import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader;
|
||||||
import org.apache.maven.cli.internal.extension.model.CoreExtension;
|
|
||||||
import org.mvndaemon.mvnd.common.Environment;
|
import org.mvndaemon.mvnd.common.Environment;
|
||||||
import org.mvndaemon.mvnd.common.InterpolationHelper;
|
import org.mvndaemon.mvnd.common.InterpolationHelper;
|
||||||
import org.mvndaemon.mvnd.common.Os;
|
import org.mvndaemon.mvnd.common.Os;
|
||||||
|
@@ -60,7 +60,11 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-embedder</artifactId>
|
<artifactId>maven-resolver-provider</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-cli</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.commons.cli.Option;
|
||||||
|
import org.apache.commons.cli.Options;
|
||||||
|
import org.apache.commons.cli.ParseException;
|
||||||
|
import org.apache.maven.cling.invoker.mvn.CommonsCliMavenOptions;
|
||||||
|
import org.codehaus.plexus.interpolation.BasicInterpolator;
|
||||||
|
import org.codehaus.plexus.interpolation.InterpolationException;
|
||||||
|
import org.mvndaemon.mvnd.common.Environment;
|
||||||
|
|
||||||
|
import static org.apache.maven.cling.invoker.Utils.createInterpolator;
|
||||||
|
|
||||||
|
public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions implements DaemonMavenOptions {
|
||||||
|
public static CommonsCliDaemonMavenOptions parse(String source, String[] args) throws ParseException {
|
||||||
|
CLIManager cliManager = new CLIManager();
|
||||||
|
return new CommonsCliDaemonMavenOptions(source, cliManager, cliManager.parse(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CommonsCliDaemonMavenOptions(String source, CLIManager cliManager, CommandLine commandLine) {
|
||||||
|
super(source, cliManager, commandLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.apache.commons.cli.Options getOptions() {
|
||||||
|
return this.cliManager.getOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Boolean> rawStreams() {
|
||||||
|
if (commandLine.hasOption(CLIManager.RAW_STREAMS)
|
||||||
|
|| Environment.MVND_RAW_STREAMS.asOptional().isPresent()) {
|
||||||
|
return Optional.of(Boolean.TRUE);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CommonsCliDaemonMavenOptions interpolate(
|
||||||
|
CommonsCliDaemonMavenOptions options, Collection<Map<String, String>> properties) {
|
||||||
|
try {
|
||||||
|
// now that we have properties, interpolate all arguments
|
||||||
|
BasicInterpolator interpolator = createInterpolator(properties);
|
||||||
|
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
|
||||||
|
commandLineBuilder.setDeprecatedHandler(o -> {});
|
||||||
|
for (Option option : options.commandLine.getOptions()) {
|
||||||
|
if (!CLIManager.USER_PROPERTY.equals(option.getOpt())) {
|
||||||
|
List<String> values = option.getValuesList();
|
||||||
|
for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) {
|
||||||
|
it.set(interpolator.interpolate(it.next()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commandLineBuilder.addOption(option);
|
||||||
|
}
|
||||||
|
for (String arg : options.commandLine.getArgList()) {
|
||||||
|
commandLineBuilder.addArg(interpolator.interpolate(arg));
|
||||||
|
}
|
||||||
|
return new CommonsCliDaemonMavenOptions(
|
||||||
|
options.source, (CLIManager) options.cliManager, commandLineBuilder.build());
|
||||||
|
} catch (InterpolationException e) {
|
||||||
|
throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DaemonMavenOptions interpolate(Collection<Map<String, String>> properties) {
|
||||||
|
return interpolate(this, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class CLIManager extends CommonsCliMavenOptions.CLIManager {
|
||||||
|
public static final String RAW_STREAMS = "ras";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void prepareOptions(Options options) {
|
||||||
|
super.prepareOptions(options);
|
||||||
|
options.addOption(Option.builder(RAW_STREAMS)
|
||||||
|
.longOpt("raw-streams")
|
||||||
|
.desc("Use raw-streams for daemon communication")
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -26,7 +26,7 @@ import org.mvndaemon.mvnd.logging.smart.BuildEventListener;
|
|||||||
/**
|
/**
|
||||||
* Simple interface to bridge maven 3.9.x and 4.0.x CLI
|
* Simple interface to bridge maven 3.9.x and 4.0.x CLI
|
||||||
*/
|
*/
|
||||||
public interface DaemonCli {
|
public interface DaemonCli extends AutoCloseable {
|
||||||
int main(
|
int main(
|
||||||
List<String> args,
|
List<String> args,
|
||||||
String workingDir,
|
String workingDir,
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.apache.maven.api.cli.ParserRequest;
|
||||||
|
import org.apache.maven.cling.invoker.ProtoLogger;
|
||||||
|
import org.apache.maven.cling.invoker.ProtoLookup;
|
||||||
|
import org.apache.maven.jline.MessageUtils;
|
||||||
|
import org.codehaus.plexus.classworlds.ClassWorld;
|
||||||
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
|
import org.jline.terminal.Terminal;
|
||||||
|
import org.jline.terminal.impl.ExternalTerminal;
|
||||||
|
import org.mvndaemon.mvnd.cli.EnvHelper;
|
||||||
|
import org.mvndaemon.mvnd.logging.smart.BuildEventListener;
|
||||||
|
|
||||||
|
public class DaemonMavenCling implements DaemonCli {
|
||||||
|
private final DaemonMavenParser parser;
|
||||||
|
private final DaemonMavenInvoker invoker;
|
||||||
|
|
||||||
|
public DaemonMavenCling() {
|
||||||
|
this.parser = new DaemonMavenParser();
|
||||||
|
this.invoker = new DaemonMavenInvoker(ProtoLookup.builder()
|
||||||
|
.addMapping(
|
||||||
|
ClassWorld.class, ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
invoker.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int main(
|
||||||
|
List<String> args,
|
||||||
|
String workingDir,
|
||||||
|
String projectDir,
|
||||||
|
Map<String, String> env,
|
||||||
|
BuildEventListener buildEventListener)
|
||||||
|
throws Exception {
|
||||||
|
Terminal terminal = new ExternalTerminal(
|
||||||
|
"Maven",
|
||||||
|
"ansi",
|
||||||
|
new ByteArrayInputStream(new byte[0]),
|
||||||
|
new ByteArrayOutputStream(),
|
||||||
|
StandardCharsets.UTF_8);
|
||||||
|
MessageUtils.systemInstall(terminal);
|
||||||
|
EnvHelper.environment(workingDir, env);
|
||||||
|
System.setProperty("maven.multiModuleProjectDirectory", projectDir);
|
||||||
|
return invoker.invoke(parser.parse(ParserRequest.builder(
|
||||||
|
"mvnd", "Maven Daemon", args, new ProtoLogger(), new DaemonMessageBuilderFactory())
|
||||||
|
.cwd(Paths.get(workingDir))
|
||||||
|
.lookup(ProtoLookup.builder()
|
||||||
|
.addMapping(Environment.class, () -> env)
|
||||||
|
.addMapping(BuildEventListener.class, buildEventListener)
|
||||||
|
.build())
|
||||||
|
.build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key for environment.
|
||||||
|
*/
|
||||||
|
interface Environment extends Supplier<Map<String, String>> {}
|
||||||
|
}
|
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import org.apache.maven.api.cli.Options;
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenInvokerRequest;
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenOptions;
|
||||||
|
import org.apache.maven.cli.event.ExecutionEventLogger;
|
||||||
|
import org.apache.maven.cling.invoker.ContainerCapsuleFactory;
|
||||||
|
import org.apache.maven.cling.invoker.ProtoLookup;
|
||||||
|
import org.apache.maven.cling.invoker.mvn.resident.DefaultResidentMavenInvoker;
|
||||||
|
import org.apache.maven.execution.ExecutionListener;
|
||||||
|
import org.apache.maven.jline.MessageUtils;
|
||||||
|
import org.eclipse.aether.transfer.TransferListener;
|
||||||
|
import org.mvndaemon.mvnd.common.Environment;
|
||||||
|
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.spi.LocationAwareLogger;
|
||||||
|
|
||||||
|
public class DaemonMavenInvoker extends DefaultResidentMavenInvoker {
|
||||||
|
public DaemonMavenInvoker(ProtoLookup protoLookup) {
|
||||||
|
super(protoLookup);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureLogging(LocalContext context) throws Exception {
|
||||||
|
super.configureLogging(context);
|
||||||
|
|
||||||
|
DaemonMavenOptions options = (DaemonMavenOptions) context.invokerRequest.options();
|
||||||
|
if (options.logFile().isEmpty() && !options.rawStreams().orElse(false)) {
|
||||||
|
MvndSimpleLogger stdout = (MvndSimpleLogger) context.loggerFactory.getLogger("stdout");
|
||||||
|
MvndSimpleLogger stderr = (MvndSimpleLogger) context.loggerFactory.getLogger("stderr");
|
||||||
|
stdout.setLogLevel(LocationAwareLogger.INFO_INT);
|
||||||
|
stderr.setLogLevel(LocationAwareLogger.INFO_INT);
|
||||||
|
System.setOut(new LoggingOutputStream(s -> stdout.info("[stdout] " + s)).printStream());
|
||||||
|
System.setErr(new LoggingOutputStream(s -> stderr.warn("[stderr] " + s)).printStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void helpOrVersionAndMayExit(LocalContext context) throws Exception {
|
||||||
|
MavenInvokerRequest<MavenOptions> invokerRequest = context.invokerRequest;
|
||||||
|
BuildEventListener buildEventListener =
|
||||||
|
context.invokerRequest.parserRequest().lookup().lookup(BuildEventListener.class);
|
||||||
|
if (invokerRequest.options().help().isPresent()) {
|
||||||
|
// TODO: ugly, clenup
|
||||||
|
buildEventListener.log(
|
||||||
|
MvndHelpFormatter.displayHelp((CommonsCliDaemonMavenOptions) context.invokerRequest.options()));
|
||||||
|
throw new ExitException(0);
|
||||||
|
}
|
||||||
|
if (invokerRequest.options().showVersionAndExit().isPresent()) {
|
||||||
|
if (invokerRequest.options().quiet().orElse(false)) {
|
||||||
|
buildEventListener.log(CLIReportingUtils.showVersionMinimal());
|
||||||
|
} else {
|
||||||
|
buildEventListener.log(CLIReportingUtils.showVersion());
|
||||||
|
}
|
||||||
|
throw new ExitException(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preCommands(LocalContext context) throws Exception {
|
||||||
|
Options mavenOptions = context.invokerRequest.options();
|
||||||
|
if (mavenOptions.verbose().orElse(false) || mavenOptions.showVersion().orElse(false)) {
|
||||||
|
context.invokerRequest
|
||||||
|
.parserRequest()
|
||||||
|
.lookup()
|
||||||
|
.lookup(BuildEventListener.class)
|
||||||
|
.log(CLIReportingUtils.showVersion());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ContainerCapsuleFactory<MavenOptions, MavenInvokerRequest<MavenOptions>, LocalContext>
|
||||||
|
createContainerCapsuleFactory() {
|
||||||
|
return new DaemonPlexusContainerCapsuleFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ExecutionListener determineExecutionListener(LocalContext context) {
|
||||||
|
if (context.lookup != null) {
|
||||||
|
LoggingExecutionListener listener = context.lookup.lookup(LoggingExecutionListener.class);
|
||||||
|
ExecutionEventLogger executionEventLogger =
|
||||||
|
new ExecutionEventLogger(context.invokerRequest.messageBuilderFactory());
|
||||||
|
listener.init(
|
||||||
|
context.eventSpyDispatcher.chainListener(executionEventLogger),
|
||||||
|
context.invokerRequest.parserRequest().lookup().lookup(BuildEventListener.class));
|
||||||
|
return listener;
|
||||||
|
} else {
|
||||||
|
// this branch happens in "early" step of container capsule to load extensions
|
||||||
|
return super.determineExecutionListener(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TransferListener determineTransferListener(LocalContext context, boolean noTransferProgress) {
|
||||||
|
return new DaemonMavenTransferListener(
|
||||||
|
context.invokerRequest.parserRequest().lookup().lookup(BuildEventListener.class),
|
||||||
|
super.determineTransferListener(context, noTransferProgress));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int doExecute(LocalContext context) throws Exception {
|
||||||
|
context.logger.info(MessageUtils.builder()
|
||||||
|
.a("Processing build on daemon ")
|
||||||
|
.strong(Environment.MVND_ID.asString())
|
||||||
|
.toString());
|
||||||
|
context.logger.info("Daemon status dump:");
|
||||||
|
context.logger.info("CWD: " + context.invokerRequest.cwd());
|
||||||
|
context.logger.info("MAVEN_HOME: " + context.invokerRequest.installationDirectory());
|
||||||
|
context.logger.info("USER_HOME: " + context.invokerRequest.userHomeDirectory());
|
||||||
|
context.logger.info("topDirectory: " + context.invokerRequest.topDirectory());
|
||||||
|
context.logger.info("rootDirectory: " + context.invokerRequest.rootDirectory());
|
||||||
|
|
||||||
|
try {
|
||||||
|
return super.doExecute(context);
|
||||||
|
} finally {
|
||||||
|
LoggingOutputStream.forceFlush(System.out);
|
||||||
|
LoggingOutputStream.forceFlush(System.err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenOptions;
|
||||||
|
|
||||||
|
public interface DaemonMavenOptions extends MavenOptions {
|
||||||
|
/**
|
||||||
|
* Should use raw-streams to communicate with daemon.
|
||||||
|
*/
|
||||||
|
Optional<Boolean> rawStreams();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
DaemonMavenOptions interpolate(Collection<Map<String, String>> properties);
|
||||||
|
}
|
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.apache.commons.cli.ParseException;
|
||||||
|
import org.apache.maven.api.cli.ParserException;
|
||||||
|
import org.apache.maven.api.cli.extensions.CoreExtension;
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenInvokerRequest;
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenOptions;
|
||||||
|
import org.apache.maven.cling.invoker.mvn.BaseMavenParser;
|
||||||
|
import org.apache.maven.cling.invoker.mvn.DefaultMavenInvokerRequest;
|
||||||
|
import org.mvndaemon.mvnd.common.Environment;
|
||||||
|
|
||||||
|
public class DaemonMavenParser extends BaseMavenParser<MavenOptions, MavenInvokerRequest<MavenOptions>> {
|
||||||
|
@Override
|
||||||
|
protected DefaultMavenInvokerRequest<MavenOptions> getInvokerRequest(LocalContext context) {
|
||||||
|
return new DefaultMavenInvokerRequest<>(
|
||||||
|
context.parserRequest,
|
||||||
|
context.cwd,
|
||||||
|
context.installationDirectory,
|
||||||
|
context.userHomeDirectory,
|
||||||
|
context.userProperties,
|
||||||
|
context.systemProperties,
|
||||||
|
context.topDirectory,
|
||||||
|
context.rootDirectory,
|
||||||
|
context.parserRequest.in(),
|
||||||
|
context.parserRequest.out(),
|
||||||
|
context.parserRequest.err(),
|
||||||
|
context.extensions,
|
||||||
|
(DaemonMavenOptions) context.options);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MavenOptions parseArgs(String source, List<String> args) throws ParserException {
|
||||||
|
try {
|
||||||
|
return CommonsCliDaemonMavenOptions.parse(source, args.toArray(new String[0]));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new ParserException("Failed to parse source " + source + ": " + e.getMessage(), e.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MavenOptions assembleOptions(List<MavenOptions> parsedOptions) {
|
||||||
|
return LayeredDaemonMavenOptions.layerDaemonMavenOptions(
|
||||||
|
parsedOptions.stream().map(o -> (DaemonMavenOptions) o).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> populateSystemProperties(LocalContext context) throws ParserException {
|
||||||
|
HashMap<String, String> systemProperties = new HashMap<>(super.populateSystemProperties(context));
|
||||||
|
Map<String, String> env = context.parserRequest
|
||||||
|
.lookup()
|
||||||
|
.lookup(DaemonMavenCling.Environment.class)
|
||||||
|
.get();
|
||||||
|
systemProperties.putAll(env);
|
||||||
|
return systemProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<CoreExtension> readCoreExtensionsDescriptor(LocalContext context) {
|
||||||
|
return Stream.of(Environment.MVND_CORE_EXTENSIONS.asString().split(";"))
|
||||||
|
.filter(s -> s != null && !s.isEmpty())
|
||||||
|
.map(s -> {
|
||||||
|
String[] parts = s.split(":");
|
||||||
|
return CoreExtension.newBuilder()
|
||||||
|
.groupId(parts[0])
|
||||||
|
.artifactId(parts[1])
|
||||||
|
.version(parts[2])
|
||||||
|
.build();
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenInvokerRequest;
|
||||||
|
import org.apache.maven.api.cli.mvn.MavenOptions;
|
||||||
|
import org.apache.maven.cling.invoker.PlexusContainerCapsuleFactory;
|
||||||
|
import org.apache.maven.cling.invoker.mvn.resident.DefaultResidentMavenInvoker;
|
||||||
|
import org.codehaus.plexus.logging.LoggerManager;
|
||||||
|
import org.mvndaemon.mvnd.common.Environment;
|
||||||
|
import org.mvndaemon.mvnd.logging.internal.Slf4jLoggerManager;
|
||||||
|
|
||||||
|
public class DaemonPlexusContainerCapsuleFactory
|
||||||
|
extends PlexusContainerCapsuleFactory<
|
||||||
|
MavenOptions, MavenInvokerRequest<MavenOptions>, DefaultResidentMavenInvoker.LocalContext> {
|
||||||
|
private final Slf4jLoggerManager slf4jLoggerManager = new Slf4jLoggerManager();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LoggerManager createLoggerManager() {
|
||||||
|
return slf4jLoggerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Path> parseExtClasspath(DefaultResidentMavenInvoker.LocalContext context) throws Exception {
|
||||||
|
return Stream.of(Environment.MVND_EXT_CLASSPATH.asString().split(","))
|
||||||
|
.filter(s -> s != null && !s.isEmpty())
|
||||||
|
.map(Paths::get)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.maven.cli;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.apache.maven.cling.invoker.mvn.LayeredMavenOptions;
|
||||||
|
|
||||||
|
public class LayeredDaemonMavenOptions extends LayeredMavenOptions<DaemonMavenOptions> implements DaemonMavenOptions {
|
||||||
|
public static DaemonMavenOptions layerDaemonMavenOptions(Collection<DaemonMavenOptions> options) {
|
||||||
|
List<DaemonMavenOptions> o = options.stream().filter(Objects::nonNull).toList();
|
||||||
|
if (o.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("No options specified (or all were null)");
|
||||||
|
} else if (o.size() == 1) {
|
||||||
|
return o.get(0);
|
||||||
|
} else {
|
||||||
|
return new LayeredDaemonMavenOptions(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LayeredDaemonMavenOptions(List<DaemonMavenOptions> options) {
|
||||||
|
super(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Boolean> rawStreams() {
|
||||||
|
return returnFirstPresentOrEmpty(DaemonMavenOptions::rawStreams);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DaemonMavenOptions interpolate(Collection<Map<String, String>> properties) {
|
||||||
|
ArrayList<DaemonMavenOptions> interpolatedOptions = new ArrayList<>(options.size());
|
||||||
|
for (DaemonMavenOptions o : options) {
|
||||||
|
interpolatedOptions.add(o.interpolate(properties));
|
||||||
|
}
|
||||||
|
return layerDaemonMavenOptions(interpolatedOptions);
|
||||||
|
}
|
||||||
|
}
|
@@ -21,7 +21,6 @@ package org.apache.maven.cli;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -48,13 +47,13 @@ public class MvndHelpFormatter {
|
|||||||
/**
|
/**
|
||||||
* Returns Maven option descriptions combined with mvnd options descriptions
|
* Returns Maven option descriptions combined with mvnd options descriptions
|
||||||
*
|
*
|
||||||
* @param cliManager
|
* @param cliManager The cli manager
|
||||||
* @return the string containing the help message
|
* @return the string containing the help message
|
||||||
*/
|
*/
|
||||||
public static String displayHelp(CLIManager cliManager) {
|
public static String displayHelp(CommonsCliDaemonMavenOptions cliManager) {
|
||||||
int terminalWidth = getTerminalWidth();
|
int terminalWidth = getTerminalWidth();
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try (PrintStream out = new PrintStream(baos, false, StandardCharsets.UTF_8.name())) {
|
try (PrintStream out = new PrintStream(baos, false, StandardCharsets.UTF_8)) {
|
||||||
out.println();
|
out.println();
|
||||||
PrintWriter pw = new PrintWriter(out);
|
PrintWriter pw = new PrintWriter(out);
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
@@ -63,16 +62,14 @@ public class MvndHelpFormatter {
|
|||||||
terminalWidth,
|
terminalWidth,
|
||||||
"mvnd [options] [<goal(s)>] [<phase(s)>]",
|
"mvnd [options] [<goal(s)>] [<phase(s)>]",
|
||||||
"\nOptions:",
|
"\nOptions:",
|
||||||
cliManager.options,
|
cliManager.getOptions(),
|
||||||
1,
|
1,
|
||||||
3,
|
3,
|
||||||
"\n",
|
"\n",
|
||||||
false);
|
false);
|
||||||
pw.flush();
|
pw.flush();
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
final String mvnHelp = new String(baos.toByteArray(), StandardCharsets.UTF_8);
|
final String mvnHelp = baos.toString(StandardCharsets.UTF_8);
|
||||||
final Matcher m = COLUMNS_DETECTOR_PATTERN.matcher(mvnHelp);
|
final Matcher m = COLUMNS_DETECTOR_PATTERN.matcher(mvnHelp);
|
||||||
final String indent = m.find() ? m.group() : " ";
|
final String indent = m.find() ? m.group() : " ";
|
||||||
|
|
||||||
@@ -201,12 +198,8 @@ public class MvndHelpFormatter {
|
|||||||
*
|
*
|
||||||
* @param stringBuilder the {@link StringBuilder} to append to
|
* @param stringBuilder the {@link StringBuilder} to append to
|
||||||
* @param count the number of spaces to append
|
* @param count the number of spaces to append
|
||||||
* @return the given {@code stringBuilder}
|
|
||||||
*/
|
*/
|
||||||
static StringBuilder spaces(StringBuilder stringBuilder, int count) {
|
static void spaces(StringBuilder stringBuilder, int count) {
|
||||||
for (int i = 0; i < count; i++) {
|
stringBuilder.append(" ".repeat(Math.max(0, count)));
|
||||||
stringBuilder.append(' ');
|
|
||||||
}
|
|
||||||
return stringBuilder;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -131,7 +131,7 @@ public class Server implements AutoCloseable, Runnable {
|
|||||||
try {
|
try {
|
||||||
cli = (DaemonCli) getClass()
|
cli = (DaemonCli) getClass()
|
||||||
.getClassLoader()
|
.getClassLoader()
|
||||||
.loadClass("org.apache.maven.cli.DaemonMavenCli")
|
.loadClass("org.apache.maven.cli.DaemonMavenCling")
|
||||||
.getDeclaredConstructor()
|
.getDeclaredConstructor()
|
||||||
.newInstance();
|
.newInstance();
|
||||||
registry = new DaemonRegistry(Environment.MVND_REGISTRY.asPath());
|
registry = new DaemonRegistry(Environment.MVND_REGISTRY.asPath());
|
||||||
@@ -187,7 +187,11 @@ public class Server implements AutoCloseable, Runnable {
|
|||||||
try {
|
try {
|
||||||
registry.close();
|
registry.close();
|
||||||
} finally {
|
} finally {
|
||||||
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
|
} finally {
|
||||||
|
cli.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -98,11 +98,9 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<rerunFailingTestsCount>4</rerunFailingTestsCount>
|
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<mvnd.home>${mvnd.home}</mvnd.home>
|
<mvnd.home>${mvnd.home}</mvnd.home>
|
||||||
<project.version>${project.version}</project.version>
|
<project.version>${project.version}</project.version>
|
||||||
<mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
|
|
||||||
<os.detected.name>${os.detected.name}</os.detected.name>
|
<os.detected.name>${os.detected.name}</os.detected.name>
|
||||||
<os.detected.arch>${os.detected.arch}</os.detected.arch>
|
<os.detected.arch>${os.detected.arch}</os.detected.arch>
|
||||||
<mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo>
|
<mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo>
|
||||||
@@ -134,40 +132,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
|
||||||
<!-- To disable mrm-maven-plugin, pass '-Dmrm=false' to the command line -->
|
|
||||||
<id>mrm</id>
|
|
||||||
<activation>
|
|
||||||
<property>
|
|
||||||
<name>mrm</name>
|
|
||||||
<value>!false</value>
|
|
||||||
</property>
|
|
||||||
</activation>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>mrm-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>mrm-start</id>
|
|
||||||
<goals>
|
|
||||||
<goal>start</goal>
|
|
||||||
</goals>
|
|
||||||
<phase>process-test-classes</phase>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>mrm-stop</id>
|
|
||||||
<goals>
|
|
||||||
<goal>stop</goal>
|
|
||||||
</goals>
|
|
||||||
<phase>post-integration-test</phase>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>native</id>
|
<id>native</id>
|
||||||
<build>
|
<build>
|
||||||
@@ -186,7 +150,6 @@
|
|||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<project.version>${project.version}</project.version>
|
<project.version>${project.version}</project.version>
|
||||||
<mvnd.home>${mvnd.home}</mvnd.home>
|
<mvnd.home>${mvnd.home}</mvnd.home>
|
||||||
<mrm.repository.url>${mrm.repository.url}</mrm.repository.url>
|
|
||||||
<os.detected.name>${os.detected.name}</os.detected.name>
|
<os.detected.name>${os.detected.name}</os.detected.name>
|
||||||
<os.detected.arch>${os.detected.arch}</os.detected.arch>
|
<os.detected.arch>${os.detected.arch}</os.detected.arch>
|
||||||
<mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo>
|
<mvnd.test.hostLocalMavenRepo>${settings.localRepository}</mvnd.test.hostLocalMavenRepo>
|
||||||
|
@@ -75,7 +75,7 @@ class MavenConfNativeIT {
|
|||||||
|
|
||||||
protected List<String> mvndParams(String expression) {
|
protected List<String> mvndParams(String expression) {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
"org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate",
|
"org.apache.maven.plugins:maven-help-plugin:3.5.0:evaluate",
|
||||||
"-D",
|
"-D",
|
||||||
"expression=" + expression,
|
"expression=" + expression,
|
||||||
"-q",
|
"-q",
|
||||||
|
@@ -52,7 +52,6 @@ class RawStreamsTest {
|
|||||||
final TestClientOutput o = new TestClientOutput();
|
final TestClientOutput o = new TestClientOutput();
|
||||||
client.execute(o, "validate", "--quiet", "--raw-streams").assertSuccess();
|
client.execute(o, "validate", "--quiet", "--raw-streams").assertSuccess();
|
||||||
String expected = "PrintOut{payload='Hello'}";
|
String expected = "PrintOut{payload='Hello'}";
|
||||||
o.getMessages().forEach(m -> System.out.println(m.toString()));
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
o.getMessages().stream().anyMatch(m -> m.toString().contains(expected)),
|
o.getMessages().stream().anyMatch(m -> m.toString().contains(expected)),
|
||||||
"Output should contain " + expected);
|
"Output should contain " + expected);
|
||||||
|
@@ -21,7 +21,6 @@ package org.mvndaemon.mvnd.junit;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -225,19 +224,6 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
|
|||||||
final Path mvndPropertiesPath = testDir.resolve("mvnd.properties");
|
final Path mvndPropertiesPath = testDir.resolve("mvnd.properties");
|
||||||
|
|
||||||
final Path localMavenRepository = deleteDir(testDir.resolve("local-maven-repo"));
|
final Path localMavenRepository = deleteDir(testDir.resolve("local-maven-repo"));
|
||||||
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 home = deleteDir(testDir.resolve("home"));
|
final Path home = deleteDir(testDir.resolve("home"));
|
||||||
final TestParameters parameters = new TestParameters(
|
final TestParameters parameters = new TestParameters(
|
||||||
testDir,
|
testDir,
|
||||||
@@ -248,7 +234,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
|
|||||||
multiModuleProjectDirectory,
|
multiModuleProjectDirectory,
|
||||||
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
|
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
|
||||||
localMavenRepository,
|
localMavenRepository,
|
||||||
settingsPath,
|
null,
|
||||||
TimeUtils.toDuration(Environment.MVND_IDLE_TIMEOUT.getDefault()),
|
TimeUtils.toDuration(Environment.MVND_IDLE_TIMEOUT.getDefault()),
|
||||||
keepAlive != null && !keepAlive.isEmpty()
|
keepAlive != null && !keepAlive.isEmpty()
|
||||||
? TimeUtils.toDuration(keepAlive)
|
? TimeUtils.toDuration(keepAlive)
|
||||||
@@ -291,22 +277,6 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
final String content = template.replaceAll("@mrm.repository.url@", mrmRepoUrl);
|
|
||||||
try {
|
|
||||||
Files.write(settingsPath, content.getBytes(StandardCharsets.UTF_8));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Could not write " + settingsPath);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Could not read " + settingsTemplatePath);
|
|
||||||
}
|
|
||||||
return settingsPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MvndResource(TestParameters parameters, TestRegistry registry, boolean isNative, long timeoutMs) {
|
public MvndResource(TestParameters parameters, TestRegistry registry, boolean isNative, long timeoutMs) {
|
||||||
super();
|
super();
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
package org.mvndaemon.mvnd.junit;
|
package org.mvndaemon.mvnd.junit;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -34,7 +33,7 @@ public class TestUtils {
|
|||||||
if (originalSrc.equals(newSrc)) {
|
if (originalSrc.equals(newSrc)) {
|
||||||
throw new IllegalStateException("[" + find + "] not found in " + path);
|
throw new IllegalStateException("[" + find + "] not found in " + path);
|
||||||
}
|
}
|
||||||
Files.write(path, newSrc.getBytes(StandardCharsets.UTF_8));
|
Files.writeString(path, newSrc);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Could not read or write " + path, e);
|
throw new RuntimeException("Could not read or write " + path, e);
|
||||||
}
|
}
|
||||||
|
@@ -17,52 +17,4 @@
|
|||||||
|
|
||||||
-->
|
-->
|
||||||
<settings>
|
<settings>
|
||||||
<mirrors>
|
|
||||||
<mirror>
|
|
||||||
<id>mrm-maven-plugin</id>
|
|
||||||
<name>Mock Repository Manager</name>
|
|
||||||
<url>@mrm.repository.url@</url>
|
|
||||||
<mirrorOf>*</mirrorOf>
|
|
||||||
</mirror>
|
|
||||||
</mirrors>
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>it-repo</id>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>snapshots</id>
|
|
||||||
<url>@mrm.repository.url@</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
<checksumPolicy>ignore</checksumPolicy>
|
|
||||||
<updatePolicy>never</updatePolicy>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
<checksumPolicy>ignore</checksumPolicy>
|
|
||||||
<updatePolicy>always</updatePolicy>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<pluginRepositories>
|
|
||||||
<pluginRepository>
|
|
||||||
<id>snapshots</id>
|
|
||||||
<url>@mrm.repository.url@</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
<checksumPolicy>ignore</checksumPolicy>
|
|
||||||
<updatePolicy>never</updatePolicy>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
<checksumPolicy>ignore</checksumPolicy>
|
|
||||||
<updatePolicy>always</updatePolicy>
|
|
||||||
</snapshots>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
<activeProfiles>
|
|
||||||
<activeProfile>it-repo</activeProfile>
|
|
||||||
</activeProfiles>
|
|
||||||
</settings>
|
</settings>
|
||||||
|
39
pom.xml
39
pom.xml
@@ -81,20 +81,22 @@
|
|||||||
<graalvm.version>24.1.0</graalvm.version>
|
<graalvm.version>24.1.0</graalvm.version>
|
||||||
<graalvm.plugin.version>0.10.3</graalvm.plugin.version>
|
<graalvm.plugin.version>0.10.3</graalvm.plugin.version>
|
||||||
<groovy.version>4.0.23</groovy.version>
|
<groovy.version>4.0.23</groovy.version>
|
||||||
<jakarta.inject.version>1.0</jakarta.inject.version>
|
|
||||||
<jansi.version>2.4.1</jansi.version>
|
<jansi.version>2.4.1</jansi.version>
|
||||||
<jline.version>3.27.0</jline.version>
|
<jline.version>3.27.0</jline.version>
|
||||||
<maven.version>4.0.0-beta-3</maven.version>
|
<maven.version>4.0.0-beta-5-SNAPSHOT</maven.version>
|
||||||
|
|
||||||
<!-- Keep in sync with Maven -->
|
<!-- Keep in sync with Maven -->
|
||||||
<maven.resolver.version>2.0.0</maven.resolver.version>
|
<maven.resolver.version>2.0.1</maven.resolver.version>
|
||||||
<slf4j.version>2.0.11</slf4j.version>
|
<slf4j.version>2.0.16</slf4j.version>
|
||||||
<sisu.version>0.9.0.M3</sisu.version>
|
<sisu.version>0.9.0.M3</sisu.version>
|
||||||
<maven.plugin-tools.version>3.15.0</maven.plugin-tools.version>
|
<maven.plugin-tools.version>3.15.0</maven.plugin-tools.version>
|
||||||
|
<version.plexus-utils>4.0.2</version.plexus-utils>
|
||||||
|
<version.plexus-xml>4.0.4</version.plexus-xml>
|
||||||
|
<jakarta.inject.version>2.0.1</jakarta.inject.version>
|
||||||
|
|
||||||
<!-- plugin versions a..z -->
|
<!-- plugin versions a..z -->
|
||||||
<buildnumber-maven-plugin.version>3.2.1</buildnumber-maven-plugin.version>
|
<buildnumber-maven-plugin.version>3.2.1</buildnumber-maven-plugin.version>
|
||||||
<groovy-maven-plugin.version>4.0.1</groovy-maven-plugin.version>
|
<groovy-maven-plugin.version>4.0.1</groovy-maven-plugin.version>
|
||||||
<mrm.version>1.6.0</mrm.version>
|
|
||||||
<junit-platform-launcher.version>1.3.2</junit-platform-launcher.version>
|
<junit-platform-launcher.version>1.3.2</junit-platform-launcher.version>
|
||||||
<takari-provisio.version>1.1.1</takari-provisio.version>
|
<takari-provisio.version>1.1.1</takari-provisio.version>
|
||||||
|
|
||||||
@@ -159,11 +161,33 @@
|
|||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-core</artifactId>
|
<artifactId>maven-core</artifactId>
|
||||||
<version>${maven.version}</version>
|
<version>${maven.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-slf4j-provider</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-resolver-provider</artifactId>
|
||||||
|
<version>${maven.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-embedder</artifactId>
|
<artifactId>maven-embedder</artifactId>
|
||||||
<version>${maven.version}</version>
|
<version>${maven.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-slf4j-provider</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-cli</artifactId>
|
||||||
|
<version>${maven.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
@@ -445,11 +469,6 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>mrm-maven-plugin</artifactId>
|
|
||||||
<version>${mrm.version}</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||||
|
Reference in New Issue
Block a user