8320249: tools/jpackage/share/AddLauncherTest.java#id1 fails intermittently on Windows in verifyDescription

Reviewed-by: almatvee
This commit is contained in:
Alexey Semenyuk 2023-11-27 21:42:47 +00:00
parent 6871a2ff12
commit 5f7f2c4ea0
8 changed files with 43 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -131,18 +131,26 @@ final class ExecutableRebrander {
I18N.getString("error.lock-resource"), target));
}
final boolean resourceUnlockedSuccess;
try {
action.editResource(resourceLock);
if (extraActions != null) {
for (UpdateResourceAction extraAction: extraActions) {
for (UpdateResourceAction extraAction : extraActions) {
extraAction.editResource(resourceLock);
}
}
} finally {
if (resourceLock != 0) {
unlockResource(resourceLock);
if (resourceLock == 0) {
resourceUnlockedSuccess = true;
} else {
resourceUnlockedSuccess = unlockResource(resourceLock);
}
}
if (!resourceUnlockedSuccess) {
throw new RuntimeException(MessageFormat.format(I18N.getString(
"error.unlock-resource"), target));
}
} finally {
target.toFile().setReadOnly();
}
@ -250,7 +258,7 @@ final class ExecutableRebrander {
private static native long lockResource(String executable);
private static native void unlockResource(long resourceLock);
private static native boolean unlockResource(long resourceLock);
private static native int iconSwap(long resourceLock, String iconTarget);

View File

@ -53,6 +53,7 @@ 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.unlock-resource=Failed to unlock: {0}
error.read-wix-l10n-file=Failed to parse {0} file
error.extract-culture-from-wix-l10n-file=Failed to read value of culture from {0} file

View File

@ -53,6 +53,7 @@ error.version-swap=Versionsinformationen für {0} konnten nicht aktualisiert wer
error.icon-swap=Symbol für {0} konnte nicht aktualisiert werden
error.invalid-envvar=Ungültiger Wert der {0}-Umgebungsvariable
error.lock-resource=Sperren nicht erfolgreich: {0}
error.unlock-resource=Failed to unlock: {0}
error.read-wix-l10n-file=Datei {0} konnte nicht geparst werden
error.extract-culture-from-wix-l10n-file=Kulturwert konnte nicht aus Datei {0} gelesen werden

View File

@ -53,6 +53,7 @@ error.version-swap={0}のバージョン情報の更新に失敗しました
error.icon-swap={0}のアイコンの更新に失敗しました
error.invalid-envvar={0}環境変数の値が無効です
error.lock-resource=ロックに失敗しました: {0}
error.unlock-resource=Failed to unlock: {0}
error.read-wix-l10n-file={0}ファイルの解析に失敗しました
error.extract-culture-from-wix-l10n-file={0}ファイルからのカルチャの値の読取りに失敗しました

View File

@ -53,6 +53,7 @@ error.version-swap=无法更新 {0} 的版本信息
error.icon-swap=无法更新 {0} 的图标
error.invalid-envvar={0} 环境变量的值无效
error.lock-resource=无法锁定:{0}
error.unlock-resource=Failed to unlock: {0}
error.read-wix-l10n-file=无法解析 {0} 文件
error.extract-culture-from-wix-l10n-file=无法从 {0} 文件读取文化值

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,19 +39,26 @@ ResourceEditor::FileLock::FileLock(const std::wstring& binaryPath) {
ownHandle(true);
discard(false);
notifyUnlockFailed();
}
ResourceEditor::FileLock::FileLock(HANDLE h): h(h) {
ownHandle(false);
discard(false);
notifyUnlockFailed();
}
ResourceEditor::FileLock::~FileLock() {
if (theOwnHandle && !EndUpdateResource(h, theDiscard)) {
if (unlockFailed) {
*unlockFailed = true;
}
JP_NO_THROW(JP_THROW(SysError(tstrings::any()
<< "EndUpdateResource(" << h << ") failed.", EndUpdateResource)));
} else if (unlockFailed) {
*unlockFailed = false;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -43,8 +43,14 @@ public:
return h;
}
void discard(bool v = true) {
FileLock& discard(bool v = true) {
theDiscard = v;
return *this;
}
FileLock& notifyUnlockFailed(bool* v = 0) {
unlockFailed = v;
return *this;
}
FileLock& ownHandle(bool v) {
@ -59,6 +65,7 @@ public:
HANDLE h;
bool theOwnHandle;
bool theDiscard;
bool* unlockFailed;
};
public:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -56,16 +56,21 @@ extern "C" {
/*
* Class: jdk_jpackage_internal_ExecutableRebrander
* Method: unlockResource
* Signature: (J;)V
* Signature: (J;)Z
*/
JNIEXPORT void JNICALL
JNIEXPORT jboolean JNICALL
Java_jdk_jpackage_internal_ExecutableRebrander_unlockResource(
JNIEnv *pEnv, jclass c, jlong jResourceLock) {
bool unlockFailed = false;
JP_TRY;
ResourceEditor::FileLock(
reinterpret_cast<HANDLE>(jResourceLock)).ownHandle(true);
reinterpret_cast<HANDLE>(jResourceLock))
.ownHandle(true)
.notifyUnlockFailed(&unlockFailed);
JP_CATCH_ALL;
return unlockFailed ? JNI_FALSE : JNI_TRUE;
}
/*