Skip to content
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 @@ -506,7 +506,7 @@ private static String getSeverityString(int severity) {
/**
* Get project dependencies information including JDK version.
*
* @param arguments List containing the project URI as the first element
* @param arguments List containing the file URI as the first element
* @param monitor Progress monitor for cancellation support
* @return List of DependencyInfo containing key-value pairs of project information
*/
Expand All @@ -515,8 +515,8 @@ public static List<DependencyInfo> getProjectDependencies(List<Object> arguments
return new ArrayList<>();
}

String projectUri = (String) arguments.get(0);
List<ProjectResolver.DependencyInfo> resolverResult = ProjectResolver.resolveProjectDependencies(projectUri, monitor);
String fileUri = (String) arguments.get(0);
List<ProjectResolver.DependencyInfo> resolverResult = ProjectResolver.resolveProjectDependencies(fileUri, monitor);

// Convert ProjectResolver.DependencyInfo to ProjectCommand.DependencyInfo
List<DependencyInfo> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IClasspathEntry;
Expand Down Expand Up @@ -44,26 +47,28 @@ public DependencyInfo(String key, String value) {

/**
* Resolve project dependencies information including JDK version.
* Supports both single projects and multi-module aggregator projects.
*
* @param projectUri The project URI
* @param fileUri The file URI
* @param monitor Progress monitor for cancellation support
* @return List of DependencyInfo containing key-value pairs of project information
*/
public static List<DependencyInfo> resolveProjectDependencies(String projectUri, IProgressMonitor monitor) {
public static List<DependencyInfo> resolveProjectDependencies(String fileUri, IProgressMonitor monitor) {
List<DependencyInfo> result = new ArrayList<>();

try {
IPath projectPath = ResourceUtils.canonicalFilePathFromURI(projectUri);
IPath fileIPath = ResourceUtils.canonicalFilePathFromURI(fileUri);

// Find the project
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = findProjectByPath(root, projectPath);
IProject project = findProjectByPath(root, fileIPath);

if (project == null || !project.isAccessible()) {
return result;
}

IJavaProject javaProject = JavaCore.create(project);
// Check if this is a Java project
if (javaProject == null || !javaProject.exists()) {
return result;
}
Expand All @@ -86,14 +91,31 @@ public static List<DependencyInfo> resolveProjectDependencies(String projectUri,

/**
* Find project by path from all projects in workspace.
* The path can be either a project root path or a file/folder path within a project.
* This method will find the project that contains the given path.
*
* @param root The workspace root
* @param filePath The path to search for (can be project root or file within project)
* @return The project that contains the path, or null if not found
*/
private static IProject findProjectByPath(IWorkspaceRoot root, IPath projectPath) {
private static IProject findProjectByPath(IWorkspaceRoot root, IPath filePath) {
IProject[] allProjects = root.getProjects();

// First pass: check for exact project location match (most efficient)
for (IProject p : allProjects) {
if (p.getLocation() != null && p.getLocation().equals(projectPath)) {
if (p.getLocation() != null && p.getLocation().equals(filePath)) {
return p;
}
}

// Second pass: check if the file path is within any project directory
// This handles cases where filePath points to a file or folder inside a project
for (IProject p : allProjects) {
if (p.getLocation() != null && p.getLocation().isPrefixOf(filePath)) {
return p;
}
}

return null;
}

Expand Down Expand Up @@ -158,17 +180,19 @@ private static void processClasspathEntries(List<DependencyInfo> result, IJavaPr

/**
* Process a library classpath entry.
* Only returns the library file name without full path to reduce data size.
*/
private static void processLibraryEntry(List<DependencyInfo> result, IClasspathEntry entry, int libCount) {
IPath libPath = entry.getPath();
if (libPath != null) {
result.add(new DependencyInfo("library_" + libCount,
libPath.lastSegment() + " (" + libPath.toOSString() + ")"));
// Only keep the file name, remove the full path
result.add(new DependencyInfo("library_" + libCount, libPath.lastSegment()));
}
}

/**
* Process a project reference classpath entry.
* Simplified to only extract essential information.
*/
private static void processProjectEntry(List<DependencyInfo> result, IClasspathEntry entry, int projectRefCount) {
IPath projectRefPath = entry.getPath();
Expand All @@ -185,12 +209,21 @@ private static void processContainerEntry(List<DependencyInfo> result, IClasspat
String containerPath = entry.getPath().toString();

if (containerPath.contains("JRE_CONTAINER")) {
result.add(new DependencyInfo(KEY_JRE_CONTAINER_PATH, containerPath));
// Only extract the JRE version, not the full container path
try {
String vmInstallName = JavaRuntime.getVMInstallName(entry.getPath());
addIfNotNull(result, KEY_JRE_CONTAINER, vmInstallName);
} catch (Exception e) {
// Ignore if unable to get VM install name
// Fallback: try to extract version from path
if (containerPath.contains("JavaSE-")) {
int startIdx = containerPath.lastIndexOf("JavaSE-");
String version = containerPath.substring(startIdx);
// Clean up any trailing characters
if (version.contains("/")) {
version = version.substring(0, version.indexOf("/"));
}
result.add(new DependencyInfo(KEY_JRE_CONTAINER, version));
}
}
} else if (containerPath.contains("MAVEN")) {
result.add(new DependencyInfo(KEY_BUILD_TOOL, "Maven"));
Expand Down
Loading