-
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.
- Loading branch information
Showing
27 changed files
with
4,068 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven</artifactId> | ||
<version>4.0.0-beta-5-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>maven-cli</artifactId> | ||
|
||
<name>Maven CLI</name> | ||
<description>Maven CLI component, with CLI and logging support.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-embedder</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-classworlds</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.sisu</groupId> | ||
<artifactId>org.eclipse.sisu.plexus</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-jline</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-cli</groupId> | ||
<artifactId>commons-cli</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.jimfs</groupId> | ||
<artifactId>jimfs</artifactId> | ||
<version>1.3.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>org.apache.maven.cling.MavenCling</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
92 changes: 92 additions & 0 deletions
92
maven-cli/src/main/java/org/apache/maven/cling/MavenCling.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,92 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.maven.cling.invoker.InvokerException; | ||
import org.apache.maven.cling.invoker.ParserException; | ||
import org.apache.maven.cling.invoker.local.LocalInvoker; | ||
import org.apache.maven.cling.invoker.local.LocalParser; | ||
import org.apache.maven.jline.MessageUtils; | ||
import org.codehaus.plexus.classworlds.ClassWorld; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Maven CLI "new-gen". | ||
*/ | ||
public class MavenCling { | ||
static final String CORE_CLASS_REALM_ID = "plexus.core"; | ||
|
||
/** | ||
* "Normal" Java entry point. Note: Maven uses ClassWorld Launcher and this entry point is NOT used under normal | ||
* circumstances. | ||
*/ | ||
public static void main(String[] args) throws IOException { | ||
int exitCode = new MavenCling().run(args); | ||
System.exit(exitCode); | ||
} | ||
|
||
/** | ||
* ClassWorld Launcher "enhanced" entry point: returning exitCode and accepts Class World. | ||
*/ | ||
public static int main(String[] args, ClassWorld world) throws IOException { | ||
return new MavenCling(world).run(args); | ||
} | ||
|
||
private final ClassWorld classWorld; | ||
private final boolean classWorldManaged; | ||
|
||
/** | ||
* Ctor that creates "managed" ClassWorld. This constructor is not used in "normal" circumstances. | ||
*/ | ||
public MavenCling() { | ||
this.classWorld = | ||
new ClassWorld(CORE_CLASS_REALM_ID, Thread.currentThread().getContextClassLoader()); | ||
this.classWorldManaged = true; | ||
} | ||
|
||
/** | ||
* Ctor used when running in ClassWorlds Launcher. | ||
*/ | ||
public MavenCling(ClassWorld classWorld) { | ||
this.classWorld = requireNonNull(classWorld); | ||
this.classWorldManaged = false; | ||
} | ||
|
||
/** | ||
* The main entry point. | ||
*/ | ||
public int run(String[] args) throws IOException { | ||
MessageUtils.systemInstall(); | ||
MessageUtils.registerShutdownHook(); | ||
try { | ||
return new LocalInvoker(classWorld).invoke(new LocalParser().parse(args)); | ||
} catch (InvokerException | ParserException e) { | ||
System.err.println(e.getMessage()); | ||
return 1; | ||
} finally { | ||
if (classWorldManaged) { | ||
classWorld.close(); | ||
} | ||
MessageUtils.systemUninstall(); | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
maven-cli/src/main/java/org/apache/maven/cling/MavenTool.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,95 @@ | ||
/* | ||
* 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; | ||
|
||
import javax.lang.model.SourceVersion; | ||
import javax.tools.Tool; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.util.Collections; | ||
import java.util.EnumSet; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.cling.invoker.InvokerException; | ||
import org.apache.maven.cling.invoker.ParserException; | ||
import org.apache.maven.cling.invoker.ParserRequest; | ||
import org.apache.maven.cling.invoker.local.LocalInvoker; | ||
import org.apache.maven.cling.invoker.local.LocalParser; | ||
import org.apache.maven.jline.MessageUtils; | ||
import org.codehaus.plexus.classworlds.ClassWorld; | ||
|
||
/** | ||
* Maven Tool. | ||
*/ | ||
public class MavenTool implements Tool { | ||
@Override | ||
public String name() { | ||
return "mvn"; | ||
} | ||
|
||
@Override | ||
public Set<SourceVersion> getSourceVersions() { | ||
// basically "all"? | ||
return Collections.unmodifiableSet(EnumSet.range(SourceVersion.RELEASE_3, SourceVersion.latest())); | ||
} | ||
|
||
@Override | ||
public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { | ||
PrintStream stderr = toPsOrDef(err, System.err); | ||
try (ClassWorld classWorld = new ClassWorld( | ||
MavenCling.CORE_CLASS_REALM_ID, Thread.currentThread().getContextClassLoader())) { | ||
MessageUtils.systemInstall(); | ||
MessageUtils.registerShutdownHook(); | ||
try { | ||
return new LocalInvoker(classWorld) | ||
.invoke(new LocalParser() | ||
.parse(ParserRequest.builder(arguments) | ||
.in(in) | ||
.out(toPs(out)) | ||
.err(toPs(err)) | ||
.build())); | ||
} catch (InvokerException | ParserException e) { | ||
e.printStackTrace(stderr); | ||
return 1; | ||
} finally { | ||
MessageUtils.systemUninstall(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(stderr); | ||
return 2; | ||
} | ||
} | ||
|
||
private PrintStream toPs(OutputStream outputStream) { | ||
return toPsOrDef(outputStream, null); | ||
} | ||
|
||
private PrintStream toPsOrDef(OutputStream outputStream, PrintStream def) { | ||
if (outputStream == null) { | ||
return def; | ||
} | ||
if (outputStream instanceof PrintStream ps) { | ||
return ps; | ||
} | ||
return new PrintStream(outputStream); | ||
} | ||
} |
Oops, something went wrong.