This is an automated email from the ASF dual-hosted git repository. jdaugherty pushed a commit to branch issue9-organization in repository https://gitbox.apache.org/repos/asf/grails-gradle-publish.git
commit 6a2dfe45fbafd131a9a4da43fe313055a2f72b4d Author: James Daugherty <[email protected]> AuthorDate: Wed Oct 1 17:42:35 2025 -0400 #9 - add organization support to Grails Publish plugin --- README.md | 4 ++ .../gradle/publish/GrailsPublishPluginSpec.groovy | 55 +++++++++++++++++++ .../other-artifacts/organization/build.gradle | 61 ++++++++++++++++++++++ .../other-artifacts/organization/gradle.properties | 15 ++++++ .../other-artifacts/organization/settings.gradle | 20 +++++++ .../groovy/org/grails/example/MyProject.groovy | 27 ++++++++++ .../organization/src/main/java/TestJava.java | 11 ++++ .../src/main/java/another/TestOtherJava.java | 13 +++++ .../gradle/publish/GrailsPublishExtension.groovy | 47 +++++------------ .../publish/GrailsPublishGradlePlugin.groovy | 16 ++++-- .../apache/grails/gradle/publish/License.groovy | 55 +++++++++++++++++++ .../grails/gradle/publish/Organization.groovy | 31 +++++++++++ 12 files changed, 318 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 4a39c8c..b287206 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ or title = 'My plugin title' desc = 'My plugin description' developers = [johndoe: 'John Doe'] + organization { + name = 'My Company' + url = 'http://mycompany.com' + } } By default, this plugin will publish to the specified `MAVEN_PUBLISH` instance for snapshots, and `NEXUS_PUBLISH` for diff --git a/plugin/src/functionalTest/groovy/org/apache/grails/gradle/publish/GrailsPublishPluginSpec.groovy b/plugin/src/functionalTest/groovy/org/apache/grails/gradle/publish/GrailsPublishPluginSpec.groovy index 2e79b51..ff1bd90 100644 --- a/plugin/src/functionalTest/groovy/org/apache/grails/gradle/publish/GrailsPublishPluginSpec.groovy +++ b/plugin/src/functionalTest/groovy/org/apache/grails/gradle/publish/GrailsPublishPluginSpec.groovy @@ -653,6 +653,61 @@ class GrailsPublishPluginSpec extends GradleSpecification { result.output.contains("Project subproject2 will be a release.") } + def "organization in pom test"() { + given: + File tempDir = File.createTempDir("organization") + toCleanup << tempDir + + and: + GradleRunner runner = setupTestResourceProject('other-artifacts', 'organization') + + runner = setGradleProperty("projectVersion", "0.0.1-SNAPSHOT", runner) + runner = setGradleProperty("mavenPublishUrl", tempDir.toPath().toAbsolutePath().toString(), runner) + runner = addEnvironmentVariable("GRAILS_PUBLISH_RELEASE", "false", runner) + + when: + def result = executeTask("publish", ["--info", "--stacktrace"], runner) + + then: + assertTaskSuccess("sourcesJar", result) + assertTaskSuccess("javadocJar", result) + assertTaskSuccess("groovydoc", result) + assertBuildSuccess(result, ["compileJava", "compileGroovy", "processResources", "classes", "jar", "groovydoc", "javadoc", "javadocJar", "sourcesJar", "grailsPublishValidation", "requireMavenPublishUrl", "generateMetadataFileForMavenPublication", "generatePomFileForMavenPublication", "publishMavenPublicationToMavenLocal", "publishToMavenLocal"]) + + !result.output.contains("does not have a version defined. Using the gradle property `projectVersion` to assume version is ") + result.output.contains("Environment Variable `GRAILS_PUBLISH_RELEASE` detected - using variable instead of project version.") + + and: + Path artifactDir = tempDir.toPath().resolve("org/grails/example/organization/0.0.1-SNAPSHOT") + Files.exists(artifactDir) + File[] artifacts = artifactDir.toFile().listFiles() + + /* + organization-0.0.1-20250212.043425-1.pom.sha1 + organization-0.0.1-20250212.043425-1.pom.md5 + organization-0.0.1-20250212.043425-1-javadoc.jar.sha1 + organization-0.0.1-20250212.043425-1.module.md5 + organization-0.0.1-20250212.043425-1-sources.jar.md5 + organization-0.0.1-20250212.043425-1.jar.md5 + maven-metadata.xml + organization-0.0.1-20250212.043425-1.module + organization-0.0.1-20250212.043425-1.pom + organization-0.0.1-20250212.043425-1.jar.sha1 + organization-0.0.1-20250212.043425-1-javadoc.jar + organization-0.0.1-20250212.043425-1-sources.jar + organization-0.0.1-20250212.043425-1.jar + organization-0.0.1-20250212.043425-1.module.sha1 + organization-0.0.1-20250212.043425-1-sources.jar.sha1 + maven-metadata.xml.md5 + organization-0.0.1-20250212.043425-1-javadoc.jar.md5 + maven-metadata.xml.sha1 + */ + + File pomFile = artifacts.find { it.name.endsWith(".pom") } + pomFile + pomFile.text.replaceAll('\\n', '').replaceAll('\\s+', ' ').contains("<organization> <name>Apache Software Foundation</name> <url>https://www.apache.org/</url> </organization>") + } + def "source artifact test - simple project"() { given: File tempDir = File.createTempDir("simple-project") diff --git a/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/build.gradle b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/build.gradle new file mode 100644 index 0000000..cddf0f7 --- /dev/null +++ b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/build.gradle @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +buildscript { + repositories { + maven { url "${System.getenv('LOCAL_MAVEN_PATH')}" } + maven { url = 'https://repo.grails.org/grails/restricted' } + } + dependencies { + classpath "org.apache.grails.gradle:grails-publish:$grailsGradlePluginVersion" + } +} + +allprojects { + repositories { + maven { url = 'https://repo.grails.org/grails/restricted' } + } +} + +version = "${projectVersion}" +group = "org.grails.example" + +apply plugin: 'java-library' +apply plugin: 'groovy' + +dependencies { + implementation "org.apache.groovy:groovy:$groovyVersion" +} + +apply plugin: 'org.apache.grails.gradle.grails-publish' +grailsPublish { + githubSlug = 'apache/grails-cores' + license { + name = 'Apache-2.0' + } + title = 'Grails Gradle Plugin - Example Project' + desc = 'A testing project for the grails gradle plugin' + developers = [ + jdaugherty: 'James Daugherty', + ] + organization { + name = 'Apache Software Foundation' + url = 'https://www.apache.org/' + } +} \ No newline at end of file diff --git a/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/gradle.properties b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/gradle.properties new file mode 100644 index 0000000..2290586 --- /dev/null +++ b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/gradle.properties @@ -0,0 +1,15 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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 +# +# http://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. +projectVersion=0.0.1-SNAPSHOT \ No newline at end of file diff --git a/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/settings.gradle b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/settings.gradle new file mode 100644 index 0000000..9912b31 --- /dev/null +++ b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/settings.gradle @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +rootProject.name = 'organization' diff --git a/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/groovy/org/grails/example/MyProject.groovy b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/groovy/org/grails/example/MyProject.groovy new file mode 100644 index 0000000..09a7b52 --- /dev/null +++ b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/groovy/org/grails/example/MyProject.groovy @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.grails.example + +class MyProject { + + def sayHello() { + println "Hello from SubProject2" + } +} \ No newline at end of file diff --git a/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/java/TestJava.java b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/java/TestJava.java new file mode 100644 index 0000000..fe48756 --- /dev/null +++ b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/java/TestJava.java @@ -0,0 +1,11 @@ +/** + * Some example javadoc + */ +public class TestJava { + /** + * An example method + */ + public void sayHelloFromJava() { + System.out.println("Hello"); + } +} \ No newline at end of file diff --git a/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/java/another/TestOtherJava.java b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/java/another/TestOtherJava.java new file mode 100644 index 0000000..979649e --- /dev/null +++ b/plugin/src/functionalTest/resources/publish-projects/other-artifacts/organization/src/main/java/another/TestOtherJava.java @@ -0,0 +1,13 @@ +package another; + +/** + * Some example javadoc + */ +public class TestOtherJava { + /** + * An example method + */ + public void sayHelloFromJava() { + System.out.println("Hello"); + } +} \ No newline at end of file diff --git a/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishExtension.groovy b/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishExtension.groovy index d80dbf6..a1d4c54 100644 --- a/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishExtension.groovy +++ b/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishExtension.groovy @@ -19,17 +19,25 @@ package org.apache.grails.gradle.publish import groovy.transform.CompileStatic +import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property +import org.gradle.api.tasks.Nested import javax.inject.Inject @CompileStatic class GrailsPublishExtension { + /** + * The organization that produces the project + */ + @Nested + final Organization organization + /** * The slug from github */ @@ -173,6 +181,11 @@ class GrailsPublishExtension { addComponents = objects.property(Boolean).convention(true) publicationName = objects.property(String).convention('maven') transitiveDependencies = objects.property(Boolean).convention(true) + organization = objects.newInstance(Organization) + } + + void organization(Action<? super Organization> action) { + action.execute(organization) } License getLicense() { @@ -200,39 +213,5 @@ class GrailsPublishExtension { this.license.name = license } - static class License { - - String name - String url - String distribution = 'repo' - - static final License APACHE2 = new License(name: 'The Apache Software License, Version 2.0', url: 'https://www.apache.org/licenses/LICENSE-2.0.txt') - static final License EPL1 = new License(name: 'Eclipse Public License - v 1.0', url: 'https://www.eclipse.org/legal/epl-v10.html') - static final License LGPL21 = new License(name: 'GNU Lesser General Public License, version 2.1', url: 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html') - static final License LGPL = new License(name: 'GNU Lesser General Public License', url: 'https://www.gnu.org/licenses/lgpl-3.0.html') - static final License GPL = new License(name: 'GNU General Public License', url: 'https://www.gnu.org/licenses/gpl-3.0.en.html') - static final License CPL = new License(name: 'Common Public License Version 1.0 (CPL)', url: 'https://opensource.org/licenses/cpl1.0.php') - static final License AGPL = new License(name: 'GNU Affero General Public License', url: 'https://www.gnu.org/licenses/agpl-3.0.html') - static final License MIT = new License(name: 'The MIT License (MIT)', url: 'https://opensource.org/licenses/MIT') - static final License BSD = new License(name: 'The BSD 3-Clause License', url: 'https://opensource.org/licenses/BSD-3-Clause') - static final Map<String, License> LICENSES = [ - 'Apache-2.0' : APACHE2, - 'Apache' : APACHE2, - 'AGPL' : AGPL, - 'AGPL-3.0' : AGPL, - 'GPL-3.0' : GPL, - 'GPL' : GPL, - 'EPL' : EPL1, - 'EPL-1.0' : EPL1, - 'CPL' : CPL, - 'CPL-1.0' : CPL, - 'LGPL' : LGPL, - 'LGPL-3.0' : LGPL, - 'LGPL-2.1' : LGPL21, - 'BSD' : BSD, - 'BSD 3-Clause': BSD, - 'MIT' : MIT - ] - } } diff --git a/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy b/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy index 65b2977..2031180 100644 --- a/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy +++ b/plugin/src/main/groovy/org/apache/grails/gradle/publish/GrailsPublishGradlePlugin.groovy @@ -41,7 +41,6 @@ import org.gradle.api.plugins.ExtraPropertiesExtension import org.gradle.api.plugins.JavaPlatformExtension import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.PluginManager -import org.gradle.api.publish.Publication import org.gradle.api.publish.PublicationContainer import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPom @@ -55,7 +54,6 @@ import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.plugins.MavenPublishPlugin import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.api.tasks.GroovySourceDirectorySet -import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskProvider @@ -333,9 +331,21 @@ Note: if project properties are used, the properties must be defined prior to ap pom.description.set(gpe.desc.get()) pom.url.set(gpe.websiteUrl.get()) + def organization = gpe.organization + if (organization.name.isPresent() || organization.url.isPresent()) { + pom.organization { org -> + if (organization.name.isPresent()) { + org.name.set(organization.name) + } + if (organization.url.isPresent()) { + org.url.set(organization.url) + } + } + } + def license = gpe.license if (license) { - def concreteLicense = GrailsPublishExtension.License.LICENSES.get(license.name) + def concreteLicense = License.LICENSES.get(license.name) if (concreteLicense) { pom.licenses { MavenPomLicenseSpec licenses -> licenses.license { MavenPomLicense pomLicense -> diff --git a/plugin/src/main/groovy/org/apache/grails/gradle/publish/License.groovy b/plugin/src/main/groovy/org/apache/grails/gradle/publish/License.groovy new file mode 100644 index 0000000..f25ce25 --- /dev/null +++ b/plugin/src/main/groovy/org/apache/grails/gradle/publish/License.groovy @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.grails.gradle.publish + +class License { + + String name + String url + String distribution = 'repo' + + static final License APACHE2 = new License(name: 'The Apache Software License, Version 2.0', url: 'https://www.apache.org/licenses/LICENSE-2.0.txt') + static final License EPL1 = new License(name: 'Eclipse Public License - v 1.0', url: 'https://www.eclipse.org/legal/epl-v10.html') + static final License LGPL21 = new License(name: 'GNU Lesser General Public License, version 2.1', url: 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html') + static final License LGPL = new License(name: 'GNU Lesser General Public License', url: 'https://www.gnu.org/licenses/lgpl-3.0.html') + static final License GPL = new License(name: 'GNU General Public License', url: 'https://www.gnu.org/licenses/gpl-3.0.en.html') + static final License CPL = new License(name: 'Common Public License Version 1.0 (CPL)', url: 'https://opensource.org/licenses/cpl1.0.php') + static final License AGPL = new License(name: 'GNU Affero General Public License', url: 'https://www.gnu.org/licenses/agpl-3.0.html') + static final License MIT = new License(name: 'The MIT License (MIT)', url: 'https://opensource.org/licenses/MIT') + static final License BSD = new License(name: 'The BSD 3-Clause License', url: 'https://opensource.org/licenses/BSD-3-Clause') + static final Map<String, License> LICENSES = [ + 'Apache-2.0' : APACHE2, + 'Apache' : APACHE2, + 'AGPL' : AGPL, + 'AGPL-3.0' : AGPL, + 'GPL-3.0' : GPL, + 'GPL' : GPL, + 'EPL' : EPL1, + 'EPL-1.0' : EPL1, + 'CPL' : CPL, + 'CPL-1.0' : CPL, + 'LGPL' : LGPL, + 'LGPL-3.0' : LGPL, + 'LGPL-2.1' : LGPL21, + 'BSD' : BSD, + 'BSD 3-Clause': BSD, + 'MIT' : MIT + ] +} diff --git a/plugin/src/main/groovy/org/apache/grails/gradle/publish/Organization.groovy b/plugin/src/main/groovy/org/apache/grails/gradle/publish/Organization.groovy new file mode 100644 index 0000000..54fd719 --- /dev/null +++ b/plugin/src/main/groovy/org/apache/grails/gradle/publish/Organization.groovy @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.grails.gradle.publish + +import groovy.transform.CompileStatic +import org.gradle.api.provider.Property + +@CompileStatic +abstract class Organization { + + abstract Property<String> getName() + + abstract Property<String> getUrl() +}
