16
16
17
17
package org .jfrog .build .extractor .gradle ;
18
18
19
- import com .google .common .collect .*;
19
+ import com .google .common .collect .ArrayListMultimap ;
20
+ import com .google .common .collect .Maps ;
21
+ import com .google .common .collect .Multimap ;
22
+ import com .google .common .collect .Sets ;
20
23
import groovy .lang .Closure ;
21
24
import org .apache .commons .lang .StringUtils ;
22
25
import org .apache .ivy .core .IvyPatternHelper ;
23
26
import org .apache .tools .ant .util .FileUtils ;
24
27
import org .gradle .api .DefaultTask ;
25
- import org .gradle .api .GradleException ;
26
28
import org .gradle .api .Project ;
27
29
import org .gradle .api .Task ;
28
30
import org .gradle .api .artifacts .Configuration ;
@@ -76,15 +78,11 @@ public class BuildInfoRecorderTask extends DefaultTask {
76
78
@ Input
77
79
private final Multimap <String , CharSequence > properties = ArrayListMultimap .create ();
78
80
81
+ private final Map <String , Boolean > flags = Maps .newHashMap ();
82
+
79
83
private boolean lastInGraph = false ;
80
84
81
85
private Map <String , String > propsToAdd ;
82
- private static final ImmutableMap <String , String > PROP_TRANSLATE = ImmutableMap .of (
83
- PUBLISH_IVY , ClientConfigurationFields .IVY ,
84
- PUBLISH_POM , ClientConfigurationFields .MAVEN ,
85
- PUBLISH_ARTIFACTS , ClientConfigurationFields .PUBLISH_ARTIFACTS ,
86
- PUBLISH_BUILD_INFO , ClientConfigurationFields .PUBLISH_BUILD_INFO
87
- );
88
86
89
87
@ Input
90
88
@ Optional
@@ -93,7 +91,7 @@ public Boolean getPublishBuildInfo() {
93
91
}
94
92
95
93
public void setPublishBuildInfo (Boolean publishBuildInfo ) {
96
- validateFlag (PUBLISH_BUILD_INFO , publishBuildInfo );
94
+ setFlag (PUBLISH_BUILD_INFO , publishBuildInfo );
97
95
}
98
96
99
97
@ Input
@@ -103,7 +101,7 @@ public Boolean getPublishArtifacts() {
103
101
}
104
102
105
103
public void setPublishArtifacts (Boolean publishArtifacts ) {
106
- validateFlag (PUBLISH_ARTIFACTS , publishArtifacts );
104
+ setFlag (PUBLISH_ARTIFACTS , publishArtifacts );
107
105
}
108
106
109
107
@ Input
@@ -113,7 +111,7 @@ public Boolean getPublishIvy() {
113
111
}
114
112
115
113
public void setPublishIvy (Boolean publishIvy ) {
116
- validateFlag (PUBLISH_IVY , publishIvy );
114
+ setFlag (PUBLISH_IVY , publishIvy );
117
115
}
118
116
119
117
@ Input
@@ -123,26 +121,15 @@ public Boolean getPublishPom() {
123
121
}
124
122
125
123
public void setPublishPom (Boolean publishPom ) {
126
- validateFlag (PUBLISH_POM , publishPom );
124
+ setFlag (PUBLISH_POM , publishPom );
127
125
}
128
126
129
127
private Boolean getFlag (String flagName ) {
130
- String publisherPropKey = PROP_TRANSLATE .get (flagName );
131
- ArtifactoryPluginConvention convention = GradlePluginUtils .getArtifactoryConvention (getProject ());
132
- ArtifactoryClientConfiguration .PublisherHandler publisherHandler = convention .getConfiguration ().publisher ;
133
- return publisherHandler .getBooleanValue (publisherPropKey );
128
+ return flags .get (flagName );
134
129
}
135
130
136
- private void validateFlag (String flagName , Boolean newValue ) {
137
- String publisherPropKey = PROP_TRANSLATE .get (flagName );
138
- ArtifactoryPluginConvention convention = GradlePluginUtils .getArtifactoryConvention (getProject ());
139
- ArtifactoryClientConfiguration .PublisherHandler publisherHandler = convention .getConfiguration ().publisher ;
140
- Boolean currentValue = publisherHandler .getBooleanValue (publisherPropKey );
141
- if (newValue != null && currentValue != null && !currentValue .equals (newValue )) {
142
- throw new GradleException ("Support for build info recording settings on per project basis, not supported yet!\n " +
143
- "Task " + getPath () + " validation for " + flagName + " flag failed." );
144
- }
145
- publisherHandler .setBooleanValue (publisherPropKey , newValue );
131
+ private void setFlag (String flagName , Boolean newValue ) {
132
+ flags .put (flagName , newValue );
146
133
}
147
134
148
135
public void setLastInGraph (boolean lastInGraph ) {
@@ -289,7 +276,7 @@ public void projectsEvaluated() {
289
276
290
277
// Set ivy descriptor parameters
291
278
TaskContainer tasks = project .getTasks ();
292
- if (acc .publisher .isIvy ()) {
279
+ if (this . isPublishIvy ( acc .publisher .isIvy () )) {
293
280
Configuration archiveConf = project .getConfigurations ().findByName (Dependency .ARCHIVES_CONFIGURATION );
294
281
if (ivyDescriptor == null && archiveConf != null ) {
295
282
// Flag to publish the Ivy XML file, but no ivy descriptor file inputted, activate default upload${configuration}.
@@ -309,7 +296,7 @@ public void projectsEvaluated() {
309
296
}
310
297
311
298
// Set maven pom parameters
312
- if (acc . publisher . isMaven ( )) {
299
+ if (isPublishMaven ( acc )) {
313
300
if (mavenDescriptor == null ) {
314
301
// Flag to publish the Maven POM, but no pom file inputted, activate default Maven install.
315
302
// if the project doesn't have the maven install task, throw an exception
@@ -329,6 +316,18 @@ public void projectsEvaluated() {
329
316
}
330
317
}
331
318
319
+ private Boolean isPublishMaven (ArtifactoryClientConfiguration acc ) {
320
+ if (getPublishPom () == null )
321
+ return acc .publisher .isMaven ();
322
+ return getPublishPom ();
323
+ }
324
+
325
+ private boolean isPublishIvy (Boolean defaultValue ) {
326
+ if (getPublishIvy () == null )
327
+ return defaultValue ;
328
+ return getPublishIvy ();
329
+ }
330
+
332
331
private ArtifactoryClientConfiguration getArtifactoryClientConfiguration (Project project ) {
333
332
return GradlePluginUtils .getArtifactoryConvention (project ).getConfiguration ();
334
333
}
0 commit comments