@@ -17,60 +17,68 @@ abstract class CodeArtifactRepositoryPlugin : Plugin<Any> {
17
17
override fun apply (scope : Any ) {
18
18
when (scope) {
19
19
is Settings -> {
20
- scope.extensions.create(extensionName , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
20
+ scope.extensions.create(EXTENSION_NAME , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
21
21
.also {
22
22
CodeArtifactRepositoryExtension .store[" " ] = it
23
23
}
24
24
}
25
+
25
26
is Project -> {
26
- scope.extensions.create(extensionName , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
27
+ scope.extensions.create(EXTENSION_NAME , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
27
28
.also {
28
29
CodeArtifactRepositoryExtension .store[" " ] = it
29
30
}
30
31
}
32
+
31
33
is Gradle -> {
32
34
scope.beforeSettings {
33
- extensions.create(extensionName, CodeArtifactRepositoryExtension ::class .java, extensions)
34
- .also {
35
- CodeArtifactRepositoryExtension .store[" " ] = it
36
- }
35
+ extensions.create(EXTENSION_NAME , CodeArtifactRepositoryExtension ::class .java, extensions).also {
36
+ CodeArtifactRepositoryExtension .store[" " ] = it
37
+ }
37
38
}
38
39
}
40
+
39
41
else -> {
40
42
throw GradleException (" Should only get applied on Settings or Project" )
41
43
}
42
44
}
43
45
}
44
46
45
47
companion object {
46
- const val extensionName = " CodeArtifactRepository"
48
+ const val EXTENSION_NAME = " CodeArtifactRepository"
47
49
}
48
50
}
49
51
50
52
inline fun Settings.codeArtifactRepository (configure : CodeArtifactRepositoryExtension .() -> Unit ) {
51
- extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .extensionName ).configure()
53
+ extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .EXTENSION_NAME ).configure()
52
54
}
53
55
54
56
inline fun Project.codeArtifactRepository (configure : CodeArtifactRepositoryExtension .() -> Unit ) {
55
- extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .extensionName ).configure()
57
+ extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .EXTENSION_NAME ).configure()
56
58
}
57
59
58
60
inline fun Gradle.codeArtifactRepository (crossinline configure : CodeArtifactRepositoryExtension .() -> Unit ) {
59
61
settingsEvaluated {
60
- extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .extensionName ).configure()
62
+ extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .EXTENSION_NAME ).configure()
61
63
}
62
64
}
63
65
64
66
/* *
65
67
* Use the default CodeArtifact config (and therefore extension)
66
68
*/
67
- fun RepositoryHandler.codeArtifact (domain : String , repository : String ): MavenArtifactRepository =
68
- codeArtifact(" " , domain, repository)
69
+ fun RepositoryHandler.codeArtifact (
70
+ domain : String ,
71
+ repository : String ,
72
+ ): MavenArtifactRepository = codeArtifact(" " , domain, repository)
69
73
70
74
/* *
71
75
* Use CodeArtifact by additional name
72
76
*/
73
- fun RepositoryHandler.codeArtifact (additionalName : String , domain : String , repository : String ) = maven {
77
+ fun RepositoryHandler.codeArtifact (
78
+ additionalName : String ,
79
+ domain : String ,
80
+ repository : String ,
81
+ ) = maven {
74
82
CodeArtifactRepositoryExtension .store[additionalName]?.let {
75
83
name = listOf (additionalName, domain, repository).joinToString(" " ) { it.capitalized() }
76
84
url = URI .create(it.repositoryEndpointResponse(domain, repository).repositoryEndpoint())
@@ -89,18 +97,25 @@ fun codeArtifactToken(domain: String): String = codeArtifactToken("", domain)
89
97
/* *
90
98
* If you need the plain endpoint uri
91
99
*/
92
- fun codeArtifactUri (domain : String , repository : String , format : String ): URI =
93
- codeArtifactUri(" " , domain, repository, format)
100
+ fun codeArtifactUri (
101
+ domain : String ,
102
+ repository : String ,
103
+ format : String ,
104
+ ): URI = codeArtifactUri(" " , domain, repository, format)
94
105
95
106
/* *
96
107
* If you need the plain token
97
108
*
98
109
* @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use
99
110
* the default extension
100
111
*/
101
- fun codeArtifactToken (additionalName : String , domain : String ): String {
102
- val settings = CodeArtifactRepositoryExtension .store[additionalName]
103
- ? : throw GradleException (" didn't find CodeArtifactRepositoryExtension with the name: $" )
112
+ fun codeArtifactToken (
113
+ additionalName : String ,
114
+ domain : String ,
115
+ ): String {
116
+ val settings =
117
+ CodeArtifactRepositoryExtension .store[additionalName]
118
+ ? : throw GradleException (" didn't find CodeArtifactRepositoryExtension with the name: $" )
104
119
return settings.authorizationTokenResponse(domain).authorizationToken()
105
120
}
106
121
@@ -110,8 +125,14 @@ fun codeArtifactToken(additionalName: String, domain: String): String {
110
125
* @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use
111
126
* the default extension
112
127
*/
113
- fun codeArtifactUri (additionalName : String , domain : String , repository : String , format : String ): URI {
114
- val settings = CodeArtifactRepositoryExtension .store[additionalName]
115
- ? : throw GradleException (" didn't find CodeArtifactRepositoryExtension with the name: $" )
128
+ fun codeArtifactUri (
129
+ additionalName : String ,
130
+ domain : String ,
131
+ repository : String ,
132
+ format : String ,
133
+ ): URI {
134
+ val settings =
135
+ CodeArtifactRepositoryExtension .store[additionalName]
136
+ ? : throw GradleException (" didn't find CodeArtifactRepositoryExtension with the name: $" )
116
137
return settings.repositoryEndpointResponse(domain, repository, format).repositoryEndpoint().let { URI .create(it) }
117
138
}
0 commit comments