diff --git a/build.gradle.kts b/build.gradle.kts index 4f70411..c3c2b0d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -50,26 +50,29 @@ gradlePlugin { create("build-recipe-library-base") { id = "org.openrewrite.build.recipe-library-base" displayName = "Rewrite recipe library base" - description = "Builds recipe libraries with the minimum of opinions or conventions about any other aspect of the build. " + - "Does not configure artifact repositories or publishing. " + - "Use org.openrewrite.build.recipe-library if you want to build a recipe library as OSS." + description = + "Builds recipe libraries with the minimum of opinions or conventions about any other aspect of the build. " + + "Does not configure artifact repositories or publishing. " + + "Use org.openrewrite.build.recipe-library if you want to build a recipe library as OSS." implementationClass = "org.openrewrite.gradle.RewriteRecipeLibraryBasePlugin" tags = listOf("rewrite", "refactoring") } create("build-recipe-repositories") { id = "org.openrewrite.build.recipe-repositories" displayName = "Rewrite recipe repositories" - description = "Configures the repositories that OpenRewrite modules in open source draw dependencies from, " + - "such as Maven Central and Nexus Snapshots. " + description = + "Configures the repositories that OpenRewrite modules in open source draw dependencies from, " + + "such as Maven Central and Nexus Snapshots. " implementationClass = "org.openrewrite.gradle.RewriteDependencyRepositoriesPlugin" tags = listOf("rewrite", "refactoring", "oss") } create("build-recipe-library") { id = "org.openrewrite.build.recipe-library" displayName = "Rewrite recipe library" - description = "Builds recipe libraries with all the conventions and configuration used in OpenRewrite repositories. " + - "Includes conventions around which repositories to draw from and publish to. " + - "Use org.openrewrite.build.recipe-library-base if you want to build a private recipe library." + description = + "Builds recipe libraries with all the conventions and configuration used in OpenRewrite repositories. " + + "Includes conventions around which repositories to draw from and publish to. " + + "Use org.openrewrite.build.recipe-library-base if you want to build a private recipe library." implementationClass = "org.openrewrite.gradle.RewriteRecipeLibraryPlugin" tags = listOf("rewrite", "refactoring", "oss") } @@ -123,7 +126,6 @@ gradlePlugin { implementationClass = "org.openrewrite.gradle.RewriteRecipeAuthorAttributionPlugin" tags = listOf("rewrite", "refactoring") } - create("build-recipe-examples") { id = "org.openrewrite.build.recipe-examples" displayName = "Rewrite recipe examples" @@ -131,6 +133,20 @@ gradlePlugin { implementationClass = "org.openrewrite.gradle.RewriteRecipeExamplesPlugin" tags = listOf("rewrite", "refactoring") } + create("moderne-source-available-license") { + id = "org.openrewrite.build.moderne-source-available-license" + displayName = "Moderne Source Available License" + description = "Applies the MSAL to the project" + implementationClass = "org.openrewrite.gradle.ModerneSourceAvailableLicensePlugin" + tags = listOf("rewrite", "refactoring") + } + create("moderne-proprietary-license") { + id = "org.openrewrite.build.moderne-proprietary-license" + displayName = "Moderne Proprietary License" + description = "Applies the Moderne Proprietary License to the project" + implementationClass = "org.openrewrite.gradle.ModerneProprietaryLicensePlugin" + tags = listOf("rewrite", "refactoring") + } } } diff --git a/src/main/java/org/openrewrite/gradle/ModerneProprietaryLicensePlugin.java b/src/main/java/org/openrewrite/gradle/ModerneProprietaryLicensePlugin.java new file mode 100644 index 0000000..be8297a --- /dev/null +++ b/src/main/java/org/openrewrite/gradle/ModerneProprietaryLicensePlugin.java @@ -0,0 +1,53 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.gradle; + +import nebula.plugin.publishing.maven.MavenBasePublishPlugin; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.publish.PublishingExtension; +import org.gradle.api.publish.maven.MavenPublication; +import org.gradle.jvm.tasks.Jar; + +public class ModerneProprietaryLicensePlugin implements Plugin { + + @Override + public void apply(Project project) { + // Empty JARs are OK: https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources + Jar sourceJar = project.getTasks().create("emptySourceJar", Jar.class, task -> { + task.from("README.md"); + task.getArchiveClassifier().set("sources"); + }); + + project.getPlugins().apply(MavenBasePublishPlugin.class); + PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); + publishing.publications(publications -> publications.withType(MavenPublication.class, + p -> configureLicense(p, sourceJar))); + } + + private void configureLicense(MavenPublication publication, Jar sourceJar) { + publication.artifact(sourceJar); + + publication.pom(pom -> { + pom.licenses(licenses -> { + licenses.license(license -> { + license.getName().set("Moderne Proprietary License"); + license.getUrl().set("https://docs.moderne.io/licensing/overview"); + }); + }); + }); + } +} diff --git a/src/main/java/org/openrewrite/gradle/ModerneSourceAvailableLicensePlugin.java b/src/main/java/org/openrewrite/gradle/ModerneSourceAvailableLicensePlugin.java new file mode 100644 index 0000000..e77085d --- /dev/null +++ b/src/main/java/org/openrewrite/gradle/ModerneSourceAvailableLicensePlugin.java @@ -0,0 +1,43 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.gradle; + +import nebula.plugin.publishing.maven.MavenBasePublishPlugin; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.publish.PublishingExtension; +import org.gradle.api.publish.maven.MavenPublication; + +public class ModerneSourceAvailableLicensePlugin implements Plugin { + + @Override + public void apply(Project project) { + project.getPlugins().apply(MavenBasePublishPlugin.class); + PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class); + publishing.publications(publications -> publications.withType(MavenPublication.class, this::configureLicense)); + } + + private void configureLicense(MavenPublication publication) { + publication.pom(pom -> { + pom.licenses(licenses -> { + licenses.license(license -> { + license.getName().set("Moderne Source Available License"); + license.getUrl().set("https://docs.moderne.io/licensing/moderne-source-available-license"); + }); + }); + }); + } +}