2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 16:27:11 -07:00

Fix to cache so that it doesn't hold on to a parsed properties file

This commit is contained in:
Geert Bevin 2024-07-19 00:02:32 -04:00
parent bb4c980e66
commit a3830dbdc0
2 changed files with 25 additions and 19 deletions

View file

@ -48,7 +48,6 @@ public class BldCache {
private static final String PROPERTY_DEPENDENCIES_HASH = PROPERTY_DEPENDENCIES_PREFIX + PROPERTY_SUFFIX_HASH; private static final String PROPERTY_DEPENDENCIES_HASH = PROPERTY_DEPENDENCIES_PREFIX + PROPERTY_SUFFIX_HASH;
private final File hashFile_; private final File hashFile_;
private final Properties hashProperties_ = new Properties();
private final VersionResolution resolution_; private final VersionResolution resolution_;
private String extensionsHash_; private String extensionsHash_;
private String dependenciesHash_; private String dependenciesHash_;
@ -59,14 +58,6 @@ public class BldCache {
new File(bldLibDir, WRAPPER_PROPERTIES_HASH).delete(); new File(bldLibDir, WRAPPER_PROPERTIES_HASH).delete();
new File(bldLibDir, BLD_BUILD_HASH).delete(); new File(bldLibDir, BLD_BUILD_HASH).delete();
if (hashFile_.exists()) {
try {
hashProperties_.load(new FileInputStream(hashFile_));
} catch (IOException e) {
// no-op, we'll store a new properties file when we're writing the cache
}
}
} }
public void fingerprintExtensions(Collection<String> repositories, Collection<String> extensions, boolean downloadSources, boolean downloadJavadoc) { public void fingerprintExtensions(Collection<String> repositories, Collection<String> extensions, boolean downloadSources, boolean downloadJavadoc) {
@ -121,16 +112,29 @@ public class BldCache {
return validateExtensionsHash(extensionsHash_); return validateExtensionsHash(extensionsHash_);
} }
private Properties hashProperties() {
var properties = new Properties();
if (hashFile_.exists()) {
try {
properties.load(new FileInputStream(hashFile_));
} catch (IOException e) {
// no-op, we'll store a new properties file when we're writing the cache
}
}
return properties;
}
private boolean validateExtensionsHash(String hash) { private boolean validateExtensionsHash(String hash) {
if (!hashFile_.exists() || hashProperties_.isEmpty()) { var properties = hashProperties();
if (!hashFile_.exists() || properties.isEmpty()) {
return false; return false;
} }
if (!hash.equals(hashProperties_.getProperty(PROPERTY_EXTENSIONS_HASH))) { if (!hash.equals(properties.getProperty(PROPERTY_EXTENSIONS_HASH))) {
return false; return false;
} }
var local_files = hashProperties_.getProperty(PROPERTY_EXTENSIONS_LOCAL); var local_files = properties.getProperty(PROPERTY_EXTENSIONS_LOCAL);
if (local_files != null && !local_files.isEmpty()) { if (local_files != null && !local_files.isEmpty()) {
var lines = StringUtils.split(local_files, "\n"); var lines = StringUtils.split(local_files, "\n");
if (!lines.isEmpty()) { if (!lines.isEmpty()) {
@ -164,11 +168,12 @@ public class BldCache {
} }
private boolean validateDependenciesHash(String hash) { private boolean validateDependenciesHash(String hash) {
if (!hashFile_.exists() || hashProperties_.isEmpty()) { var properties = hashProperties();
if (!hashFile_.exists() || properties.isEmpty()) {
return false; return false;
} }
return hash.equals(hashProperties_.getProperty(PROPERTY_DEPENDENCIES_HASH)); return hash.equals(properties.getProperty(PROPERTY_DEPENDENCIES_HASH));
} }
public void writeCache() { public void writeCache() {
@ -176,9 +181,11 @@ public class BldCache {
} }
public void writeCache(List<File> extensionsLocalArtifacts) { public void writeCache(List<File> extensionsLocalArtifacts) {
var properties = hashProperties();
try { try {
if (extensionsHash_ != null) { if (extensionsHash_ != null) {
hashProperties_.put(PROPERTY_EXTENSIONS_HASH, extensionsHash_); properties.put(PROPERTY_EXTENSIONS_HASH, extensionsHash_);
} }
if (extensionsLocalArtifacts != null) { if (extensionsLocalArtifacts != null) {
@ -188,15 +195,15 @@ public class BldCache {
extensions_local.append("\n").append(file.lastModified()).append(':').append(file.getAbsolutePath()); extensions_local.append("\n").append(file.lastModified()).append(':').append(file.getAbsolutePath());
} }
} }
hashProperties_.put(PROPERTY_EXTENSIONS_LOCAL, extensions_local.toString()); properties.put(PROPERTY_EXTENSIONS_LOCAL, extensions_local.toString());
} }
if (dependenciesHash_ != null) { if (dependenciesHash_ != null) {
hashProperties_.put(PROPERTY_DEPENDENCIES_HASH, dependenciesHash_); properties.put(PROPERTY_DEPENDENCIES_HASH, dependenciesHash_);
} }
hashFile_.getParentFile().mkdirs(); hashFile_.getParentFile().mkdirs();
hashProperties_.store(new FileOutputStream(hashFile_), null); properties.store(new FileOutputStream(hashFile_), null);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -606,7 +606,6 @@ public class TestWrapperExtensionResolver {
bld.cache""", String.join("\n", files3)); bld.cache""", String.join("\n", files3));
FileUtils.writeString("updated", hash_file); FileUtils.writeString("updated", hash_file);
resolver = new WrapperExtensionResolver(tmp1, tmp2, new Properties(), new Properties(), List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, false);
resolver.updateExtensions(); resolver.updateExtensions();
var files4 = FileUtils.getFileList(tmp2); var files4 = FileUtils.getFileList(tmp2);
assertEquals(10, files4.size()); assertEquals(10, files4.size());