Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing to call mvn or gradle at MAVEN_HOME, GRADLE_HOME respectively in Windows (Resolves #975) #998

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
package org.ngrinder.starter;

import com.sun.jna.Platform;

import java.io.File;
import java.util.List;

import static java.lang.System.*;
Expand All @@ -38,20 +41,19 @@
* */
public enum InstallationChecker {

MAVEN(MAVEN_HOME_ENV_NAME, "mvn -version",
MAVEN(MAVEN_HOME_ENV_NAME, Platform.isWindows() ? "mvn.cmd -version" : "mvn -version",
"Maven isn't installed, You can't run Maven groovy scripts. Please install Maven and set MAVEN_HOME. "),
GRADLE(GRADLE_HOME_ENV_NAME, "gradle -version",
GRADLE(GRADLE_HOME_ENV_NAME, Platform.isWindows() ? "gradle.bat -version" : "gradle -version",
"Gradle isn't installed, You can't run Gradle groovy scripts. Please install Gradle and set GRADLE_HOME.");

private final String homePath;
private final String homeEnvName;
private final String installationCheckingCommand;
private final String warningMessage;

InstallationChecker(String homeEnvName, String installationCheckingCommand, String warningMessage) {
this.homeEnvName = homeEnvName;
this.warningMessage = warningMessage;
this.installationCheckingCommand = installationCheckingCommand;

homePath = getenv(homeEnvName) == null ? "" : getenv(homeEnvName) + "/bin/";
}

public static void checkAll() {
Expand All @@ -63,6 +65,8 @@ public static void checkAll() {
}

private boolean isInstalled() {
String env = getenv(homeEnvName);
String homePath = env == null ? "" : env + File.separator + "bin" + File.separator;
String checkCommand = homePath + installationCheckingCommand;
List<String> result = runNative(checkCommand.split(" "), null);
return !result.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ngrinder.starter;

import org.junit.Test;

public class InstallationCheckerTest {

@Test
public void checkInstalled() {
InstallationChecker.checkAll();
}
}