in src/archetype/ArchetypeModule.ts [59:109]
async function executeInTerminalHandler(metadata: IProjectCreationMetadata): Promise<void> {
const {
archetypeArtifactId,
archetypeGroupId,
archetypeVersion,
groupId,
artifactId,
targetFolder
} = metadata;
if (archetypeArtifactId === undefined || archetypeGroupId === undefined || archetypeVersion === undefined) {
throw new Error("Archetype information is incomplete.");
}
sendInfo("", { archetypeArtifactId, archetypeGroupId, archetypeVersion });
const cmdArgs: string[] = [
// explicitly using 3.1.2 as maven-archetype-plugin:3.0.1 ignores -DoutputDirectory
// see https://github.com/microsoft/vscode-maven/issues/478
"org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate",
`-DarchetypeArtifactId="${archetypeArtifactId}"`,
`-DarchetypeGroupId="${archetypeGroupId}"`,
`-DarchetypeVersion="${archetypeVersion}"`,
`-DgroupId="${groupId}"`,
`-DartifactId="${artifactId}"`
];
let cwd: string | undefined = targetFolder;
let mvnPath: string | undefined = await getMaven();
if (mvnPath === undefined) {
cmdArgs.push(`-DoutputDirectory="${targetFolder}"`);
mvnPath = getEmbeddedMavenWrapper();
cwd = path.dirname(mvnPath);
}
if (mvnPath === undefined) { return; }
const mvnString: string = wrappedWithQuotes(await mavenTerminal.formattedPathForTerminal(mvnPath));
const defaultArgs: string | undefined = Settings.Executable.options(metadata.targetFolder);
const mvnSettingsFile: string | undefined = Settings.getSettingsFilePath();
const mvnSettingsArg: string | undefined = mvnSettingsFile ? `-s "${await mavenTerminal.formattedPathForTerminal(mvnSettingsFile)}"` : undefined;
let commandLine: string = [mvnString, ...cmdArgs, defaultArgs, mvnSettingsArg].filter(Boolean).join(" ");
const options: vscode.ShellExecutionOptions = { cwd };
if (vscode.env.remoteName === undefined && process.platform === "win32") { // VS Code launched in Windows Desktop.
options.shellQuoting = shellQuotes.cmd;
options.executable = "cmd.exe";
options.shellArgs = ["/c"];
commandLine = `"${commandLine}"`; // wrap full command with quotation marks, cmd /c "<fullcommand>", see https://stackoverflow.com/a/6378038
} else {
options.shellQuoting = shellQuotes.bash;
}
const execution = new vscode.ShellExecution(commandLine, options);
const createProjectTask = new vscode.Task({ type: "maven", targetFolder, artifactId }, vscode.TaskScope.Global, "createProject", "maven", execution);
vscode.tasks.executeTask(createProjectTask);
}