Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build init plugin improvements #9191

Merged
merged 20 commits into from Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
eb978f0
Add a build init template for a Gradle plugin implemented in Java. Th…
adammurdoch Apr 16, 2019
b0069d0
Add build init templates for a basic Gradle plugin implemented in Gro…
adammurdoch Apr 16, 2019
63d096d
Split up some pieces of the build init plugin to use composition inst…
adammurdoch Apr 16, 2019
c939e44
Use more composition oof the build init descriptors.
adammurdoch Apr 16, 2019
82bbc76
Use more idiomatic Kotlin DSL in build script generated by build init…
adammurdoch Apr 16, 2019
79221ad
Some clean up of the build files generated by the build init plugin.
adammurdoch Apr 16, 2019
983e6d5
Change the Gradle plugins generated by the build init plugin to regis…
adammurdoch Apr 16, 2019
4c20855
Add a functional test suite to the Gradle plugin builds generated by …
adammurdoch Apr 17, 2019
a86e495
Change the functional test suite generated by the build init plugin t…
adammurdoch Apr 17, 2019
2464900
Fix Java gradle plugin functional tests on Java 8.
adammurdoch Apr 19, 2019
6864cdb
Improve the DSL generated by build init plugin for Gradle plugin builds.
adammurdoch Apr 18, 2019
8038199
Update release notes and user manual for changes to build init plugin.
adammurdoch Apr 18, 2019
7c7ca53
Polish the build scripts generated by the build init plugin.
adammurdoch Apr 18, 2019
f346ebe
Polish the build scripts generated by the build init plugin.
adammurdoch Apr 19, 2019
e7b8023
Add some comments to the source files generated by the build init plu…
adammurdoch Apr 19, 2019
26558be
Tweak the plugin id generated by the build init plugin.
adammurdoch Apr 19, 2019
b972b74
Split the interactive question used by the build init plugin to selec…
adammurdoch Apr 19, 2019
25e0a16
Use 'java' as the default implementation language for builds generate…
adammurdoch Apr 19, 2019
d8edfcf
Some release note and user manual edits for the build init changes.
adammurdoch Apr 19, 2019
62b8e2e
Update library versions used by the build init plugin.
adammurdoch Apr 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions subprojects/build-init/build-init.gradle.kts
Expand Up @@ -65,6 +65,7 @@ tasks {
findLatest("scala-xml", "org.scala-lang.modules:scala-xml_${versionProperties["scala"]}:latest.release", versionProperties)
findLatest("groovy", "org.codehaus.groovy:groovy:(2.5,)", versionProperties)
findLatest("junit", "junit:junit:(4.0,)", versionProperties)
findLatest("junit-jupiter", "org.junit.jupiter:junit-jupiter-api:(5,)", versionProperties)
findLatest("testng", "org.testng:testng:(6.0,)", versionProperties)
findLatest("slf4j", "org.slf4j:slf4j-api:(1.7,)", versionProperties)

Expand Down Expand Up @@ -112,6 +113,7 @@ val devSuffixes = arrayOf(
"-beta-?\\d+",
"-dev-?\\d+",
"-rc-?\\d+",
"-RC-?\\d+",
"-M\\d+",
"-eap-?\\d+"
)
Expand Up @@ -39,6 +39,12 @@ class AbstractInitIntegrationSpec extends AbstractIntegrationSpec {
result.testClass(className).assertTestPassed(name)
}

void assertFunctionalTestPassed(String className, String name) {
def result = new DefaultTestExecutionResult(targetDir, 'build', '', '', 'functionalTest')
result.assertTestClassesExecuted(className)
result.testClass(className).assertTestPassed(name)
}

protected void commonFilesGenerated(BuildInitDsl scriptDsl) {
dslFixtureFor(scriptDsl).assertGradleFilesGenerated()
targetDir.file(".gitignore").assertIsFile()
Expand Down
Expand Up @@ -39,13 +39,18 @@ class BuildInitInteractiveIntegrationTest extends AbstractInitIntegrationSpec {
ConcurrentTestUtil.poll(60) {
assert handle.standardOutput.contains(projectTypePrompt)
assert handle.standardOutput.contains(basicType)
assert handle.standardOutput.contains("2: application")
assert handle.standardOutput.contains("3: library")
assert handle.standardOutput.contains("4: Gradle plugin")
assert !handle.standardOutput.contains("pom")
}
handle.stdinPipe.write(("1" + TextUtil.platformLineSeparator).bytes)

// Select 'kotlin'
ConcurrentTestUtil.poll {
assert handle.standardOutput.contains(dslPrompt)
assert handle.standardOutput.contains("1: Groovy")
assert handle.standardOutput.contains("2: Kotlin")
}
handle.stdinPipe.write(("2" + TextUtil.platformLineSeparator).bytes)

Expand All @@ -61,6 +66,62 @@ class BuildInitInteractiveIntegrationTest extends AbstractInitIntegrationSpec {
dslFixtureFor(BuildInitDsl.KOTLIN).assertGradleFilesGenerated()
}

def "user can provide details for JVM based build"() {
when:
executer.withForceInteractive(true)
executer.withStdinPipe()
executer.withTasks("init")
def handle = executer.start()

// Select 'library'
ConcurrentTestUtil.poll(60) {
assert handle.standardOutput.contains(projectTypePrompt)
}
handle.stdinPipe.write(("3" + TextUtil.platformLineSeparator).bytes)

// Select 'java'
ConcurrentTestUtil.poll {
assert handle.standardOutput.contains("Select implementation language:")
assert handle.standardOutput.contains("1: C++")
assert handle.standardOutput.contains("2: Groovy")
assert handle.standardOutput.contains("3: Java")
assert handle.standardOutput.contains("4: Kotlin")
assert handle.standardOutput.contains("5: Scala")
}
handle.stdinPipe.write(("3" + TextUtil.platformLineSeparator).bytes)

// Select 'kotlin' DSL
ConcurrentTestUtil.poll {
assert handle.standardOutput.contains(dslPrompt)
}
handle.stdinPipe.write(("2" + TextUtil.platformLineSeparator).bytes)

// Select 'junit'
ConcurrentTestUtil.poll {
assert handle.standardOutput.contains("Select test framework:")
assert handle.standardOutput.contains("1: JUnit 4")
}
handle.stdinPipe.write(("1" + TextUtil.platformLineSeparator).bytes)

// Select default project name
ConcurrentTestUtil.poll {
assert handle.standardOutput.contains(projectNamePrompt)
}
handle.stdinPipe.write(TextUtil.platformLineSeparator.bytes)

// Enter a package name
ConcurrentTestUtil.poll {
assert handle.standardOutput.contains("Source package (default: some.thing)")
}
handle.stdinPipe.write(("org.gradle.test" + TextUtil.platformLineSeparator).bytes)

handle.stdinPipe.close()
handle.waitForFinish()

then:
dslFixtureFor(BuildInitDsl.KOTLIN).assertGradleFilesGenerated()
}

def "prompts user when run from an interactive session and pom.xml present"() {
when:
pom()
Expand Down
Expand Up @@ -198,15 +198,18 @@ include("child")
fails('init', '--type', 'some-unknown-library')

then:
failure.assertHasCause("""The requested build setup type 'some-unknown-library' is not supported. Supported types:
failure.assertHasCause("""The requested build type 'some-unknown-library' is not supported. Supported types:
- 'basic'
- 'cpp-application'
- 'cpp-library'
- 'groovy-application'
- 'groovy-gradle-plugin'
- 'groovy-library'
- 'java-application'
- 'java-gradle-plugin'
- 'java-library'
- 'kotlin-application'
- 'kotlin-gradle-plugin'
- 'kotlin-library'
- 'pom'
- 'scala-library'""")
Expand All @@ -227,7 +230,7 @@ include("child")
fails('init', '--type', 'basic', '--test-framework', 'fake')

then:
failure.assertHasCause("""The requested test framework 'fake' is not supported for 'basic' setup type. Supported frameworks:
failure.assertHasCause("""The requested test framework 'fake' is not supported for 'basic' build type. Supported frameworks:
- 'none'""")
}

Expand All @@ -236,7 +239,7 @@ include("child")
fails('init', '--type', 'basic', '--test-framework', 'spock')

then:
failure.assertHasCause("""The requested test framework 'spock' is not supported for 'basic' setup type. Supported frameworks:
failure.assertHasCause("""The requested test framework 'spock' is not supported for 'basic' build type. Supported frameworks:
- 'none'""")
}

Expand All @@ -245,15 +248,15 @@ include("child")
fails('init', '--type', 'pom', '--project-name', 'thing')

then:
failure.assertHasCause("Project name is not supported for 'pom' setup type.")
failure.assertHasCause("Project name is not supported for 'pom' build type.")
}

def "gives decent error message when package name option is not supported by specific type"() {
when:
fails('init', '--type', 'basic', '--package', 'thing')

then:
failure.assertHasCause("Package name is not supported for 'basic' setup type.")
failure.assertHasCause("Package name is not supported for 'basic' build type.")
}

def "displays all build types and modifiers in help command output"() {
Expand All @@ -274,7 +277,7 @@ include("child")
--test-framework Set the test framework to be used.
Available values are:
junit
junitjupiter
junit-jupiter
kotlintest
scalatest
spock
Expand All @@ -286,10 +289,13 @@ include("child")
cpp-application
cpp-library
groovy-application
groovy-gradle-plugin
groovy-library
java-application
java-gradle-plugin
java-library
kotlin-application
kotlin-gradle-plugin
kotlin-library
pom
scala-library""")
Expand Down
Expand Up @@ -80,7 +80,7 @@ class GroovyApplicationInitIntegrationTest extends AbstractInitIntegrationSpec {
fails('init', '--type', 'groovy-application', '--test-framework', 'testng', '--dsl', scriptDsl.id)

then:
failure.assertHasCause("""The requested test framework 'testng' is not supported for 'groovy-application' setup type. Supported frameworks:
failure.assertHasCause("""The requested test framework 'testng' is not supported for 'groovy-application' build type. Supported frameworks:
- 'spock'""")

where:
Expand Down
@@ -0,0 +1,48 @@
/*
* Copyright 2019 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
*
* 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.gradle.buildinit.plugins

import org.gradle.buildinit.plugins.fixtures.ScriptDslFixture
import spock.lang.Unroll


class GroovyGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
@Unroll
def "creates sample source if no source present with #scriptDsl build scripts"() {
when:
run('init', '--type', 'groovy-gradle-plugin', '--dsl', scriptDsl.id)

then:
targetDir.file("src/main/groovy").assertHasDescendants("some/thing/SomeThingPlugin.groovy")
targetDir.file("src/test/groovy").assertHasDescendants("some/thing/SomeThingPluginTest.groovy")
targetDir.file("src/functionalTest/groovy").assertHasDescendants("some/thing/SomeThingPluginFunctionalTest.groovy")

and:
commonJvmFilesGenerated(scriptDsl)

when:
executer.requireGradleDistribution() // TestKit and Kotlin DSL both require a distribution
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "plugin registers task")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "can run task")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
}
}
Expand Up @@ -20,12 +20,22 @@ import org.gradle.buildinit.plugins.fixtures.ScriptDslFixture
import org.gradle.buildinit.plugins.internal.modifiers.BuildInitTestFramework
import spock.lang.Unroll

import static org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl.GROOVY

class JavaApplicationInitIntegrationTest extends AbstractInitIntegrationSpec {

public static final String SAMPLE_APP_CLASS = "some/thing/App.java"
public static final String SAMPLE_APP_TEST_CLASS = "some/thing/AppTest.java"
public static final String SAMPLE_APP_SPOCK_TEST_CLASS = "some/thing/AppTest.groovy"

def "defaults to Groovy build scripts"() {
when:
run ('init', '--type', 'java-application')

then:
dslFixtureFor(GROOVY).assertGradleFilesGenerated()
}

@Unroll
def "creates sample source if no source present with #scriptDsl build scripts"() {
when:
Expand Down Expand Up @@ -100,9 +110,9 @@ class JavaApplicationInitIntegrationTest extends AbstractInitIntegrationSpec {
}

@Unroll
def "creates sample source using junitjupiter instead of junit with #scriptDsl build scripts"() {
def "creates sample source using junit-jupiter instead of junit with #scriptDsl build scripts"() {
when:
run('init', '--type', 'java-application', '--test-framework', 'junitjupiter', '--dsl', scriptDsl.id)
run('init', '--type', 'java-application', '--test-framework', 'junit-jupiter', '--dsl', scriptDsl.id)

then:
targetDir.file("src/main/java").assertHasDescendants(SAMPLE_APP_CLASS)
Expand Down
@@ -0,0 +1,48 @@
/*
* Copyright 2019 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
*
* 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.gradle.buildinit.plugins

import org.gradle.buildinit.plugins.fixtures.ScriptDslFixture
import spock.lang.Unroll


class JavaGradlePluginInitIntegrationTest extends AbstractInitIntegrationSpec {
@Unroll
def "creates sample source if no source present with #scriptDsl build scripts"() {
when:
run('init', '--type', 'java-gradle-plugin', '--dsl', scriptDsl.id)

then:
targetDir.file("src/main/java").assertHasDescendants("some/thing/SomeThingPlugin.java")
targetDir.file("src/test/java").assertHasDescendants("some/thing/SomeThingPluginTest.java")
targetDir.file("src/functionalTest/java").assertHasDescendants("some/thing/SomeThingPluginFunctionalTest.java")

and:
commonJvmFilesGenerated(scriptDsl)

when:
executer.requireGradleDistribution() // TestKit and Kotlin DSL both require a distribution
run("build")

then:
assertTestPassed("some.thing.SomeThingPluginTest", "pluginRegistersATask")
assertFunctionalTestPassed("some.thing.SomeThingPluginFunctionalTest", "canRunTask")

where:
scriptDsl << ScriptDslFixture.SCRIPT_DSLS
}
}
Expand Up @@ -20,6 +20,7 @@ import org.gradle.buildinit.plugins.fixtures.ScriptDslFixture
import org.gradle.buildinit.plugins.internal.modifiers.BuildInitTestFramework
import spock.lang.Unroll

import static org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl.GROOVY
import static org.hamcrest.Matchers.allOf

class JavaLibraryInitIntegrationTest extends AbstractInitIntegrationSpec {
Expand All @@ -28,6 +29,14 @@ class JavaLibraryInitIntegrationTest extends AbstractInitIntegrationSpec {
public static final String SAMPLE_LIBRARY_TEST_CLASS = "some/thing/LibraryTest.java"
public static final String SAMPLE_SPOCK_LIBRARY_TEST_CLASS = "some/thing/LibraryTest.groovy"

def "defaults to Groovy build scripts"() {
when:
run ('init', '--type', 'java-library')

then:
dslFixtureFor(GROOVY).assertGradleFilesGenerated()
}

@Unroll
def "creates sample source if no source present with #scriptDsl build scripts"() {
when:
Expand Down Expand Up @@ -102,9 +111,9 @@ class JavaLibraryInitIntegrationTest extends AbstractInitIntegrationSpec {
}

@Unroll
def "creates sample source using junitjupiter instead of junit with #scriptDsl build scripts"() {
def "creates sample source using junit-jupiter instead of junit with #scriptDsl build scripts"() {
when:
run('init', '--type', 'java-library', '--test-framework', 'junitjupiter', '--dsl', scriptDsl.id)
run('init', '--type', 'java-library', '--test-framework', 'junit-jupiter', '--dsl', scriptDsl.id)

then:
targetDir.file("src/main/java").assertHasDescendants(SAMPLE_LIBRARY_CLASS)
Expand Down