Skip to content

Commit

Permalink
Don't hold on to the cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jul 19, 2024
1 parent e731b00 commit a33e373
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/rife/bld/BldCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public class BldCache {
private static final String PROPERTY_DEPENDENCIES_PREFIX = "bld.dependencies";
private static final String PROPERTY_DEPENDENCIES_HASH = PROPERTY_DEPENDENCIES_PREFIX + PROPERTY_SUFFIX_HASH;

private final File hashFile_;
private final File bldLibDir_;
private final VersionResolution resolution_;
private String extensionsHash_;
private String dependenciesHash_;

public BldCache(File bldLibDir, VersionResolution resolution) {
hashFile_ = new File(bldLibDir, BLD_CACHE);
bldLibDir_ = bldLibDir;
resolution_ = resolution;

new File(bldLibDir, WRAPPER_PROPERTIES_HASH).delete();
Expand Down Expand Up @@ -112,11 +112,15 @@ public boolean isExtensionHashValid() {
return validateExtensionsHash(extensionsHash_);
}

private File getCacheFile() {
return new File(bldLibDir_, BLD_CACHE);
}

private Properties hashProperties() {
var properties = new Properties();
if (hashFile_.exists()) {
if (getCacheFile().exists()) {
try {
properties.load(new FileInputStream(hashFile_));
properties.load(new FileInputStream(getCacheFile()));
} catch (IOException e) {
// no-op, we'll store a new properties file when we're writing the cache
}
Expand All @@ -126,7 +130,7 @@ private Properties hashProperties() {

private boolean validateExtensionsHash(String hash) {
var properties = hashProperties();
if (!hashFile_.exists() || properties.isEmpty()) {
if (properties.isEmpty()) {
return false;
}

Expand Down Expand Up @@ -169,7 +173,7 @@ public boolean isDependenciesHashValid() {

private boolean validateDependenciesHash(String hash) {
var properties = hashProperties();
if (!hashFile_.exists() || properties.isEmpty()) {
if (properties.isEmpty()) {
return false;
}

Expand Down Expand Up @@ -202,8 +206,8 @@ public void writeCache(List<File> extensionsLocalArtifacts) {
properties.put(PROPERTY_DEPENDENCIES_HASH, dependenciesHash_);
}

hashFile_.getParentFile().mkdirs();
properties.store(new FileOutputStream(hashFile_), null);
bldLibDir_.mkdirs();
properties.store(new FileOutputStream(getCacheFile()), null);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit a33e373

Please sign in to comment.