28
28
*/
29
29
package com.google.protobuf.gradle
30
30
31
- import groovy.transform.CompileDynamic
31
+ import com.google.gradle.osdetector.OsDetector
32
+ import groovy.transform.CompileStatic
32
33
import org.gradle.api.NamedDomainObjectContainer
33
34
import org.gradle.api.Project
34
35
import org.gradle.api.artifacts.Configuration
@@ -38,12 +39,12 @@ import org.gradle.api.file.FileCollection
38
39
/**
39
40
* Holds locations of all external executables, i.e., protoc and plugins.
40
41
*/
41
- @CompileDynamic
42
+ @CompileStatic
42
43
class ToolsLocator {
43
44
44
45
private final Project project
45
- private final ExecutableLocator protoc
46
- private final NamedDomainObjectContainer<ExecutableLocator > plugins
46
+ final ExecutableLocator protoc
47
+ final NamedDomainObjectContainer<ExecutableLocator > plugins
47
48
48
49
static List<String > artifactParts (String artifactCoordinate ) {
49
50
String artifact
@@ -53,11 +54,14 @@ class ToolsLocator {
53
54
String version
54
55
String classifier
55
56
56
- (artifact, extension) = artifactCoordinate. tokenize(' @' )
57
+ List<String > artifactCoordinateTokenized = artifactCoordinate. tokenize(' @' )
58
+ (artifact, extension) = [artifactCoordinateTokenized[0 ], artifactCoordinateTokenized[1 ]]
57
59
if (extension == null && artifactCoordinate. endsWith(' @' )) {
58
60
extension = ' '
59
61
}
60
- (group, name, version, classifier) = artifact. tokenize(' :' )
62
+ List<String > artifactTokenized = artifact. tokenize(' :' )
63
+ (group, name, version, classifier) =
64
+ [artifactTokenized[0 ], artifactTokenized[1 ], artifactTokenized[2 ], artifactTokenized[3 ]]
61
65
62
66
return [group, name, version, classifier, extension]
63
67
}
@@ -92,19 +96,20 @@ class ToolsLocator {
92
96
93
97
void registerDependencyWithTasks (ExecutableLocator locator , Collection<GenerateProtoTask > protoTasks ) {
94
98
// create a project configuration dependency for the artifact
95
- Configuration config = project. configurations. create(" protobufToolsLocator_${ locator.name} " ) {
96
- visible = false
97
- transitive = false
98
- extendsFrom = []
99
+ Configuration config = project. configurations. create(" protobufToolsLocator_${ locator.name} " ) { Configuration conf ->
100
+ conf. visible = false
101
+ conf. transitive = false
99
102
}
100
103
String groupId, artifact, version, classifier, extension
101
- (groupId, artifact, version, classifier, extension) = artifactParts(locator. artifact)
104
+ OsDetector osdetector = project. extensions. getByName(" osdetector" ) as OsDetector
105
+ List<String > parts = artifactParts(locator. artifact)
106
+ (groupId, artifact, version, classifier, extension) = [parts[0 ], parts[1 ], parts[2 ], parts[3 ], parts[4 ]]
102
107
Map<String , String > notation = [
103
- group :groupId,
104
- name :artifact,
105
- version :version,
106
- classifier :classifier ?: project . osdetector. classifier,
107
- ext :extension ?: ' exe' ,
108
+ group :groupId,
109
+ name :artifact,
110
+ version :version,
111
+ classifier :classifier ?: osdetector. classifier,
112
+ ext :extension ?: ' exe' ,
108
113
]
109
114
Dependency dep = project. dependencies. add(config. name, notation)
110
115
FileCollection artifactFiles = config. fileCollection(dep)
0 commit comments