8132527: jimage tool extract and recreate options are not consistent (no NPE)
Module metadata original name must be reused when recreating a jimage Reviewed-by: jlaskey
This commit is contained in:
parent
64e18f581d
commit
4d4cf68fd9
@ -139,6 +139,7 @@ public final class ImageFileCreator {
|
||||
}
|
||||
|
||||
public static void recreateJimage(Path jimageFile,
|
||||
String jdataName,
|
||||
Set<Archive> archives,
|
||||
Map<String, Set<String>> modulePackages)
|
||||
throws IOException {
|
||||
@ -159,12 +160,7 @@ public final class ImageFileCreator {
|
||||
throw new UnsupportedOperationException("Not supported, no external file "
|
||||
+ "in a jimage file");
|
||||
}, entriesForModule, order);
|
||||
String fileName = jimageFile.getFileName().toString();
|
||||
if (fileName.endsWith(IMAGE_EXT)) {
|
||||
fileName = fileName.substring(0, fileName.length()
|
||||
- BasicImageWriter.IMAGE_EXT.length());
|
||||
}
|
||||
generateJImage(jimageFile, fileName, resources, order);
|
||||
generateJImage(jimageFile, jdataName, resources, order);
|
||||
}
|
||||
|
||||
private void writeImage(String fileName,
|
||||
|
@ -164,17 +164,19 @@ public final class ExtractedImage {
|
||||
private Set<Archive> archives = new HashSet<>();
|
||||
private final PrintWriter log;
|
||||
private final boolean verbose;
|
||||
|
||||
private final String jdataName;
|
||||
ExtractedImage(Path dirPath, PrintWriter log,
|
||||
boolean verbose) throws IOException {
|
||||
if (!Files.isDirectory(dirPath)) {
|
||||
throw new IOException("Not a directory");
|
||||
}
|
||||
List<String> jdataNameHolder = new ArrayList<>();
|
||||
Files.walk(dirPath, 1).forEach((p) -> {
|
||||
try {
|
||||
if (!dirPath.equals(p)) {
|
||||
String name = getPathName(p);
|
||||
if (name.endsWith(ImageModuleData.META_DATA_EXTENSION)) {
|
||||
jdataNameHolder.add(p.getFileName().toString());
|
||||
List<String> lines = Files.readAllLines(p);
|
||||
for (Entry<String, List<String>> entry
|
||||
: ImageModuleDataWriter.toModulePackages(lines).entrySet()) {
|
||||
@ -197,11 +199,22 @@ public final class ExtractedImage {
|
||||
archives = Collections.unmodifiableSet(archives);
|
||||
this.log = log;
|
||||
this.verbose = verbose;
|
||||
if (jdataNameHolder.size() != 1) {
|
||||
throw new IOException("Wrong module information");
|
||||
}
|
||||
// The name of the metadata resource must be reused in the recreated jimage
|
||||
String name = jdataNameHolder.get(0);
|
||||
// Extension will be added when recreating the jimage
|
||||
if (name.endsWith(ImageModuleData.META_DATA_EXTENSION)) {
|
||||
name = name.substring(0, name.length()
|
||||
- ImageModuleData.META_DATA_EXTENSION.length());
|
||||
}
|
||||
jdataName = name;
|
||||
}
|
||||
|
||||
void recreateJImage(Path path) throws IOException {
|
||||
|
||||
ImageFileCreator.recreateJimage(path, archives, modulePackages);
|
||||
ImageFileCreator.recreateJimage(path, jdataName, archives, modulePackages);
|
||||
}
|
||||
|
||||
private static String getPathName(Path path) {
|
||||
|
@ -66,9 +66,10 @@ public class JImageTest {
|
||||
String bootimage = bootimagePath.toAbsolutePath().toString();
|
||||
String extractDir = Paths.get(".", "extract").toAbsolutePath().toString();
|
||||
String recreateImage = Paths.get(".", "recreate.jimage").toAbsolutePath().toString();
|
||||
|
||||
String relativeRecreateImage = Paths.get(".", "recreate2.jimage").toString();
|
||||
jimage("extract", "--dir", extractDir, bootimage);
|
||||
jimage("recreate", "--dir", extractDir, recreateImage);
|
||||
jimage("recreate", "--dir", extractDir, relativeRecreateImage);
|
||||
|
||||
System.out.println("Test successful");
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user