Skip to content

Commit

Permalink
8293453: tools/jpackage/share/AddLShortcutTest.java "Failed: Check th…
Browse files Browse the repository at this point in the history
…e number of mismatched pixels [1024] of [1024] is < [0.100000] threshold"

Reviewed-by: almatvee
  • Loading branch information
Alexey Semenyuk committed Dec 6, 2022
1 parent 8af6e8a commit 884b9ad
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void rebrandExecutable(Map<String, ? super Object> params, Path icon,
createSubstituteData(
params), target);
if (icon != null) {
iconSwap(resourceLock, icon.toString());
iconSwapWrapper(resourceLock, icon.toString());
}
});
}
Expand Down Expand Up @@ -208,10 +208,8 @@ private void rebrandProperties(long resourceLock, OverridableResource properties
});
}

if (versionSwap(resourceLock, propList.toArray(String[]::new)) != 0) {
throw new RuntimeException(MessageFormat.format(
I18N.getString("error.version-swap"), target));
}
versionSwapWrapper(resourceLock, propList.toArray(String[]::new),
target.toString());
}

private static void validateValueAndPut(
Expand All @@ -228,6 +226,22 @@ private static void validateValueAndPut(
data.put(key, value);
}

private static void iconSwapWrapper(long resourceLock,
String iconTarget) {
if (iconSwap(resourceLock, iconTarget) != 0) {
throw new RuntimeException(MessageFormat.format(I18N.getString(
"error.icon-swap"), iconTarget));
}
}

private static void versionSwapWrapper(long resourceLock,
String[] executableProperties, String target) {
if (versionSwap(resourceLock, executableProperties) != 0) {
throw new RuntimeException(MessageFormat.format(I18N.getString(
"error.version-swap"), target));
}
}

private List<UpdateResourceAction> extraActions;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ error.msi-product-version-major-out-of-range=Major version must be in the range
error.msi-product-version-build-out-of-range=Build part of version must be in the range [0, 65535]
error.msi-product-version-minor-out-of-range=Minor version must be in the range [0, 255]
error.version-swap=Failed to update version information for {0}
error.icon-swap=Failed to update icon for {0}
error.invalid-envvar=Invalid value of {0} environment variable
error.lock-resource=Failed to lock: {0}
error.read-wix-l10n-file=Failed to parse {0} file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ error.msi-product-version-major-out-of-range=Hauptversion muss im Bereich [0, 25
error.msi-product-version-build-out-of-range=Build-Teil der Version muss im Bereich [0, 65535] liegen
error.msi-product-version-minor-out-of-range=Nebenversion muss im Bereich [0, 255] liegen
error.version-swap=Versionsinformationen f\u00FCr {0} konnten nicht aktualisiert werden
error.icon-swap=Failed to update icon for {0}
error.invalid-envvar=Ung\u00FCltiger Wert der {0}-Umgebungsvariable
error.lock-resource=Sperren nicht erfolgreich: {0}
error.read-wix-l10n-file=Datei {0} konnte nicht geparst werden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ error.msi-product-version-major-out-of-range=\u30E1\u30B8\u30E3\u30FC\u30FB\u30D
error.msi-product-version-build-out-of-range=\u30D0\u30FC\u30B8\u30E7\u30F3\u306E\u30D3\u30EB\u30C9\u90E8\u5206\u306F\u7BC4\u56F2[0, 65535]\u5185\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059
error.msi-product-version-minor-out-of-range=\u30DE\u30A4\u30CA\u30FC\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u7BC4\u56F2[0, 255]\u5185\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059
error.version-swap={0}\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u60C5\u5831\u306E\u66F4\u65B0\u306B\u5931\u6557\u3057\u307E\u3057\u305F
error.icon-swap=Failed to update icon for {0}
error.invalid-envvar={0}\u74B0\u5883\u5909\u6570\u306E\u5024\u304C\u7121\u52B9\u3067\u3059
error.lock-resource=\u30ED\u30C3\u30AF\u306B\u5931\u6557\u3057\u307E\u3057\u305F: {0}
error.read-wix-l10n-file={0}\u30D5\u30A1\u30A4\u30EB\u306E\u89E3\u6790\u306B\u5931\u6557\u3057\u307E\u3057\u305F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ error.msi-product-version-major-out-of-range=\u4E3B\u7248\u672C\u5FC5\u987B\u4F4
error.msi-product-version-build-out-of-range=\u7248\u672C\u7684\u5DE5\u4F5C\u7248\u672C\u90E8\u5206\u5FC5\u987B\u4F4D\u4E8E [0, 65535] \u8303\u56F4\u4E2D
error.msi-product-version-minor-out-of-range=\u6B21\u7248\u672C\u5FC5\u987B\u4F4D\u4E8E [0, 255] \u8303\u56F4\u4E2D
error.version-swap=\u65E0\u6CD5\u66F4\u65B0 {0} \u7684\u7248\u672C\u4FE1\u606F
error.icon-swap=Failed to update icon for {0}
error.invalid-envvar={0} \u73AF\u5883\u53D8\u91CF\u7684\u503C\u65E0\u6548
error.lock-resource=\u65E0\u6CD5\u9501\u5B9A\uFF1A{0}
error.read-wix-l10n-file=\u65E0\u6CD5\u89E3\u6790 {0} \u6587\u4EF6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ private WinIconVerifier() {
"unlockResource", long.class);
unlockResource.setAccessible(true);

iconSwap = executableRebranderClass.getDeclaredMethod("iconSwap",
long.class, String.class);
iconSwap.setAccessible(true);
iconSwapWrapper = executableRebranderClass.getDeclaredMethod(
"iconSwapWrapper", long.class, String.class);
iconSwapWrapper.setAccessible(true);
} catch (ClassNotFoundException | NoSuchMethodException
| SecurityException ex) {
throw Functional.rethrowUnchecked(ex);
Expand All @@ -180,16 +180,30 @@ private WinIconVerifier() {

private Path extractIconFromExecutable(Path outputDir, Path executable,
String label) {
// Run .NET code to extract icon from the given executable.
// ExtractAssociatedIcon() will succeed even if the target file
// is locked (by an antivirus). It will output a default icon
// in case of error. To prevent this "fail safe" behavior we try
// lock the target file with Open() call. If the attempt
// fails ExtractAssociatedIcon() is not called and the script exits
// with the exit code that will be trapped
// inside of Executor.executeAndRepeatUntilExitCode() method that
// will keep running the script until it succeeds or the number of
// allowed attempts is exceeded.

Path extractedIcon = outputDir.resolve(label + ".bmp");
String script = String.join(";",
String.format(
"try { [System.io.File]::Open('%s', 'Open', 'Read', 'None') } catch { exit 100 }",
executable.toAbsolutePath().normalize()),
"[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')",
String.format(
"[System.Drawing.Icon]::ExtractAssociatedIcon('%s').ToBitmap().Save('%s', [System.Drawing.Imaging.ImageFormat]::Bmp)",
executable.toAbsolutePath().normalize(),
extractedIcon.toAbsolutePath().normalize()));

Executor.of("powershell", "-NoLogo", "-NoProfile", "-Command",
script).execute();
script).executeAndRepeatUntilExitCode(0, 5, 10);

return extractedIcon;
}
Expand Down Expand Up @@ -230,7 +244,7 @@ private void setIcon(Path iconPath, Path launcherPath) {
"Failed to lock [%s] executable",
launcherPath));
}
iconSwap.invoke(null, new Object[]{lock,
iconSwapWrapper.invoke(null, new Object[]{lock,
iconPath.toAbsolutePath().normalize().toString()});
} finally {
if (lock != 0) {
Expand All @@ -250,7 +264,7 @@ private void setIcon(Path iconPath, Path launcherPath) {
private final Class executableRebranderClass;
private final Method lockResource;
private final Method unlockResource;
private final Method iconSwap;
private final Method iconSwapWrapper;
}

private String launcherName;
Expand Down

1 comment on commit 884b9ad

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.