Skip to content

Commit a444949

Browse files
authored
feat: Support run build from tasks (#660)
* feat: Support run build from tasks - Add a new task provider with type: 'java (build)'. - Use 'paths' to define the root path of the project to be built. - Use 'isFullBuild' to define whether this build is a full built or not. Signed-off-by: Sheng Chen <[email protected]>
1 parent 932edfe commit a444949

File tree

10 files changed

+430
-1
lines changed

10 files changed

+430
-1
lines changed

extension.bundle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ export { contextManager } from "./src/contextManager";
2222
export { DependencyExplorer } from "./src/views/dependencyExplorer";
2323
export { Commands } from "./src/commands";
2424
export { LanguageServerMode } from "./src/languageServerApi/LanguageServerMode";
25+
26+
// tasks
27+
export { BuildTaskProvider, categorizePaths, getFinalPaths } from "./src/tasks/build/buildTaskProvider";

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,40 @@
628628
"description": "%taskDefinitions.java.project.exportJar.elements%"
629629
}
630630
}
631+
},
632+
{
633+
"type": "java (build)",
634+
"properties": {
635+
"paths": {
636+
"type": "array",
637+
"items": {
638+
"anyOf": [
639+
{
640+
"type": "string"
641+
},
642+
{
643+
"enum": [
644+
"${workspace}",
645+
"!<path>"
646+
],
647+
"enumDescriptions": [
648+
"%taskDefinitions.java.project.build.path.workspace%",
649+
"%taskDefinitions.java.project.build.path.exclude%"
650+
]
651+
}
652+
]
653+
},
654+
"default": [
655+
"${workspace}"
656+
],
657+
"description": "%taskDefinitions.java.project.build.path%"
658+
},
659+
"isFullBuild": {
660+
"type": "boolean",
661+
"default": "true",
662+
"description": "%taskDefinitions.java.project.build.isFullBuild%"
663+
}
664+
}
631665
}
632666
]
633667
},

package.nls.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"taskDefinitions.java.project.exportJar.testCompileOutput": "The folders containing output class files in the test scope.",
3838
"taskDefinitions.java.project.exportJar.dependencies": "The artifact dependencies in the runtime scope.",
3939
"taskDefinitions.java.project.exportJar.testDependencies": "The artifact dependencies in the test scope.",
40+
"taskDefinitions.java.project.build.path": "The project root paths that will be built. Both absolute path and relative path to the workspace folder are supported.",
41+
"taskDefinitions.java.project.build.path.workspace": "All the projects in workspace.",
42+
"taskDefinitions.java.project.build.path.exclude": "The path after '!' will be excluded from the paths to be built.",
43+
"taskDefinitions.java.project.build.isFullBuild": "Whether to execute a clean build or not.",
4044
"viewsWelcome.workbench.createNewJavaProject": "You can also [open a Java project folder](command:_java.project.open), or create a new Java project by clicking the button below.\n[Create Java Project](command:java.project.create)",
4145
"viewsWelcome.workbench.noJavaProject": "No Java projects found in the current workspace. You can [open a Java project folder](command:_java.project.open), or create a new Java project by clicking the button below.\n[Create Java Project](command:java.project.create)",
4246
"viewsWelcome.workbench.inLightWeightMode": "To view the projects, you can import the projects into workspace.\n[Import Projects](command:java.server.mode.switch?%5B%22Standard%22,true%5D)",

package.nls.zh.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"taskDefinitions.java.project.exportJar.testCompileOutput": "在 test scope 内包含输出的 class 文件的文件夹。",
3838
"taskDefinitions.java.project.exportJar.dependencies": "在 runtime scope 内的依赖。",
3939
"taskDefinitions.java.project.exportJar.testDependencies": "在 test scope 内的依赖。",
40+
"taskDefinitions.java.project.build.path": "被构建项目的根目录路径。绝对路径或者相对于工作空间目录的相对路径都可以使用。",
41+
"taskDefinitions.java.project.build.path.workspace": "工作空间中的所有项目。",
42+
"taskDefinitions.java.project.build.path.exclude": "'!' 后的路径将会从待构建项目路径中移除。",
43+
"taskDefinitions.java.project.build.isFullBuild": "是否要重新构建项目。",
4044
"viewsWelcome.workbench.createNewJavaProject": "您也可以[打开一个 Java 项目目录](command:_java.project.open),或点击下方按钮创建一个新的 Java 项目。\n[创建 Java 项目](command:java.project.create)",
4145
"viewsWelcome.workbench.noJavaProject": "当前工作空间未发现 Java 项目,您可以[打开一个 Java 项目目录](command:_java.project.open),或点击下方按钮创建一个新的 Java 项目。\n[创建 Java 项目](command:java.project.create)",
4246
"viewsWelcome.workbench.inLightWeightMode": "要浏览项目信息,你可以将项目导入到工作空间中。\n[导入项目](command:java.server.mode.switch?%5B%22Standard%22,true%5D)",

src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function handleBuildFailure(operationId: string, err: any): Promise<boolea
6060
return false;
6161
}
6262

63-
function checkErrorsReportedByJavaExtension(): boolean {
63+
export function checkErrorsReportedByJavaExtension(): boolean {
6464
const problems = languages.getDiagnostics() || [];
6565
for (const problem of problems) {
6666
const fileName = basename(problem[0].fsPath || "");

src/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,18 @@ export namespace Commands {
101101

102102
export const WORKBENCH_ACTION_FILES_OPENFILEFOLDER = "workbench.action.files.openFileFolder";
103103

104+
export const WORKBENCH_VIEW_PROBLEMS = "workbench.actions.view.problems";
105+
104106
/**
105107
* Commands from JLS
106108
*/
107109
export const LIST_SOURCEPATHS = "java.project.listSourcePaths";
110+
111+
export const COMPILE_WORKSPACE = "java.workspace.compile";
112+
113+
export const GET_ALL_PROJECTS = "java.project.getAll";
114+
115+
export const BUILD_PROJECT = "java.project.build";
108116
}
109117

110118
export function executeJavaLanguageServerCommand(...rest: any[]) {

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { commands, Extension, ExtensionContext, extensions, tasks, Uri, workspace } from "vscode";
55
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
66
import { Commands, contextManager } from "../extension.bundle";
7+
import { BuildTaskProvider } from "./tasks/build/buildTaskProvider";
78
import { Context, ExtensionName } from "./constants";
89
import { LibraryController } from "./controllers/libraryController";
910
import { ProjectController } from "./controllers/projectController";
@@ -38,6 +39,7 @@ async function activateExtension(_operationId: string, context: ExtensionContext
3839
context.subscriptions.push(contextManager);
3940
context.subscriptions.push(syncHandler);
4041
context.subscriptions.push(tasks.registerTaskProvider(ExportJarTaskProvider.exportJarType, new ExportJarTaskProvider()));
42+
context.subscriptions.push(tasks.registerTaskProvider(BuildTaskProvider.type, new BuildTaskProvider()));
4143
}
4244

4345
// this method is called when your extension is deactivated

src/java/jdtls.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export namespace Jdtls {
1212
return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_LIST, params) || [];
1313
}
1414

15+
export async function getProjectUris(): Promise<string[]> {
16+
return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_PROJECTS) || [];
17+
}
18+
1519
export async function refreshLibraries(params: string): Promise<boolean | undefined> {
1620
return commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_REFRESH_LIB_SERVER, params);
1721
}

0 commit comments

Comments
 (0)