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 #59: when editing an exisiting project, add base starter if no dependencies are selected. #62

Merged
merged 1 commit into from
Apr 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
2 changes: 1 addition & 1 deletion src/DependencyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class DependencyManager {
}

public getSelectedDependencies(): IDependency[] {
return this.selectedIds.map((id: string) => this.dict[id]);
return this.selectedIds.map((id: string) => this.dict[id]).filter(Boolean);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for robustness

}

public getUnselectedDependencies(): IDependency[] {
Expand Down
3 changes: 2 additions & 1 deletion src/Metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as _ from "lodash";
import { IDependency, IStarters, ITopLevelAttribute } from "./Interfaces";
import { Utils } from "./Utils";
import { Versions } from "./Versions";
Expand All @@ -26,7 +27,7 @@ export namespace dependencies {
const rawJSONString: string = await Utils.downloadFile(`${Utils.settings.getServiceUrl()}dependencies?bootVersion=${bootVersion}`, true, { Accept: "application/vnd.initializr.v2.1+json" });
starters[bootVersion] = JSON.parse(rawJSONString);
}
return starters[bootVersion];
return _.cloneDeep(starters[bootVersion]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always return a copy, in case the caller modify the cached content.

}
}

Expand Down
12 changes: 10 additions & 2 deletions src/Routines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export module Routines {
vscode.window.showInformationMessage("No changes.");
return;
}
const msgRemove: string = (toRemove && toRemove.length) ? `Removing: [${toRemove.map(d => manager.dict[d].name).join(", ")}].` : "";
const msgAdd: string = (toAdd && toAdd.length) ? `Adding: [${toAdd.map(d => manager.dict[d].name).join(", ")}].` : "";
const msgRemove: string = (toRemove && toRemove.length) ? `Removing: [${toRemove.map(d => manager.dict[d] && manager.dict[d].name).filter(Boolean).join(", ")}].` : "";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid potential NPE

const msgAdd: string = (toAdd && toAdd.length) ? `Adding: [${toAdd.map(d => manager.dict[d] && manager.dict[d].name).filter(Boolean).join(", ")}].` : "";
const choice: string = await vscode.window.showWarningMessage(`${msgRemove} ${msgAdd} Proceed?`, "Proceed", "Cancel");
if (choice !== "Proceed") {
TelemetryHelper.finishStep(stepCancel);
Expand All @@ -196,6 +196,14 @@ export module Routines {
TelemetryHelper.finishStep(stepProceed);
}

// add spring-boot-starter if no selected starters
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add default starter, same issue with spring-projects/sts4#52

if (manager.selectedIds.length === 0) {
toAdd.push("spring-boot-starter");
starters.dependencies["spring-boot-starter"] = {
groupId: "org.springframework.boot",
artifactId: "spring-boot-starter"
};
}
// modify xml object
const newXml: { project: XmlNode } = getUpdatedPomXml(xml, starters, toRemove, toAdd);

Expand Down