Move some classes from org.apache.maven to org.jboss.fuse.mvnd

This commit is contained in:
Guillaume Nodet
2020-11-06 09:19:05 +01:00
parent 314487b732
commit 7e6e127f92
8 changed files with 32 additions and 95 deletions

View File

@@ -126,14 +126,16 @@ public class DaemonParameters {
return value(Environment.USER_DIR)
.orSystemProperty()
.orFail()
.asPath();
.asPath()
.toAbsolutePath();
}
public Path userHome() {
return value(Environment.USER_HOME)
.orSystemProperty()
.orFail()
.asPath();
.asPath()
.toAbsolutePath();
}
public Path suppliedPropertiesPath() {

View File

@@ -1,76 +0,0 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed 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.util.List;
import java.util.Properties;
import org.codehaus.plexus.classworlds.ClassWorld;
public class CliRequestBuilder {
CliRequest request = new CliRequest(null, null);
public CliRequestBuilder arguments(List<String> arguments) {
request.args = arguments.toArray(new String[0]);
return this;
}
public CliRequestBuilder classWorld(ClassWorld classWorld) {
request.classWorld = classWorld;
return this;
}
public CliRequestBuilder workingDirectory(Path workingDirectory) {
request.workingDirectory = workingDirectory.toAbsolutePath().toString();
return this;
}
public CliRequestBuilder projectDirectory(Path projectDirectory) {
request.multiModuleProjectDirectory = projectDirectory.toAbsolutePath().toFile();
return this;
}
public CliRequestBuilder debug(boolean debug) {
request.debug = debug;
return this;
}
public CliRequestBuilder quiet(boolean quiet) {
request.quiet = quiet;
return this;
}
public CliRequestBuilder showErrors(boolean showErrors) {
request.showErrors = showErrors;
return this;
}
public CliRequestBuilder userProperties(Properties userProperties) {
request.userProperties = userProperties;
return this;
}
public CliRequestBuilder systemProperties(Properties systemProperties) {
request.systemProperties = systemProperties;
return this;
}
public CliRequest build() {
return request;
}
}

View File

@@ -54,7 +54,6 @@ import org.apache.maven.cli.configuration.SettingsXmlConfigurationProcessor;
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.logging.Slf4jLoggerManager;
import org.apache.maven.cli.transfer.ConsoleMavenTransferListener;
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
import org.apache.maven.cli.transfer.Slf4jMavenTransferListener;
@@ -92,6 +91,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.transfer.TransferListener;
import org.jboss.fuse.mvnd.common.Environment;
import org.jboss.fuse.mvnd.logging.internal.Slf4jLoggerManager;
import org.jboss.fuse.mvnd.logging.smart.AbstractLoggingSpy;
import org.jboss.fuse.mvnd.logging.smart.LoggingExecutionListener;
import org.slf4j.ILoggerFactory;
@@ -102,8 +102,6 @@ import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
// TODO push all common bits back to plexus cli and prepare for transition to Guice. We don't need 50 ways to make CLIs
/**
* File origin:
* https://github.com/apache/maven/blob/maven-3.6.2/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -166,7 +164,17 @@ public class DaemonMavenCli {
container();
}
// TODO need to externalize CliRequest
public int main(List<String> arguments,
String workingDirectory,
String projectDirectory,
Map<String, String> clientEnv) throws Exception {
CliRequest req = new CliRequest(null, null);
req.args = arguments.toArray(new String[0]);
req.workingDirectory = workingDirectory;
req.multiModuleProjectDirectory = new File(projectDirectory);
return doMain(req, clientEnv);
}
public int doMain(CliRequest cliRequest, Map<String, String> clientEnv) throws Exception {
Properties props = (Properties) System.getProperties().clone();
try {

View File

@@ -21,7 +21,6 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -37,8 +36,6 @@ import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import org.apache.maven.cli.CliRequest;
import org.apache.maven.cli.CliRequestBuilder;
import org.apache.maven.cli.DaemonMavenCli;
import org.apache.maven.execution.MavenSession;
import org.jboss.fuse.mvnd.common.DaemonConnection;
@@ -396,11 +393,6 @@ public class Server implements AutoCloseable, Runnable {
int keepAlive = Environment.DAEMON_KEEP_ALIVE_MS.asInt();
LOGGER.info("Executing request");
CliRequest req = new CliRequestBuilder()
.arguments(buildRequest.getArgs())
.workingDirectory(Paths.get(buildRequest.getWorkingDir()))
.projectDirectory(Paths.get(buildRequest.getProjectDir()))
.build();
BlockingQueue<Message> queue = new PriorityBlockingQueue<Message>(64,
Comparator.comparingInt(this::getClassOrder).thenComparingLong(Message::timestamp));
@@ -440,7 +432,10 @@ public class Server implements AutoCloseable, Runnable {
});
pumper.start();
try {
cli.doMain(req, buildRequest.getEnv());
cli.main(buildRequest.getArgs(),
buildRequest.getWorkingDir(),
buildRequest.getProjectDir(),
buildRequest.getEnv());
LOGGER.info("Build finished, finishing message dispatch");
loggingSpy.finish();
} catch (Throwable t) {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.maven.cli.logging;
package org.jboss.fuse.mvnd.logging.internal;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
@@ -24,6 +24,10 @@ import ch.qos.logback.core.CoreConstants;
import static org.apache.maven.shared.utils.logging.MessageUtils.level;
/**
* This appender acts like the slf4j simple logger.
* It's used
*/
public class SimpleAppender extends AppenderBase<ILoggingEvent> {
@Override

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.cli.logging;
package org.jboss.fuse.mvnd.logging.internal;
import org.codehaus.plexus.logging.Logger;
import org.jboss.fuse.mvnd.logging.smart.ProjectBuildLogAppender;
@@ -29,6 +29,8 @@ import org.slf4j.MDC;
* <p>
* Adapted from
* https://github.com/apache/maven/blob/maven-3.6.3/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java
* The main change is that the MDC property for redirecting the log to the correct maven project is set
* when the logger is instantiated (usually when injected into a mojo).
*
* @author Jason van Zyl
*/

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.cli.logging;
package org.jboss.fuse.mvnd.logging.internal;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.LoggerManager;
@@ -31,6 +31,8 @@ import org.slf4j.LoggerFactory;
* <p>
* Adapted from
* https://github.com/apache/maven/blob/maven-3.6.3/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jLoggerManager.java
* This class has no differences with the above beyond formatting. Its purpose is simply to be able to call the
* Slf4Logger.
*
* @author Jason van Zyl
*/

View File

@@ -28,7 +28,7 @@
<!--
| write project-specific build log messages to ${project.build.directory}/build.log files
-->
<appender name="CONSOLE" class="org.apache.maven.cli.logging.SimpleAppender" />
<appender name="CONSOLE" class="org.jboss.fuse.mvnd.logging.internal.SimpleAppender" />
<logger name="Sisu" level="INFO" />