amondel2 commented on code in PR #432:
URL: 
https://github.com/apache/grails-intellij-plugin/pull/432#discussion_r4195067170


##########
plugin/src/main/java/org/apache/grails/intellij/plugin/projectView/impl/Grails3NodeProvider.java:
##########
@@ -77,4 +118,52 @@ public class Grails3NodeProvider implements 
GrailsViewNodeProvider {
     result.add(new GrailsPluginsNode(application.getProject(), settings));
     return result;
   }
+
+  /**
+   * Discovers the test source roots to lift out of {@code src}. {@code 
ProjectFileIndex} is consulted
+   * first, but only as positive evidence: a module registers the whole 
content root as one SOURCE root,
+   * so it reports a non-test type for every candidate — including in this 
project's own light fixture —
+   * and on its own would lift nothing. The structural rule below is therefore 
the heuristic that
+   * carries discovery wherever the module does not register each phase as its 
own test source root.
+   */
+  private static @NotNull List<PsiDirectory> 
findTestSourceDirectories(@NotNull PsiDirectory src) {
+    ProjectFileIndex index = ProjectFileIndex.getInstance(src.getProject());
+    List<PsiDirectory> result = new ArrayList<>();
+    for (VirtualFile child : src.getVirtualFile().getChildren()) {
+      if (!child.isDirectory() || !isTestSourceRoot(index, child)) continue;
+      PsiDirectory directory = 
PsiManager.getInstance(src.getProject()).findDirectory(child);
+      if (directory != null) result.add(directory);
+    }
+    return result;
+  }
+
+  private static boolean isTestSourceRoot(@NotNull ProjectFileIndex index, 
@NotNull VirtualFile child) {
+    JpsModuleSourceRootType<?> type = index.getContainingSourceRootType(child);
+    if (type != null && type.isForTests()) return true;
+    // src/main is the production root, and a built-in phase is a test root 
whatever it holds. Any other
+    // child qualifies only on the shape of a Grails source root: it holds a 
conventional code source
+    // directory, which is what a custom testPhases entry generates.
+    //
+    // This rule assumes every non-main code-source root under src is a phase. 
A project with a
+    // non-standard production root there (src/legacy/groovy, say) has it 
lifted out of src and labelled
+    // Tests:legacy. Skipping the rule when the index reports a production 
root would not help: Gradle
+    // registers the whole content root as one SOURCE root, so the index 
reports non-test for every
+    // candidate and the rule would stop lifting anything at all.
+    String name = child.getName();
+    if ("main".equals(name)) return false;
+    if (PHASE_TITLES.containsKey(name)) return true;
+    for (VirtualFile grandChild : child.getChildren()) {
+      if (grandChild.isDirectory() && 
CODE_SOURCE_DIRS.contains(grandChild.getName())) return true;

Review Comment:
   Addressed the P2 from the re-review. Test-phase discovery is now 
registration-driven rather than shape-based.
   
   **What changed**
   
   `findTestSourceDirectories` now asks `ModuleRootManager` for the module's 
source roots, keeps the ones `ProjectFileIndex.isInTestSourceContent` reports 
as test content, and lifts the direct child of `src` that contains each. The 
conventional names (`test`, `integration-test`, `functional-test`) remain as a 
fallback for phases the module does not register, which is common before Gradle 
import.
   
   This fixes both cases from the review:
   
   - A production root registered under `src` (e.g. `src/generated/java` as 
`SOURCE`) is no longer lifted as a `Tests` node.
   - A custom phase registered as `TEST_RESOURCE` (e.g. 
`src/smoke-test/resources`) is now found even without a Groovy/Java directory.
   
   **Tests**
   
   - `testProductionSourceRootUnderSrcIsNotLifted` — a `SOURCE` root under 
`src` stays put; `src` still claims its files.
   - `testCustomPhaseRegisteredAsTestResourcesIsLifted` — a 
`TEST_RESOURCE`-only phase is lifted.
   - `testTestSourceRootRegisteredAsDirectChildOfSrcIsLifted` — a test source 
root registered as a direct child of `src` (not a grandchild) is lifted.
   - `testLiftsCustomTestPhaseAndTitlesItFromItsDirectoryName` — updated to 
register its fixtures through `ModuleRootModificationUtil`, the way Gradle 
import would.
   
   **Javadoc**
   
   Corrected the `findTestSourceDirectories` comment: the fallback covers any 
unregistered phase, not just the case where the module registers none of the 
built-in phases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to