diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java index 812b62824..fd49d4073 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DaemonParameters.java @@ -126,14 +126,16 @@ public Path userDir() { 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() { diff --git a/daemon/src/main/java/org/apache/maven/cli/CliRequestBuilder.java b/daemon/src/main/java/org/apache/maven/cli/CliRequestBuilder.java deleted file mode 100644 index 625d06575..000000000 --- a/daemon/src/main/java/org/apache/maven/cli/CliRequestBuilder.java +++ /dev/null @@ -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 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; - } - -} diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index 64ace0c15..9587cc01d 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -54,7 +54,6 @@ 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.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.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 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 DaemonMavenCli() throws Exception { container(); } - // TODO need to externalize CliRequest + public int main(List arguments, + String workingDirectory, + String projectDirectory, + Map 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 clientEnv) throws Exception { Properties props = (Properties) System.getProperties().clone(); try { @@ -451,14 +458,12 @@ void container() } 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 @@ protected void configure() { } eventSpyDispatcher = container.lookup(EventSpyDispatcher.class); - eventSpyDispatcher.getEventSpies().add(realmCache.asEventSpy()); maven = container.lookup(Maven.class); @@ -1042,7 +1046,7 @@ private void populateRequest(CliRequest cliRequest, MavenExecutionRequest reques ExecutionListener executionListener = new ExecutionEventLogger(); if (eventSpyDispatcher != null) { - executionListener = eventSpyDispatcher.chainListener(executionListener); + executionListener = new LoggingExecutionListener(eventSpyDispatcher.chainListener(executionListener)); } String alternatePomFile = null; diff --git a/daemon/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java b/daemon/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java deleted file mode 100644 index c6cc19105..000000000 --- a/daemon/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java +++ /dev/null @@ -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. - *

- * 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 eventSpies; - - public void setEventSpies(List eventSpies) { - // make copy to get rid of needless overhead for dynamic lookups - this.eventSpies = new ArrayList<>(eventSpies); - } - - public List 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); - } - } - -} diff --git a/daemon/src/main/java/org/apache/maven/project/CachingProjectBuilder.java b/daemon/src/main/java/org/apache/maven/project/CachingProjectBuilder.java index f1a90f53a..b025b9cfd 100644 --- a/daemon/src/main/java/org/apache/maven/project/CachingProjectBuilder.java +++ b/daemon/src/main/java/org/apache/maven/project/CachingProjectBuilder.java @@ -31,6 +31,9 @@ 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.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.WorkspaceRepository; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.sisu.Typed; /** * DefaultProjectBuilder @@ -81,36 +83,41 @@ * 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 @@ private ProjectBuildingResult build(File pomFile, ModelSource modelSource, Inter } 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; diff --git a/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java b/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java index 518dfa596..ad370665c 100644 --- a/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java @@ -21,7 +21,6 @@ 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.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 @@ private void handle(DaemonConnection connection, BuildRequest buildRequest) { 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 queue = new PriorityBlockingQueue(64, Comparator.comparingInt(this::getClassOrder).thenComparingLong(Message::timestamp)); @@ -440,7 +432,10 @@ private void handle(DaemonConnection connection, BuildRequest buildRequest) { }); 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) { diff --git a/daemon/src/main/java/org/apache/maven/cli/logging/SimpleAppender.java b/daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/SimpleAppender.java similarity index 94% rename from daemon/src/main/java/org/apache/maven/cli/logging/SimpleAppender.java rename to daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/SimpleAppender.java index 6ef1981d2..4dec8a851 100644 --- a/daemon/src/main/java/org/apache/maven/cli/logging/SimpleAppender.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/SimpleAppender.java @@ -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 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 { @Override diff --git a/daemon/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java b/daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/Slf4jLogger.java similarity index 94% rename from daemon/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java rename to daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/Slf4jLogger.java index 4a26c2252..8a8426b0f 100644 --- a/daemon/src/main/java/org/apache/maven/cli/logging/Slf4jLogger.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/Slf4jLogger.java @@ -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 @@ *

* 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 */ diff --git a/daemon/src/main/java/org/apache/maven/cli/logging/Slf4jLoggerManager.java b/daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/Slf4jLoggerManager.java similarity index 94% rename from daemon/src/main/java/org/apache/maven/cli/logging/Slf4jLoggerManager.java rename to daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/Slf4jLoggerManager.java index 632f6ab70..96685d475 100644 --- a/daemon/src/main/java/org/apache/maven/cli/logging/Slf4jLoggerManager.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/logging/internal/Slf4jLoggerManager.java @@ -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 @@ *

* 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 */ diff --git a/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCache.java b/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCache.java index 9d49044d5..afb35117a 100644 --- a/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCache.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCache.java @@ -20,10 +20,8 @@ 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.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.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.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 @@ */ @Singleton @Named -@Default +@Priority(10) +@Typed(PluginRealmCache.class) public class CliPluginRealmCache implements PluginRealmCache, Disposable { /** @@ -223,7 +219,7 @@ void add(ValidableCacheRecord record) { 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 @@ void add(ValidableCacheRecord record) { } } 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 @@ void remove(ValidableCacheRecord record) { 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 void validateRecords() { 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 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 ValidableCacheRecord newRecord(ClassRealm pluginRealm, List plu } - private static final Logger log = LoggerFactory.getLogger(CliPluginRealmCache.class); + private static final Logger LOG = LoggerFactory.getLogger(CliPluginRealmCache.class); + protected final Map 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> i = cache.entrySet().iterator(); - while (i.hasNext()) { - final Entry 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 void dispose() { flush(); } - public EventSpy asEventSpy() { - return eventSpy; - } - } diff --git a/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCacheEventSpy.java b/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCacheEventSpy.java new file mode 100644 index 000000000..7335ba45e --- /dev/null +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/plugin/CliPluginRealmCacheEventSpy.java @@ -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> i = cache.cache + .entrySet().iterator(); + while (i.hasNext()) { + final Map.Entry 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); + } + } +} diff --git a/daemon/src/main/java/org/jboss/fuse/mvnd/timing/BuildTimeEventSpy.java b/daemon/src/main/java/org/jboss/fuse/mvnd/timing/BuildTimeEventSpy.java index 23a894173..193f0c4a7 100644 --- a/daemon/src/main/java/org/jboss/fuse/mvnd/timing/BuildTimeEventSpy.java +++ b/daemon/src/main/java/org/jboss/fuse/mvnd/timing/BuildTimeEventSpy.java @@ -26,15 +26,18 @@ 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; diff --git a/daemon/src/main/resources/META-INF/plexus/components.xml b/daemon/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index c0ae5e3c4..000000000 --- a/daemon/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - org.apache.maven.plugin.PluginRealmCache - org.jboss.fuse.mvnd.plugin.CliPluginRealmCache - false - - - org.apache.maven.project.ProjectBuilder - default - org.apache.maven.project.CachingProjectBuilder - - false - - - org.codehaus.plexus.logging.Logger - logger - - - org.apache.maven.model.building.ModelBuilder - modelBuilder - - - org.apache.maven.model.building.ModelProcessor - modelProcessor - - - org.apache.maven.project.ProjectBuildingHelper - projectBuildingHelper - - - org.apache.maven.bridge.MavenRepositorySystem - repositorySystem - - - org.eclipse.aether.RepositorySystem - repoSystem - - - org.eclipse.aether.impl.RemoteRepositoryManager - repositoryManager - - - org.apache.maven.project.ProjectDependenciesResolver - dependencyResolver - - - - - diff --git a/dist/src/main/distro/mvn/conf/logging/logback-mvn.xml b/dist/src/main/distro/mvn/conf/logging/logback-mvn.xml index 3d344993c..f6e604e27 100644 --- a/dist/src/main/distro/mvn/conf/logging/logback-mvn.xml +++ b/dist/src/main/distro/mvn/conf/logging/logback-mvn.xml @@ -28,7 +28,7 @@ - +