Skip to content

Commit

Permalink
Handle missing classes.jar in sharedClassesTestData
Browse files Browse the repository at this point in the history
- ensure the presence of classes.jar , if doesnt exist regenerate it.

related: eclipse-openj9/openj9#19582

Signed-off-by: Anna Babu Palathingal <[email protected]>
  • Loading branch information
annaibm committed Dec 2, 2024
1 parent 748831f commit 4e67f6c
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@

import static net.adoptopenjdk.stf.extensions.core.StfCoreExtension.Echo.ECHO_ON;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.stream.Stream;

import net.adoptopenjdk.stf.environment.DirectoryRef;
import net.adoptopenjdk.stf.environment.FileRef;
Expand Down Expand Up @@ -196,8 +203,15 @@ public void setUp(StfCoreExtension test, StfSharedClassesExtension sharedClasses
System.out.println(sharedClassesDataDir.getSpec() + " does not exist");
}
else {
System.out.println(sharedClassesDataDir.getSpec() + " exists");
found = 1;
FileRef sharedClassesJar = sharedClassesDataDir.childFile("classes.jar");
if (sharedClassesJar.exists()) {
System.out.println(sharedClassesDataDir.getSpec() + " exists and contains classes.jar");
found = 1;
} else {
System.out.println(sharedClassesDataDir.getSpec() + " exists but classes.jar does not exist");
Path sharedClassesDataDirPath = sharedClassesDataDir.asJavaFile().toPath();
removeAllContentsAndDeleteDir(sharedClassesDataDirPath);
}
}
}

Expand Down Expand Up @@ -275,4 +289,20 @@ public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClas
sharedClasses.doDestroySpecificCache("Destroy cache", "-Xshareclasses:name=" + SCSoftmxTestUtil.CACHE_NAME + ",cacheDir=" + cacheDir + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", "-Xshareclasses:name=" + SCSoftmxTestUtil.CACHE_NAME + ",cacheDir=" + cacheDir + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}
public void removeAllContentsAndDeleteDir(Path directory) throws IOException {
System.out.println("Attempting to delete directory and its contents: " + directory.toAbsolutePath());
try (Stream<Path> paths = Files.walk(directory)) {
paths.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.delete(path);
System.out.println("Deleted: " + path);
} catch (IOException e) {
System.out.println("Failed to delete: " + path);
e.printStackTrace();
}
});
}
}

}

0 comments on commit 4e67f6c

Please sign in to comment.