diff --git a/convention-plugin/src/main/kotlin/org/metaborg/convention/MavenPublishConventionExtension.kt b/convention-plugin/src/main/kotlin/org/metaborg/convention/MavenPublishConventionExtension.kt new file mode 100644 index 0000000..b62d35e --- /dev/null +++ b/convention-plugin/src/main/kotlin/org/metaborg/convention/MavenPublishConventionExtension.kt @@ -0,0 +1,113 @@ +package org.metaborg.convention + +import org.gradle.api.Action +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Property +import org.gradle.kotlin.dsl.newInstance +import javax.inject.Inject + +/** + * Configuration for the Maven Publish convention. + * + * Create an instance like this: + * + * ```kotlin + * extensions.create("mavenPublishConvention") + * extension.setConvention() + * ``` + */ +open class MavenPublishConventionExtension @Inject constructor( + /** The Gradle object factory. */ + objects: ObjectFactory, +) { + /** The owner of the repository. */ + val repoOwner: Property = objects.property(String::class.java) + /** The name of the repository. */ + val repoName: Property = objects.property(String::class.java) + + /** Whether to publish to GitHub packages. */ + val publishToGitHubPackages: Property = objects.property(Boolean::class.java) + /** Whether to publish to Metaborg Artifacts. */ + val publishToMetaborgArtifacts: Property = objects.property(Boolean::class.java) + + /** The publication metadata (dot notation). */ + val metadata: MetadataHandler = objects.newInstance() + + /** The publication metadata (DSL notation). */ + fun metadata(action: Action) { + action.execute(metadata) + } + + /** + * Sets the convention (default values) for the configuration extension. + */ + fun setConvention() { + publishToGitHubPackages.convention(metadata.scm.map { it == SCM.GitHub }) + publishToMetaborgArtifacts.convention(true) + metadata.setConvention() + } + + /** Configuration of publication metadata. */ + interface MetadataHandler { + /** The year the project was started. */ + val inceptionYear: Property + /** The developers of the project. */ + val developers: ListProperty + /** The source control management system. */ + val scm: Property + /** The open source license that the project is published under. */ + val license: Property + /** The HTTP SCM URL format. */ + val httpUrlFormat: Property + /** The SCM URL format. */ + val scmUrlFormat: Property + + /** + * Sets the convention (default values) for the configuration extension. + */ + fun setConvention() { + scm.convention(SCM.GitHub) + license.convention(OpenSourceLicense.Apache2) + httpUrlFormat.convention(scm.map { it.httpUrlFormat }) + scmUrlFormat.convention(scm.map { it.scmUrlFormat }) + } + } +} + + +/** Specifies a developer. */ +data class Developer( + /** The developer's ID or username. */ + val id: String, + /** The developer's full name. */ + val name: String, + /** The developer's email address. */ + val email: String, +) + + +/** Specifies a source control management system. */ +enum class SCM( + /** The HTTP URL for the SCM. */ + val httpUrlFormat: String, + /** The SCM URL for the SCM. */ + val scmUrlFormat: String, +) { + /** GitHub */ + GitHub("https://github.com/%s/%s", "scm:git@github.com:%s/%s.git"), +} + + +/** Specifies the open source license. */ +enum class OpenSourceLicense( + /** The unique identifier of the license. */ + val id: String, + /** The license URL. */ + val url: String, +) { + // From: https://spdx.org/licenses/ + + /** Apache 2 */ + Apache2("Apache-2.0", "https://www.apache.org/licenses/LICENSE-2.0.txt"), +} \ No newline at end of file diff --git a/convention-plugin/src/main/kotlin/org/metaborg/gradle/Developer.kt b/convention-plugin/src/main/kotlin/org/metaborg/gradle/Developer.kt deleted file mode 100644 index 962a2aa..0000000 --- a/convention-plugin/src/main/kotlin/org/metaborg/gradle/Developer.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.metaborg.gradle - -/** Specifies a developer. */ -data class Developer( - /** The developer's ID or username. */ - val id: String, - /** The developer's full name. */ - val name: String, - /** The developer's email address. */ - val email: String, -) diff --git a/convention-plugin/src/main/kotlin/org/metaborg/gradle/MavenPublishConventionExtension.kt b/convention-plugin/src/main/kotlin/org/metaborg/gradle/MavenPublishConventionExtension.kt deleted file mode 100644 index 385fcb0..0000000 --- a/convention-plugin/src/main/kotlin/org/metaborg/gradle/MavenPublishConventionExtension.kt +++ /dev/null @@ -1,45 +0,0 @@ -package org.metaborg.gradle - -import org.gradle.api.provider.ListProperty -import org.gradle.api.provider.Property -import org.gradle.jvm.toolchain.JavaLanguageVersion - -/** Configuration for the Maven Publish convention. */ -interface MavenPublishConventionExtension { - /** The owner of the repository. */ - val repoOwner: Property - /** The name of the repository. */ - val repoName: Property - /** The year the project was started. */ - val inceptionYear: Property - /** The developers of the project. */ - val developers: ListProperty - /** The source control management system. */ - val scm: Property - /** The open source license that the project is published under. */ - val license: Property - /** Whether to publish to GitHub packages. */ - val publishToGitHubPackages: Property - /** Whether to publish to Metaborg Artifacts. */ - val publishToMetaborgArtifacts: Property - /** Whether to sign the artifacts. */ - val sign: Property - /** The HTTP SCM URL format. */ - val httpUrlFormat: Property - /** The SCM URL format. */ - val scmUrlFormat: Property - - - /** - * Sets the convention (default values) for the configuration extension. - */ - fun setConvention() { - scm.convention(SCM.GitHub) - license.convention(OpenSourceLicense.Apache2) - publishToGitHubPackages.convention(scm.map { it == SCM.GitHub }) - publishToMetaborgArtifacts.convention(true) - sign.convention(false) // Not yet supported - httpUrlFormat.convention(scm.map { it.httpUrlFormat }) - scmUrlFormat.convention(scm.map { it.scmUrlFormat }) - } -} \ No newline at end of file diff --git a/convention-plugin/src/main/kotlin/org/metaborg/gradle/OpenSourceLicense.kt b/convention-plugin/src/main/kotlin/org/metaborg/gradle/OpenSourceLicense.kt deleted file mode 100644 index e003f16..0000000 --- a/convention-plugin/src/main/kotlin/org/metaborg/gradle/OpenSourceLicense.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.metaborg.gradle - -/** Specifies the open source license. */ -enum class OpenSourceLicense( - /** The unique identifier of the license. */ - val id: String, - /** The license URL. */ - val url: String, -) { - // From: https://spdx.org/licenses/ - - /** Apache 2 */ - Apache2("Apache-2.0", "https://www.apache.org/licenses/LICENSE-2.0.txt"), -} \ No newline at end of file diff --git a/convention-plugin/src/main/kotlin/org/metaborg/gradle/SCM.kt b/convention-plugin/src/main/kotlin/org/metaborg/gradle/SCM.kt deleted file mode 100644 index 35c9435..0000000 --- a/convention-plugin/src/main/kotlin/org/metaborg/gradle/SCM.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.metaborg.gradle - -/** Specifies a source control management system. */ -enum class SCM( - /** The HTTP URL for the SCM. */ - val httpUrlFormat: String, - /** The SCM URL for the SCM. */ - val scmUrlFormat: String, -) { - /** GitHub */ - GitHub("https://github.com/%s/%s", "scm:git@github.com:%s/%s.git"), -} \ No newline at end of file