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

Inject classpath into test + use individual test projects #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down
41 changes: 35 additions & 6 deletions src/test/java/org/openjfx/gradle/JavaFXPluginSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,76 @@

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;
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;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class JavaFXPluginSmokeTest {

private List<File> pluginClasspath;

@BeforeAll
public void setup() {
pluginClasspath = pluginClasspath();
}

@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<File> pluginClasspath() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are reading it three times, while it could probably be done in one previous setup single step?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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);
}
}
}
25 changes: 0 additions & 25 deletions test-project/build.gradle

This file was deleted.

9 changes: 9 additions & 0 deletions test-project/modular/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
plugins {
id 'application'
id 'org.openjfx.javafxplugin'
}

abhinayagarwal marked this conversation as resolved.
Show resolved Hide resolved
repositories {
mavenCentral()
}

mainClassName = 'org.openjfx.gradle.javafx.test/org.openjfx.gradle.javafx.test.Main'

javafx {
Expand Down
1 change: 1 addition & 0 deletions test-project/modular/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'modular'
9 changes: 9 additions & 0 deletions test-project/non-modular/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
plugins {
id 'application'
id 'org.openjfx.javafxplugin'
}

repositories {
mavenCentral()
}

mainClassName = 'org.openjfx.gradle.javafx.test.Main'

javafx {
Expand Down
1 change: 1 addition & 0 deletions test-project/non-modular/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'non-modular'
5 changes: 0 additions & 5 deletions test-project/settings.gradle

This file was deleted.

9 changes: 9 additions & 0 deletions test-project/transitive/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
plugins {
id 'application'
id 'org.openjfx.javafxplugin'
}

repositories {
mavenCentral()
}

mainClassName = 'org.openjfx.gradle.javafx.test.Main'

javafx {
Expand Down
1 change: 1 addition & 0 deletions test-project/transitive/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'transitive'