Skip to content

Commit

Permalink
Merge pull request #155 from grails/scaffolding
Browse files Browse the repository at this point in the history
Update Scaffolding Feature
  • Loading branch information
puneetbehl authored Jun 20, 2023
2 parents cad3692 + c956e50 commit 58b9166
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ micronautDocsVersion=2.0.0
micronautVersion=3.9.3
rockerVersion=1.3.0
groovyVersion=3.0.17
grailsVersion=6.0.0-RC1
grailsVersion=6.0.0-SNAPSHOT
spockVersion=2.0-groovy-3.0
title=Grails Application Forge
projectDesc=Generates Grails applications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import jakarta.inject.Singleton;
import org.grails.forge.application.ApplicationType;
import org.grails.forge.application.generator.GeneratorContext;
import org.grails.forge.build.dependencies.Dependency;
import org.grails.forge.feature.DefaultFeature;
import org.grails.forge.feature.Feature;
import org.grails.forge.feature.FeatureContext;
Expand Down Expand Up @@ -66,7 +67,7 @@ public String getThirdPartyDocumentation() {

@Override
public boolean supports(ApplicationType applicationType) {
return true;
return applicationType == ApplicationType.WEB || applicationType == ApplicationType.WEB_PLUGIN;
}

@Override
Expand All @@ -78,6 +79,14 @@ public void processSelectedFeatures(FeatureContext featureContext) {

@Override
public void apply(GeneratorContext generatorContext) {
generatorContext.addDependency(Dependency.builder()
.groupId("org.fusesource.jansi")
.lookupArtifactId("jansi")
.runtime());

generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.plugins")
.artifactId("scaffolding")
.compile());
}
}
7 changes: 6 additions & 1 deletion grails-forge-core/src/main/resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-gradle-plugin</artifactId>
Expand Down Expand Up @@ -83,7 +88,7 @@
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>gradle.plugin.com.github.erdi.webdriver-binaries</groupId>
<groupId>com.github.erdi</groupId>
<artifactId>webdriver-binaries-gradle-plugin</artifactId>
<version>3.0</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class EHCacheSpec extends ApplicationContextSpec implements CommandOutputFixture

then:
readme
readme.contains("https://docs.grails.org/6.0.0-RC1/guide/index.html")
readme.contains("https://docs.grails.org/6.0.0-RC1/api/index.html")
readme.contains("https://docs.grails.org/snapshot/guide/index.html")
readme.contains("https://docs.grails.org/snapshot/api/index.html")
readme.contains("https://guides.grails.org/index.html")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GrailsGradlePluginSpec extends BeanContextSpec implements CommandOutputFix

then:
gradleProps.contains("grailsGradlePluginVersion=6.0.0-RC1")
gradleProps.contains("grailsVersion=6.0.0-RC1")
gradleProps.contains("grailsVersion=6.0.0-SNAPSHOT")
}

void "test dependencies are present for buildSrc"() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.grails.forge.feature.view

import org.grails.forge.ApplicationContextSpec
import org.grails.forge.BuildBuilder
import org.grails.forge.feature.Features
import org.grails.forge.fixture.CommandOutputFixture

class ScaffoldingSpec extends ApplicationContextSpec implements CommandOutputFixture {

void "test scaffolding feature"() {
when:
final Features features = getFeatures(['scaffolding'])

then:
features.contains('scaffolding')
}

void "test dependencies are present in build.gradle"() {
when:
final String template = new BuildBuilder(beanContext)
.features(['scaffolding'])
.render()

then:
template.contains('implementation("org.grails.plugins:scaffolding")')
template.contains('runtimeOnly("org.fusesource.jansi:jansi:1.18")')
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.grails.forge.features.scaffolding

import org.gradle.testkit.runner.BuildResult
import org.grails.forge.options.Language
import org.grails.forge.utils.CommandSpec

class ScaffoldingSpec extends CommandSpec {

void "test generate-controller command"() {

given:
generateProject(Language.DEFAULT_OPTION)

when:
final File domainPkg = new File(dir, "grails-app/domain/example/grails")
domainPkg.mkdirs()
new File(domainPkg, "Bird.groovy").text = '''package example.grails
class Bird {
String name
}
'''
final String output = executeGradle("runCommand", "-Pargs=generate-controller example.grails.Bird").getOutput()

then:
output.contains('Rendered template Controller.groovy to destination grails-app/controllers/example/grails/BirdController.groovy')
output.contains('Rendered template Service.groovy to destination grails-app/services/example/grails/BirdService.groovy')
output.contains('Rendered template Spec.groovy to destination src/test/groovy/example/grails/BirdControllerSpec.groovy')
output.contains('Rendered template ServiceSpec.groovy to destination src/test/groovy/example/grails/BirdServiceSpec.groovy')
new File(dir, "grails-app/controllers/example/grails/BirdController.groovy").exists()
new File(dir, "grails-app/services/example/grails/BirdService.groovy").exists()
new File(dir, "src/test/groovy/example/grails/BirdControllerSpec.groovy").exists()
new File(dir, "src/test/groovy/example/grails/BirdControllerSpec.groovy").exists()
}

@Override
String getTempDirectoryPrefix() {
'testapp'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ abstract class CommandSpec extends Specification {
.build()
}

BuildResult executeGradle(String... arguments) {
gradleRunner.withProjectDir(dir)
.withArguments(arguments)
.build()
}

void generateProject(Language lang,
BuildTool buildTool = BuildTool.DEFAULT_OPTION,
OperatingSystem operatingSystem = OperatingSystem.LINUX,
Expand Down

0 comments on commit 58b9166

Please sign in to comment.