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 4a96cb9 commit 63de23e
Showing 1 changed file with 34 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,16 @@ 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 = Paths.get(sharedClassesDataDir.getSpec());
Path sharedClassesDataDirPath = sharedClassesDataDir.asJavaFile().toPath();
removeAllContentsAndDeleteDir(sharedClassesDataDirPath);
}
}
}

Expand Down Expand Up @@ -275,4 +290,21 @@ 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());
// Use Files.walk to traverse the directory and delete all files/subdirectories
try (Stream<Path> paths = Files.walk(directory)) {
paths.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.delete(path); // Delete each file or directory
System.out.println("Deleted: " + path);
} catch (IOException e) {
System.out.println("Failed to delete: " + path);
e.printStackTrace();
}
});
}
}

}

0 comments on commit 63de23e

Please sign in to comment.