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

Fixes for dependency override property behavior.

This commit is contained in:
Geert Bevin 2024-07-13 20:44:45 -04:00
parent bb6052250e
commit 48c43a05ed
6 changed files with 74 additions and 11 deletions

Binary file not shown.

View file

@ -1618,6 +1618,7 @@ public class BaseProject extends BuildExecutor {
private String createHash() {
var resolution = new VersionResolution(properties());
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');
@ -1627,7 +1628,7 @@ public class BaseProject extends BuildExecutor {
finger_print.append('\n');
if (entry.getValue() != null) {
for (var dependency : entry.getValue()) {
finger_print.append(resolution.overrideDependency(dependency).toString());
finger_print.append(dependency.toString());
finger_print.append('\n');
}
}

View file

@ -112,4 +112,14 @@ public class VersionResolution {
original.exclusions(),
original.parent());
}
/**
* Returns the map of version overrides, where the key is the name of the dependency and the value is the overridden version.
*
* @return the map of version overrides
* @since 2.0
*/
public Map<String, VersionNumber> versionOverrides() {
return versionOverrides_;
}
}

View file

@ -6,6 +6,7 @@ package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.BldVersion;
import rife.bld.BuildExecutor;
import rife.bld.dependencies.*;
import rife.bld.wrapper.Wrapper;
import rife.ioc.HierarchicalProperties;
@ -24,6 +25,7 @@ import static rife.bld.dependencies.Scope.*;
*/
public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOperation> {
private HierarchicalProperties properties_ = null;
private HierarchicalProperties extensionProperties_ = null;
private ArtifactRetriever retriever_ = null;
private final List<Repository> repositories_ = new ArrayList<>();
private final DependencyScopes dependencies_ = new DependencyScopes();
@ -68,7 +70,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
* @since 2.0
*/
protected String executeGenerateExtensionsDependencies() {
var extensions_tree = extensionDependencies().scope(compile).generateTransitiveDependencyTree(new VersionResolution(properties()), artifactRetriever(), extensionRepositories(), compile, runtime);
var extensions_tree = extensionDependencies().scope(compile).generateTransitiveDependencyTree(new VersionResolution(extensionProperties()), artifactRetriever(), extensionRepositories(), compile, runtime);
if (extensions_tree.isEmpty()) {
extensions_tree = "no dependencies" + System.lineSeparator();
}
@ -140,8 +142,14 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
wrapper.currentDir(project.workDirectory());
try {
wrapper.initWrapperProperties(BldVersion.getVersion());
var extension_properties = BuildExecutor.setupProperties(project.workDirectory());
extension_properties = new HierarchicalProperties().parent(extension_properties);
extension_properties.putAll(wrapper.wrapperProperties());
extensionProperties(extension_properties);
for (var repository : wrapper.repositories()) {
extensionRepositories().add(Repository.resolveRepository(project.properties(), repository));
extensionRepositories().add(Repository.resolveRepository(extensionProperties(), repository));
}
extensionDependencies().scope(compile).addAll(wrapper.extensions().stream().map(Dependency::parse).toList());
} catch (IOException e) {
@ -255,6 +263,18 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
return this;
}
/**
* Provides the extension hierarchical properties to use.
*
* @param properties the extension hierarchical properties
* @return this operation instance
* @since 2.0
*/
public DependencyTreeOperation extensionProperties(HierarchicalProperties properties) {
extensionProperties_ = properties;
return this;
}
/**
* Retrieves the repositories in which the dependencies will be resolved.
* <p>
@ -338,4 +358,17 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
}
return properties_;
}
/**
* Returns the extension hierarchical properties that are used.
*
* @return the extension hierarchical properties
* @since 2.0
*/
public HierarchicalProperties extensionProperties() {
if (extensionProperties_ == null) {
extensionProperties_ = new HierarchicalProperties();
}
return extensionProperties_;
}
}

View file

@ -305,6 +305,22 @@ public class Wrapper {
return extensions_;
}
/**
* Returns the wrapper properties.
*
* @return the wrapper properties
* @since 2.0
*/
public Properties wrapperProperties() {
return wrapperProperties_;
}
/**
* Returns the wrapper properties file.
*
* @return the wrapper properties file
* @since 2.0
*/
public File wrapperPropertiesFile() {
return wrapperPropertiesFile_;
}

View file

@ -29,7 +29,6 @@ import static rife.bld.dependencies.Dependency.CLASSIFIER_SOURCES;
* @since 1.5.8
*/
public class WrapperExtensionResolver {
private final HierarchicalProperties properties_;
private final VersionResolution resolution_;
private final ArtifactRetriever retriever_;
private final File hashFile_;
@ -49,20 +48,20 @@ public class WrapperExtensionResolver {
boolean downloadSources, boolean downloadJavadoc) {
var properties = BuildExecutor.setupProperties(currentDir);
properties.getRoot().putAll(jvmProperties);
properties_ = new HierarchicalProperties().parent(properties);
properties_.putAll(wrapperProperties);
properties = new HierarchicalProperties().parent(properties);
properties.putAll(wrapperProperties);
resolution_ = new VersionResolution(properties_);
resolution_ = new VersionResolution(properties);
retriever_ = ArtifactRetriever.cachingInstance();
Repository.resolveMavenLocal(properties_);
Repository.resolveMavenLocal(properties);
hashFile_ = hashFile;
destinationDirectory_ = destinationDirectory;
for (var repository : repositories) {
repositories_.add(Repository.resolveRepository(properties_, repository));
repositories_.add(Repository.resolveRepository(properties, repository));
}
dependencies_.addAll(extensions.stream().map(d -> resolution_.overrideDependency(Dependency.parse(d))).toList());
@ -70,14 +69,18 @@ public class WrapperExtensionResolver {
downloadSources_ = downloadSources;
downloadJavadoc_ = downloadJavadoc;
fingerPrintHash_ = createHash(
resolution_,
repositories_.stream().map(Objects::toString).toList(),
dependencies_.stream().map(Objects::toString).toList(),
downloadSources, downloadJavadoc);
}
private String createHash(Collection<String> repositories, Collection<String> extensions, boolean downloadSources, boolean downloadJavadoc) {
private static String createHash(VersionResolution resolution, Collection<String> repositories, Collection<String> extensions, boolean downloadSources, boolean downloadJavadoc) {
try {
var fingerprint = String.join("\n", repositories) + "\n" + String.join("\n", extensions) + "\n" + downloadSources + "\n" + downloadJavadoc;
var overrides_fp = String.join("\n", resolution.versionOverrides().entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).toList());
var repositories_fp = String.join("\n", repositories);
var extensions_fp = String.join("\n", extensions);
var fingerprint = overrides_fp + "\n" + repositories_fp + "\n" + extensions_fp + "\n" + downloadSources + "\n" + downloadJavadoc;
var digest = MessageDigest.getInstance("SHA-1");
digest.update(fingerprint.getBytes(StandardCharsets.UTF_8));
return StringUtils.encodeHexLower(digest.digest());