Skip to content

Commit c54e52c

Browse files
authored
Fix 52: "EEXIST:file already exists" raises during creating java project (#61)
* Fix bug 52: "EEXIST:file already exists" raises during creating java project, using Promise.all will cause the racing of creating the target folder.
1 parent b60e1de commit c54e52c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/controllers/projectController.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ export class ProjectController {
5050
}
5151

5252
private async scaffoldJavaProject(basePath: string, projectName: string, javaVersion: number): Promise<boolean> {
53-
const projectFile: string = path.join(basePath, projectName, ".project");
54-
const extensionPath: string = this.context.extensionPath;
53+
const projectRoot: string = path.join(basePath, projectName);
54+
const templateRoot: string = path.join(this.context.extensionPath, "templates");
55+
const projectFile: string = path.join(projectRoot, ".project");
5556
try {
57+
await fse.ensureDir(projectRoot);
58+
5659
await Promise.all([
57-
fse.copy(path.join(extensionPath, "templates", "App.java.sample"), path.join(basePath, projectName, "src", "app", "App.java")),
58-
fse.copy(path.join(extensionPath, "templates", `Java${javaVersion}`), path.join(basePath, projectName)),
59-
fse.copy(path.join(extensionPath, "templates", ".project"), projectFile),
60-
fse.ensureDir(path.join(basePath, projectName, "bin")),
60+
fse.copy(path.join(templateRoot, "App.java.sample"), path.join(projectRoot, "src", "app", "App.java")),
61+
fse.copy(path.join(templateRoot, `Java${javaVersion}`), projectRoot),
62+
fse.copy(path.join(templateRoot, ".project"), path.join(projectRoot, ".project")),
63+
fse.ensureDir(path.join(projectRoot, "bin")),
6164
]);
6265

6366
// replace the project name with user input project name

templates/App.java.sample

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package app;
22

33
public class App {
4-
public static void main(String[] args) throws Exception {
5-
System.out.println("Hello Java");
6-
}
7-
4+
public static void main(String[] args) throws Exception {
5+
System.out.println("Hello Java");
6+
}
87
}

0 commit comments

Comments
 (0)