Skip to content

Commit 4ea3f77

Browse files
committed
Avoid deleting in contributing task
1 parent 456a163 commit 4ea3f77

File tree

9 files changed

+57
-196
lines changed

9 files changed

+57
-196
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Then, point to the local repository in the configuration of either
2121

2222
## Contribute Metadata
2323

24-
The suggested way to contribute to Reachability metadata repository is by using the `contributing` task.
24+
The suggested way to contribute to Reachability metadata repository is by using the `contribute` task.
2525
Before you start the task, you should have your tests implemented somewhere locally on your machine (please verify that tests are working on Java).
2626

2727
In order to start this task, run (we suggest using `--console=plain` to reduce amount of gradle logging):
@@ -34,7 +34,7 @@ When started, the task will ask you few simple questions (like: where are your t
3434
In case you don't understand the question, just type "help".
3535

3636
After it collects your answers, the task will:
37-
- generate necessary infrastructure
37+
- generate necessary boilerplate code
3838
- copy your tests to the proper location
3939
- generate metadata and store it in the proper location
4040
- ask you if you want to create a pull request, or you want to keep working on it locally

tests/src/index.json

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,28 @@
179179
"versions" : [ "2.16.11" ]
180180
} ]
181181
}, {
182-
"test-project-path" : "io.netty/netty-common/4.1.80.Final",
182+
"test-project-path" : "io.netty/netty-common/4.1.115.Final",
183183
"libraries" : [ {
184184
"name" : "io.netty:netty-common",
185-
"versions" : [ "4.1.80.Final" ]
185+
"versions" : [ "4.1.115.Final" ]
186186
} ]
187187
}, {
188-
"test-project-path" : "io.netty/netty-transport/4.1.80.Final",
188+
"test-project-path" : "io.netty/netty-common/4.1.80.Final",
189189
"libraries" : [ {
190-
"name" : "io.netty:netty-transport",
190+
"name" : "io.netty:netty-common",
191191
"versions" : [ "4.1.80.Final" ]
192192
} ]
193193
}, {
194-
"test-project-path" : "io.netty/netty-common/4.1.115.Final",
194+
"test-project-path" : "io.netty/netty-transport/4.1.115.Final",
195195
"libraries" : [ {
196-
"name" : "io.netty:netty-common",
196+
"name" : "io.netty:netty-transport",
197197
"versions" : [ "4.1.115.Final" ]
198198
} ]
199199
}, {
200-
"test-project-path" : "io.netty/netty-transport/4.1.115.Final",
200+
"test-project-path" : "io.netty/netty-transport/4.1.80.Final",
201201
"libraries" : [ {
202202
"name" : "io.netty:netty-transport",
203-
"versions" : [ "4.1.115.Final" ]
203+
"versions" : [ "4.1.80.Final" ]
204204
} ]
205205
}, {
206206
"test-project-path" : "io.opentelemetry/opentelemetry-exporter-jaeger/1.19.0",
@@ -443,16 +443,16 @@
443443
"versions" : [ "10.15.0" ]
444444
} ]
445445
}, {
446-
"test-project-path": "org.flywaydb/flyway-core/10.20.0",
447-
"libraries": [ {
448-
"name": "org.flywaydb:flyway-core",
449-
"versions": [ "10.20.0" ]
446+
"test-project-path" : "org.flywaydb/flyway-core/10.20.0",
447+
"libraries" : [ {
448+
"name" : "org.flywaydb:flyway-core",
449+
"versions" : [ "10.20.0" ]
450450
} ]
451451
}, {
452-
"test-project-path": "org.flywaydb/flyway-core/10.20.1",
453-
"libraries": [ {
454-
"name": "org.flywaydb:flyway-core",
455-
"versions": [ "10.20.1" ]
452+
"test-project-path" : "org.flywaydb/flyway-core/10.20.1",
453+
"libraries" : [ {
454+
"name" : "org.flywaydb:flyway-core",
455+
"versions" : [ "10.20.1" ]
456456
} ]
457457
}, {
458458
"test-project-path" : "org.flywaydb/flyway-core/9.0.1",
@@ -622,6 +622,12 @@
622622
"name" : "org.mockito:mockito-core",
623623
"versions" : [ "5.0.0" ]
624624
} ]
625+
}, {
626+
"test-project-path" : "org.mockito/mockito-core/5.1.0",
627+
"libraries" : [ {
628+
"name" : "org.mockito:mockito-core",
629+
"versions" : [ "5.1.0" ]
630+
} ]
625631
}, {
626632
"test-project-path" : "org.opengauss/opengauss-jdbc/3.1.0-og",
627633
"libraries" : [ {
@@ -688,4 +694,4 @@
688694
"name" : "samples:docker",
689695
"versions" : [ "image-pull" ]
690696
} ]
691-
} ]
697+
} ]

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

Lines changed: 8 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.fasterxml.jackson.databind.SerializationFeature;
99
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;
1210
import org.graalvm.internal.tck.model.contributing.Question;
13-
import org.graalvm.internal.tck.model.contributing.SerializationConfigModel;
1411
import org.graalvm.internal.tck.utils.ConfigurationStringBuilder;
1512
import org.graalvm.internal.tck.utils.FilesUtils;
1613
import org.graalvm.internal.tck.utils.InteractiveTaskUtils;
@@ -112,9 +109,6 @@ void run() throws IOException {
112109
// run agent in conditional mode
113110
collectMetadata();
114111

115-
// remove empty files
116-
removeEmptyConfigFiles();
117-
118112
// create a PR
119113
boolean shouldCreatePR = shouldCreatePullRequest();
120114
if (shouldCreatePR) {
@@ -285,13 +279,13 @@ private List<Coordinates> getAdditionalDependencies() {
285279
private void createStubs(boolean shouldUpdate){
286280
InteractiveTaskUtils.printUserInfo("Generating stubs for: " + coordinates );
287281
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);
289283
} else {
290-
invokeCommand(gradlew + " scaffold --coordinates " + coordinates, "Cannot generate stubs for: " + coordinates);
284+
invokeCommand(gradlew + " scaffold --coordinates " + coordinates + " --skipTests", "Cannot generate stubs for: " + coordinates);
291285
}
292286
}
293287

294-
private void updateAllowedPackages(List<String> allowedPackages, boolean isAlreadyExistingLibrary) throws IOException {
288+
private void updateAllowedPackages(List<String> allowedPackages, boolean libraryAlreadyExists) throws IOException {
295289
InteractiveTaskUtils.printUserInfo("Updating allowed packages in: " + METADATA_INDEX);
296290
File metadataIndex = getProject().file(METADATA_INDEX);
297291

@@ -307,7 +301,7 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean isAlrea
307301
Set<String> extendedAllowedPackages = new HashSet<>();
308302
MetadataIndexEntry replacedEntry = entries.remove(replaceEntryIndex);
309303

310-
if (isAlreadyExistingLibrary) {
304+
if (libraryAlreadyExists) {
311305
// we don't want to break existing tests, so we must add existing allowed packages
312306
extendedAllowedPackages.addAll(replacedEntry.allowedPackages());
313307
}
@@ -329,14 +323,6 @@ private void addTests(Path originalTestsLocation){
329323
Path allTests = originalTestsLocation.resolve(".");
330324

331325
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-
340326
InteractiveTaskUtils.printUserInfo("Copying tests from: " + originalTestsLocation + " to " + destination);
341327
getFileSystemOperations().copy(copySpec -> {
342328
copySpec.from(allTests);
@@ -350,6 +336,8 @@ private void addResources(Path originalResourcesDirectory){
350336
}
351337

352338
Path destination = testsDirectory.resolve("src").resolve("test").resolve("resources");
339+
ensureFileBelongsToProject(destination);
340+
353341
InteractiveTaskUtils.printUserInfo("Copying resources from: " + originalResourcesDirectory + " to " + destination);
354342
getFileSystemOperations().copy(copySpec -> {
355343
copySpec.from(originalResourcesDirectory);
@@ -364,6 +352,8 @@ private void addDockerImages(List<String> images) throws IOException {
364352

365353
InteractiveTaskUtils.printUserInfo("Adding following docker images to " + REQUIRED_DOCKER_IMAGES_FILE + ": " + images);
366354
Path destination = testsDirectory.resolve(REQUIRED_DOCKER_IMAGES_FILE);
355+
ensureFileBelongsToProject(destination);
356+
367357
if (!Files.exists(destination)) {
368358
Files.createFile(destination);
369359
}
@@ -428,7 +418,6 @@ private void addAgentConfigBlock() {
428418
throw new RuntimeException("Cannot add agent block to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location.");
429419
}
430420

431-
432421
try(InputStream stream = ContributionTask.class.getResourceAsStream("/contributing/agent.template")) {
433422
if (stream == null) {
434423
throw new RuntimeException("Cannot find template for the graalvm configuration block");
@@ -449,101 +438,6 @@ private void collectMetadata() {
449438
invokeCommand(gradlew + " metadataCopy --task test --dir " + metadataDirectory, "Cannot perform metadata copy", testsDirectory);
450439
}
451440

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-
547441
private boolean shouldCreatePullRequest() {
548442
ContributingQuestion question = questions.get("shouldCreatePullRequest");
549443
return InteractiveTaskUtils.askYesNoQuestion(question.question(), question.help(), true);

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ScaffoldTask extends DefaultTask {
3939

4040
private boolean force;
4141
private boolean update;
42+
private boolean skipTests;
4243

4344
public ScaffoldTask() {
4445
}
@@ -64,6 +65,11 @@ void setUpdate(boolean update) {
6465
this.update = update;
6566
}
6667

68+
@Option(option = "skipTests", description = "Skip adding test stubs")
69+
void setSkipTests(boolean skip) {
70+
this.skipTests = skip;
71+
}
72+
6773
@TaskAction
6874
void run() throws IOException {
6975
Coordinates coordinates = Coordinates.parse(this.coordinates);
@@ -196,10 +202,12 @@ private void writeTestScaffold(Path coordinatesTestRoot, Coordinates coordinates
196202
);
197203

198204
// src/test/java/
199-
writeToFile(
200-
coordinatesTestRoot.resolve(CoordinateUtils.replace("src/test/java/$sanitizedGroup$/$sanitizedArtifact$/$capitalizedSanitizedArtifact$Test.java", coordinates)),
201-
CoordinateUtils.replace(loadResource("/scaffold/Test.java.template"), coordinates)
202-
);
205+
if (!skipTests) {
206+
writeToFile(
207+
coordinatesTestRoot.resolve(CoordinateUtils.replace("src/test/java/$sanitizedGroup$/$sanitizedArtifact$/$capitalizedSanitizedArtifact$Test.java", coordinates)),
208+
CoordinateUtils.replace(loadResource("/scaffold/Test.java.template"), coordinates)
209+
);
210+
}
203211
}
204212

205213
private void writeCoordinatesMetadataVersionJsons(Path metadataVersionRoot, Coordinates coordinates) throws IOException {

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/model/contributing/PredefinedClassesConfigModel.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/model/contributing/ResourceConfigModel.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/model/contributing/SerializationConfigModel.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.graalvm.internal.tck.utils;
22

3-
import java.nio.file.Path;
43
import java.util.Scanner;
54
import java.util.function.Function;
65

@@ -53,15 +52,6 @@ public static boolean askYesNoQuestion(String question, String helpMessage, bool
5352
}
5453
}
5554

56-
public static boolean askForDeletePermission(Path file) {
57-
String question = "The contributing task would like to delete following file: " + file +
58-
". If this file is not generated by the task, please report the error on the metadata repository. " +
59-
"Do you confirm that contributing task can delete this file? [y/N]";
60-
String help = "The task should only remove dummy files generated in the previous step. Please verify that the following file can be removed: " + file;
61-
62-
return askYesNoQuestion(question, help, false);
63-
}
64-
6555
public static void closeSection() {
6656
ColoredOutput.println("------------------------------------------------------------------------------------------", ColoredOutput.OUTPUT_COLOR.BLUE);
6757
}

0 commit comments

Comments
 (0)