|
9 | 9 | import groovy.transform.stc.ClosureParams; |
10 | 10 | import groovy.transform.stc.FirstParam; |
11 | 11 | import kotlin.jvm.functions.Function0; |
| 12 | +import org.codehaus.groovy.runtime.DefaultGroovyMethods; |
| 13 | +import org.codehaus.groovy.runtime.InvokerHelper; |
12 | 14 | import org.gradle.TaskExecutionRequest; |
13 | 15 | import org.gradle.api.Action; |
14 | 16 | import org.gradle.api.DomainObjectCollection; |
@@ -240,6 +242,38 @@ public List<String> getArgs() { |
240 | 242 | } |
241 | 243 | //endregion |
242 | 244 |
|
| 245 | + //region Dependency Information |
| 246 | + |
| 247 | + public static String dependencyToArtifactString(Dependency dependency) { |
| 248 | + var builder = new StringBuilder(); |
| 249 | + |
| 250 | + builder.append(dependency.getGroup() != null ? dependency.getGroup() + ':' : ""); |
| 251 | + builder.append(dependency.getName()); |
| 252 | + builder.append(dependency.getVersion() != null ? ':' + dependency.getVersion() : ""); |
| 253 | + var classifier = getProperty(dependency, "classifier"); |
| 254 | + builder.append(classifier != null ? ':' + classifier : ""); |
| 255 | + var extension = getProperty(dependency, "extension", "artifactType"); |
| 256 | + builder.append(extension != null ? '@' + extension : ""); |
| 257 | + |
| 258 | + return builder.toString(); |
| 259 | + } |
| 260 | + |
| 261 | + private static @Nullable String getProperty(Object object, String... property) { |
| 262 | + for (var name : property) { |
| 263 | + var p = DefaultGroovyMethods.hasProperty(object, name); |
| 264 | + if (p == null) continue; |
| 265 | + |
| 266 | + var o = p.getProperty(object); |
| 267 | + if (o == null) continue; |
| 268 | + |
| 269 | + var s = o.toString(); |
| 270 | + return !"null".equals(s) ? s : null; |
| 271 | + } |
| 272 | + |
| 273 | + return null; |
| 274 | + } |
| 275 | + //endregion |
| 276 | + |
243 | 277 | //region Dependency Handling |
244 | 278 |
|
245 | 279 | /// Checks if the given dependency is in the given source set. |
@@ -312,7 +346,7 @@ public static Set<Dependency> collect(NamedDomainObjectSet<Configuration> config |
312 | 346 | .collect(Collectors.toSet()); |
313 | 347 | } |
314 | 348 |
|
315 | | - private static <T> void guardCheck(T t) { } |
| 349 | + static <T> void guardCheck(T t) { } |
316 | 350 |
|
317 | 351 | /// Iterates through the given source set's classpath configurations using the given action. |
318 | 352 | /// |
|
0 commit comments