-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Changes: * there is only one parser for "just maven", no need for 3 * aligned scopes (public) of local context for simplicity, we can fix visibility later * allow custom guice modules (unused, may undo this) * split logging setup in two steps: config and activate --- https://issues.apache.org/jira/browse/MNG-8283
- Loading branch information
Showing
21 changed files
with
173 additions
and
632 deletions.
There are no files selected for viewing
32 changes: 0 additions & 32 deletions
32
api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/local/LocalMavenParser.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
...-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenInvokerRequest.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
...ven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenOptions.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
...aven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenParser.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/BaseMavenParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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.cling.invoker.mvn; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
import org.apache.maven.api.cli.Options; | ||
import org.apache.maven.api.cli.ParserException; | ||
import org.apache.maven.api.cli.ParserRequest; | ||
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.api.cli.mvn.MavenParser; | ||
import org.apache.maven.cling.invoker.BaseParser; | ||
|
||
public abstract class BaseMavenParser<O extends MavenOptions, R extends MavenInvokerRequest<O>> extends BaseParser<O, R> | ||
implements MavenParser<R> { | ||
@SuppressWarnings("ParameterNumber") | ||
@Override | ||
protected abstract R getInvokerRequest( | ||
ParserRequest parserRequest, | ||
Path cwd, | ||
Path installationDirectory, | ||
Path userHomeDirectory, | ||
Map<String, String> userProperties, | ||
Map<String, String> systemProperties, | ||
Path topDirectory, | ||
Path rootDirectory, | ||
ArrayList<CoreExtension> extensions, | ||
Options options); | ||
|
||
@Override | ||
protected List<O> parseCliOptions(Path rootDirectory, List<String> args) throws ParserException, IOException { | ||
ArrayList<O> result = new ArrayList<>(); | ||
// CLI args | ||
result.add(parseMavenCliOptions(args)); | ||
// maven.config; if exists | ||
Path mavenConfig = rootDirectory.resolve(".mvn/maven.config"); | ||
if (Files.isRegularFile(mavenConfig)) { | ||
result.add(parseMavenConfigOptions(mavenConfig)); | ||
} | ||
return result; | ||
} | ||
|
||
protected O parseMavenCliOptions(List<String> args) throws ParserException { | ||
return parseArgs(Options.SOURCE_CLI, args); | ||
} | ||
|
||
protected O parseMavenConfigOptions(Path configFile) throws ParserException, IOException { | ||
try (Stream<String> lines = Files.lines(configFile, Charset.defaultCharset())) { | ||
List<String> args = | ||
lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#")).toList(); | ||
O options = parseArgs("maven.config", args); | ||
if (options.goals().isPresent()) { | ||
// This file can only contain options, not args (goals or phases) | ||
throw new ParserException("Unrecognized maven.config file entries: " | ||
+ options.goals().get()); | ||
} | ||
return options; | ||
} | ||
} | ||
|
||
protected abstract O parseArgs(String source, List<String> args) throws ParserException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.