Skip to content

Commit

Permalink
feat!: backport changes from branch 8.0-jdk17
Browse files Browse the repository at this point in the history
  • Loading branch information
v1nc3n4 committed Aug 23, 2023
1 parent 5a5b832 commit 1304336
Show file tree
Hide file tree
Showing 53 changed files with 452 additions and 806 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ With their feedback, plugin improvement is possible. Special thanks to:
@[joschi](https://github.com/joschi),
@[jorgheymans](https://github.com/jorgheymans),
@[ludik0](https://github.com/ludik0),
@[mhalbritter](https://github.com/mhalbritter),
@[mike-howell](https://github.com/mike-howell),
@[napstr](https://github.com/napstr),
@[nitzan-n](https://github.com/nitzan-n),
Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ tasks.named<Wrapper>("wrapper") {

tasks.withType<Test> {
useJUnitPlatform()
outputs.upToDateWhen { false }
jvmArgs(
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"
)
outputs.upToDateWhen { false }
}

tasks.register<Test>("integrationTest") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,27 @@ void setUp() throws IOException {
}

@Test
void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"))
.assembleScript("run assemble")
.packageJsonDirectory(packageJsonDirectoryPath);
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.ASSEMBLE_TASK_NAME);

assertAssembleTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand All @@ -56,7 +76,7 @@ void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
}

@Test
void should_skip_plugin_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), packageJsonDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@
* distributions, to avoid the download overhead. The 'yarn' and 'npm' executables in these distributions simply call
* the 'node' executable with the same arguments.
*/
class CheckTaskFuncTest {
class CheckFrontendTaskFuncTest {

@TempDir
Path projectDirectoryPath;

@Test
void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"))
.checkScript("run check");
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CHECK_TASK_NAME);

assertCheckTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CHECK_TASK_NAME);

assertCheckTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand All @@ -47,7 +66,7 @@ void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
}

@Test
void should_skip_plugin_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@
* distributions, to avoid the download overhead. The 'yarn' and 'npm' executables in these distributions simply call
* the 'node' executable with the same arguments.
*/
class CleanTaskFuncTest {
class CleanFrontendTaskFuncTest {

@TempDir
Path projectDirectoryPath;

@Test
void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"))
.cleanScript("run clean");
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CLEAN_TASK_NAME);

assertCleanTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.CLEAN_TASK_NAME);

assertCleanTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED, null);
}

@Test
void should_skip_task_when_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand All @@ -47,7 +66,7 @@ void should_skip_plugin_task_when_script_is_not_defined() throws IOException {
}

@Test
void should_skip_plugin_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
void should_skip_task_when_running_gradle_task_and_script_is_not_defined() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ class InstallFrontendTaskFuncTest {
@TempDir
Path projectDirectoryPath;

@Test
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"));
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath, FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME);

assertTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED);

final BuildResult result2 = runGradle(projectDirectoryPath, FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME);

assertTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED,
PluginTaskOutcome.SKIPPED);
}

@Test
void should_succeed_with_default_script() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.siouan.frontendgradleplugin.test.GradleBuildAssertions.assertTaskOutcomes;
import static org.siouan.frontendgradleplugin.test.GradleBuildFiles.createBuildFile;
import static org.siouan.frontendgradleplugin.test.GradleHelper.runGradle;
import static org.siouan.frontendgradleplugin.test.GradleHelper.runGradleAndExpectFailure;
import static org.siouan.frontendgradleplugin.test.Resources.getResourcePath;
import static org.siouan.frontendgradleplugin.test.Resources.getResourceUrl;

Expand All @@ -28,6 +29,35 @@ class InstallPackageManagerTaskFuncTest {
@TempDir
Path projectDirectoryPath;

@Test
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder()
.nodeVersion("18.17.1")
.nodeDistributionUrl(getResourceUrl("node-v18.17.1.zip"));
createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap());

final BuildResult result1 = runGradle(projectDirectoryPath,
FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME);

assertTaskOutcomes(result1, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED);

final BuildResult result2 = runGradle(projectDirectoryPath,
FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME);

assertTaskOutcomes(result2, PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SKIPPED);
}

@Test
void should_fail_when_node_install_directory_is_not_a_directory() throws IOException {
Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json"));
createBuildFile(projectDirectoryPath, new FrontendMapBuilder().nodeDistributionProvided(true).toMap());

final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath,
FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME);

assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.FAILED);
}

@Test
void should_install_package_managers() throws IOException {
Files.copy(getResourcePath("package-npm.json"), projectDirectoryPath.resolve("package.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ResolvePackageManagerTaskFuncTest {
Path projectDirectoryPath;

@Test
void should_be_skipped_when_package_json_file_is_not_readable() throws IOException {
void should_skip_task_when_package_json_file_is_not_a_file() throws IOException {
Files.createDirectory(projectDirectoryPath.resolve(FrontendGradlePlugin.PACKAGE_JSON_FILE_NAME));
createBuildFile(projectDirectoryPath, new FrontendMapBuilder().nodeDistributionProvided(true).toMap());

final BuildResult result = runGradle(projectDirectoryPath,
Expand All @@ -50,7 +51,10 @@ void should_be_skipped_when_package_json_file_is_not_readable() throws IOExcepti
@Test
void should_fail_when_package_manager_property_is_not_set_in_package_json_file() throws IOException {
Files.copy(getResourcePath("package-no-manager.json"), projectDirectoryPath.resolve("package.json"));
createBuildFile(projectDirectoryPath, new FrontendMapBuilder().nodeDistributionProvided(true).toMap());
createBuildFile(projectDirectoryPath, new FrontendMapBuilder()
.nodeDistributionProvided(true)
.nodeInstallDirectory(getResourcePath("node-dist-provided"))
.toMap());

final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath,
FrontendGradlePlugin.RESOLVE_PACKAGE_MANAGER_TASK_NAME);
Expand All @@ -67,8 +71,10 @@ void should_fail_when_package_manager_property_is_not_set_in_package_json_file()
@Test
void should_fail_when_package_manager_property_is_invalid_in_package_json_file() throws IOException {
Files.copy(getResourcePath("package-invalid-manager.json"), projectDirectoryPath.resolve("package.json"));
createBuildFile(projectDirectoryPath,
new FrontendMapBuilder().nodeDistributionProvided(true).nodeDistributionProvided(true).toMap());
createBuildFile(projectDirectoryPath, new FrontendMapBuilder()
.nodeDistributionProvided(true)
.nodeInstallDirectory(getResourcePath("node-dist-provided"))
.toMap());

final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath,
FrontendGradlePlugin.RESOLVE_PACKAGE_MANAGER_TASK_NAME);
Expand Down
Loading

0 comments on commit 1304336

Please sign in to comment.