Skip to content

Commit 27258c0

Browse files
cstamasgnodet
andauthored
Maven Daemon CLIng (#1158)
Co-authored-by: Guillaume Nodet <[email protected]>
1 parent 06eb5fd commit 27258c0

File tree

22 files changed

+626
-1702
lines changed

22 files changed

+626
-1702
lines changed

.github/workflows/early-access.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
with:
5656
name: daemon-test-logs-default-build
5757
path: integration-tests/target/mvnd-tests/**/daemon*.log
58+
include-hidden-files: 'true'
5859

5960
native-build:
6061
name: 'Build with GraalVM on ${{ matrix.os }}'
@@ -141,6 +142,7 @@ jobs:
141142
with:
142143
name: daemon-test-logs-${{ env.OS }}-${{ env.ARCH }}
143144
path: integration-tests/target/mvnd-tests/**/daemon*.log
145+
include-hidden-files: 'true'
144146

145147
- name: 'Upload artifact'
146148
uses: actions/upload-artifact@v4

client/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
<groupId>org.apache.maven.daemon</groupId>
4444
<artifactId>mvnd-logging</artifactId>
4545
</dependency>
46-
<dependency>
47-
<groupId>org.apache.maven</groupId>
48-
<artifactId>maven-embedder</artifactId>
49-
</dependency>
5046
<dependency>
5147
<groupId>org.slf4j</groupId>
5248
<artifactId>jul-to-slf4j</artifactId>

client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
import java.util.stream.Collectors;
4646
import java.util.stream.Stream;
4747

48+
import org.apache.maven.api.cli.extensions.CoreExtension;
4849
import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader;
49-
import org.apache.maven.cli.internal.extension.model.CoreExtension;
5050
import org.mvndaemon.mvnd.common.Environment;
5151
import org.mvndaemon.mvnd.common.InterpolationHelper;
5252
import org.mvndaemon.mvnd.common.Os;

daemon/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
</dependency>
6161
<dependency>
6262
<groupId>org.apache.maven</groupId>
63-
<artifactId>maven-embedder</artifactId>
63+
<artifactId>maven-resolver-provider</artifactId>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.apache.maven</groupId>
67+
<artifactId>maven-cli</artifactId>
6468
</dependency>
6569
<dependency>
6670
<groupId>org.codehaus.plexus</groupId>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.cli;
20+
21+
import java.util.Collection;
22+
import java.util.List;
23+
import java.util.ListIterator;
24+
import java.util.Map;
25+
import java.util.Optional;
26+
27+
import org.apache.commons.cli.CommandLine;
28+
import org.apache.commons.cli.Option;
29+
import org.apache.commons.cli.Options;
30+
import org.apache.commons.cli.ParseException;
31+
import org.apache.maven.cling.invoker.mvn.CommonsCliMavenOptions;
32+
import org.codehaus.plexus.interpolation.BasicInterpolator;
33+
import org.codehaus.plexus.interpolation.InterpolationException;
34+
import org.mvndaemon.mvnd.common.Environment;
35+
36+
import static org.apache.maven.cling.invoker.Utils.createInterpolator;
37+
38+
public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions implements DaemonMavenOptions {
39+
public static CommonsCliDaemonMavenOptions parse(String source, String[] args) throws ParseException {
40+
CLIManager cliManager = new CLIManager();
41+
return new CommonsCliDaemonMavenOptions(source, cliManager, cliManager.parse(args));
42+
}
43+
44+
protected CommonsCliDaemonMavenOptions(String source, CLIManager cliManager, CommandLine commandLine) {
45+
super(source, cliManager, commandLine);
46+
}
47+
48+
public org.apache.commons.cli.Options getOptions() {
49+
return this.cliManager.getOptions();
50+
}
51+
52+
@Override
53+
public Optional<Boolean> rawStreams() {
54+
if (commandLine.hasOption(CLIManager.RAW_STREAMS)
55+
|| Environment.MVND_RAW_STREAMS.asOptional().isPresent()) {
56+
return Optional.of(Boolean.TRUE);
57+
}
58+
return Optional.empty();
59+
}
60+
61+
private static CommonsCliDaemonMavenOptions interpolate(
62+
CommonsCliDaemonMavenOptions options, Collection<Map<String, String>> properties) {
63+
try {
64+
// now that we have properties, interpolate all arguments
65+
BasicInterpolator interpolator = createInterpolator(properties);
66+
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
67+
commandLineBuilder.setDeprecatedHandler(o -> {});
68+
for (Option option : options.commandLine.getOptions()) {
69+
if (!CLIManager.USER_PROPERTY.equals(option.getOpt())) {
70+
List<String> values = option.getValuesList();
71+
for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) {
72+
it.set(interpolator.interpolate(it.next()));
73+
}
74+
}
75+
commandLineBuilder.addOption(option);
76+
}
77+
for (String arg : options.commandLine.getArgList()) {
78+
commandLineBuilder.addArg(interpolator.interpolate(arg));
79+
}
80+
return new CommonsCliDaemonMavenOptions(
81+
options.source, (CLIManager) options.cliManager, commandLineBuilder.build());
82+
} catch (InterpolationException e) {
83+
throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e);
84+
}
85+
}
86+
87+
@Override
88+
public DaemonMavenOptions interpolate(Collection<Map<String, String>> properties) {
89+
return interpolate(this, properties);
90+
}
91+
92+
protected static class CLIManager extends CommonsCliMavenOptions.CLIManager {
93+
public static final String RAW_STREAMS = "ras";
94+
95+
@Override
96+
protected void prepareOptions(Options options) {
97+
super.prepareOptions(options);
98+
options.addOption(Option.builder(RAW_STREAMS)
99+
.longOpt("raw-streams")
100+
.desc("Use raw-streams for daemon communication")
101+
.build());
102+
}
103+
}
104+
}

daemon/src/main/java/org/apache/maven/cli/DaemonCli.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* Simple interface to bridge maven 3.9.x and 4.0.x CLI
2828
*/
29-
public interface DaemonCli {
29+
public interface DaemonCli extends AutoCloseable {
3030
int main(
3131
List<String> args,
3232
String workingDir,

0 commit comments

Comments
 (0)