Skip to content

Commit cf3fefb

Browse files
author
IceBuildUser
committed
Merge remote-tracking branch 'origin/release' into HEAD
2 parents 7cbc8f6 + b5897c4 commit cf3fefb

File tree

11 files changed

+59
-74
lines changed

11 files changed

+59
-74
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/commands/plugin/remove-plugin.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
export class RemovePluginCommand implements ICommand {
55
constructor(private $pluginsService: IPluginsService,
6-
private $errors: IErrors) { }
6+
private $errors: IErrors,
7+
private $logger: ILogger,
8+
private $projectData: IProjectData) { }
79

810
execute(args: string[]): IFuture<void> {
911
return this.$pluginsService.remove(args[0]);
@@ -15,9 +17,18 @@ export class RemovePluginCommand implements ICommand {
1517
this.$errors.fail("You must specify plugin name.");
1618
}
1719

18-
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
20+
let pluginNames: string[] = [];
21+
try {
22+
// try installing the plugins, so we can get information from node_modules about their native code, libs, etc.
23+
let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait();
24+
pluginNames = installedPlugins.map(pl => pl.name);
25+
} catch(err) {
26+
this.$logger.trace("Error while installing plugins. Error is:", err);
27+
pluginNames = _.keys(this.$projectData.dependencies);
28+
}
29+
1930
let pluginName = args[0].toLowerCase();
20-
if(!_.any(installedPlugins, (plugin: IPluginData) => plugin.name.toLowerCase() === pluginName)) {
31+
if(!_.any(pluginNames, name => name.toLowerCase() === pluginName)) {
2132
this.$errors.failWithoutHelp(`Plugin "${pluginName}" is not installed.`);
2233
}
2334

lib/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class StaticConfig extends StaticConfigBase implements IStaticConfig {
2727
public CLIENT_NAME = "tns";
2828
public CLIENT_NAME_ALIAS = "NativeScript";
2929
public ANALYTICS_API_KEY = "5752dabccfc54c4ab82aea9626b7338e";
30+
public ANALYTICS_FEATURE_USAGE_TRACKING_API_KEY = "9912cff308334c6d9ad9c33f76a983e3";
3031
public TRACK_FEATURE_USAGE_SETTING_NAME = "TrackFeatureUsage";
3132
public ERROR_REPORT_SETTING_NAME = "TrackExceptions";
3233
public ANALYTICS_INSTALLATION_ID_SETTING_NAME = "AnalyticsInstallationID";

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/definitions/plugins.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ interface IPluginVariablesService {
3636
savePluginVariablesInProjectFile(pluginData: IPluginData): IFuture<void>;
3737
/**
3838
* Removes plugin variables from project package.json file.
39-
* @param {IPluginData} pluginData for the plugin.
39+
* @param {string} pluginName Name of the plugin.
4040
* @return {IFuture<void>}
4141
*/
42-
removePluginVariablesFromProjectFile(pluginData: IPluginData): IFuture<void>;
42+
removePluginVariablesFromProjectFile(pluginName: string): IFuture<void>;
4343
/**
4444
* Replaces all plugin variables with their corresponding values.
4545
* @param {IPluginData} pluginData for the plugin.
@@ -59,10 +59,10 @@ interface IPluginVariablesService {
5959
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string): IFuture<void>;
6060
/**
6161
* Returns the
62-
* @param {IPluginData} pluginData for the plugin.
62+
* @param {string} pluginName for the plugin.
6363
* @return {IFuture<string>} returns the changed plugin configuration file content.
6464
*/
65-
getPluginVariablePropertyName(pluginData: IPluginData): string;
65+
getPluginVariablePropertyName(pluginName: string): string;
6666

6767
}
6868

lib/nativescript-cli.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as fiber from "fibers";
99
import Future = require("fibers/future");
1010
import * as shelljs from "shelljs";
1111
shelljs.config.silent = true;
12-
shelljs.config.fatal = true;
1312
import {installUncaughtExceptionListener} from "./common/errors";
1413
installUncaughtExceptionListener(process.exit);
1514

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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ let clui = require("clui");
88
class DoctorService implements IDoctorService {
99
private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
1010

11-
constructor(private $androidToolsInfo: IAndroidToolsInfo,
11+
constructor(private $analyticsService: IAnalyticsService,
12+
private $androidToolsInfo: IAndroidToolsInfo,
1213
private $hostInfo: IHostInfo,
1314
private $logger: ILogger,
1415
private $progressIndicator: IProgressIndicator,
@@ -18,7 +19,7 @@ class DoctorService implements IDoctorService {
1819
private $npm: INodePackageManager,
1920
private $fs: IFileSystem) { }
2021

21-
public printWarnings(): boolean {
22+
public printWarnings(configOptions?: { trackResult: boolean }): boolean {
2223
let result = false;
2324
let sysInfo = this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait();
2425

@@ -87,8 +88,14 @@ class DoctorService implements IDoctorService {
8788
}
8889

8990
let androidToolsIssues = this.$androidToolsInfo.validateInfo().wait();
90-
let javaVersionIssue = this.$androidToolsInfo.validateJava(sysInfo.javacVersion).wait();
91-
return result || androidToolsIssues || javaVersionIssue;
91+
let javaVersionIssue = this.$androidToolsInfo.validateJavacVersion(sysInfo.javacVersion).wait();
92+
let doctorResult = result || androidToolsIssues || javaVersionIssue;
93+
94+
if(!configOptions || configOptions.trackResult) {
95+
this.$analyticsService.track("DoctorEnvironmentSetup", doctorResult ? "incorrect" : "correct").wait();
96+
}
97+
98+
return doctorResult;
9299
}
93100

94101
private printPackageManagerTip() {

lib/services/plugin-variables-service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class PluginVariablesService implements IPluginVariablesService {
1313
private $prompter: IPrompter,
1414
private $fs: IFileSystem) { }
1515

16-
public getPluginVariablePropertyName(pluginData: IPluginData): string {
17-
return `${pluginData.name}-${PluginVariablesService.PLUGIN_VARIABLES_KEY}`;
16+
public getPluginVariablePropertyName(pluginName: string): string {
17+
return `${pluginName}-${PluginVariablesService.PLUGIN_VARIABLES_KEY}`;
1818
}
1919

2020
public savePluginVariablesInProjectFile(pluginData: IPluginData): IFuture<void> {
@@ -29,14 +29,14 @@ export class PluginVariablesService implements IPluginVariablesService {
2929

3030
if(!_.isEmpty(values)) {
3131
this.$projectDataService.initialize(this.$projectData.projectDir);
32-
this.$projectDataService.setValue(this.getPluginVariablePropertyName(pluginData), values).wait();
32+
this.$projectDataService.setValue(this.getPluginVariablePropertyName(pluginData.name), values).wait();
3333
}
3434
}).future<void>()();
3535
}
3636

37-
public removePluginVariablesFromProjectFile(pluginData: IPluginData): IFuture<void> {
37+
public removePluginVariablesFromProjectFile(pluginName: string): IFuture<void> {
3838
this.$projectDataService.initialize(this.$projectData.projectDir);
39-
return this.$projectDataService.removeProperty(this.getPluginVariablePropertyName(pluginData));
39+
return this.$projectDataService.removeProperty(this.getPluginVariablePropertyName(pluginName));
4040
}
4141

4242
public interpolatePluginVariables(pluginData: IPluginData, pluginConfigurationFilePath: string): IFuture<void> {
@@ -115,7 +115,7 @@ export class PluginVariablesService implements IPluginVariablesService {
115115
variableData.name = pluginVariableName;
116116

117117
this.$projectDataService.initialize(this.$projectData.projectDir);
118-
let pluginVariableValues = this.$projectDataService.getValue(this.getPluginVariablePropertyName(pluginData)).wait();
118+
let pluginVariableValues = this.$projectDataService.getValue(this.getPluginVariablePropertyName(pluginData.name)).wait();
119119
variableData.value = pluginVariableValues ? pluginVariableValues[pluginVariableName] : undefined;
120120

121121
return variableData;

0 commit comments

Comments
 (0)