Skip to content

Commit cef4958

Browse files
committed
Remove empty config files and trim metadata/index.json
1 parent 6c21f7f commit cef4958

File tree

5 files changed

+140
-3
lines changed

5 files changed

+140
-3
lines changed

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/ContributionTask.java

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.fasterxml.jackson.databind.SerializationFeature;
77
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;
810
import org.graalvm.internal.tck.model.contributing.Question;
11+
import org.graalvm.internal.tck.model.contributing.SerializationConfigModel;
912
import org.graalvm.internal.tck.utils.ConfigurationStringBuilder;
1013
import org.graalvm.internal.tck.utils.FilesUtils;
1114
import org.graalvm.internal.tck.utils.InteractiveTaskUtils;
@@ -29,7 +32,6 @@ public abstract class ContributionTask extends DefaultTask {
2932
private static final String BUILD_FILE = "build.gradle";
3033
private static final String USER_CODE_FILTER_FILE = "user-code-filter.json";
3134
private static final String REQUIRED_DOCKER_IMAGES_FILE = "required-docker-images.txt";
32-
3335
@Inject
3436
protected abstract ExecOperations getExecOperations();
3537

@@ -100,11 +102,15 @@ void run() throws IOException {
100102
// run agent in conditional mode
101103
collectMetadata();
102104

105+
// remove empty files
106+
removeEmptyConfigFiles();
107+
103108
// create a PR
104109
boolean shouldCreatePR = shouldCreatePullRequest();
105110
if (shouldCreatePR) {
106111
String branch = "add-support-for-" + coordinates.toString().replace(':', '-');
107-
createPullRequest(branch);
112+
System.out.println("shouldCreatePR = " + shouldCreatePR);
113+
// createPullRequest(branch);
108114

109115
InteractiveTaskUtils.printUserInfo("After your pull requests gets generated, please update the pull request description to mention all places where your pull request" +
110116
"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() {
426432
invokeCommand("gradle metadataCopy --task test --dir " + metadataDirectory, "Cannot perform metadata copy", testsDirectory);
427433
}
428434

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+
429534
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]:";
431536
String helpMessage = "If you want, we can create a pull request for you! " +
432537
"All you have to do is to provide necessary information for the GitHub CLI, and answer few contributingQuestions regarding the pull request description.";
433538

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.graalvm.internal.tck.model.contributing;
2+
3+
import java.util.List;
4+
5+
public record PredefinedClassesConfigModel(
6+
String type,
7+
List<Object> classes
8+
) {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.graalvm.internal.tck.model.contributing;
2+
import java.util.List;
3+
4+
public record ResourceConfigModel(
5+
Object resources,
6+
List<Object> bundles
7+
) {
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.graalvm.internal.tck.model.contributing;
2+
3+
4+
import java.util.List;
5+
6+
public record SerializationConfigModel(
7+
List<Object> types,
8+
List<Object> proxies,
9+
List<Object> lambdaCapturingTypes
10+
) {
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"resources":{},
3+
"bundles":[]
4+
}

0 commit comments

Comments
 (0)