Skip to content

Commit

Permalink
Bugfix - Multi values property set
Browse files Browse the repository at this point in the history
  • Loading branch information
talarian1 committed Dec 7, 2021
1 parent a95a381 commit 47e5665
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +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);
checkBuildInfoProps(artifactoryManager, buildResult);
checkArtifactsProps(artifactoryManager);
// Cleanup
Pair<String, String> buildDetails = getBuildDetails(buildResult);
cleanTestBuilds(buildDetails.getLeft(), buildDetails.getRight(), null);
Expand All @@ -87,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<String, String> buildDetails = getBuildDetails(buildResult);
cleanTestBuilds(buildDetails.getLeft(), buildDetails.getRight(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jfrog.build.api.Build;
import org.jfrog.build.api.Dependency;
import org.jfrog.build.api.Module;
import org.jfrog.build.api.dependency.PropertySearchResult;
import org.jfrog.build.api.util.CommonUtils;
import org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager;

Expand Down Expand Up @@ -245,23 +246,21 @@ private static void checkBuildInfoModules(Build buildInfo, int expectedModules,
}

/**
* Check expected build info properties is found on each published artifacts.
* Check expected properties is found on each published artifacts.
*
* @param artifactoryManager - ArtifactoryManager client
* @param buildResult - The build results
*/
static void checkBuildInfoProps(ArtifactoryManager artifactoryManager, BuildResult buildResult) throws IOException {
Build buildInfo = getBuildInfo(artifactoryManager, buildResult);
for (Module module : buildInfo.getModules()) {
for (Artifact artifact : module.getArtifacts()) {
Properties properties = artifact.getProperties();
assertNotNull(properties);
assertEquals(properties.getProperty("qa.level"), "basic");
assertEquals(properties.getProperty("q.os"), "win32");
assertEquals(properties.getProperty("q.os"), "deb");
assertEquals(properties.getProperty("q.os"), "osx");
}
}
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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ configure<org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention> {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,20 @@ public static String encodePath(String unescaped) {
return escaped;
}


public static String buildMatrixParamsString(ArrayListMultimap<String, String> 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);
}
}
}
}
Expand Down

0 comments on commit 47e5665

Please sign in to comment.