7
7
import com .fasterxml .jackson .databind .ObjectMapper ;
8
8
import com .fasterxml .jackson .databind .SerializationFeature ;
9
9
import org .graalvm .internal .tck .model .MetadataIndexEntry ;
10
- import org .graalvm .internal .tck .model .contributing .PredefinedClassesConfigModel ;
11
- import org .graalvm .internal .tck .model .contributing .ResourceConfigModel ;
12
10
import org .graalvm .internal .tck .model .contributing .Question ;
13
- import org .graalvm .internal .tck .model .contributing .SerializationConfigModel ;
14
11
import org .graalvm .internal .tck .utils .ConfigurationStringBuilder ;
15
12
import org .graalvm .internal .tck .utils .FilesUtils ;
16
13
import org .graalvm .internal .tck .utils .InteractiveTaskUtils ;
@@ -112,9 +109,6 @@ void run() throws IOException {
112
109
// run agent in conditional mode
113
110
collectMetadata ();
114
111
115
- // remove empty files
116
- removeEmptyConfigFiles ();
117
-
118
112
// create a PR
119
113
boolean shouldCreatePR = shouldCreatePullRequest ();
120
114
if (shouldCreatePR ) {
@@ -285,13 +279,13 @@ private List<Coordinates> getAdditionalDependencies() {
285
279
private void createStubs (boolean shouldUpdate ){
286
280
InteractiveTaskUtils .printUserInfo ("Generating stubs for: " + coordinates );
287
281
if (shouldUpdate ) {
288
- invokeCommand (gradlew + " scaffold --coordinates " + coordinates + " --update" , "Cannot generate stubs for: " + coordinates );
282
+ invokeCommand (gradlew + " scaffold --coordinates " + coordinates + " --skipTests -- update " , "Cannot generate stubs for: " + coordinates );
289
283
} else {
290
- invokeCommand (gradlew + " scaffold --coordinates " + coordinates , "Cannot generate stubs for: " + coordinates );
284
+ invokeCommand (gradlew + " scaffold --coordinates " + coordinates + " --skipTests" , "Cannot generate stubs for: " + coordinates );
291
285
}
292
286
}
293
287
294
- private void updateAllowedPackages (List <String > allowedPackages , boolean isAlreadyExistingLibrary ) throws IOException {
288
+ private void updateAllowedPackages (List <String > allowedPackages , boolean libraryAlreadyExists ) throws IOException {
295
289
InteractiveTaskUtils .printUserInfo ("Updating allowed packages in: " + METADATA_INDEX );
296
290
File metadataIndex = getProject ().file (METADATA_INDEX );
297
291
@@ -307,7 +301,7 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean isAlrea
307
301
Set <String > extendedAllowedPackages = new HashSet <>();
308
302
MetadataIndexEntry replacedEntry = entries .remove (replaceEntryIndex );
309
303
310
- if (isAlreadyExistingLibrary ) {
304
+ if (libraryAlreadyExists ) {
311
305
// we don't want to break existing tests, so we must add existing allowed packages
312
306
extendedAllowedPackages .addAll (replacedEntry .allowedPackages ());
313
307
}
@@ -329,14 +323,6 @@ private void addTests(Path originalTestsLocation){
329
323
Path allTests = originalTestsLocation .resolve ("." );
330
324
331
325
ensureFileBelongsToProject (destination );
332
- InteractiveTaskUtils .printUserInfo ("Removing dummy test stubs" );
333
- boolean shouldDelete = InteractiveTaskUtils .askForDeletePermission (destination );
334
- if (!shouldDelete ) {
335
- throw new RuntimeException ("The task didn't get permission to delete dummy stubs. Cannot proceed with the task execution" );
336
- }
337
-
338
- getFileSystemOperations ().delete (deleteSpec -> deleteSpec .delete (destination ));
339
-
340
326
InteractiveTaskUtils .printUserInfo ("Copying tests from: " + originalTestsLocation + " to " + destination );
341
327
getFileSystemOperations ().copy (copySpec -> {
342
328
copySpec .from (allTests );
@@ -350,6 +336,8 @@ private void addResources(Path originalResourcesDirectory){
350
336
}
351
337
352
338
Path destination = testsDirectory .resolve ("src" ).resolve ("test" ).resolve ("resources" );
339
+ ensureFileBelongsToProject (destination );
340
+
353
341
InteractiveTaskUtils .printUserInfo ("Copying resources from: " + originalResourcesDirectory + " to " + destination );
354
342
getFileSystemOperations ().copy (copySpec -> {
355
343
copySpec .from (originalResourcesDirectory );
@@ -364,6 +352,8 @@ private void addDockerImages(List<String> images) throws IOException {
364
352
365
353
InteractiveTaskUtils .printUserInfo ("Adding following docker images to " + REQUIRED_DOCKER_IMAGES_FILE + ": " + images );
366
354
Path destination = testsDirectory .resolve (REQUIRED_DOCKER_IMAGES_FILE );
355
+ ensureFileBelongsToProject (destination );
356
+
367
357
if (!Files .exists (destination )) {
368
358
Files .createFile (destination );
369
359
}
@@ -428,7 +418,6 @@ private void addAgentConfigBlock() {
428
418
throw new RuntimeException ("Cannot add agent block to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location." );
429
419
}
430
420
431
-
432
421
try (InputStream stream = ContributionTask .class .getResourceAsStream ("/contributing/agent.template" )) {
433
422
if (stream == null ) {
434
423
throw new RuntimeException ("Cannot find template for the graalvm configuration block" );
@@ -449,101 +438,6 @@ private void collectMetadata() {
449
438
invokeCommand (gradlew + " metadataCopy --task test --dir " + metadataDirectory , "Cannot perform metadata copy" , testsDirectory );
450
439
}
451
440
452
- private enum CONFIG_FILES {
453
- RESOURCE ("resource-config.json" ),
454
- REFLECTION ("reflect-config.json" ),
455
- SERIALIZATION ("serialization-config.json" ),
456
- JNI ("jni-config.json" ),
457
- PROXY ("proxy-config.json" ),
458
- PREDEFINED_CLASSES ("predefined-classes-config.json" );
459
-
460
- private final String value ;
461
- public String get () {
462
- return value ;
463
- }
464
-
465
- CONFIG_FILES (String val ) {
466
- this .value = val ;
467
- }
468
- }
469
-
470
- private void removeEmptyConfigFiles () throws IOException {
471
- Path indexFile = metadataDirectory .resolve ("index.json" );
472
- List <CONFIG_FILES > remainingFiles = new LinkedList <>(Arrays .asList (CONFIG_FILES .values ()));
473
-
474
- Path resourceConfigPath = metadataDirectory .resolve (CONFIG_FILES .RESOURCE .get ());
475
- ResourceConfigModel resourceConfig = objectMapper .readValue (resourceConfigPath .toFile (), new TypeReference <>() {});
476
- if (resourceConfig .isEmpty ()) {
477
- removeConfigFile (resourceConfigPath , CONFIG_FILES .RESOURCE , remainingFiles );
478
- }
479
-
480
- Path serializationConfigPath = metadataDirectory .resolve (CONFIG_FILES .SERIALIZATION .get ());
481
- SerializationConfigModel serializationConfig = objectMapper .readValue (serializationConfigPath .toFile (), new TypeReference <>() {});
482
- if (serializationConfig .isEmpty ()) {
483
- removeConfigFile (serializationConfigPath , CONFIG_FILES .SERIALIZATION , remainingFiles );
484
- }
485
-
486
- Path jniConfigPath = metadataDirectory .resolve (CONFIG_FILES .JNI .get ());
487
- List <Object > jniConfig = objectMapper .readValue (jniConfigPath .toFile (), new TypeReference <>() {});
488
- if (jniConfig .isEmpty ()) {
489
- removeConfigFile (jniConfigPath , CONFIG_FILES .JNI , remainingFiles );
490
- }
491
-
492
- Path proxyConfigPath = metadataDirectory .resolve (CONFIG_FILES .PROXY .get ());
493
- List <Object > proxyConfig = objectMapper .readValue (proxyConfigPath .toFile (), new TypeReference <>() {});
494
- if (proxyConfig .isEmpty ()) {
495
- removeConfigFile (proxyConfigPath , CONFIG_FILES .PROXY , remainingFiles );
496
- }
497
-
498
- Path reflectConfigPath = metadataDirectory .resolve (CONFIG_FILES .REFLECTION .get ());
499
- List <Object > reflectConfig = objectMapper .readValue (reflectConfigPath .toFile (), new TypeReference <>() {});
500
- if (reflectConfig .isEmpty ()) {
501
- removeConfigFile (reflectConfigPath , CONFIG_FILES .REFLECTION , remainingFiles );
502
- }
503
-
504
- Path predefinedClassesConfigPath = metadataDirectory .resolve (CONFIG_FILES .PREDEFINED_CLASSES .get ());
505
- List <PredefinedClassesConfigModel > predefinedClassesConfig = objectMapper .readValue (predefinedClassesConfigPath .toFile (), new TypeReference <>() {});
506
- if (predefinedClassesConfig .size () == 1 ) {
507
- if (predefinedClassesConfig .get (0 ).isEmpty ()) {
508
- removeConfigFile (predefinedClassesConfigPath , CONFIG_FILES .PREDEFINED_CLASSES , remainingFiles );
509
- }
510
- }
511
-
512
- Path agentExtractedPredefinedClasses = metadataDirectory .resolve ("agent-extracted-predefined-classes" );
513
- if (Files .exists (agentExtractedPredefinedClasses )) {
514
- File [] extractedPredefinedClasses = agentExtractedPredefinedClasses .toFile ().listFiles ();
515
- if (extractedPredefinedClasses == null || extractedPredefinedClasses .length == 0 ) {
516
- ensureFileBelongsToProject (agentExtractedPredefinedClasses );
517
-
518
- InteractiveTaskUtils .printUserInfo ("Removing empty: agent-extracted-predefined-classes" );
519
- boolean canDelete = InteractiveTaskUtils .askForDeletePermission (agentExtractedPredefinedClasses );
520
- if (canDelete ) {
521
- getFileSystemOperations ().delete (deleteSpec -> deleteSpec .delete (agentExtractedPredefinedClasses ));
522
- }
523
- }
524
- }
525
-
526
- trimIndexFile (indexFile , remainingFiles );
527
- }
528
-
529
- private void removeConfigFile (Path path , CONFIG_FILES file , List <CONFIG_FILES > remainingFiles ) {
530
- ensureFileBelongsToProject (path );
531
-
532
- InteractiveTaskUtils .printUserInfo ("Removing empty: " + file .get ());
533
- boolean canDelete = InteractiveTaskUtils .askForDeletePermission (path );
534
- if (canDelete ) {
535
- getFileSystemOperations ().delete (deleteSpec -> deleteSpec .delete (path ));
536
- remainingFiles .remove (file );
537
- }
538
- }
539
-
540
- private void trimIndexFile (Path index , List <CONFIG_FILES > remainingFiles ) throws IOException {
541
- InteractiveTaskUtils .printUserInfo ("Removing sufficient entries from: " + index );
542
- DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter ();
543
- prettyPrinter .indentArraysWith (DefaultIndenter .SYSTEM_LINEFEED_INSTANCE );
544
- objectMapper .writer (prettyPrinter ).writeValue (index .toFile (), remainingFiles .stream ().map (CONFIG_FILES ::get ).toList ());
545
- }
546
-
547
441
private boolean shouldCreatePullRequest () {
548
442
ContributingQuestion question = questions .get ("shouldCreatePullRequest" );
549
443
return InteractiveTaskUtils .askYesNoQuestion (question .question (), question .help (), true );
0 commit comments