@@ -100,16 +100,38 @@ public Path getTestDir(String coordinates) {
100100 Objects .requireNonNull (artifactId , "Artifact ID must be specified" );
101101 Objects .requireNonNull (version , "Version must be specified" );
102102
103- // First, let's try if we can find test directory from the new `tests/src/index.json` file.
104- List <Map <String , ?>> index = (List <Map <String , ?>>) readIndexFile (testRoot ());
105- for (Map <String , ?> entry : index ) {
106- boolean found = ((List <Map <String , ?>>) entry .get ("libraries" )).stream ().anyMatch (
107- lib -> coordinatesMatch ((String ) lib .get ("name" ), groupId , artifactId ) &&
108- ((List <String >) lib .get ("versions" )).contains (version )
109- );
110- if (found ) {
111- return testRoot ().resolve ((String ) entry .get ("test-project-path" ));
103+ // First, try to locate the test project via the aggregated tests/src/index.json (new layout).
104+ try {
105+ List <Map <String , ?>> index = (List <Map <String , ?>>) readIndexFile (testRoot ());
106+ for (Map <String , ?> entry : index ) {
107+ boolean found = ((List <Map <String , ?>>) entry .get ("libraries" )).stream ().anyMatch (
108+ lib -> coordinatesMatch ((String ) lib .get ("name" ), groupId , artifactId ) &&
109+ ((List <String >) lib .get ("versions" )).contains (version )
110+ );
111+ if (found ) {
112+ return testRoot ().resolve ((String ) entry .get ("test-project-path" ));
113+ }
114+ }
115+ } catch (Exception ignored ) {
116+ // Fall through to conventional layout resolution below.
117+ }
118+ // Fallback: conventional layout tests/src/<group>/<artifact>/<version>
119+ Path conventional = testRoot ().resolve (groupId ).resolve (artifactId ).resolve (version );
120+ if (Files .isDirectory (conventional )) {
121+ return conventional ;
122+ }
123+ // Secondary fallback: derive test dir from metadata "metadata-version"
124+ try {
125+ Path mdDir = getMetadataDir (coordinates ); // .../metadata/<group>/<artifact>/<metadata-version>
126+ Path mdVersion = mdDir .getFileName ();
127+ if (mdVersion != null ) {
128+ Path testsForMetadataVersion = testRoot ().resolve (groupId ).resolve (artifactId ).resolve (mdVersion .toString ());
129+ if (Files .isDirectory (testsForMetadataVersion )) {
130+ return testsForMetadataVersion ;
131+ }
112132 }
133+ } catch (Exception ignored ) {
134+ // ignore and fall through to error
113135 }
114136 throw new RuntimeException ("Missing test-directory for coordinates `" + coordinates + "`" );
115137 }
0 commit comments