Skip to content

Commit

Permalink
feat - Gradle project view keeps project hierarchy (#1612)
Browse files Browse the repository at this point in the history
* Gradle project view keeps project hierarchy

Implements #945 by parsing the project path which is found in the
'definition.script' property. The project path, which is unique for
every subproject, is then used as key in the 'projectTreeItemMap'.

* Update 'actions/download-artifact' and 'actions/upload-artifact' to v4

* Update target platform definition

---------

Co-authored-by: Sheng Chen <sheche@microsoft.com>
  • Loading branch information
jjohannes and jdneo authored Oct 8, 2024
1 parent 23bfc97 commit 9ac3ffe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
JAVA_HOME: ""
NODE_OPTIONS: "--max-old-space-size=4096"
- name: Upload lib
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: lib
path: |
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
restore-keys: |
${{ runner.os }}-vscode-
- name: Download lib
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: lib
path: extension/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
<unit id="org.mockito.mockito-core" version="0.0.0"/>
<unit id="org.apache.commons.commons-io" version="0.0.0"/>
<unit id="org.eclipse.jdt.apt.pluggable.core" version="0.0.0"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.33-I-builds/I20240613-1800/"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.33/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
<repository location="https://download.eclipse.org/releases/2024-03/"/>
<repository location="https://download.eclipse.org/releases/2024-09/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.ls.core" version="0.0.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class DefaultProjectsTreeDataProvider implements vscode.TreeDataProvider<

private async getChildrenForProjectTreeItem(element: ProjectTreeItem): Promise<vscode.TreeItem[]> {
const projectTaskItem = new ProjectTaskTreeItem("Tasks", vscode.TreeItemCollapsibleState.Collapsed, element);
projectTaskItem.setChildren([...element.groups, ...element.tasks]);
projectTaskItem.setChildren([...element.tasks, ...element.groups]);
const results: vscode.TreeItem[] = [projectTaskItem];
const resourceUri = element.resourceUri;
if (!resourceUri) {
Expand All @@ -68,6 +68,6 @@ export class DefaultProjectsTreeDataProvider implements vscode.TreeDataProvider<
path.dirname(resourceUri.fsPath),
typeof element.label === "string" ? element.label : resourceUri.fsPath
);
return [...results, projectDependencyTreeItem];
return [projectDependencyTreeItem, ...results];
}
}
24 changes: 17 additions & 7 deletions extension/src/views/gradleTasks/GradleTasksTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider<vsco

public async getChildrenForProjectTreeItem(element: ProjectTreeItem): Promise<vscode.TreeItem[]> {
const projectTaskItem = new ProjectTaskTreeItem("Tasks", vscode.TreeItemCollapsibleState.Collapsed, element);
projectTaskItem.setChildren([...element.groups, ...element.tasks]);
projectTaskItem.setChildren([...element.tasks, ...element.groups]);
const results: vscode.TreeItem[] = [projectTaskItem];
const resourceUri = element.resourceUri;
if (!resourceUri) {
return results;
return [...results, ...element.subprojects];
}
const projectDependencyTreeItem: ProjectDependencyTreeItem = new ProjectDependencyTreeItem(
"Dependencies",
Expand All @@ -226,7 +226,7 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider<vsco
path.dirname(resourceUri.fsPath),
typeof element.label === "string" ? element.label : resourceUri.fsPath
);
return [...results, projectDependencyTreeItem];
return [...results, projectDependencyTreeItem, ...element.subprojects];
}

public static buildItemsTreeFromTasks(
Expand All @@ -253,15 +253,25 @@ export class GradleTasksTreeDataProvider implements vscode.TreeDataProvider<vsco
gradleProjectTreeItemMap.set(definition.projectFolder, gradleProjectTreeItem);
}

let projectTreeItem = projectTreeItemMap.get(definition.buildFile);
const projectPath = definition.script.split(":").slice(0, -1);
let projectTreeItem = projectTreeItemMap.get(projectPath.join(":"));
if (!projectTreeItem) {
const parentProjectPath = projectPath.length == 0 ? null : projectPath.slice(0, -1);
const parentProject =
parentProjectPath === null
? gradleProjectTreeItem
: projectTreeItemMap.get(parentProjectPath.join(":"));
projectTreeItem = new ProjectTreeItem(
definition.project,
gradleProjectTreeItem,
parentProject,
vscode.Uri.file(definition.buildFile)
);
gradleProjectTreeItem.addProject(projectTreeItem);
projectTreeItemMap.set(definition.buildFile, projectTreeItem);
if (parentProject instanceof ProjectTreeItem) {
parentProject.addSubproject(projectTreeItem);
} else {
gradleProjectTreeItem.addProject(projectTreeItem);
}
projectTreeItemMap.set(projectPath.join(":"), projectTreeItem);
}

const taskName = definition.script.slice(definition.script.lastIndexOf(":") + 1);
Expand Down
11 changes: 10 additions & 1 deletion extension/src/views/gradleTasks/TreeItemWithTasksOrGroups.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as vscode from "vscode";
import { GradleTaskTreeItem } from ".";
import { GradleTaskTreeItem, ProjectTreeItem } from ".";
import { GroupTreeItem } from "..";
import { treeItemSortCompareFunc, gradleTaskTreeItemSortCompareFunc } from "../viewUtil";

export class TreeItemWithTasksOrGroups extends vscode.TreeItem {
private readonly _tasks: GradleTaskTreeItem[] = [];
private readonly _groups: GroupTreeItem[] = [];
private readonly _subprojects: ProjectTreeItem[] = [];
public readonly parentTreeItem?: vscode.TreeItem;
public readonly iconPath = new vscode.ThemeIcon("file-submodule");
public readonly contextValue = "folder";
Expand Down Expand Up @@ -35,4 +36,12 @@ export class TreeItemWithTasksOrGroups extends vscode.TreeItem {
public get groups(): GroupTreeItem[] {
return this._groups.sort(treeItemSortCompareFunc);
}

public get subprojects(): ProjectTreeItem[] {
return this._subprojects;
}

public addSubproject(subproject: ProjectTreeItem): void {
this._subprojects.push(subproject);
}
}

0 comments on commit 9ac3ffe

Please sign in to comment.