Skip to content

fix: platform update/clean commands may fail with Java 10 #3626

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 5 commits into from
May 28, 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
11 changes: 7 additions & 4 deletions lib/commands/platform-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class CleanCommand implements ICommand {
private $projectData: IProjectData,
private $platformService: IPlatformService,
private $errors: IErrors,
private $platformsData: IPlatformsData) {
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements) {
this.$projectData.initializeProjectData();
}

Expand All @@ -18,12 +18,15 @@ export class CleanCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify a platform to clean");
}

_.each(args, platform => {
this.$platformService.validatePlatform(platform, this.$projectData);
});

for (const platform of args) {
this.$platformService.validatePlatformInstalled(platform, this.$projectData);

const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
const currentRuntimeVersion = this.$platformService.getCurrentPlatformVersion(platform, this.$projectData);
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(platform, this.$projectData.projectDir, currentRuntimeVersion);
}

return true;
Expand Down
24 changes: 18 additions & 6 deletions lib/commands/update-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export class UpdatePlatformCommand implements ICommand {
constructor(private $options: IOptions,
private $projectData: IProjectData,
private $platformService: IPlatformService,
private $errors: IErrors,
private $platformsData: IPlatformsData) {
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
private $errors: IErrors) {
this.$projectData.initializeProjectData();
}

Expand All @@ -18,12 +18,24 @@ export class UpdatePlatformCommand implements ICommand {
this.$errors.fail("No platform specified. Please specify platforms to update.");
}

for (const arg of args) {
_.each(args, arg => {
const platform = arg.split("@")[0];
this.$platformService.validatePlatform(platform, this.$projectData);
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
});

for (const arg of args) {
const [ platform, versionToBeInstalled ] = arg.split("@");
this.$platformService.validatePlatformInstalled(platform, this.$projectData);
const argsToCheckEnvironmentRequirements: string[] = [ platform ];
// If version is not specified, we know the command will install the latest compatible Android runtime.
// The latest compatible Android runtime supports Java version, so we do not need to pass it here.
// Passing projectDir to the nativescript-doctor validation will cause it to check the runtime from the current package.json
// So in this case, where we do not want to validate the runtime, just do not pass both projectDir and runtimeVersion.
if (versionToBeInstalled) {
argsToCheckEnvironmentRequirements.push(this.$projectData.projectDir, versionToBeInstalled);
}

await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(...argsToCheckEnvironmentRequirements);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 2 files
+2 −2 declarations.d.ts
+1 −1 package.json
12 changes: 10 additions & 2 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
* @returns {void}
*/
saveBuildInfoFile(platform: string, projectDir: string, buildInfoFileDirname: string): void;

/**
* Gives information for the current version of the runtime.
* @param {string} platform The platform to be checked.
* @param {IProjectData} projectData The data describing the project
* @returns {string} Runtime version
*/
getCurrentPlatformVersion(platform: string, projectData: IProjectData): string;
}

interface IPlatformOptions extends IPlatformSpecificData, ICreateProjectOptions { }
Expand Down Expand Up @@ -381,5 +389,5 @@ interface IUpdateAppOptions extends IOptionalFilesToSync, IOptionalFilesToRemove
}

interface IPlatformEnvironmentRequirements {
checkEnvironmentRequirements(platform?: string, projectDir?: string): Promise<boolean>;
}
checkEnvironmentRequirements(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean>;
}
8 changes: 4 additions & 4 deletions lib/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class DoctorService implements IDoctorService {
private $terminalSpinnerService: ITerminalSpinnerService,
private $versionsService: IVersionsService) { }

public async printWarnings(configOptions?: { trackResult: boolean , projectDir?: string }): Promise<void> {
public async printWarnings(configOptions?: { trackResult: boolean , projectDir?: string, runtimeVersion?: string }): Promise<void> {
const infos = await this.$terminalSpinnerService.execute<NativeScriptDoctor.IInfo[]>({
text: `Getting environment information ${EOL}`
}, () => doctor.getInfos({ projectDir: configOptions && configOptions.projectDir }));
}, () => doctor.getInfos({ projectDir: configOptions && configOptions.projectDir, androidRuntimeVersion: configOptions && configOptions.runtimeVersion }));

const warnings = infos.filter(info => info.type === constants.WARNING_TYPE_NAME);
const hasWarnings = warnings.length > 0;
Expand Down Expand Up @@ -80,12 +80,12 @@ class DoctorService implements IDoctorService {
});
}

public async canExecuteLocalBuild(platform?: string, projectDir?: string): Promise<boolean> {
public async canExecuteLocalBuild(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.CheckLocalBuildSetup,
additionalData: "Starting",
});
const infos = await doctor.getInfos({ platform, projectDir });
const infos = await doctor.getInfos({ platform, projectDir, androidRuntimeVersion: runtimeVersion });

const warnings = this.filterInfosByType(infos, constants.WARNING_TYPE_NAME);
const hasWarnings = warnings.length > 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/services/platform-environment-requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
"deploy": "tns cloud deploy"
};

public async checkEnvironmentRequirements(platform?: string, projectDir?: string): Promise<boolean> {
public async checkEnvironmentRequirements(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> {
if (process.env.NS_SKIP_ENV_CHECK) {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
action: TrackActionNames.CheckEnvironmentRequirements,
Expand All @@ -39,7 +39,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
return true;
}

const canExecute = await this.$doctorService.canExecuteLocalBuild(platform, projectDir);
const canExecute = await this.$doctorService.canExecuteLocalBuild(platform, projectDir, runtimeVersion);
if (!canExecute) {
if (!isInteractive()) {
await this.$analyticsService.trackEventActionInGoogleAnalytics({
Expand Down Expand Up @@ -71,7 +71,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
if (selectedOption === PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME) {
await this.$doctorService.runSetupScript();

if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir)) {
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir, runtimeVersion)) {
return true;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ

if (selectedOption === PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME) {
await this.processBothCloudBuildsAndSetupScript();
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir)) {
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir, runtimeVersion)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}
}

private getCurrentPlatformVersion(platform: string, projectData: IProjectData): string {
public getCurrentPlatformVersion(platform: string, projectData: IProjectData): string {
const platformData = this.$platformsData.getPlatformData(platform, projectData);
const currentPlatformData: any = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
let version: string;
Expand Down
36 changes: 18 additions & 18 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"minimatch": "3.0.2",
"mkdirp": "0.5.1",
"mute-stream": "0.0.5",
"nativescript-doctor": "1.1.0",
"nativescript-doctor": "1.2.0",
"open": "0.0.5",
"ora": "2.0.0",
"osenv": "0.1.3",
Expand Down
3 changes: 3 additions & 0 deletions test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ function createTestInjector() {
getPlaygroundInfo: () => Promise.resolve(null)
});
testInjector.register("filesHashService", {});
testInjector.register("platformEnvironmentRequirements", {
checkEnvironmentRequirements: async (platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> => true
});

return testInjector;
}
Expand Down
4 changes: 4 additions & 0 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,10 @@ export class PlatformServiceStub extends EventEmitter implements IPlatformServic
public async trackActionForPlatform(actionData: ITrackPlatformAction): Promise<void> {
return null;
}

public getCurrentPlatformVersion(platform: string, projectData: IProjectData): string {
return null;
}
}

export class EmulatorPlatformService implements IEmulatorPlatformService {
Expand Down