Skip to content

Commit

Permalink
8320249: tools/jpackage/share/AddLauncherTest.java#id1 fails intermit…
Browse files Browse the repository at this point in the history
…tently on Windows in verifyDescription

Reviewed-by: almatvee
  • Loading branch information
Alexey Semenyuk committed Nov 27, 2023
1 parent 6871a2f commit 5f7f2c4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -131,18 +131,26 @@ private void rebrandExecutable(Map<String, ? super Object> params,
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();
}
Expand Down Expand Up @@ -250,7 +258,7 @@ private static void versionSwapWrapper(long resourceLock,

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}ファイルからのカルチャの値の読取りに失敗しました

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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} 文件读取文化值

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/jdk.jpackage/windows/native/libjpackage/ResourceEditor.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,8 +43,14 @@ class ResourceEditor {
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) {
Expand All @@ -59,6 +65,7 @@ class ResourceEditor {
HANDLE h;
bool theOwnHandle;
bool theDiscard;
bool* unlockFailed;
};

public:
Expand Down
13 changes: 9 additions & 4 deletions src/jdk.jpackage/windows/native/libjpackage/jpackage.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}

/*
Expand Down

1 comment on commit 5f7f2c4

@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.