8287971: Throw exception for missing values in .jpackage.xml #9
Conversation
👋 Welcome back almatvee! A progress list of the required criteria for merging this PR into |
@sashamatveev The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
private final boolean signed; | ||
private final boolean appStore; | ||
private final String signedStr; | ||
private final String appStoreStr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the idea of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To store string values, so it can be validated to make sure it is true or false only. I changed it back, since I moved validation to ctor.
warning.foreign-app-image=Warnung: app-image-Verzeichnis ({0}) wurde von jpackage nicht generiert. | ||
warning.invalid-app-image=Warnung: .jpackage.xml kann in app-image-Verzeichnis ({0}) nicht geparst werden | ||
|
||
error.foreign-app-image=Error: app-image dir ({0}) not generated by jpackage. Missing .jpackage.xml. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message will be misleading in case app image was generated by jpackage and adjusted after.
I'd put it as "Missing .jpackage.xml file in app-image dir ({0})."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
public static void createJPackageXMLFile(Path appImageDir, | ||
String mainLauncher, String mainClass) throws IOException { | ||
String version = System.getProperty("java.version"); | ||
String platform = ""; | ||
Path appDir = appImageDir; | ||
if (TKit.isWindows()) { | ||
platform = "windows"; | ||
appDir = Files.createDirectories( | ||
appImageDir.resolve("app")); | ||
} else if (TKit.isLinux()) { | ||
platform = "linux"; | ||
appDir = Files.createDirectories( | ||
appImageDir.resolve("lib").resolve("app")); | ||
} else if (TKit.isOSX()) { | ||
platform = "macOS"; | ||
appDir = Files.createDirectories( | ||
appImageDir.resolve("Contents").resolve("app")); | ||
} | ||
|
||
TKit.createTextFile(appDir.resolve(".jpackage.xml"), List.of( | ||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>", | ||
String.format( | ||
"<jpackage-state platform=\"%s\" version=\"%s\">", | ||
platform, version), | ||
"<app-version>1.0</app-version>", | ||
String.format( | ||
"<main-launcher>%s</main-launcher>", | ||
mainLauncher), | ||
String.format( | ||
"<main-class>%s</main-class>", | ||
mainClass), | ||
"<signed>false</signed>", | ||
"<app-store>false</app-store>", | ||
"</jpackage-state>" | ||
)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This is jpackage specific, so it should belong to JPackageCommand class.
- Please use proper XML API to create XML output.
- Having
<app-version>1.0</app-version>
in .jpackage.xml file will makeAppImageFile.isValid()
returnfalse
andAppImageFile.load()
to throw exception. This seems to be equivalent to not having .jpackage.xml file in app image at all raising a question if this new function is needed at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 and 2 done. I think you mistaken <app-version>1.0</app-version>
with <jpackage-state version=\"%s\"
. We never read and I do put correct value for <jpackage-state version=\"%s\"
. It is required for several tests which uses empty/dummy app images and since we started required .jpackage.xml file we need it for empty app images as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! My bad, sorry for the confusion.
private boolean isValid() { | ||
if (!Objects.equals(getVersion(), creatorVersion)) { | ||
return false; | ||
} | ||
|
||
if (!Objects.equals(getPlatform(), creatorPlatform)) { | ||
return false; | ||
} | ||
|
||
if (launcherName == null || launcherName.length() == 0) { | ||
return false; | ||
} | ||
|
||
if (mainClass == null || mainClass.length() == 0) { | ||
return false; | ||
} | ||
|
||
for (var launcher : addLauncherInfos) { | ||
if ("".equals(launcher.getName())) { | ||
return false; | ||
} | ||
} | ||
|
||
if (!Objects.equals(getVersion(), creatorVersion)) { | ||
if (signedStr == null || | ||
!("true".equals(signedStr) || "false".equals(signedStr))) { | ||
return false; | ||
} | ||
|
||
if (!Objects.equals(getPlatform(), creatorPlatform)) { | ||
if (appStoreStr == null || | ||
!("true".equals(appStoreStr) || "false".equals(appStoreStr))) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to unfold this function in the ctor as we don't allow empty AppImageFile instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to copy/paste xml authoring code from IOUtils. This API is accessible outside of jpackage. Check out https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/test/jdk/tools/jpackage/windows/WinScriptTest.java#L151
8287971: Throw exception for missing values in .jpackage.xml [v3]
|
String appImage = getArgumentValue("--app-image"); | ||
if (appImage == null) { | ||
throw new RuntimeException("Error: --app-image expected"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified to:
Path jpackageXMLFile = AppImageFile.getPathInAppImage(
Optional.ofNullable(getArgumentValue("--app-image")).map(
Path::of).orElseThrow(() -> {
return new RuntimeException(
"Error: --app-image expected");
}));
And you don't need copy/paste code from AppImageFile.getPathInAppImage()
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I also switched to use AppImageFile.getVersion() and AppImageFile.getPlatform().
@sashamatveev This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 21 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 70008da.
Your commit was automatically rebased without conflicts. |
@sashamatveev Pushed as commit 70008da. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk19 pull/9/head:pull/9
$ git checkout pull/9
Update a local copy of the PR:
$ git checkout pull/9
$ git pull https://git.openjdk.org/jdk19 pull/9/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9
View PR using the GUI difftool:
$ git pr show -t 9
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk19/pull/9.diff