mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-12 14:18:03 +00:00
Fix #40 Cannot clean on Windows as long as mvnd keeps a plugin from the tree loaded
This commit is contained in:
@@ -416,13 +416,14 @@ public class DaemonMavenCli {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);
|
final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);
|
||||||
|
final CliPluginRealmCache realmCache = new CliPluginRealmCache();
|
||||||
|
|
||||||
container = new DefaultPlexusContainer(cc, new AbstractModule() {
|
container = new DefaultPlexusContainer(cc, new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
|
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
|
||||||
bind(CoreExports.class).toInstance(exports);
|
bind(CoreExports.class).toInstance(exports);
|
||||||
bind(PluginRealmCache.class).toInstance(new CliPluginRealmCache());
|
bind(PluginRealmCache.class).toInstance(realmCache);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -440,6 +441,7 @@ public class DaemonMavenCli {
|
|||||||
// container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() );
|
// container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() );
|
||||||
|
|
||||||
eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
|
eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
|
||||||
|
eventSpyDispatcher.getEventSpies().add(realmCache.asEventSpy());
|
||||||
|
|
||||||
maven = container.lookup(Maven.class);
|
maven = container.lookup(Maven.class);
|
||||||
|
|
||||||
|
@@ -20,9 +20,12 @@ package org.jboss.fuse.mvnd.plugin;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardWatchEventKinds;
|
import java.nio.file.StandardWatchEventKinds;
|
||||||
import java.nio.file.WatchEvent;
|
import java.nio.file.WatchEvent;
|
||||||
import java.nio.file.WatchEvent.Kind;
|
import java.nio.file.WatchEvent.Kind;
|
||||||
@@ -32,6 +35,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||||||
import java.nio.file.attribute.FileTime;
|
import java.nio.file.attribute.FileTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -45,6 +49,9 @@ import javax.inject.Named;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import org.apache.maven.RepositoryUtils;
|
import org.apache.maven.RepositoryUtils;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
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.model.Plugin;
|
||||||
import org.apache.maven.plugin.PluginRealmCache;
|
import org.apache.maven.plugin.PluginRealmCache;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
@@ -427,6 +434,51 @@ 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<>();
|
protected final Map<Key, ValidableCacheRecord> cache = new ConcurrentHashMap<>();
|
||||||
private final RecordValidator watcher;
|
private final RecordValidator watcher;
|
||||||
|
private final EventSpy eventSpy = new EventSpy() {
|
||||||
|
|
||||||
|
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()
|
||||||
|
.toRealPath();
|
||||||
|
} 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()).toRealPath();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Context context) throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public CliPluginRealmCache() {
|
public CliPluginRealmCache() {
|
||||||
this.watcher = System.getProperty("os.name").toLowerCase().contains("mac")
|
this.watcher = System.getProperty("os.name").toLowerCase().contains("mac")
|
||||||
@@ -488,4 +540,8 @@ public class CliPluginRealmCache
|
|||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EventSpy asEventSpy() {
|
||||||
|
return eventSpy;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,7 @@ public class ModuleAndPluginNativeIT {
|
|||||||
|
|
||||||
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
final ClientOutput output = Mockito.mock(ClientOutput.class);
|
||||||
client.execute(output,
|
client.execute(output,
|
||||||
// "clean", workaround for https://github.com/mvndaemon/mvnd/issues/40
|
"clean",
|
||||||
"install", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess();
|
"install", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess();
|
||||||
|
|
||||||
Assertions.assertThat(helloPath).exists();
|
Assertions.assertThat(helloPath).exists();
|
||||||
|
Reference in New Issue
Block a user