Skip to content

Commit 931ef78

Browse files
runchen0919claude
andcommitted
fix: compute longest common prefix for sibling packages in empty source roots
When a Bazel package contains source files from sibling Java packages (e.g. dto/ and merge/) without files in the root package, findCommonParentPackagePrefix returned null because it only checked if a detected package was a prefix of all others. This caused "an empty package fragment root must map to one Java package" errors. Now falls back to computing the actual longest common prefix path, allowing targets like messier_merger_lib with sources spanning sibling sub-packages to be provisioned correctly. Also adds support for merging multiple targets sharing an empty source root into a single Eclipse project, and collects dependencies from unprovisioned sibling targets for complete classpath computation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9921802 commit 931ef78

2 files changed

Lines changed: 232 additions & 53 deletions

File tree

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BaseProvisioningStrategy.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,28 @@ private IPath findCommonParentPackagePrefix(Collection<IPath> detectedJavaPackag
12621262
}
12631263
}
12641264

1265-
return null;
1265+
// none of the detected packages is a prefix of all others (sibling packages case)
1266+
// compute the actual longest common prefix path
1267+
// e.g. for [com/foo/bar/dto, com/foo/bar/merge] this yields com/foo/bar
1268+
IPath commonPrefix = null;
1269+
for (IPath path : detectedJavaPackagesForSourceDirectory) {
1270+
if (commonPrefix == null) {
1271+
commonPrefix = path;
1272+
} else {
1273+
var minLen = Math.min(commonPrefix.segmentCount(), path.segmentCount());
1274+
var commonLen = 0;
1275+
for (var i = 0; i < minLen; i++) {
1276+
if (commonPrefix.segment(i).equals(path.segment(i))) {
1277+
commonLen = i + 1;
1278+
} else {
1279+
break;
1280+
}
1281+
}
1282+
commonPrefix = commonPrefix.uptoSegment(commonLen);
1283+
}
1284+
}
1285+
1286+
return (commonPrefix == null) || commonPrefix.isEmpty() ? null : commonPrefix;
12661287
}
12671288

12681289
private IProject findProjectForLocation(IPath location) {

0 commit comments

Comments
 (0)