Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - Multi Values Properties Set #583

Merged
merged 4 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> buildDetails = getBuildDetails(buildResult);
cleanTestBuilds(buildDetails.getLeft(), buildDetails.getRight(), null);
Expand All @@ -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<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 @@ -8,40 +8,25 @@
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;
import java.io.IOException;
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
Expand Down Expand Up @@ -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.
*
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 @@ -71,14 +71,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth to add a reference to this bug in Artifactory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I couldn't find a public open issue for that. I will contact our suitable team to make sure it will be fixed soon.

// 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