Skip to content

Commit

Permalink
Merge branch '6.2.x' into gradle-89-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
codeconsole committed Aug 16, 2024
2 parents 5c5966d + f1623f5 commit b6b1c05
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 17 deletions.
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ dependencies {
implementation "com.bmuschko:gradle-nexus-plugin:2.3.1"
implementation "org.grails:grails-bootstrap:$grailsVersion"
implementation "org.grails:grails-gradle-model:$grailsVersion"
implementation "org.grails:grails-shell:$grailsVersion"
implementation "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
implementation "io.spring.gradle:dependency-management-plugin:1.1.4"
}
Expand Down Expand Up @@ -113,6 +114,12 @@ gradlePlugin {
id = 'org.grails.grails-plugin'
implementationClass = 'org.grails.gradle.plugin.core.GrailsPluginGradlePlugin'
}
grailsProfile {
displayName = "Grails Profile Gradle Plugin"
description = 'A plugin that is capable of compiling a Grails profile into a JAR file for distribution'
id = 'org.grails.grails-profile'
implementationClass = 'org.grails.gradle.plugin.profiles.GrailsProfileGradlePlugin'
}
grailsWeb {
displayName = "Grails Web Gradle Plugin"
description = 'Adds web specific extensions'
Expand All @@ -125,6 +132,12 @@ gradlePlugin {
id = 'org.grails.internal.grails-plugin-publish'
implementationClass = 'org.grails.gradle.plugin.publishing.internal.GrailsCentralPublishGradlePlugin'
}
grailsProfilePublish {
displayName = "Grails Profile Publish Plugin"
description = 'A plugin for publishing profiles'
id = 'org.grails.internal.grails-profile-publish'
implementationClass = 'org.grails.gradle.plugin.profiles.internal.GrailsProfilePublishGradlePlugin'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
projectVersion=6.2.1-SNAPSHOT
grailsVersion=6.2.0
grailsVersion=6.2.1-SNAPSHOT
springBootVersion=2.7.18

org.gradle.caching=true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright 2015 original 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
*
* 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.
*/
package org.grails.gradle.plugin.profiles

import grails.io.IOUtils
import grails.util.BuildSettings
import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.DependencyResolveDetails
import org.gradle.api.file.CopySpec
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar
import org.grails.cli.profile.commands.script.GroovyScriptCommand
import org.grails.gradle.plugin.profiles.tasks.ProfileCompilerTask


import static org.gradle.api.plugins.BasePlugin.*

/**
* A plugin that is capable of compiling a Grails profile into a JAR file for distribution
*
* @author Graeme Rocher
* @since 3.1
*/
@CompileStatic
class GrailsProfileGradlePlugin implements Plugin<Project> {

static final String CONFIGURATION_NAME = 'grails'

public static final String RUNTIME_CONFIGURATION = "profileRuntimeOnly"

@Override
void apply(Project project) {
project.getPluginManager().apply(BasePlugin.class)
project.configurations.create(CONFIGURATION_NAME)
def profileConfiguration = project.configurations.create(RUNTIME_CONFIGURATION)

profileConfiguration.resolutionStrategy.eachDependency {
DependencyResolveDetails details = (DependencyResolveDetails)it
def requested = details.requested
def group = requested.group
def version = requested.version

if(!group || !version) {
group = group ?: "org.grails.profiles"
version = version ?: BuildSettings.grailsVersion

details.useTarget(group: group, name: requested.name,version:version)
}
}

def profileYml = project.file("profile.yml")

def commandsDir = project.file("commands")
def resourcesDir = new File(project.buildDir, "resources/profile")
def templatesDir = project.file("templates")
def skeletonsDir = project.file("skeleton")
def featuresDir = project.file("features")

def spec1 = project.copySpec { CopySpec spec ->
spec.from(commandsDir)
spec.exclude("*.groovy")
spec.into("commands")
}
def spec2 = project.copySpec { CopySpec spec ->
spec.from(templatesDir)
spec.into("templates")
}
def spec4 = project.copySpec { CopySpec spec ->
spec.from(featuresDir)
spec.into("features")
}
def spec3 = project.copySpec { CopySpec spec ->
spec.from(skeletonsDir)
spec.into("skeleton")
}

def processResources = project.tasks.create("processResources", Copy, (Action){ Copy c ->
c.with(spec1, spec2, spec3, spec4)
c.into(new File(resourcesDir, "/META-INF/grails-profile"))
})

def classsesDir = new File(project.buildDir, "classes/profile")
def compileTask = project.tasks.create("compileProfile", ProfileCompilerTask, (Action) { ProfileCompilerTask task ->
task.destinationDir = classsesDir
task.source = commandsDir
task.config = profileYml
if(templatesDir.exists()) {
task.templatesDir = templatesDir
}
task.classpath = project.configurations.getByName(RUNTIME_CONFIGURATION) + project.files(IOUtils.findJarFile(GroovyScriptCommand))
})

def jarTask = project.tasks.create("jar", Jar, (Action) { Jar jar ->
jar.dependsOn(processResources, compileTask)
jar.from(resourcesDir)
jar.from(classsesDir)
jar.destinationDir = new File(project.buildDir, "libs")
jar.setDescription("Assembles a jar archive containing the profile classes.")
jar.setGroup(BUILD_GROUP)

ArchivePublishArtifact jarArtifact = new ArchivePublishArtifact(jar)
project.artifacts.add(CONFIGURATION_NAME, jarArtifact)
})

project.tasks.create("sourcesJar", Jar, (Action) { Jar jar ->
jar.from(commandsDir)
if(profileYml.exists()) {
jar.from(profileYml)
}
jar.from(templatesDir) { CopySpec spec ->
spec.into("templates")
}
jar.from(skeletonsDir) { CopySpec spec ->
spec.into("skeleton")
}
jar.archiveClassifier.set("sources")
jar.destinationDirectory.set(new File(project.buildDir, "libs"))
jar.setDescription("Assembles a jar archive containing the profile sources.")
jar.setGroup(BUILD_GROUP)

})
project.tasks.findByName("assemble").dependsOn jarTask

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2015 original 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
*
* 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.
*/
package org.grails.gradle.plugin.profiles.internal


import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.XmlProvider
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.DependencySet
import org.gradle.api.artifacts.SelfResolvingDependency
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.grails.gradle.plugin.profiles.GrailsProfileGradlePlugin
import org.grails.gradle.plugin.publishing.internal.GrailsCentralPublishGradlePlugin

import java.nio.file.Files

import static org.gradle.api.plugins.BasePlugin.BUILD_GROUP

/**
* A plugin for publishing profiles
*
* @author Graeme Rocher
* @since 3.1
*/
@CompileStatic
class GrailsProfilePublishGradlePlugin extends GrailsCentralPublishGradlePlugin {

@Override
void apply(Project project) {
super.apply(project)
final File tempReadmeForJavadoc = Files.createTempFile("README", "txt").toFile()
tempReadmeForJavadoc << "https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources"
project.tasks.create("javadocJar", Jar, (Action) { Jar jar ->
jar.from(tempReadmeForJavadoc)
jar.archiveClassifier.set("javadoc")
jar.destinationDirectory.set(new File(project.buildDir, "libs"))
jar.setDescription("Assembles a jar archive containing the profile javadoc.")
jar.setGroup(BUILD_GROUP)
})
}

@Override
protected String getDefaultGrailsCentralReleaseRepo() {
"https://repo.grails.org/grails/libs-releases-local"
}

@Override
protected String getDefaultGrailsCentralSnapshotRepo() {
"https://repo.grails.org/grails/libs-snapshots-local"
}

@Override
protected Map<String, String> getDefaultExtraArtifact(Project project) {
[source: "${project.buildDir}/classes/profile/META-INF/grails-profile/profile.yml".toString(),
classifier: defaultClassifier,
extension : 'yml']
}

@Override
protected String getDefaultClassifier() {
'profile'
}

@Override
protected String getDefaultRepo() {
'profiles'
}

@Override
protected void doAddArtefact(Project project, MavenPublication publication) {
publication.artifact(project.tasks.findByName("jar"))
publication.pom(new Action<org.gradle.api.publish.maven.MavenPom>() {
@Override
void execute(org.gradle.api.publish.maven.MavenPom mavenPom) {
mavenPom.withXml(new Action<XmlProvider>() {
@Override
void execute(XmlProvider xml) {
Node dependenciesNode = xml.asNode().appendNode('dependencies')

DependencySet dependencySet = project.configurations[GrailsProfileGradlePlugin.RUNTIME_CONFIGURATION].allDependencies

for (Dependency dependency : dependencySet) {
if (! (dependency instanceof SelfResolvingDependency)) {
Node dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
dependencyNode.appendNode('scope', GrailsProfileGradlePlugin.RUNTIME_CONFIGURATION)
}
}
}
})
}
})
}
}
Loading

0 comments on commit b6b1c05

Please sign in to comment.