mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-11 13:39:32 +00:00
Try to fix some with pom changes not being detected
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
package org.jboss.fuse.mvnd.daemon;
|
package org.jboss.fuse.mvnd.daemon;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
@@ -24,6 +25,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.PriorityBlockingQueue;
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
@@ -113,7 +115,12 @@ public class Server implements AutoCloseable, Runnable {
|
|||||||
try {
|
try {
|
||||||
registry.close();
|
registry.close();
|
||||||
} finally {
|
} finally {
|
||||||
|
try {
|
||||||
socket.close();
|
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() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
executor.scheduleAtFixedRate(this::expirationCheck,
|
executor.scheduleAtFixedRate(this::expirationCheck,
|
||||||
|
@@ -16,12 +16,19 @@
|
|||||||
package org.jboss.fuse.mvnd.plugin;
|
package org.jboss.fuse.mvnd.plugin;
|
||||||
|
|
||||||
import java.io.File;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.enterprise.inject.Default;
|
import javax.enterprise.inject.Default;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
@@ -146,19 +153,52 @@ public class CliPluginRealmCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static class TimestampedCacheRecord extends CacheRecord {
|
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) {
|
public TimestampedCacheRecord(ClassRealm realm, List<Artifact> artifacts) {
|
||||||
super(realm, artifacts);
|
super(realm, artifacts);
|
||||||
timestamp = current();
|
timestamp = current();
|
||||||
}
|
}
|
||||||
public boolean isValid() {
|
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)
|
return getArtifacts().stream().map(Artifact::getFile)
|
||||||
.mapToLong(File::lastModified)
|
.map(File::toPath)
|
||||||
.max()
|
.map(ArtifactTimestamp::new)
|
||||||
.orElse(0);
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
ClassRealm realm = getRealm();
|
ClassRealm realm = getRealm();
|
||||||
|
Reference in New Issue
Block a user