Skip to content

Commit

Permalink
Add cross-version coverage for PlayIdeaPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
big-guy committed May 11, 2021
1 parent f19f2cf commit 53a3552
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import spock.lang.Unroll
* In-depth testing of user guide samples.
*/
abstract class InDepthUserGuideSamplesIntegrationTest extends Specification {
protected static final String[] VERSIONS_UNDER_TEST = ["5.1.1", "5.2.1", "5.5.1", "5.6.4", "6.0.1", "6.6.1"]
protected static final String[] VERSIONS_UNDER_TEST = ["5.1.1", "5.2.1", "5.5.1", "5.6.4", "6.0.1", "6.6.1", "7.0.1"]

@Rule
Sample sample = Sample.from("src/docs/samples")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package org.gradle.playframework

import org.gradle.playframework.fixtures.test.JUnitXmlTestExecutionResult
import org.gradle.playframework.fixtures.test.TestExecutionResult
import org.gradle.samples.test.rule.UsesSample
import spock.lang.Unroll

@Unroll
class MiscUserGuideIntegrationTest extends InDepthUserGuideSamplesIntegrationTest {
@UsesSample("basic/groovy")
def "basic sample is buildable #gradleVersion"(String gradleVersion) {
setupRunner(gradleVersion)
new File(sample.dir, "build.gradle") << """
apply plugin: "org.gradle.playframework-ide"
apply plugin: "idea"
"""

expect:
build("idea")

where:
gradleVersion << VERSIONS_UNDER_TEST
}

@UsesSample("source-sets/groovy")
def "source-sets sample is buildable #gradleVersion"(String gradleVersion) {
setupRunner(gradleVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.gradle.playframework.application
import org.gradle.playframework.fixtures.ide.IdeaModuleFixture
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Ignore

import static org.gradle.playframework.fixtures.ide.IdeaFixtures.parseIml
import static org.gradle.playframework.fixtures.ide.IdeaFixtures.parseIpr
Expand Down Expand Up @@ -51,39 +50,6 @@ abstract class PlayIdeaPluginIntegrationTest extends PlayIdePluginIntegrationTes
content.assertContainsExcludes("build", ".gradle")
}

@Ignore
def "IDEA metadata contains correct Scala version"() {
applyIdePlugin()
buildFile << """
allprojects {
pluginManager.withPlugin("org.gradle.playframework") {
tasks.idea {
doLast {
assert ideaModule.module.scalaPlatform.getScalaCompatibilityVersion() == play.platform.scalaVersion.get()
println "Validated Scala Version"
}
}
}
}
"""
when:
BuildResult result = build(ideTask)
then:
result.output.contains("Validated Scala Version")

parseIml(moduleFile).dependencies.dependencies.any {
if (it instanceof IdeaModuleFixture.ImlLibrary) {
return it.name.startsWith("scala-sdk") && it.level == "project"
}
false
}

def libraryTable = parseIpr(projectFile).libraryTable
def scalaSdk = libraryTable.library.find { it.@name.toString().startsWith("scala-sdk") && it.@type == "Scala" }
def scalaClasspath = scalaSdk.properties."compiler-classpath".root."@url"
scalaClasspath.size() == expectedScalaClasspathSize
}

def "IDEA metadata contains correct Java version"() {
applyIdePlugin()
buildFile << """
Expand Down
35 changes: 4 additions & 31 deletions src/main/java/org/gradle/playframework/plugins/PlayIdeaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public void apply(Project project) {
ConventionMapping conventionMapping = conventionMappingFor(module);

TaskProvider<JavaScriptMinify> javaScriptMinifyTask = project.getTasks().named(PlayJavaScriptPlugin.JS_MINIFY_TASK_NAME, JavaScriptMinify.class);
TaskProvider<RoutesCompile> routesCompileTask =
project.getTasks().named(PlayRoutesPlugin.ROUTES_COMPILE_TASK_NAME, RoutesCompile.class);
TaskProvider<TwirlCompile> twirlCompileTask =
project.getTasks().named(PlayTwirlPlugin.TWIRL_COMPILE_TASK_NAME, TwirlCompile.class);

conventionMapping.map("sourceDirs", (Callable<Set<File>>) () -> {
// TODO: Assets should probably be a source set too
Expand All @@ -57,44 +53,21 @@ public void apply(Project project) {
return sourceDirs;
});

conventionMapping.map("singleEntryLibraries", (Callable<Map<String, Iterable<File>>>) () -> {
SourceSet mainSourceSet = getMainJavaSourceSet(project);
SourceSet testSourceSet = getTestJavaSourceSet(project);

Map<String, Iterable<File>> libs = new HashMap<>();
libs.put("COMPILE", mainSourceSet.getOutput().getClassesDirs());
libs.put("RUNTIME", Collections.singleton(mainSourceSet.getOutput().getResourcesDir()));
libs.put("TEST", testSourceSet.getOutput().getClassesDirs());
return Collections.unmodifiableMap(libs);
});

PlayExtension playExtension = (PlayExtension) project.getExtensions().getByName(PLAY_EXTENSION_NAME);
module.setScalaPlatform(new DefaultScalaPlatform(playExtension.getPlatform().getScalaVersion().get()));

conventionMapping.map("targetBytecodeVersion", (Callable<JavaVersion>) () -> getTargetJavaVersion(playExtension.getPlatform()));
conventionMapping.map("languageLevel", (Callable<IdeaLanguageLevel>) () -> new IdeaLanguageLevel(getTargetJavaVersion(playExtension.getPlatform())));

module.getIml().withXml(xml -> {
NodeList sourceFolders = xml.asNode().getAt(QName.valueOf("component")).getAt(QName.valueOf("content")).getAt(QName.valueOf("sourceFolder"));
sourceFolders.forEach(sourceFolder -> {
Node node = (Node) sourceFolder;
if (node.get("@url").equals("file://$MODULE_DIR$/conf")) {
node.attributes().put("type", "java-resource");
}
});
});

ideaModuleTask.dependsOn(javaScriptMinifyTask);
ideaModuleTask.dependsOn(routesCompileTask);
ideaModuleTask.dependsOn(twirlCompileTask);
ideaModuleTask.dependsOn(project.getTasks().withType(TwirlCompile.class));
ideaModuleTask.dependsOn(project.getTasks().withType(RoutesCompile.class));
});
}

private ConventionMapping conventionMappingFor(IdeaModule module) {
return new DslObject(module).getConventionMapping();
}

private JavaVersion getTargetJavaVersion(PlayPlatform Platform) {
return Platform.getJavaVersion().get();
private JavaVersion getTargetJavaVersion(PlayPlatform platform) {
return platform.getJavaVersion().get();
}
}

0 comments on commit 53a3552

Please sign in to comment.