Try to fix some with pom changes not being detected

This commit is contained in:
Guillaume Nodet
2020-02-10 08:43:43 +01:00
parent 2f6a343a52
commit c0644c55da
2 changed files with 66 additions and 7 deletions

View File

@@ -16,6 +16,7 @@
package org.jboss.fuse.mvnd.daemon;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
@@ -24,6 +25,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
@@ -113,7 +115,12 @@ public class Server implements AutoCloseable, Runnable {
try {
registry.close();
} finally {
socket.close();
try {
socket.close();
} finally {
clearCache("sun.net.www.protocol.jar.JarFileFactory", "urlCache");
clearCache("sun.net.www.protocol.jar.JarFileFactory", "fileCache");
}
}
}
}
@@ -122,6 +129,18 @@ public class Server implements AutoCloseable, Runnable {
}
}
public void clearCache(String clazzName, String fieldName) {
try {
Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass(clazzName);
Field f = clazz.getDeclaredField(fieldName);
f.setAccessible(true);
Map cache = (Map) f.get(null);
cache.clear();
} catch (Throwable t) {
// ignore
}
}
public void run() {
try {
executor.scheduleAtFixedRate(this::expirationCheck,

View File

@@ -16,12 +16,19 @@
package org.jboss.fuse.mvnd.plugin;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.enterprise.inject.Default;
import javax.inject.Named;
@@ -146,19 +153,52 @@ public class CliPluginRealmCache
}
protected static class TimestampedCacheRecord extends CacheRecord {
long timestamp;
static class ArtifactTimestamp {
final Path path;
final FileTime lastModifiedTime;
final Object fileKey;
ArtifactTimestamp(Path path) {
this.path = path;
try {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
this.lastModifiedTime = attrs.lastModifiedTime();
this.fileKey = attrs.fileKey();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ArtifactTimestamp that = (ArtifactTimestamp) o;
return path.equals(that.path) &&
Objects.equals(lastModifiedTime, that.lastModifiedTime) &&
Objects.equals(fileKey, that.fileKey);
}
@Override
public int hashCode() {
return Objects.hash(path, lastModifiedTime, fileKey);
}
}
Set<ArtifactTimestamp> timestamp;
public TimestampedCacheRecord(ClassRealm realm, List<Artifact> artifacts) {
super(realm, artifacts);
timestamp = current();
}
public boolean isValid() {
return current() == timestamp;
try {
return Objects.equals(current(), timestamp);
} catch (Exception e) {
return false;
}
}
private long current() {
private Set<ArtifactTimestamp> current() {
return getArtifacts().stream().map(Artifact::getFile)
.mapToLong(File::lastModified)
.max()
.orElse(0);
.map(File::toPath)
.map(ArtifactTimestamp::new)
.collect(Collectors.toSet());
}
public void dispose() {
ClassRealm realm = getRealm();