Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 0.22.0
### Added
- Display non-Java files in Java Projects explorer. [#145](https://github.com/microsoft/vscode-java-dependency/issues/145)
- Show non Java projects in the Java Projects explorer. [#736](https://github.com/microsoft/vscode-java-dependency/issues/736)
- Show non-Java projects in the Java Projects explorer. [#736](https://github.com/microsoft/vscode-java-dependency/issues/736)
- Introduce a setting: `java.project.explorer.filters` to control whether non-Java resources show in Java Projects explorer. [#751](https://github.com/microsoft/vscode-java-dependency/issues/751)
- Support creating files and folders in Java Projects explorer. [#598](https://github.com/microsoft/vscode-java-dependency/issues/598)
- Apply file decorators to project level. [#481](https://github.com/microsoft/vscode-java-dependency/issues/481)
- Give more hints about the project import status. [#580](https://github.com/microsoft/vscode-java-dependency/issues/580)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
IPath workspaceFolderPath = ResourceUtils.canonicalFilePathFromURI(workspaceUri);

IProject[] projects;
boolean includeNonJava = false;
boolean filterNonJava = false;
if (arguments.size() > 1) {
includeNonJava = (boolean) arguments.get(1);
filterNonJava = (boolean) arguments.get(1);
}
if (includeNonJava) {
if (!filterNonJava) {
projects = ProjectUtils.getAllProjects();
} else {
projects = Arrays.stream(ProjectUtils.getJavaProjects())
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
"light": "icons/light/icon-link.svg"
}
},
{
"command": "java.project.explorer.configureFilters",
"title": "%contributes.commands.java.project.explorer.configureFilters%",
"category": "Java"
},
{
"command": "java.view.package.revealFileInOS",
"title": "%contributes.commands.java.view.package.revealFileInOS%",
Expand Down Expand Up @@ -258,6 +263,18 @@
],
"markdownDescription": "%configuration.java.project.exportJar.targetPath.customization%",
"default": "${workspaceFolder}/${workspaceFolderBasename}.jar"
},
"java.project.explorer.filters": {
"type": "object",
"description": "%configuration.java.project.explorer.filters%",
"default": {},
"properties": {
"nonJavaResources": {
"type": "boolean",
"description": "%configuration.java.project.explorer.filters.nonJavaResources%",
"default": false
}
}
}
}
},
Expand Down Expand Up @@ -481,6 +498,11 @@
"when": "view == javaProjectExplorer && java:serverMode == Standard && config.java.dependency.syncWithFolderExplorer == true",
"group": "overflow_10@20"
},
{
"command": "java.project.explorer.configureFilters",
"when": "view == javaProjectExplorer && java:serverMode == Standard",
"group": "overflow_10@30"
},
{
"command": "java.project.clean.workspace",
"when": "view == javaProjectExplorer && java:serverMode == Standard && !java:noJavaProjects",
Expand Down
3 changes: 3 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"Hierarchical View",
"contributes.commands.java.view.package.linkWithFolderExplorer":"Synchronize with Editor",
"contributes.commands.java.view.package.unlinkWithFolderExplorer":"Desynchronize with Editor",
"contributes.commands.java.project.explorer.configureFilters": "Configure Filters",
"contributes.commands.java.view.package.revealFileInOS": "Reveal in Explorer",
"contributes.commands.java.view.package.exportJar": "Export Jar...",
"contributes.commands.java.view.package.copyFilePath": "Copy Path",
Expand All @@ -33,6 +34,8 @@
"configuration.java.dependency.autoRefresh": "Synchronize Java Projects explorer with changes",
"configuration.java.dependency.refreshDelay": "The delay time (ms) the auto refresh is invoked when changes are detected",
"configuration.java.dependency.packagePresentation": "Package presentation mode: flat or hierarchical",
"configuration.java.project.explorer.filters": "Filters for the Java Projects explorer.",
"configuration.java.project.explorer.filters.nonJavaResources": "Specify whether non-Java resources will be filtered out.",
"configuration.java.project.exportJar.targetPath.customization": "The output path of the exported jar. Leave it empty if you want to manually pick the output location.",
"configuration.java.project.exportJar.targetPath.workspaceFolder": "Export the jar file into the workspace folder. Its name is the same as the folder's.",
"configuration.java.project.exportJar.targetPath.select": "Select output location manually when exporting the jar file.",
Expand Down
3 changes: 3 additions & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"层级显示",
"contributes.commands.java.view.package.linkWithFolderExplorer":"启用编辑器关联",
"contributes.commands.java.view.package.unlinkWithFolderExplorer":"关闭编辑器关联",
"contributes.commands.java.project.explorer.configureFilters": "设置过滤器",
"contributes.commands.java.view.package.revealFileInOS": "打开所在的文件夹",
"contributes.commands.java.view.package.exportJar": "导出到 Jar 文件...",
"contributes.commands.java.view.package.copyFilePath": "复制路径",
Expand All @@ -33,6 +34,8 @@
"configuration.java.dependency.autoRefresh": "在 Java 项目管理器中自动同步修改",
"configuration.java.dependency.refreshDelay": "控制 Java 项目管理器刷新的延迟时间 (毫秒)",
"configuration.java.dependency.packagePresentation": "Java 包显示方式: 平行显示或者分层显示",
"configuration.java.project.explorer.filters": "设置 Java 项目管理器要过滤的内容。",
"configuration.java.project.explorer.filters.nonJavaResources": "是否需要过滤非 Java 资源。",
"configuration.java.project.exportJar.targetPath.customization": "导出 Jar 文件的路径。您可以将此选项置为空串来手动选择 jar 文件的导出路径。",
"configuration.java.project.exportJar.targetPath.workspaceFolder": "导出 Jar 文件到工作空间文件夹下。Jar 文件的名称和工作空间文件夹的名称相同。",
"configuration.java.project.exportJar.targetPath.select": "在导出 Jar 文件时手动选择输出目录。",
Expand Down
2 changes: 2 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export namespace Commands {

export const VIEW_PACKAGE_UNLINKWITHFOLDER = "java.view.package.unlinkWithFolderExplorer";

export const JAVA_PROJECT_EXPLORER_CONFIGURE_FILTERS = "java.project.explorer.configureFilters";

export const VIEW_PACKAGE_REFRESH = "java.view.package.refresh";

export const VIEW_PACKAGE_INTERNAL_REFRESH = "_java.view.package.internal.refresh";
Expand Down
13 changes: 11 additions & 2 deletions src/java/jdtls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import { CancellationToken, Uri, commands, workspace } from "vscode";
import { Commands, executeJavaLanguageServerCommand } from "../commands";
import { IClasspath } from "../tasks/buildArtifact/IStepMetadata";
import { IMainClassInfo } from "../tasks/buildArtifact/ResolveMainClassExecutor";
import { INodeData } from "./nodeData";
import { INodeData, NodeKind } from "./nodeData";
import { Settings } from "../settings";

export namespace Jdtls {
export async function getProjects(params: string): Promise<INodeData[]> {
return await commands.executeCommand(
Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_PROJECT_LIST,
params,
true /*includeNonJavaProjects*/
Settings.nonJavaResourcesFiltered()
) || [];
}

Expand All @@ -33,6 +34,14 @@ export namespace Jdtls {

let nodeData: INodeData[] = await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND,
Commands.JAVA_GETPACKAGEDATA, params) || [];

// check filter settings.
if (Settings.nonJavaResourcesFiltered()) {
nodeData = nodeData.filter((data: INodeData) => {
return data.kind !== NodeKind.Folder && data.kind !== NodeKind.File;
});
}

if (excludePatterns && nodeData.length) {
const uriOfChildren: string[] = nodeData.map((node: INodeData) => node.uri).filter(Boolean) as string[];
const urisToExclude: Set<string> = new Set<string>();
Expand Down
22 changes: 21 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import {
commands, ConfigurationChangeEvent, ExtensionContext,
commands, ConfigurationChangeEvent, ConfigurationTarget, ExtensionContext,
workspace,
} from "vscode";
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
Expand All @@ -17,6 +17,7 @@ export class Settings {
if ((e.affectsConfiguration("java.dependency.syncWithFolderExplorer") && Settings.syncWithFolderExplorer()) ||
e.affectsConfiguration("java.dependency.showMembers") ||
e.affectsConfiguration("java.dependency.packagePresentation") ||
e.affectsConfiguration("java.project.explorer.filters") ||
e.affectsConfiguration("files.exclude")) {
commands.executeCommand(Commands.VIEW_PACKAGE_INTERNAL_REFRESH);
} else if (e.affectsConfiguration("java.dependency.autoRefresh")) {
Expand Down Expand Up @@ -57,6 +58,13 @@ export class Settings {
workspace.getConfiguration("java.dependency").update("packagePresentation", PackagePresentation.Hierarchical, false);
}

public static switchNonJavaResourceFilter(enabled: boolean): void {
workspace.getConfiguration("java.project.explorer").update(
"filters",
{ nonJavaResources: enabled },
ConfigurationTarget.Workspace);
}

public static updateReferencedLibraries(libraries: IReferencedLibraries): void {
let updateSetting: string[] | Partial<IReferencedLibraries> = {
include: libraries.include,
Expand Down Expand Up @@ -103,6 +111,14 @@ export class Settings {
// tslint:disable-next-line: no-invalid-template-strings
return workspace.getConfiguration("java.project.exportJar").get<string>("targetPath", "${workspaceFolder}/${workspaceFolderBasename}.jar");
}

/**
* Get whether non-Java resources should be filtered in the explorer.
*/
public static nonJavaResourcesFiltered(): boolean {
const filter: IExplorerFilter = workspace.getConfiguration("java.project.explorer").get<IExplorerFilter>("filters", {});
return !!filter.nonJavaResources;
}
}

enum PackagePresentation {
Expand All @@ -115,3 +131,7 @@ export interface IReferencedLibraries {
exclude: string[];
sources: { [binary: string]: string };
}

interface IExplorerFilter {
nonJavaResources?: boolean
}
17 changes: 17 additions & 0 deletions src/views/dependencyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ export class DependencyExplorer implements Disposable {

this.reveal(uri, false /*force to reveal even the sync setting is turned off*/);
}),
instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_EXPLORER_CONFIGURE_FILTERS, async () => {
const filters = await window.showQuickPick(
[{
label: "Non-Java resources",
picked: Settings.nonJavaResourcesFiltered(),
}],
{
placeHolder: "Select filters to apply to the Java Projects Explorer",
Comment thread
jdneo marked this conversation as resolved.
canPickMany: true,
}
);
if (!filters) {
return;
}

Settings.switchNonJavaResourceFilter(filters.some((filter) => filter.label === "Non-Java resources"));
}),
);

// register telemetry events
Expand Down
12 changes: 12 additions & 0 deletions test/maven-suite/projectView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,16 @@ suite("Maven Project View Tests", () => {
const projectChildren = await projectNode.getChildren();
assert.ok(!projectChildren.find((node: DataNode) => node.nodeData.name === ".hidden"));
});

test("Can apply 'java.project.explorer.filters.nonJavaResources'", async function() {
await vscode.workspace.getConfiguration("java.project.explorer").update(
"filters",
{ nonJavaResources:true }
);
const explorer = DependencyExplorer.getInstance(contextManager.context);

const projectNode = (await explorer.dataProvider.getChildren())![0] as ProjectNode;
const projectChildren = await projectNode.getChildren();
assert.equal(projectChildren.length, 4);
});
});