NIFI-11323: Fixed last modified change detection of dynamicallyModifiesClasspath resources (#7069)

This commit is contained in:
Peter Turcsanyi 2023-03-22 14:15:48 +01:00 committed by GitHub
parent 69aa181fde
commit 00707f684f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -155,13 +155,17 @@ public class ClassLoaderUtils {
}
private static long getLastModified(String url) {
File file = null;
long lastModified = 0;
try {
file = new File(new URI(url));
final URI uri = new URI(url);
if (uri.getScheme().equals("file")) {
final File file = new File(uri);
lastModified = file.lastModified();
}
} catch (URISyntaxException e) {
LOGGER.error("Error getting last modified date for " + url);
}
return file != null ? file.lastModified() : 0;
return lastModified;
}
protected static ClassLoader createModuleClassLoader(URL[] modules, ClassLoader parentClassLoader) {

View File

@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.HashSet;
@ -114,7 +113,7 @@ public class TestClassLoaderUtils {
}
@Test
public void testGenerateAdditionalUrlsFingerprint() throws MalformedURLException, URISyntaxException {
public void testGenerateAdditionalUrlsFingerprintForFileUrl() throws MalformedURLException {
final Set<URL> urls = new HashSet<>();
URL testUrl = Paths.get("src/test/resources/TestClassLoaderUtils/TestSuccess.jar").toUri().toURL();
urls.add(testUrl);
@ -122,6 +121,15 @@ public class TestClassLoaderUtils {
assertNotNull(testFingerprint);
}
@Test
public void testGenerateAdditionalUrlsFingerprintForHttpUrl() throws MalformedURLException {
final Set<URL> urls = new HashSet<>();
URL testUrl = new URL("http://myhost/TestSuccess.jar");
urls.add(testUrl);
String testFingerprint = ClassLoaderUtils.generateAdditionalUrlsFingerprint(urls, null);
assertNotNull(testFingerprint);
}
protected FilenameFilter getJarFilenameFilter(){
return (dir, name) -> name != null && name.endsWith(".jar");
}