Skip to content

Commit

Permalink
Merge pull request #189 from grails/buildPluginVersion
Browse files Browse the repository at this point in the history
Move Gradle build plugin version to settings.gradle
  • Loading branch information
puneetbehl authored Aug 2, 2023
2 parents 60d36ae + 34d0c5b commit 3e139c5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public List<GradlePlugin> getPlugins() {
return plugins;
}

@NonNull
public List<GradlePlugin> getPluginsWithVersion() {
return plugins.stream().filter(plugin -> plugin.getVersion() != null).collect(Collectors.toList());
}

@NonNull
public String renderExtensions() {
return renderWritableExtensions(Stream.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GradleBuild gradleBuild
}
plugins {
@for (GradlePlugin gradlePlugin : gradleBuild.getPlugins()) {
id "@gradlePlugin.getId()" @(gradlePlugin.getVersion() != null ? "version \"" + gradlePlugin.getVersion() + "\"" : "")
id "@gradlePlugin.getId()"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import org.grails.forge.build.dependencies.CoordinateResolver
@import org.grails.forge.build.dependencies.Coordinate
@import org.grails.forge.build.gradle.GradleBuild
@import org.grails.forge.build.gradle.GradlePlugin
@import org.grails.forge.feature.Features

@args (
Expand Down Expand Up @@ -39,6 +40,10 @@ pluginManagement {
@if(features.contains("asset-pipeline-grails")) {
id "com.bertramlabs.asset-pipeline" version "@assetPipelineVersion"
}

@for (GradlePlugin gradlePlugin : gradleBuild.getPluginsWithVersion()) {
id "@gradlePlugin.getId()" version "@gradlePlugin.getVersion()"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,63 @@
package org.grails.forge.feature.asciidoctor

import io.micronaut.core.version.SemanticVersion
import org.grails.forge.ApplicationContextSpec
import org.grails.forge.BuildBuilder
import spock.lang.Unroll
import org.grails.forge.application.ApplicationType
import org.grails.forge.feature.Features
import org.grails.forge.fixture.CommandOutputFixture
import org.grails.forge.options.JdkVersion
import org.grails.forge.options.Options
import org.grails.forge.options.TestFramework

class AsciidoctorSpec extends ApplicationContextSpec {
class AsciidoctorSpec extends ApplicationContextSpec implements CommandOutputFixture {

@Unroll
void 'test gradle asciidoctor feature'() {
when:
String template = new BuildBuilder(beanContext)
.features(['asciidoctor'])
.render()
final Features features = getFeatures(["asciidoctor"])

then:
template.contains("apply from: \"gradle/asciidoc.gradle\"")
features.contains("asciidoctor")
}

when:
String pluginId = 'org.asciidoctor.jvm.convert'
String applyPlugin = 'id "' + pluginId + '" version "'
void "test asciidoctor gradle configurations"() {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ["asciidoctor"])
final def buildGradle = output["build.gradle"]
final def settingGradle = output["settings.gradle"]

then:
template.contains(applyPlugin)
expect:
settingGradle.contains("id \"org.asciidoctor.jvm.convert\" version \"4.0.0-alpha.1\"")
buildGradle.contains("apply from: \"gradle/asciidoc.gradle\"")
}

when:
Optional<SemanticVersion> semanticVersionOptional = parseCommunityGradlePluginVersion(pluginId, template).map(SemanticVersion::new)
void "test asciidoctor gradle configurations"() {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11), ["asciidoctor"])
final def asciidocGradle = output["gradle/asciidoc.gradle"]

expect:
asciidocGradle.contains("""asciidoctorj {
version '2.1.0'
modules {
diagram {
version '1.5.18'
}
}
then:
noExceptionThrown()
semanticVersionOptional.isPresent()
options doctype: "book", ruby: "erubis"
attributes "sourcedir": "src/docs/asciidoc",
"source-highlighter": "coderay",
"toc": "left",
"idprefix": "",
"idseparator": "-",
"icons": "font",
"setanchors": "",
"listing-caption": "",
"imagesdir": "images",
"project-version": "\$project.version",
"revnumber": "\$project.version"
}
""")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class GebSpec extends ApplicationContextSpec implements CommandOutputFixture {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11))
final def buildGradle = output["build.gradle"]
final def settingGradle = output["settings.gradle"]

expect:
buildGradle.contains("id \"com.github.erdi.webdriver-binaries\" version \"3.0\"")
settingGradle.contains("id \"com.github.erdi.webdriver-binaries\" version \"3.0\"")
buildGradle.contains("id \"com.github.erdi.webdriver-binaries\"")
buildGradle.contains("webdriverBinaries")
buildGradle.contains("chromedriver '110.0.5481.77'")
buildGradle.contains("geckodriver '0.32.2'")
Expand All @@ -74,9 +76,11 @@ class GebSpec extends ApplicationContextSpec implements CommandOutputFixture {
given:
final def output = generate(ApplicationType.WEB, new Options(TestFramework.SPOCK, JdkVersion.JDK_11, OperatingSystem.WINDOWS))
final def buildGradle = output["build.gradle"]
final def settingGradle = output["settings.gradle"]

expect:
buildGradle.contains("id \"com.github.erdi.webdriver-binaries\" version \"3.0\"")
settingGradle.contains("id \"com.github.erdi.webdriver-binaries\" version \"3.0\"")
buildGradle.contains("id \"com.github.erdi.webdriver-binaries\"")
buildGradle.contains("webdriverBinaries")
buildGradle.contains("chromedriver '110.0.5481.77'")
buildGradle.contains("geckodriver '0.32.2'")
Expand Down

0 comments on commit 3e139c5

Please sign in to comment.