diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTaskFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTaskFuncTest.java index 35010779..7e66db15 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTaskFuncTest.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTaskFuncTest.java @@ -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") @@ -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") diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTaskFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckFrontendTaskFuncTest.java similarity index 78% rename from plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTaskFuncTest.java rename to plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckFrontendTaskFuncTest.java index c9c9da34..56ada41d 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTaskFuncTest.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckFrontendTaskFuncTest.java @@ -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") @@ -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") diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTaskFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanFrontendTaskFuncTest.java similarity index 78% rename from plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTaskFuncTest.java rename to plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanFrontendTaskFuncTest.java index f0442ae8..3173bb85 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTaskFuncTest.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanFrontendTaskFuncTest.java @@ -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") @@ -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") diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallFrontendTaskFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallFrontendTaskFuncTest.java index 880c9319..68553f11 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallFrontendTaskFuncTest.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallFrontendTaskFuncTest.java @@ -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")); diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallPackageManagerTaskFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallPackageManagerTaskFuncTest.java index 63770a4c..30cd8924 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallPackageManagerTaskFuncTest.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallPackageManagerTaskFuncTest.java @@ -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; @@ -28,6 +29,42 @@ 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_corepack_executable_is_not_a_file() throws IOException { + // The fact that the corepack executable is not present is enough to simulate the following use cases: + // - The Node.js distribution is already provided, but the install directory was not set accordingly. + // - The Node.js distribution is already provided, but the install directory contains a non-supported release. + // - The Node.js distribution was downloaded but is a non-supported release. + // - The Node.js distribution was downloaded but was corrupted later so as the corepack executable is not + // present anymore. + Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json")); + Files.createDirectory(projectDirectoryPath.resolve(FrontendGradlePlugin.DEFAULT_NODE_INSTALL_DIRECTORY_NAME)); + 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")); diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolvePackageManagerTaskFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolvePackageManagerTaskFuncTest.java index 537f5438..841ffd59 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolvePackageManagerTaskFuncTest.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolvePackageManagerTaskFuncTest.java @@ -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, @@ -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); @@ -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); diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskTypesWithGlobalDistributionsFuncTest.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskTypesWithGlobalDistributionsFuncTest.java deleted file mode 100644 index bf6c986f..00000000 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskTypesWithGlobalDistributionsFuncTest.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.siouan.frontendgradleplugin.infrastructure.gradle; - -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.TaskTypes.buildCorepackTaskDefinition; -import static org.siouan.frontendgradleplugin.test.TaskTypes.buildNodeTaskDefinition; -import static org.siouan.frontendgradleplugin.test.TaskTypes.buildNpmTaskDefinition; -import static org.siouan.frontendgradleplugin.test.TaskTypes.buildPnpmTaskDefinition; -import static org.siouan.frontendgradleplugin.test.TaskTypes.buildYarnTaskDefinition; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import org.siouan.frontendgradleplugin.FrontendGradlePlugin; -import org.siouan.frontendgradleplugin.test.FrontendMapBuilder; -import org.siouan.frontendgradleplugin.test.PluginTaskOutcome; - -/** - * Functional tests to verify task types {@link RunNode}, {@link RunNpm}, {@link RunYarn} in a Gradle build, with a - * Node.js distribution resolved with the {@link FrontendGradlePlugin#NODEJS_HOME_ENV_VAR} environment variable. Test - * cases uses a fake Node.js distribution, to avoid the download overhead. The 'npm' and 'npx' executables in these - * distributions simply call the 'node' executable with the same arguments. - */ -class TaskTypesWithGlobalDistributionsFuncTest { - - private static final String RUN_COREPACK_TASK_NAME = "customCorepackTask"; - - private static final String RUN_NODE_TASK_NAME = "customNodeTask"; - - private static final String RUN_NPM_TASK_NAME = "customNpmTask"; - - private static final String RUN_PNPM_TASK_NAME = "customPnpmTask"; - - private static final String RUN_YARN_TASK_NAME = "customYarnTask"; - - @TempDir - Path temporaryDirectoryPath; - - private Path projectDirectoryPath; - - private Path temporaryScriptPath; - - @BeforeEach - void setUp() { - projectDirectoryPath = temporaryDirectoryPath; - temporaryScriptPath = temporaryDirectoryPath.resolve("script.js"); - } - - @Test - void should_fail_running_custom_corepack_task_when_node_executable_does_not_exist() throws IOException { - final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder() - .nodeDistributionProvided(true) - .verboseModeEnabled(true); - final String runCorepackTaskDefinition = buildCorepackTaskDefinition(RUN_COREPACK_TASK_NAME, - FrontendGradlePlugin.INSTALL_NODE_TASK_NAME, "disable"); - createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap(), runCorepackTaskDefinition); - final Path nodejsHomePath = getResourcePath("node-dist-without-node"); - - final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath, nodejsHomePath, - RUN_COREPACK_TASK_NAME); - - assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, RUN_COREPACK_TASK_NAME, PluginTaskOutcome.FAILED); - } - - @Test - void should_fail_running_custom_node_task_when_node_executable_does_not_exist() throws IOException { - final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder().nodeDistributionProvided(true); - final String runNodeTaskDefinition = buildNodeTaskDefinition(RUN_NODE_TASK_NAME, - temporaryScriptPath.toString().replace("\\", "\\\\")); - createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap(), runNodeTaskDefinition); - final Path nodejsHomePath = getResourcePath("node-dist-without-node"); - - final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath, nodejsHomePath, RUN_NODE_TASK_NAME); - - assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, RUN_NODE_TASK_NAME, PluginTaskOutcome.FAILED); - } - - @Test - void should_fail_running_custom_npm_task_when_node_executable_does_not_exist() throws IOException { - Files.copy(getResourcePath("package-npm.json"), projectDirectoryPath.resolve("package.json")); - final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder().nodeDistributionProvided(true); - final String runNpmTaskDefinition = buildNpmTaskDefinition(RUN_NPM_TASK_NAME, - FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME, "run npm-script"); - createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap(), runNpmTaskDefinition); - final Path nodejsHomePath = getResourcePath("node-dist-without-node"); - - final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath, nodejsHomePath, RUN_NPM_TASK_NAME); - - assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.FAILED, - RUN_NPM_TASK_NAME, PluginTaskOutcome.IGNORED); - } - - @Test - void should_fail_running_custom_pnpm_task_when_node_executable_does_not_exist() throws IOException { - Files.copy(getResourcePath("package-pnpm.json"), projectDirectoryPath.resolve("package.json")); - final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder().nodeDistributionProvided(true); - final String runNpmTaskDefinition = buildPnpmTaskDefinition(RUN_PNPM_TASK_NAME, - FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME, "run pnpm-script"); - createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap(), runNpmTaskDefinition); - final Path nodejsHomePath = getResourcePath("node-dist-without-node"); - - final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath, nodejsHomePath, RUN_PNPM_TASK_NAME); - - assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.FAILED, - RUN_PNPM_TASK_NAME, PluginTaskOutcome.IGNORED); - } - - @Test - void should_fail_running_custom_yarn_task_when_node_executable_does_not_exist() throws IOException { - Files.copy(getResourcePath("package-yarn.json"), projectDirectoryPath.resolve("package.json")); - final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder().nodeDistributionProvided(true); - final String runNpmTaskDefinition = buildYarnTaskDefinition(RUN_YARN_TASK_NAME, - FrontendGradlePlugin.INSTALL_PACKAGE_MANAGER_TASK_NAME, "run yarn-script"); - createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap(), runNpmTaskDefinition); - final Path nodejsHomePath = getResourcePath("node-dist-without-node"); - - final BuildResult result = runGradleAndExpectFailure(projectDirectoryPath, nodejsHomePath, RUN_YARN_TASK_NAME); - - assertTaskOutcomes(result, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SUCCESS, PluginTaskOutcome.FAILED, - RUN_YARN_TASK_NAME, PluginTaskOutcome.IGNORED); - } - - @Test - void should_run_custom_tasks() throws IOException { - Files.copy(getResourcePath("package-any-manager.json"), projectDirectoryPath.resolve("package.json")); - final FrontendMapBuilder frontendMapBuilder = new FrontendMapBuilder().nodeDistributionProvided(true); - final String runNodeTaskDefinition = buildNodeTaskDefinition(RUN_NODE_TASK_NAME, - temporaryScriptPath.toString().replace("\\", "\\\\")); - final String runCorepackTaskDefinition = buildCorepackTaskDefinition(RUN_COREPACK_TASK_NAME, - FrontendGradlePlugin.INSTALL_NODE_TASK_NAME, "disable"); - final String runNpmTaskDefinition = buildNpmTaskDefinition(RUN_NPM_TASK_NAME, - FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME, "run npm-script"); - final String runPnpmTaskDefinition = buildPnpmTaskDefinition(RUN_PNPM_TASK_NAME, - FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME, "run pnpm-script"); - final String runYarnTaskDefinition = buildYarnTaskDefinition(RUN_YARN_TASK_NAME, - FrontendGradlePlugin.INSTALL_FRONTEND_TASK_NAME, "run yarn-script"); - final String additionalContent = String.join("\n", runNodeTaskDefinition, runCorepackTaskDefinition, - runNpmTaskDefinition, runPnpmTaskDefinition, runYarnTaskDefinition); - createBuildFile(projectDirectoryPath, frontendMapBuilder.toMap(), additionalContent); - final Path nodejsHomePath = getResourcePath("node-dist-provided"); - - final BuildResult nodeTaskResult = runGradle(projectDirectoryPath, nodejsHomePath, RUN_NODE_TASK_NAME); - - assertTaskOutcomes(nodeTaskResult, PluginTaskOutcome.SKIPPED, RUN_NODE_TASK_NAME, PluginTaskOutcome.SUCCESS); - - final BuildResult corepackTaskResult = runGradle(projectDirectoryPath, nodejsHomePath, RUN_COREPACK_TASK_NAME); - - assertTaskOutcomes(corepackTaskResult, PluginTaskOutcome.SKIPPED, RUN_COREPACK_TASK_NAME, - PluginTaskOutcome.SUCCESS); - - final BuildResult npmTaskResult = runGradle(projectDirectoryPath, nodejsHomePath, RUN_NPM_TASK_NAME); - - assertTaskOutcomes(npmTaskResult, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.SUCCESS, - PluginTaskOutcome.SUCCESS, PluginTaskOutcome.SUCCESS, RUN_NPM_TASK_NAME, PluginTaskOutcome.SUCCESS); - - final BuildResult pnpmTaskResult = runGradle(projectDirectoryPath, nodejsHomePath, RUN_PNPM_TASK_NAME); - - assertTaskOutcomes(pnpmTaskResult, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.UP_TO_DATE, - PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SUCCESS, RUN_PNPM_TASK_NAME, PluginTaskOutcome.SUCCESS); - - final BuildResult yarnTaskResult = runGradle(projectDirectoryPath, nodejsHomePath, RUN_YARN_TASK_NAME); - - assertTaskOutcomes(yarnTaskResult, PluginTaskOutcome.SKIPPED, PluginTaskOutcome.UP_TO_DATE, - PluginTaskOutcome.UP_TO_DATE, PluginTaskOutcome.SUCCESS, RUN_YARN_TASK_NAME, PluginTaskOutcome.SUCCESS); - } -} diff --git a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/test/GradleHelper.java b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/test/GradleHelper.java index 8c6d0ed5..28f92a76 100644 --- a/plugin/src/intTest/java/org/siouan/frontendgradleplugin/test/GradleHelper.java +++ b/plugin/src/intTest/java/org/siouan/frontendgradleplugin/test/GradleHelper.java @@ -4,15 +4,12 @@ import java.nio.file.Path; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import org.gradle.api.logging.LogLevel; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; -import org.siouan.frontendgradleplugin.FrontendGradlePlugin; /** * Helper to prepare and run Gradle builds. @@ -34,17 +31,6 @@ public static BuildResult runGradle(final Path projectDirectory, final String... return runGradle(projectDirectory, LogLevel.LIFECYCLE, additionalArguments); } - /** - * Runs a Gradle task in the given project directory, and expects a success. - * - * @param projectDirectory Project directory. - * @return The build result. - */ - public static BuildResult runGradle(final Path projectDirectory, final Path nodejsHomePath, - final String... additionalArguments) { - return runGradle(projectDirectory, LogLevel.LIFECYCLE, nodejsHomePath, additionalArguments); - } - /** * Runs a Gradle task in the given project directory, and expects a success. * @@ -53,18 +39,7 @@ public static BuildResult runGradle(final Path projectDirectory, final Path node */ public static BuildResult runGradle(final Path projectDirectory, final LogLevel loggingLevel, final String... additionalArguments) { - return runGradle(projectDirectory, loggingLevel, null, additionalArguments); - } - - /** - * Runs a Gradle task in the given project directory, and expects a success. - * - * @param projectDirectory Project directory. - * @return The build result. - */ - public static BuildResult runGradle(final Path projectDirectory, final LogLevel loggingLevel, - final Path nodejsHomePath, final String... additionalArguments) { - return createGradleRunner(projectDirectory, loggingLevel, nodejsHomePath, additionalArguments).build(); + return createGradleRunner(projectDirectory, loggingLevel, additionalArguments).build(); } /** @@ -86,29 +61,7 @@ public static BuildResult runGradleAndExpectFailure(final Path projectDirectory, */ public static BuildResult runGradleAndExpectFailure(final Path projectDirectory, final LogLevel loggingLevel, final String... additionalArguments) { - return runGradleAndExpectFailure(projectDirectory, loggingLevel, null, additionalArguments); - } - - /** - * Runs a Gradle task in the given project directory, and expects a failure. - * - * @param projectDirectory Project directory. - * @return The build result. - */ - public static BuildResult runGradleAndExpectFailure(final Path projectDirectory, final Path nodejsHomePath, - final String... additionalArguments) { - return runGradleAndExpectFailure(projectDirectory, LogLevel.LIFECYCLE, nodejsHomePath, additionalArguments); - } - - /** - * Runs a Gradle task in the given project directory, and expects a failure. - * - * @param projectDirectory Project directory. - * @return The build result. - */ - public static BuildResult runGradleAndExpectFailure(final Path projectDirectory, final LogLevel loggingLevel, - final Path nodejsHomePath, final String... additionalArguments) { - return createGradleRunner(projectDirectory, loggingLevel, nodejsHomePath, additionalArguments).buildAndFail(); + return createGradleRunner(projectDirectory, loggingLevel, additionalArguments).buildAndFail(); } /** @@ -116,61 +69,34 @@ public static BuildResult runGradleAndExpectFailure(final Path projectDirectory, * * @param projectDirectory Project directory. * @param loggingLevel Gradle logging level. - * @param nodejsHomePath Optional path to set the {@link FrontendGradlePlugin#NODEJS_HOME_ENV_VAR} environment - * variable. * @return The Gradle runner. */ private static GradleRunner createGradleRunner(final Path projectDirectory, final LogLevel loggingLevel, - final Path nodejsHomePath, final String... additionalArguments) { + final String... additionalArguments) { final List arguments = new ArrayList<>(); arguments.add("-s"); arguments.add("--warning-mode=all"); toLoggingLevelProperty(loggingLevel).ifPresent(arguments::add); arguments.addAll(asList(additionalArguments)); - final Map originalEnvironment = System.getenv(); - final Map additionalEnvironment = new HashMap<>(); - if (nodejsHomePath != null) { - additionalEnvironment.put(FrontendGradlePlugin.NODEJS_HOME_ENV_VAR, nodejsHomePath.toString()); - } - final GradleRunner gradleRunner = GradleRunner + return GradleRunner .create() .withGradleVersion(MINIMAL_GRADLE_VERSION) .withProjectDir(projectDirectory.toFile()) .withPluginClasspath() .withArguments(arguments) - .withDebug(additionalEnvironment.isEmpty()) + .withDebug(true) .forwardOutput(); - if (!additionalEnvironment.isEmpty()) { - final Map testEnvironment = new HashMap<>(originalEnvironment); - testEnvironment.putAll(additionalEnvironment); - gradleRunner.withEnvironment(Map.copyOf(testEnvironment)); - } - return gradleRunner; } private static Optional toLoggingLevelProperty(final LogLevel loggingLevel) { - final String property; - switch (loggingLevel) { - case DEBUG: - property = "-d"; - break; - case INFO: - property = "-i"; - break; - case WARN: - property = "-w"; - break; - case ERROR: - property = "-e"; - break; - case QUIET: - property = "-q"; - break; - case LIFECYCLE: - default: - property = null; - break; - } + final String property = switch (loggingLevel) { + case DEBUG -> "-d"; + case INFO -> "-i"; + case WARN -> "-w"; + case ERROR -> "-e"; + case QUIET -> "-q"; + default -> null; + }; return Optional.ofNullable(property); } } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java index 6465ce47..369e43ca 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java @@ -12,21 +12,20 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; -import org.gradle.api.file.Directory; import org.gradle.api.file.RegularFile; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.provider.Provider; -import org.gradle.api.provider.ProviderFactory; import org.gradle.api.publish.plugins.PublishingPlugin; import org.gradle.api.tasks.TaskContainer; +import org.gradle.api.tasks.TaskState; import org.gradle.language.base.plugins.LifecycleBasePlugin; import org.siouan.frontendgradleplugin.domain.ExecutableType; import org.siouan.frontendgradleplugin.domain.FileManager; import org.siouan.frontendgradleplugin.domain.MalformedPackageManagerSpecification; import org.siouan.frontendgradleplugin.domain.ParsePackageManagerSpecification; import org.siouan.frontendgradleplugin.domain.PlatformProvider; -import org.siouan.frontendgradleplugin.domain.ResolveGlobalExecutablePathCommand; -import org.siouan.frontendgradleplugin.domain.ResolveGlobalNodeExecutablePath; +import org.siouan.frontendgradleplugin.domain.ResolveExecutablePathCommand; +import org.siouan.frontendgradleplugin.domain.ResolveNodeExecutablePath; import org.siouan.frontendgradleplugin.domain.SystemSettingsProvider; import org.siouan.frontendgradleplugin.domain.UnsupportedPackageManagerException; import org.siouan.frontendgradleplugin.infrastructure.archiver.ArchiverProviderImpl; @@ -34,7 +33,20 @@ import org.siouan.frontendgradleplugin.infrastructure.bean.Beans; import org.siouan.frontendgradleplugin.infrastructure.bean.TooManyCandidateBeansException; import org.siouan.frontendgradleplugin.infrastructure.bean.ZeroOrMultiplePublicConstructorsException; -import org.siouan.frontendgradleplugin.infrastructure.gradle.*; +import org.siouan.frontendgradleplugin.infrastructure.gradle.AssembleTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.CheckTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.CleanTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.FrontendExtension; +import org.siouan.frontendgradleplugin.infrastructure.gradle.GradleLoggerAdapter; +import org.siouan.frontendgradleplugin.infrastructure.gradle.GradleSettings; +import org.siouan.frontendgradleplugin.infrastructure.gradle.InstallFrontendTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.InstallNodeTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.InstallPackageManagerTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.PublishTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.ResolvePackageManagerTask; +import org.siouan.frontendgradleplugin.infrastructure.gradle.SystemExtension; +import org.siouan.frontendgradleplugin.infrastructure.gradle.SystemSettingsProviderImpl; +import org.siouan.frontendgradleplugin.infrastructure.gradle.TaskLoggerConfigurer; import org.siouan.frontendgradleplugin.infrastructure.httpclient.HttpClientProviderImpl; import org.siouan.frontendgradleplugin.infrastructure.system.ChannelProviderImpl; import org.siouan.frontendgradleplugin.infrastructure.system.FileManagerImpl; @@ -157,11 +169,6 @@ public class FrontendGradlePlugin implements Plugin { */ public static final String INSTALL_NODE_TASK_NAME = "installNode"; - /** - * Name of the environment variable providing the path to a global Node.js installation. - */ - public static final String NODEJS_HOME_ENV_VAR = "FGP_NODEJS_HOME"; - /** * Name of the file containing the name and version of the package manager resolved. */ @@ -201,6 +208,9 @@ public void apply(final Project project) { frontendExtension.getNodeDistributionProvided().convention(false); frontendExtension.getNodeDistributionUrlRoot().convention(DEFAULT_NODE_DISTRIBUTION_URL_ROOT); frontendExtension.getNodeDistributionUrlPathPattern().convention(DEFAULT_NODE_DISTRIBUTION_URL_PATH_PATTERN); + frontendExtension + .getNodeInstallDirectory() + .convention(project.getLayout().getProjectDirectory().dir(DEFAULT_NODE_INSTALL_DIRECTORY_NAME)); frontendExtension.getInstallScript().convention(DEFAULT_INSTALL_SCRIPT); frontendExtension.getPackageJsonDirectory().convention(project.getLayout().getProjectDirectory()); frontendExtension.getHttpProxyPort().convention(DEFAULT_HTTP_PROXY_PORT); @@ -213,10 +223,6 @@ public void apply(final Project project) { frontendExtension .getCacheDirectory() .convention(project.getLayout().getProjectDirectory().dir(DEFAULT_CACHE_DIRECTORY_NAME)); - frontendExtension - .getInternalPackageJsonFile() - .fileProvider( - frontendExtension.getPackageJsonDirectory().file(PACKAGE_JSON_FILE_NAME).map(RegularFile::getAsFile)); frontendExtension .getInternalPackageManagerSpecificationFile() .convention(frontendExtension @@ -254,30 +260,13 @@ protected String configureBeanRegistry(final Project project, final SystemExtens final PlatformProvider platformProvider = new PlatformProviderImpl(systemSettingsProvider); final GradleSettings gradleSettings = new GradleSettings(project.getLogging().getLevel(), project.getGradle().getStartParameter().getLogLevel()); - final ProviderFactory providerFactory = project.getProviders(); - final TaskContext taskContext = TaskContext.builder() - // This default install directory must not be applied with a convention on the related extension property, - // because, when null, it allows to know whether the install directory must be resolved from an environment - // variable. - .defaultNodeInstallDirectoryPath(project - .getLayout() - .getProjectDirectory() - .getAsFile() - .toPath() - .resolve(DEFAULT_NODE_INSTALL_DIRECTORY_NAME)) - .nodeInstallDirectoryFromEnvironment( - providerFactory.environmentVariable(NODEJS_HOME_ENV_VAR).map(Paths::get)) - .extension(frontendExtension) - .build(); Beans.initBeanRegistry(beanRegistryId); Beans.registerBean(beanRegistryId, frontendExtension); Beans.registerBean(beanRegistryId, systemSettingsProvider); Beans.registerBean(beanRegistryId, platformProvider); Beans.registerBean(beanRegistryId, gradleSettings); - Beans.registerBean(beanRegistryId, taskContext); Beans.registerBean(beanRegistryId, GradleLoggerAdapter.class); Beans.registerBean(beanRegistryId, TaskLoggerConfigurer.class); - Beans.registerBean(beanRegistryId, ResolveNodeInstallDirectoryPath.class); Beans.registerBean(beanRegistryId, FileManagerImpl.class); Beans.registerBean(beanRegistryId, ChannelProviderImpl.class); Beans.registerBean(beanRegistryId, ArchiverProviderImpl.class); @@ -293,23 +282,23 @@ protected String configureBeanRegistry(final Project project, final SystemExtens */ protected void configureTasks(final Project project, final String beanRegistryId) { final TaskContainer taskContainer = project.getTasks(); - final TaskContext taskContext = getBeanOrFail(beanRegistryId, TaskContext.class); + final FrontendExtension frontendExtension = getBeanOrFail(beanRegistryId, FrontendExtension.class); taskContainer.register(INSTALL_NODE_TASK_NAME, InstallNodeTask.class, - task -> configureInstallNodeTask(task, beanRegistryId, taskContext)); + task -> configureInstallNodeTask(task, beanRegistryId, frontendExtension)); taskContainer.register(RESOLVE_PACKAGE_MANAGER_TASK_NAME, ResolvePackageManagerTask.class, - task -> configureResolvePackageManagerTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configureResolvePackageManagerTask(task, taskContainer, frontendExtension)); taskContainer.register(INSTALL_PACKAGE_MANAGER_TASK_NAME, InstallPackageManagerTask.class, - task -> configureInstallPackageManagerTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configureInstallPackageManagerTask(task, beanRegistryId, taskContainer, frontendExtension)); taskContainer.register(INSTALL_FRONTEND_TASK_NAME, InstallFrontendTask.class, - task -> configureInstallFrontendTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configureInstallFrontendTask(task, beanRegistryId, taskContainer, frontendExtension)); taskContainer.register(CLEAN_TASK_NAME, CleanTask.class, - task -> configureCleanTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configureCleanTask(task, beanRegistryId, taskContainer, frontendExtension)); taskContainer.register(CHECK_TASK_NAME, CheckTask.class, - task -> configureCheckTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configureCheckTask(task, beanRegistryId, taskContainer, frontendExtension)); taskContainer.register(ASSEMBLE_TASK_NAME, AssembleTask.class, - task -> configureAssembleTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configureAssembleTask(task, beanRegistryId, taskContainer, frontendExtension)); taskContainer.register(PUBLISH_TASK_NAME, PublishTask.class, - task -> configurePublishTask(task, beanRegistryId, taskContainer, taskContext)); + task -> configurePublishTask(task, beanRegistryId, taskContainer, frontendExtension)); // Configure dependencies with Gradle built-in tasks. configureDependency(taskContainer, GRADLE_CLEAN_TASK_NAME, CLEAN_TASK_NAME, CleanTask.class); @@ -323,80 +312,68 @@ protected void configureTasks(final Project project, final String beanRegistryId * * @param task Task. * @param beanRegistryId Bean registry ID. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configureInstallNodeTask(final InstallNodeTask task, final String beanRegistryId, - final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Downloads and installs a Node.js distribution."); - task.getNodeVersion().set(extension.getNodeVersion()); - task.getNodeDistributionUrlRoot().set(extension.getNodeDistributionUrlRoot()); - task.getNodeDistributionUrlPathPattern().set(extension.getNodeDistributionUrlPathPattern()); - task.getNodeDistributionServerUsername().set(extension.getNodeDistributionServerUsername()); - task.getNodeDistributionServerPassword().set(extension.getNodeDistributionServerPassword()); - task - .getNodeInstallDirectory() - .set(extension - .getNodeInstallDirectory() - .map(Directory::getAsFile) - .orElse(taskContext.defaultNodeInstallDirectoryPath().toFile())); - task.getHttpProxyHost().set(extension.getHttpProxyHost()); - task.getHttpProxyPort().set(extension.getHttpProxyPort()); - task.getHttpProxyUsername().set(extension.getHttpProxyUsername()); - task.getHttpProxyPassword().set(extension.getHttpProxyPassword()); - task.getHttpsProxyHost().set(extension.getHttpsProxyHost()); - task.getHttpsProxyPort().set(extension.getHttpsProxyPort()); - task.getHttpsProxyUsername().set(extension.getHttpsProxyUsername()); - task.getHttpsProxyPassword().set(extension.getHttpsProxyPassword()); + task.getNodeVersion().set(frontendExtension.getNodeVersion()); + task.getNodeDistributionUrlRoot().set(frontendExtension.getNodeDistributionUrlRoot()); + task.getNodeDistributionUrlPathPattern().set(frontendExtension.getNodeDistributionUrlPathPattern()); + task.getNodeDistributionServerUsername().set(frontendExtension.getNodeDistributionServerUsername()); + task.getNodeDistributionServerPassword().set(frontendExtension.getNodeDistributionServerPassword()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); + task.getHttpProxyHost().set(frontendExtension.getHttpProxyHost()); + task.getHttpProxyPort().set(frontendExtension.getHttpProxyPort()); + task.getHttpProxyUsername().set(frontendExtension.getHttpProxyUsername()); + task.getHttpProxyPassword().set(frontendExtension.getHttpProxyPassword()); + task.getHttpsProxyHost().set(frontendExtension.getHttpsProxyHost()); + task.getHttpsProxyPort().set(frontendExtension.getHttpsProxyPort()); + task.getHttpsProxyUsername().set(frontendExtension.getHttpsProxyUsername()); + task.getHttpsProxyPassword().set(frontendExtension.getHttpsProxyPassword()); task .getNodeExecutableFile() - .fileProvider(extension + .fileProvider(frontendExtension .getNodeInstallDirectory() - .map(directory -> directory.getAsFile().toPath()) - .orElse(taskContext.defaultNodeInstallDirectoryPath()) - .map(nodeInstallDirectoryPath -> getBeanOrFail(beanRegistryId, ResolveGlobalNodeExecutablePath.class) - .execute(ResolveGlobalExecutablePathCommand + .map(directory -> getBeanOrFail(beanRegistryId, ResolveNodeExecutablePath.class) + .execute(ResolveExecutablePathCommand .builder() - .nodeInstallDirectoryPath(nodeInstallDirectoryPath) + .nodeInstallDirectoryPath(directory.getAsFile().toPath()) .platform(getBeanOrFail(beanRegistryId, PlatformProvider.class).getPlatform()) .build()) .toFile())); - task.getMaxDownloadAttempts().set(extension.getMaxDownloadAttempts()); - task.getRetryHttpStatuses().set(extension.getRetryHttpStatuses()); - task.getRetryInitialIntervalMs().set(extension.getRetryInitialIntervalMs()); - task.getRetryIntervalMultiplier().set(extension.getRetryIntervalMultiplier()); - task.getRetryMaxIntervalMs().set(extension.getRetryMaxIntervalMs()); - task.setOnlyIf(t -> !extension.getNodeDistributionProvided().get()); + task.getMaxDownloadAttempts().set(frontendExtension.getMaxDownloadAttempts()); + task.getRetryHttpStatuses().set(frontendExtension.getRetryHttpStatuses()); + task.getRetryInitialIntervalMs().set(frontendExtension.getRetryInitialIntervalMs()); + task.getRetryIntervalMultiplier().set(frontendExtension.getRetryIntervalMultiplier()); + task.getRetryMaxIntervalMs().set(frontendExtension.getRetryMaxIntervalMs()); + task.setOnlyIf(t -> !frontendExtension.getNodeDistributionProvided().get()); } /** * Configures the given task with the plugin extension. * * @param task Task. - * @param beanRegistryId Bean registry ID. * @param taskContainer Gradle task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ - protected void configureResolvePackageManagerTask(final ResolvePackageManagerTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + protected void configureResolvePackageManagerTask(final ResolvePackageManagerTask task, + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Resolves the package manager."); - task.getPackageJsonFile().set(extension.getInternalPackageJsonFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); - task.getPackageManagerSpecificationFile().set(extension.getInternalPackageManagerSpecificationFile()); - task.getPackageManagerExecutablePathFile().set(extension.getInternalPackageManagerExecutablePathFile()); + final Provider packageJsonFileProvider = frontendExtension + .getPackageJsonDirectory() + .file(PACKAGE_JSON_FILE_NAME) + .map(RegularFile::getAsFile); + task.getPackageJsonFile().fileProvider(packageJsonFileProvider); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); + task.getPackageManagerSpecificationFile().set(frontendExtension.getInternalPackageManagerSpecificationFile()); + task.getPackageManagerExecutablePathFile().set(frontendExtension.getInternalPackageManagerExecutablePathFile()); // The task is skipped when there's no package.json file. It allows to define a project that installs only a // Node.js distribution. - task.setOnlyIf(t -> extension - .getInternalPackageJsonFile() - .getAsFile() - .map(File::toPath) - .map(Files::exists) - .getOrElse(false)); + task.setOnlyIf(t -> packageJsonFileProvider.map(File::toPath).map(Files::isRegularFile).getOrElse(false)); + configureDependency(taskContainer, task, INSTALL_NODE_TASK_NAME, InstallNodeTask.class); } @@ -406,16 +383,14 @@ protected void configureResolvePackageManagerTask(final ResolvePackageManagerTas * @param task Task. * @param beanRegistryId Bean registry ID. * @param taskContainer Task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configureInstallPackageManagerTask(final InstallPackageManagerTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Installs the package manager."); - task.getPackageJsonDirectory().set(extension.getPackageJsonDirectory().getAsFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); + task.getPackageJsonDirectory().set(frontendExtension.getPackageJsonDirectory().getAsFile()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); final Provider resolvePackageManagerTaskProvider = taskContainer.named( RESOLVE_PACKAGE_MANAGER_TASK_NAME, ResolvePackageManagerTask.class); task @@ -427,25 +402,25 @@ protected void configureInstallPackageManagerTask(final InstallPackageManagerTas .set(resolvePackageManagerTaskProvider .flatMap(ResolvePackageManagerTask::getPackageManagerExecutablePathFile) .map(f -> { - if (!Files.exists(f.getAsFile().toPath())) { + final Path filePath = f.getAsFile().toPath(); + if (!Files.exists(filePath)) { + // Setting the output property to null avoids automatic creation of any parent directories by + // Gradle if the task is not skipped. If it is skipped, the file system would not have been + // touched by Gradle. return null; } try { - return getBeanOrFail(beanRegistryId, FileManager.class).readString(f.getAsFile().toPath(), + return getBeanOrFail(beanRegistryId, FileManager.class).readString(filePath, StandardCharsets.UTF_8); } catch (final IOException e) { - throw new GradleException(e.getClass().getName() + ": " + e.getMessage(), e); + throw new GradleException( + "Cannot read path to package manager executable from file: " + filePath, e); } }) .map(packageManagerExecutablePathFilePath -> () -> Paths .get(packageManagerExecutablePathFilePath) .toFile())); - task.setOnlyIf(t -> extension - .getInternalPackageManagerExecutablePathFile() - .getAsFile() - .map(File::toPath) - .map(Files::exists) - .getOrElse(false)); + task.setOnlyIf(t -> isTaskExecuted(taskContainer, RESOLVE_PACKAGE_MANAGER_TASK_NAME)); } /** @@ -454,24 +429,17 @@ protected void configureInstallPackageManagerTask(final InstallPackageManagerTas * @param task Task. * @param beanRegistryId Bean registry ID. * @param taskContainer Task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configureInstallFrontendTask(final InstallFrontendTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Installs frontend dependencies."); - task.getPackageJsonDirectory().set(extension.getPackageJsonDirectory().getAsFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); + task.getPackageJsonDirectory().set(frontendExtension.getPackageJsonDirectory().getAsFile()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); task.getExecutableType().set(getExecutableType(taskContainer, beanRegistryId)); - task.getInstallScript().set(extension.getInstallScript()); - task.setOnlyIf(t -> extension - .getInternalPackageManagerSpecificationFile() - .getAsFile() - .map(File::toPath) - .map(Files::exists) - .getOrElse(false)); + task.getInstallScript().set(frontendExtension.getInstallScript()); + task.setOnlyIf(t -> isTaskExecuted(taskContainer, INSTALL_PACKAGE_MANAGER_TASK_NAME)); configureDependency(taskContainer, task, INSTALL_PACKAGE_MANAGER_TASK_NAME, InstallPackageManagerTask.class); } @@ -481,19 +449,19 @@ protected void configureInstallFrontendTask(final InstallFrontendTask task, fina * @param task Task. * @param beanRegistryId Bean registry ID. * @param taskContainer Task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configureCleanTask(final CleanTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Cleans frontend resources outside the build directory by running a specific script."); - task.getPackageJsonDirectory().set(extension.getPackageJsonDirectory().getAsFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); + task.getPackageJsonDirectory().set(frontendExtension.getPackageJsonDirectory().getAsFile()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); task.getExecutableType().set(getExecutableType(taskContainer, beanRegistryId)); - task.getCleanScript().set(extension.getCleanScript()); - task.setOnlyIf(t -> extension.getCleanScript().isPresent()); + task.getCleanScript().set(frontendExtension.getCleanScript()); + task.setOnlyIf(t -> isTaskExecuted(taskContainer, INSTALL_FRONTEND_TASK_NAME) && frontendExtension + .getCleanScript() + .isPresent()); configureDependency(taskContainer, task, INSTALL_FRONTEND_TASK_NAME, InstallFrontendTask.class); } @@ -503,19 +471,19 @@ protected void configureCleanTask(final CleanTask task, final String beanRegistr * @param task Task. * @param beanRegistryId Bean registry ID. * @param taskContainer Task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configureCheckTask(final CheckTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Checks frontend by running a specific script."); - task.getPackageJsonDirectory().set(extension.getPackageJsonDirectory().getAsFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); + task.getPackageJsonDirectory().set(frontendExtension.getPackageJsonDirectory().getAsFile()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); task.getExecutableType().set(getExecutableType(taskContainer, beanRegistryId)); - task.getCheckScript().set(extension.getCheckScript()); - task.setOnlyIf(t -> extension.getCheckScript().isPresent()); + task.getCheckScript().set(frontendExtension.getCheckScript()); + task.setOnlyIf(t -> isTaskExecuted(taskContainer, INSTALL_FRONTEND_TASK_NAME) && frontendExtension + .getCheckScript() + .isPresent()); configureDependency(taskContainer, task, INSTALL_FRONTEND_TASK_NAME, InstallFrontendTask.class); } @@ -525,19 +493,19 @@ protected void configureCheckTask(final CheckTask task, final String beanRegistr * @param task Task. * @param beanRegistryId Bean registry ID. * @param taskContainer Task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configureAssembleTask(final AssembleTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Assembles frontend artifacts by running a specific script."); - task.getPackageJsonDirectory().set(extension.getPackageJsonDirectory().getAsFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); + task.getPackageJsonDirectory().set(frontendExtension.getPackageJsonDirectory().getAsFile()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); task.getExecutableType().set(getExecutableType(taskContainer, beanRegistryId)); - task.getAssembleScript().set(extension.getAssembleScript()); - task.setOnlyIf(t -> extension.getAssembleScript().isPresent()); + task.getAssembleScript().set(frontendExtension.getAssembleScript()); + task.setOnlyIf(t -> isTaskExecuted(taskContainer, INSTALL_FRONTEND_TASK_NAME) && frontendExtension + .getAssembleScript() + .isPresent()); configureDependency(taskContainer, task, INSTALL_FRONTEND_TASK_NAME, InstallFrontendTask.class); } @@ -547,19 +515,19 @@ protected void configureAssembleTask(final AssembleTask task, final String beanR * @param task Task. * @param beanRegistryId Bean registry ID. * @param taskContainer Task container. - * @param taskContext Configuration context. + * @param frontendExtension Plugin extension. */ protected void configurePublishTask(final PublishTask task, final String beanRegistryId, - final TaskContainer taskContainer, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - + final TaskContainer taskContainer, final FrontendExtension frontendExtension) { task.setGroup(TASK_GROUP); task.setDescription("Publishes frontend artifacts by running a specific script."); - task.getPackageJsonDirectory().set(extension.getPackageJsonDirectory().getAsFile()); - task.getNodeInstallDirectory().set(resolveNodeInstallDirectory(beanRegistryId, taskContext)); + task.getPackageJsonDirectory().set(frontendExtension.getPackageJsonDirectory().getAsFile()); + task.getNodeInstallDirectory().set(frontendExtension.getNodeInstallDirectory().getAsFile()); task.getExecutableType().set(getExecutableType(taskContainer, beanRegistryId)); - task.getPublishScript().set(extension.getPublishScript()); - task.setOnlyIf(t -> extension.getAssembleScript().isPresent() && extension.getPublishScript().isPresent()); + task.getPublishScript().set(frontendExtension.getPublishScript()); + task.setOnlyIf(t -> isTaskExecuted(taskContainer, INSTALL_FRONTEND_TASK_NAME) && frontendExtension + .getAssembleScript() + .isPresent() && frontendExtension.getPublishScript().isPresent()); configureDependency(taskContainer, task, ASSEMBLE_TASK_NAME, AssembleTask.class); } @@ -567,17 +535,19 @@ private Provider getExecutableType(final TaskContainer taskConta return taskContainer .named(RESOLVE_PACKAGE_MANAGER_TASK_NAME, ResolvePackageManagerTask.class) .flatMap(ResolvePackageManagerTask::getPackageManagerSpecificationFile) - .map(RegularFile::getAsFile) .map(f -> { + final Path packageManagerSpecificationFilePath = f.getAsFile().toPath(); try { return getBeanOrFail(beanRegistryId, ParsePackageManagerSpecification.class) - .execute(getBeanOrFail(beanRegistryId, FileManager.class).readString(f.toPath(), - StandardCharsets.UTF_8)) + .execute(getBeanOrFail(beanRegistryId, FileManager.class).readString( + packageManagerSpecificationFilePath, StandardCharsets.UTF_8)) .type() .getExecutableType(); } catch (final IOException | MalformedPackageManagerSpecification | UnsupportedPackageManagerException e) { - throw new GradleException(e.getClass().getName() + ": " + e.getMessage(), e); + throw new GradleException( + "Cannot read package manager specification from file: " + packageManagerSpecificationFilePath, + e); } }); } @@ -612,27 +582,6 @@ private void configureDependency(final TaskCont task.dependsOn(taskContainer.named(dependsOnTaskName, dependsOnTaskClass).getName()); } - private Provider resolveNodeInstallDirectory(final String beanRegistryId, final TaskContext taskContext) { - final FrontendExtension extension = taskContext.extension(); - final ResolveNodeInstallDirectoryPath resolveNodeInstallDirectoryPath; - try { - resolveNodeInstallDirectoryPath = Beans.getBean(beanRegistryId, ResolveNodeInstallDirectoryPath.class); - } catch (final BeanInstanciationException | TooManyCandidateBeansException | - ZeroOrMultiplePublicConstructorsException e) { - throw new GradleException(e.getClass().getName() + ": " + e.getMessage(), e); - } - - return resolveNodeInstallDirectoryPath - .execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(extension.getNodeInstallDirectory().getAsFile().map(File::toPath)) - .nodeDistributionProvided(extension.getNodeDistributionProvided()) - .nodeInstallDirectoryFromEnvironment(taskContext.nodeInstallDirectoryFromEnvironment()) - .defaultPath(taskContext.defaultNodeInstallDirectoryPath()) - .build()) - .map(Path::toFile); - } - /** * Returns a bean from a registry of throws an error if no bean is registered or is instanciable. * @@ -649,4 +598,18 @@ private T getBeanOrFail(final String beanRegistryId, final Class beanClas throw new GradleException(e.getClass().getName() + ": " + e.getMessage(), e); } } + + /** + * Tells whether a task has been executed in the current build. + * + * @param taskContainer Task container. + * @param taskName Task name. + * @return {@code true} if the task was executed (i.e. not skipped or up-to-date). + */ + private boolean isTaskExecuted(final TaskContainer taskContainer, final String taskName) { + return taskContainer.named(taskName).map(task -> { + final TaskState taskState = task.getState(); + return taskState.getUpToDate() || !taskState.getSkipped(); + }).getOrElse(false); + } } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/AbstractResolveGlobalExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/AbstractResolveExecutablePath.java similarity index 93% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/AbstractResolveGlobalExecutablePath.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/AbstractResolveExecutablePath.java index 3760064b..edf909bd 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/AbstractResolveGlobalExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/AbstractResolveExecutablePath.java @@ -11,7 +11,7 @@ * @since 2.0.0 */ @RequiredArgsConstructor(access = AccessLevel.PROTECTED) -public abstract class AbstractResolveGlobalExecutablePath { +public abstract class AbstractResolveExecutablePath { private final Logger logger; @@ -21,7 +21,7 @@ public abstract class AbstractResolveGlobalExecutablePath { * @param command Command providing resolution parameters. * @return The path, which may be a single file name if it must be resolved using the PATH environment variable. */ - public Path execute(final ResolveGlobalExecutablePathCommand command) { + public Path execute(final ResolveExecutablePathCommand command) { final Path relativeExecutablePath; if (command.getPlatform().isWindowsOs()) { relativeExecutablePath = getWindowsRelativeExecutablePath(); diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/GetExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/GetExecutablePath.java index cd598098..405b44e9 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/GetExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/GetExecutablePath.java @@ -12,15 +12,15 @@ @RequiredArgsConstructor public class GetExecutablePath { - private final ResolveGlobalCorepackExecutablePath getCorepackExecutablePath; + private final ResolveCorepackExecutablePath getCorepackExecutablePath; - private final ResolveGlobalNodeExecutablePath getNodeExecutablePath; + private final ResolveNodeExecutablePath getNodeExecutablePath; - private final ResolveGlobalNpmExecutablePath getNpmExecutablePath; + private final ResolveNpmExecutablePath getNpmExecutablePath; - private final ResolveGlobalPnpmExecutablePath getPnpmExecutablePath; + private final ResolvePnpmExecutablePath getPnpmExecutablePath; - private final ResolveGlobalYarnExecutablePath getYarnExecutablePath; + private final ResolveYarnExecutablePath getYarnExecutablePath; /** * Resolves the path of the executable. @@ -30,17 +30,17 @@ public class GetExecutablePath { * @see ExecutableType */ public Path execute(final GetExecutablePathCommand command) { - final ResolveGlobalExecutablePathCommand resolveGlobalExecutablePathCommand = ResolveGlobalExecutablePathCommand + final ResolveExecutablePathCommand resolveExecutablePathCommand = ResolveExecutablePathCommand .builder() .platform(command.getPlatform()) .nodeInstallDirectoryPath(command.getNodeInstallDirectoryPath()) .build(); return switch (command.getExecutableType()) { - case COREPACK -> getCorepackExecutablePath.execute(resolveGlobalExecutablePathCommand); - case NODE -> getNodeExecutablePath.execute(resolveGlobalExecutablePathCommand); - case NPM -> getNpmExecutablePath.execute(resolveGlobalExecutablePathCommand); - case PNPM -> getPnpmExecutablePath.execute(resolveGlobalExecutablePathCommand); - case YARN -> getYarnExecutablePath.execute(resolveGlobalExecutablePathCommand); + case COREPACK -> getCorepackExecutablePath.execute(resolveExecutablePathCommand); + case NODE -> getNodeExecutablePath.execute(resolveExecutablePathCommand); + case NPM -> getNpmExecutablePath.execute(resolveExecutablePathCommand); + case PNPM -> getPnpmExecutablePath.execute(resolveExecutablePathCommand); + case YARN -> getYarnExecutablePath.execute(resolveExecutablePathCommand); }; } } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveCorepackExecutablePath.java similarity index 89% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePath.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveCorepackExecutablePath.java index fb57e776..b29b166b 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveCorepackExecutablePath.java @@ -8,7 +8,7 @@ * * @since 7.0.0 */ -public class ResolveGlobalCorepackExecutablePath extends AbstractResolveGlobalExecutablePath { +public class ResolveCorepackExecutablePath extends AbstractResolveExecutablePath { /** * Relative executable path on Windows O/S. @@ -32,7 +32,7 @@ public class ResolveGlobalCorepackExecutablePath extends AbstractResolveGlobalEx .get("bin") .resolve(NON_WINDOWS_EXECUTABLE_FILE_NAME); - public ResolveGlobalCorepackExecutablePath(final Logger logger) { + public ResolveCorepackExecutablePath(final Logger logger) { super(logger); } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalExecutablePathCommand.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutablePathCommand.java similarity index 91% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalExecutablePathCommand.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutablePathCommand.java index 70735345..a019fae1 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalExecutablePathCommand.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutablePathCommand.java @@ -14,7 +14,7 @@ @Builder @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class ResolveGlobalExecutablePathCommand { +public class ResolveExecutablePathCommand { /** * Path to the Node.js install directory. diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettings.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettings.java index 2ce49db3..15e9118d 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettings.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettings.java @@ -47,7 +47,7 @@ public class ResolveExecutionSettings { */ public static final char UNIX_SCRIPT_ARG_ESCAPE_CHAR = '\\'; - private final ResolveGlobalNodeExecutablePath getNodeExecutablePath; + private final ResolveNodeExecutablePath getNodeExecutablePath; private final GetExecutablePath getExecutablePath; @@ -59,7 +59,7 @@ public class ResolveExecutionSettings { * @see ExecutableType */ public ExecutionSettings execute(final ResolveExecutionSettingsCommand command) { - final Path nodeExecutablePath = getNodeExecutablePath.execute(ResolveGlobalExecutablePathCommand + final Path nodeExecutablePath = getNodeExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(command.getNodeInstallDirectoryPath()) .platform(command.getPlatform()) diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveNodeExecutablePath.java similarity index 89% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePath.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveNodeExecutablePath.java index 7f5170d7..0f4a4312 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveNodeExecutablePath.java @@ -8,7 +8,7 @@ * * @since 2.0.0 */ -public class ResolveGlobalNodeExecutablePath extends AbstractResolveGlobalExecutablePath { +public class ResolveNodeExecutablePath extends AbstractResolveExecutablePath { /** * Executable name on Windows O/S. @@ -32,7 +32,7 @@ public class ResolveGlobalNodeExecutablePath extends AbstractResolveGlobalExecut .get("bin") .resolve(NON_WINDOWS_EXECUTABLE_FILE_NAME); - public ResolveGlobalNodeExecutablePath(final Logger logger) { + public ResolveNodeExecutablePath(final Logger logger) { super(logger); } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveNpmExecutablePath.java similarity index 90% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePath.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveNpmExecutablePath.java index 9513d6cb..10cc9a9b 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveNpmExecutablePath.java @@ -8,7 +8,7 @@ * * @since 2.0.0 */ -public class ResolveGlobalNpmExecutablePath extends AbstractResolveGlobalExecutablePath { +public class ResolveNpmExecutablePath extends AbstractResolveExecutablePath { /** * Relative executable path on Windows O/S. @@ -32,7 +32,7 @@ public class ResolveGlobalNpmExecutablePath extends AbstractResolveGlobalExecuta .get("bin") .resolve(NON_WINDOWS_EXECUTABLE_FILE_NAME); - public ResolveGlobalNpmExecutablePath(final Logger logger) { + public ResolveNpmExecutablePath(final Logger logger) { super(logger); } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolvePnpmExecutablePath.java similarity index 89% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePath.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolvePnpmExecutablePath.java index fd41b3d2..06395340 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolvePnpmExecutablePath.java @@ -8,7 +8,7 @@ * * @since 7.0.0 */ -public class ResolveGlobalPnpmExecutablePath extends AbstractResolveGlobalExecutablePath { +public class ResolvePnpmExecutablePath extends AbstractResolveExecutablePath { /** * Relative executable path on Windows O/S. @@ -32,7 +32,7 @@ public class ResolveGlobalPnpmExecutablePath extends AbstractResolveGlobalExecut .get("bin") .resolve(NON_WINDOWS_EXECUTABLE_FILE_NAME); - public ResolveGlobalPnpmExecutablePath(final Logger logger) { + public ResolvePnpmExecutablePath(final Logger logger) { super(logger); } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveYarnExecutablePath.java similarity index 89% rename from plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePath.java rename to plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveYarnExecutablePath.java index c1d0f19d..6e472084 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePath.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/ResolveYarnExecutablePath.java @@ -8,7 +8,7 @@ * * @since 2.0.0 */ -public class ResolveGlobalYarnExecutablePath extends AbstractResolveGlobalExecutablePath { +public class ResolveYarnExecutablePath extends AbstractResolveExecutablePath { /** * Relative executable path on Windows O/S. @@ -32,7 +32,7 @@ public class ResolveGlobalYarnExecutablePath extends AbstractResolveGlobalExecut .get("bin") .resolve(NON_WINDOWS_EXECUTABLE_FILE_NAME); - public ResolveGlobalYarnExecutablePath(final Logger logger) { + public ResolveYarnExecutablePath(final Logger logger) { super(logger); } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTaskType.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTaskType.java index 7d2956b3..230c6625 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTaskType.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTaskType.java @@ -1,8 +1,5 @@ package org.siouan.frontendgradleplugin.infrastructure.gradle; -import java.io.File; -import java.nio.file.Path; - import org.gradle.api.GradleException; import org.gradle.api.file.ProjectLayout; import org.gradle.api.model.ObjectFactory; @@ -19,24 +16,13 @@ public abstract class AbstractRunCommandTaskType extends AbstractRunCommandTask AbstractRunCommandTaskType(final ProjectLayout projectLayout, final ObjectFactory objectFactory, final ExecOperations execOperations) { super(projectLayout, objectFactory, execOperations); - final TaskContext taskContext; - final ResolveNodeInstallDirectoryPath resolveNodeInstallDirectoryPath; + final FrontendExtension frontendExtension; try { - taskContext = Beans.getBean(beanRegistryId, TaskContext.class); - resolveNodeInstallDirectoryPath = Beans.getBean(beanRegistryId, ResolveNodeInstallDirectoryPath.class); + frontendExtension = Beans.getBean(beanRegistryId, FrontendExtension.class); } catch (final BeanRegistryException e) { throw new GradleException(e.getClass().getName() + ": " + e.getMessage(), e); } - final FrontendExtension extension = taskContext.extension(); - this.packageJsonDirectory.set(extension.getPackageJsonDirectory().getAsFile()); - this.nodeInstallDirectory.set(resolveNodeInstallDirectoryPath - .execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(extension.getNodeInstallDirectory().getAsFile().map(File::toPath)) - .nodeDistributionProvided(extension.getNodeDistributionProvided()) - .nodeInstallDirectoryFromEnvironment(taskContext.nodeInstallDirectoryFromEnvironment()) - .defaultPath(taskContext.defaultNodeInstallDirectoryPath()) - .build()) - .map(Path::toFile)); + this.packageJsonDirectory.set(frontendExtension.getPackageJsonDirectory().getAsFile()); + this.nodeInstallDirectory.set(frontendExtension.getNodeInstallDirectory().getAsFile()); } } diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java index 57cef05a..79c12ef9 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java @@ -186,14 +186,6 @@ public class FrontendExtension { */ private final DirectoryProperty cacheDirectory; - /** - * WARNING: THIS IS AN INTERNAL PROPERTY, WHICH MUST NOT BE USED/OVERRIDDEN IN GRADLE BUILD FILES. - *

The {@code package.json} file derived from the {@link #packageJsonDirectory} property.

- * - * @since 7.0.0 - */ - private final RegularFileProperty internalPackageJsonFile; - /** * WARNING: THIS IS AN INTERNAL PROPERTY, WHICH MUST NOT BE USED/OVERRIDDEN IN GRADLE BUILD FILES. *

File derived from the {@link #cacheDirectory} property where task "resolvePackageManager" stores the name and @@ -247,7 +239,6 @@ public FrontendExtension(final ObjectFactory objectFactory) { retryIntervalMultiplier = objectFactory.property(Double.class); retryMaxIntervalMs = objectFactory.property(Integer.class); cacheDirectory = objectFactory.directoryProperty(); - internalPackageJsonFile = objectFactory.fileProperty(); internalPackageManagerSpecificationFile = objectFactory.fileProperty(); internalPackageManagerExecutablePathFile = objectFactory.fileProperty(); verboseModeEnabled = objectFactory.property(Boolean.class); diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPath.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPath.java deleted file mode 100644 index dcadaef6..00000000 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPath.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.siouan.frontendgradleplugin.infrastructure.gradle; - -import java.nio.file.Path; - -import org.gradle.api.provider.Provider; - -/** - * Resolves the path to the Node.js distribution. - * - * @since 7.0.0 - */ -public class ResolveNodeInstallDirectoryPath { - - /** - * Resolves the applicable path to the Node.js distribution just-in-time. - * - * @param command Command providing resolution parameters. - * @return A provider of the path to the install directory: - *

    - *
  • The directory given by a provider user-defined.
  • - *
  • Or the directory given by a provider scanning the environment if the distribution is already provided.
  • - *
  • Or a default directory.
  • - *
- */ - public Provider execute(final ResolveNodeInstallDirectoryPathCommand command) { - final Provider nodeInstallDirectoryPath = command - .nodeDistributionProvided() - .flatMap(nodeDistributionProvided -> Boolean.TRUE.equals(nodeDistributionProvided) ? command - .nodeInstallDirectoryFromUser() - .orElse(command.nodeInstallDirectoryFromEnvironment()) : command.nodeInstallDirectoryFromUser()); - return nodeInstallDirectoryPath.orElse(command.defaultPath()); - } -} diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPathCommand.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPathCommand.java deleted file mode 100644 index 807e0ede..00000000 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPathCommand.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.siouan.frontendgradleplugin.infrastructure.gradle; - -import java.nio.file.Path; - -import lombok.Builder; -import org.gradle.api.provider.Provider; - -/** - * @param nodeInstallDirectoryFromUser A user-defined provider of the path to the install directory - * @param nodeDistributionProvided Whether the Node.js distribution is already installed in the system and shall not be - * downloaded. - * @param nodeInstallDirectoryFromEnvironment A provider of the path to the install directory given by the environment. - * @param defaultPath A default path to an install directory. - */ -@Builder -public record ResolveNodeInstallDirectoryPathCommand(Provider nodeInstallDirectoryFromUser, - Provider nodeDistributionProvided, Provider nodeInstallDirectoryFromEnvironment, Path defaultPath) {} diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskContext.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskContext.java deleted file mode 100644 index 5cbcf0be..00000000 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskContext.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.siouan.frontendgradleplugin.infrastructure.gradle; - -import java.nio.file.Path; - -import lombok.Builder; -import org.gradle.api.provider.Provider; - -@Builder -public record TaskContext(Path defaultNodeInstallDirectoryPath, Provider nodeInstallDirectoryFromEnvironment, - FrontendExtension extension) {} diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/FrontendGradlePluginTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/FrontendGradlePluginTest.java index 9ce76c94..301b1f81 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/FrontendGradlePluginTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/FrontendGradlePluginTest.java @@ -2,12 +2,12 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.nio.file.Paths; import java.util.Objects; import java.util.Set; import org.gradle.api.Project; +import org.gradle.api.file.RegularFile; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.publish.plugins.PublishingPlugin; import org.gradle.language.base.plugins.LifecycleBasePlugin; @@ -51,7 +51,11 @@ void should_register_tasks_with_default_extension_values_applied() { assertThat(extension.getNodeDistributionProvided().get()).isFalse(); assertThat(extension.getNodeVersion().isPresent()).isFalse(); - assertThat(extension.getNodeInstallDirectory().getAsFile().isPresent()).isFalse(); + assertThat(extension.getNodeInstallDirectory().getAsFile().get()).isEqualTo(project + .getLayout() + .getProjectDirectory() + .dir(FrontendGradlePlugin.DEFAULT_NODE_INSTALL_DIRECTORY_NAME) + .getAsFile()); assertThat(extension.getNodeDistributionUrlRoot().get()).isEqualTo( FrontendGradlePlugin.DEFAULT_NODE_DISTRIBUTION_URL_ROOT); assertThat(extension.getNodeDistributionUrlPathPattern().get()).isEqualTo( @@ -82,8 +86,6 @@ void should_register_tasks_with_default_extension_values_applied() { FrontendGradlePlugin.DEFAULT_RETRY_INTERVAL_MULTIPLIER); assertThat(extension.getRetryMaxIntervalMs().get()).isEqualTo( FrontendGradlePlugin.DEFAULT_RETRY_MAX_INTERVAL_MS); - assertThat(extension.getInternalPackageJsonFile().getAsFile().get()).isEqualTo( - project.getProjectDir().toPath().resolve(FrontendGradlePlugin.PACKAGE_JSON_FILE_NAME).toFile()); assertThat(extension.getInternalPackageManagerSpecificationFile().getAsFile().get()).isEqualTo(project .getProjectDir() .toPath() @@ -134,7 +136,6 @@ void should_register_tasks_with_custom_extension_values_applied() { extension.getRetryIntervalMultiplier().set(7.3); extension.getRetryMaxIntervalMs().set(9623); extension.getVerboseModeEnabled().set(true); - extension.getInternalPackageJsonFile().set(new File("metadata.json")); assertThatTasksAreConfigured(project, extension); } @@ -184,8 +185,11 @@ private void assertThatTasksAreConfigured(final Project project, final FrontendE .getTasks() .named(FrontendGradlePlugin.RESOLVE_PACKAGE_MANAGER_TASK_NAME, ResolvePackageManagerTask.class) .get(); - assertThat(resolvePackageManagerTask.getPackageJsonFile().getAsFile().get()).isEqualTo( - extension.getInternalPackageJsonFile().getAsFile().get()); + assertThat(resolvePackageManagerTask.getPackageJsonFile().getAsFile().get()).isEqualTo(extension + .getPackageJsonDirectory() + .file(FrontendGradlePlugin.PACKAGE_JSON_FILE_NAME) + .map(RegularFile::getAsFile) + .get()); assertThat(resolvePackageManagerTask.getNodeInstallDirectory().isPresent()).isTrue(); assertThat(resolvePackageManagerTask.getPackageManagerSpecificationFile().getAsFile().get()).isEqualTo( extension.getInternalPackageManagerSpecificationFile().getAsFile().get()); diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/AbstractResolveGlobalExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/AbstractResolveExecutablePathTest.java similarity index 83% rename from plugin/src/test/java/org/siouan/frontendgradleplugin/domain/AbstractResolveGlobalExecutablePathTest.java rename to plugin/src/test/java/org/siouan/frontendgradleplugin/domain/AbstractResolveExecutablePathTest.java index 3c5bb8d3..3bbd4cdb 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/AbstractResolveGlobalExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/AbstractResolveExecutablePathTest.java @@ -14,7 +14,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class AbstractResolveGlobalExecutablePathTest { +class AbstractResolveExecutablePathTest { private static final Path WINDOWS_EXECUTABLE_FILE_PATH = ANY_PATH.resolve("windows-path"); @@ -22,11 +22,11 @@ class AbstractResolveGlobalExecutablePathTest { private static final Path INSTALL_DIRECTORY_PATH = ANY_PATH; - private ResolveGlobalExecutablePathImpl usecase; + private ResolveExecutablePathImpl usecase; @BeforeEach void setUp() { - usecase = new ResolveGlobalExecutablePathImpl(mock(Logger.class), WINDOWS_EXECUTABLE_FILE_PATH, + usecase = new ResolveExecutablePathImpl(mock(Logger.class), WINDOWS_EXECUTABLE_FILE_PATH, NON_WINDOWS_EXECUTABLE_FILE_PATH); } @@ -34,7 +34,7 @@ void setUp() { void should_return_executable_path_when_os_is_windows_and_executable_exists_in_install_directory() { final Path executablePath = INSTALL_DIRECTORY_PATH.resolve(WINDOWS_EXECUTABLE_FILE_PATH); - assertThat(usecase.execute(ResolveGlobalExecutablePathCommand + assertThat(usecase.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(INSTALL_DIRECTORY_PATH) .platform(ANY_WINDOWS_PLATFORM) @@ -45,20 +45,20 @@ void should_return_executable_path_when_os_is_windows_and_executable_exists_in_i void should_return_executable_path_when_os_is_not_windows_and_executable_exists_in_install_directory() { final Path executablePath = INSTALL_DIRECTORY_PATH.resolve(NON_WINDOWS_EXECUTABLE_FILE_PATH); - assertThat(usecase.execute(ResolveGlobalExecutablePathCommand + assertThat(usecase.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(INSTALL_DIRECTORY_PATH) .platform(ANY_NON_WINDOWS_PLATFORM) .build())).isEqualTo(executablePath); } - private static class ResolveGlobalExecutablePathImpl extends AbstractResolveGlobalExecutablePath { + private static class ResolveExecutablePathImpl extends AbstractResolveExecutablePath { private final Path windowsExecutablePath; private final Path nonWindowsExecutablePath; - ResolveGlobalExecutablePathImpl(final Logger logger, final Path windowsExecutablePath, + ResolveExecutablePathImpl(final Logger logger, final Path windowsExecutablePath, final Path nonWindowsExecutablePath) { super(logger); this.windowsExecutablePath = windowsExecutablePath; diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/GetExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/GetExecutablePathTest.java index 57b09b74..d8f33999 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/GetExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/GetExecutablePathTest.java @@ -21,19 +21,19 @@ class GetExecutablePathTest { private static final Path NODE_INSTALL_DIRECTORY_PATH = ANY_PATH.resolve("node"); @Mock - private ResolveGlobalCorepackExecutablePath getCorepackExecutablePath; + private ResolveCorepackExecutablePath getCorepackExecutablePath; @Mock - private ResolveGlobalNodeExecutablePath getNodeExecutablePath; + private ResolveNodeExecutablePath getNodeExecutablePath; @Mock - private ResolveGlobalNpmExecutablePath getNpmExecutablePath; + private ResolveNpmExecutablePath getNpmExecutablePath; @Mock - private ResolveGlobalPnpmExecutablePath getPnpmExecutablePath; + private ResolvePnpmExecutablePath getPnpmExecutablePath; @Mock - private ResolveGlobalYarnExecutablePath getYarnExecutablePath; + private ResolveYarnExecutablePath getYarnExecutablePath; @InjectMocks private GetExecutablePath usecase; @@ -42,7 +42,7 @@ class GetExecutablePathTest { void should_resolve_node_executable_path() { final Platform platform = aPlatform(); final Path executablePath = Paths.get("node"); - when(getNodeExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getNodeExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -63,7 +63,7 @@ void should_resolve_node_executable_path() { void should_resolve_corepack_executable_path() { final Platform platform = aPlatform(); final Path executablePath = Paths.get("corepack"); - when(getCorepackExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getCorepackExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -84,7 +84,7 @@ void should_resolve_corepack_executable_path() { void should_resolve_npm_executable_path() { final Platform platform = aPlatform(); final Path executablePath = Paths.get("npm"); - when(getNpmExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getNpmExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -105,7 +105,7 @@ void should_resolve_npm_executable_path() { void should_resolve_pnpm_executable_path() { final Platform platform = aPlatform(); final Path executablePath = Paths.get("pnpm"); - when(getPnpmExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getPnpmExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -126,7 +126,7 @@ void should_resolve_pnpm_executable_path() { void should_resolve_yarn_executable_path() { final Platform platform = aPlatform(); final Path executablePath = Paths.get("yarn"); - when(getYarnExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getYarnExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettingsTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettingsTest.java index f147bda9..ef7bc483 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettingsTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveExecutionSettingsTest.java @@ -25,7 +25,7 @@ class ResolveExecutionSettingsTest { private static final String SCRIPT = " run script "; @Mock - private ResolveGlobalNodeExecutablePath getNodeExecutablePath; + private ResolveNodeExecutablePath getNodeExecutablePath; @Mock private GetExecutablePath getExecutablePath; @@ -37,7 +37,7 @@ class ResolveExecutionSettingsTest { void should_resolve_exec_settings_with_windows_cmd_when_executable_is_node_in_distribution_and_os_is_windows() { final Platform platform = aPlatform(getSystemJvmArch(), "Windows NT"); final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node"); - when(getNodeExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getNodeExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -70,7 +70,7 @@ void should_resolve_exec_settings_with_windows_cmd_when_executable_is_not_node_i final Platform platform = aPlatform(getSystemJvmArch(), "Windows NT"); final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node"); final Path npmExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("npm"); - when(getNodeExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getNodeExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -102,7 +102,7 @@ void should_resolve_exec_settings_with_windows_cmd_when_executable_is_not_node_i void should_resolve_exec_settings_with_unix_shell_when_executable_is_node_in_path_and_os_is_not_windows() { final Platform platform = aPlatform(getSystemJvmArch(), "Linux"); final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node"); - when(getNodeExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getNodeExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) @@ -135,7 +135,7 @@ void should_resolve_exec_settings_with_unix_shell_when_executable_is_npm_in_path final Platform platform = aPlatform(getSystemJvmArch(), "Linux"); final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node"); final Path npmExecutablePath = nodeExecutablePath.resolveSibling("npm"); - when(getNodeExecutablePath.execute(ResolveGlobalExecutablePathCommand + when(getNodeExecutablePath.execute(ResolveExecutablePathCommand .builder() .nodeInstallDirectoryPath(NODE_INSTALL_DIRECTORY_PATH) .platform(platform) diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePathTest.java index 1085eaab..6ac5f328 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalCorepackExecutablePathTest.java @@ -12,13 +12,13 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ResolveGlobalCorepackExecutablePathTest { +class ResolveCorepackExecutablePathTest { @Mock private FileManager fileManager; @InjectMocks - private ResolveGlobalCorepackExecutablePath usecase; + private ResolveCorepackExecutablePath usecase; @Test void should_return_relative_executable_path_when_os_is_windows() { diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePathTest.java index c3a928ec..71d31c4c 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNodeExecutablePathTest.java @@ -12,13 +12,13 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ResolveGlobalNodeExecutablePathTest { +class ResolveNodeExecutablePathTest { @Mock private FileManager fileManager; @InjectMocks - private ResolveGlobalNodeExecutablePath usecase; + private ResolveNodeExecutablePath usecase; @Test void should_return_relative_executable_path_when_os_is_windows() { diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePathTest.java index 385e20f9..68614744 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalNpmExecutablePathTest.java @@ -12,13 +12,13 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ResolveGlobalNpmExecutablePathTest { +class ResolveNpmExecutablePathTest { @Mock private FileManager fileManager; @InjectMocks - private ResolveGlobalNpmExecutablePath usecase; + private ResolveNpmExecutablePath usecase; @Test void should_return_relative_executable_path_when_os_is_windows() { diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePathTest.java index 377d4648..113237a6 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalPnpmExecutablePathTest.java @@ -12,13 +12,13 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ResolveGlobalPnpmExecutablePathTest { +class ResolvePnpmExecutablePathTest { @Mock private FileManager fileManager; @InjectMocks - private ResolveGlobalPnpmExecutablePath usecase; + private ResolvePnpmExecutablePath usecase; @Test void should_return_relative_executable_path_when_os_is_windows() { diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePathTest.java index 3497ce70..4512c606 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePathTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/ResolveGlobalYarnExecutablePathTest.java @@ -12,13 +12,13 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ResolveGlobalYarnExecutablePathTest { +class ResolveYarnExecutablePathTest { @Mock private FileManager fileManager; @InjectMocks - private ResolveGlobalYarnExecutablePath usecase; + private ResolveYarnExecutablePath usecase; @Test void should_return_relative_executable_path_when_os_is_windows() { diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPathTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPathTest.java deleted file mode 100644 index 3afa72a0..00000000 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/ResolveNodeInstallDirectoryPathTest.java +++ /dev/null @@ -1,151 +0,0 @@ -package org.siouan.frontendgradleplugin.infrastructure.gradle; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import java.nio.file.Path; -import java.nio.file.Paths; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.gradle.api.Transformer; -import org.gradle.api.provider.Provider; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.stubbing.Answer; - -@ExtendWith(MockitoExtension.class) -class ResolveNodeInstallDirectoryPathTest { - - private static final Path DEFAULT_NODE_INSTALL_DIRECTORY_PATH = Paths.get("node"); - - @Mock - private Provider nodeDistributionProvided; - - @Mock - private Provider nodeInstallDirectoryFromUser; - - @Mock - private Provider defaultNodeInstallDirectory; - - @Mock - private Provider nodeInstallDirectoryFromEnvironment; - - @InjectMocks - private ResolveNodeInstallDirectoryPath resolveNodeInstallDirectoryPath; - - @Test - void should_return_install_directory_from_user_when_defined_and_distribution_is_not_provided() { - when(nodeDistributionProvided.flatMap(any(Transformer.class))).then(new ReturnsTransformerResult(false)); - when(nodeInstallDirectoryFromUser.orElse(DEFAULT_NODE_INSTALL_DIRECTORY_PATH)).thenReturn( - nodeInstallDirectoryFromUser); - - assertThat(resolveNodeInstallDirectoryPath.execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(nodeInstallDirectoryFromUser) - .nodeDistributionProvided(nodeDistributionProvided) - .nodeInstallDirectoryFromEnvironment(nodeInstallDirectoryFromEnvironment) - .defaultPath(DEFAULT_NODE_INSTALL_DIRECTORY_PATH) - .build())).isEqualTo(nodeInstallDirectoryFromUser); - - verifyNoMoreInteractions(nodeDistributionProvided, nodeInstallDirectoryFromUser, defaultNodeInstallDirectory, - nodeInstallDirectoryFromEnvironment); - } - - @Test - void should_return_default_install_directory_when_not_defined_by_user_and_distribution_is_not_provided() { - when(nodeDistributionProvided.flatMap(any(Transformer.class))).then(new ReturnsTransformerResult(false)); - when(nodeInstallDirectoryFromUser.orElse(DEFAULT_NODE_INSTALL_DIRECTORY_PATH)).thenReturn( - defaultNodeInstallDirectory); - - assertThat(resolveNodeInstallDirectoryPath.execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(nodeInstallDirectoryFromUser) - .nodeDistributionProvided(nodeDistributionProvided) - .nodeInstallDirectoryFromEnvironment(nodeInstallDirectoryFromEnvironment) - .defaultPath(DEFAULT_NODE_INSTALL_DIRECTORY_PATH) - .build())).isEqualTo(defaultNodeInstallDirectory); - - verifyNoMoreInteractions(nodeDistributionProvided, nodeInstallDirectoryFromUser, defaultNodeInstallDirectory, - nodeInstallDirectoryFromEnvironment); - } - - @Test - void should_return_install_directory_from_user_when_defined_and_distribution_is_provided() { - when(nodeDistributionProvided.flatMap(any(Transformer.class))).then(new ReturnsTransformerResult(true)); - when(nodeInstallDirectoryFromUser.orElse(nodeInstallDirectoryFromEnvironment)).thenReturn( - nodeInstallDirectoryFromUser); - when(nodeInstallDirectoryFromUser.orElse(DEFAULT_NODE_INSTALL_DIRECTORY_PATH)).thenReturn( - nodeInstallDirectoryFromUser); - - assertThat(resolveNodeInstallDirectoryPath.execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(nodeInstallDirectoryFromUser) - .nodeDistributionProvided(nodeDistributionProvided) - .nodeInstallDirectoryFromEnvironment(nodeInstallDirectoryFromEnvironment) - .defaultPath(DEFAULT_NODE_INSTALL_DIRECTORY_PATH) - .build())).isEqualTo(nodeInstallDirectoryFromUser); - - verifyNoMoreInteractions(nodeDistributionProvided, nodeInstallDirectoryFromUser, defaultNodeInstallDirectory, - nodeInstallDirectoryFromEnvironment); - } - - @Test - void should_return_install_directory_from_environment_when_not_defined_by_user_and_distribution_is_provided() { - when(nodeDistributionProvided.flatMap(any(Transformer.class))).then(new ReturnsTransformerResult(true)); - when(nodeInstallDirectoryFromUser.orElse(nodeInstallDirectoryFromEnvironment)).thenReturn( - nodeInstallDirectoryFromEnvironment); - when(nodeInstallDirectoryFromEnvironment.orElse(DEFAULT_NODE_INSTALL_DIRECTORY_PATH)).thenReturn( - nodeInstallDirectoryFromEnvironment); - - assertThat(resolveNodeInstallDirectoryPath.execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(nodeInstallDirectoryFromUser) - .nodeDistributionProvided(nodeDistributionProvided) - .nodeInstallDirectoryFromEnvironment(nodeInstallDirectoryFromEnvironment) - .defaultPath(DEFAULT_NODE_INSTALL_DIRECTORY_PATH) - .build())).isEqualTo(nodeInstallDirectoryFromEnvironment); - - verifyNoMoreInteractions(nodeDistributionProvided, nodeInstallDirectoryFromUser, defaultNodeInstallDirectory, - nodeInstallDirectoryFromEnvironment); - } - - @Test - void should_return_default_install_directory_when_distribution_is_provided_without_predefined_path() { - when(nodeDistributionProvided.flatMap(any(Transformer.class))).then(new ReturnsTransformerResult(true)); - when(nodeInstallDirectoryFromUser.orElse(nodeInstallDirectoryFromEnvironment)).thenReturn( - nodeInstallDirectoryFromEnvironment); - when(nodeInstallDirectoryFromEnvironment.orElse(DEFAULT_NODE_INSTALL_DIRECTORY_PATH)).thenReturn( - defaultNodeInstallDirectory); - - assertThat(resolveNodeInstallDirectoryPath.execute(ResolveNodeInstallDirectoryPathCommand - .builder() - .nodeInstallDirectoryFromUser(nodeInstallDirectoryFromUser) - .nodeDistributionProvided(nodeDistributionProvided) - .nodeInstallDirectoryFromEnvironment(nodeInstallDirectoryFromEnvironment) - .defaultPath(DEFAULT_NODE_INSTALL_DIRECTORY_PATH) - .build())).isEqualTo(defaultNodeInstallDirectory); - - verifyNoMoreInteractions(nodeDistributionProvided, nodeInstallDirectoryFromUser, defaultNodeInstallDirectory, - nodeInstallDirectoryFromEnvironment); - } - - @RequiredArgsConstructor - @Getter - private static class ReturnsTransformerResult implements Answer> { - - private final boolean nodeDistributionProvided; - - @Override - public Provider answer(final InvocationOnMock invocationOnMock) { - return ((Transformer, Boolean>) invocationOnMock.getArgument(0)).transform( - nodeDistributionProvided); - } - } -} diff --git a/site/src/components/faq/node-install-directory-from-environment-faq.vue b/site/src/components/faq/node-install-directory-from-environment-faq.vue new file mode 100644 index 00000000..7d3c2a28 --- /dev/null +++ b/site/src/components/faq/node-install-directory-from-environment-faq.vue @@ -0,0 +1,39 @@ + + + diff --git a/site/src/components/property/node-distribution-provided-property.vue b/site/src/components/property/node-distribution-provided-property.vue index fb547a36..6ac76174 100644 --- a/site/src/components/property/node-distribution-provided-property.vue +++ b/site/src/components/property/node-distribution-provided-property.vue @@ -1,24 +1,23 @@ diff --git a/site/src/components/property/property.vue b/site/src/components/property/property.vue index d9d4a656..9edbb7b8 100644 --- a/site/src/components/property/property.vue +++ b/site/src/components/property/property.vue @@ -27,7 +27,7 @@ Required: {{ required }}
  • - Default value: {{ defaultScriptValue }} + Default value: {{ defaultTypedValue }}
  • Example: {{ scriptExample }} @@ -80,7 +80,7 @@ export default Vue.component('fgp-property', { }, }, computed: { - defaultScriptValue() { + defaultTypedValue() { if (this.defaultValue === null) { return 'null'; } diff --git a/site/src/components/sub-sub-title.vue b/site/src/components/sub-sub-title.vue index 0ba705e6..0034b743 100644 --- a/site/src/components/sub-sub-title.vue +++ b/site/src/components/sub-sub-title.vue @@ -1,6 +1,6 @@ diff --git a/site/src/components/task/assemble-frontend-task.vue b/site/src/components/task/assemble-frontend-task.vue index 08659100..89e750b9 100644 --- a/site/src/components/task/assemble-frontend-task.vue +++ b/site/src/components/task/assemble-frontend-task.vue @@ -1,8 +1,9 @@