Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Referenced Libraries container should be immutable for build tool projects #826

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,8 @@ private static List<PackageNode> getProjectChildren(PackageParams query, IProgre
List<PackageNode> result = visitor.getNodes();

// Invisible project will always have the referenced libraries entry
if (!ProjectUtils.isVisibleProject(project)) {
if (!ProjectUtils.isVisibleProject(project) || hasReferencedLibraries) {
result.add(PackageNode.REFERENCED_LIBRARIES_CONTAINER);
} else if (hasReferencedLibraries) {
result.add(PackageNode.IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER);
}
return result;
}
Expand Down Expand Up @@ -589,7 +587,7 @@ public static IProject getProject(String projectUri) {
}

// This must be an invisible project.
// There might be more than one way to access it, but all containers should link to the same project.
// There might be more than one way to access it, but all containers should link to the same project.
return containers[0].getProject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ public class PackageNode {

public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
private static final String REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries";
private static final String IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries (Read-only)";
public static final ContainerNode REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(
REFERENCED_LIBRARIES_CONTAINER_NAME, REFERENCED_LIBRARIES_PATH,
NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(
IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME,
REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);

/**
* Nature Id for the IProject.
Expand Down
3 changes: 2 additions & 1 deletion src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class ContainerNode extends DataNode {
return ContainerType.Maven;
} else if (containerPath.startsWith(ContainerPath.Gradle)) {
return ContainerType.Gradle;
} else if (containerPath.startsWith(ContainerPath.ReferencedLibrary)) {
} else if (containerPath.startsWith(ContainerPath.ReferencedLibrary) && this._project.isUnmanagedFolder()) {
// currently, we only support editing referenced libraries in unmanaged folders
return ContainerType.ReferencedLibrary;
}
return ContainerType.Unknown;
Expand Down
3 changes: 2 additions & 1 deletion src/views/packageRootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class PackageRootNode extends DataNode {
if (data.entryKind === PackageRootKind.K_BINARY) {
contextValue = Explorer.ContextValueType.Jar;
const parent = <ContainerNode>this.getParent();
if (parent.path?.startsWith("REFERENCED_LIBRARIES_PATH")) {
// currently, we only support editing referenced libraries in unmanaged folders
if (parent.path?.startsWith("REFERENCED_LIBRARIES_PATH") && this._project.isUnmanagedFolder()) {
contextValue += "+referencedLibrary";
}
return contextValue;
Expand Down
4 changes: 2 additions & 2 deletions test/suite/contextValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const referencedLibrariesContainer: ContainerNode = new ContainerNode({
uri: Uri.file(__dirname).toString(),
kind: NodeKind.Container,
path: "REFERENCED_LIBRARIES_PATH",
}, mavenProject, mavenProject);
}, mavenProject, unmanagedFolder);

const sourceRoot: PackageRootNode = new PackageRootNode({
name: "src/main/java",
Expand Down Expand Up @@ -220,7 +220,7 @@ const referencedLibraryJar: PackageRootNode = new PackageRootNode({
uri: Uri.file(__dirname).toString(),
kind: NodeKind.PackageRoot,
entryKind: PackageRootKind.K_BINARY,
} as INodeData, referencedLibrariesContainer, mavenProject);
} as INodeData, referencedLibrariesContainer, unmanagedFolder);

const sourcePackage: PackageNode = new PackageNode({
name: "com.microsoft.java",
Expand Down
Loading