Skip to content

Cherry-pick commits for 3.4.1 release #3310

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

Merged
merged 4 commits into from
Jan 9, 2018
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
NativeScript CLI Changelog
================

3.4.0 (2017, December 20)
==

### New
* [Implemented #3171](https://github.com/NativeScript/nativescript-cli/issues/3171): Make --chrome the default for tns debug ios

### Fixed
* [Fixed #3268](https://github.com/NativeScript/nativescript-cli/issues/3268): tns run android - EMFILE: too many open files
* [Fixed #3202](https://github.com/NativeScript/nativescript-cli/issues/3202): `tns update <version>` does not work
* [Fixed #3187](https://github.com/NativeScript/nativescript-cli/issues/3187): Android tns debug, crashing when there is a response from server

3.3.1 (2017, November 17)
==

### Fixed
* [Fixed #3164](https://github.com/NativeScript/nativescript-cli/issues/3164): `npm run build-*-bundle` gets stuck at nativescript-unit-test-runner hook.
* [Fixed #3182](https://github.com/NativeScript/nativescript-cli/issues/3182): CLI fails when unable to start Analytics Broker process.
Expand Down
17 changes: 12 additions & 5 deletions lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from "path";
import * as semver from "semver";
import { EOL } from "os";
import { cache } from "./common/decorators";
import { appendZeroesToVersion } from './common/helpers';

export class AndroidToolsInfo implements IAndroidToolsInfo {
private static ANDROID_TARGET_PREFIX = "android";
Expand All @@ -10,6 +11,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
private static REQUIRED_BUILD_TOOLS_RANGE_PREFIX = ">=23";
private static VERSION_REGEX = /((\d+\.){2}\d+)/;
private static MIN_JAVA_VERSION = "1.8.0";
private static MAX_JAVA_VERSION = "1.9.0";

private showWarningsAsErrors: boolean;
private toolsInfo: IAndroidToolsInfoData;
Expand Down Expand Up @@ -101,7 +103,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
return detectedErrors || !isAndroidHomeValid;
}

public async validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): Promise<boolean> {
public validateJavacVersion(installedJavacVersion: string, options?: { showWarningsAsErrors: boolean }): boolean {
let hasProblemWithJavaVersion = false;
if (options) {
this.showWarningsAsErrors = options.showWarningsAsErrors;
Expand All @@ -110,11 +112,16 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
const additionalMessage = "You will not be able to build your projects for Android." + EOL
+ "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 +
" described in " + this.$staticConfig.SYS_REQUIREMENTS_LINK;
const matchingVersion = (installedJavaVersion || "").match(AndroidToolsInfo.VERSION_REGEX);
if (matchingVersion && matchingVersion[1]) {
if (semver.lt(matchingVersion[1], AndroidToolsInfo.MIN_JAVA_VERSION)) {

const matchingVersion = appendZeroesToVersion(installedJavacVersion || "", 3).match(AndroidToolsInfo.VERSION_REGEX);
const installedJavaCompilerVersion = matchingVersion && matchingVersion[1];
if (installedJavaCompilerVersion) {
if (semver.lt(installedJavaCompilerVersion, AndroidToolsInfo.MIN_JAVA_VERSION)) {
hasProblemWithJavaVersion = true;
this.printMessage(`Javac version ${installedJavacVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, additionalMessage);
} else if (semver.gte(installedJavaCompilerVersion, AndroidToolsInfo.MAX_JAVA_VERSION)) {
hasProblemWithJavaVersion = true;
this.printMessage(`Javac version ${installedJavaVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, additionalMessage);
this.printMessage(`Javac version ${installedJavacVersion} is not supported. You have to install version ${AndroidToolsInfo.MIN_JAVA_VERSION}.`, additionalMessage);
}
} else {
hasProblemWithJavaVersion = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ interface IAndroidToolsInfo {
* @param {any} options Defines if the warning messages should treated as error.
* @return {boolean} True if there are detected issues, false otherwise.
*/
validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): Promise<boolean>;
validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): boolean;

/**
* Validates if ANDROID_HOME environment variable is set correctly.
Expand Down
2 changes: 1 addition & 1 deletion lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

const javaCompilerVersion = await this.$sysInfo.getJavaCompilerVersion();

await this.$androidToolsInfo.validateJavacVersion(javaCompilerVersion, { showWarningsAsErrors: true });
this.$androidToolsInfo.validateJavacVersion(javaCompilerVersion, { showWarningsAsErrors: true });

await this.$androidToolsInfo.validateInfo({ showWarningsAsErrors: true, validateTargetSdk: true });
}
Expand Down
4 changes: 2 additions & 2 deletions lib/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class DoctorService implements IDoctorService {
}

const androidToolsIssues = this.$androidToolsInfo.validateInfo();
const javaVersionIssue = await this.$androidToolsInfo.validateJavacVersion(sysInfo.javacVersion);
const javaCompilerVersionIssue = this.$androidToolsInfo.validateJavacVersion(sysInfo.javacVersion);
const pythonIssues = await this.validatePythonPackages();
const doctorResult = result || androidToolsIssues || javaVersionIssue || pythonIssues;
const doctorResult = result || androidToolsIssues || javaCompilerVersionIssue || pythonIssues;

if (!configOptions || configOptions.trackResult) {
await this.$analyticsService.track("DoctorEnvironmentSetup", doctorResult ? "incorrect" : "correct");
Expand Down
2 changes: 1 addition & 1 deletion lib/services/subscription-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SubscriptionService implements ISubscriptionService {

public async subscribeForNewsletter(): Promise<void> {
if (await this.shouldAskForEmail()) {
this.$logger.out("Leave your e-mail address here to subscribe for NativeScript newsletter and product updates, tips and tricks:");
this.$logger.out("Enter your e-mail address to subscribe to the NativeScript Newsletter and hear about product updates, tips & tricks, and community happenings:");
const email = await this.getEmail("(press Enter for blank)");
await this.$userSettingsService.saveSetting("EMAIL_REGISTERED", true);
await this.sendEmail(email);
Expand Down
112 changes: 112 additions & 0 deletions test/android-tools-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Yok } from "../lib/common/yok";
import { AndroidToolsInfo } from "../lib/android-tools-info";
import { EOL } from "os";
import { format } from "util";
import { assert } from "chai";

interface ITestData {
javacVersion: string;
expectedResult: boolean;
warnings?: string[];
}

describe("androidToolsInfo", () => {
let loggedWarnings: string[] = [];
let loggedMarkdownMessages: string[] = [];
const sysRequirementsLink = "";

const additionalMsg = "You will not be able to build your projects for Android." + EOL
+ "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 +
" described in " + sysRequirementsLink;

beforeEach(() => {
loggedWarnings = [];
loggedMarkdownMessages = [];
});

const createTestInjector = (): IInjector => {
const testInjector = new Yok();
testInjector.register("childProcess", {});
testInjector.register("errors", {
failWithoutHelp: (message: string, ...args: any[]): any => {
const loggedError = format(message, args);
throw new Error(loggedError);
}
});
testInjector.register("fs", {});
testInjector.register("hostInfo", {});
testInjector.register("logger", {
warn: (...args: string[]): void => {
loggedWarnings.push(format.apply(null, args));
},

printMarkdown: (...args: string[]): void => {
loggedMarkdownMessages.push(format.apply(null, args));
}
});
testInjector.register("options", {});
testInjector.register("staticConfig", {
SYS_REQUIREMENTS_LINK: sysRequirementsLink
});
return testInjector;
};

describe("validateJavacVersion", () => {
const testData: ITestData[] = [
{
javacVersion: "1.8.0",
expectedResult: false
},
{
javacVersion: "1.8.0_152",
expectedResult: false
},
{
javacVersion: "9",
expectedResult: true,
warnings: ["Javac version 9 is not supported. You have to install version 1.8.0."]
},
{
javacVersion: "9.0.1",
expectedResult: true,
warnings: ["Javac version 9.0.1 is not supported. You have to install version 1.8.0."]
},
{
javacVersion: "1.7.0",
expectedResult: true,
warnings: ["Javac version 1.7.0 is not supported. You have to install at least 1.8.0."]
},
{
javacVersion: "1.7.0_132",
expectedResult: true,
warnings: ["Javac version 1.7.0_132 is not supported. You have to install at least 1.8.0."]
},
{
javacVersion: null,
expectedResult: true,
warnings: ["Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable."]
}
];

_.each(testData, ({ javacVersion, expectedResult, warnings }) => {
it(`returns ${expectedResult} when version is ${javacVersion}`, () => {
const testInjector = createTestInjector();
const androidToolsInfo = testInjector.resolve<IAndroidToolsInfo>(AndroidToolsInfo);
assert.deepEqual(androidToolsInfo.validateJavacVersion(javacVersion), expectedResult);
if (warnings && warnings.length) {
assert.deepEqual(loggedWarnings, warnings);
assert.deepEqual(loggedMarkdownMessages, [additionalMsg]);
} else {
assert.equal(loggedWarnings.length, 0);
assert.equal(loggedMarkdownMessages.length, 0);
}
});
});

it("throws error when passing showWarningsAsErrors to true and javac is not installed", () => {
const testInjector = createTestInjector();
const androidToolsInfo = testInjector.resolve<IAndroidToolsInfo>(AndroidToolsInfo);
assert.throws(() => androidToolsInfo.validateJavacVersion(null, { showWarningsAsErrors: true }), "Error executing command 'javac'. Make sure you have installed The Java Development Kit (JDK) and set JAVA_HOME environment variable.");
});
});
});
2 changes: 1 addition & 1 deletion test/services/subscription-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe("subscriptionService", () => {

await subscriptionService.subscribeForNewsletter();

assert.equal(loggerOutput, "Leave your e-mail address here to subscribe for NativeScript newsletter and product updates, tips and tricks:");
assert.equal(loggerOutput, "Enter your e-mail address to subscribe to the NativeScript Newsletter and hear about product updates, tips & tricks, and community happenings:");
});

const expectedMessageInPrompter = "(press Enter for blank)";
Expand Down
2 changes: 1 addition & 1 deletion test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ export class AndroidToolsInfoStub implements IAndroidToolsInfo {
return true;
}

public async validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): Promise<boolean> {
public validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): boolean {
return true;
}

Expand Down