@@ -205,20 +205,25 @@ public Builder withVisitor(Supplier<? extends ParseTreeVisitor<?>> visitor) {
205
205
return this ;
206
206
}
207
207
208
- public Builder withTagExpression (String str ) {
209
- Preconditions .checkNotNull (str , "Tag expression cannot be null!" );
210
- String commandLineTags = System .getProperty ("tags" );
211
- if (commandLineTags != null && !commandLineTags .isEmpty ()) {
212
- this .tagExpression = commandLineTags ;
213
- logger .info ("Overriding runner tags with tags provided in the command line {%s}" .formatted (commandLineTags ) );
214
- logger .info ("Ignoring provided tag expression {%s}" .formatted (str ) );
215
- } else {
216
- this .tagExpression =str ;
208
+ public Builder withTagExpression (String str ) {
209
+ Preconditions .checkNotNull (str , "Tag expression cannot be null!" );
210
+ // Check if there are tags specified using the system property "tags".
211
+ String commandLineTags = System .getProperty ("tags" );
212
+ if (commandLineTags != null && !commandLineTags .isEmpty ()) {
213
+ // If command-line tags are present, use them and log a message informing the user
214
+ // that the provided tag expression is being ignored.
215
+ this .tagExpression = commandLineTags ;
216
+ logger .info ("Overriding runner tags with tags provided in the command line {%s}" .formatted (
217
+ commandLineTags ));
218
+ logger .info ("Ignoring provided tag expression {%s}" .formatted (str ));
219
+ } else {
220
+ // If no command-line tags are present, use the provided tag expression.
221
+ this .tagExpression = str ;
222
+ }
223
+
224
+ return this ;
217
225
}
218
226
219
- return this ;
220
- }
221
-
222
227
public Builder withIncludedResources (String [] resources ) {
223
228
this .includesResources = resources ;
224
229
return this ;
@@ -246,52 +251,5 @@ public PdslTestParameter build() {
246
251
return new PdslTestParameter (this );
247
252
}
248
253
}
249
- public static PdslTestParameter createTestParameter (Supplier <ParseTreeListener > parseTreeListenerSupplier ,
250
- Class <? extends Lexer > lexerClass ,
251
- Class <? extends Parser > parserClass ,
252
- String [] includedResources ) {
253
- String defaultTagExpression = "@comment_tag#2" ;
254
- String commandLineTags = System .getProperty ("tags" ); // Get the value
255
-
256
- String effectiveTagExpression = (commandLineTags != null && !commandLineTags .isEmpty ())
257
- ? commandLineTags
258
- : defaultTagExpression ;
259
-
260
- return new PdslTestParameter .Builder (parseTreeListenerSupplier , lexerClass , parserClass )
261
- .withTagExpression (effectiveTagExpression )
262
- .withIncludedResources (includedResources )
263
- .build ();
264
- }
265
-
266
- /**
267
- * I've introduced a static factory method createTestParameter. This method handles the logic for
268
- * overriding the tag expression. This keeps the builder focused on building objects and separates
269
- * the configuration logic.
270
- */
271
- public static PdslTestParameter createTestParameter (
272
- Supplier <ParseTreeListener > parseTreeListenerSupplier ,
273
- Class <? extends Lexer > lexerClass ,
274
- Class <? extends Parser > parserClass ,
275
- String [] includedResources , String defaultTagExpression ) {
276
- // retrieves the value passed from the command line (e.g., -Dtags="@smoke").
277
- String commandLineTags = System .getProperty ("tags" );
278
- // handles the logic for overriding the tag expression
279
- String effectiveTagExpression = (commandLineTags != null && !commandLineTags .isEmpty ())
280
- ? commandLineTags
281
- : defaultTagExpression ;
282
-
283
- // // String effectiveTagExpression = defaultTagExpression; // Use default if invalid format
284
- // if (commandLineTags != null && !commandLineTags.isEmpty()) {
285
- // String pattern = "^(?:@\\w+(?: and | or )?)*@\\w+$";
286
- // if (Pattern.matches(pattern, commandLineTags)) {
287
- // // ... logic to build effectiveTagExpression from commandLineTags (as shown above) ...
288
- // }
289
- // }
290
-
291
- return new PdslTestParameter .Builder (parseTreeListenerSupplier , lexerClass , parserClass )
292
- .withTagExpression (effectiveTagExpression )
293
- .withIncludedResources (includedResources )
294
- .build ();
295
- }
296
254
}
297
255
0 commit comments