mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 08:17:11 -07:00
Cleanups
This commit is contained in:
parent
586aec0eae
commit
ad8a866dc3
4 changed files with 116 additions and 107 deletions
|
@ -1593,7 +1593,7 @@ public class BaseProject extends BuildExecutor {
|
|||
private void performAutoDownloadPurge() {
|
||||
var resolution = new VersionResolution(properties());
|
||||
var cache = new BldCache(libBldDirectory(), resolution);
|
||||
cache.fingerprintDependencies(repositories(), dependencies());
|
||||
cache.cacheDependenciesHash(repositories(), dependencies());
|
||||
if (cache.isDependenciesCacheValid(downloadSources(), downloadJavadoc())) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ public class BldCache {
|
|||
private String extensionsHash_;
|
||||
private Boolean extensionsDownloadSources_;
|
||||
private Boolean extensionsDownloadJavadocs_;
|
||||
private List<File> extensionsLocalArtifacts_;
|
||||
private String extensionsDependencyTree_;
|
||||
private String dependenciesHash_;
|
||||
private Boolean dependenciesDownloadSources_;
|
||||
|
@ -70,6 +71,13 @@ public class BldCache {
|
|||
private String dependenciesRuntimeDependencyTree_;
|
||||
private String dependenciesTestDependencyTree_;
|
||||
|
||||
/**
|
||||
* Creates a new {@code BldCache} instance.
|
||||
*
|
||||
* @param bldLibDir the library directory where the bld cache file is stored
|
||||
* @param resolution the version resolution that should be used when needed during the cache operations
|
||||
* @since 2.0
|
||||
*/
|
||||
public BldCache(File bldLibDir, VersionResolution resolution) {
|
||||
bldLibDir_ = bldLibDir;
|
||||
resolution_ = resolution;
|
||||
|
@ -78,7 +86,7 @@ public class BldCache {
|
|||
new File(bldLibDir, BLD_BUILD_HASH).delete();
|
||||
}
|
||||
|
||||
public void fingerprintExtensions(Collection<String> repositories, Collection<String> extensions) {
|
||||
public void cacheExtensionsHash(Collection<String> repositories, Collection<String> extensions) {
|
||||
try {
|
||||
var overrides_fp = String.join("\n", resolution_.versionOverrides().entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).toList());
|
||||
var repositories_fp = String.join("\n", repositories);
|
||||
|
@ -94,84 +102,6 @@ public class BldCache {
|
|||
}
|
||||
}
|
||||
|
||||
public void cacheExtensionsDownloads(boolean downloadSources, boolean downloadJavadoc) {
|
||||
extensionsDownloadSources_ = downloadSources;
|
||||
extensionsDownloadJavadocs_ = downloadJavadoc;
|
||||
}
|
||||
|
||||
public void cacheExtensionsDependencyTree(String dependencyTree) {
|
||||
extensionsDependencyTree_ = dependencyTree;
|
||||
}
|
||||
|
||||
public String getCachedExtensionsDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_EXTENSIONS_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void fingerprintDependencies(List<Repository> repositories, DependencyScopes dependencies) {
|
||||
var finger_print = new StringBuilder();
|
||||
finger_print.append(String.join("\n", resolution_.versionOverrides().entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).toList()));
|
||||
for (var repository : repositories) {
|
||||
finger_print.append(repository.toString());
|
||||
finger_print.append('\n');
|
||||
}
|
||||
for (var entry : dependencies.entrySet()) {
|
||||
finger_print.append(entry.getKey());
|
||||
finger_print.append('\n');
|
||||
if (entry.getValue() != null) {
|
||||
for (var dependency : entry.getValue()) {
|
||||
finger_print.append(dependency.toString());
|
||||
finger_print.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var digest = MessageDigest.getInstance("SHA-1");
|
||||
digest.update(finger_print.toString().getBytes(StandardCharsets.UTF_8));
|
||||
dependenciesHash_ = StringUtils.encodeHexLower(digest.digest());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// should not happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void cacheDependenciesDownloads(boolean downloadSources, boolean downloadJavadoc) {
|
||||
dependenciesDownloadSources_ = downloadSources;
|
||||
dependenciesDownloadJavadocs_ = downloadJavadoc;
|
||||
}
|
||||
|
||||
public void cacheDependenciesCompileDependencyTree(String compileTree) {
|
||||
dependenciesCompileDependencyTree_ = compileTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesCompileDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_COMPILE_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheDependenciesProvidedDependencyTree(String providedTree) {
|
||||
dependenciesProvidedDependencyTree_ = providedTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesProvidedDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_PROVIDED_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheDependenciesRuntimeDependencyTree(String runtimeTree) {
|
||||
dependenciesRuntimeDependencyTree_ = runtimeTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesRuntimeDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_RUNTIME_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheDependenciesTestDependencyTree(String testTree) {
|
||||
dependenciesTestDependencyTree_ = testTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesTestDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_TEST_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public boolean isExtensionHashValid() {
|
||||
return validateExtensionsHash(extensionsHash_);
|
||||
}
|
||||
|
@ -193,24 +123,6 @@ public class BldCache {
|
|||
return validateExtensionsHash(extensionsHash_);
|
||||
}
|
||||
|
||||
private File getCacheFile() {
|
||||
return new File(bldLibDir_, BLD_CACHE);
|
||||
}
|
||||
|
||||
private Properties hashProperties() {
|
||||
var properties = new Properties();
|
||||
if (getCacheFile().exists()) {
|
||||
try {
|
||||
try (var reader = new BufferedReader(new FileReader(getCacheFile()))) {
|
||||
properties.load(reader);
|
||||
}
|
||||
} 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) {
|
||||
var properties = hashProperties();
|
||||
if (properties.isEmpty()) {
|
||||
|
@ -250,6 +162,51 @@ public class BldCache {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void cacheExtensionsDownloads(boolean downloadSources, boolean downloadJavadoc) {
|
||||
extensionsDownloadSources_ = downloadSources;
|
||||
extensionsDownloadJavadocs_ = downloadJavadoc;
|
||||
}
|
||||
|
||||
public void cacheExtensionsDependencyTree(String dependencyTree) {
|
||||
extensionsDependencyTree_ = dependencyTree;
|
||||
}
|
||||
|
||||
public String getCachedExtensionsDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_EXTENSIONS_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheExtensionsLocalArtifacts(List<File> extensionsLocalArtifacts) {
|
||||
extensionsLocalArtifacts_ = extensionsLocalArtifacts;
|
||||
}
|
||||
|
||||
public void cacheDependenciesHash(List<Repository> repositories, DependencyScopes dependencies) {
|
||||
var finger_print = new StringBuilder();
|
||||
finger_print.append(String.join("\n", resolution_.versionOverrides().entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).toList()));
|
||||
for (var repository : repositories) {
|
||||
finger_print.append(repository.toString());
|
||||
finger_print.append('\n');
|
||||
}
|
||||
for (var entry : dependencies.entrySet()) {
|
||||
finger_print.append(entry.getKey());
|
||||
finger_print.append('\n');
|
||||
if (entry.getValue() != null) {
|
||||
for (var dependency : entry.getValue()) {
|
||||
finger_print.append(dependency.toString());
|
||||
finger_print.append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var digest = MessageDigest.getInstance("SHA-1");
|
||||
digest.update(finger_print.toString().getBytes(StandardCharsets.UTF_8));
|
||||
dependenciesHash_ = StringUtils.encodeHexLower(digest.digest());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// should not happen
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDependenciesHashValid() {
|
||||
return validateDependenciesHash(dependenciesHash_);
|
||||
}
|
||||
|
@ -280,11 +237,62 @@ public class BldCache {
|
|||
return hash.equals(properties.getProperty(PROPERTY_DEPENDENCIES_HASH));
|
||||
}
|
||||
|
||||
public void writeCache() {
|
||||
writeCache(null);
|
||||
public void cacheDependenciesDownloads(boolean downloadSources, boolean downloadJavadoc) {
|
||||
dependenciesDownloadSources_ = downloadSources;
|
||||
dependenciesDownloadJavadocs_ = downloadJavadoc;
|
||||
}
|
||||
|
||||
public void writeCache(List<File> extensionsLocalArtifacts) {
|
||||
public void cacheDependenciesCompileDependencyTree(String compileTree) {
|
||||
dependenciesCompileDependencyTree_ = compileTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesCompileDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_COMPILE_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheDependenciesProvidedDependencyTree(String providedTree) {
|
||||
dependenciesProvidedDependencyTree_ = providedTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesProvidedDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_PROVIDED_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheDependenciesRuntimeDependencyTree(String runtimeTree) {
|
||||
dependenciesRuntimeDependencyTree_ = runtimeTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesRuntimeDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_RUNTIME_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
public void cacheDependenciesTestDependencyTree(String testTree) {
|
||||
dependenciesTestDependencyTree_ = testTree;
|
||||
}
|
||||
|
||||
public String getCachedDependenciesTestDependencyTree() {
|
||||
return hashProperties().getProperty(PROPERTY_DEPENDENCIES_TEST_DEPENDENCY_TREE);
|
||||
}
|
||||
|
||||
private File getCacheFile() {
|
||||
return new File(bldLibDir_, BLD_CACHE);
|
||||
}
|
||||
|
||||
private Properties hashProperties() {
|
||||
var properties = new Properties();
|
||||
if (getCacheFile().exists()) {
|
||||
try {
|
||||
try (var reader = new BufferedReader(new FileReader(getCacheFile()))) {
|
||||
properties.load(reader);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// no-op, we'll store a new properties file when we're writing the cache
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void writeCache() {
|
||||
var properties = hashProperties();
|
||||
|
||||
try {
|
||||
|
@ -307,9 +315,9 @@ public class BldCache {
|
|||
properties.put(PROPERTY_EXTENSIONS_DOWNLOAD_JAVADOC, String.valueOf(extensionsDownloadJavadocs_));
|
||||
}
|
||||
|
||||
if (extensionsLocalArtifacts != null) {
|
||||
if (extensionsLocalArtifacts_ != null) {
|
||||
var extensions_local = new StringBuilder();
|
||||
for (var file : extensionsLocalArtifacts) {
|
||||
for (var file : extensionsLocalArtifacts_) {
|
||||
if (file.exists() && file.canRead()) {
|
||||
if (!extensions_local.isEmpty()) {
|
||||
extensions_local.append("\n");
|
||||
|
|
|
@ -55,7 +55,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
BldCache extensions_cache = null;
|
||||
if (libBldDir_ != null) {
|
||||
extensions_cache = new BldCache(libBldDir_, new VersionResolution(extensionProperties()));
|
||||
extensions_cache.fingerprintExtensions(
|
||||
extensions_cache.cacheExtensionsHash(
|
||||
extensionRepositories().stream().map(Repository::toString).toList(),
|
||||
extensionDependencies().scope(compile).stream().map(Dependency::toString).toList());
|
||||
if (extensions_cache.isExtensionHashValid()) {
|
||||
|
@ -83,7 +83,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
BldCache dependencies_cache = null;
|
||||
if (libBldDir_ != null) {
|
||||
dependencies_cache = new BldCache(libBldDir_, new VersionResolution(properties()));
|
||||
dependencies_cache.fingerprintDependencies(repositories(), dependencies());
|
||||
dependencies_cache.cacheDependenciesHash(repositories(), dependencies());
|
||||
if (dependencies_cache.isDependenciesHashValid()) {
|
||||
var cached_compile_tree = dependencies_cache.getCachedDependenciesCompileDependencyTree();
|
||||
if (cached_compile_tree != null) {
|
||||
|
|
|
@ -62,7 +62,7 @@ public class WrapperExtensionResolver {
|
|||
|
||||
downloadSources_ = downloadSources;
|
||||
downloadJavadoc_ = downloadJavadoc;
|
||||
cache_.fingerprintExtensions(
|
||||
cache_.cacheExtensionsHash(
|
||||
repositories_.stream().map(Objects::toString).toList(),
|
||||
dependencies_.stream().map(Objects::toString).toList());
|
||||
}
|
||||
|
@ -81,7 +81,8 @@ public class WrapperExtensionResolver {
|
|||
purgeExtensionDependencies(filenames);
|
||||
|
||||
cache_.cacheExtensionsDownloads(downloadSources_, downloadJavadoc_);
|
||||
cache_.writeCache(localArtifacts_);
|
||||
cache_.cacheExtensionsLocalArtifacts(localArtifacts_);
|
||||
cache_.writeCache();
|
||||
|
||||
if (headerPrinted_) {
|
||||
System.out.println();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue