55
55
import org .junit .platform .launcher .listeners .UniqueIdTrackingListener ;
56
56
import org .junit .platform .reporting .legacy .xml .LegacyXmlReportGeneratingListener ;
57
57
58
+ import java .io .File ;
58
59
import java .io .IOException ;
59
60
import java .io .PrintWriter ;
60
61
import java .io .UncheckedIOException ;
@@ -82,7 +83,6 @@ public static void main(String... args) {
82
83
83
84
/* scan runtime arguments */
84
85
String xmlOutput = DEFAULT_OUTPUT_FOLDER ;
85
- String testIds = null ;
86
86
boolean silent = false ;
87
87
88
88
LinkedList <String > arguments = new LinkedList <>(Arrays .asList (args ));
@@ -94,17 +94,13 @@ public static void main(String... args) {
94
94
System .out .println ("----------------------------------------\n " );
95
95
System .out .println ("Flags:" );
96
96
System .out .println (stringPad ("--xml-output-dir" ) + "Selects report xml output directory (default: `" + DEFAULT_OUTPUT_FOLDER + "`)" );
97
- System .out .println (stringPad ("--test-ids" ) + "Provides path to generated testIDs" );
98
97
System .out .println (stringPad ("--silent" ) + "Only output xml without stdout summary" );
99
98
System .out .println (stringPad ("--help" ) + "Displays this help screen" );
100
99
System .exit (0 );
101
100
break ;
102
101
case "--xml-output-dir" :
103
102
xmlOutput = arguments .poll ();
104
103
break ;
105
- case "--test-ids" :
106
- testIds = arguments .poll ();
107
- break ;
108
104
case "--silent" :
109
105
silent = true ;
110
106
break ;
@@ -119,14 +115,8 @@ public static void main(String... args) {
119
115
throw new RuntimeException ("xml-output-dir argument passed incorrectly to the launcher class." );
120
116
}
121
117
122
- if (testIds == null ) {
123
- System .out .println ("[junit-platform-native] WARNING: test-ids not provided to the NativeImageJUnitLauncher. " +
124
- "This should only happen if you are running tests binary manually (instead of using 'gradle nativeTest' command)" );
125
- testIds = getTestIDsFromDefaultLocations ();
126
- }
127
-
128
118
Launcher launcher = LauncherFactory .create ();
129
- TestPlan testPlan = getTestPlan (launcher , testIds );
119
+ TestPlan testPlan = getTestPlan (launcher );
130
120
131
121
PrintWriter out = new PrintWriter (System .out );
132
122
if (!silent ) {
@@ -151,28 +141,30 @@ public static void main(String... args) {
151
141
System .exit (failedCount > 0 ? 1 : 0 );
152
142
}
153
143
154
- private static TestPlan getTestPlan (Launcher launcher , String testIDs ) {
155
- List <? extends DiscoverySelector > selectors = getSelectors (testIDs );
144
+ private static TestPlan getTestPlan (Launcher launcher ) {
145
+ List <? extends DiscoverySelector > selectors = getSelectors ();
156
146
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder .request ()
157
147
.selectors (selectors )
158
148
.build ();
159
149
160
150
return launcher .discover (request );
161
151
}
162
152
163
- private static List <? extends DiscoverySelector > getSelectors (String testIDs ) {
153
+ private static List <? extends DiscoverySelector > getSelectors () {
164
154
try {
165
- Path outputDir = Paths .get (testIDs );
166
- String prefix = System .getProperty (UniqueIdTrackingListener .OUTPUT_FILE_PREFIX_PROPERTY_NAME ,
155
+ String systemPropertyBasedLocation = System .getProperty (UniqueIdTrackingListener .OUTPUT_DIR_PROPERTY_NAME );
156
+ Path uniqueIdDirectory = systemPropertyBasedLocation != null ? Path .of (systemPropertyBasedLocation ) : getTestIDsFromDefaultLocations ();
157
+ String uniqueIdFilePrefix = System .getProperty (UniqueIdTrackingListener .OUTPUT_FILE_PREFIX_PROPERTY_NAME ,
167
158
UniqueIdTrackingListener .DEFAULT_OUTPUT_FILE_PREFIX );
168
- List <UniqueIdSelector > selectors = readAllFiles (outputDir , prefix )
159
+
160
+ List <UniqueIdSelector > selectors = readAllFiles (uniqueIdDirectory , uniqueIdFilePrefix )
169
161
.map (DiscoverySelectors ::selectUniqueId )
170
162
.collect (Collectors .toList ());
171
163
if (!selectors .isEmpty ()) {
172
164
System .out .printf (
173
165
"[junit-platform-native] Running in 'test listener' mode using files matching pattern [%s*] "
174
166
+ "found in folder [%s] and its subfolders.%n" ,
175
- prefix , outputDir .toAbsolutePath ());
167
+ uniqueIdFilePrefix , uniqueIdDirectory .toAbsolutePath ());
176
168
return selectors ;
177
169
}
178
170
} catch (Exception ex ) {
@@ -201,47 +193,53 @@ private static Stream<Path> findFiles(Path dir, String prefix) throws IOExceptio
201
193
&& path .getFileName ().toString ().startsWith (prefix )));
202
194
}
203
195
204
- private static String getTestIDsFromDefaultLocations () {
205
- System .out .println ("[junit-platform-native] WARNING: Trying to find test-ids on default locations." );
196
+ private static Path getTestIDsFromDefaultLocations () {
197
+ System .out .println ("[junit-platform-native] WARNING: Trying to find test-ids on default locations. " +
198
+ "This should only happen if you are running tests executable manually." );
206
199
Path defaultGradleTestIDsLocation = getGradleTestIdsDefaultLocation ();
207
200
Path defaultMavenTestIDsLocation = getMavenTestIDsDefaultLocation ();
208
201
209
202
if (Files .exists (defaultGradleTestIDsLocation ) && Files .exists (defaultMavenTestIDsLocation )) {
210
203
throw new RuntimeException ("[junit-platform-native] test-ids found in both " + defaultGradleTestIDsLocation + " and " + defaultMavenTestIDsLocation +
211
- ". Please specify the test-ids location by passing the '--test-ids <path-to-test-ids>' argument to your tests executable." );
204
+ ". Please specify the test-ids location by passing the '--test-ids <path-to-test-ids>' argument to your tests executable." );
212
205
}
213
206
214
207
if (Files .exists (defaultGradleTestIDsLocation )) {
215
208
System .out .println ("[junit-platform-native] WARNING: Using test-ids from default Gradle project location:" + defaultGradleTestIDsLocation );
216
- return defaultGradleTestIDsLocation . toString () ;
209
+ return defaultGradleTestIDsLocation ;
217
210
}
218
211
219
212
if (Files .exists (defaultMavenTestIDsLocation )) {
220
213
System .out .println ("[junit-platform-native] WARNING: Using test-ids from default Maven project location:" + defaultMavenTestIDsLocation );
221
- return defaultMavenTestIDsLocation . toString () ;
214
+ return defaultMavenTestIDsLocation ;
222
215
}
223
216
224
217
throw new RuntimeException ("[junit-platform-native] test-ids not provided to the NativeImageJUnitLauncher and cannot be found on default locations. " +
225
- "Searched in: " + defaultGradleTestIDsLocation + " and " + defaultMavenTestIDsLocation );
218
+ "Searched in: " + defaultGradleTestIDsLocation + " and " + defaultMavenTestIDsLocation );
226
219
}
227
220
228
221
private static Path getGradleTestIdsDefaultLocation () {
229
- return Path .of (getBuildDirectory ("/ build/" ))
222
+ return Path .of (getBuildDirectory (File . separator + " build" + File . separator ))
230
223
.resolve ("test-results" )
231
224
.resolve ("test" )
232
225
.resolve ("testlist" )
233
226
.toAbsolutePath ();
234
227
}
235
228
236
229
private static Path getMavenTestIDsDefaultLocation () {
237
- return Path .of (getBuildDirectory ("/ target/" ))
230
+ return Path .of (getBuildDirectory (File . separator + " target" + File . separator ))
238
231
.resolve ("test-ids" )
239
232
.toAbsolutePath ();
240
233
}
241
234
242
235
private static String getBuildDirectory (String buildDir ) {
243
236
String executableLocation = Path .of ("." ).toAbsolutePath ().toString ();
244
- return executableLocation .substring (0 , executableLocation .indexOf (buildDir ) + buildDir .length ());
237
+ int index = executableLocation .indexOf (buildDir );
238
+ if (index < 0 ) {
239
+ return buildDir .substring (1 );
240
+ }
241
+
242
+ return executableLocation .substring (0 , index + buildDir .length ());
245
243
}
246
244
247
245
}
0 commit comments