Skip to content

Commit

Permalink
Fu
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Jul 29, 2020
1 parent 1c13ff5 commit f0125b7
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand Down Expand Up @@ -439,31 +440,36 @@ public boolean isValid() {

@Override
public void onEvent(Object event) throws Exception {
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();
final boolean startsWith = path.startsWith(multiModuleProjectDirectory);
log.warn("{} {} starts with {}", startsWith, path, multiModuleProjectDirectory);
if (startsWith) {
log.debug(
"Removing PluginRealmCache entry {} because it refers to an artifact in the build tree {}",
entry.getKey(), path);
record.dispose();
i.remove();
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();
final boolean startsWith = path.startsWith(multiModuleProjectDirectory);
log.warn("{} {} starts with {}", startsWith, path, multiModuleProjectDirectory);
if (startsWith) {
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);
}
}

Expand Down

0 comments on commit f0125b7

Please sign in to comment.