diff --git a/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/GradlePluginTest.java b/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/GradlePluginTest.java index fc61ec4c4..8a45ec06e 100644 --- a/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/GradlePluginTest.java +++ b/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/GradlePluginTest.java @@ -73,6 +73,7 @@ public void publicationsTest(String gradleVersion) throws IOException { BuildResult buildResult = runGradle(gradleVersion, envVars, false); // Check results checkBuildResults(artifactoryManager, buildResult, VersionNumber.parse(gradleVersion).getMajor() >= 6, localRepo1); + checkArtifactsProps(artifactoryManager); // Cleanup Pair buildDetails = getBuildDetails(buildResult); cleanTestBuilds(buildDetails.getLeft(), buildDetails.getRight(), null); @@ -86,6 +87,7 @@ public void publicationsTestKotlinDsl(String gradleVersion) throws IOException { BuildResult buildResult = runGradle(gradleVersion, envVars, false); // Check results checkBuildResults(artifactoryManager, buildResult, VersionNumber.parse(gradleVersion).getMajor() >= 6, localRepo1); + checkArtifactsProps(artifactoryManager); // Cleanup Pair buildDetails = getBuildDetails(buildResult); cleanTestBuilds(buildDetails.getLeft(), buildDetails.getRight(), null); diff --git a/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/Utils.java b/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/Utils.java index 3a02668aa..603d28e74 100644 --- a/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/Utils.java +++ b/build-info-extractor-gradle/src/test/java/org/jfrog/gradle/plugin/artifactory/Utils.java @@ -8,10 +8,11 @@ import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.BuildTask; import org.gradle.testkit.runner.GradleRunner; +import org.jfrog.build.api.dependency.PropertySearchResult; +import org.jfrog.build.api.util.CommonUtils; +import org.jfrog.build.extractor.ci.BuildInfo; import org.jfrog.build.extractor.ci.Dependency; import org.jfrog.build.extractor.ci.Module; -import org.jfrog.build.extractor.ci.BuildInfo; -import org.jfrog.build.api.util.CommonUtils; import org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager; import java.io.File; @@ -19,29 +20,13 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; import static org.jfrog.build.extractor.BuildInfoExtractorUtils.jsonStringToBuildInfo; import static org.jfrog.build.extractor.clientConfiguration.client.artifactory.services.PublishBuildInfo.BUILD_BROWSE_URL; -import static org.jfrog.gradle.plugin.artifactory.Consts.ARTIFACTS_GROUP_ID; -import static org.jfrog.gradle.plugin.artifactory.Consts.BUILD_INFO_PROPERTIES_SOURCE_DEPLOYER; -import static org.jfrog.gradle.plugin.artifactory.Consts.BUILD_INFO_PROPERTIES_SOURCE_RESOLVER; -import static org.jfrog.gradle.plugin.artifactory.Consts.BUILD_INFO_PROPERTIES_TARGET; -import static org.jfrog.gradle.plugin.artifactory.Consts.EXPECTED_ARTIFACTS; -import static org.jfrog.gradle.plugin.artifactory.Consts.EXPECTED_MODULE_ARTIFACTS; -import static org.jfrog.gradle.plugin.artifactory.Consts.INIT_SCRIPT; -import static org.jfrog.gradle.plugin.artifactory.Consts.LIBS_DIR; -import static org.jfrog.gradle.plugin.artifactory.Consts.TEST_DIR; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.jfrog.gradle.plugin.artifactory.Consts.*; +import static org.testng.Assert.*; /** * @author yahavi @@ -259,6 +244,24 @@ private static void checkBuildInfoModules(BuildInfo buildInfo, int expectedModul } } + /** + * Check that the expected properties are found on each published artifact. + * + * @param artifactoryManager - ArtifactoryManager client + */ + static void checkArtifactsProps(ArtifactoryManager artifactoryManager) throws IOException { + // Test single value prop + PropertySearchResult artifacts = artifactoryManager.searchArtifactsByProperties("gradle.test.single.value.key=basic"); + assertTrue(artifacts.getResults().size() >= 12); + // Test multi value props + artifacts = artifactoryManager.searchArtifactsByProperties("gradle.test.multi.values.key=val1"); + assertTrue(artifacts.getResults().size() >= 12); + artifacts = artifactoryManager.searchArtifactsByProperties("gradle.test.multi.values.key=val2"); + assertTrue(artifacts.getResults().size() >= 12); + artifacts = artifactoryManager.searchArtifactsByProperties("gradle.test.multi.values.key=val3"); + assertTrue(artifacts.getResults().size() >= 12); + } + /** * Assert build success for task. * diff --git a/build-info-extractor-gradle/src/test/resources/integration/gradle-example-publish/build.gradle b/build-info-extractor-gradle/src/test/resources/integration/gradle-example-publish/build.gradle index 12d12c65c..da9bc5b29 100644 --- a/build-info-extractor-gradle/src/test/resources/integration/gradle-example-publish/build.gradle +++ b/build-info-extractor-gradle/src/test/resources/integration/gradle-example-publish/build.gradle @@ -69,6 +69,9 @@ artifactory { publications('mavenJava', 'ivyJava') publishArtifacts = true // Properties to be attached to the published artifacts. + properties.put("gradle.test.multi.values.key", "val1, val2, val3") + properties.put("gradle.test.single.value.key", "basic") + properties = ["gradle.test.single.value.key": 'basic', "gradle.test.multi.values.key": 'val1, val2, val3'] publishPom = true // Publish generated POM files to Artifactory (true by default) publishIvy = true // Publish generated Ivy descriptor files to Artifactory (true by default) } diff --git a/build-info-extractor-gradle/src/test/resources/integration/gradle-kts-example-publish/build.gradle.kts b/build-info-extractor-gradle/src/test/resources/integration/gradle-kts-example-publish/build.gradle.kts index e977e62b5..f6c683cba 100644 --- a/build-info-extractor-gradle/src/test/resources/integration/gradle-kts-example-publish/build.gradle.kts +++ b/build-info-extractor-gradle/src/test/resources/integration/gradle-kts-example-publish/build.gradle.kts @@ -81,6 +81,8 @@ configure { publications("mavenJava", "ivyJava") setPublishArtifacts(true) // Properties to be attached to the published artifacts. + properties.put("gradle.test.multi.values.key", "val1, val2, val3") + properties.put("gradle.test.single.value.key", "basic") setPublishPom(true) // Publish generated POM files to Artifactory (true by default) setPublishIvy(true) // Publish generated Ivy descriptor files to Artifactory (true by default) } diff --git a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java index 5fe14c584..c71c98032 100644 --- a/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java +++ b/build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/DeploymentUrlUtils.java @@ -71,14 +71,20 @@ public static String encodePath(String unescaped) { return escaped; } + public static String buildMatrixParamsString(ArrayListMultimap matrixParams, boolean encodeProperties) throws UnsupportedEncodingException { StringBuilder matrix = new StringBuilder(); if (matrixParams != null && !matrixParams.isEmpty()) { for (String propertyKey : matrixParams.keySet()) { - for (String propertyValue : matrixParams.get(propertyKey)) { - matrix.append(";").append(encodeProperties ? encode(propertyKey) : propertyKey) - .append("=").append(encodeProperties ? encode(propertyValue) : propertyValue); + for (String multiPropertyValue : matrixParams.get(propertyKey)) { + // Due to known bug in Artifactory, in order to support multi values properties + // we add a statement to each value separately. + for (String propertyValue:multiPropertyValue.split(",")) { + propertyValue = propertyValue.trim(); + matrix.append(";").append(encodeProperties ? encode(propertyKey) : propertyKey) + .append("=").append(encodeProperties ? encode(propertyValue) : propertyValue); + } } } }