import * as fse from 'fs-extra' ; import * as os from 'os' ; import * as path from 'path' ; import { IActionContext } from 'vscode-azureextensionui' ; import { ext } from '../../../extensionVariables' ; import * as fsUtil from '../../../utils/fs' ; import { mavenUtils } from '../../../utils/mavenUtils' ; import { nonNullProp } from '../../../utils/nonNull' ; import { IJavaProjectWizardContext } from '../javaSteps/IJavaProjectWizardContext' ; import { ProjectCreateStepBase } from './ProjectCreateStepBase' ; export class JavaProjectCreateStep extends ProjectCreateStepBase { private constructor ( ) { super ( ) ; } public static async createStep ( context ) { await mavenUtils . validateMavenInstalled ( context ) ; return new JavaProjectCreateStep ( ) ; } public async executeCore ( context ) { const javaVersion = nonNullProp ( context , 'javaVersion' ) ; const artifactId = nonNullProp ( context , 'javaArtifactId' ) ; const tempFolder = path . join ( os . tmpdir ( ) , fsUtil . getRandomHexString ( ) ) ; await fse . ensureDir ( tempFolder ) ; try { ext . outputChannel . show ( ) ; await mavenUtils . executeMvnCommand ( context . telemetry . properties , ext . outputChannel , tempFolder , 'archetype:generate' , mavenUtils . formatMavenArg ( 'DarchetypeGroupId' , 'com.microsoft.azure' ) , mavenUtils . formatMavenArg ( 'DarchetypeArtifactId' , 'azure-functions-archetype' ) , mavenUtils . formatMavenArg ( 'DjavaVersion' , javaVersion ) , mavenUtils . formatMavenArg ( 'DgroupId' , nonNullProp ( context , 'javaGroupId' ) ) , mavenUtils . formatMavenArg ( 'DartifactId' , artifactId ) , mavenUtils . formatMavenArg ( 'Dversion' , nonNullProp ( context , 'javaProjectVersion' ) ) , mavenUtils . formatMavenArg ( 'Dpackage' , nonNullProp ( context , 'javaPackageName' ) ) , mavenUtils . formatMavenArg ( 'DappName' , nonNullProp ( context , 'javaAppName' ) ) , '-B' ) ; await fsUtil . copyFolder ( context , path . join ( tempFolder , artifactId ) , context . projectPath ) ; } finally { await fse . remove ( tempFolder ) ; } } }