Skip to content

Commit 95a3fc9

Browse files
committed
fix(creation): ensure project creation is more robust
1 parent 117dd19 commit 95a3fc9

5 files changed

Lines changed: 45 additions & 69 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "coc-java-explorer",
33
"description": "coc.nvim extension project manager for java",
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"main": "lib/index.js",
66
"repository": {
77
"type": "git",

src/controllers/projectController.ts

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ async function promptUpdateExtension(projectType: string, metaData: IProjectType
137137

138138
async function scaffoldSimpleProject(context: ExtensionContext): Promise<void> {
139139
const workspaceFolder = Utility.getDefaultWorkspaceFolder();
140-
const location: string | undefined = await window.requestInput(
141-
"Select the project location",
142-
workspaceFolder && workspaceFolder.uri,
143-
{}
144-
);
145-
if (!location || !location.length) {
140+
const uri: Uri = Uri.parse(workspaceFolder?.uri);
141+
const location: string | undefined = await window.requestInput("Select project location: ", uri.fsPath, {});
142+
143+
if (!location || !location.length || !(await fse.exists(location))) {
144+
window.showErrorMessage("Invalid project location was provided");
146145
return;
147146
}
147+
148148
const projectName: string | undefined = await window.requestInput("Enter Java project name: ");
149149

150150
if (!projectName) {
151+
window.showErrorMessage("Invalid project name was provided");
151152
return;
152153
}
153154

@@ -157,18 +158,17 @@ async function scaffoldSimpleProject(context: ExtensionContext): Promise<void> {
157158
await fse.ensureDir(projectRoot);
158159
await fse.copy(templateRoot, projectRoot);
159160
await fse.ensureDir(path.join(projectRoot, "lib"));
161+
window.showInformationMessage(`Created a new simple project at ${projectRoot}`);
160162
} catch (error) {
161163
window.showErrorMessage(error.message);
162164
return;
163165
}
164-
const openInNewWindow = workspace && !_.isEmpty(workspace.workspaceFolders);
165-
await commands.executeCommand(Commands.VSCODE_OPEN_FOLDER, Uri.file(path.join(location, projectName)), openInNewWindow);
166+
await commands.executeCommand(Commands.VSCODE_OPEN, Uri.file(path.join(location, projectName)));
166167
}
167168

168169
const projectTypes: IProjectType[] = [
169170
{
170-
displayName: "No build tools",
171-
detail: "Work with source code directly without any build tools",
171+
displayName: "Simple",
172172
metadata: {
173173
type: ProjectType.NoBuildTool,
174174
extensionId: "",
@@ -178,10 +178,9 @@ const projectTypes: IProjectType[] = [
178178
},
179179
{
180180
displayName: "Maven",
181-
description: "create from archetype",
182181
metadata: {
183182
type: ProjectType.Maven,
184-
extensionId: "vscjava.vscode-maven",
183+
extensionId: "coc-maven",
185184
extensionName: "Maven for Java",
186185
createCommandId: "maven.archetype.generate"
187186
}
@@ -190,7 +189,7 @@ const projectTypes: IProjectType[] = [
190189
displayName: "Gradle",
191190
metadata: {
192191
type: ProjectType.Gradle,
193-
extensionId: "vscjava.vscode-gradle",
192+
extensionId: "coc-gradle",
194193
extensionName: "Gradle for Java",
195194
leastExtensionVersion: "3.10.0",
196195
createCommandId: "gradle.createProject"
@@ -200,63 +199,9 @@ const projectTypes: IProjectType[] = [
200199
displayName: "Spring Boot",
201200
metadata: {
202201
type: ProjectType.SpringBoot,
203-
extensionId: "vscjava.vscode-spring-initializr",
202+
extensionId: "coc-spring-initializr",
204203
extensionName: "Spring Initializr Java Support",
205204
createCommandId: "spring.initializr.createProject"
206205
}
207-
},
208-
{
209-
displayName: "Quarkus",
210-
metadata: {
211-
type: ProjectType.Quarkus,
212-
extensionId: "redhat.vscode-quarkus",
213-
extensionName: "Quarkus",
214-
createCommandId: "quarkusTools.createProject"
215-
}
216-
},
217-
{
218-
displayName: "MicroProfile",
219-
metadata: {
220-
type: ProjectType.MicroProfile,
221-
extensionId: "microprofile-community.mp-starter-vscode-ext",
222-
extensionName: "MicroProfile Starter",
223-
createCommandId: "extension.microProfileStarter"
224-
}
225-
},
226-
{
227-
displayName: "JavaFX",
228-
description: "create from archetype",
229-
metadata: {
230-
type: ProjectType.JavaFX,
231-
extensionId: "vscjava.vscode-maven",
232-
extensionName: "Maven for Java",
233-
leastExtensionVersion: "0.35.0",
234-
createCommandId: "maven.archetype.generate",
235-
createCommandArgs: [
236-
{
237-
archetypeGroupId: "org.openjfx",
238-
archetypeArtifactId: "javafx-archetype-fxml",
239-
archetypeVersion: "RELEASE"
240-
}
241-
]
242-
}
243-
},
244-
{
245-
displayName: "Micronaut",
246-
metadata: {
247-
type: ProjectType.Micronaut,
248-
extensionId: "oracle-labs-graalvm.micronaut",
249-
extensionName: "Launch for Micronaut® framework",
250-
createCommandId: "extension.micronaut.createProject"
251-
}
252-
},
253-
{
254-
displayName: "Graal Development Kit for Micronaut",
255-
metadata: {
256-
type: ProjectType.GDK,
257-
extensionId: "oracle-labs-graalvm.gcn",
258-
extensionName: "Graal Development Kit for Micronaut Launcher",
259-
createCommandId: "gdk.createGdkProject"
260-
}
261206
}
262207
];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"java.project.sourcePaths": ["src"],
3+
"java.project.outputPath": "bin",
4+
"java.project.referencedLibraries": ["lib/**/*.jar"]
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Getting Started
2+
3+
Welcome to the Java world. Here is a guideline to help you get started to write
4+
Java code.
5+
6+
## Folder Structure
7+
8+
The workspace contains two folders by default, where:
9+
10+
- `src`: the folder to maintain sources
11+
- `lib`: the folder to maintain dependencies
12+
13+
Meanwhile, the compiled output files will be generated in the `bin` folder by
14+
default.
15+
16+
> If you want to customize the folder structure, open `.vim/settings.json` and
17+
> update the related settings there.
18+
19+
## Dependency Management
20+
21+
The `JAVA PROJECTS` view allows you to manage your dependencies.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class App {
2+
public static void main(String[] args) throws Exception {
3+
System.out.println("Hello, World!");
4+
}
5+
}

0 commit comments

Comments
 (0)