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

Support to create project with specific archetype version #357

Merged
merged 4 commits into from
Jul 1, 2019
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ All notable changes to the "vscode-maven" extension will be documented in this f

## 0.18.0
#### Added
- Fallback to use an embedded Maven wrapper if no availble Maven executable is found. [PR#344](https://github.com/microsoft/vscode-maven/pull/344)
- For Maven project creation:
- Fallback to use an embedded Maven wrapper if no availble Maven executable is found. [PR#344](https://github.com/microsoft/vscode-maven/pull/344)
- Support to select archetype version. [#354](https://github.com/microsoft/vscode-maven/issues/354)
- Refresh explorer when config `maven.pomfile.globPattern` changes. [#334](https://github.com/microsoft/vscode-maven/issues/334)

#### Changed
Expand Down
26 changes: 18 additions & 8 deletions TestPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,28 @@
## Maven Archetypes
### Generate project from maven archetypes
1. Right-click a target folder in file explorer view.
2. Click `Generate from Maven Archetype`.
2. Click `Create Maven Project`.
3. Verify:
1. It should show a dropdown list of popular maven archetypes.
2. The first item is `More ...`.
4. Select one of the listed archetype.
5. Select the target folder in the popup dialog.
6. Verify:
5. Select one of the listed version.
6. Select the target folder in the popup dialog.
7. Verify:
1. It opens an integrated terminal, and navigates to the target folder you previously selected.
2. It issues the corresponding maven command (archetype:generate) with correct parameters.
3. You can interactively continue to fill in missing params in the terminal to complete the task.

### Generate project from maven archetypes (for empty workspace)
1. Open Command Palette.
2. Click `Maven: Generate from Maven Archetype`.
2. Click `Maven: Create Maven Project`.
3. Verify:
1. It should show a dropdown list of popular maven archetypes.
2. The first item is `More ...`.
4. Select one of the listed archetype.
5. Select the target folder in the popup dialog.
6. Verify:
5. Select one of the listed version.
6. Select the target folder in the popup dialog.
7. Verify:
1. It opens an integrated terminal, and navigates to the target folder you previously selected.
2. It issues the corresponding maven command (archetype:generate) with correct parameters.
3. You can interactively continue to fill in missing params in the terminal to complete the task.
Expand All @@ -124,7 +126,7 @@
## Executable related
### Maven Wrapper support
1. Clone code https://github.com/Microsoft/todo-app-java-on-azure.git
2. Test `clean`, `Generate project from Maven Archetype` and `Effective POM`.
2. Test `clean`, `Create Maven Project` and `Effective POM`.
3. Verify:
1. It uses `./mvnw` in the root folder as executable, and no error occurs.

Expand All @@ -134,10 +136,18 @@
3. Change value of `maven.executable.path` according to the maven executable absolute path.
* For maven executables, use path of `mvn` / `mvn.cmd`
* For maven wrapper, use path of `mvnw` / `mvnw.cmd`
4. Test `clean`, `Generate project from Maven Archetype` and `Effective POM`.
4. Test `clean`, `Create Maven Project` and `Effective POM`.
5. Verify:
1. Corresponding executable is used and commands can be successfully executed with no error.

### Fallback Embedded Maven Wrapper
1. Make sure `mvn` is not in `PATH`, i.e., you can not directly run `mvn`.
2. Launch VS Code without opening any folder.
3. Open Command Palette and click `Maven: Create Maven Project`.
4. Select archetype, version, and target folder.
5. Verify:
1. It should create project in the target folder.

## Pom.xml file watcher
The tree view of maven projects should update when any pom.xml is created/modified/deleted in the current workspace.

Expand Down
2 changes: 1 addition & 1 deletion resources/archetypes.json

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions src/archetype/ArchetypeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ const REMOTE_ARCHETYPE_CATALOG_URL: string = "https://repo.maven.apache.org/mave
const POPULAR_ARCHETYPES_URL: string = "https://vscodemaventelemetry.blob.core.windows.net/public/popular_archetypes.json";

export namespace ArchetypeModule {
async function selectArchetype(): Promise<Archetype> {
async function selectArchetype(): Promise<{ artifactId: string, groupId: string, version: string }> {
let selectedArchetype: Archetype | undefined | null = await showQuickPickForArchetypes();
while (selectedArchetype === null) {
selectedArchetype = await showQuickPickForArchetypes(true);
}
if (selectedArchetype === undefined) {
throw new OperationCanceledError("Archetype not selected.");
}

return selectedArchetype;
const version: string | undefined = await window.showQuickPick(selectedArchetype.versions, {
placeHolder: "Select a version ..."
});
if (version === undefined) {
throw new OperationCanceledError("Archetype version not selected.");
}
const { artifactId, groupId } = selectedArchetype;
return { artifactId, groupId, version };
}

async function chooseTargetFolder(entry: Uri | undefined): Promise<string> {
Expand All @@ -40,11 +46,12 @@ export namespace ArchetypeModule {
return cwd;
}

async function executeInTerminalHandler(archetypeGroupId: string, archetypeArtifactId: string, targetFolder: string): Promise<void> {
async function executeInTerminalHandler(archetypeGroupId: string, archetypeArtifactId: string, archetypeVersion: string, targetFolder: string): Promise<void> {
const cmdArgs: string[] = [
"archetype:generate",
`-DarchetypeArtifactId="${archetypeArtifactId}"`,
`-DarchetypeGroupId="${archetypeGroupId}"`
`-DarchetypeGroupId="${archetypeGroupId}"`,
`-DarchetypeVersion="${archetypeVersion}"`
];
let mvnPath: string | undefined;
let cwd: string = targetFolder;
Expand All @@ -58,8 +65,8 @@ export namespace ArchetypeModule {

export async function generateFromArchetype(entry: Uri | undefined, operationId: string): Promise<void> {
// select archetype.
const { artifactId, groupId } = await instrumentOperationStep(operationId, "selectArchetype", selectArchetype)();
sendInfo(operationId, { archetypeArtifactId: artifactId, archetypeGroupId: groupId });
const { artifactId, groupId, version } = await instrumentOperationStep(operationId, "selectArchetype", selectArchetype)();
sendInfo(operationId, { archetypeArtifactId: artifactId, archetypeGroupId: groupId, archetypeVersion: version });

// choose target folder.
let targetFolderHint: Uri | undefined;
Expand All @@ -71,7 +78,7 @@ export namespace ArchetypeModule {
const cwd: string = await instrumentOperationStep(operationId, "chooseTargetFolder", chooseTargetFolder)(targetFolderHint);

// execute in terminal.
await instrumentOperationStep(operationId, "executeInTerminal", executeInTerminalHandler)(groupId, artifactId, cwd);
await instrumentOperationStep(operationId, "executeInTerminal", executeInTerminalHandler)(groupId, artifactId, version, cwd);
}

export async function updateArchetypeCatalog(): Promise<void> {
Expand Down
3 changes: 1 addition & 2 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,5 @@
"no-switch-case-fall-through": false,
"typeof-compare": false
},
"rulesDirectory": "node_modules/tslint-microsoft-contrib/",
"defaultSeverity": "warning"
"rulesDirectory": "node_modules/tslint-microsoft-contrib/"
}