Skip to content

Commit 865364c

Browse files
Revert strict check for JAVA_HOME
Due to change in runtime, we do not need strict check for JAVA_HOME, so revert the logic introduced yesterday.
1 parent bdbf39c commit 865364c

File tree

4 files changed

+16
-52
lines changed

4 files changed

+16
-52
lines changed

lib/android-tools-info.ts

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -156,63 +156,28 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
156156
}).future<boolean>()();
157157
}
158158

159-
public validateJava(javacVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean> {
159+
public validateJavacVersion(installedJavaVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean> {
160160
return ((): boolean => {
161+
let hasProblemWithJavaVersion = false;
161162
if(options) {
162163
this.showWarningsAsErrors = options.showWarningsAsErrors;
163164
}
164-
165-
let helpfulMessage = "You will not be able to build your projects for Android." + EOL
165+
let additionalMessage = "You will not be able to build your projects for Android." + EOL
166166
+ "To be able to build for Android, verify that you have installed The Java Development Kit (JDK) and configured it according to system requirements as" + EOL +
167167
" described in https://github.com/NativeScript/nativescript-cli#system-requirements.";
168-
169-
let hasProblemWithJavaHome = this.validateJavaHome(helpfulMessage).wait();
170-
let hasProblemWithJavaVersion: boolean;
171-
if(!hasProblemWithJavaHome) {
172-
hasProblemWithJavaVersion = this.validateJavacVersion(javacVersion, helpfulMessage);
173-
}
174-
175-
return hasProblemWithJavaHome || hasProblemWithJavaVersion;
176-
}).future<boolean>()();
177-
}
178-
179-
private validateJavaHome(helpfulMessage: string): IFuture<boolean> {
180-
return ((): boolean => {
181-
let hasProblemWithJavaHome = false;
182-
let javaHome = process.env.JAVA_HOME;
183-
184-
if(javaHome) {
185-
// validate jarsigner as it does not exist in JRE, but is mandatory for JDK and Android Runtime
186-
let jarSigner = path.join(javaHome, "bin", "jarsigner");
187-
let childProcessResult = this.$childProcess.spawnFromEvent(jarSigner, [], "close", {}, { throwError: false }).wait();
188-
this.$logger.trace(`Result of calling jarsigner from path: ${jarSigner}:`, childProcessResult);
189-
if(childProcessResult.stderr || childProcessResult.exitCode !== 0) {
190-
hasProblemWithJavaHome = true;
191-
this.printMessage("JAVA_HOME environment variable points to incorrect path. Make sure it points to the installation directory of JDK.", helpfulMessage);
168+
let matchingVersion = (installedJavaVersion || "").match(AndroidToolsInfo.VERSION_REGEX);
169+
if(matchingVersion && matchingVersion[1]) {
170+
if(semver.lt(matchingVersion[1], AndroidToolsInfo.MIN_JAVA_VERSION)) {
171+
hasProblemWithJavaVersion = true;
172+
this.printMessage(`Javac version ${installedJavaVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, additionalMessage);
192173
}
193174
} else {
194-
hasProblemWithJavaHome = true;
195-
this.printMessage("JAVA_HOME environment variable is not set.", helpfulMessage);
196-
}
197-
198-
return hasProblemWithJavaHome;
199-
}).future<boolean>()();
200-
}
201-
202-
private validateJavacVersion(installedJavaVersion: string, helpfulMessage: string): boolean {
203-
let hasProblemWithJavaVersion = false;
204-
let matchingVersion = (installedJavaVersion || "").match(AndroidToolsInfo.VERSION_REGEX);
205-
if(matchingVersion && matchingVersion[1]) {
206-
if(semver.lt(matchingVersion[1], AndroidToolsInfo.MIN_JAVA_VERSION)) {
207175
hasProblemWithJavaVersion = true;
208-
this.printMessage(`Javac version ${installedJavaVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, helpfulMessage);
176+
this.printMessage("Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.", additionalMessage);
209177
}
210-
} else {
211-
hasProblemWithJavaVersion = true;
212-
this.printMessage("Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.", helpfulMessage);
213-
}
214178

215-
return hasProblemWithJavaVersion;
179+
return hasProblemWithJavaVersion;
180+
}).future<boolean>()();
216181
}
217182

218183
public getPathToAdbFromAndroidHome(): IFuture<string> {

lib/declarations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ interface IAndroidToolsInfo {
161161
validateInfo(options?: {showWarningsAsErrors: boolean, validateTargetSdk: boolean}): IFuture<boolean>;
162162

163163
/**
164-
* Validates the information about required JAVA version and JAVA_HOME.
165-
* @param {string} javacVersion The JAVA version that will be checked.
164+
* Validates the information about required JAVA version.
165+
* @param {string} installedJavaVersion The JAVA version that will be checked.
166166
* @param {any} options Defines if the warning messages should treated as error.
167167
* @return {boolean} True if there are detected issues, false otherwise.
168168
*/
169-
validateJava(javacVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean>;
169+
validateJavacVersion(installedJavaVersion: string, options?: {showWarningsAsErrors: boolean}): IFuture<boolean>;
170170

171171
/**
172172
* Returns the path to `android` executable. It should be `$ANDROID_HOME/tools/android`.

lib/services/android-project-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
8888

8989
// this call will fail in case `android` is not set correctly.
9090
this.$androidToolsInfo.getPathToAndroidExecutable({showWarningsAsErrors: true}).wait();
91-
this.$androidToolsInfo.validateJava(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait();
91+
this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait();
9292
}).future<void>()();
9393
}
9494

lib/services/doctor-service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ class DoctorService implements IDoctorService {
8888
}
8989

9090
let androidToolsIssues = this.$androidToolsInfo.validateInfo().wait();
91-
let javaVersionIssue = this.$androidToolsInfo.validateJava(sysInfo.javacVersion).wait();
92-
91+
let javaVersionIssue = this.$androidToolsInfo.validateJavacVersion(sysInfo.javacVersion).wait();
9392
let doctorResult = result || androidToolsIssues || javaVersionIssue;
9493

9594
if(!configOptions || configOptions.trackResult) {

0 commit comments

Comments
 (0)