diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java index f64bd07c..a872a7fe 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaSourceInfo.java @@ -164,15 +164,20 @@ public void analyzeSourceDirectories(MultiStatus result) throws CoreException { // (this is a strong split-package indication) Set potentialSplitPackageOrSubsetFolders = new HashSet<>(); for (Map.Entry> entry : sourceEntriesByParentFolder.entrySet()) { - var entryParentPath = entry.getKey(); - var entryParentLocation = bazelPackageLocation.append(entryParentPath).toPath(); + var potentialSourceRoot = entry.getKey(); + if (isContainedInSharedSourceDirectories(potentialSourceRoot)) { + // don't check for split packages for stuff covered in shared sources already + continue; + } + + var entryParentLocation = bazelPackageLocation.append(potentialSourceRoot).toPath(); var declaredJavaFilesInFolder = entry.getValue().size(); try { // when there are declared Java files, expect them to match if (declaredJavaFilesInFolder > 0) { var javaFilesInParent = Files.list(entryParentLocation).filter(JavaSourceInfo::isJavaFile).count(); if (javaFilesInParent != declaredJavaFilesInFolder) { - if (potentialSplitPackageOrSubsetFolders.add(entryParentPath)) { + if (potentialSplitPackageOrSubsetFolders.add(potentialSourceRoot)) { result.add( Status.warning( format( @@ -197,6 +202,10 @@ public void analyzeSourceDirectories(MultiStatus result) throws CoreException { if (!(potentialSourceRootAndSourceEntries.getValue() instanceof List)) { continue; } + if (isContainedInSharedSourceDirectories(potentialSourceRoot)) { + // don't check for split packages for stuff covered in shared sources already + continue; + } var potentialSourceRootPath = bazelPackageLocation.append(potentialSourceRoot).toPath(); try { @@ -220,17 +229,9 @@ public void analyzeSourceDirectories(MultiStatus result) throws CoreException { } } - /* - * Bazel allows to re-use sources in multiple targets. It will then compile those multiple times. An example setup - * is where all code is exposed as java_library as well as many targets for java_test with - * only one test class. If this is the case, we want to not issue "split package" warnings when the test class is - * already handled at the java_library level. - */ + // don't issue split packages warning nfor stuff covered in shared sources already if ((sharedSourceInfo != null) && sharedSourceInfo.hasSourceDirectories()) { - var sharedSourceDirectories = sharedSourceInfo.getSourceDirectories(); - potentialSplitPackageOrSubsetFolders.removeIf( - potentialSourceRoot -> sharedSourceDirectories.contains(potentialSourceRoot) - || sharedSourceDirectories.stream().anyMatch(p -> p.isPrefixOf(potentialSourceRoot))); + potentialSplitPackageOrSubsetFolders.removeIf(this::isContainedInSharedSourceDirectories); } // when there are no split packages we found a good setup @@ -381,6 +382,23 @@ public boolean hasSourceFilesWithoutCommonRoot() { return (sourceFilesWithoutCommonRoot != null) && !sourceFilesWithoutCommonRoot.isEmpty(); } + private boolean isContainedInSharedSourceDirectories(IPath potentialSourceRoot) { + if ((sharedSourceInfo == null) || !sharedSourceInfo.hasSourceDirectories()) { + return false; + } + + /* + * Bazel allows to re-use sources in multiple targets. It will then compile those multiple times. An example setup + * is where all code is exposed as java_library as well as many targets for java_test with + * only one test class. If this is the case, we want to not issue "split package" warnings when the test class is + * already handled at the java_library level. + */ + + var sharedSourceDirectories = sharedSourceInfo.getSourceDirectories(); + return sharedSourceDirectories.contains(potentialSourceRoot) + || sharedSourceDirectories.stream().anyMatch(p -> p.isPrefixOf(potentialSourceRoot)); + } + @SuppressWarnings("deprecation") // use of TokenNameIdentifier is ok here private String readPackageName(JavaSourceEntry fileEntry) { var packageName = new StringBuilder();