diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 51301a1e..283c778e 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -26,7 +26,7 @@ Hi,
- OS: [e.g. Ubuntu 18.04.1, Windows 10 Pro, Mac OS X]
- JDK: [e.g. Oracle JDK 11 64 bits]
- Gradle: [e.g. Gradle 6.8]
-- Frontend Gradle plugin: [e.g. 5.1.0 JDK 11]
+- Frontend Gradle plugin: [e.g. 5.2.0 JDK 11]
Settings in `build.gradle[.kts]` file:
```groovy
diff --git a/README.md b/README.md
index 976fe673..9e146213 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
Frontend Gradle plugin - Integrated Node.js, npm, Yarn builds
-
+
@@ -48,6 +48,7 @@ With their feedback, plugin improvement is possible. Special thanks to:
@[ckosloski](https://github.com/ckosloski),
@[davidkron](https://github.com/davidkron),
@[fdw](https://github.com/fdw),
+@[joschi](https://github.com/joschi),
@[jorgheymans](https://github.com/jorgheymans),
@[ludik0](https://github.com/ludik0),
@[mike-howell](https://github.com/mike-howell),
diff --git a/build.gradle.kts b/build.gradle.kts
index ed806b40..cf14e9d1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -123,7 +123,7 @@ sonarqube {
property("sonar.organization", "siouan")
property("sonar.projectKey", "siouan_frontend-gradle-plugin")
property("sonar.projectName", "frontend-gradle-plugin")
- property("sonar.projectVersion", "5.1.0")
+ property("sonar.projectVersion", "5.2.0")
property("sonar.links.homepage", "https://github.com/siouan/frontend-gradle-plugin")
property("sonar.links.ci", "https://travis-ci.com/siouan/frontend-gradle-plugin")
diff --git a/examples/multi-projects-applications-shared-distributions/settings.gradle b/examples/multi-projects-applications-shared-distributions/settings.gradle
index 2c08b9dc..28b0626f 100644
--- a/examples/multi-projects-applications-shared-distributions/settings.gradle
+++ b/examples/multi-projects-applications-shared-distributions/settings.gradle
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
- id 'org.siouan.frontend-jdk11' version '5.1.0'
+ id 'org.siouan.frontend-jdk11' version '5.2.0'
}
repositories {
gradlePluginPortal()
diff --git a/examples/multi-projects-war-application/backend/build.gradle b/examples/multi-projects-war-application/backend/build.gradle
index 15f4aa0d..797588a3 100644
--- a/examples/multi-projects-war-application/backend/build.gradle
+++ b/examples/multi-projects-war-application/backend/build.gradle
@@ -5,7 +5,7 @@ plugins {
id 'io.spring.dependency-management'
}
-version '5.1.0'
+version '5.2.0'
repositories {
mavenCentral()
diff --git a/examples/multi-projects-war-application/settings.gradle b/examples/multi-projects-war-application/settings.gradle
index 9aeded90..2e6aed71 100644
--- a/examples/multi-projects-war-application/settings.gradle
+++ b/examples/multi-projects-war-application/settings.gradle
@@ -4,7 +4,7 @@ pluginManagement {
id 'war'
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
- id 'org.siouan.frontend-jdk11' version '5.1.0'
+ id 'org.siouan.frontend-jdk11' version '5.2.0'
}
repositories {
gradlePluginPortal()
diff --git a/examples/single-project-application-preinstalled-distributions/settings.gradle b/examples/single-project-application-preinstalled-distributions/settings.gradle
index 20fb9530..6661f4e6 100644
--- a/examples/single-project-application-preinstalled-distributions/settings.gradle
+++ b/examples/single-project-application-preinstalled-distributions/settings.gradle
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
- id 'org.siouan.frontend-jdk11' version '5.1.0'
+ id 'org.siouan.frontend-jdk11' version '5.2.0'
}
repositories {
gradlePluginPortal()
diff --git a/examples/single-project-application/settings.gradle b/examples/single-project-application/settings.gradle
index 20fb9530..6661f4e6 100644
--- a/examples/single-project-application/settings.gradle
+++ b/examples/single-project-application/settings.gradle
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
- id 'org.siouan.frontend-jdk11' version '5.1.0'
+ id 'org.siouan.frontend-jdk11' version '5.2.0'
}
repositories {
gradlePluginPortal()
diff --git a/gradle.properties b/gradle.properties
index a79c0c9d..9e9929d2 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
fgpArtifactId=frontend-gradle-plugin-jdk11
fgpGroup=org.siouan
-fgpVersion=5.1.0
+fgpVersion=5.2.0
fgpDisplayName=Frontend Gradle plugin
fgpDescription=Build frontend applications with Node, NPM, Yarn: distribution management, configurable tasks (build, test, publish), additional types, support of NPX.
fgpPluginId=org.siouan.frontend-jdk11
diff --git a/site/build.gradle.kts b/site/build.gradle.kts
index 0c5fc8fd..1b2bfa54 100644
--- a/site/build.gradle.kts
+++ b/site/build.gradle.kts
@@ -1,5 +1,5 @@
plugins {
- id("org.siouan.frontend-jdk11") version "5.0.1"
+ id("org.siouan.frontend-jdk11") version "5.1.0"
}
frontend {
diff --git a/site/package.json b/site/package.json
index 9185dbf8..957d6c43 100644
--- a/site/package.json
+++ b/site/package.json
@@ -2,7 +2,7 @@
"name": "frontend-gradle-plugin-site",
"description": "Frontend Gradle plugin's official site",
"license": "Apache-2.0",
- "version": "5.1.0",
+ "version": "5.2.0",
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
diff --git a/site/src/pages/getting-started.vue b/site/src/pages/getting-started.vue
index f2079c08..a0d972e8 100644
--- a/site/src/pages/getting-started.vue
+++ b/site/src/pages/getting-started.vue
@@ -4,7 +4,7 @@
Requirements
- - 5.1+
+ - 6.1+
- JDK 8+ 64 bits
-
The plugin is built and tested on Linux, Mac OS, Windows (see the list of build environments used in
@@ -23,7 +23,7 @@
Starting from release 3.0.1, ID
org.siouan.frontend and classpath
org.siouan:frontend-gradle-plugin:<version> are deprecated. If you are already using
- the plugin, we recommend upgrading to the latest
+ the plugin, we recommend upgrading to the latest
release as soon as possible.
@@ -41,17 +41,17 @@
plugins {
// For JDK 11+
- id 'org.siouan.frontend-jdk11' version '5.1.0'
+ id 'org.siouan.frontend-jdk11' version '5.2.0'
// For JDK 8+
- id 'org.siouan.frontend-jdk8' version '5.1.0'
+ id 'org.siouan.frontend-jdk8' version '5.2.0'
}
plugins {
// For JDK 11+
- id("org.siouan.frontend-jdk11") version "5.1.0"
+ id("org.siouan.frontend-jdk11") version "5.2.0"
// For JDK 8+
- id("org.siouan.frontend-jdk8") version "5.1.0"
+ id("org.siouan.frontend-jdk8") version "5.2.0"
}
@@ -70,9 +70,9 @@
}
dependencies {
// For JDK 11+
- classpath 'org.siouan:frontend-gradle-plugin-jdk11:5.1.0'
+ classpath 'org.siouan:frontend-gradle-plugin-jdk11:5.2.0'
// For JDK 8+
- classpath 'org.siouan:frontend-gradle-plugin-jdk8:5.1.0'
+ classpath 'org.siouan:frontend-gradle-plugin-jdk8:5.2.0'
}
}
@@ -88,9 +88,9 @@ apply plugin: 'org.siouan.frontend-jdk8'
}
dependencies {
// For JDK 11+
- classpath("org.siouan:frontend-gradle-plugin-jdk11:5.1.0")
+ classpath("org.siouan:frontend-gradle-plugin-jdk11:5.2.0")
// For JDK 8+
- classpath("org.siouan:frontend-gradle-plugin-jdk8:5.1.0")
+ classpath("org.siouan:frontend-gradle-plugin-jdk8:5.2.0")
}
}
diff --git a/site/src/pages/index.vue b/site/src/pages/index.vue
index 4d87eac9..d1759a33 100644
--- a/site/src/pages/index.vue
+++ b/site/src/pages/index.vue
@@ -6,9 +6,9 @@
- Integrated , , builds
diff --git a/site/src/static/sitemap.xml b/site/src/static/sitemap.xml
index c2e6b3b5..c1113e1c 100644
--- a/site/src/static/sitemap.xml
+++ b/site/src/static/sitemap.xml
@@ -4,27 +4,27 @@
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
https://siouan.github.io/frontend-gradle-plugin/
- 2021-05-02
+ 2021-05-30
weekly
https://siouan.github.io/frontend-gradle-plugin/getting-started/
- 2021-05-02
+ 2021-05-30
weekly
https://siouan.github.io/frontend-gradle-plugin/configuration/
- 2021-05-02
+ 2021-05-30
weekly
https://siouan.github.io/frontend-gradle-plugin/node-npm-npx-yarn-tasks/
- 2021-05-02
+ 2021-05-30
weekly
https://siouan.github.io/frontend-gradle-plugin/faqs/
- 2021-05-02
+ 2021-05-30
weekly
diff --git a/src/intTest/java/org/siouan/frontendgradleplugin/test/util/GradleHelper.java b/src/intTest/java/org/siouan/frontendgradleplugin/test/util/GradleHelper.java
index ee7db9bb..d1718dc0 100644
--- a/src/intTest/java/org/siouan/frontendgradleplugin/test/util/GradleHelper.java
+++ b/src/intTest/java/org/siouan/frontendgradleplugin/test/util/GradleHelper.java
@@ -24,7 +24,7 @@
*/
public final class GradleHelper {
- private static final String MINIMAL_GRADLE_VERSION = "5.1";
+ private static final String MINIMAL_GRADLE_VERSION = "6.1";
private GradleHelper() {
}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java b/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java
index 9de07cc2..11d59fd4 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/FrontendGradlePlugin.java
@@ -1,12 +1,8 @@
package org.siouan.frontendgradleplugin;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Optional;
import java.util.function.BiPredicate;
import javax.annotation.Nonnull;
-import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
@@ -16,20 +12,18 @@
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.language.base.plugins.LifecycleBasePlugin;
-import org.siouan.frontendgradleplugin.domain.model.Environment;
-import org.siouan.frontendgradleplugin.domain.model.Platform;
-import org.siouan.frontendgradleplugin.domain.model.SystemProxySettings;
-import org.siouan.frontendgradleplugin.domain.util.SystemUtils;
-import org.siouan.frontendgradleplugin.infrastructure.BeanRegistry;
-import org.siouan.frontendgradleplugin.infrastructure.BeanRegistryException;
+import org.siouan.frontendgradleplugin.domain.model.SystemSettingsProvider;
import org.siouan.frontendgradleplugin.infrastructure.Beans;
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.GradleSettings;
import org.siouan.frontendgradleplugin.infrastructure.gradle.InstallDependenciesTask;
import org.siouan.frontendgradleplugin.infrastructure.gradle.NodeInstallTask;
import org.siouan.frontendgradleplugin.infrastructure.gradle.PublishTask;
+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.gradle.YarnInstallTask;
import org.siouan.frontendgradleplugin.infrastructure.gradle.adapter.GradleLoggerAdapter;
@@ -77,29 +71,29 @@ public class FrontendGradlePlugin implements Plugin {
public static final String PUBLISH_TASK_NAME = "publishFrontend";
/**
- * Name of the task that installs a Node.js distribution.
+ * Default port for the proxy server handling HTTP requests.
*/
- public static final String DEFAULT_NODE_INSTALL_DIRNAME = "node";
+ public static final int DEFAULT_HTTP_PROXY_PORT = 80;
/**
- * URL pattern used to download the Node.js distribution.
+ * Default port for the proxy server handling HTTPS requests.
*/
- public static final String DEFAULT_NODE_DISTRIBUTION_URL_PATH_PATTERN = "vVERSION/node-vVERSION-ARCH.TYPE";
+ public static final int DEFAULT_HTTPS_PROXY_PORT = 443;
/**
- * URL pattern used to download the Node.js distribution.
+ * Name of the task that installs a Node.js distribution.
*/
- public static final String DEFAULT_NODE_DISTRIBUTION_URL_ROOT = "https://nodejs.org/dist/";
+ public static final String DEFAULT_NODE_INSTALL_DIRNAME = "node";
/**
- * Default port for the proxy server handling HTTP requests.
+ * URL pattern used to download the Node.js distribution.
*/
- public static final int DEFAULT_HTTP_PROXY_PORT = 80;
+ public static final String DEFAULT_NODE_DISTRIBUTION_URL_PATH_PATTERN = "vVERSION/node-vVERSION-ARCH.TYPE";
/**
- * Default port for the proxy server handling HTTPS requests.
+ * URL pattern used to download the Node.js distribution.
*/
- public static final int DEFAULT_HTTPS_PROXY_PORT = 443;
+ public static final String DEFAULT_NODE_DISTRIBUTION_URL_ROOT = "https://nodejs.org/dist/";
/**
* URL pattern used to download the Yarn distribution.
@@ -162,17 +156,11 @@ public void apply(final Project project) {
project.getPluginManager().apply(BasePlugin.class);
project.getPluginManager().apply(PublishingPlugin.class);
- final Path nodejsHomePath = getEnvironmentVariable(NODEJS_HOME_ENV_VAR).map(Paths::get).orElse(null);
- final Path yarnHomePath = getEnvironmentVariable(YARN_HOME_ENV_VAR).map(Paths::get).orElse(null);
- final SystemProxySettings systemProxySettings = new SystemProxySettings(SystemUtils.getHttpProxyHost(),
- SystemUtils.getHttpProxyPort().orElse(DEFAULT_HTTP_PROXY_PORT), SystemUtils.getHttpsProxyHost(),
- SystemUtils.getHttpsProxyPort().orElse(DEFAULT_HTTPS_PROXY_PORT), SystemUtils.getNonProxyHosts());
- final Platform platform = new Platform(SystemUtils.getSystemJvmArch(), SystemUtils.getSystemOsName(),
- new Environment(nodejsHomePath, yarnHomePath));
+ final SystemExtension systemExtension = new SystemExtension(project.getProviders());
final FrontendExtension extension = project
.getExtensions()
- .create(EXTENSION_NAME, FrontendExtension.class, project);
+ .create(EXTENSION_NAME, FrontendExtension.class, project.getObjects());
extension.getNodeDistributionProvided().convention(false);
extension.getNodeDistributionUrlRoot().convention(DEFAULT_NODE_DISTRIBUTION_URL_ROOT);
@@ -193,6 +181,22 @@ public void apply(final Project project) {
extension.getHttpsProxyPort().convention(DEFAULT_HTTPS_PROXY_PORT);
extension.getVerboseModeEnabled().convention(false);
+ final SystemSettingsProvider systemSettingsProvider = new SystemSettingsProviderImpl(systemExtension,
+ DEFAULT_HTTP_PROXY_PORT, DEFAULT_HTTPS_PROXY_PORT);
+ final GradleSettings gradleSettings = new GradleSettings(project.getLogging().getLevel(),
+ project.getGradle().getStartParameter().getLogLevel());
+ final String beanRegistryId = Beans.getBeanRegistryId(project.getLayout().getProjectDirectory().toString());
+ Beans.initBeanRegistry(beanRegistryId);
+ Beans.registerBean(beanRegistryId, extension);
+ Beans.registerBean(beanRegistryId, systemSettingsProvider);
+ Beans.registerBean(beanRegistryId, gradleSettings);
+ Beans.registerBean(beanRegistryId, GradleLoggerAdapter.class);
+ Beans.registerBean(beanRegistryId, TaskLoggerConfigurer.class);
+ Beans.registerBean(beanRegistryId, FileManagerImpl.class);
+ Beans.registerBean(beanRegistryId, ChannelProviderImpl.class);
+ Beans.registerBean(beanRegistryId, ArchiverProviderImpl.class);
+ Beans.registerBean(beanRegistryId, HttpClientProviderImpl.class);
+
final TaskContainer taskContainer = project.getTasks();
taskContainer.register(NODE_INSTALL_TASK_NAME, NodeInstallTask.class,
task -> configureNodeInstallTask(task, extension));
@@ -215,24 +219,6 @@ public void apply(final Project project) {
configureDependency(taskContainer, PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME, PUBLISH_TASK_NAME,
PublishTask.class);
- final String beanRegistryId = project.getPath();
- Beans.initBeanRegistry(beanRegistryId);
- Beans.registerBean(beanRegistryId, systemProxySettings);
- Beans.registerBean(beanRegistryId, platform);
- Beans.registerBean(beanRegistryId, GradleLoggerAdapter.class);
- Beans.registerBean(beanRegistryId, FileManagerImpl.class);
- Beans.registerBean(beanRegistryId, ChannelProviderImpl.class);
- Beans.registerBean(beanRegistryId, ArchiverProviderImpl.class);
- Beans.registerBean(beanRegistryId, HttpClientProviderImpl.class);
- try {
- project
- .getGradle()
- .addListener(new TaskLoggerConfigurer(Beans.getBean(beanRegistryId, BeanRegistry.class), extension));
- project.getLogger().debug("Platform: {}", Beans.getBean(beanRegistryId, Platform.class));
- } catch (final BeanRegistryException e) {
- throw new GradleException("Cannot get instance of bean registry", e);
- }
-
project.afterEvaluate(p -> finalizeExtension(extension));
}
@@ -469,15 +455,4 @@ private boolean canDependOn(final T task,
final TaskProvider dependsOnTaskProvider, final BiPredicate condition) {
return dependsOnTaskProvider.isPresent() && condition.test(task, dependsOnTaskProvider.get());
}
-
- /**
- * Gets the value of an environment variable.
- *
- * @param variableName Variable name.
- * @return Variable value.
- */
- @Nonnull
- private Optional getEnvironmentVariable(@Nonnull final String variableName) {
- return Optional.ofNullable(System.getenv(variableName)).filter(value -> !value.trim().isEmpty());
- }
}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemProperty.java b/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemProperty.java
new file mode 100644
index 00000000..921e3259
--- /dev/null
+++ b/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemProperty.java
@@ -0,0 +1,25 @@
+package org.siouan.frontendgradleplugin.domain.model;
+
+import java.util.regex.Pattern;
+
+public final class SystemProperty {
+
+ public static final String JVM_ARCH_PROPERTY = "os.arch";
+
+ public static final String HTTP_PROXY_HOST = "http.proxyHost";
+
+ public static final String HTTP_PROXY_PORT = "http.proxyPort";
+
+ public static final String HTTPS_PROXY_HOST = "https.proxyHost";
+
+ public static final String HTTPS_PROXY_PORT = "https.proxyPort";
+
+ public static final String NON_PROXY_HOSTS = "http.nonProxyHosts";
+
+ public static final String NON_PROXY_HOSTS_SPLIT_PATTERN = Pattern.quote("|");
+
+ public static final String OS_NAME_PROPERTY = "os.name";
+
+ private SystemProperty() {
+ }
+}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemProxySettings.java b/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemProxySettings.java
deleted file mode 100644
index f4d52a55..00000000
--- a/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemProxySettings.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.siouan.frontendgradleplugin.domain.model;
-
-import java.util.Collections;
-import java.util.Set;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-/**
- * System-wide proxy settings.
- *
- * @since 5.0.0
- */
-public class SystemProxySettings {
-
- private final String httpProxyHost;
-
- private final int httpProxyPort;
-
- private final String httpsProxyHost;
-
- private final int httpsProxyPort;
-
- private final Set nonProxyHosts;
-
- public SystemProxySettings(@Nullable final String httpProxyHost, final int httpProxyPort,
- @Nullable final String httpsProxyHost, final int httpsProxyPort, @Nonnull final Set nonProxyHosts) {
- this.httpProxyHost = httpProxyHost;
- this.httpProxyPort = httpProxyPort;
- this.httpsProxyHost = httpsProxyHost;
- this.httpsProxyPort = httpsProxyPort;
- this.nonProxyHosts = Collections.unmodifiableSet(nonProxyHosts);
- }
-
- @Nullable
- public String getHttpProxyHost() {
- return httpProxyHost;
- }
-
- public int getHttpProxyPort() {
- return httpProxyPort;
- }
-
- @Nullable
- public String getHttpsProxyHost() {
- return httpsProxyHost;
- }
-
- public int getHttpsProxyPort() {
- return httpsProxyPort;
- }
-
- @Nonnull
- public Set getNonProxyHosts() {
- return nonProxyHosts;
- }
-
- @Override
- public String toString() {
- return SystemProxySettings.class.getSimpleName() + " {httpProxyHost=" + httpProxyHost + ", httpProxyPort="
- + httpProxyPort + ", httpsProxyHost=" + httpsProxyHost + ", httpsProxyPort=" + httpsProxyPort
- + ", nonProxyHosts=" + nonProxyHosts + '}';
- }
-}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemSettingsProvider.java b/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemSettingsProvider.java
new file mode 100644
index 00000000..3b018eab
--- /dev/null
+++ b/src/main/java/org/siouan/frontendgradleplugin/domain/model/SystemSettingsProvider.java
@@ -0,0 +1,73 @@
+package org.siouan.frontendgradleplugin.domain.model;
+
+import java.nio.file.Path;
+import java.util.Set;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+/**
+ * System-wide settings provider.
+ *
+ * @since 5.2.0
+ */
+public interface SystemSettingsProvider {
+
+ /**
+ * Gets a list of hosts that should be reached directly, bypassing the proxy.
+ *
+ * @return List of patterns separated by '|'. The patterns may start or end with a '*' for wildcards. Any host
+ * matching one of these patterns will be reached through a direct connection instead of through a proxy.
+ */
+ @Nonnull
+ Set getNonProxyHosts();
+
+ /**
+ * Gets the host name of the proxy server for HTTP requests.
+ *
+ * @return Host name.
+ */
+ @Nullable
+ String getHttpProxyHost();
+
+ /**
+ * Gets the port number of the proxy server for HTTP requests.
+ *
+ * @return Port number.
+ */
+ int getHttpProxyPort();
+
+ /**
+ * Gets the host name of the proxy server for HTTPS requests.
+ *
+ * @return Host name.
+ */
+ @Nullable
+ String getHttpsProxyHost();
+
+ /**
+ * Gets the port number of the proxy server for HTTPS requests.
+ *
+ * @return Port number.
+ */
+ int getHttpsProxyPort();
+
+ /**
+ * Gets the current JVM architecture.
+ *
+ * @return String describing the JVM architecture.
+ */
+ @Nonnull
+ String getSystemJvmArch();
+
+ /**
+ * Gets the current O/S name.
+ *
+ * @return String describing the O/S.
+ */
+ @Nonnull
+ String getSystemOsName();
+
+ Path getNodejsHomePath();
+
+ Path getYarnHomePath();
+}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrl.java b/src/main/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrl.java
index 1a53ee58..4043c790 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrl.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrl.java
@@ -6,7 +6,7 @@
import org.siouan.frontendgradleplugin.domain.model.Credentials;
import org.siouan.frontendgradleplugin.domain.model.ProxySettings;
-import org.siouan.frontendgradleplugin.domain.model.SystemProxySettings;
+import org.siouan.frontendgradleplugin.domain.model.SystemSettingsProvider;
/**
* Resolves proxy settings for a given URL.
@@ -21,15 +21,15 @@ public class ResolveProxySettingsByUrl {
private static final String HTTPS_PROTOCOL = "https";
- private final SystemProxySettings systemProxySettings;
+ private final SystemSettingsProvider systemSettingsProvider;
private final IsNonProxyHost isNonProxyHost;
private final SelectProxySettings selectProxySettings;
- public ResolveProxySettingsByUrl(@Nonnull final SystemProxySettings systemProxySettings,
+ public ResolveProxySettingsByUrl(@Nonnull final SystemSettingsProvider systemSettingsProvider,
@Nonnull final IsNonProxyHost isNonProxyHost, @Nonnull final SelectProxySettings selectProxySettings) {
- this.systemProxySettings = systemProxySettings;
+ this.systemSettingsProvider = systemSettingsProvider;
this.isNonProxyHost = isNonProxyHost;
this.selectProxySettings = selectProxySettings;
}
@@ -41,14 +41,14 @@ public ProxySettings execute(@Nullable final String httpProxyHost, final int htt
final String resourceProtocol = resourceUrl.getProtocol();
if (resourceProtocol.equals(HTTP_PROTOCOL) || resourceProtocol.equals(HTTPS_PROTOCOL)) {
- if (isNonProxyHost.execute(systemProxySettings.getNonProxyHosts(), resourceUrl.getHost())) {
+ if (isNonProxyHost.execute(systemSettingsProvider.getNonProxyHosts(), resourceUrl.getHost())) {
return null;
} else if (resourceProtocol.equals(HTTPS_PROTOCOL)) {
- return selectProxySettings.execute(systemProxySettings.getHttpsProxyHost(),
- systemProxySettings.getHttpsProxyPort(), httpsProxyHost, httpsProxyPort, httpsProxyCredentials);
+ return selectProxySettings.execute(systemSettingsProvider.getHttpsProxyHost(),
+ systemSettingsProvider.getHttpsProxyPort(), httpsProxyHost, httpsProxyPort, httpsProxyCredentials);
} else {
- return selectProxySettings.execute(systemProxySettings.getHttpProxyHost(),
- systemProxySettings.getHttpProxyPort(), httpProxyHost, httpProxyPort, httpProxyCredentials);
+ return selectProxySettings.execute(systemSettingsProvider.getHttpProxyHost(),
+ systemSettingsProvider.getHttpProxyPort(), httpProxyHost, httpProxyPort, httpProxyCredentials);
}
} else if (resourceProtocol.equals(FILE_PROTOCOL)) {
return null;
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/Beans.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/Beans.java
index a9f8d8e2..e8a29a95 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/Beans.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/Beans.java
@@ -1,5 +1,7 @@
package org.siouan.frontendgradleplugin.infrastructure;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,6 +34,10 @@ public static void initBeanRegistry(final String registryId) {
.ifPresentOrElse(BeanRegistry::init, () -> INSTANCE.addBeanRegistry(registryId, new BeanRegistry()));
}
+ public static String getBeanRegistryId(@Nonnull final String decodedId) {
+ return Base64.getEncoder().encodeToString(decodedId.getBytes(StandardCharsets.UTF_8));
+ }
+
public static T getBean(@Nonnull final String registryId, @Nonnull final Class beanClass)
throws BeanInstanciationException, TooManyCandidateBeansException, ZeroOrMultiplePublicConstructorsException {
return INSTANCE.findBeanRegistryByIdOrFail(registryId).getBean(beanClass);
@@ -51,8 +57,8 @@ public void addBeanRegistry(@Nonnull final String registryId, @Nonnull final Bea
@Nonnull
public BeanRegistry findBeanRegistryByIdOrFail(@Nonnull final String registryId) {
- return findBeanRegistryById(registryId).orElseThrow(
- () -> new IllegalArgumentException("No registry was found with ID " + registryId));
+ return findBeanRegistryById(registryId)
+ .orElseThrow(() -> new IllegalArgumentException("No registry was found with ID " + registryId));
}
@Nonnull
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractDistributionInstallTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractDistributionInstallTask.java
index 8304a61a..b737abb4 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractDistributionInstallTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractDistributionInstallTask.java
@@ -6,6 +6,8 @@
import javax.annotation.Nullable;
import org.gradle.api.DefaultTask;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;
@@ -18,9 +20,11 @@
import org.siouan.frontendgradleplugin.domain.exception.UnsupportedDistributionIdException;
import org.siouan.frontendgradleplugin.domain.exception.UnsupportedPlatformException;
import org.siouan.frontendgradleplugin.domain.model.Credentials;
+import org.siouan.frontendgradleplugin.domain.model.Environment;
import org.siouan.frontendgradleplugin.domain.model.InstallSettings;
import org.siouan.frontendgradleplugin.domain.model.Platform;
import org.siouan.frontendgradleplugin.domain.model.ProxySettings;
+import org.siouan.frontendgradleplugin.domain.model.SystemSettingsProvider;
import org.siouan.frontendgradleplugin.domain.usecase.AbstractInstallDistribution;
import org.siouan.frontendgradleplugin.domain.usecase.ResolveProxySettingsByUrl;
import org.siouan.frontendgradleplugin.infrastructure.BeanRegistryException;
@@ -31,6 +35,13 @@
*/
public abstract class AbstractDistributionInstallTask extends DefaultTask {
+ /**
+ * Bean registry ID.
+ *
+ * @since 5.2.0
+ */
+ private final String beanRegistryId;
+
/**
* Proxy host used to download resources with HTTP protocol.
*
@@ -87,15 +98,17 @@ public abstract class AbstractDistributionInstallTask extends DefaultTask {
*/
private final Property httpsProxyPassword;
- protected AbstractDistributionInstallTask() {
- this.httpProxyHost = getProject().getObjects().property(String.class);
- this.httpProxyPort = getProject().getObjects().property(Integer.class);
- this.httpProxyUsername = getProject().getObjects().property(String.class);
- this.httpProxyPassword = getProject().getObjects().property(String.class);
- this.httpsProxyHost = getProject().getObjects().property(String.class);
- this.httpsProxyPort = getProject().getObjects().property(Integer.class);
- this.httpsProxyUsername = getProject().getObjects().property(String.class);
- this.httpsProxyPassword = getProject().getObjects().property(String.class);
+ protected AbstractDistributionInstallTask(@Nonnull final ProjectLayout projectLayout,
+ @Nonnull final ObjectFactory objectFactory) {
+ this.beanRegistryId = Beans.getBeanRegistryId(projectLayout.getProjectDirectory().toString());
+ this.httpProxyHost = objectFactory.property(String.class);
+ this.httpProxyPort = objectFactory.property(Integer.class);
+ this.httpProxyUsername = objectFactory.property(String.class);
+ this.httpProxyPassword = objectFactory.property(String.class);
+ this.httpsProxyHost = objectFactory.property(String.class);
+ this.httpsProxyPort = objectFactory.property(Integer.class);
+ this.httpsProxyUsername = objectFactory.property(String.class);
+ this.httpsProxyPassword = objectFactory.property(String.class);
}
@Internal
@@ -153,6 +166,8 @@ public Property getHttpsProxyPassword() {
*/
@TaskAction
public void execute() throws BeanRegistryException, FrontendException, IOException {
+ Beans.getBean(beanRegistryId, TaskLoggerConfigurer.class).initLoggerAdapter(this);
+
final Credentials distributionServerCredentials = getDistributionServerCredentials();
final Credentials httpProxyCredentials = httpProxyUsername
.map(username -> new Credentials(username, httpProxyPassword.get()))
@@ -161,15 +176,19 @@ public void execute() throws BeanRegistryException, FrontendException, IOExcepti
.map(username -> new Credentials(username, httpsProxyPassword.get()))
.getOrNull();
- final String beanRegistryId = getProject().getPath();
+ final SystemSettingsProvider systemSettingsProvider = Beans.getBean(beanRegistryId,
+ SystemSettingsProvider.class);
+ final Platform platform = new Platform(systemSettingsProvider.getSystemJvmArch(),
+ systemSettingsProvider.getSystemOsName(),
+ new Environment(systemSettingsProvider.getNodejsHomePath(), systemSettingsProvider.getYarnHomePath()));
+ getLogger().debug("Platform: {}", platform);
Beans
.getBean(beanRegistryId, getInstallDistributionClass())
- .execute(getInstallSettings(Beans.getBean(beanRegistryId, Platform.class), distributionServerCredentials,
- Beans
- .getBean(beanRegistryId, ResolveProxySettingsByUrl.class)
- .execute(httpProxyHost.getOrNull(), httpProxyPort.get(), httpProxyCredentials,
- httpsProxyHost.getOrNull(), httpsProxyPort.get(), httpsProxyCredentials,
- new URL(getDistributionUrlRoot()))));
+ .execute(getInstallSettings(platform, distributionServerCredentials, Beans
+ .getBean(beanRegistryId, ResolveProxySettingsByUrl.class)
+ .execute(httpProxyHost.getOrNull(), httpProxyPort.get(), httpProxyCredentials,
+ httpsProxyHost.getOrNull(), httpsProxyPort.get(), httpsProxyCredentials,
+ new URL(getDistributionUrlRoot()))));
}
/**
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTask.java
index 74e9a180..67feded6 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunCommandTask.java
@@ -1,16 +1,23 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
import java.io.File;
+import javax.annotation.Nonnull;
import org.gradle.api.DefaultTask;
+import org.gradle.api.GradleException;
import org.gradle.api.file.DirectoryProperty;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;
+import org.gradle.process.ExecOperations;
import org.siouan.frontendgradleplugin.domain.exception.ExecutableNotFoundException;
+import org.siouan.frontendgradleplugin.domain.model.Environment;
import org.siouan.frontendgradleplugin.domain.model.Platform;
+import org.siouan.frontendgradleplugin.domain.model.SystemSettingsProvider;
import org.siouan.frontendgradleplugin.infrastructure.BeanRegistryException;
import org.siouan.frontendgradleplugin.infrastructure.Beans;
import org.siouan.frontendgradleplugin.infrastructure.gradle.adapter.GradleScriptRunnerAdapter;
@@ -22,6 +29,15 @@
*/
public abstract class AbstractRunCommandTask extends DefaultTask {
+ final ExecOperations execOperations;
+
+ /**
+ * Bean registry ID.
+ *
+ * @since 5.2.0
+ */
+ final String beanRegistryId;
+
/**
* Directory where the 'package.json' file is located.
*/
@@ -47,12 +63,27 @@ public abstract class AbstractRunCommandTask extends DefaultTask {
*/
final Property script;
- AbstractRunCommandTask() {
- packageJsonDirectory = getProject().getObjects().property(File.class);
- nodeInstallDirectory = getProject().getObjects().directoryProperty();
- yarnEnabled = getProject().getObjects().property(Boolean.class);
- yarnInstallDirectory = getProject().getObjects().directoryProperty();
- script = getProject().getObjects().property(String.class);
+ AbstractRunCommandTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ this.execOperations = execOperations;
+ this.beanRegistryId = Beans.getBeanRegistryId(projectLayout.getProjectDirectory().toString());
+ this.packageJsonDirectory = objectFactory.property(File.class);
+ this.nodeInstallDirectory = objectFactory.directoryProperty();
+ this.yarnEnabled = objectFactory.property(Boolean.class);
+ this.yarnInstallDirectory = objectFactory.directoryProperty();
+ this.script = objectFactory.property(String.class);
+ final FrontendExtension extension;
+ try {
+ extension = Beans.getBean(beanRegistryId, FrontendExtension.class);
+ } catch (final BeanRegistryException e) {
+ throw new GradleException("Frontend plugin's bean registry failed", e);
+ }
+ this.packageJsonDirectory.set(extension.getPackageJsonDirectory());
+ this.nodeInstallDirectory.set(extension.getNodeInstallDirectory());
+ this.yarnEnabled.set(extension.getYarnEnabled());
+ if (extension.getYarnEnabled().get()) {
+ this.yarnInstallDirectory.set(extension.getYarnInstallDirectory());
+ }
}
@Input
@@ -84,13 +115,19 @@ public DirectoryProperty getYarnInstallDirectory() {
@TaskAction
public void execute() throws ExecutableNotFoundException, BeanRegistryException {
if (script.isPresent()) {
- final String beanRegistryId = getProject().getPath();
+ Beans.getBean(beanRegistryId, TaskLoggerConfigurer.class).initLoggerAdapter(this);
+
+ final SystemSettingsProvider systemSettingsProvider = Beans.getBean(beanRegistryId,
+ SystemSettingsProvider.class);
+ final Platform platform = new Platform(systemSettingsProvider.getSystemJvmArch(),
+ systemSettingsProvider.getSystemOsName(),
+ new Environment(systemSettingsProvider.getNodejsHomePath(), systemSettingsProvider.getYarnHomePath()));
+ getLogger().debug("Platform: {}", platform);
Beans
.getBean(beanRegistryId, GradleScriptRunnerAdapter.class)
- .execute(new ScriptProperties(getProject(), packageJsonDirectory.map(File::toPath).get(),
+ .execute(new ScriptProperties(execOperations, packageJsonDirectory.map(File::toPath).get(),
getExecutableType(), nodeInstallDirectory.getAsFile().map(File::toPath).getOrNull(),
- yarnInstallDirectory.getAsFile().map(File::toPath).getOrNull(), script.get(),
- Beans.getBean(beanRegistryId, Platform.class)));
+ yarnInstallDirectory.getAsFile().map(File::toPath).getOrNull(), script.get(), platform));
}
}
}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunPredefinedCommandTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunPredefinedCommandTask.java
index d7626683..cf7311c3 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunPredefinedCommandTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AbstractRunPredefinedCommandTask.java
@@ -1,7 +1,12 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
+import javax.annotation.Nonnull;
+
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
+import org.gradle.process.ExecOperations;
import org.siouan.frontendgradleplugin.domain.model.ExecutableType;
/**
@@ -9,6 +14,11 @@
*/
public abstract class AbstractRunPredefinedCommandTask extends AbstractRunCommandTask {
+ AbstractRunPredefinedCommandTask(@Nonnull final ProjectLayout projectLayout,
+ @Nonnull final ObjectFactory objectFactory, @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
+ }
+
@Input
public Property getYarnEnabled() {
return yarnEnabled;
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTask.java
index 9979e120..11ce2df1 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/AssembleTask.java
@@ -1,14 +1,26 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
+import org.gradle.process.ExecOperations;
/**
* This task assembles frontend artifacts.
*/
public class AssembleTask extends AbstractRunPredefinedCommandTask {
+ @Inject
+ public AssembleTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
+ }
+
@Input
@Optional
public Property getAssembleScript() {
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTask.java
index 8697baba..0959ee84 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CheckTask.java
@@ -1,14 +1,26 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
+import org.gradle.process.ExecOperations;
/**
* This task executes frontend tests.
*/
public class CheckTask extends AbstractRunPredefinedCommandTask {
+ @Inject
+ public CheckTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
+ }
+
@Input
@Optional
public Property getCheckScript() {
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTask.java
index 6613ee05..007da11c 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/CleanTask.java
@@ -1,14 +1,26 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
+import org.gradle.process.ExecOperations;
/**
* This task cleans frontend resources, using a custom script.
*/
public class CleanTask extends AbstractRunPredefinedCommandTask {
+ @Inject
+ public CleanTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
+ }
+
@Input
@Optional
public Property getCleanScript() {
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java
index f6c433a6..c308643f 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/FrontendExtension.java
@@ -1,9 +1,11 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
import java.io.File;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
-import org.gradle.api.Project;
import org.gradle.api.file.DirectoryProperty;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
/**
@@ -199,37 +201,38 @@ public class FrontendExtension {
*/
private final Property verboseModeEnabled;
- public FrontendExtension(final Project project) {
- nodeDistributionProvided = project.getObjects().property(Boolean.class);
- nodeVersion = project.getObjects().property(String.class);
- nodeInstallDirectory = project.getObjects().directoryProperty();
- nodeDistributionUrlRoot = project.getObjects().property(String.class);
- nodeDistributionUrlPathPattern = project.getObjects().property(String.class);
- nodeDistributionServerUsername = project.getObjects().property(String.class);
- nodeDistributionServerPassword = project.getObjects().property(String.class);
- yarnDistributionProvided = project.getObjects().property(Boolean.class);
- yarnEnabled = project.getObjects().property(Boolean.class);
- yarnVersion = project.getObjects().property(String.class);
- yarnInstallDirectory = project.getObjects().directoryProperty();
- yarnDistributionUrlRoot = project.getObjects().property(String.class);
- yarnDistributionUrlPathPattern = project.getObjects().property(String.class);
- yarnDistributionServerUsername = project.getObjects().property(String.class);
- yarnDistributionServerPassword = project.getObjects().property(String.class);
- installScript = project.getObjects().property(String.class);
- cleanScript = project.getObjects().property(String.class);
- assembleScript = project.getObjects().property(String.class);
- checkScript = project.getObjects().property(String.class);
- publishScript = project.getObjects().property(String.class);
- packageJsonDirectory = project.getObjects().property(File.class);
- httpProxyHost = project.getObjects().property(String.class);
- httpProxyPort = project.getObjects().property(Integer.class);
- httpProxyUsername = project.getObjects().property(String.class);
- httpProxyPassword = project.getObjects().property(String.class);
- httpsProxyHost = project.getObjects().property(String.class);
- httpsProxyPort = project.getObjects().property(Integer.class);
- httpsProxyUsername = project.getObjects().property(String.class);
- httpsProxyPassword = project.getObjects().property(String.class);
- verboseModeEnabled = project.getObjects().property(Boolean.class);
+ @Inject
+ public FrontendExtension(@Nonnull final ObjectFactory objectFactory) {
+ nodeDistributionProvided = objectFactory.property(Boolean.class);
+ nodeVersion = objectFactory.property(String.class);
+ nodeInstallDirectory = objectFactory.directoryProperty();
+ nodeDistributionUrlRoot = objectFactory.property(String.class);
+ nodeDistributionUrlPathPattern = objectFactory.property(String.class);
+ nodeDistributionServerUsername = objectFactory.property(String.class);
+ nodeDistributionServerPassword = objectFactory.property(String.class);
+ yarnDistributionProvided = objectFactory.property(Boolean.class);
+ yarnEnabled = objectFactory.property(Boolean.class);
+ yarnVersion = objectFactory.property(String.class);
+ yarnInstallDirectory = objectFactory.directoryProperty();
+ yarnDistributionUrlRoot = objectFactory.property(String.class);
+ yarnDistributionUrlPathPattern = objectFactory.property(String.class);
+ yarnDistributionServerUsername = objectFactory.property(String.class);
+ yarnDistributionServerPassword = objectFactory.property(String.class);
+ installScript = objectFactory.property(String.class);
+ cleanScript = objectFactory.property(String.class);
+ assembleScript = objectFactory.property(String.class);
+ checkScript = objectFactory.property(String.class);
+ publishScript = objectFactory.property(String.class);
+ packageJsonDirectory = objectFactory.property(File.class);
+ httpProxyHost = objectFactory.property(String.class);
+ httpProxyPort = objectFactory.property(Integer.class);
+ httpProxyUsername = objectFactory.property(String.class);
+ httpProxyPassword = objectFactory.property(String.class);
+ httpsProxyHost = objectFactory.property(String.class);
+ httpsProxyPort = objectFactory.property(Integer.class);
+ httpsProxyUsername = objectFactory.property(String.class);
+ httpsProxyPassword = objectFactory.property(String.class);
+ verboseModeEnabled = objectFactory.property(Boolean.class);
}
public Property getNodeDistributionProvided() {
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/GradleSettings.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/GradleSettings.java
new file mode 100644
index 00000000..c349a1c4
--- /dev/null
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/GradleSettings.java
@@ -0,0 +1,33 @@
+package org.siouan.frontendgradleplugin.infrastructure.gradle;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.gradle.api.logging.LogLevel;
+
+/**
+ * Global settings fixed for the entire build.
+ *
+ * @since 5.2.0
+ */
+public class GradleSettings {
+
+ private final LogLevel projectLogLevel;
+
+ private final LogLevel commandLineLogLevel;
+
+ public GradleSettings(@Nullable final LogLevel projectLogLevel, @Nonnull final LogLevel commandLineLogLevel) {
+ this.projectLogLevel = projectLogLevel;
+ this.commandLineLogLevel = commandLineLogLevel;
+ }
+
+ @Nullable
+ public LogLevel getProjectLogLevel() {
+ return projectLogLevel;
+ }
+
+ @Nonnull
+ public LogLevel getCommandLineLogLevel() {
+ return commandLineLogLevel;
+ }
+}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallDependenciesTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallDependenciesTask.java
index 030d6170..e981bb07 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallDependenciesTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/InstallDependenciesTask.java
@@ -1,7 +1,13 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
+import org.gradle.process.ExecOperations;
/**
* This task installs frontend dependencies (by executing a {@code npm/yarn} command). Optionally, the command may be
@@ -9,6 +15,12 @@
*/
public class InstallDependenciesTask extends AbstractRunPredefinedCommandTask {
+ @Inject
+ public InstallDependenciesTask(@Nonnull final ProjectLayout projectLayout,
+ @Nonnull final ObjectFactory objectFactory, @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
+ }
+
@Input
public Property getInstallScript() {
return script;
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/NodeInstallTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/NodeInstallTask.java
index a76bdf74..fdc17345 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/NodeInstallTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/NodeInstallTask.java
@@ -2,8 +2,11 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.inject.Inject;
import org.gradle.api.file.DirectoryProperty;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
@@ -58,14 +61,15 @@ public class NodeInstallTask extends AbstractDistributionInstallTask {
*/
private final Property nodeDistributionServerPassword;
- public NodeInstallTask() {
- super();
- this.nodeVersion = getProject().getObjects().property(String.class);
- this.nodeInstallDirectory = getProject().getObjects().directoryProperty();
- this.nodeDistributionUrlRoot = getProject().getObjects().property(String.class);
- this.nodeDistributionUrlPathPattern = getProject().getObjects().property(String.class);
- this.nodeDistributionServerUsername = getProject().getObjects().property(String.class);
- this.nodeDistributionServerPassword = getProject().getObjects().property(String.class);
+ @Inject
+ public NodeInstallTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory) {
+ super(projectLayout, objectFactory);
+ this.nodeVersion = objectFactory.property(String.class);
+ this.nodeInstallDirectory = objectFactory.directoryProperty();
+ this.nodeDistributionUrlRoot = objectFactory.property(String.class);
+ this.nodeDistributionUrlPathPattern = objectFactory.property(String.class);
+ this.nodeDistributionServerUsername = objectFactory.property(String.class);
+ this.nodeDistributionServerPassword = objectFactory.property(String.class);
}
@Input
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/PublishTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/PublishTask.java
index 11b3bd9b..79bc8a28 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/PublishTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/PublishTask.java
@@ -1,8 +1,14 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
+import org.gradle.process.ExecOperations;
/**
* This task publishes frontend artifacts.
@@ -11,6 +17,12 @@
*/
public class PublishTask extends AbstractRunPredefinedCommandTask {
+ @Inject
+ public PublishTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
+ }
+
@Input
@Optional
public Property getPublishScript() {
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNode.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNode.java
index 48035c88..fd344f90 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNode.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNode.java
@@ -1,9 +1,13 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
-import java.util.Objects;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
+import org.gradle.process.ExecOperations;
import org.siouan.frontendgradleplugin.domain.model.ExecutableType;
/**
@@ -24,12 +28,10 @@
*/
public class RunNode extends AbstractRunCommandTask {
- public RunNode() {
- super();
- final FrontendExtension extension = Objects.requireNonNull(
- getProject().getExtensions().findByType(FrontendExtension.class));
- packageJsonDirectory.set(extension.getPackageJsonDirectory());
- nodeInstallDirectory.set(extension.getNodeInstallDirectory());
+ @Inject
+ public RunNode(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
}
@Input
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpmYarn.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpmYarn.java
index f747e07c..abdeb9a7 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpmYarn.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpmYarn.java
@@ -1,9 +1,13 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
-import java.util.Objects;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
+import org.gradle.process.ExecOperations;
import org.siouan.frontendgradleplugin.domain.model.ExecutableType;
/**
@@ -21,16 +25,10 @@
*/
public class RunNpmYarn extends AbstractRunCommandTask {
- public RunNpmYarn() {
- super();
- final FrontendExtension extension = Objects.requireNonNull(
- getProject().getExtensions().findByType(FrontendExtension.class));
- packageJsonDirectory.set(extension.getPackageJsonDirectory());
- nodeInstallDirectory.set(extension.getNodeInstallDirectory());
- yarnEnabled.set(extension.getYarnEnabled());
- if (extension.getYarnEnabled().get()) {
- yarnInstallDirectory.set(extension.getYarnInstallDirectory());
- }
+ @Inject
+ public RunNpmYarn(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
}
@Input
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpx.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpx.java
index cde33628..21db9a09 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpx.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/RunNpx.java
@@ -1,9 +1,13 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle;
-import java.util.Objects;
+import javax.annotation.Nonnull;
+import javax.inject.Inject;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
+import org.gradle.process.ExecOperations;
import org.siouan.frontendgradleplugin.domain.exception.ExecutableNotFoundException;
import org.siouan.frontendgradleplugin.domain.model.ExecutableType;
import org.siouan.frontendgradleplugin.infrastructure.BeanRegistryException;
@@ -26,13 +30,10 @@
*/
public class RunNpx extends AbstractRunCommandTask {
- public RunNpx() {
- super();
- final FrontendExtension extension = Objects.requireNonNull(
- getProject().getExtensions().findByType(FrontendExtension.class));
- packageJsonDirectory.set(extension.getPackageJsonDirectory());
- nodeInstallDirectory.set(extension.getNodeInstallDirectory());
- yarnEnabled.set(extension.getYarnEnabled());
+ @Inject
+ public RunNpx(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory,
+ @Nonnull final ExecOperations execOperations) {
+ super(projectLayout, objectFactory, execOperations);
}
@Input
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemExtension.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemExtension.java
new file mode 100644
index 00000000..416b1237
--- /dev/null
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemExtension.java
@@ -0,0 +1,92 @@
+package org.siouan.frontendgradleplugin.infrastructure.gradle;
+
+import org.gradle.api.provider.Provider;
+import org.gradle.api.provider.ProviderFactory;
+import org.siouan.frontendgradleplugin.FrontendGradlePlugin;
+import org.siouan.frontendgradleplugin.domain.model.SystemProperty;
+
+/**
+ * Extension providing system settings.
+ *
+ * @since 5.2.0
+ */
+public class SystemExtension {
+
+ /**
+ * Proxy host used to download resources with HTTP protocol.
+ */
+ private final Provider httpProxyHost;
+
+ /**
+ * Proxy port used to download resources with HTTP protocol.
+ */
+ private final Provider httpProxyPort;
+
+ /**
+ * Proxy host used to download resources with HTTPS protocol.
+ */
+ private final Provider httpsProxyHost;
+
+ /**
+ * Proxy port used to download resources with HTTPS protocol.
+ */
+ private final Provider httpsProxyPort;
+
+ private final Provider nonProxyHosts;
+
+ private final Provider jvmArch;
+
+ private final Provider osName;
+
+ private final Provider nodejsHomePath;
+
+ private final Provider yarnHomePath;
+
+ public SystemExtension(final ProviderFactory providerFactory) {
+ httpProxyHost = providerFactory.systemProperty(SystemProperty.HTTP_PROXY_HOST);
+ httpProxyPort = providerFactory.systemProperty(SystemProperty.HTTP_PROXY_PORT);
+ httpsProxyHost = providerFactory.systemProperty(SystemProperty.HTTPS_PROXY_HOST);
+ httpsProxyPort = providerFactory.systemProperty(SystemProperty.HTTPS_PROXY_PORT);
+ nonProxyHosts = providerFactory.systemProperty(SystemProperty.NON_PROXY_HOSTS);
+ jvmArch = providerFactory.systemProperty(SystemProperty.JVM_ARCH_PROPERTY);
+ osName = providerFactory.systemProperty(SystemProperty.OS_NAME_PROPERTY);
+ nodejsHomePath = providerFactory.environmentVariable(FrontendGradlePlugin.NODEJS_HOME_ENV_VAR);
+ yarnHomePath = providerFactory.environmentVariable(FrontendGradlePlugin.YARN_HOME_ENV_VAR);
+ }
+
+ public Provider getHttpProxyHost() {
+ return httpProxyHost;
+ }
+
+ public Provider getHttpProxyPort() {
+ return httpProxyPort;
+ }
+
+ public Provider getHttpsProxyHost() {
+ return httpsProxyHost;
+ }
+
+ public Provider getHttpsProxyPort() {
+ return httpsProxyPort;
+ }
+
+ public Provider getNonProxyHosts() {
+ return nonProxyHosts;
+ }
+
+ public Provider getJvmArch() {
+ return jvmArch;
+ }
+
+ public Provider getOsName() {
+ return osName;
+ }
+
+ public Provider getNodejsHomePath() {
+ return nodejsHomePath;
+ }
+
+ public Provider getYarnHomePath() {
+ return yarnHomePath;
+ }
+}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemSettingsProviderImpl.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemSettingsProviderImpl.java
new file mode 100644
index 00000000..b50a8d88
--- /dev/null
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemSettingsProviderImpl.java
@@ -0,0 +1,135 @@
+package org.siouan.frontendgradleplugin.infrastructure.gradle;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.gradle.api.provider.Provider;
+import org.siouan.frontendgradleplugin.domain.model.SystemProperty;
+import org.siouan.frontendgradleplugin.domain.model.SystemSettingsProvider;
+
+/**
+ * System-wide proxy settings.
+ *
+ * @since 5.2.0
+ */
+public class SystemSettingsProviderImpl implements SystemSettingsProvider {
+
+ private final Provider httpProxyHost;
+
+ private final Provider httpProxyPort;
+
+ private final Provider httpsProxyHost;
+
+ private final Provider httpsProxyPort;
+
+ private final Provider nonProxyHosts;
+
+ private final Provider jvmArch;
+
+ private final Provider osName;
+
+ private final Provider nodejsHomePath;
+
+ private final Provider yarnHomePath;
+
+ private final int defaultHttpProxyPort;
+
+ private final int defaultHttpsProxyPort;
+
+ public SystemSettingsProviderImpl(@Nonnull final SystemExtension systemExtension, final int defaultHttpProxyPort,
+ final int defaultHttpsProxyPort) {
+ this.httpProxyHost = systemExtension.getHttpProxyHost();
+ this.httpProxyPort = systemExtension.getHttpProxyPort();
+ this.httpsProxyHost = systemExtension.getHttpsProxyHost();
+ this.httpsProxyPort = systemExtension.getHttpsProxyPort();
+ this.nonProxyHosts = systemExtension.getNonProxyHosts();
+ this.jvmArch = systemExtension.getJvmArch();
+ this.osName = systemExtension.getOsName();
+ this.nodejsHomePath = systemExtension.getNodejsHomePath();
+ this.yarnHomePath = systemExtension.getYarnHomePath();
+ this.defaultHttpProxyPort = defaultHttpProxyPort;
+ this.defaultHttpsProxyPort = defaultHttpsProxyPort;
+ }
+
+ @Nullable
+ @Override
+ public String getHttpProxyHost() {
+ return httpProxyHost.getOrNull();
+ }
+
+ @Override
+ public int getHttpProxyPort() {
+ return Optional
+ .ofNullable(httpProxyPort.getOrNull())
+ .filter(port -> !port.isBlank())
+ .map(Integer::parseInt)
+ .orElse(defaultHttpProxyPort);
+ }
+
+ @Nullable
+ @Override
+ public String getHttpsProxyHost() {
+ return httpsProxyHost.getOrNull();
+ }
+
+ @Override
+ public int getHttpsProxyPort() {
+ return Optional
+ .ofNullable(httpsProxyPort.getOrNull())
+ .filter(port -> !port.isBlank())
+ .map(Integer::parseInt)
+ .orElse(defaultHttpsProxyPort);
+ }
+
+ @Nonnull
+ @Override
+ public Set getNonProxyHosts() {
+ return Optional
+ .ofNullable(nonProxyHosts.getOrNull())
+ .filter(Predicate.not(String::isBlank))
+ .map(hosts -> hosts.split(SystemProperty.NON_PROXY_HOSTS_SPLIT_PATTERN))
+ .map(Set::of)
+ .orElseGet(Collections::emptySet);
+ }
+
+ @Nonnull
+ @Override
+ public String getSystemJvmArch() {
+ return jvmArch.get();
+ }
+
+ @Nonnull
+ @Override
+ public String getSystemOsName() {
+ return osName.get();
+ }
+
+ @Nullable
+ @Override
+ public Path getNodejsHomePath() {
+ return toPath(nodejsHomePath.getOrNull());
+ }
+
+ @Nullable
+ @Override
+ public Path getYarnHomePath() {
+ return toPath(yarnHomePath.getOrNull());
+ }
+
+ /**
+ * Gets the value of an environment variable.
+ *
+ * @param value Value.
+ * @return Path
+ */
+ @Nullable
+ private Path toPath(@Nullable final String value) {
+ return Optional.ofNullable(value).filter(v -> !v.trim().isEmpty()).map(Paths::get).orElse(null);
+ }
+}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskLoggerConfigurer.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskLoggerConfigurer.java
index 7f718ee5..c4b9c534 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskLoggerConfigurer.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/TaskLoggerConfigurer.java
@@ -2,14 +2,9 @@
import javax.annotation.Nonnull;
-import org.gradle.api.GradleException;
import org.gradle.api.Task;
-import org.gradle.api.execution.TaskExecutionListener;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.logging.LoggingManager;
-import org.gradle.api.tasks.TaskState;
-import org.siouan.frontendgradleplugin.infrastructure.BeanRegistry;
-import org.siouan.frontendgradleplugin.infrastructure.BeanRegistryException;
import org.siouan.frontendgradleplugin.infrastructure.gradle.adapter.GradleLoggerAdapter;
/**
@@ -17,36 +12,28 @@
*
* @since 2.0.0
*/
-public class TaskLoggerConfigurer implements TaskExecutionListener {
-
- private final BeanRegistry beanRegistry;
+public class TaskLoggerConfigurer {
private final FrontendExtension extension;
- public TaskLoggerConfigurer(final BeanRegistry beanRegistry, final FrontendExtension extension) {
- this.beanRegistry = beanRegistry;
+ private final GradleLoggerAdapter gradleLoggerAdapter;
+
+ private final GradleSettings gradleSettings;
+
+ public TaskLoggerConfigurer(final FrontendExtension extension, final GradleLoggerAdapter gradleLoggerAdapter,
+ final GradleSettings gradleSettings) {
this.extension = extension;
+ this.gradleLoggerAdapter = gradleLoggerAdapter;
+ this.gradleSettings = gradleSettings;
}
- @Override
- public void beforeExecute(@Nonnull final Task task) {
+ public void initLoggerAdapter(@Nonnull final Task task) {
task
.getLogger()
.debug("Configuring logger for task '{}': verboseModeEnabled={}", task.getName(),
extension.getVerboseModeEnabled().get());
- try {
- beanRegistry
- .getBean(GradleLoggerAdapter.class)
- .init(task.getLogger(), resolveLogLevel(task), extension.getVerboseModeEnabled().get(),
- '[' + task.getName() + "] ");
- } catch (final BeanRegistryException e) {
- throw new GradleException("Cannot get instance of bean registry", e);
- }
- }
-
- @Override
- public void afterExecute(@Nonnull final Task task, @Nonnull final TaskState state) {
- // Event not used
+ gradleLoggerAdapter.init(task.getLogger(), resolveLogLevel(task), extension.getVerboseModeEnabled().get(),
+ '[' + task.getName() + "] ");
}
/**
@@ -65,11 +52,11 @@ private LogLevel resolveLogLevel(@Nonnull final Task task) {
return loggingLevel;
}
- loggingLevel = task.getProject().getLogging().getLevel();
+ loggingLevel = gradleSettings.getProjectLogLevel();
if (loggingLevel != null) {
return loggingLevel;
}
- return task.getProject().getGradle().getStartParameter().getLogLevel();
+ return gradleSettings.getCommandLineLogLevel();
}
}
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/YarnInstallTask.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/YarnInstallTask.java
index 2a9d7cbd..eb783372 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/YarnInstallTask.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/YarnInstallTask.java
@@ -2,8 +2,11 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import javax.inject.Inject;
import org.gradle.api.file.DirectoryProperty;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
@@ -58,13 +61,15 @@ public class YarnInstallTask extends AbstractDistributionInstallTask {
*/
private final Property yarnDistributionServerPassword;
- public YarnInstallTask() {
- this.yarnVersion = getProject().getObjects().property(String.class);
- this.yarnInstallDirectory = getProject().getObjects().directoryProperty();
- this.yarnDistributionUrlRoot = getProject().getObjects().property(String.class);
- this.yarnDistributionUrlPathPattern = getProject().getObjects().property(String.class);
- this.yarnDistributionServerUsername = getProject().getObjects().property(String.class);
- this.yarnDistributionServerPassword = getProject().getObjects().property(String.class);
+ @Inject
+ public YarnInstallTask(@Nonnull final ProjectLayout projectLayout, @Nonnull final ObjectFactory objectFactory) {
+ super(projectLayout, objectFactory);
+ this.yarnVersion = objectFactory.property(String.class);
+ this.yarnInstallDirectory = objectFactory.directoryProperty();
+ this.yarnDistributionUrlRoot = objectFactory.property(String.class);
+ this.yarnDistributionUrlPathPattern = objectFactory.property(String.class);
+ this.yarnDistributionServerUsername = objectFactory.property(String.class);
+ this.yarnDistributionServerPassword = objectFactory.property(String.class);
}
@Input
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapter.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapter.java
index 57216495..a950de7d 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapter.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapter.java
@@ -40,7 +40,7 @@ public void execute(@Nonnull final ScriptProperties scriptProperties) throws Exe
logger.debug("Execution settings: {}", executionSettings);
scriptProperties
- .getProject()
+ .getExecOperations()
.exec(new ExecSpecAction(executionSettings, this::logExecSpecBeforeExecution))
.rethrowFailure()
.assertNormalExitValue();
diff --git a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/ScriptProperties.java b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/ScriptProperties.java
index 2d1992ab..ea5c54a9 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/ScriptProperties.java
+++ b/src/main/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/ScriptProperties.java
@@ -4,7 +4,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.gradle.api.Project;
+import org.gradle.process.ExecOperations;
import org.siouan.frontendgradleplugin.domain.model.ExecutableType;
import org.siouan.frontendgradleplugin.domain.model.Platform;
@@ -16,9 +16,9 @@
public class ScriptProperties {
/**
- * Gradle project.
+ * Gradle exec operations.
*/
- private final Project project;
+ private final ExecOperations execOperations;
/**
* Path to the directory containing the {@code package.json} file.
@@ -53,7 +53,7 @@ public class ScriptProperties {
/**
* Builds a job to run a script.
*
- * @param project Gradle project.
+ * @param execOperations Gradle project.
* @param packageJsonDirectoryPath Path to the directory containing the {@code package.json} file.
* @param executableType Executor to use to run the script.
* @param nodeInstallDirectory Node install directory.
@@ -62,10 +62,10 @@ public class ScriptProperties {
* @param platform Underlying platform.
* @see ExecutableType
*/
- public ScriptProperties(@Nonnull final Project project, @Nonnull final Path packageJsonDirectoryPath,
+ public ScriptProperties(@Nonnull final ExecOperations execOperations, @Nonnull final Path packageJsonDirectoryPath,
@Nonnull final String executableType, @Nullable final Path nodeInstallDirectory,
@Nullable final Path yarnInstallDirectory, @Nonnull final String script, @Nonnull final Platform platform) {
- this.project = project;
+ this.execOperations = execOperations;
this.packageJsonDirectoryPath = packageJsonDirectoryPath;
this.executableType = executableType;
this.nodeInstallDirectory = nodeInstallDirectory;
@@ -75,8 +75,8 @@ public ScriptProperties(@Nonnull final Project project, @Nonnull final Path pack
}
@Nonnull
- public Project getProject() {
- return project;
+ public ExecOperations getExecOperations() {
+ return execOperations;
}
@Nonnull
diff --git a/src/test/java/org/siouan/frontendgradleplugin/domain/model/PlatformTest.java b/src/test/java/org/siouan/frontendgradleplugin/domain/model/PlatformTest.java
index 6847018b..77a9789e 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/domain/model/PlatformTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/domain/model/PlatformTest.java
@@ -5,7 +5,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.siouan.frontendgradleplugin.domain.util.SystemUtils;
+import org.siouan.frontendgradleplugin.test.fixture.SystemPropertyFixture;
import org.siouan.frontendgradleplugin.test.fixture.PlatformFixture;
@ExtendWith(MockitoExtension.class)
@@ -13,72 +13,72 @@ class PlatformTest {
@Test
void shouldReturnFalseWhenJvmArchIsNot64Bits() {
- assertThat(PlatformFixture.aPlatform("OS_64_bits", SystemUtils.getSystemOsName()).is64BitsArch()).isFalse();
+ assertThat(PlatformFixture.aPlatform("OS_64_bits", SystemPropertyFixture.getSystemOsName()).is64BitsArch()).isFalse();
}
@Test
void shouldReturnTrueWhenJvmArchContains_x64() {
- assertThat(PlatformFixture.aPlatform("_X64_", SystemUtils.getSystemOsName()).is64BitsArch()).isTrue();
+ assertThat(PlatformFixture.aPlatform("_X64_", SystemPropertyFixture.getSystemOsName()).is64BitsArch()).isTrue();
}
@Test
void shouldReturnTrueWhenJvmArchContains_x86_64() {
- assertThat(PlatformFixture.aPlatform("_X86_64_", SystemUtils.getSystemOsName()).is64BitsArch()).isTrue();
+ assertThat(PlatformFixture.aPlatform("_X86_64_", SystemPropertyFixture.getSystemOsName()).is64BitsArch()).isTrue();
}
@Test
void shouldReturnTrueWhenJvmArchContains_amd64() {
- assertThat(PlatformFixture.aPlatform("_Amd64_", SystemUtils.getSystemOsName()).is64BitsArch()).isTrue();
+ assertThat(PlatformFixture.aPlatform("_Amd64_", SystemPropertyFixture.getSystemOsName()).is64BitsArch()).isTrue();
}
@Test
void shouldReturnTrueWhenJvmArchContains_aarch64() {
- assertThat(PlatformFixture.aPlatform("_Aarch64_", SystemUtils.getSystemOsName()).is64BitsArch())
+ assertThat(PlatformFixture.aPlatform("_Aarch64_", SystemPropertyFixture.getSystemOsName()).is64BitsArch())
.isTrue();
}
@Test
void shouldReturnTrueWhenJvmArchContains_ppc() {
- assertThat(PlatformFixture.aPlatform("_PPC_", SystemUtils.getSystemOsName()).is64BitsArch()).isTrue();
+ assertThat(PlatformFixture.aPlatform("_PPC_", SystemPropertyFixture.getSystemOsName()).is64BitsArch()).isTrue();
}
@Test
void shouldReturnTrueWhenJvmArchContains_sparc() {
- assertThat(PlatformFixture.aPlatform("_Sparc_", SystemUtils.getSystemOsName()).is64BitsArch()).isTrue();
+ assertThat(PlatformFixture.aPlatform("_Sparc_", SystemPropertyFixture.getSystemOsName()).is64BitsArch()).isTrue();
}
@Test
void shouldConfirmArm64ArchWhenJvmArchContains_aarch64() {
- assertThat(PlatformFixture.aPlatform("_Aarch64_", SystemUtils.getSystemOsName()).isArm64BitsArch()).isTrue();
+ assertThat(PlatformFixture.aPlatform("_Aarch64_", SystemPropertyFixture.getSystemOsName()).isArm64BitsArch()).isTrue();
}
@Test
void shouldReturnFalseWhenOsNameDoesNotContain_linux() {
- assertThat(PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "_Unix_").isLinuxOs()).isFalse();
+ assertThat(PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "_Unix_").isLinuxOs()).isFalse();
}
@Test
void shouldReturnTrueWhenOsNameContains_linux() {
- assertThat(PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "_Linux_").isLinuxOs()).isTrue();
+ assertThat(PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "_Linux_").isLinuxOs()).isTrue();
}
@Test
void shouldReturnFalseWhenOsNameDoesNotContain_mac_os() {
- assertThat(PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "_MACOS_").isMacOs()).isFalse();
+ assertThat(PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "_MACOS_").isMacOs()).isFalse();
}
@Test
void shouldReturnTrueWhenOsNameContains_mac_os() {
- assertThat(PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "_Mac OS_").isMacOs()).isTrue();
+ assertThat(PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "_Mac OS_").isMacOs()).isTrue();
}
@Test
void shouldReturnFalseWhenOsNameDoesNotContain_windows() {
- assertThat(PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "_WinNT_").isWindowsOs()).isFalse();
+ assertThat(PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "_WinNT_").isWindowsOs()).isFalse();
}
@Test
void shouldReturnTrueWhenOsNameContains_windows() {
- assertThat(PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "_Windows_").isWindowsOs()).isTrue();
+ assertThat(PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "_Windows_").isWindowsOs()).isTrue();
}
}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/AbstractArchiverTest.java b/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/AbstractArchiverTest.java
index 06ab1e5b..f9ca0d01 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/AbstractArchiverTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/AbstractArchiverTest.java
@@ -39,7 +39,7 @@
import org.siouan.frontendgradleplugin.domain.model.ArchiverContext;
import org.siouan.frontendgradleplugin.domain.model.ExplodeSettings;
import org.siouan.frontendgradleplugin.domain.provider.FileManager;
-import org.siouan.frontendgradleplugin.domain.util.SystemUtils;
+import org.siouan.frontendgradleplugin.test.fixture.SystemPropertyFixture;
import org.siouan.frontendgradleplugin.test.fixture.ArchiveEntryImpl;
import org.siouan.frontendgradleplugin.test.fixture.ArchiverImpl;
import org.siouan.frontendgradleplugin.test.fixture.PlatformFixture;
@@ -173,7 +173,7 @@ void shouldExplodeArchive(final String osName) throws IOException, ArchiverExcep
final Path otherEmptyDirPath = rootDirPath.resolve("other-empty-dir");
final Path rootFilePath = temporaryDirectoryPath.resolve("root-file");
final ExplodeSettings settings = new ExplodeSettings(
- PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), osName), archiveFilePath, temporaryDirectoryPath);
+ PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), osName), archiveFilePath, temporaryDirectoryPath);
when(fileManager.isDirectory(temporaryDirectoryPath)).thenReturn(true);
when(context.getSettings()).thenReturn(settings);
diff --git a/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveExecutionSettingsTest.java b/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveExecutionSettingsTest.java
index 5507ad3f..0d06e681 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveExecutionSettingsTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveExecutionSettingsTest.java
@@ -17,7 +17,7 @@
import org.siouan.frontendgradleplugin.domain.model.ExecutableType;
import org.siouan.frontendgradleplugin.domain.model.ExecutionSettings;
import org.siouan.frontendgradleplugin.domain.model.Platform;
-import org.siouan.frontendgradleplugin.domain.util.SystemUtils;
+import org.siouan.frontendgradleplugin.test.fixture.SystemPropertyFixture;
import org.siouan.frontendgradleplugin.test.fixture.PathFixture;
import org.siouan.frontendgradleplugin.test.fixture.PlatformFixture;
@@ -74,7 +74,7 @@ void shouldFailResolvingExecSettingsWhenExecutablePathCannotBeFound() throws Exe
@Test
void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNodeInPathAndOsIsWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT");
final Path nodeExecutablePath = Paths.get("node");
when(getNodeExecutablePath.execute(null, platform)).thenReturn(nodeExecutablePath);
when(resolveExecutablePath.execute(ExecutableType.NODE, null, null, platform)).thenReturn(nodeExecutablePath);
@@ -93,7 +93,7 @@ void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNodeInPathAndOsIsWin
@Test
void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNodeInDistributionAndOsIsWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
when(
@@ -114,7 +114,7 @@ void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNodeInDistributionAn
@Test
void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNpmInDistributionAndOsIsWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
final Path npmExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("npm");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
@@ -135,7 +135,7 @@ void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNpmInDistributionAnd
@Test
void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNpxInDistributionAndOsIsWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
final Path npxExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("npx");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
@@ -156,7 +156,7 @@ void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsNpxInDistributionAnd
@Test
void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsYarnInDistributionAndNodeIsInDistributionAndOsIsWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
final Path yarnExecutablePath = YARN_INSTALL_DIRECTORY_PATH.resolve("yarn");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
@@ -178,7 +178,7 @@ void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsYarnInDistributionAn
@Test
void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsYarnInPathAndNodeIsInPathAndOsIsWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT");
final Path nodeExecutablePath = Paths.get("node");
final Path yarnExecutablePath = Paths.get("yarn");
when(getNodeExecutablePath.execute(null, platform)).thenReturn(nodeExecutablePath);
@@ -198,7 +198,7 @@ void shouldResolveExecSettingsWithWindowsCmdWhenExecutableIsYarnInPathAndNodeIsI
@Test
void shouldResolveExecSettingsWithUnixShellWhenExecutableIsNodeInPathAndOsIsNotWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Linux");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
when(
@@ -219,7 +219,7 @@ void shouldResolveExecSettingsWithUnixShellWhenExecutableIsNodeInPathAndOsIsNotW
@Test
void shouldResolveExecSettingsWithUnixShellWhenExecutableIsNpmInPathAndOsIsNotWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Linux");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
final Path npmExecutablePath = nodeExecutablePath.resolveSibling("npm");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
@@ -240,7 +240,7 @@ void shouldResolveExecSettingsWithUnixShellWhenExecutableIsNpmInPathAndOsIsNotWi
@Test
void shouldResolveExecSettingsWithUnixShellWhenExecutableIsNpxInPathAndOsIsNotWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Linux");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
final Path npxExecutablePath = nodeExecutablePath.resolveSibling("npx");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
@@ -261,7 +261,7 @@ void shouldResolveExecSettingsWithUnixShellWhenExecutableIsNpxInPathAndOsIsNotWi
@Test
void shouldResolveExecSettingsWithUnixShellWhenExecutableIsYarnInPathAndOsIsNotWindows()
throws ExecutableNotFoundException {
- final Platform platform = PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Linux");
+ final Platform platform = PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux");
final Path nodeExecutablePath = NODE_INSTALL_DIRECTORY_PATH.resolve("node");
final Path yarnExecutablePath = YARN_INSTALL_DIRECTORY_PATH.resolve("yarn");
when(getNodeExecutablePath.execute(NODE_INSTALL_DIRECTORY_PATH, platform)).thenReturn(nodeExecutablePath);
diff --git a/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrlTest.java b/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrlTest.java
index 5cea7ff0..441fca17 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrlTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/domain/usecase/ResolveProxySettingsByUrlTest.java
@@ -17,7 +17,7 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.siouan.frontendgradleplugin.domain.model.Credentials;
import org.siouan.frontendgradleplugin.domain.model.ProxySettings;
-import org.siouan.frontendgradleplugin.domain.model.SystemProxySettings;
+import org.siouan.frontendgradleplugin.domain.model.SystemSettingsProvider;
import org.siouan.frontendgradleplugin.test.fixture.CredentialsFixture;
import org.siouan.frontendgradleplugin.test.fixture.ProxySettingsFixture;
@@ -55,7 +55,7 @@ class ResolveProxySettingsByUrlTest {
private static final int SYSTEM_HTTPS_PROXY_PORT = 91;
@Mock
- private SystemProxySettings systemProxySettings;
+ private SystemSettingsProvider systemSettingsProvider;
@Mock
private IsNonProxyHost isNonProxyHost;
@@ -73,36 +73,36 @@ void shouldFailWhenUrlUsesUnsupportedProtocol() throws MalformedURLException {
assertThatThrownBy(() -> usecase.execute(null, 80, null, null, 443, null, url))
.isInstanceOf(IllegalArgumentException.class);
- verifyNoMoreInteractions(systemProxySettings, isNonProxyHost, selectProxySettings);
+ verifyNoMoreInteractions(systemSettingsProvider, isNonProxyHost, selectProxySettings);
}
@Test
void shouldReturnNullWhenUrlUsesFileProtocol() throws MalformedURLException {
assertThat(usecase.execute(null, 80, null, null, 443, null, new URL(FILE_RESOURCE_URL))).isNull();
- verifyNoMoreInteractions(systemProxySettings, isNonProxyHost, selectProxySettings);
+ verifyNoMoreInteractions(systemSettingsProvider, isNonProxyHost, selectProxySettings);
}
@Test
void shouldReturnNullWhenUrlUsesNonProxyHost() throws MalformedURLException {
final Set nonProxyHosts = Collections.singleton(PLUGIN_HTTP_PROXY_HOST);
- when(systemProxySettings.getNonProxyHosts()).thenReturn(nonProxyHosts);
+ when(systemSettingsProvider.getNonProxyHosts()).thenReturn(nonProxyHosts);
final URL resourceUrl = new URL(HTTP_RESOURCE_URL);
when(isNonProxyHost.execute(nonProxyHosts, resourceUrl.getHost())).thenReturn(true);
assertThat(usecase.execute(null, 80, null, null, 443, null, resourceUrl)).isNull();
- verifyNoMoreInteractions(systemProxySettings, isNonProxyHost, selectProxySettings);
+ verifyNoMoreInteractions(systemSettingsProvider, isNonProxyHost, selectProxySettings);
}
@Test
void shouldReturnHttpProxySettingsWhenUrlUsesNonSecureHttpProtocol() throws MalformedURLException {
final Set nonProxyHosts = Collections.emptySet();
- when(systemProxySettings.getNonProxyHosts()).thenReturn(nonProxyHosts);
+ when(systemSettingsProvider.getNonProxyHosts()).thenReturn(nonProxyHosts);
final URL resourceUrl = new URL(HTTP_RESOURCE_URL);
when(isNonProxyHost.execute(nonProxyHosts, resourceUrl.getHost())).thenReturn(false);
- when(systemProxySettings.getHttpProxyHost()).thenReturn(SYSTEM_HTTP_PROXY_HOST);
- when(systemProxySettings.getHttpProxyPort()).thenReturn(SYSTEM_HTTP_PROXY_PORT);
+ when(systemSettingsProvider.getHttpProxyHost()).thenReturn(SYSTEM_HTTP_PROXY_HOST);
+ when(systemSettingsProvider.getHttpProxyPort()).thenReturn(SYSTEM_HTTP_PROXY_PORT);
final ProxySettings proxySettings = ProxySettingsFixture.someProxySettings();
when(selectProxySettings.execute(SYSTEM_HTTP_PROXY_HOST, SYSTEM_HTTP_PROXY_PORT, PLUGIN_HTTP_PROXY_HOST,
PLUGIN_HTTP_PROXY_PORT, PLUGIN_HTTP_PROXY_CREDENTIALS)).thenReturn(proxySettings);
@@ -111,17 +111,17 @@ void shouldReturnHttpProxySettingsWhenUrlUsesNonSecureHttpProtocol() throws Malf
PLUGIN_HTTPS_PROXY_HOST, PLUGIN_HTTPS_PROXY_PORT, PLUGIN_HTTPS_PROXY_CREDENTIALS, resourceUrl))
.isEqualTo(proxySettings);
- verifyNoMoreInteractions(systemProxySettings, isNonProxyHost, selectProxySettings);
+ verifyNoMoreInteractions(systemSettingsProvider, isNonProxyHost, selectProxySettings);
}
@Test
void shouldReturnHttpsProxySettingsWhenUrlUsesSecureHttpProtocol() throws MalformedURLException {
final Set nonProxyHosts = Collections.emptySet();
- when(systemProxySettings.getNonProxyHosts()).thenReturn(nonProxyHosts);
+ when(systemSettingsProvider.getNonProxyHosts()).thenReturn(nonProxyHosts);
final URL resourceUrl = new URL(HTTPS_RESOURCE_URL);
when(isNonProxyHost.execute(nonProxyHosts, resourceUrl.getHost())).thenReturn(false);
- when(systemProxySettings.getHttpsProxyHost()).thenReturn(SYSTEM_HTTPS_PROXY_HOST);
- when(systemProxySettings.getHttpsProxyPort()).thenReturn(SYSTEM_HTTPS_PROXY_PORT);
+ when(systemSettingsProvider.getHttpsProxyHost()).thenReturn(SYSTEM_HTTPS_PROXY_HOST);
+ when(systemSettingsProvider.getHttpsProxyPort()).thenReturn(SYSTEM_HTTPS_PROXY_PORT);
final ProxySettings proxySettings = ProxySettingsFixture.someProxySettings();
when(selectProxySettings.execute(SYSTEM_HTTPS_PROXY_HOST, SYSTEM_HTTPS_PROXY_PORT, PLUGIN_HTTPS_PROXY_HOST,
PLUGIN_HTTPS_PROXY_PORT, PLUGIN_HTTPS_PROXY_CREDENTIALS)).thenReturn(proxySettings);
@@ -130,6 +130,6 @@ void shouldReturnHttpsProxySettingsWhenUrlUsesSecureHttpProtocol() throws Malfor
PLUGIN_HTTPS_PROXY_HOST, PLUGIN_HTTPS_PROXY_PORT, PLUGIN_HTTPS_PROXY_CREDENTIALS, resourceUrl))
.isEqualTo(proxySettings);
- verifyNoMoreInteractions(systemProxySettings, isNonProxyHost, selectProxySettings);
+ verifyNoMoreInteractions(systemSettingsProvider, isNonProxyHost, selectProxySettings);
}
}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/domain/util/SystemUtilsTest.java b/src/test/java/org/siouan/frontendgradleplugin/domain/util/SystemUtilsTest.java
deleted file mode 100644
index 22e5a4c8..00000000
--- a/src/test/java/org/siouan/frontendgradleplugin/domain/util/SystemUtilsTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.siouan.frontendgradleplugin.domain.util;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-@ExtendWith(MockitoExtension.class)
-class SystemUtilsTest {
-
- @BeforeEach
- @AfterEach
- void clearNetworkProperties() {
- System.setProperty("http.proxyHost", "");
- System.setProperty("http.proxyPort", "");
- System.setProperty("http.nonProxyHosts", "");
- System.setProperty("https.proxyHost", "");
- System.setProperty("https.proxyPort", "");
- }
-
- @Test
- void shouldReturnANonNullStringWhenGettingJvmArch() {
- assertThat(SystemUtils.getSystemJvmArch()).isNotNull();
- }
-
- @Test
- void shouldReturnANonNullStringWhenGettingOsName() {
- assertThat(SystemUtils.getSystemOsName()).isNotNull();
- }
-
- @Test
- void shouldReturnHttpProxyHost() {
- System.setProperty("http.proxyHost", "http-proxy");
-
- assertThat(SystemUtils.getHttpProxyHost()).isEqualTo("http-proxy");
- }
-
- @Test
- void shouldReturnNoHttpProxyPortWhenUndefined() {
- assertThat(SystemUtils.getHttpProxyPort()).isEmpty();
- }
-
- @Test
- void shouldReturnHttpProxyPortWhenNonBlank() {
- System.setProperty("http.proxyPort", "743");
-
- assertThat(SystemUtils.getHttpProxyPort()).contains(743);
- }
-
- @Test
- void shouldReturnNoHttpNonProxyHostsWhenSystemPropertyIsNullOrBlank() {
- assertThat(SystemUtils.getNonProxyHosts()).isEmpty();
- }
-
- @Test
- void shouldReturnHttpNonProxyHostsWhenSystemPropertyIsDefined() {
- System.setProperty("http.nonProxyHosts", "localhost|127.*|[::1]");
-
- assertThat(SystemUtils.getNonProxyHosts()).containsExactlyInAnyOrder("localhost", "127.*", "[::1]");
- }
-
- @Test
- void shouldReturnHttpsProxyHost() {
- System.setProperty("https.proxyHost", "https-proxy");
-
- assertThat(SystemUtils.getHttpsProxyHost()).isEqualTo("https-proxy");
- }
-
- @Test
- void shouldReturnNoHttpsProxyPortWhenUndefined() {
- assertThat(SystemUtils.getHttpsProxyPort()).isEmpty();
- }
-
- @Test
- void shouldReturnHttpsProxyPortWhenNonBlank() {
- System.setProperty("https.proxyPort", "1988");
-
- assertThat(SystemUtils.getHttpsProxyPort()).contains(1988);
- }
-}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemSettingsProviderImplTest.java b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemSettingsProviderImplTest.java
new file mode 100644
index 00000000..dfd47b1c
--- /dev/null
+++ b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/SystemSettingsProviderImplTest.java
@@ -0,0 +1,122 @@
+package org.siouan.frontendgradleplugin.infrastructure.gradle;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import org.gradle.api.provider.Provider;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.siouan.frontendgradleplugin.test.fixture.SystemPropertyFixture;
+
+@ExtendWith(MockitoExtension.class)
+class SystemSettingsProviderImplTest {
+
+ private static final int DEFAULT_HTTP_PROXY_PORT = 80;
+
+ private static final int DEFAULT_HTTPS_PROXY_PORT = 443;
+
+ @Mock
+ private Provider stringProvider;
+
+ @Mock
+ private SystemExtension systemExtension;
+
+ private SystemSettingsProviderImpl systemSettingsProvider;
+
+ @BeforeEach
+ void clearNetworkProperties() {
+ when(systemExtension.getHttpProxyHost()).thenReturn(stringProvider);
+ when(systemExtension.getHttpProxyPort()).thenReturn(stringProvider);
+ when(systemExtension.getHttpsProxyHost()).thenReturn(stringProvider);
+ when(systemExtension.getHttpsProxyPort()).thenReturn(stringProvider);
+ when(systemExtension.getJvmArch()).thenReturn(stringProvider);
+ when(systemExtension.getNodejsHomePath()).thenReturn(stringProvider);
+ when(systemExtension.getNonProxyHosts()).thenReturn(stringProvider);
+ when(systemExtension.getOsName()).thenReturn(stringProvider);
+ when(systemExtension.getYarnHomePath()).thenReturn(stringProvider);
+ systemSettingsProvider = new SystemSettingsProviderImpl(systemExtension, DEFAULT_HTTP_PROXY_PORT,
+ DEFAULT_HTTPS_PROXY_PORT);
+ }
+
+ @Test
+ void shouldReturnJvmArchFromExtension() {
+ final String jvmArch = SystemPropertyFixture.getSystemJvmArch();
+ when(stringProvider.get()).thenReturn(jvmArch);
+
+ assertThat(systemSettingsProvider.getSystemJvmArch()).isEqualTo(jvmArch);
+ }
+
+ @Test
+ void shouldReturnOsNameFromExtension() {
+ final String osName = SystemPropertyFixture.getSystemOsName();
+ when(stringProvider.get()).thenReturn(osName);
+
+ assertThat(systemSettingsProvider.getSystemOsName()).isEqualTo(osName);
+ }
+
+ @Test
+ void shouldReturnHttpProxyHostFromExtension() {
+ final String httpProxyHost = "http-proxy";
+ when(stringProvider.getOrNull()).thenReturn(httpProxyHost);
+
+ assertThat(systemSettingsProvider.getHttpProxyHost()).isEqualTo(httpProxyHost);
+ }
+
+ @Test
+ void shouldReturnNoHttpProxyPortFromExtension() {
+ when(stringProvider.getOrNull()).thenReturn(null);
+
+ assertThat(systemSettingsProvider.getHttpProxyPort()).isEqualTo(DEFAULT_HTTP_PROXY_PORT);
+
+ verifyNoMoreInteractions(systemExtension);
+ }
+
+ @Test
+ void shouldReturnHttpProxyPortWhenNonBlank() {
+ final String httpProxyPort = "743";
+ when(stringProvider.getOrNull()).thenReturn(httpProxyPort);
+
+ assertThat(systemSettingsProvider.getHttpProxyPort()).hasToString(httpProxyPort);
+ }
+
+ @Test
+ void shouldReturnNoHttpNonProxyHostsWhenSystemPropertyIsNullOrBlank() {
+ when(stringProvider.getOrNull()).thenReturn(null);
+
+ assertThat(systemSettingsProvider.getNonProxyHosts()).isEmpty();
+ }
+
+ @Test
+ void shouldReturnHttpNonProxyHostsWhenSystemPropertyIsDefined() {
+ when(stringProvider.getOrNull()).thenReturn("localhost|127.*|[::1]");
+
+ assertThat(systemSettingsProvider.getNonProxyHosts()).containsExactlyInAnyOrder("localhost", "127.*", "[::1]");
+ }
+
+ @Test
+ void shouldReturnHttpsProxyHostFromExtension() {
+ final String httpsProxyHost = "https-proxy";
+ when(stringProvider.getOrNull()).thenReturn(httpsProxyHost);
+
+ assertThat(systemSettingsProvider.getHttpsProxyHost()).isEqualTo(httpsProxyHost);
+ }
+
+ @Test
+ void shouldReturnNoHttpsProxyPortFromExtension() {
+ when(stringProvider.getOrNull()).thenReturn(null);
+
+ assertThat(systemSettingsProvider.getHttpsProxyPort()).isEqualTo(DEFAULT_HTTPS_PROXY_PORT);
+ }
+
+ @Test
+ void shouldReturnHttpsProxyPortWhenNonBlank() {
+ final String httpsProxyPort = "1988";
+ when(stringProvider.getOrNull()).thenReturn(httpsProxyPort);
+
+ assertThat(systemSettingsProvider.getHttpsProxyPort()).hasToString(httpsProxyPort);
+ }
+}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapterTest.java b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapterTest.java
index b05306e1..3db3f47a 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapterTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/GradleScriptRunnerAdapterTest.java
@@ -14,7 +14,7 @@
import java.util.List;
import java.util.Set;
-import org.gradle.api.Project;
+import org.gradle.process.ExecOperations;
import org.gradle.process.ExecResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,7 +38,7 @@ class GradleScriptRunnerAdapterTest {
private static final String SCRIPT = "script";
@Mock
- private Project project;
+ private ExecOperations execOperations;
@Mock
private ResolveExecutionSettings resolveExecutionSettings;
@@ -53,24 +53,24 @@ void setUp() {
@Test
void shouldFailResolvingExecSettingsWhenExecutableIsNotFound() throws ExecutableNotFoundException {
- final ScriptProperties scriptProperties = new ScriptProperties(project,
+ final ScriptProperties scriptProperties = new ScriptProperties(execOperations,
PathFixture.ANY_PATH.resolve("frontend"), ExecutableType.NPM, PathFixture.ANY_PATH.resolve("node"),
PathFixture.ANY_PATH.resolve("yarn"), SCRIPT, PlatformFixture.LOCAL_PLATFORM);
final ExecutableNotFoundException expectedException = new ExecutableNotFoundException(Paths.get("exe"));
when(resolveExecutionSettings.execute(scriptProperties.getPackageJsonDirectoryPath(),
scriptProperties.getExecutableType(), scriptProperties.getNodeInstallDirectory(),
- scriptProperties.getYarnInstallDirectory(), scriptProperties.getPlatform(),
- scriptProperties.getScript())).thenThrow(expectedException);
+ scriptProperties.getYarnInstallDirectory(), scriptProperties.getPlatform(), scriptProperties.getScript()))
+ .thenThrow(expectedException);
assertThatThrownBy(() -> adapter.execute(scriptProperties)).isEqualTo(expectedException);
- verifyNoMoreInteractions(resolveExecutionSettings, project);
+ verifyNoMoreInteractions(resolveExecutionSettings, execOperations);
}
@Test
void shouldRunScriptWhenSettingsAreResolved() throws ExecutableNotFoundException {
final Path nodeInstallationDirectory = PathFixture.ANY_PATH.resolve("node");
- final ScriptProperties scriptProperties = new ScriptProperties(project,
+ final ScriptProperties scriptProperties = new ScriptProperties(execOperations,
PathFixture.ANY_PATH.resolve("frontend"), ExecutableType.NPM, nodeInstallationDirectory,
PathFixture.ANY_PATH.resolve("yarn"), SCRIPT, PlatformFixture.LOCAL_PLATFORM);
final Set executablePaths = emptySet();
@@ -79,17 +79,17 @@ void shouldRunScriptWhenSettingsAreResolved() throws ExecutableNotFoundException
executablePaths, nodeInstallationDirectory.resolve("npm"), arguments);
when(resolveExecutionSettings.execute(scriptProperties.getPackageJsonDirectoryPath(),
scriptProperties.getExecutableType(), scriptProperties.getNodeInstallDirectory(),
- scriptProperties.getYarnInstallDirectory(), scriptProperties.getPlatform(),
- scriptProperties.getScript())).thenReturn(executionSettings);
+ scriptProperties.getYarnInstallDirectory(), scriptProperties.getPlatform(), scriptProperties.getScript()))
+ .thenReturn(executionSettings);
final ExecResult execResult = mock(ExecResult.class);
- when(project.exec(
- argThat(new ExecSpecActionMatcher(new ExecSpecAction(executionSettings, execSpec -> {}))))).thenReturn(
- execResult);
+ when(execOperations.exec(
+ argThat(new ExecSpecActionMatcher(new ExecSpecAction(executionSettings, execSpec -> {})))))
+ .thenReturn(execResult);
when(execResult.rethrowFailure()).thenReturn(execResult);
adapter.execute(scriptProperties);
verify(execResult).assertNormalExitValue();
- verifyNoMoreInteractions(resolveExecutionSettings, project, execResult);
+ verifyNoMoreInteractions(resolveExecutionSettings, execOperations, execResult);
}
}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/TaskLoggerConfigurerTest.java b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/TaskLoggerConfigurerTest.java
index 121174dd..d02ed119 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/TaskLoggerConfigurerTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/gradle/adapter/TaskLoggerConfigurerTest.java
@@ -1,32 +1,23 @@
package org.siouan.frontendgradleplugin.infrastructure.gradle.adapter;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import org.gradle.StartParameter;
-import org.gradle.api.Project;
import org.gradle.api.Task;
-import org.gradle.api.invocation.Gradle;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.LoggingManager;
import org.gradle.api.provider.Property;
-import org.gradle.api.tasks.TaskState;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.siouan.frontendgradleplugin.infrastructure.BeanInstanciationException;
-import org.siouan.frontendgradleplugin.infrastructure.BeanRegistry;
-import org.siouan.frontendgradleplugin.infrastructure.TooManyCandidateBeansException;
-import org.siouan.frontendgradleplugin.infrastructure.ZeroOrMultiplePublicConstructorsException;
import org.siouan.frontendgradleplugin.infrastructure.gradle.FrontendExtension;
+import org.siouan.frontendgradleplugin.infrastructure.gradle.GradleSettings;
import org.siouan.frontendgradleplugin.infrastructure.gradle.TaskLoggerConfigurer;
@ExtendWith(MockitoExtension.class)
@@ -39,9 +30,6 @@ class TaskLoggerConfigurerTest {
@Mock
private Property verboseModeEnabled;
- @Mock
- private BeanRegistry beanRegistry;
-
@Mock
private Logger gradleLogger;
@@ -51,116 +39,63 @@ class TaskLoggerConfigurerTest {
@Mock
private LoggingManager taskLoggingManager;
- @Mock
- private LoggingManager projectLoggingManager;
-
- @Mock
- private Project project;
-
- @Mock
- private Gradle gradle;
-
@Mock
private GradleLoggerAdapter adapter;
@Mock
private FrontendExtension extension;
- private TaskLoggerConfigurer taskLoggerConfigurer;
-
- @BeforeEach
- void setUp() {
- taskLoggerConfigurer = new TaskLoggerConfigurer(beanRegistry, extension);
- }
-
- @Test
- void shouldFailBeforeTaskExecutionWhenLoggerIsNotInstanciable()
- throws BeanInstanciationException, TooManyCandidateBeansException, ZeroOrMultiplePublicConstructorsException {
- when(task.getName()).thenReturn(TASK_NAME);
- when(task.getLogger()).thenReturn(gradleLogger);
- when(extension.getVerboseModeEnabled()).thenReturn(verboseModeEnabled);
- when(verboseModeEnabled.get()).thenReturn(false);
- final ZeroOrMultiplePublicConstructorsException expectedException = mock(
- ZeroOrMultiplePublicConstructorsException.class);
- when(beanRegistry.getBean(GradleLoggerAdapter.class)).thenThrow(expectedException);
-
- assertThatThrownBy(() -> taskLoggerConfigurer.beforeExecute(task))
- .isInstanceOf(RuntimeException.class)
- .hasCause(expectedException);
+ @Mock
+ private GradleSettings gradleSettings;
- verifyNoMoreInteractions(beanRegistry, task, taskLoggingManager, project, projectLoggingManager, gradle,
- adapter);
- }
+ @InjectMocks
+ private TaskLoggerConfigurer taskLoggerConfigurer;
@Test
- void shouldInitLoggerBeforeTaskExecutionWithTaskLevel()
- throws BeanInstanciationException, TooManyCandidateBeansException, ZeroOrMultiplePublicConstructorsException {
+ void shouldInitLoggerBeforeTaskExecutionWithTaskLevel() {
when(task.getName()).thenReturn(TASK_NAME);
when(task.getLogger()).thenReturn(gradleLogger);
when(task.getLogging()).thenReturn(taskLoggingManager);
when(taskLoggingManager.getLevel()).thenReturn(LOGGING_LEVEL);
when(extension.getVerboseModeEnabled()).thenReturn(verboseModeEnabled);
when(verboseModeEnabled.get()).thenReturn(true);
- when(beanRegistry.getBean(GradleLoggerAdapter.class)).thenReturn(adapter);
- taskLoggerConfigurer.beforeExecute(task);
+ taskLoggerConfigurer.initLoggerAdapter(task);
verify(adapter).init(eq(gradleLogger), eq(LOGGING_LEVEL), eq(true), anyString());
- verifyNoMoreInteractions(beanRegistry, task, taskLoggingManager, project, projectLoggingManager, gradle,
- adapter);
+ verifyNoMoreInteractions(task, taskLoggingManager, adapter, gradleSettings);
}
@Test
- void shouldInitLoggerBeforeTaskExecutionWithProjectLevel()
- throws BeanInstanciationException, TooManyCandidateBeansException, ZeroOrMultiplePublicConstructorsException {
+ void shouldInitLoggerBeforeTaskExecutionWithProjectLevel() {
when(task.getName()).thenReturn(TASK_NAME);
when(task.getLogger()).thenReturn(gradleLogger);
when(task.getLogging()).thenReturn(taskLoggingManager);
- when(task.getProject()).thenReturn(project);
- when(project.getLogging()).thenReturn(projectLoggingManager);
- when(projectLoggingManager.getLevel()).thenReturn(LOGGING_LEVEL);
+ when(gradleSettings.getProjectLogLevel()).thenReturn(LOGGING_LEVEL);
when(extension.getVerboseModeEnabled()).thenReturn(verboseModeEnabled);
when(verboseModeEnabled.get()).thenReturn(true);
- when(beanRegistry.getBean(GradleLoggerAdapter.class)).thenReturn(adapter);
- taskLoggerConfigurer.beforeExecute(task);
+ taskLoggerConfigurer.initLoggerAdapter(task);
verify(adapter).init(eq(gradleLogger), eq(LOGGING_LEVEL), eq(true), anyString());
verify(taskLoggingManager).getLevel();
- verifyNoMoreInteractions(beanRegistry, task, taskLoggingManager, project, projectLoggingManager, gradle,
- adapter);
+ verifyNoMoreInteractions(task, taskLoggingManager, adapter, gradleSettings);
}
@Test
- void shouldInitLoggerBeforeTaskExecutionWithGradleStartLevel()
- throws BeanInstanciationException, TooManyCandidateBeansException, ZeroOrMultiplePublicConstructorsException {
+ void shouldInitLoggerBeforeTaskExecutionWithGradleStartLevel() {
when(task.getName()).thenReturn(TASK_NAME);
when(task.getLogger()).thenReturn(gradleLogger);
when(task.getLogging()).thenReturn(taskLoggingManager);
- when(task.getProject()).thenReturn(project);
- when(project.getLogging()).thenReturn(projectLoggingManager);
- when(project.getGradle()).thenReturn(gradle);
- final StartParameter startParameter = new StartParameter();
- startParameter.setLogLevel(LOGGING_LEVEL);
- when(gradle.getStartParameter()).thenReturn(startParameter);
+ when(gradleSettings.getProjectLogLevel()).thenReturn(null);
+ when(gradleSettings.getCommandLineLogLevel()).thenReturn(LOGGING_LEVEL);
when(extension.getVerboseModeEnabled()).thenReturn(verboseModeEnabled);
when(verboseModeEnabled.get()).thenReturn(true);
- when(beanRegistry.getBean(GradleLoggerAdapter.class)).thenReturn(adapter);
- taskLoggerConfigurer.beforeExecute(task);
+ taskLoggerConfigurer.initLoggerAdapter(task);
verify(adapter).init(eq(gradleLogger), eq(LOGGING_LEVEL), eq(true), anyString());
verify(taskLoggingManager).getLevel();
- verify(projectLoggingManager).getLevel();
- verifyNoMoreInteractions(beanRegistry, task, taskLoggingManager, project, projectLoggingManager, gradle,
- adapter);
- }
-
- @Test
- void shouldDoNothingAfterTaskExecution() {
- taskLoggerConfigurer.afterExecute(task, mock(TaskState.class));
-
- verifyNoMoreInteractions(beanRegistry, task, taskLoggingManager, project, projectLoggingManager, gradle,
- adapter);
+ verifyNoMoreInteractions(task, taskLoggingManager, adapter, gradleSettings);
}
}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/provider/FileManagerImplTest.java b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/provider/FileManagerImplTest.java
index 32a3d6a6..358545f4 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/infrastructure/provider/FileManagerImplTest.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/infrastructure/provider/FileManagerImplTest.java
@@ -9,7 +9,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.siouan.frontendgradleplugin.domain.util.SystemUtils;
+import org.siouan.frontendgradleplugin.test.fixture.SystemPropertyFixture;
import org.siouan.frontendgradleplugin.test.fixture.PlatformFixture;
@ExtendWith(MockitoExtension.class)
@@ -21,12 +21,12 @@ class FileManagerImplTest {
@Test
void shouldNotTouchFilePermissionsWhenOsIsWindows() throws IOException {
assertThat(fileProvider.setFileExecutable(Paths.get("afile"),
- PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT"))).isFalse();
+ PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Windows NT"))).isFalse();
}
@Test
void shouldNotTouchFilePermissionsWhenFileNotFound() throws IOException {
assertThat(fileProvider.setFileExecutable(Paths.get("afile"),
- PlatformFixture.aPlatform(SystemUtils.getSystemJvmArch(), "Linux"))).isFalse();
+ PlatformFixture.aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux"))).isFalse();
}
}
diff --git a/src/test/java/org/siouan/frontendgradleplugin/test/fixture/PlatformFixture.java b/src/test/java/org/siouan/frontendgradleplugin/test/fixture/PlatformFixture.java
index eed4041f..d9397b8f 100644
--- a/src/test/java/org/siouan/frontendgradleplugin/test/fixture/PlatformFixture.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/test/fixture/PlatformFixture.java
@@ -3,16 +3,16 @@
import javax.annotation.Nonnull;
import org.siouan.frontendgradleplugin.domain.model.Platform;
-import org.siouan.frontendgradleplugin.domain.util.SystemUtils;
public final class PlatformFixture {
- public static final Platform LOCAL_PLATFORM = aPlatform(SystemUtils.getSystemJvmArch(),
- SystemUtils.getSystemOsName());
+ public static final Platform LOCAL_PLATFORM = aPlatform(SystemPropertyFixture.getSystemJvmArch(),
+ SystemPropertyFixture.getSystemOsName());
- public static final Platform ANY_WINDOWS_PLATFORM = aPlatform(SystemUtils.getSystemJvmArch(), "Windows NT");
+ public static final Platform ANY_WINDOWS_PLATFORM = aPlatform(SystemPropertyFixture.getSystemJvmArch(),
+ "Windows NT");
- public static final Platform ANY_UNIX_PLATFORM = aPlatform(SystemUtils.getSystemJvmArch(), "Linux");
+ public static final Platform ANY_UNIX_PLATFORM = aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux");
public static final Platform ANY_NON_WINDOWS_PLATFORM = ANY_UNIX_PLATFORM;
@@ -20,7 +20,7 @@ private PlatformFixture() {
}
public static Platform aPlatform() {
- return aPlatform(SystemUtils.getSystemJvmArch(), "Linux");
+ return aPlatform(SystemPropertyFixture.getSystemJvmArch(), "Linux");
}
public static Platform aPlatform(@Nonnull final String jvmArch, @Nonnull final String osName) {
diff --git a/src/main/java/org/siouan/frontendgradleplugin/domain/util/SystemUtils.java b/src/test/java/org/siouan/frontendgradleplugin/test/fixture/SystemPropertyFixture.java
similarity index 65%
rename from src/main/java/org/siouan/frontendgradleplugin/domain/util/SystemUtils.java
rename to src/test/java/org/siouan/frontendgradleplugin/test/fixture/SystemPropertyFixture.java
index 94852672..7d4c4349 100644
--- a/src/main/java/org/siouan/frontendgradleplugin/domain/util/SystemUtils.java
+++ b/src/test/java/org/siouan/frontendgradleplugin/test/fixture/SystemPropertyFixture.java
@@ -1,37 +1,22 @@
-package org.siouan.frontendgradleplugin.domain.util;
+package org.siouan.frontendgradleplugin.test.fixture;
import java.util.Collections;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.siouan.frontendgradleplugin.domain.model.SystemProperty;
+
/**
* This class provides utilities to get system information.
*
* @since 2.0.0
*/
-public final class SystemUtils {
-
- private static final String JVM_ARCH_PROPERTY = "os.arch";
-
- private static final String HTTP_PROXY_HOST = "http.proxyHost";
-
- private static final String HTTP_PROXY_PORT = "http.proxyPort";
-
- private static final String HTTPS_PROXY_HOST = "https.proxyHost";
-
- private static final String HTTPS_PROXY_PORT = "https.proxyPort";
-
- private static final String NON_PROXY_HOSTS = "http.nonProxyHosts";
-
- private static final String NON_PROXY_HOSTS_SPLIT_PATTERN = Pattern.quote("|");
-
- private static final String OS_NAME_PROPERTY = "os.name";
+public final class SystemPropertyFixture {
- private SystemUtils() {
+ private SystemPropertyFixture() {
}
/**
@@ -42,9 +27,9 @@ private SystemUtils() {
*/
@Nonnull
public static Set getNonProxyHosts() {
- final String nonProxyHosts = System.getProperty(NON_PROXY_HOSTS);
+ final String nonProxyHosts = System.getProperty(SystemProperty.NON_PROXY_HOSTS);
return ((nonProxyHosts == null) || nonProxyHosts.isBlank()) ? Collections.emptySet()
- : Set.of(nonProxyHosts.split(NON_PROXY_HOSTS_SPLIT_PATTERN));
+ : Set.of(nonProxyHosts.split(SystemProperty.NON_PROXY_HOSTS_SPLIT_PATTERN));
}
/**
@@ -54,7 +39,7 @@ public static Set getNonProxyHosts() {
*/
@Nullable
public static String getHttpProxyHost() {
- return System.getProperty(HTTP_PROXY_HOST);
+ return System.getProperty(SystemProperty.HTTP_PROXY_HOST);
}
/**
@@ -63,7 +48,7 @@ public static String getHttpProxyHost() {
* @return Port number.
*/
public static Optional getHttpProxyPort() {
- final String httpProxyPort = System.getProperty(HTTP_PROXY_PORT);
+ final String httpProxyPort = System.getProperty(SystemProperty.HTTP_PROXY_PORT);
return Optional.ofNullable(httpProxyPort).filter(port -> !port.isBlank()).map(Integer::parseInt);
}
@@ -74,7 +59,7 @@ public static Optional getHttpProxyPort() {
*/
@Nullable
public static String getHttpsProxyHost() {
- return System.getProperty(HTTPS_PROXY_HOST);
+ return System.getProperty(SystemProperty.HTTPS_PROXY_HOST);
}
/**
@@ -83,7 +68,7 @@ public static String getHttpsProxyHost() {
* @return Port number.
*/
public static Optional getHttpsProxyPort() {
- final String httpsProxyPort = System.getProperty(HTTPS_PROXY_PORT);
+ final String httpsProxyPort = System.getProperty(SystemProperty.HTTPS_PROXY_PORT);
return Optional.ofNullable(httpsProxyPort).filter(port -> !port.isBlank()).map(Integer::parseInt);
}
@@ -94,7 +79,7 @@ public static Optional getHttpsProxyPort() {
*/
@Nonnull
public static String getSystemJvmArch() {
- return getPropertyAndAssertNotNull(JVM_ARCH_PROPERTY);
+ return getPropertyAndAssertNotNull(SystemProperty.JVM_ARCH_PROPERTY);
}
/**
@@ -104,7 +89,7 @@ public static String getSystemJvmArch() {
*/
@Nonnull
public static String getSystemOsName() {
- return getPropertyAndAssertNotNull(OS_NAME_PROPERTY);
+ return getPropertyAndAssertNotNull(SystemProperty.OS_NAME_PROPERTY);
}
@Nonnull
diff --git a/src/test/java/org/siouan/frontendgradleplugin/test/fixture/SystemProxySettingsFixture.java b/src/test/java/org/siouan/frontendgradleplugin/test/fixture/SystemProxySettingsFixture.java
deleted file mode 100644
index 414f8980..00000000
--- a/src/test/java/org/siouan/frontendgradleplugin/test/fixture/SystemProxySettingsFixture.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.siouan.frontendgradleplugin.test.fixture;
-
-import java.util.Set;
-
-import org.siouan.frontendgradleplugin.domain.model.SystemProxySettings;
-
-public final class SystemProxySettingsFixture {
-
- private SystemProxySettingsFixture() {
- }
-
- public static SystemProxySettings defaultSystemProxySettings() {
- return new SystemProxySettings(null, 80, null, 443, Set.of("localhost", "127.*", "[::1]"));
- }
-}