in jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/wizard/SamInitRunner.kt [25:70]
fun execute(
outputDir: VirtualFile,
templateParameters: TemplateParameters,
schemaParameters: SchemaTemplateParameters?
) {
// set output to a temp dir
val tempDir = createTempDir()
ExecutableManager.getInstance().getExecutable<SamExecutable>().thenApply {
val samExecutable = when (it) {
is ExecutableInstance.Executable -> it
else -> throw RuntimeException((it as? ExecutableInstance.BadExecutable)?.validationError)
}
val extraContent = if (schemaParameters?.templateExtraContext != null) {
jacksonObjectMapper().convertValue<Map<String, String>>(schemaParameters.templateExtraContext)
} else {
emptyMap()
}
val commandLine = samExecutable.getCommandLine().samInitCommand(
tempDir.toPath(),
templateParameters,
extraContent
)
LOG.info { "Running SAM command ${commandLine.commandLineString}" }
val process = CapturingProcessHandler(commandLine).runProcess()
if (process.exitCode != 0) {
throw RuntimeException("${message("sam.init.execution_error")}: ${process.stderrLines}")
} else {
LOG.info { "SAM init output stdout:\n${process.stdout}" }
LOG.info { "SAM init output stderr:\n${process.stderr}" }
}
val subFolders = tempDir.listFiles()?.toList() ?: emptyList()
assert(subFolders.size == 1 && subFolders.first().isDirectory) {
message("sam.init.error.subfolder_not_one", tempDir.name)
}
FileUtil.copyDirContent(subFolders.first(), VfsUtil.virtualToIoFile(outputDir))
FileUtil.delete(tempDir)
}.toCompletableFuture().join()
}