@@ -17,60 +17,68 @@ abstract class CodeArtifactRepositoryPlugin : Plugin<Any> {
1717 override fun apply (scope : Any ) {
1818 when (scope) {
1919 is Settings -> {
20- scope.extensions.create(extensionName , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
20+ scope.extensions.create(EXTENSION_NAME , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
2121 .also {
2222 CodeArtifactRepositoryExtension .store[" " ] = it
2323 }
2424 }
25+
2526 is Project -> {
26- scope.extensions.create(extensionName , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
27+ scope.extensions.create(EXTENSION_NAME , CodeArtifactRepositoryExtension ::class .java, scope.extensions)
2728 .also {
2829 CodeArtifactRepositoryExtension .store[" " ] = it
2930 }
3031 }
32+
3133 is Gradle -> {
3234 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+ }
3738 }
3839 }
40+
3941 else -> {
4042 throw GradleException (" Should only get applied on Settings or Project" )
4143 }
4244 }
4345 }
4446
4547 companion object {
46- const val extensionName = " CodeArtifactRepository"
48+ const val EXTENSION_NAME = " CodeArtifactRepository"
4749 }
4850}
4951
5052inline fun Settings.codeArtifactRepository (configure : CodeArtifactRepositoryExtension .() -> Unit ) {
51- extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .extensionName ).configure()
53+ extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .EXTENSION_NAME ).configure()
5254}
5355
5456inline fun Project.codeArtifactRepository (configure : CodeArtifactRepositoryExtension .() -> Unit ) {
55- extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .extensionName ).configure()
57+ extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .EXTENSION_NAME ).configure()
5658}
5759
5860inline fun Gradle.codeArtifactRepository (crossinline configure : CodeArtifactRepositoryExtension .() -> Unit ) {
5961 settingsEvaluated {
60- extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .extensionName ).configure()
62+ extensions.getByName<CodeArtifactRepositoryExtension >(CodeArtifactRepositoryPlugin .EXTENSION_NAME ).configure()
6163 }
6264}
6365
6466/* *
6567 * Use the default CodeArtifact config (and therefore extension)
6668 */
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)
6973
7074/* *
7175 * Use CodeArtifact by additional name
7276 */
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 {
7482 CodeArtifactRepositoryExtension .store[additionalName]?.let {
7583 name = listOf (additionalName, domain, repository).joinToString(" " ) { it.capitalized() }
7684 url = URI .create(it.repositoryEndpointResponse(domain, repository).repositoryEndpoint())
@@ -89,18 +97,25 @@ fun codeArtifactToken(domain: String): String = codeArtifactToken("", domain)
8997/* *
9098 * If you need the plain endpoint uri
9199 */
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)
94105
95106/* *
96107 * If you need the plain token
97108 *
98109 * @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use
99110 * the default extension
100111 */
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: $" )
104119 return settings.authorizationTokenResponse(domain).authorizationToken()
105120}
106121
@@ -110,8 +125,14 @@ fun codeArtifactToken(additionalName: String, domain: String): String {
110125 * @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use
111126 * the default extension
112127 */
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: $" )
116137 return settings.repositoryEndpointResponse(domain, repository, format).repositoryEndpoint().let { URI .create(it) }
117138}
0 commit comments