From fc652ea4049708809cd9a0b17bcbaa17b63d4752 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Fri, 5 May 2023 15:20:54 +0530 Subject: [PATCH 1/2] Inject classpath into test + use individual test projects --- build.gradle | 15 +++++++++ .../openjfx/gradle/JavaFXPluginSmokeTest.java | 31 +++++++++++++++---- test-project/build.gradle | 25 --------------- test-project/modular/build.gradle | 9 ++++++ test-project/modular/settings.gradle | 1 + test-project/non-modular/build.gradle | 9 ++++++ test-project/non-modular/settings.gradle | 1 + test-project/settings.gradle | 5 --- test-project/transitive/build.gradle | 9 ++++++ test-project/transitive/settings.gradle | 1 + 10 files changed, 70 insertions(+), 36 deletions(-) delete mode 100644 test-project/build.gradle create mode 100644 test-project/modular/settings.gradle create mode 100644 test-project/non-modular/settings.gradle delete mode 100644 test-project/settings.gradle create mode 100644 test-project/transitive/settings.gradle diff --git a/build.gradle b/build.gradle index 868243a..5738652 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,19 @@ repositories { } } +// Write the plugin's classpath to a file to share with the tests +task createClasspathManifest { + def outputDir = file("$buildDir/$name") + + inputs.files sourceSets.main.runtimeClasspath + outputs.dir outputDir + + doLast { + outputDir.mkdirs() + file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n") + } +} + dependencies { implementation gradleApi() @@ -34,6 +47,8 @@ dependencies { testImplementation gradleTestKit() testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2' + // Add the classpath file to the test runtime classpath + testRuntimeOnly files(createClasspathManifest) } test { diff --git a/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java b/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java index 277540c..f447cb1 100644 --- a/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java +++ b/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java @@ -34,6 +34,13 @@ import org.junit.jupiter.api.Test; import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -42,36 +49,48 @@ class JavaFXPluginSmokeTest { @Test void smokeTestModular() { var result = GradleRunner.create() - .withProjectDir(new File("test-project")) + .withProjectDir(new File("test-project/modular")) .withGradleVersion("6.0.1") .withArguments("clean", "build", "run", "--stacktrace", "--refresh-dependencies") + .withPluginClasspath(pluginClasspath()) .forwardOutput() .build(); - assertEquals(TaskOutcome.SUCCESS, result.task(":modular:run").getOutcome(), "Failed build!"); + assertEquals(TaskOutcome.SUCCESS, result.task(":run").getOutcome(), "Failed build!"); } @Test void smokeTestNonModular() { var result = GradleRunner.create() - .withProjectDir(new File("test-project")) + .withProjectDir(new File("test-project/non-modular")) .withGradleVersion("6.0.1") .withArguments("clean", "build", "run", "--stacktrace", "--refresh-dependencies") + .withPluginClasspath(pluginClasspath()) .forwardOutput() .build(); - assertEquals(TaskOutcome.SUCCESS, result.task(":non-modular:run").getOutcome(), "Failed build!"); + assertEquals(TaskOutcome.SUCCESS, result.task(":run").getOutcome(), "Failed build!"); } @Test void smokeTestTransitive() { var result = GradleRunner.create() - .withProjectDir(new File("test-project")) + .withProjectDir(new File("test-project/transitive")) .withGradleVersion("6.0.1") .withArguments("clean", "build", "run", "--stacktrace", "--refresh-dependencies") + .withPluginClasspath(pluginClasspath()) .forwardOutput() .build(); - assertEquals(TaskOutcome.SUCCESS, result.task(":transitive:run").getOutcome(), "Failed build!"); + assertEquals(TaskOutcome.SUCCESS, result.task(":run").getOutcome(), "Failed build!"); + } + + private List pluginClasspath() { + try { + var pluginClasspathResource = Objects.requireNonNull(getClass().getResource("../../../../createClasspathManifest/plugin-classpath.txt")).toURI(); + return Files.readAllLines(Paths.get(pluginClasspathResource)).stream().map(File::new).collect(Collectors.toList()); + } catch (IOException | URISyntaxException e) { + throw new RuntimeException(e); + } } } diff --git a/test-project/build.gradle b/test-project/build.gradle deleted file mode 100644 index 459ec63..0000000 --- a/test-project/build.gradle +++ /dev/null @@ -1,25 +0,0 @@ -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - maven { - url 'https://oss.sonatype.org/content/repositories/snapshots/' - } - } - dependencies { - classpath "org.openjfx:javafx-plugin:0.0.+" - } -} - -subprojects { - apply plugin: 'application' - apply plugin: 'org.openjfx.javafxplugin' - - sourceCompatibility = 11 - targetCompatibility = 11 - - repositories { - mavenCentral() - } -} \ No newline at end of file diff --git a/test-project/modular/build.gradle b/test-project/modular/build.gradle index 3dfee46..1b1326c 100644 --- a/test-project/modular/build.gradle +++ b/test-project/modular/build.gradle @@ -1,3 +1,12 @@ +plugins { + id 'application' + id 'org.openjfx.javafxplugin' +} + +repositories { + mavenCentral() +} + mainClassName = 'org.openjfx.gradle.javafx.test/org.openjfx.gradle.javafx.test.Main' javafx { diff --git a/test-project/modular/settings.gradle b/test-project/modular/settings.gradle new file mode 100644 index 0000000..24d738d --- /dev/null +++ b/test-project/modular/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'modular' diff --git a/test-project/non-modular/build.gradle b/test-project/non-modular/build.gradle index cef1ed9..5a372c7 100644 --- a/test-project/non-modular/build.gradle +++ b/test-project/non-modular/build.gradle @@ -1,3 +1,12 @@ +plugins { + id 'application' + id 'org.openjfx.javafxplugin' +} + +repositories { + mavenCentral() +} + mainClassName = 'org.openjfx.gradle.javafx.test.Main' javafx { diff --git a/test-project/non-modular/settings.gradle b/test-project/non-modular/settings.gradle new file mode 100644 index 0000000..1774b1f --- /dev/null +++ b/test-project/non-modular/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'non-modular' diff --git a/test-project/settings.gradle b/test-project/settings.gradle deleted file mode 100644 index 96a142a..0000000 --- a/test-project/settings.gradle +++ /dev/null @@ -1,5 +0,0 @@ -rootProject.name = 'javafxplugintests' - -include 'modular' -include 'non-modular' -include 'transitive' \ No newline at end of file diff --git a/test-project/transitive/build.gradle b/test-project/transitive/build.gradle index 4991c60..e54d14d 100644 --- a/test-project/transitive/build.gradle +++ b/test-project/transitive/build.gradle @@ -1,3 +1,12 @@ +plugins { + id 'application' + id 'org.openjfx.javafxplugin' +} + +repositories { + mavenCentral() +} + mainClassName = 'org.openjfx.gradle.javafx.test.Main' javafx { diff --git a/test-project/transitive/settings.gradle b/test-project/transitive/settings.gradle new file mode 100644 index 0000000..68eae4c --- /dev/null +++ b/test-project/transitive/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'transitive' From 086a4678490e3a4077eaa85c31fd2e8bf28542db Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Tue, 23 May 2023 19:01:22 +0530 Subject: [PATCH 2/2] initialize pluginClasspath just once --- .../openjfx/gradle/JavaFXPluginSmokeTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java b/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java index f447cb1..b7cd1ae 100644 --- a/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java +++ b/src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java @@ -31,7 +31,9 @@ import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import java.io.File; import java.io.IOException; @@ -44,15 +46,23 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class JavaFXPluginSmokeTest { + private List pluginClasspath; + + @BeforeAll + public void setup() { + pluginClasspath = pluginClasspath(); + } + @Test void smokeTestModular() { var result = GradleRunner.create() .withProjectDir(new File("test-project/modular")) .withGradleVersion("6.0.1") .withArguments("clean", "build", "run", "--stacktrace", "--refresh-dependencies") - .withPluginClasspath(pluginClasspath()) + .withPluginClasspath(pluginClasspath) .forwardOutput() .build(); @@ -65,7 +75,7 @@ void smokeTestNonModular() { .withProjectDir(new File("test-project/non-modular")) .withGradleVersion("6.0.1") .withArguments("clean", "build", "run", "--stacktrace", "--refresh-dependencies") - .withPluginClasspath(pluginClasspath()) + .withPluginClasspath(pluginClasspath) .forwardOutput() .build(); @@ -78,7 +88,7 @@ void smokeTestTransitive() { .withProjectDir(new File("test-project/transitive")) .withGradleVersion("6.0.1") .withArguments("clean", "build", "run", "--stacktrace", "--refresh-dependencies") - .withPluginClasspath(pluginClasspath()) + .withPluginClasspath(pluginClasspath) .forwardOutput() .build();