22
33import java .util .ArrayList ;
44import java .util .List ;
5+ import java .util .Map ;
6+ import java .util .concurrent .ConcurrentHashMap ;
57
68import org .eclipse .core .resources .IProject ;
79import org .eclipse .core .resources .IWorkspaceRoot ;
810import org .eclipse .core .resources .ResourcesPlugin ;
11+ import org .eclipse .core .runtime .CoreException ;
912import org .eclipse .core .runtime .IPath ;
1013import org .eclipse .core .runtime .IProgressMonitor ;
1114import org .eclipse .jdt .core .IClasspathEntry ;
@@ -44,26 +47,28 @@ public DependencyInfo(String key, String value) {
4447
4548 /**
4649 * Resolve project dependencies information including JDK version.
50+ * Supports both single projects and multi-module aggregator projects.
4751 *
48- * @param projectUri The project URI
52+ * @param fileUri The file URI
4953 * @param monitor Progress monitor for cancellation support
5054 * @return List of DependencyInfo containing key-value pairs of project information
5155 */
52- public static List <DependencyInfo > resolveProjectDependencies (String projectUri , IProgressMonitor monitor ) {
56+ public static List <DependencyInfo > resolveProjectDependencies (String fileUri , IProgressMonitor monitor ) {
5357 List <DependencyInfo > result = new ArrayList <>();
5458
5559 try {
56- IPath projectPath = ResourceUtils .canonicalFilePathFromURI (projectUri );
60+ IPath fileIPath = ResourceUtils .canonicalFilePathFromURI (fileUri );
5761
5862 // Find the project
5963 IWorkspaceRoot root = ResourcesPlugin .getWorkspace ().getRoot ();
60- IProject project = findProjectByPath (root , projectPath );
64+ IProject project = findProjectByPath (root , fileIPath );
6165
6266 if (project == null || !project .isAccessible ()) {
6367 return result ;
6468 }
6569
6670 IJavaProject javaProject = JavaCore .create (project );
71+ // Check if this is a Java project
6772 if (javaProject == null || !javaProject .exists ()) {
6873 return result ;
6974 }
@@ -86,14 +91,31 @@ public static List<DependencyInfo> resolveProjectDependencies(String projectUri,
8691
8792 /**
8893 * Find project by path from all projects in workspace.
94+ * The path can be either a project root path or a file/folder path within a project.
95+ * This method will find the project that contains the given path.
96+ *
97+ * @param root The workspace root
98+ * @param filePath The path to search for (can be project root or file within project)
99+ * @return The project that contains the path, or null if not found
89100 */
90- private static IProject findProjectByPath (IWorkspaceRoot root , IPath projectPath ) {
101+ private static IProject findProjectByPath (IWorkspaceRoot root , IPath filePath ) {
91102 IProject [] allProjects = root .getProjects ();
103+
104+ // First pass: check for exact project location match (most efficient)
92105 for (IProject p : allProjects ) {
93- if (p .getLocation () != null && p .getLocation ().equals (projectPath )) {
106+ if (p .getLocation () != null && p .getLocation ().equals (filePath )) {
94107 return p ;
95108 }
96109 }
110+
111+ // Second pass: check if the file path is within any project directory
112+ // This handles cases where filePath points to a file or folder inside a project
113+ for (IProject p : allProjects ) {
114+ if (p .getLocation () != null && p .getLocation ().isPrefixOf (filePath )) {
115+ return p ;
116+ }
117+ }
118+
97119 return null ;
98120 }
99121
@@ -158,17 +180,19 @@ private static void processClasspathEntries(List<DependencyInfo> result, IJavaPr
158180
159181 /**
160182 * Process a library classpath entry.
183+ * Only returns the library file name without full path to reduce data size.
161184 */
162185 private static void processLibraryEntry (List <DependencyInfo > result , IClasspathEntry entry , int libCount ) {
163186 IPath libPath = entry .getPath ();
164187 if (libPath != null ) {
165- result . add ( new DependencyInfo ( "library_" + libCount ,
166- libPath . lastSegment () + " (" + libPath .toOSString () + ")" ));
188+ // Only keep the file name, remove the full path
189+ result . add ( new DependencyInfo ( "library_" + libCount , libPath .lastSegment () ));
167190 }
168191 }
169192
170193 /**
171194 * Process a project reference classpath entry.
195+ * Simplified to only extract essential information.
172196 */
173197 private static void processProjectEntry (List <DependencyInfo > result , IClasspathEntry entry , int projectRefCount ) {
174198 IPath projectRefPath = entry .getPath ();
@@ -185,12 +209,21 @@ private static void processContainerEntry(List<DependencyInfo> result, IClasspat
185209 String containerPath = entry .getPath ().toString ();
186210
187211 if (containerPath .contains ("JRE_CONTAINER" )) {
188- result . add ( new DependencyInfo ( KEY_JRE_CONTAINER_PATH , containerPath ));
212+ // Only extract the JRE version, not the full container path
189213 try {
190214 String vmInstallName = JavaRuntime .getVMInstallName (entry .getPath ());
191215 addIfNotNull (result , KEY_JRE_CONTAINER , vmInstallName );
192216 } catch (Exception e ) {
193- // Ignore if unable to get VM install name
217+ // Fallback: try to extract version from path
218+ if (containerPath .contains ("JavaSE-" )) {
219+ int startIdx = containerPath .lastIndexOf ("JavaSE-" );
220+ String version = containerPath .substring (startIdx );
221+ // Clean up any trailing characters
222+ if (version .contains ("/" )) {
223+ version = version .substring (0 , version .indexOf ("/" ));
224+ }
225+ result .add (new DependencyInfo (KEY_JRE_CONTAINER , version ));
226+ }
194227 }
195228 } else if (containerPath .contains ("MAVEN" )) {
196229 result .add (new DependencyInfo (KEY_BUILD_TOOL , "Maven" ));
0 commit comments