Skip to content

Commit

Permalink
Added ability to individually exclude sources and javadocs downloads …
Browse files Browse the repository at this point in the history
…for dependencies
  • Loading branch information
gbevin committed Aug 29, 2024
1 parent a07db3f commit df173c4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
29 changes: 29 additions & 0 deletions src/main/java/rife/bld/dependencies/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package rife.bld.dependencies;

import java.util.HashSet;
import java.util.Objects;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -46,6 +47,7 @@ public class Dependency {
private final String type_;
private final ExclusionSet exclusions_;
private final Dependency parent_;
private final HashSet<String> excludedClassifiers_;

public Dependency(String groupId, String artifactId) {
this(groupId, artifactId, null, null, null);
Expand Down Expand Up @@ -82,6 +84,7 @@ public Dependency(String groupId, String artifactId, Version version, String cla
this.type_ = type;
this.exclusions_ = (exclusions == null ? new ExclusionSet() : exclusions);
this.parent_ = parent;
this.excludedClassifiers_ = new HashSet<>();
}

private static final Pattern DEPENDENCY_PATTERN = Pattern.compile("^(?<groupId>[^:@]+):(?<artifactId>[^:@]+)(?::(?<version>[^:@]+)(?::(?<classifier>[^:@]+))?)?(?:@(?<type>[^:@]+))?$");
Expand Down Expand Up @@ -152,6 +155,28 @@ public Dependency withClassifier(String classifier) {
return new Dependency(groupId_, artifactId_, version_, classifier, type_);
}

/**
* Exclude the sources artifact from download operations.
*
* @return this dependency instance
* @since 2.1
*/
public Dependency excludeSources() {
excludedClassifiers_.add(CLASSIFIER_SOURCES);
return this;
}

/**
* Exclude the javadoc artifact from download operations.
*
* @return this dependency instance
* @since 2.1
*/
public Dependency excludeJavadoc() {
excludedClassifiers_.add(CLASSIFIER_JAVADOC);
return this;
}

/**
* Returns a filename that corresponds to the dependency information.
*
Expand Down Expand Up @@ -253,6 +278,10 @@ public ExclusionSet exclusions() {
return exclusions_;
}

public HashSet<String> excludedClassifiers() {
return excludedClassifiers_;
}

/**
* Returns this dependency's {@code parent} dependency that created this
* dependency (only for information purposes).
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rife/bld/dependencies/DependencySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public List<RepositoryArtifact> transferIntoDirectory(VersionResolution resoluti
* @param repositories the repositories to use for the download
* @param directory the directory to download the artifacts into
* @param modulesDirectory the directory to download the modules into
* @param classifiers the additional classifiers to transfer
* @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 2.1
Expand Down Expand Up @@ -166,7 +166,7 @@ else if (directory == null) {

if (classifiers != null) {
for (var classifier : classifiers) {
if (classifier != null) {
if (classifier != null && !dependency.excludedClassifiers().contains(classifier)) {
var classifier_artifact = new DependencyResolver(resolution, retriever, repositories, dependency.withClassifier(classifier)).transferIntoDirectory(transfer_directory);
if (classifier_artifact != null) {
result.add(classifier_artifact);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rife/bld/operations/PurgeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ protected void executePurgeDependencies(File classpathDirectory, File modulesDir
filenames = modules_names;
}
addTransferLocations(filenames, dependency);
if (preserveSources_) {
if (preserveSources_ && !dependency.excludedClassifiers().contains(CLASSIFIER_SOURCES)) {
addTransferLocations(filenames, dependency.withClassifier(CLASSIFIER_SOURCES));
}
if (preserveJavadoc_) {
if (preserveJavadoc_ && !dependency.excludedClassifiers().contains(CLASSIFIER_JAVADOC)) {
addTransferLocations(filenames, dependency.withClassifier(CLASSIFIER_JAVADOC));
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/rife/bld/operations/TestDownloadOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ void testExecutionAdditionalSourcesJavadoc()
.downloadSources(true);
operation.dependencies().scope(Scope.compile)
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3,12,0)))
.include(new Module("org.json", "json", new VersionNumber(20240303)));
.include(new Module("org.json", "json", new VersionNumber(20240303)).excludeSources());
operation.dependencies().scope(Scope.provided)
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,17,0)))
.include(new Module("com.google.zxing", "javase", new VersionNumber(3,5,3)));
.include(new Module("com.google.zxing", "javase", new VersionNumber(3,5,3)).excludeJavadoc());
operation.dependencies().scope(Scope.runtime)
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4,4)))
.include(new Module("org.postgresql", "postgresql", new VersionNumber(42,7,3)));
Expand All @@ -252,7 +252,7 @@ void testExecutionAdditionalSourcesJavadoc()
.include(new Module("org.eclipse.jetty.ee10", "jetty-ee10-servlet", new VersionNumber(12,0,12)));
operation.dependencies().scope(Scope.test)
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5,2,1)))
.include(new Module("org.jsoup", "jsoup", new VersionNumber(1,18,1)));
.include(new Module("org.jsoup", "jsoup", new VersionNumber(1,18,1)).excludeSources().excludeJavadoc());

operation.execute();

Expand Down Expand Up @@ -299,8 +299,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir4/slf4j-simple-2.0.6.jar
/dir5
/dir5/dir10
/dir5/dir10/jsoup-1.18.1-javadoc.jar
/dir5/dir10/jsoup-1.18.1-sources.jar
/dir5/dir10/jsoup-1.18.1.jar
/dir5/httpclient5-5.2.1-javadoc.jar
/dir5/httpclient5-5.2.1-sources.jar
Expand All @@ -316,7 +314,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir5/slf4j-api-1.7.36.jar
/dir6
/dir6/json-20240303-javadoc.jar
/dir6/json-20240303-sources.jar
/dir6/json-20240303.jar
/dir7
/dir7/core-3.5.3-javadoc.jar
Expand All @@ -325,7 +322,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir7/jai-imageio-core-1.4.0-javadoc.jar
/dir7/jai-imageio-core-1.4.0-sources.jar
/dir7/jai-imageio-core-1.4.0.jar
/dir7/javase-3.5.3-javadoc.jar
/dir7/javase-3.5.3-sources.jar
/dir7/javase-3.5.3.jar
/dir7/jcommander-1.82-javadoc.jar
Expand Down Expand Up @@ -366,7 +362,7 @@ void testFromProject()
project.repositories().add(Repository.MAVEN_CENTRAL);
project.dependencies().scope(Scope.compile)
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3,12,0)))
.include(new Module("org.json", "json", new VersionNumber(20240303)));
.include(new Module("org.json", "json", new VersionNumber(20240303)).excludeSources());
project.dependencies().scope(Scope.provided)
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,17,0)))
.include(new Module("com.google.zxing", "javase", new VersionNumber(3,5,3)));
Expand All @@ -392,7 +388,6 @@ void testFromProject()
/lib/compile/commons-lang3-3.12.0-sources.jar
/lib/compile/commons-lang3-3.12.0.jar
/lib/compile/modules
/lib/compile/modules/json-20240303-sources.jar
/lib/compile/modules/json-20240303.jar
/lib/provided
/lib/provided/commons-codec-1.17.0-sources.jar
Expand Down
12 changes: 3 additions & 9 deletions src/test/java/rife/bld/operations/TestPurgeOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,10 @@ void testExecutionAdditionalSourcesJavadoc()
.preserveJavadoc(true);
operation_purge.dependencies().scope(Scope.compile)
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3,12,0)))
.include(new Module("org.json", "json", new VersionNumber(20240303)));
.include(new Module("org.json", "json", new VersionNumber(20240303)).excludeSources());
operation_purge.dependencies().scope(Scope.provided)
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,17,0)))
.include(new Module("com.google.zxing", "javase", new VersionNumber(3,5,3)));
.include(new Module("com.google.zxing", "javase", new VersionNumber(3,5,3)).excludeJavadoc());
operation_purge.dependencies().scope(Scope.runtime)
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4,4)))
.include(new Module("org.postgresql", "postgresql", new VersionNumber(42,7,3)));
Expand All @@ -593,7 +593,7 @@ void testExecutionAdditionalSourcesJavadoc()
.include(new Module("org.eclipse.jetty.ee10", "jetty-ee10-servlet", new VersionNumber(12,0,12)));
operation_purge.dependencies().scope(Scope.test)
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5,2,1)))
.include(new Module("org.jsoup", "jsoup", new VersionNumber(1,18,1)));
.include(new Module("org.jsoup", "jsoup", new VersionNumber(1,18,1)).excludeSources().excludeJavadoc());

operation_purge.execute();

Expand Down Expand Up @@ -640,8 +640,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir4/slf4j-simple-2.0.6.jar
/dir5
/dir5/dir10
/dir5/dir10/jsoup-1.18.1-javadoc.jar
/dir5/dir10/jsoup-1.18.1-sources.jar
/dir5/dir10/jsoup-1.18.1.jar
/dir5/httpclient5-5.2.1-javadoc.jar
/dir5/httpclient5-5.2.1-sources.jar
Expand All @@ -657,7 +655,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir5/slf4j-api-1.7.36.jar
/dir6
/dir6/json-20240303-javadoc.jar
/dir6/json-20240303-sources.jar
/dir6/json-20240303.jar
/dir7
/dir7/core-3.5.3-javadoc.jar
Expand All @@ -666,7 +663,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir7/jai-imageio-core-1.4.0-javadoc.jar
/dir7/jai-imageio-core-1.4.0-sources.jar
/dir7/jai-imageio-core-1.4.0.jar
/dir7/javase-3.5.3-javadoc.jar
/dir7/javase-3.5.3-sources.jar
/dir7/javase-3.5.3.jar
/dir7/jcommander-1.82-javadoc.jar
Expand Down Expand Up @@ -719,7 +715,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir4/slf4j-simple-2.0.6.jar
/dir5
/dir5/dir10
/dir5/dir10/jsoup-1.18.1-sources.jar
/dir5/dir10/jsoup-1.18.1.jar
/dir5/httpclient5-5.2.1-sources.jar
/dir5/httpclient5-5.2.1.jar
Expand All @@ -730,7 +725,6 @@ void testExecutionAdditionalSourcesJavadoc()
/dir5/slf4j-api-1.7.36-sources.jar
/dir5/slf4j-api-1.7.36.jar
/dir6
/dir6/json-20240303-sources.jar
/dir6/json-20240303.jar
/dir7
/dir7/core-3.5.3-sources.jar
Expand Down

0 comments on commit df173c4

Please sign in to comment.