mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-26 00:37:10 -07:00
Added support for overriding dependency versions with properties throughout all of dependency resolution.
This commit is contained in:
parent
fd38de9644
commit
30f456e47a
27 changed files with 1002 additions and 214 deletions
|
@ -1616,6 +1616,7 @@ public class BaseProject extends BuildExecutor {
|
|||
}
|
||||
|
||||
private String createHash() {
|
||||
var resolution = new VersionResolution(properties());
|
||||
var finger_print = new StringBuilder();
|
||||
for (var repository : repositories()) {
|
||||
finger_print.append(repository.toString());
|
||||
|
@ -1626,7 +1627,7 @@ public class BaseProject extends BuildExecutor {
|
|||
finger_print.append('\n');
|
||||
if (entry.getValue() != null) {
|
||||
for (var dependency : entry.getValue()) {
|
||||
finger_print.append(dependency.toString());
|
||||
finger_print.append(resolution.overrideDependency(dependency).toString());
|
||||
finger_print.append('\n');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ public class BuildExecutor {
|
|||
*
|
||||
* @return {@code true} if JSON output is enabled;
|
||||
* or {@code false} otherwise
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public boolean outputJson() {
|
||||
return outputJson_;
|
||||
|
|
|
@ -139,6 +139,16 @@ public record Dependency(String groupId, String artifactId, VersionNumber versio
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the dependency in the format "groupId:artifactId".
|
||||
*
|
||||
* @return the string representation of the dependency
|
||||
* @since 2.0
|
||||
*/
|
||||
public String toArtifactString() {
|
||||
return groupId + ':' + artifactId;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
var result = new StringBuilder(groupId).append(':').append(artifactId);
|
||||
if (!version.equals(VersionNumber.UNKNOWN)) {
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class DependencyResolver {
|
||||
private final VersionResolution resolution_;
|
||||
private final ArtifactRetriever retriever_;
|
||||
private final List<Repository> repositories_;
|
||||
private final Dependency dependency_;
|
||||
|
@ -30,12 +31,14 @@ public class DependencyResolver {
|
|||
* <p>
|
||||
* The repositories will be checked in the order they're listed.
|
||||
*
|
||||
* @param resolution the version resolution state that can be cached
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the resolution
|
||||
* @param dependency the dependency to resolve
|
||||
* @since 1.5.18
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencyResolver(ArtifactRetriever retriever, List<Repository> repositories, Dependency dependency) {
|
||||
public DependencyResolver(VersionResolution resolution, ArtifactRetriever retriever, List<Repository> repositories, Dependency dependency) {
|
||||
resolution_ = resolution;
|
||||
retriever_ = retriever;
|
||||
if (repositories == null) {
|
||||
repositories = Collections.emptyList();
|
||||
|
@ -64,7 +67,6 @@ public class DependencyResolver {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resolves the dependency version in the provided repositories.
|
||||
* <p>
|
||||
|
@ -77,7 +79,7 @@ public class DependencyResolver {
|
|||
* @since 1.5
|
||||
*/
|
||||
public VersionNumber resolveVersion() {
|
||||
var version = dependency_.version();
|
||||
var version = resolution_.overrideVersion(dependency_);
|
||||
if (version.equals(VersionNumber.UNKNOWN)) {
|
||||
return latestVersion();
|
||||
}
|
||||
|
@ -98,7 +100,7 @@ public class DependencyResolver {
|
|||
var pom_dependencies = getMavenPom(dependency_).getDependencies(scopes);
|
||||
var result = new DependencySet();
|
||||
for (var dependency : pom_dependencies) {
|
||||
result.add(dependency.convertToDependency());
|
||||
result.add(resolution_.overrideDependency(dependency.convertToDependency()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -118,11 +120,12 @@ public class DependencyResolver {
|
|||
*/
|
||||
public DependencySet getAllDependencies(Scope... scopes) {
|
||||
var result = new DependencySet();
|
||||
result.add(dependency_);
|
||||
var overridden = resolution_.overrideDependency(dependency_);
|
||||
result.add(overridden);
|
||||
|
||||
var dependency_queue = new ArrayList<PomDependency>();
|
||||
|
||||
var parent = dependency_;
|
||||
var parent = overridden;
|
||||
var next_dependencies = getMavenPom(parent).getDependencies(scopes);
|
||||
|
||||
while (parent != null && next_dependencies != null) {
|
||||
|
@ -142,7 +145,7 @@ public class DependencyResolver {
|
|||
// part of the results yet
|
||||
while (!dependency_queue.isEmpty()) {
|
||||
var candidate = dependency_queue.remove(0);
|
||||
var dependency = candidate.convertToDependency();
|
||||
var dependency = resolution_.overrideDependency(candidate.convertToDependency());
|
||||
if (!result.contains(dependency)) {
|
||||
result.add(dependency);
|
||||
|
||||
|
@ -150,7 +153,7 @@ public class DependencyResolver {
|
|||
// dependencies so that they can be added to the queue after
|
||||
// filtering
|
||||
parent = dependency;
|
||||
next_dependencies = new DependencyResolver(retriever_, repositories_, dependency).getMavenPom(parent).getDependencies(scopes);
|
||||
next_dependencies = new DependencyResolver(resolution_, retriever_, repositories_, dependency).getMavenPom(parent).getDependencies(scopes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -258,6 +261,16 @@ public class DependencyResolver {
|
|||
return dependency_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version resolution state that can be cached.
|
||||
*
|
||||
* @return the version resolution state
|
||||
* @since 2.0
|
||||
*/
|
||||
public VersionResolution resolution() {
|
||||
return resolution_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the potential locations for the dependency
|
||||
* within the provided repositories.
|
||||
|
@ -435,7 +448,7 @@ public class DependencyResolver {
|
|||
throw new ArtifactNotFoundException(dependency_, location);
|
||||
}
|
||||
|
||||
var xml = new Xml2MavenPom(parent, retriever_, repositories_);
|
||||
var xml = new Xml2MavenPom(parent, resolution_, retriever_, repositories_);
|
||||
if (!xml.processXml(pom)) {
|
||||
throw new DependencyXmlParsingErrorException(dependency_, retrieved_artifact.location(), xml.getErrors());
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -66,13 +68,14 @@ public class DependencyScopes extends LinkedHashMap<Scope, DependencySet> {
|
|||
/**
|
||||
* Returns the transitive set of dependencies that would be used for the compile scope in a project.
|
||||
*
|
||||
* @param properties the properties to use to get artifacts
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the resolution
|
||||
* @return the compile scope dependency set
|
||||
* @since 1.6
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencySet resolveCompileDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(retriever, repositories,
|
||||
public DependencySet resolveCompileDependencies(HierarchicalProperties properties, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(properties, retriever, repositories,
|
||||
new Scope[]{Scope.compile},
|
||||
new Scope[]{Scope.compile},
|
||||
null);
|
||||
|
@ -81,13 +84,14 @@ public class DependencyScopes extends LinkedHashMap<Scope, DependencySet> {
|
|||
/**
|
||||
* Returns the transitive set of dependencies that would be used for the provided scope in a project.
|
||||
*
|
||||
* @param properties the properties to use to get artifacts
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the resolution
|
||||
* @return the provided scope dependency set
|
||||
* @since 1.8
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencySet resolveProvidedDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(retriever, repositories,
|
||||
public DependencySet resolveProvidedDependencies(HierarchicalProperties properties, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(properties, retriever, repositories,
|
||||
new Scope[]{Scope.provided},
|
||||
new Scope[]{Scope.compile, Scope.runtime},
|
||||
null);
|
||||
|
@ -96,28 +100,30 @@ public class DependencyScopes extends LinkedHashMap<Scope, DependencySet> {
|
|||
/**
|
||||
* Returns the transitive set of dependencies that would be used for the runtime scope in a project.
|
||||
*
|
||||
* @param properties the properties to use to get artifacts
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the resolution
|
||||
* @return the runtime scope dependency set
|
||||
* @since 1.6
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencySet resolveRuntimeDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(retriever, repositories,
|
||||
public DependencySet resolveRuntimeDependencies(HierarchicalProperties properties, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(properties, retriever, repositories,
|
||||
new Scope[]{Scope.compile, Scope.runtime},
|
||||
new Scope[]{Scope.compile, Scope.runtime},
|
||||
resolveCompileDependencies(retriever, repositories));
|
||||
resolveCompileDependencies(properties, retriever, repositories));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the transitive set of dependencies that would be used for the standalone scope in a project.
|
||||
*
|
||||
* @param properties the properties to use to get artifacts
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the resolution
|
||||
* @return the standalone scope dependency set
|
||||
* @since 1.6
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencySet resolveStandaloneDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(retriever, repositories,
|
||||
public DependencySet resolveStandaloneDependencies(HierarchicalProperties properties, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(properties, retriever, repositories,
|
||||
new Scope[]{Scope.standalone},
|
||||
new Scope[]{Scope.compile, Scope.runtime},
|
||||
null);
|
||||
|
@ -126,25 +132,27 @@ public class DependencyScopes extends LinkedHashMap<Scope, DependencySet> {
|
|||
/**
|
||||
* Returns the transitive set of dependencies that would be used for the test scope in a project.
|
||||
*
|
||||
* @param properties the properties to use to get artifacts
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the resolution
|
||||
* @return the test scope dependency set
|
||||
* @since 1.6
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencySet resolveTestDependencies(ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(retriever, repositories,
|
||||
public DependencySet resolveTestDependencies(HierarchicalProperties properties, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
return resolveScopedDependencies(properties, retriever, repositories,
|
||||
new Scope[]{Scope.test},
|
||||
new Scope[]{Scope.compile, Scope.runtime},
|
||||
null);
|
||||
}
|
||||
|
||||
private DependencySet resolveScopedDependencies(ArtifactRetriever retriever, List<Repository> repositories, Scope[] resolvedScopes, Scope[] transitiveScopes, DependencySet excluded) {
|
||||
private DependencySet resolveScopedDependencies(HierarchicalProperties properties, ArtifactRetriever retriever, List<Repository> repositories, Scope[] resolvedScopes, Scope[] transitiveScopes, DependencySet excluded) {
|
||||
var resolution = new VersionResolution(properties);
|
||||
var dependencies = new DependencySet();
|
||||
for (var scope : resolvedScopes) {
|
||||
var scoped_dependencies = get(scope);
|
||||
if (scoped_dependencies != null) {
|
||||
for (var dependency : scoped_dependencies) {
|
||||
dependencies.addAll(new DependencyResolver(retriever, repositories, dependency).getAllDependencies(transitiveScopes));
|
||||
dependencies.addAll(new DependencyResolver(resolution, retriever, repositories, dependency).getAllDependencies(transitiveScopes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,15 +84,16 @@ public class DependencySet extends AbstractSet<Dependency> implements Set<Depend
|
|||
* <p>
|
||||
* The destination directory must exist and be writable.
|
||||
*
|
||||
* @param resolution the version resolution state that can be cached
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the transfer
|
||||
* @param directory the directory to transfer the artifacts into
|
||||
* @return the list of artifacts that were transferred successfully
|
||||
* @throws DependencyTransferException when an error occurred during the transfer
|
||||
* @since 1.5.10
|
||||
* @since 2.0
|
||||
*/
|
||||
public List<RepositoryArtifact> transferIntoDirectory(ArtifactRetriever retriever, List<Repository> repositories, File directory) {
|
||||
return transferIntoDirectory(retriever, repositories, directory, (String[]) null);
|
||||
public List<RepositoryArtifact> transferIntoDirectory(VersionResolution resolution, ArtifactRetriever retriever, List<Repository> repositories, File directory) {
|
||||
return transferIntoDirectory(resolution, retriever, repositories, directory, (String[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,18 +102,19 @@ public class DependencySet extends AbstractSet<Dependency> implements Set<Depend
|
|||
* <p>
|
||||
* The destination directory must exist and be writable.
|
||||
*
|
||||
* @param resolution the version resolution state that can be cached
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to use for the download
|
||||
* @param directory the directory to download the artifacts into
|
||||
* @param classifiers the additional classifiers to transfer
|
||||
* @return the list of artifacts that were transferred successfully
|
||||
* @throws DependencyTransferException when an error occurred during the transfer
|
||||
* @since 1.5.10
|
||||
* @since 2.0
|
||||
*/
|
||||
public List<RepositoryArtifact> transferIntoDirectory(ArtifactRetriever retriever, List<Repository> repositories, File directory, String... classifiers) {
|
||||
public List<RepositoryArtifact> transferIntoDirectory(VersionResolution resolution, ArtifactRetriever retriever, List<Repository> repositories, File directory, String... classifiers) {
|
||||
var result = new ArrayList<RepositoryArtifact>();
|
||||
for (var dependency : this) {
|
||||
var artifact = new DependencyResolver(retriever, repositories, dependency).transferIntoDirectory(directory);
|
||||
var artifact = new DependencyResolver(resolution, retriever, repositories, dependency).transferIntoDirectory(directory);
|
||||
if (artifact != null) {
|
||||
result.add(artifact);
|
||||
}
|
||||
|
@ -120,7 +122,7 @@ public class DependencySet extends AbstractSet<Dependency> implements Set<Depend
|
|||
if (classifiers != null) {
|
||||
for (var classifier : classifiers) {
|
||||
if (classifier != null) {
|
||||
var classifier_artifact = new DependencyResolver(retriever, repositories, dependency.withClassifier(classifier)).transferIntoDirectory(directory);
|
||||
var classifier_artifact = new DependencyResolver(resolution, retriever, repositories, dependency.withClassifier(classifier)).transferIntoDirectory(directory);
|
||||
if (classifier_artifact != null) {
|
||||
result.add(classifier_artifact);
|
||||
}
|
||||
|
@ -150,17 +152,18 @@ public class DependencySet extends AbstractSet<Dependency> implements Set<Depend
|
|||
* Generates the string description of the transitive hierarchical tree of
|
||||
* dependencies for a particular scope.
|
||||
*
|
||||
* @param resolution the version resolution state that can be cached
|
||||
* @param retriever the retriever to use to get artifacts
|
||||
* @param repositories the repositories to look for dependencies in
|
||||
* @param scopes the scopes to return the transitive dependencies for
|
||||
* @return the generated tree description string; or an empty string if
|
||||
* there were no dependencies to describe
|
||||
* @since 1.5.21
|
||||
* @since 2.0
|
||||
*/
|
||||
public String generateTransitiveDependencyTree(ArtifactRetriever retriever, List<Repository> repositories, Scope... scopes) {
|
||||
public String generateTransitiveDependencyTree(VersionResolution resolution, ArtifactRetriever retriever, List<Repository> repositories, Scope... scopes) {
|
||||
var compile_dependencies = new DependencySet();
|
||||
for (var dependency : this) {
|
||||
compile_dependencies.addAll(new DependencyResolver(retriever, repositories, dependency).getAllDependencies(scopes));
|
||||
compile_dependencies.addAll(new DependencyResolver(resolution, retriever, repositories, dependency).getAllDependencies(scopes));
|
||||
}
|
||||
return compile_dependencies.generateDependencyTree();
|
||||
}
|
||||
|
|
115
src/main/java/rife/bld/dependencies/VersionResolution.java
Normal file
115
src/main/java/rife/bld/dependencies/VersionResolution.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright 2001-2024 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is responsible for managing version overrides for dependencies.
|
||||
* <p>
|
||||
* It allows users to specify a property keys with the prefix "{@code bld.override}" where the values will be parsed as
|
||||
* a comma-separated list of dependencies with the versions that should override any other versions that are encountered.
|
||||
* <p>
|
||||
* For instance:
|
||||
* <pre>
|
||||
* bld.override=com.uwyn.rife2:bld-tests-badge:1.4.7,com.h2database:h2:2.2.222
|
||||
* </pre>
|
||||
* <p>
|
||||
* Multiple override properties can be used by simply adding differentiators behind the "{@code bld.override}" keys.
|
||||
* <p>
|
||||
* For instance:
|
||||
* <pre>
|
||||
* bld.override-tests=com.uwyn.rife2:bld-tests-badge:1.4.7
|
||||
* bld.override-h2=com.h2database:h2:2.2.222
|
||||
* </pre>
|
||||
* @since 2.0
|
||||
*/
|
||||
public class VersionResolution {
|
||||
/**
|
||||
* The prefix for property keys used to override versions of dependencies.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final String PROPERTY_OVERRIDE_PREFIX = "bld.override";
|
||||
|
||||
private final Map<String, VersionNumber> versionOverrides_ = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Returns a dummy {@code VersionResolution} instance that doesn't override anything.
|
||||
*
|
||||
* @return the dummy instance
|
||||
* @since 2.0
|
||||
*/
|
||||
static VersionResolution dummy() {
|
||||
return new VersionResolution(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code VersionReslution} class from hierarchical properties that
|
||||
* are passed in.
|
||||
* <p>
|
||||
* The actual version overrides are determined at instantiation time and any future changes to the
|
||||
* properties will not influence version resolution.
|
||||
*
|
||||
* @param properties the hierarchical properties that will be used to determine the version overrides
|
||||
* @since 2.0
|
||||
*/
|
||||
public VersionResolution(HierarchicalProperties properties) {
|
||||
if (properties != null) {
|
||||
for (var name : properties.getNames()) {
|
||||
if (name.startsWith(PROPERTY_OVERRIDE_PREFIX)) {
|
||||
for (var override : properties.get(name).toString().split(",")) {
|
||||
override = override.trim();
|
||||
if (!override.isBlank()) {
|
||||
var dependency = Dependency.parse(override);
|
||||
if (dependency != null) {
|
||||
versionOverrides_.put(dependency.toArtifactString(), dependency.version());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the version of a given dependency with the corresponding overridden version.
|
||||
*
|
||||
* @param original the dependency for which the version needs to be overridden
|
||||
* @return the overridden version if it is available; or the original version otherwise
|
||||
* @since 2.0
|
||||
*/
|
||||
public VersionNumber overrideVersion(Dependency original) {
|
||||
var overridden = versionOverrides_.get(original.toArtifactString());
|
||||
if (overridden == null) {
|
||||
return original.version();
|
||||
}
|
||||
return overridden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the version of a given dependency with the corresponding overridden version and
|
||||
* creates a new dependency object with the overridden version, if needed.
|
||||
*
|
||||
* @param original the dependency for which the version needs to be overridden
|
||||
* @return the dependency with the overridden version if it's available; or the original dependency otherwise
|
||||
* @since 2.0
|
||||
*/
|
||||
public Dependency overrideDependency(Dependency original) {
|
||||
var overridden = versionOverrides_.get(original.toArtifactString());
|
||||
if (overridden == null) {
|
||||
return original;
|
||||
}
|
||||
return new Dependency(original.groupId(),
|
||||
original.artifactId(),
|
||||
overridden,
|
||||
original.classifier(),
|
||||
original.type(),
|
||||
original.exclusions(),
|
||||
original.parent());
|
||||
}
|
||||
}
|
|
@ -18,13 +18,14 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
class Xml2MavenPom extends Xml2Data {
|
||||
private final Dependency parent_;
|
||||
private final VersionResolution resolution_;
|
||||
private final ArtifactRetriever retriever_;
|
||||
private final List<Repository> repositories_;
|
||||
private Map<Scope, Set<PomDependency>> resolvedDependencies_ = null;
|
||||
|
||||
private final Map<PomDependency, PomDependency> dependencyManagement_ = new LinkedHashMap<>();
|
||||
private final Set<PomDependency> dependencies_ = new LinkedHashSet<>();
|
||||
private final Map<String, String> properties_ = new HashMap<>();
|
||||
private final Map<String, String> mavenProperties_ = new HashMap<>();
|
||||
private final Stack<String> elementStack_ = new Stack<>();
|
||||
private ExclusionSet exclusions_ = null;
|
||||
|
||||
|
@ -45,8 +46,9 @@ class Xml2MavenPom extends Xml2Data {
|
|||
private String lastExclusionGroupId_ = null;
|
||||
private String lastExclusionArtifactId_ = null;
|
||||
|
||||
Xml2MavenPom(Dependency parent, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
Xml2MavenPom(Dependency parent, VersionResolution resolution, ArtifactRetriever retriever, List<Repository> repositories) {
|
||||
parent_ = parent;
|
||||
resolution_ = resolution;
|
||||
retriever_ = retriever;
|
||||
repositories_ = repositories;
|
||||
}
|
||||
|
@ -85,17 +87,17 @@ class Xml2MavenPom extends Xml2Data {
|
|||
if (dep_scope == null) {
|
||||
dep_scope = "compile";
|
||||
}
|
||||
optional = resolveProperties(optional);
|
||||
optional = resolveMavenProperties(optional);
|
||||
if ("true".equals(optional)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var resolved_dependency = new PomDependency(
|
||||
resolveProperties(dependency.groupId()),
|
||||
resolveProperties(dependency.artifactId()),
|
||||
resolveProperties(version),
|
||||
resolveProperties(dependency.classifier()),
|
||||
resolveProperties(dependency.type()),
|
||||
resolveMavenProperties(dependency.groupId()),
|
||||
resolveMavenProperties(dependency.artifactId()),
|
||||
resolveMavenProperties(version),
|
||||
resolveMavenProperties(dependency.classifier()),
|
||||
resolveMavenProperties(dependency.type()),
|
||||
dep_scope,
|
||||
"false",
|
||||
exclusions,
|
||||
|
@ -126,13 +128,13 @@ class Xml2MavenPom extends Xml2Data {
|
|||
|
||||
PomDependency resolveDependency(PomDependency dependency) {
|
||||
return new PomDependency(
|
||||
resolveProperties(dependency.groupId()),
|
||||
resolveProperties(dependency.artifactId()),
|
||||
resolveProperties(dependency.version()),
|
||||
resolveProperties(dependency.classifier()),
|
||||
resolveProperties(dependency.type()),
|
||||
resolveMavenProperties(dependency.groupId()),
|
||||
resolveMavenProperties(dependency.artifactId()),
|
||||
resolveMavenProperties(dependency.version()),
|
||||
resolveMavenProperties(dependency.classifier()),
|
||||
resolveMavenProperties(dependency.type()),
|
||||
dependency.scope(),
|
||||
resolveProperties(dependency.optional()),
|
||||
resolveMavenProperties(dependency.optional()),
|
||||
dependency.exclusions(),
|
||||
dependency.parent());
|
||||
}
|
||||
|
@ -178,11 +180,11 @@ class Xml2MavenPom extends Xml2Data {
|
|||
switch (qName) {
|
||||
case "parent" -> {
|
||||
if (isChildOfProject()) {
|
||||
var parent_dependency = new Dependency(resolveProperties(lastGroupId_), resolveProperties(lastArtifactId_), VersionNumber.parse(resolveProperties(lastVersion_)));
|
||||
var parent = new DependencyResolver(retriever_, repositories_, parent_dependency).getMavenPom(parent_);
|
||||
var parent_dependency = new Dependency(resolveMavenProperties(lastGroupId_), resolveMavenProperties(lastArtifactId_), VersionNumber.parse(resolveMavenProperties(lastVersion_)));
|
||||
var parent = new DependencyResolver(resolution_, retriever_, repositories_, parent_dependency).getMavenPom(parent_);
|
||||
|
||||
parent.properties_.keySet().removeAll(properties_.keySet());
|
||||
properties_.putAll(parent.properties_);
|
||||
parent.mavenProperties_.keySet().removeAll(mavenProperties_.keySet());
|
||||
mavenProperties_.putAll(parent.mavenProperties_);
|
||||
|
||||
parent.dependencyManagement_.keySet().removeAll(dependencyManagement_.keySet());
|
||||
dependencyManagement_.putAll(parent.dependencyManagement_);
|
||||
|
@ -206,8 +208,8 @@ class Xml2MavenPom extends Xml2Data {
|
|||
var dependency = new PomDependency(lastGroupId_, lastArtifactId_, lastVersion_, lastClassifier_, lastType_, lastScope_, lastOptional_, exclusions_, parent_);
|
||||
if (collectDependencyManagement_) {
|
||||
if (dependency.isPomImport()) {
|
||||
var import_dependency = new Dependency(resolveProperties(lastGroupId_), resolveProperties(lastArtifactId_), VersionNumber.parse(resolveProperties(lastVersion_)));
|
||||
var imported_pom = new DependencyResolver(retriever_, repositories_, import_dependency).getMavenPom(parent_);
|
||||
var import_dependency = new Dependency(resolveMavenProperties(lastGroupId_), resolveMavenProperties(lastArtifactId_), VersionNumber.parse(resolveMavenProperties(lastVersion_)));
|
||||
var imported_pom = new DependencyResolver(resolution_, retriever_, repositories_, import_dependency).getMavenPom(parent_);
|
||||
imported_pom.dependencyManagement_.keySet().removeAll(dependencyManagement_.keySet());
|
||||
var resolved_dependencies = new LinkedHashSet<PomDependency>();
|
||||
for (var managed_dependency : imported_pom.dependencyManagement_.keySet()) {
|
||||
|
@ -278,7 +280,7 @@ class Xml2MavenPom extends Xml2Data {
|
|||
}
|
||||
default -> {
|
||||
if (collectProperties_) {
|
||||
properties_.put(qName, getCharacterData());
|
||||
mavenProperties_.put(qName, getCharacterData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +305,7 @@ class Xml2MavenPom extends Xml2Data {
|
|||
}
|
||||
|
||||
private void addProjectProperty(String name) {
|
||||
properties_.put("project." + name, getCharacterData());
|
||||
mavenProperties_.put("project." + name, getCharacterData());
|
||||
}
|
||||
|
||||
private String getCharacterData() {
|
||||
|
@ -320,7 +322,7 @@ class Xml2MavenPom extends Xml2Data {
|
|||
|
||||
private static final Pattern MAVEN_PROPERTY = Pattern.compile("\\$\\{([^<>{}]+)}");
|
||||
|
||||
private String resolveProperties(String data) {
|
||||
private String resolveMavenProperties(String data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -335,9 +337,9 @@ class Xml2MavenPom extends Xml2Data {
|
|||
while (matcher.find()) {
|
||||
if (matcher.groupCount() == 1) {
|
||||
var property = matcher.group(1);
|
||||
if (properties_.containsKey(property)) {
|
||||
if (mavenProperties_.containsKey(property)) {
|
||||
processed_data.append(data, last_end, matcher.start());
|
||||
processed_data.append(properties_.get(property));
|
||||
processed_data.append(mavenProperties_.get(property));
|
||||
last_end = matcher.end();
|
||||
|
||||
replaced = true;
|
||||
|
|
|
@ -8,6 +8,7 @@ import rife.bld.BaseProject;
|
|||
import rife.bld.BldVersion;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.bld.wrapper.Wrapper;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -22,6 +23,7 @@ import static rife.bld.dependencies.Scope.*;
|
|||
* @since 1.5.21
|
||||
*/
|
||||
public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOperation> {
|
||||
private HierarchicalProperties properties_ = null;
|
||||
private ArtifactRetriever retriever_ = null;
|
||||
private final List<Repository> repositories_ = new ArrayList<>();
|
||||
private final DependencyScopes dependencies_ = new DependencyScopes();
|
||||
|
@ -66,7 +68,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
* @since 2.0
|
||||
*/
|
||||
protected String executeGenerateExtensionsDependencies() {
|
||||
var extensions_tree = extensionDependencies().scope(compile).generateTransitiveDependencyTree(artifactRetriever(), extensionRepositories(), compile, runtime);
|
||||
var extensions_tree = extensionDependencies().scope(compile).generateTransitiveDependencyTree(new VersionResolution(properties()), artifactRetriever(), extensionRepositories(), compile, runtime);
|
||||
if (extensions_tree.isEmpty()) {
|
||||
extensions_tree = "no dependencies" + System.lineSeparator();
|
||||
}
|
||||
|
@ -79,7 +81,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
* @since 1.5.21
|
||||
*/
|
||||
protected String executeGenerateCompileDependencies() {
|
||||
var compile_tree = dependencies().scope(compile).generateTransitiveDependencyTree(artifactRetriever(), repositories(), compile);
|
||||
var compile_tree = dependencies().scope(compile).generateTransitiveDependencyTree(new VersionResolution(properties()), artifactRetriever(), repositories(), compile);
|
||||
if (compile_tree.isEmpty()) {
|
||||
compile_tree = "no dependencies" + System.lineSeparator();
|
||||
}
|
||||
|
@ -92,7 +94,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
* @since 1.7.3
|
||||
*/
|
||||
protected String executeGenerateProvidedDependencies() {
|
||||
var provided_tree = dependencies().scope(provided).generateTransitiveDependencyTree(artifactRetriever(), repositories(), compile, runtime);
|
||||
var provided_tree = dependencies().scope(provided).generateTransitiveDependencyTree(new VersionResolution(properties()), artifactRetriever(), repositories(), compile, runtime);
|
||||
if (provided_tree.isEmpty()) {
|
||||
provided_tree = "no dependencies" + System.lineSeparator();
|
||||
}
|
||||
|
@ -105,7 +107,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
* @since 1.5.21
|
||||
*/
|
||||
protected String executeGenerateRuntimeDependencies() {
|
||||
var runtime_tree = dependencies().scope(runtime).generateTransitiveDependencyTree(artifactRetriever(), repositories(), compile, runtime);
|
||||
var runtime_tree = dependencies().scope(runtime).generateTransitiveDependencyTree(new VersionResolution(properties()), artifactRetriever(), repositories(), compile, runtime);
|
||||
if (runtime_tree.isEmpty()) {
|
||||
runtime_tree = "no dependencies" + System.lineSeparator();
|
||||
}
|
||||
|
@ -118,7 +120,7 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
* @since 1.7.3
|
||||
*/
|
||||
protected String executeGenerateTestDependencies() {
|
||||
var test_tree = dependencies().scope(test).generateTransitiveDependencyTree(artifactRetriever(), repositories(), compile, runtime);
|
||||
var test_tree = dependencies().scope(test).generateTransitiveDependencyTree(new VersionResolution(properties()), artifactRetriever(), repositories(), compile, runtime);
|
||||
if (test_tree.isEmpty()) {
|
||||
test_tree = "no dependencies" + System.lineSeparator();
|
||||
}
|
||||
|
@ -147,7 +149,8 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
}
|
||||
|
||||
// add the repositories and the dependencies from the project
|
||||
return artifactRetriever(project.artifactRetriever())
|
||||
return properties(project.properties())
|
||||
.artifactRetriever(project.artifactRetriever())
|
||||
.repositories(project.repositories())
|
||||
.dependencies(project.dependencies());
|
||||
}
|
||||
|
@ -240,6 +243,18 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the hierarchical properties to use.
|
||||
*
|
||||
* @param properties the hierarchical properties
|
||||
* @return this operation instance
|
||||
* @since 2.0
|
||||
*/
|
||||
public DependencyTreeOperation properties(HierarchicalProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the repositories in which the dependencies will be resolved.
|
||||
* <p>
|
||||
|
@ -310,4 +325,17 @@ public class DependencyTreeOperation extends AbstractOperation<DependencyTreeOpe
|
|||
public String dependencyTree() {
|
||||
return dependencyTree_.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hierarchical properties that are used.
|
||||
*
|
||||
* @return the hierarchical properties
|
||||
* @since 2.0
|
||||
*/
|
||||
public HierarchicalProperties properties() {
|
||||
if (properties_ == null) {
|
||||
properties_ = new HierarchicalProperties();
|
||||
}
|
||||
return properties_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package rife.bld.operations;
|
|||
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -24,6 +25,7 @@ import static rife.bld.dependencies.Dependency.CLASSIFIER_SOURCES;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
||||
private HierarchicalProperties properties_ = null;
|
||||
private ArtifactRetriever retriever_ = null;
|
||||
private final List<Repository> repositories_ = new ArrayList<>();
|
||||
private final DependencyScopes dependencies_ = new DependencyScopes();
|
||||
|
@ -57,7 +59,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executeDownloadCompileDependencies() {
|
||||
executeDownloadDependencies(libCompileDirectory(), dependencies().resolveCompileDependencies(artifactRetriever(), repositories()));
|
||||
executeDownloadDependencies(libCompileDirectory(), dependencies().resolveCompileDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +68,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
* @since 1.8
|
||||
*/
|
||||
protected void executeDownloadProvidedDependencies() {
|
||||
executeDownloadDependencies(libProvidedDirectory(), dependencies().resolveProvidedDependencies(artifactRetriever(), repositories()));
|
||||
executeDownloadDependencies(libProvidedDirectory(), dependencies().resolveProvidedDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +77,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executeDownloadRuntimeDependencies() {
|
||||
executeDownloadDependencies(libRuntimeDirectory(), dependencies().resolveRuntimeDependencies(artifactRetriever(), repositories()));
|
||||
executeDownloadDependencies(libRuntimeDirectory(), dependencies().resolveRuntimeDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +86,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executeDownloadStandaloneDependencies() {
|
||||
executeDownloadDependencies(libStandaloneDirectory(), dependencies().resolveStandaloneDependencies(artifactRetriever(), repositories()));
|
||||
executeDownloadDependencies(libStandaloneDirectory(), dependencies().resolveStandaloneDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +95,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executeDownloadTestDependencies() {
|
||||
executeDownloadDependencies(libTestDirectory(), dependencies().resolveTestDependencies(artifactRetriever(), repositories()));
|
||||
executeDownloadDependencies(libTestDirectory(), dependencies().resolveTestDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,7 +122,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
additional_classifiers = classifiers.toArray(new String[0]);
|
||||
}
|
||||
|
||||
dependencies.transferIntoDirectory(artifactRetriever(), repositories(), destinationDirectory, additional_classifiers);
|
||||
dependencies.transferIntoDirectory(new VersionResolution(properties()), artifactRetriever(), repositories(), destinationDirectory, additional_classifiers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,7 +133,8 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
public DownloadOperation fromProject(BaseProject project) {
|
||||
return artifactRetriever(project.artifactRetriever())
|
||||
return properties(project.properties())
|
||||
.artifactRetriever(project.artifactRetriever())
|
||||
.repositories(project.repositories())
|
||||
.dependencies(project.dependencies())
|
||||
.libCompileDirectory(project.libCompileDirectory())
|
||||
|
@ -279,6 +282,18 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the hierarchical properties to use.
|
||||
*
|
||||
* @param properties the hierarchical properties
|
||||
* @return this operation instance
|
||||
* @since 2.0
|
||||
*/
|
||||
public DownloadOperation properties(HierarchicalProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the repositories in which the dependencies will be resolved.
|
||||
* <p>
|
||||
|
@ -387,4 +402,17 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
|||
}
|
||||
return retriever_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hierarchical properties that are used.
|
||||
*
|
||||
* @return the hierarchical properties
|
||||
* @since 2.0
|
||||
*/
|
||||
public HierarchicalProperties properties() {
|
||||
if (properties_ == null) {
|
||||
properties_ = new HierarchicalProperties();
|
||||
}
|
||||
return properties_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import rife.bld.operations.exceptions.OperationOptionException;
|
|||
import rife.bld.operations.exceptions.SignException;
|
||||
import rife.bld.operations.exceptions.UploadException;
|
||||
import rife.bld.publish.*;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
import rife.tools.FileUtils;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
||||
|
@ -38,6 +39,7 @@ import static rife.tools.StringUtils.encodeHexLower;
|
|||
* @since 1.5.7
|
||||
*/
|
||||
public class PublishOperation extends AbstractOperation<PublishOperation> {
|
||||
private HierarchicalProperties properties_ = null;
|
||||
private ArtifactRetriever retriever_ = null;
|
||||
private final HttpClient client_ = HttpClient.newHttpClient();
|
||||
|
||||
|
@ -45,7 +47,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
private final List<Repository> repositories_ = new ArrayList<>();
|
||||
private final DependencyScopes dependencies_ = new DependencyScopes();
|
||||
private PublishInfo info_ = new PublishInfo();
|
||||
private PublishProperties properties_ = new PublishProperties();
|
||||
private PublishProperties publishProperties_ = new PublishProperties();
|
||||
private final List<PublishArtifact> artifacts_ = new ArrayList<>();
|
||||
|
||||
/**
|
||||
|
@ -121,7 +123,8 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
// determine which build number to use
|
||||
var snapshot_build_number = 1;
|
||||
try {
|
||||
var resolver = new DependencyResolver(artifactRetriever(), List.of(repository), new Dependency(info().groupId(), info().artifactId(), info().version()));
|
||||
var resolution = new VersionResolution(properties());
|
||||
var resolver = new DependencyResolver(resolution, artifactRetriever(), List.of(repository), new Dependency(info().groupId(), info().artifactId(), info().version()));
|
||||
var snapshot_meta = resolver.getSnapshotMavenMetadata();
|
||||
snapshot_build_number = snapshot_meta.getSnapshotBuildNumber() + 1;
|
||||
} catch (DependencyException e) {
|
||||
|
@ -191,7 +194,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
// generate and upload pom
|
||||
executePublishStringArtifact(
|
||||
repository,
|
||||
new PomBuilder().properties(properties()).info(info()).dependencies(dependencies()).build(),
|
||||
new PomBuilder().properties(publishProperties()).info(info()).dependencies(dependencies()).build(),
|
||||
info().version() + "/" + info().artifactId() + "-" + actualVersion + ".pom", true);
|
||||
}
|
||||
|
||||
|
@ -204,7 +207,8 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
*/
|
||||
protected void executePublishMetadata(Repository repository, ZonedDateTime moment) {
|
||||
var current_versions = new ArrayList<VersionNumber>();
|
||||
var resolver = new DependencyResolver(artifactRetriever(), List.of(repository), new Dependency(info().groupId(), info().artifactId(), info().version()));
|
||||
var resolution = new VersionResolution(properties());
|
||||
var resolver = new DependencyResolver(resolution, artifactRetriever(), List.of(repository), new Dependency(info().groupId(), info().artifactId(), info().version()));
|
||||
try {
|
||||
current_versions.addAll(resolver.getMavenMetadata().getVersions());
|
||||
} catch (DependencyException e) {
|
||||
|
@ -498,10 +502,11 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
*/
|
||||
public PublishOperation fromProject(BaseProject project) {
|
||||
if (project.javaRelease() != null) {
|
||||
properties()
|
||||
publishProperties()
|
||||
.mavenCompilerSource(project.javaRelease())
|
||||
.mavenCompilerTarget(project.javaRelease());
|
||||
}
|
||||
properties(project.properties());
|
||||
artifactRetriever(project.artifactRetriever());
|
||||
dependencies().include(project.dependencies());
|
||||
artifacts(List.of(
|
||||
|
@ -604,10 +609,10 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
*
|
||||
* @param properties the publication properties
|
||||
* @return this operation instance
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public PublishOperation properties(PublishProperties properties) {
|
||||
properties_ = properties;
|
||||
public PublishOperation publishProperties(PublishProperties properties) {
|
||||
publishProperties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -661,6 +666,18 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the hierarchical properties to use.
|
||||
*
|
||||
* @param properties the hierarchical properties
|
||||
* @return this operation instance
|
||||
* @since 2.0
|
||||
*/
|
||||
public PublishOperation properties(HierarchicalProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the repositories to which will be published.
|
||||
* <p>
|
||||
|
@ -691,10 +708,10 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
* This is a modifiable structure that can be retrieved and changed.
|
||||
*
|
||||
* @return the publication properties
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public PublishProperties properties() {
|
||||
return properties_;
|
||||
public PublishProperties publishProperties() {
|
||||
return publishProperties_;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -733,4 +750,17 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
}
|
||||
return retriever_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hierarchical properties that are used.
|
||||
*
|
||||
* @return the hierarchical properties
|
||||
* @since 2.0
|
||||
*/
|
||||
public HierarchicalProperties properties() {
|
||||
if (properties_ == null) {
|
||||
properties_ = new HierarchicalProperties();
|
||||
}
|
||||
return properties_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package rife.bld.operations;
|
|||
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -24,6 +25,7 @@ import static rife.bld.dependencies.Dependency.CLASSIFIER_SOURCES;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
||||
private HierarchicalProperties properties_ = null;
|
||||
private ArtifactRetriever retriever_ = null;
|
||||
private final List<Repository> repositories_ = new ArrayList<>();
|
||||
private final DependencyScopes dependencies_ = new DependencyScopes();
|
||||
|
@ -57,7 +59,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executePurgeCompileDependencies() {
|
||||
executePurgeDependencies(libCompileDirectory(), dependencies().resolveCompileDependencies(artifactRetriever(), repositories()));
|
||||
executePurgeDependencies(libCompileDirectory(), dependencies().resolveCompileDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +68,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
* @since 1.8
|
||||
*/
|
||||
protected void executePurgeProvidedDependencies() {
|
||||
executePurgeDependencies(libProvidedDirectory(), dependencies().resolveProvidedDependencies(artifactRetriever(), repositories()));
|
||||
executePurgeDependencies(libProvidedDirectory(), dependencies().resolveProvidedDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +77,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executePurgeRuntimeDependencies() {
|
||||
executePurgeDependencies(libRuntimeDirectory(), dependencies().resolveRuntimeDependencies(artifactRetriever(), repositories()));
|
||||
executePurgeDependencies(libRuntimeDirectory(), dependencies().resolveRuntimeDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +86,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executePurgeStandaloneDependencies() {
|
||||
executePurgeDependencies(libStandaloneDirectory(), dependencies().resolveStandaloneDependencies(artifactRetriever(), repositories()));
|
||||
executePurgeDependencies(libStandaloneDirectory(), dependencies().resolveStandaloneDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +95,7 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
protected void executePurgeTestDependencies() {
|
||||
executePurgeDependencies(libTestDirectory(), dependencies().resolveTestDependencies(artifactRetriever(), repositories()));
|
||||
executePurgeDependencies(libTestDirectory(), dependencies().resolveTestDependencies(properties(), artifactRetriever(), repositories()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +134,8 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
}
|
||||
|
||||
private void addTransferLocations(HashSet<String> filenames, Dependency dependency) {
|
||||
for (var location : new DependencyResolver(artifactRetriever(), repositories(), dependency).getTransferLocations()) {
|
||||
var resolution = new VersionResolution(properties());
|
||||
for (var location : new DependencyResolver(resolution, artifactRetriever(), repositories(), dependency).getTransferLocations()) {
|
||||
filenames.add(location.substring(location.lastIndexOf("/") + 1));
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +147,8 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
public PurgeOperation fromProject(BaseProject project) {
|
||||
return artifactRetriever(project.artifactRetriever())
|
||||
return properties(project.properties())
|
||||
.artifactRetriever(project.artifactRetriever())
|
||||
.repositories(project.repositories())
|
||||
.dependencies(project.dependencies())
|
||||
.libCompileDirectory(project.libCompileDirectory())
|
||||
|
@ -292,6 +296,18 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the hierarchical properties to use.
|
||||
*
|
||||
* @param properties the hierarchical properties
|
||||
* @return this operation instance
|
||||
* @since 2.0
|
||||
*/
|
||||
public PurgeOperation properties(HierarchicalProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the repositories in which the dependencies will be resolved.
|
||||
* <p>
|
||||
|
@ -400,4 +416,17 @@ public class PurgeOperation extends AbstractOperation<PurgeOperation> {
|
|||
}
|
||||
return retriever_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hierarchical properties that are used.
|
||||
*
|
||||
* @return the hierarchical properties
|
||||
* @since 2.0
|
||||
*/
|
||||
public HierarchicalProperties properties() {
|
||||
if (properties_ == null) {
|
||||
properties_ = new HierarchicalProperties();
|
||||
}
|
||||
return properties_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package rife.bld.operations;
|
|||
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -17,6 +18,7 @@ import java.util.List;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class UpdatesOperation extends AbstractOperation<UpdatesOperation> {
|
||||
private HierarchicalProperties properties_ = null;
|
||||
private ArtifactRetriever retriever_ = null;
|
||||
private final List<Repository> repositories_ = new ArrayList<>();
|
||||
private final DependencyScopes dependencies_ = new DependencyScopes();
|
||||
|
@ -28,11 +30,12 @@ public class UpdatesOperation extends AbstractOperation<UpdatesOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
public void execute() {
|
||||
var resolution = new VersionResolution(properties());
|
||||
var result = new DependencyScopes();
|
||||
for (var entry : dependencies_.entrySet()) {
|
||||
var scope = entry.getKey();
|
||||
for (var dependency : entry.getValue()) {
|
||||
var latest = new DependencyResolver(artifactRetriever(), repositories(), dependency).latestVersion();
|
||||
var latest = new DependencyResolver(resolution, artifactRetriever(), repositories(), dependency).latestVersion();
|
||||
if (latest.compareTo(dependency.version()) > 0) {
|
||||
var latest_dependency = new Dependency(dependency.groupId(), dependency.artifactId(), latest,
|
||||
dependency.classifier(), dependency.type());
|
||||
|
@ -65,7 +68,8 @@ public class UpdatesOperation extends AbstractOperation<UpdatesOperation> {
|
|||
* @since 1.5
|
||||
*/
|
||||
public UpdatesOperation fromProject(BaseProject project) {
|
||||
return artifactRetriever(project.artifactRetriever())
|
||||
return properties(project.properties())
|
||||
.artifactRetriever(project.artifactRetriever())
|
||||
.repositories(project.repositories())
|
||||
.dependencies(project.dependencies());
|
||||
}
|
||||
|
@ -120,6 +124,18 @@ public class UpdatesOperation extends AbstractOperation<UpdatesOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the hierarchical properties to use.
|
||||
*
|
||||
* @param properties the hierarchical properties
|
||||
* @return this operation instance
|
||||
* @since 2.0
|
||||
*/
|
||||
public UpdatesOperation properties(HierarchicalProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the repositories in which the dependencies will be resolved.
|
||||
* <p>
|
||||
|
@ -166,4 +182,17 @@ public class UpdatesOperation extends AbstractOperation<UpdatesOperation> {
|
|||
}
|
||||
return retriever_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hierarchical properties that are used.
|
||||
*
|
||||
* @return the hierarchical properties
|
||||
* @since 2.0
|
||||
*/
|
||||
public HierarchicalProperties properties() {
|
||||
if (properties_ == null) {
|
||||
properties_ = new HierarchicalProperties();
|
||||
}
|
||||
return properties_;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class PomBuilder {
|
|||
*
|
||||
* @param properties the properties to use
|
||||
* @return this {@code PomBuilder} instance
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public PomBuilder properties(PublishProperties properties) {
|
||||
properties_ = properties;
|
||||
|
@ -63,7 +63,7 @@ public class PomBuilder {
|
|||
* Retrieves the properties to build the POM with.
|
||||
*
|
||||
* @return the properties to use
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public PublishProperties properties() {
|
||||
return properties_;
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.*;
|
|||
* Provides the properties information for publication.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public class PublishProperties extends LinkedHashMap<String, String> {
|
||||
private static final String MAVEN_COMPILER_SOURCE = "maven.compiler.source";
|
||||
|
@ -21,7 +21,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
|||
*
|
||||
* @param value the value to be set for the 'maven.compiler.source' property
|
||||
* @return this {@code PomProperties} instance
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public PublishProperties mavenCompilerSource(Integer value) {
|
||||
if (value == null) {
|
||||
|
@ -37,7 +37,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
|||
* Retrieves the value of the 'maven.compiler.source' property.
|
||||
*
|
||||
* @return the value of the 'maven.compiler.source' property
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public Integer mavenCompilerSource() {
|
||||
var value = get(MAVEN_COMPILER_SOURCE);
|
||||
|
@ -52,7 +52,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
|||
*
|
||||
* @param value the value to be set for the 'maven.compiler.target' property
|
||||
* @return this {@code PomProperties} instance
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public PublishProperties mavenCompilerTarget(Integer value) {
|
||||
if (value == null) {
|
||||
|
@ -68,7 +68,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
|||
* Retrieves the value of the 'maven.compiler.target' property.
|
||||
*
|
||||
* @return the value of the 'maven.compiler.target' property
|
||||
* @since 2.0.0
|
||||
* @since 2.0
|
||||
*/
|
||||
public Integer mavenCompilerTarget() {
|
||||
var value = get(MAVEN_COMPILER_TARGET);
|
||||
|
|
|
@ -69,6 +69,7 @@ public class Wrapper {
|
|||
static final Pattern META_DATA_LOCAL_COPY = Pattern.compile("<localCopy>\\s*true\\s*</localCopy>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||
static final Pattern META_DATA_SNAPSHOT_VERSION = Pattern.compile("<snapshotVersion>.*?<value>([^<]+)</value>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||
static final Pattern OPTIONS_PATTERN = Pattern.compile("\"[^\"]+\"|\\S+");
|
||||
static final Pattern JVM_PROPERTY_PATTERN = Pattern.compile("-D(.+?)=(.*)");
|
||||
|
||||
private static final Pattern JAR_EXCLUDE_SOURCES_PATTERN = Pattern.compile("^.*-sources\\.jar$", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern JAR_EXCLUDE_JAVADOC_PATTERN = Pattern.compile("^.*-javadoc\\.jar$", Pattern.CASE_INSENSITIVE);
|
||||
|
@ -78,6 +79,7 @@ public class Wrapper {
|
|||
private File currentDir_ = new File(System.getProperty("user.dir"));
|
||||
private LaunchMode launchMode_ = LaunchMode.Cli;
|
||||
|
||||
private final Properties jvmProperties_ = new Properties();
|
||||
private final Properties wrapperProperties_ = new Properties();
|
||||
private File wrapperPropertiesFile_ = null;
|
||||
private final Set<String> repositories_ = new LinkedHashSet<>();
|
||||
|
@ -376,6 +378,7 @@ public class Wrapper {
|
|||
}
|
||||
|
||||
try {
|
||||
extractJvmProperties(arguments);
|
||||
initWrapperProperties(getVersion());
|
||||
File distribution;
|
||||
try {
|
||||
|
@ -389,6 +392,15 @@ public class Wrapper {
|
|||
}
|
||||
}
|
||||
|
||||
private void extractJvmProperties(List<String> arguments) {
|
||||
for (var arg : arguments) {
|
||||
var matcher = JVM_PROPERTY_PATTERN.matcher(arg);
|
||||
if (matcher.matches()) {
|
||||
jvmProperties_.put(matcher.group(1), matcher.group(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File buildBldDirectory() {
|
||||
return Path.of(currentDir_.getAbsolutePath(), "build", "bld").toFile();
|
||||
}
|
||||
|
@ -587,9 +599,10 @@ public class Wrapper {
|
|||
|
||||
try {
|
||||
var resolver_class = classloader_.loadClass("rife.bld.wrapper.WrapperExtensionResolver");
|
||||
var constructor = resolver_class.getConstructor(File.class, File.class, File.class, Collection.class, Collection.class, boolean.class, boolean.class);
|
||||
var constructor = resolver_class.getConstructor(File.class, File.class, File.class, Properties.class, Properties.class, Collection.class, Collection.class, boolean.class, boolean.class);
|
||||
var update_method = resolver_class.getMethod("updateExtensions");
|
||||
var resolver = constructor.newInstance(currentDir_, new File(wrapperPropertiesFile_.getAbsolutePath() + ".hash"), libBldDirectory(),
|
||||
jvmProperties_, wrapperProperties_,
|
||||
repositories_, extensions_,
|
||||
downloadExtensionSources_, downloadExtensionJavadoc_);
|
||||
update_method.invoke(resolver);
|
||||
|
@ -612,7 +625,7 @@ public class Wrapper {
|
|||
throws IOException, InterruptedException {
|
||||
var args = new ArrayList<String>();
|
||||
args.add("java");
|
||||
includeJvmParameters(arguments, args);
|
||||
includeJvmProperties(arguments, args);
|
||||
|
||||
args.add("-cp");
|
||||
args.add(jarFile.getAbsolutePath());
|
||||
|
@ -665,7 +678,7 @@ public class Wrapper {
|
|||
|
||||
var java_args = new ArrayList<String>();
|
||||
java_args.add("java");
|
||||
includeJvmParameters(arguments, java_args);
|
||||
includeJvmProperties(arguments, java_args);
|
||||
|
||||
java_args.add("-cp");
|
||||
java_args.add(classpath);
|
||||
|
@ -681,11 +694,11 @@ public class Wrapper {
|
|||
return process.waitFor();
|
||||
}
|
||||
|
||||
private static void includeJvmParameters(List<String> arguments, List<String> javaArgs) {
|
||||
private static void includeJvmProperties(List<String> arguments, List<String> javaArgs) {
|
||||
var i = arguments.iterator();
|
||||
while (i.hasNext()) {
|
||||
var arg = i.next();
|
||||
if (arg.matches("-D(.+?)=(.*)")) {
|
||||
if (JVM_PROPERTY_PATTERN.matcher(arg).matches()) {
|
||||
javaArgs.add(arg);
|
||||
i.remove();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package rife.bld.wrapper;
|
|||
|
||||
import rife.bld.BuildExecutor;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
import rife.tools.FileUtils;
|
||||
import rife.tools.StringUtils;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
@ -28,7 +29,9 @@ import static rife.bld.dependencies.Dependency.CLASSIFIER_SOURCES;
|
|||
* @since 1.5.8
|
||||
*/
|
||||
public class WrapperExtensionResolver {
|
||||
private final ArtifactRetriever retriever_ = ArtifactRetriever.cachingInstance();
|
||||
private final HierarchicalProperties properties_;
|
||||
private final VersionResolution resolution_;
|
||||
private final ArtifactRetriever retriever_;
|
||||
private final File hashFile_;
|
||||
private final String fingerPrintHash_;
|
||||
private final File destinationDirectory_;
|
||||
|
@ -41,20 +44,35 @@ public class WrapperExtensionResolver {
|
|||
private boolean headerPrinted_ = false;
|
||||
|
||||
public WrapperExtensionResolver(File currentDir, File hashFile, File destinationDirectory,
|
||||
Properties jvmProperties, Properties wrapperProperties,
|
||||
Collection<String> repositories, Collection<String> extensions,
|
||||
boolean downloadSources, boolean downloadJavadoc) {
|
||||
var properties = BuildExecutor.setupProperties(currentDir);
|
||||
Repository.resolveMavenLocal(properties);
|
||||
properties.getRoot().putAll(jvmProperties);
|
||||
properties_ = new HierarchicalProperties().parent(properties);
|
||||
properties_.putAll(wrapperProperties);
|
||||
|
||||
resolution_ = new VersionResolution(properties_);
|
||||
|
||||
retriever_ = ArtifactRetriever.cachingInstance();
|
||||
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(Dependency::parse).toList());
|
||||
|
||||
dependencies_.addAll(extensions.stream().map(d -> resolution_.overrideDependency(Dependency.parse(d))).toList());
|
||||
|
||||
downloadSources_ = downloadSources;
|
||||
downloadJavadoc_ = downloadJavadoc;
|
||||
fingerPrintHash_ = createHash(repositories_.stream().map(Objects::toString).toList(), extensions, downloadSources, downloadJavadoc);
|
||||
fingerPrintHash_ = createHash(
|
||||
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) {
|
||||
|
@ -149,7 +167,7 @@ public class WrapperExtensionResolver {
|
|||
var dependencies = new DependencySet();
|
||||
for (var d : dependencies_) {
|
||||
if (d != null) {
|
||||
dependencies.addAll(new DependencyResolver(retriever_, repositories_, d).getAllDependencies(Scope.compile, Scope.runtime));
|
||||
dependencies.addAll(new DependencyResolver(resolution_, retriever_, repositories_, d).getAllDependencies(Scope.compile, Scope.runtime));
|
||||
}
|
||||
}
|
||||
if (!dependencies.isEmpty()) {
|
||||
|
@ -166,7 +184,7 @@ public class WrapperExtensionResolver {
|
|||
additional_classifiers = classifiers.toArray(new String[0]);
|
||||
}
|
||||
|
||||
var artifacts = dependencies.transferIntoDirectory(retriever_, repositories_, destinationDirectory_, additional_classifiers);
|
||||
var artifacts = dependencies.transferIntoDirectory(resolution_, retriever_, repositories_, destinationDirectory_, additional_classifiers);
|
||||
for (var artifact : artifacts) {
|
||||
var location = artifact.location();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue