Skip to content

Commit

Permalink
Fixes for dependency override property behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jul 14, 2024
1 parent bb60522 commit 48c43a0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
Binary file modified lib/bld/bld-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/java/rife/bld/BaseProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@ private void performAutoDownloadPurge() {
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');
Expand All @@ -1627,7 +1628,7 @@ private String createHash() {
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');
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/rife/bld/dependencies/VersionResolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,14 @@ public Dependency overrideDependency(Dependency original) {
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_;
}
}
37 changes: 35 additions & 2 deletions src/main/java/rife/bld/operations/DependencyTreeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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;
Expand All @@ -24,6 +25,7 @@
*/
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();
Expand Down Expand Up @@ -68,7 +70,7 @@ public void execute() {
* @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();
}
Expand Down Expand Up @@ -140,8 +142,14 @@ public DependencyTreeOperation fromProject(BaseProject project) {
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) {
Expand Down Expand Up @@ -255,6 +263,18 @@ public DependencyTreeOperation properties(HierarchicalProperties properties) {
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>
Expand Down Expand Up @@ -338,4 +358,17 @@ public HierarchicalProperties properties() {
}
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_;
}
}
16 changes: 16 additions & 0 deletions src/main/java/rife/bld/wrapper/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ public Set<String> extensions() {
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_;
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/rife/bld/wrapper/WrapperExtensionResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @since 1.5.8
*/
public class WrapperExtensionResolver {
private final HierarchicalProperties properties_;
private final VersionResolution resolution_;
private final ArtifactRetriever retriever_;
private final File hashFile_;
Expand All @@ -49,35 +48,39 @@ public WrapperExtensionResolver(File currentDir, File hashFile, File destination
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());

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());
Expand Down

0 comments on commit 48c43a0

Please sign in to comment.