5
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
6
import com .fasterxml .jackson .databind .SerializationFeature ;
7
7
import org .graalvm .internal .tck .model .MetadataIndexEntry ;
8
+ import org .graalvm .internal .tck .model .contributing .PredefinedClassesConfigModel ;
9
+ import org .graalvm .internal .tck .model .contributing .ResourceConfigModel ;
8
10
import org .graalvm .internal .tck .model .contributing .Question ;
11
+ import org .graalvm .internal .tck .model .contributing .SerializationConfigModel ;
9
12
import org .graalvm .internal .tck .utils .ConfigurationStringBuilder ;
10
13
import org .graalvm .internal .tck .utils .FilesUtils ;
11
14
import org .graalvm .internal .tck .utils .InteractiveTaskUtils ;
@@ -29,7 +32,6 @@ public abstract class ContributionTask extends DefaultTask {
29
32
private static final String BUILD_FILE = "build.gradle" ;
30
33
private static final String USER_CODE_FILTER_FILE = "user-code-filter.json" ;
31
34
private static final String REQUIRED_DOCKER_IMAGES_FILE = "required-docker-images.txt" ;
32
-
33
35
@ Inject
34
36
protected abstract ExecOperations getExecOperations ();
35
37
@@ -100,11 +102,15 @@ void run() throws IOException {
100
102
// run agent in conditional mode
101
103
collectMetadata ();
102
104
105
+ // remove empty files
106
+ removeEmptyConfigFiles ();
107
+
103
108
// create a PR
104
109
boolean shouldCreatePR = shouldCreatePullRequest ();
105
110
if (shouldCreatePR ) {
106
111
String branch = "add-support-for-" + coordinates .toString ().replace (':' , '-' );
107
- createPullRequest (branch );
112
+ System .out .println ("shouldCreatePR = " + shouldCreatePR );
113
+ // createPullRequest(branch);
108
114
109
115
InteractiveTaskUtils .printUserInfo ("After your pull requests gets generated, please update the pull request description to mention all places where your pull request" +
110
116
"accesses files, network, docker, or any other external service, and check if all checks in the description are correctly marked" );
@@ -426,8 +432,107 @@ private void collectMetadata() {
426
432
invokeCommand ("gradle metadataCopy --task test --dir " + metadataDirectory , "Cannot perform metadata copy" , testsDirectory );
427
433
}
428
434
435
+ private enum CONFIG_FILES {
436
+ RESOURCE ("resource-config.json" ),
437
+ REFLECTION ("reflect-config.json" ),
438
+ SERIALIZATION ("serialization-config.json" ),
439
+ JNI ("jni-config.json" ),
440
+ PROXY ("proxy-config.json" ),
441
+ PREDEFINED_CLASSES ("predefined-classes-config.json" );
442
+
443
+ private final String value ;
444
+ public String get () {
445
+ return value ;
446
+ }
447
+
448
+ CONFIG_FILES (String val ) {
449
+ this .value = val ;
450
+ }
451
+ }
452
+
453
+ private void removeEmptyConfigFiles () throws IOException {
454
+ Path indexFile = metadataDirectory .resolve ("index.json" );
455
+ List <CONFIG_FILES > remainingFiles = new LinkedList <>(Arrays .asList (CONFIG_FILES .values ()));
456
+
457
+ Path resourceConfigPath = metadataDirectory .resolve (CONFIG_FILES .RESOURCE .get ());
458
+ ResourceConfigModel resourceConfig = objectMapper .readValue (new File (resourceConfigPath .toUri ()), new TypeReference <>() {});
459
+ if (resourceConfig .bundles ().isEmpty () && resourceConfig .resources ().toString ().equalsIgnoreCase ("{}" )) {
460
+ removeConfigFile (resourceConfigPath , CONFIG_FILES .RESOURCE , remainingFiles );
461
+ }
462
+
463
+ Path serializationConfigPath = metadataDirectory .resolve (CONFIG_FILES .SERIALIZATION .get ());
464
+ SerializationConfigModel serializationConfig = objectMapper .readValue (new File (serializationConfigPath .toUri ()), new TypeReference <>() {});
465
+ if (serializationConfig .lambdaCapturingTypes ().isEmpty () && serializationConfig .types ().isEmpty () && serializationConfig .proxies ().isEmpty ()) {
466
+ removeConfigFile (serializationConfigPath , CONFIG_FILES .SERIALIZATION , remainingFiles );
467
+ }
468
+
469
+ Path jniConfigPath = metadataDirectory .resolve (CONFIG_FILES .JNI .get ());
470
+ List <Object > jniConfig = objectMapper .readValue (new File (jniConfigPath .toUri ()), new TypeReference <>() {});
471
+ if (jniConfig .isEmpty ()) {
472
+ removeConfigFile (jniConfigPath , CONFIG_FILES .JNI , remainingFiles );
473
+ }
474
+
475
+ Path proxyConfigPath = metadataDirectory .resolve (CONFIG_FILES .PROXY .get ());
476
+ List <Object > proxyConfig = objectMapper .readValue (new File (proxyConfigPath .toUri ()), new TypeReference <>() {});
477
+ if (proxyConfig .isEmpty ()) {
478
+ removeConfigFile (proxyConfigPath , CONFIG_FILES .PROXY , remainingFiles );
479
+ }
480
+
481
+ Path reflectConfigPath = metadataDirectory .resolve (CONFIG_FILES .REFLECTION .get ());
482
+ List <Object > reflectConfig = objectMapper .readValue (new File (reflectConfigPath .toUri ()), new TypeReference <>() {});
483
+ if (reflectConfig .isEmpty ()) {
484
+ removeConfigFile (reflectConfigPath , CONFIG_FILES .REFLECTION , remainingFiles );
485
+ }
486
+
487
+ Path predefinedClassesConfigPath = metadataDirectory .resolve (CONFIG_FILES .PREDEFINED_CLASSES .get ());
488
+ List <PredefinedClassesConfigModel > predefinedClassesConfig = objectMapper .readValue (new File (predefinedClassesConfigPath .toUri ()), new TypeReference <>() {});
489
+ if (predefinedClassesConfig .size () == 1 ) {
490
+ if (predefinedClassesConfig .get (0 ).type ().equalsIgnoreCase ("agent-extracted" ) && predefinedClassesConfig .get (0 ).classes ().isEmpty ()) {
491
+ removeConfigFile (predefinedClassesConfigPath , CONFIG_FILES .PREDEFINED_CLASSES , remainingFiles );
492
+ }
493
+ }
494
+
495
+ Path agentExtractedPredefinedClasses = metadataDirectory .resolve ("agent-extracted-predefined-classes" );
496
+ if (Files .exists (agentExtractedPredefinedClasses )) {
497
+ File [] extractedPredefinedClasses = new File (agentExtractedPredefinedClasses .toUri ()).listFiles ();
498
+ if (extractedPredefinedClasses == null || extractedPredefinedClasses .length == 0 ) {
499
+ InteractiveTaskUtils .printUserInfo ("Removing empty: agent-extracted-predefined-classes" );
500
+ invokeCommand ("rm -r " + agentExtractedPredefinedClasses , "Cannot delete empty config file: " + agentExtractedPredefinedClasses );
501
+ }
502
+ }
503
+
504
+ trimIndexFile (indexFile , remainingFiles );
505
+ }
506
+
507
+ private void removeConfigFile (Path path , CONFIG_FILES file , List <CONFIG_FILES > remainingFiles ) {
508
+ InteractiveTaskUtils .printUserInfo ("Removing empty: " + file .get ());
509
+ invokeCommand ("rm " + path , "Cannot delete empty config file: " + path );
510
+ remainingFiles .remove (file );
511
+ }
512
+
513
+ private void trimIndexFile (Path index , List <CONFIG_FILES > remainingFiles ) throws IOException {
514
+ InteractiveTaskUtils .printUserInfo ("Removing sufficient entries from: " + index );
515
+ ConfigurationStringBuilder sb = new ConfigurationStringBuilder ();
516
+ sb .openArray ().newLine ();
517
+ sb .indent ();
518
+ for (int i = 0 ; i < remainingFiles .size (); i ++) {
519
+ sb .quote (remainingFiles .get (i ).get ());
520
+
521
+ if (i != remainingFiles .size () - 1 ) {
522
+ sb .concat ();
523
+ }
524
+
525
+ sb .newLine ();
526
+ }
527
+
528
+ sb .unindent ();
529
+ sb .closeArray ();
530
+
531
+ writeToFile (index , sb .toString (), StandardOpenOption .TRUNCATE_EXISTING );
532
+ }
533
+
429
534
private boolean shouldCreatePullRequest () {
430
- String question = "Do you want to create a pull request to the reachability metadata repository [Y/n]: " ;
535
+ String question = "Do you want to create a pull request to the reachability metadata repository [Y/n]:" ;
431
536
String helpMessage = "If you want, we can create a pull request for you! " +
432
537
"All you have to do is to provide necessary information for the GitHub CLI, and answer few contributingQuestions regarding the pull request description." ;
433
538
0 commit comments