From 16c865ef09c927db65966ba1606c301719304779 Mon Sep 17 00:00:00 2001 From: Yahav Itschak Date: Thu, 13 Jun 2024 14:08:00 +0300 Subject: [PATCH] Remove Guava (#114) --- .github/workflows/analysis.yml | 6 +++--- .github/workflows/frogbot-scan-and-fix.yml | 6 +++--- .../workflows/frogbot-scan-pull-request.yml | 6 +++--- .github/workflows/gradle.yml | 6 +++--- .github/workflows/test.yml | 13 ++++++++++--- build.gradle.kts | 7 ++++--- .../artifactory/GradleFunctionalTestBase.java | 7 ++++++- .../extractor/GradleModuleExtractor.java | 14 ++++++-------- .../artifactory/task/ArtifactoryTask.java | 8 ++++---- .../plugin/artifactory/utils/ProjectUtils.java | 18 +++++++++++------- .../artifactory/utils/PublicationUtils.java | 6 +++--- 11 files changed, 56 insertions(+), 41 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index 223e613..c2f0071 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -15,14 +15,14 @@ jobs: spotbugs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} # Install required tools - name: Set up Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - distribution: "temurin" + distribution: "zulu" java-version: "8" # Run tests diff --git a/.github/workflows/frogbot-scan-and-fix.yml b/.github/workflows/frogbot-scan-and-fix.yml index 3537c63..3c37f37 100644 --- a/.github/workflows/frogbot-scan-and-fix.yml +++ b/.github/workflows/frogbot-scan-and-fix.yml @@ -15,16 +15,16 @@ jobs: # The repository scanning will be triggered periodically on the following branches. branch: [ "main" ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ matrix.branch }} # Install prerequisites - name: Set up Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: "8" - distribution: "temurin" + distribution: "zulu" - uses: jfrog/frogbot@v2 env: diff --git a/.github/workflows/frogbot-scan-pull-request.yml b/.github/workflows/frogbot-scan-pull-request.yml index 826a49d..45a3b81 100644 --- a/.github/workflows/frogbot-scan-pull-request.yml +++ b/.github/workflows/frogbot-scan-pull-request.yml @@ -10,16 +10,16 @@ jobs: runs-on: ubuntu-latest environment: frogbot steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} # Install prerequisites - name: Set up Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: "8" - distribution: "temurin" + distribution: "zulu" - uses: jfrog/frogbot@v2 env: diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 29cfab2..b911dd3 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -38,13 +38,13 @@ jobs: - name: "Log if Already Exist" run: echo "::warning::Version $LATEST_MVN_CENTRAL_VERSION already exist in the Gradle Gallery." if: ${{ env.SHOULD_NOT_PUBLISH == 'TRUE'}} - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: refs/tags/${{ env.LATEST_MVN_CENTRAL_VERSION }} if: ${{ env.SHOULD_NOT_PUBLISH != 'TRUE'}} - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: - distribution: "temurin" + distribution: "zulu" java-version: "11" if: ${{ env.SHOULD_NOT_PUBLISH != 'TRUE'}} - name: "Publish to Gradle Gallery" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c257f1..38cb965 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,16 +16,23 @@ jobs: os: [ ubuntu-latest, windows-latest, macOS-latest ] java-version: [ "8", "11" ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} # Install required tools - name: Set up Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - distribution: "temurin" + distribution: "zulu" java-version: ${{ matrix.java-version }} + # Install Go for the Artifactory setup in the next step + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.22.x + cache: false + - name: Setup Artifactory env: RTLIC: ${{ secrets.RTLIC }} diff --git a/build.gradle.kts b/build.gradle.kts index 57a6e0b..c79aa09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,8 +15,9 @@ repositories { mavenCentral() } -val buildInfoVersion = "2.41.12" +val buildInfoVersion = "2.41.18" val fileSpecsVersion = "1.1.2" +val commonsCollections4Version = "4.4" val commonsLangVersion = "3.12.0" val commonsIoVersion = "2.11.0" val commonsTxtVersion = "1.10.0" @@ -40,9 +41,9 @@ dependencies { api("org.jfrog.buildinfo", "build-info-client", buildInfoVersion) api("org.jfrog.filespecs", "file-specs-java", fileSpecsVersion) + implementation("org.apache.commons", "commons-collections4", commonsCollections4Version) implementation("org.apache.commons", "commons-lang3", commonsLangVersion) implementation("org.apache.ivy", "ivy", "2.5.2") - implementation("com.google.guava", "guava", "32.0.1-jre") // Dependencies that are used by the build-info dependencies and need to be included in the UberJar implementation("com.fasterxml.jackson.core", "jackson-databind", "2.14.1") @@ -195,6 +196,6 @@ tasks.register("spotBugs") { } } excludeFilter.set( - file("${projectDir}/spotbugs-filter.xml") + file("${projectDir}/spotbugs-filter.xml") ) } diff --git a/src/functionalTest/java/org/jfrog/gradle/plugin/artifactory/GradleFunctionalTestBase.java b/src/functionalTest/java/org/jfrog/gradle/plugin/artifactory/GradleFunctionalTestBase.java index 3037abd..b477d6d 100644 --- a/src/functionalTest/java/org/jfrog/gradle/plugin/artifactory/GradleFunctionalTestBase.java +++ b/src/functionalTest/java/org/jfrog/gradle/plugin/artifactory/GradleFunctionalTestBase.java @@ -3,6 +3,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.text.StringSubstitutor; import org.gradle.testkit.runner.BuildResult; @@ -53,7 +54,11 @@ public class GradleFunctionalTestBase { @DataProvider public Object[][] gradleVersions() { - return new Object[][]{{"6.8.1"}, {"7.5.1"}, {"7.6"}, {"8.1"}}; + if (SystemUtils.IS_OS_MAC && SystemUtils.OS_ARCH.equals("aarch64")) { + // For Apple Silicon (ARM64), exclude Gradle 6 due to a known issue + return new Object[][]{{"7.5.1"}, {"7.6"}, {"8.8"}}; + } + return new Object[][]{{"6.8.1"}, {"7.5.1"}, {"7.6"}, {"8.8"}}; } @BeforeClass diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/GradleModuleExtractor.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/GradleModuleExtractor.java index ad5a963..28fed6b 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/GradleModuleExtractor.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/extractor/GradleModuleExtractor.java @@ -1,6 +1,5 @@ package org.jfrog.gradle.plugin.artifactory.extractor; -import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -33,13 +32,10 @@ import java.io.File; import java.io.IOException; import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.StreamSupport; -import static com.google.common.collect.Lists.newArrayList; import static org.jfrog.build.api.util.FileChecksumCalculator.*; import static org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString; import static org.jfrog.gradle.plugin.artifactory.utils.PluginUtils.getModuleType; @@ -62,7 +58,7 @@ public Module extractModule(Project project) { */ private Set getCollectedDeployDetails(ArtifactoryTask artifactoryTask) { if (artifactoryTask == null) { - return Sets.newHashSet(); + return new HashSet<>(); } return artifactoryTask.getDeployDetails(); } @@ -129,7 +125,7 @@ private List calculateDependencies(Project project, String moduleId) Map requestedByMap = artifactoryDependencyResolutionListener.getModulesHierarchyMap().get(moduleId); Set configurationSet = project.getConfigurations(); - List dependencies = newArrayList(); + List dependencies = new ArrayList<>(); for (Configuration configuration : configurationSet) { if (configuration.getState() != Configuration.State.RESOLVED) { log.info("Artifacts for configuration '{}' were not all resolved, skipping", configuration.getName()); @@ -164,10 +160,12 @@ private Dependency extractDependencyFromResolvedArtifact(Configuration configura return null; } // New dependency to extract + Set scopes = new HashSet<>(); + scopes.add(configuration.getName()); DependencyBuilder dependencyBuilder = new DependencyBuilder() .type(StringUtils.substringAfterLast(file.getName(), ".")) .id(depId) - .scopes(Sets.newHashSet(configuration.getName())); + .scopes(scopes); if (requestedByMap != null) { dependencyBuilder.requestedBy(requestedByMap.get(depId)); } diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java index 89d2e9a..0db9e56 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/task/ArtifactoryTask.java @@ -1,8 +1,8 @@ package org.jfrog.gradle.plugin.artifactory.task; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.apache.commons.collections4.MultiMapUtils; +import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.gradle.api.*; import org.gradle.api.artifacts.Configuration; @@ -51,7 +51,7 @@ public class ArtifactoryTask extends DefaultTask { // Publication containers input private final Set publications = new HashSet<>(); // Properties input - private final Multimap properties = ArrayListMultimap.create(); + private final MultiValuedMap properties = MultiMapUtils.newSetValuedHashMap(); @Input public final ArtifactSpecs artifactSpecs = new ArtifactSpecs(); @@ -394,7 +394,7 @@ public Set getPublications() { } @Input - public Multimap getProperties() { + public MultiValuedMap getProperties() { return properties; } diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/ProjectUtils.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/ProjectUtils.java index 9a98aef..4f176d1 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/ProjectUtils.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/ProjectUtils.java @@ -1,7 +1,5 @@ package org.jfrog.gradle.plugin.artifactory.utils; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import org.gradle.api.Project; import org.gradle.api.artifacts.ModuleVersionIdentifier; import org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration; @@ -13,6 +11,8 @@ import java.util.ArrayList; import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; public class ProjectUtils { @@ -77,10 +77,12 @@ public static Iterable filterIncludeExcludeDetails(Project publisher.getIncludePatterns(), publisher.getExcludePatterns()); if (publisher.isFilterExcludedArtifactsFromBuild()) { - return Iterables.filter(gradleDeployDetails, new IncludeExcludePredicate(project, patterns, isInclude)); - } else { - return isInclude ? Iterables.filter(gradleDeployDetails, new ProjectPredicate(project)) : new ArrayList<>(); + return gradleDeployDetails.stream().filter(new IncludeExcludePredicate(project, patterns, isInclude)).collect(Collectors.toSet()); } + if (!isInclude) { + return new ArrayList<>(); + } + return gradleDeployDetails.stream().filter(new ProjectPredicate(project)).collect(Collectors.toSet()); } public static class ProjectPredicate implements Predicate { @@ -90,7 +92,8 @@ private ProjectPredicate(Project project) { this.project = project; } - public boolean apply(@Nullable GradleDeployDetails input) { + @Override + public boolean test(@Nullable GradleDeployDetails input) { if (input == null) { return false; } @@ -109,7 +112,8 @@ public IncludeExcludePredicate(Project project, IncludeExcludePatterns patterns, this.include = include; } - public boolean apply(@Nullable GradleDeployDetails input) { + @Override + public boolean test(@Nullable GradleDeployDetails input) { if (input == null || !Objects.equals(input.getProject(), project)) { return false; } diff --git a/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PublicationUtils.java b/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PublicationUtils.java index e69787c..522f9f3 100644 --- a/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PublicationUtils.java +++ b/src/main/java/org/jfrog/gradle/plugin/artifactory/utils/PublicationUtils.java @@ -1,6 +1,6 @@ package org.jfrog.gradle.plugin.artifactory.utils; -import com.google.common.collect.Multimap; +import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.lang3.StringUtils; import org.apache.ivy.core.IvyPatternHelper; import org.gradle.api.GradleException; @@ -201,12 +201,12 @@ private static Map getPropsToAdd(ArtifactoryTask destination, Pu .name(project.getName()).version(project.getVersion().toString()) .classifier(artifact.getClassifier()) .type(artifact.getType()).build(); - Multimap artifactSpecsProperties = destination.artifactSpecs.getProperties(spec); + MultiValuedMap artifactSpecsProperties = destination.artifactSpecs.getProperties(spec); addProps(propsToAdd, artifactSpecsProperties); return propsToAdd; } - public static void addProps(Map target, Multimap props) { + public static void addProps(Map target, MultiValuedMap props) { for (Map.Entry entry : props.entries()) { // Make sure all GString are now Java Strings String key = entry.getKey();