Merge pull request #190 from gnodet/refactor

Use issue annotations, move some classes out of org.apache.maven package
This commit is contained in:
Guillaume Nodet
2020-11-06 10:26:00 +01:00
committed by GitHub
14 changed files with 153 additions and 361 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;
@@ -72,7 +71,6 @@ import org.apache.maven.extension.internal.CoreExports;
import org.apache.maven.extension.internal.CoreExtensionEntry;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.plugin.PluginRealmCache;
import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.properties.internal.SystemProperties;
@@ -93,8 +91,9 @@ 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.plugin.CliPluginRealmCache;
import org.jboss.fuse.mvnd.logging.smart.LoggingExecutionListener;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -103,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
@@ -167,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 {
@@ -451,14 +458,12 @@ public class DaemonMavenCli {
}
final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);
final CliPluginRealmCache realmCache = new CliPluginRealmCache();
container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
bind(CoreExports.class).toInstance(exports);
bind(PluginRealmCache.class).toInstance(realmCache);
}
});
@@ -474,7 +479,6 @@ public class DaemonMavenCli {
}
eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
eventSpyDispatcher.getEventSpies().add(realmCache.asEventSpy());
maven = container.lookup(Maven.class);
@@ -1042,7 +1046,7 @@ public class DaemonMavenCli {
ExecutionListener executionListener = new ExecutionEventLogger();
if (eventSpyDispatcher != null) {
executionListener = eventSpyDispatcher.chainListener(executionListener);
executionListener = new LoggingExecutionListener(eventSpyDispatcher.chainListener(executionListener));
}
String alternatePomFile = null;

View File

@@ -1,123 +0,0 @@
/*
* 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.eventspy.internal;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.ExecutionListener;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.aether.RepositoryListener;
import org.jboss.fuse.mvnd.logging.smart.LoggingExecutionListener;
/**
* Dispatches callbacks to all registered eventspies.
* <p>
* Adapted from
* https://github.com/apache/maven/blob/maven-3.6.3/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java
* in order to wrap the ExecutionListener into a {@link org.jboss.fuse.mvnd.logging.smart.LoggingExecutionListener}.
*/
@Component(role = EventSpyDispatcher.class)
public class EventSpyDispatcher {
@Requirement
private Logger logger;
@Requirement(role = EventSpy.class)
private List<EventSpy> eventSpies;
public void setEventSpies(List<EventSpy> eventSpies) {
// make copy to get rid of needless overhead for dynamic lookups
this.eventSpies = new ArrayList<>(eventSpies);
}
public List<EventSpy> getEventSpies() {
return eventSpies;
}
public ExecutionListener chainListener(ExecutionListener listener) {
return new LoggingExecutionListener(doChainListener(listener));
}
protected ExecutionListener doChainListener(ExecutionListener listener) {
if (eventSpies.isEmpty()) {
return listener;
}
return new EventSpyExecutionListener(this, listener);
}
public RepositoryListener chainListener(RepositoryListener listener) {
if (eventSpies.isEmpty()) {
return listener;
}
return new EventSpyRepositoryListener(this, listener);
}
public void init(EventSpy.Context context) {
if (eventSpies.isEmpty()) {
return;
}
for (EventSpy eventSpy : eventSpies) {
try {
eventSpy.init(context);
} catch (Exception | LinkageError e) {
logError("initialize", e, eventSpy);
}
}
}
public void onEvent(Object event) {
if (eventSpies.isEmpty()) {
return;
}
for (EventSpy eventSpy : eventSpies) {
try {
eventSpy.onEvent(event);
} catch (Exception | LinkageError e) {
logError("notify", e, eventSpy);
}
}
}
public void close() {
if (eventSpies.isEmpty()) {
return;
}
for (EventSpy eventSpy : eventSpies) {
try {
eventSpy.close();
} catch (Exception | LinkageError e) {
logError("close", e, eventSpy);
}
}
}
private void logError(String action, Throwable e, EventSpy spy) {
String msg = "Failed to " + action + " spy " + spy.getClass().getName() + ": " + e.getMessage();
if (logger.isDebugEnabled()) {
logger.warn(msg, e);
} else {
logger.warn(msg);
}
}
}

View File

@@ -31,6 +31,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidArtifactRTException;
@@ -61,8 +64,6 @@ import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.building.StringModelSource;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
@@ -74,6 +75,7 @@ import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.WorkspaceRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.sisu.Typed;
/**
* DefaultProjectBuilder
@@ -81,36 +83,41 @@ import org.eclipse.aether.resolution.ArtifactResult;
* File origin:
* https://github.com/apache/maven/blob/maven-3.6.2/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
*/
@Component(role = ProjectBuilder.class)
@Named
@Singleton
@Typed(ProjectBuilder.class)
public class CachingProjectBuilder
implements ProjectBuilder {
@Requirement
@Inject
private Logger logger;
@Requirement
@Inject
private ModelBuilder modelBuilder;
@Requirement
@Inject
private ModelProcessor modelProcessor;
@Requirement
@Inject
private ProjectBuildingHelper projectBuildingHelper;
@Requirement
@Inject
private MavenRepositorySystem repositorySystem;
@Requirement
@Inject
private org.eclipse.aether.RepositorySystem repoSystem;
@Requirement
@Inject
private RemoteRepositoryManager repositoryManager;
@Requirement
@Inject
private ProjectDependenciesResolver dependencyResolver;
private final ModelCache modelCache = new ReactorModelCache();
public CachingProjectBuilder() {
}
// ----------------------------------------------------------------------
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
@@ -161,7 +168,8 @@ public class CachingProjectBuilder
} catch (ModelBuildingException e) {
result = e.getResult();
if (result == null || result.getEffectiveModel() == null) {
throw new ProjectBuildingException(e.getModelId(), e.getMessage(), pomFile, e);
throw (ProjectBuildingException) new ProjectBuildingException(e.getModelId(), e.getMessage(), pomFile)
.initCause(e);
}
// validation error, continue project building and delay failing to help IDEs
error = e;

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

@@ -20,10 +20,8 @@ package org.jboss.fuse.mvnd.plugin;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchEvent.Kind;
@@ -31,7 +29,6 @@ import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -43,10 +40,6 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginRealmCache;
import org.apache.maven.project.MavenProject;
@@ -58,6 +51,8 @@ import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.WorkspaceRepository;
import org.eclipse.sisu.Priority;
import org.eclipse.sisu.Typed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,7 +64,8 @@ import org.slf4j.LoggerFactory;
*/
@Singleton
@Named
@Default
@Priority(10)
@Typed(PluginRealmCache.class)
public class CliPluginRealmCache
implements PluginRealmCache, Disposable {
/**
@@ -223,7 +219,7 @@ public class CliPluginRealmCache
final Path dir = p.getParent();
registrationsByDir.compute(dir, (key, value) -> {
if (value == null) {
log.debug("Starting to watch path {}", key);
LOG.debug("Starting to watch path {}", key);
try {
final WatchKey watchKey = dir.register(watchService, StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
@@ -233,7 +229,7 @@ public class CliPluginRealmCache
}
} else {
int cnt = value.count.incrementAndGet();
log.debug("Already {} watchers for path {}", cnt, key);
LOG.debug("Already {} watchers for path {}", cnt, key);
return value;
}
});
@@ -253,16 +249,16 @@ public class CliPluginRealmCache
final Path dir = p.getParent();
registrationsByDir.compute(dir, (key, value) -> {
if (value == null) {
log.debug("Already unwatchers for path {}", key);
LOG.debug("Already unwatchers for path {}", key);
return null;
} else {
final int cnt = value.count.decrementAndGet();
if (cnt <= 0) {
log.debug("Unwatching path {}", key);
LOG.debug("Unwatching path {}", key);
value.watchKey.cancel();
return null;
} else {
log.debug("Still {} watchers for path {}", cnt, key);
LOG.debug("Still {} watchers for path {}", cnt, key);
return value;
}
}
@@ -279,15 +275,15 @@ public class CliPluginRealmCache
final WatchKey watchKey = entry.getValue().watchKey;
for (WatchEvent<?> event : watchKey.pollEvents()) {
Kind<?> kind = event.kind();
log.debug("Got watcher event {}", kind.name());
LOG.debug("Got watcher event {}", kind.name());
if (kind == StandardWatchEventKinds.ENTRY_DELETE || kind == StandardWatchEventKinds.ENTRY_MODIFY) {
final Path path = dir.resolve((Path) event.context());
final List<ValidableCacheRecord> records = validRecordsByPath.get(path);
log.debug("Records for path {}: {}", path, records);
LOG.debug("Records for path {}: {}", path, records);
if (records != null) {
synchronized (records) {
for (ValidableCacheRecord record : records) {
log.debug("Invalidating recorder of path {}", path);
LOG.debug("Invalidating recorder of path {}", path);
record.valid = false;
remove(record);
}
@@ -337,45 +333,10 @@ public class CliPluginRealmCache
}
private static final Logger log = LoggerFactory.getLogger(CliPluginRealmCache.class);
private static final Logger LOG = LoggerFactory.getLogger(CliPluginRealmCache.class);
protected final Map<Key, ValidableCacheRecord> cache = new ConcurrentHashMap<>();
private final RecordValidator watcher;
private final EventSpy eventSpy = new AbstractEventSpy() {
private Path multiModuleProjectDirectory;
@Override
public void onEvent(Object event) throws Exception {
try {
if (event instanceof MavenExecutionRequest) {
/* Store the multiModuleProjectDirectory path */
multiModuleProjectDirectory = ((MavenExecutionRequest) event).getMultiModuleProjectDirectory().toPath();
} else if (event instanceof MavenExecutionResult) {
/* Evict the entries refering to jars under multiModuleProjectDirectory */
final Iterator<Entry<Key, ValidableCacheRecord>> i = cache.entrySet().iterator();
while (i.hasNext()) {
final Entry<Key, ValidableCacheRecord> entry = i.next();
final ValidableCacheRecord record = entry.getValue();
for (URL url : record.getRealm().getURLs()) {
if (url.getProtocol().equals("file")) {
final Path path = Paths.get(url.toURI());
if (path.startsWith(multiModuleProjectDirectory)) {
log.debug(
"Removing PluginRealmCache entry {} because it refers to an artifact in the build tree {}",
entry.getKey(), path);
record.dispose();
i.remove();
break;
}
}
}
}
}
} catch (Exception e) {
log.warn("Could not notify CliPluginRealmCache", e);
}
}
};
public CliPluginRealmCache() {
this.watcher = new RecordValidator();
@@ -420,8 +381,4 @@ public class CliPluginRealmCache
flush();
}
public EventSpy asEventSpy() {
return eventSpy;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2020 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.jboss.fuse.mvnd.plugin;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.plugin.PluginRealmCache;
import org.eclipse.sisu.Typed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Named
@Singleton
@Typed(EventSpy.class)
public class CliPluginRealmCacheEventSpy extends AbstractEventSpy {
private static final Logger LOG = LoggerFactory.getLogger(CliPluginRealmCacheEventSpy.class);
private final CliPluginRealmCache cache;
private Path multiModuleProjectDirectory;
@Inject
public CliPluginRealmCacheEventSpy(CliPluginRealmCache cache) {
this.cache = cache;
}
@Override
public void onEvent(Object event) throws Exception {
try {
if (event instanceof MavenExecutionRequest) {
/* Store the multiModuleProjectDirectory path */
multiModuleProjectDirectory = ((MavenExecutionRequest) event).getMultiModuleProjectDirectory().toPath();
} else if (event instanceof MavenExecutionResult) {
/* Evict the entries refering to jars under multiModuleProjectDirectory */
final Iterator<Map.Entry<PluginRealmCache.Key, CliPluginRealmCache.ValidableCacheRecord>> i = cache.cache
.entrySet().iterator();
while (i.hasNext()) {
final Map.Entry<PluginRealmCache.Key, CliPluginRealmCache.ValidableCacheRecord> entry = i.next();
final CliPluginRealmCache.ValidableCacheRecord record = entry.getValue();
for (URL url : record.getRealm().getURLs()) {
if (url.getProtocol().equals("file")) {
final Path path = Paths.get(url.toURI());
if (path.startsWith(multiModuleProjectDirectory)) {
LOG.debug(
"Removing PluginRealmCache entry {} because it refers to an artifact in the build tree {}",
entry.getKey(), path);
record.dispose();
i.remove();
break;
}
}
}
}
}
} catch (Exception e) {
LOG.warn("Could not notify CliPluginRealmCache", e);
}
}
}

View File

@@ -26,15 +26,18 @@ import java.util.stream.Stream;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.sisu.Typed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
@Named("timing")
@Typed(EventSpy.class)
public class BuildTimeEventSpy extends AbstractEventSpy {
public static final int MAX_NAME_LENGTH = 58;

View File

@@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<component-set>
<components>
<component>
<role>org.apache.maven.plugin.PluginRealmCache</role>
<implementation>org.jboss.fuse.mvnd.plugin.CliPluginRealmCache</implementation>
<isolated-realm>false</isolated-realm>
</component>
<component>
<role>org.apache.maven.project.ProjectBuilder</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.project.CachingProjectBuilder</implementation>
<description />
<isolated-realm>false</isolated-realm>
<requirements>
<requirement>
<role>org.codehaus.plexus.logging.Logger</role>
<field-name>logger</field-name>
</requirement>
<requirement>
<role>org.apache.maven.model.building.ModelBuilder</role>
<field-name>modelBuilder</field-name>
</requirement>
<requirement>
<role>org.apache.maven.model.building.ModelProcessor</role>
<field-name>modelProcessor</field-name>
</requirement>
<requirement>
<role>org.apache.maven.project.ProjectBuildingHelper</role>
<field-name>projectBuildingHelper</field-name>
</requirement>
<requirement>
<role>org.apache.maven.bridge.MavenRepositorySystem</role>
<field-name>repositorySystem</field-name>
</requirement>
<requirement>
<role>org.eclipse.aether.RepositorySystem</role>
<field-name>repoSystem</field-name>
</requirement>
<requirement>
<role>org.eclipse.aether.impl.RemoteRepositoryManager</role>
<field-name>repositoryManager</field-name>
</requirement>
<requirement>
<role>org.apache.maven.project.ProjectDependenciesResolver</role>
<field-name>dependencyResolver</field-name>
</requirement>
</requirements>
</component>
</components>
</component-set>

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" />