Skip to content

Commit cd4d86a

Browse files
committed
GAP-115 - Allow attaching different deploy properties to different artifacts from a single build - wip
1 parent 391a6fa commit cd4d86a

File tree

10 files changed

+149
-126
lines changed

10 files changed

+149
-126
lines changed

Diff for: build-info-client/src/main/java/org/jfrog/build/client/ArtifactSpec.java

+10-28
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class ArtifactSpec {
3030

31-
public static final String CONFIG_ANY = "any";
31+
public static final String CONFIG_ALL = "all";
3232
public static final String WILDCARD = "*";
3333

3434
private String group;
@@ -38,7 +38,7 @@ public class ArtifactSpec {
3838
private String type;
3939
private String configuration;
4040

41-
private final Map<String, String> properties = new HashMap<String, String>();
41+
private final Map<String, CharSequence> properties = new HashMap<String, CharSequence>();
4242

4343
private static final Pattern ARTIFACT_NOTATION =
4444
Pattern.compile("^([^:]+):([^:]+):([^:]+):([^:]+?)(?:\\@([^:]+$)){0,1}$");
@@ -72,7 +72,7 @@ public static ArtifactSpec newSpec(String notation) {
7272
spec = builder.build();
7373
} else if (splits.length == 3) {
7474
//Convert 'any' config to a wild card
75-
builder.configuration(splits[0].equalsIgnoreCase(CONFIG_ANY) ? WILDCARD : splits[0]);
75+
builder.configuration(splits[0].equalsIgnoreCase(CONFIG_ALL) ? WILDCARD : splits[0]);
7676
builder.artifactNotation(splits[1]);
7777
builder.properties(splits[2]);
7878
spec = builder.build();
@@ -123,7 +123,7 @@ public String getType() {
123123
return type;
124124
}
125125

126-
public Map<String, String> getProperties() {
126+
public Map<String, CharSequence> getProperties() {
127127
return properties;
128128
}
129129

@@ -198,50 +198,32 @@ public Builder artifactNotation(String artifactNotation) {
198198
}
199199

200200
public Builder group(String group) {
201-
if (group == null) {
202-
throw new IllegalArgumentException("Group cannot be null");
203-
}
204-
spec.group = group;
201+
spec.group = group != null ? group : WILDCARD;
205202
return this;
206203
}
207204

208205
public Builder name(String name) {
209-
if (name == null) {
210-
throw new IllegalArgumentException("Artifact name cannot be null");
211-
}
212-
spec.name = name;
206+
spec.name = name != null ? name : WILDCARD;
213207
return this;
214208
}
215209

216210
public Builder version(String version) {
217-
if (version == null) {
218-
throw new IllegalArgumentException("Version cannot be null");
219-
}
220-
spec.version = version;
211+
spec.version = version != null ? version : WILDCARD;
221212
return this;
222213
}
223214

224215
public Builder classifier(String classifier) {
225-
if (classifier == null) {
226-
throw new IllegalArgumentException("Classifier cannot be null");
227-
}
228-
spec.classifier = classifier;
216+
spec.classifier = classifier != null ? classifier : WILDCARD;
229217
return this;
230218
}
231219

232220
public Builder type(String type) {
233-
if (type == null) {
234-
throw new IllegalArgumentException("Type cannot be null");
235-
}
236-
spec.type = type;
221+
spec.type = type != null ? type : WILDCARD;
237222
return this;
238223
}
239224

240225
public Builder configuration(String configuration) {
241-
if (configuration == null) {
242-
throw new IllegalArgumentException("Configuration cannot be null");
243-
}
244-
spec.configuration = configuration;
226+
spec.configuration = configuration != null ? configuration : WILDCARD;
245227
return this;
246228
}
247229

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2011 JFrog Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jfrog.build.client;
18+
19+
import com.google.common.collect.ArrayListMultimap;
20+
import com.google.common.collect.Multimap;
21+
22+
import java.util.LinkedList;
23+
import java.util.Map;
24+
25+
/**
26+
* A map of artifact specs per configuration
27+
*
28+
* @author Yoav Landman
29+
*/
30+
public class ArtifactSpecs extends LinkedList<ArtifactSpec> {
31+
32+
/**
33+
* Iterate over all the specs and if matches add the properties
34+
*
35+
* @param spec
36+
* @return
37+
*/
38+
public Multimap<String, CharSequence> getProperties(ArtifactSpec spec) {
39+
Multimap<String, CharSequence> props = ArrayListMultimap.create();
40+
for (ArtifactSpec matcherSpec : this) {
41+
if (matcherSpec.matches(spec)) {
42+
Map<String, CharSequence> matcherSpecProperties = matcherSpec.getProperties();
43+
for (Map.Entry<String, CharSequence> entry : matcherSpecProperties.entrySet()) {
44+
props.put(entry.getKey(), entry.getValue());
45+
}
46+
}
47+
}
48+
return props;
49+
}
50+
}

Diff for: build-info-client/src/main/java/org/jfrog/build/client/ConfigArtifactSpecs.java

-33
This file was deleted.

Diff for: build-info-client/src/test/java/org/jfrog/build/client/ArtifactSpecTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void stringConstruction() throws Exception {
1717
ArtifactSpec standard = ArtifactSpec.newSpec("conf grp:art:ver:cls@jar k1:v1, k2:v2 , k3: v3");
1818
ArtifactSpec noPropSpaces = ArtifactSpec.newSpec("conf grp:art:ver:cls@jar k1:v1,k2:v2,k3:v3");
1919
ArtifactSpec noConf = ArtifactSpec.newSpec("grp:art:ver:cls@jar k1:v1, k2:v2 , k3: v3");
20-
ArtifactSpec anyConf = ArtifactSpec.newSpec("any grp:art:ver:cls@jar k1:v1 , k2:v2 ,k3:v3");
20+
ArtifactSpec allConf = ArtifactSpec.newSpec("all grp:art:ver:cls@jar k1:v1 , k2:v2 ,k3:v3");
2121

2222
assertEquals(standard.getConfiguration(), "conf");
2323
assertEquals(standard.getGroup(), "grp");
@@ -44,18 +44,18 @@ public void stringConstruction() throws Exception {
4444
assertEquals(noConf.getProperties(), ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"));
4545

4646
try {
47-
ArtifactSpec noProps = ArtifactSpec.newSpec("any grp:art:ver:cls@jar");
47+
ArtifactSpec noProps = ArtifactSpec.newSpec("all grp:art:ver:cls@jar");
4848
fail("Artifact spec cannot be constructed from string without a properties notation.");
4949
} catch (IllegalArgumentException e) {
5050
//Expected
5151
}
52-
assertEquals(anyConf.getConfiguration(), "*");
53-
assertEquals(anyConf.getGroup(), "grp");
54-
assertEquals(anyConf.getName(), "art");
55-
assertEquals(anyConf.getVersion(), "ver");
56-
assertEquals(anyConf.getClassifier(), "cls");
57-
assertEquals(anyConf.getType(), "jar");
58-
assertEquals(anyConf.getProperties(), ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"));
52+
assertEquals(allConf.getConfiguration(), "*");
53+
assertEquals(allConf.getGroup(), "grp");
54+
assertEquals(allConf.getName(), "art");
55+
assertEquals(allConf.getVersion(), "ver");
56+
assertEquals(allConf.getClassifier(), "cls");
57+
assertEquals(allConf.getType(), "jar");
58+
assertEquals(allConf.getProperties(), ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"));
5959
}
6060

6161
@Test

Diff for: build-info-extractor-gradle/src/examples/multiproject/build.gradle

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ allprojects {
4040
apply plugin: 'maven'
4141
apply plugin: 'artifactory'
4242
}
43-
group = 'org.gradle'
43+
group = 'org.jfrog'
4444
version = '1.0'
4545
}
4646

@@ -58,11 +58,11 @@ subprojects {
5858
dependsOnChildren()
5959

6060
artifactory {
61-
contextUrl = 'http://repo.jfrog.org/artifactory'
62-
//contextUrl = 'http://localhost:8080/artifactory'
61+
//contextUrl = 'http://repo.jfrog.org/artifactory'
62+
contextUrl = 'http://localhost:8080/artifactory'
6363
publish {
6464
repository {
65-
repoKey = 'Framework'
65+
repoKey = 'libs-release-local'
6666
username = 'admin'
6767
password = 'password'
6868
ivy {
@@ -76,8 +76,10 @@ artifactory {
7676
//publishPom = false
7777
properties = ['qa.level': 'basic']
7878
properties {
79-
ccc 'g1.2.3:a:v:c@ext', kkk: 'sds', yyy: 'xxx'
80-
any 'g:a1:v1:*@ext', kkk: 'sds'
79+
archives 'org.jfrog:*:*:*@*', key1: 'val1', key2: 'val2'
80+
all 'org.jfrog:shared:1.?:*@*', key3: 'val3', key4: 'val4'
81+
all 'org.jfrog:*:2.?:*@*', nokey1: 'noVal1'
82+
foo 'org.jfrog:*:2.?:*@*', nokey1: 'noVal2'
8183
}
8284
}
8385
}

Diff for: build-info-extractor-gradle/src/main/groovy/org/jfrog/gradle/plugin/artifactory/dsl/PropertiesConfig.groovy

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import org.gradle.api.GradleException
2020
import org.gradle.api.Project
2121
import org.gradle.api.artifacts.UnknownConfigurationException
2222
import org.jfrog.build.client.ArtifactSpec
23-
import org.jfrog.build.client.ConfigArtifactSpecs
23+
import org.jfrog.build.client.ArtifactSpecs
2424

2525
/**
2626
* @author Yoav Landman
2727
*/
2828
class PropertiesConfig {
2929
final Project project
30-
final ConfigArtifactSpecs artifactSpecs = new ConfigArtifactSpecs()
30+
final ArtifactSpecs artifactSpecs = new ArtifactSpecs()
3131

3232
PropertiesConfig(org.gradle.api.Project project) {
3333
this.project = project
@@ -51,8 +51,6 @@ class PropertiesConfig {
5151
throw new GradleException("Invalid artifact properties spec: $name, $args.\nExpected: configName artifactSpec key:val, key:val")
5252
}
5353
def spec = ArtifactSpec.builder().artifactNotation(artifactSpecNotation).configuration(name).properties(props).build()
54-
def specs = artifactSpecs[name] ?: new ArrayList<ArtifactSpec>()
55-
specs.add(spec)
56-
artifactSpecs.put(name, specs)
54+
artifactSpecs.add(spec)
5755
}
5856
}

0 commit comments

Comments
 (0)