8218681: Windows exe's generated by jpackage have wrong info
Submitten-by: almatvee
Reviewed-by: herrick
--- a/src/jdk.jpackage/share/native/libapplauncher/Platform.h Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/share/native/libapplauncher/Platform.h Tue Feb 26 12:08:20 2019 -0500
@@ -243,12 +243,6 @@
static WideString MultibyteStringToWideString(const char* value);
static MultibyteString WideStringToMultibyteString(const wchar_t* value);
-
-#ifdef DEBUG
- virtual DebugState GetDebugState() = 0;
- virtual int GetProcessID() = 0;
- virtual bool IsNativeDebuggerPresent() = 0;
-#endif //DEBUG
};
class Exception: public std::exception {
--- a/src/jdk.jpackage/share/native/libapplauncher/main.cpp Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/share/native/libapplauncher/main.cpp Tue Feb 26 12:08:20 2019 -0500
@@ -81,19 +81,6 @@
else if (argument == _T("-Xapp:child")) {
parentProcess = false;
}
-#ifdef DEBUG
- // There is a compiler bug on Mac when overloading
- // ShowResponseMessage.
- else if (argument == _T("-nativedebug")) {
- if (platform.ShowResponseMessage(_T("Test"),
- TString(_T("Would you like to debug?\n\nProcessID: "))
- + PlatformString(platform.GetProcessID()).toString())
- == mrOK) {
- while (platform.IsNativeDebuggerPresent() == false) {
- }
- }
- }
-#endif //DEBUG
}
// Package must be initialized after Platform is fully initialized.
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java Tue Feb 26 12:08:20 2019 -0500
@@ -329,29 +329,25 @@
Map<String, String> data = new HashMap<>();
// mapping Java parameters in strings for version resource
- data.put("COMMENTS", "");
validateValueAndPut(data, "COMPANY_NAME", VENDOR, params);
validateValueAndPut(data, "FILE_DESCRIPTION", DESCRIPTION, params);
validateValueAndPut(data, "FILE_VERSION", VERSION, params);
data.put("INTERNAL_NAME", getLauncherName(params));
validateValueAndPut(data, "LEGAL_COPYRIGHT", COPYRIGHT, params);
- data.put("LEGAL_TRADEMARK", "");
data.put("ORIGINAL_FILENAME", getLauncherName(params));
- data.put("PRIVATE_BUILD", "");
validateValueAndPut(data, "PRODUCT_NAME", APP_NAME, params);
validateValueAndPut(data, "PRODUCT_VERSION", VERSION, params);
- data.put("SPECIAL_BUILD", "");
- Writer w = new BufferedWriter(
- new FileWriter(getConfig_ExecutableProperties(params)));
- String content = preprocessTextResource(
- getConfig_ExecutableProperties(params).getName(),
- I18N.getString("resource.executable-properties-template"),
- EXECUTABLE_PROPERTIES_TEMPLATE, data,
- VERBOSE.fetchFrom(params),
- RESOURCE_DIR.fetchFrom(params));
- w.write(content);
- w.close();
+ try (Writer w = new BufferedWriter(
+ new FileWriter(getConfig_ExecutableProperties(params)))) {
+ String content = preprocessTextResource(
+ getConfig_ExecutableProperties(params).getName(),
+ I18N.getString("resource.executable-properties-template"),
+ EXECUTABLE_PROPERTIES_TEMPLATE, data,
+ VERBOSE.fetchFrom(params),
+ RESOURCE_DIR.fetchFrom(params));
+ w.write(content);
+ }
}
private void createLauncherForEntryPoint(
@@ -412,8 +408,12 @@
File executableProperties = getConfig_ExecutableProperties(p);
if (executableProperties.exists()) {
- versionSwap(executableProperties.getAbsolutePath(),
- launcher.getAbsolutePath());
+ if (versionSwap(executableProperties.getAbsolutePath(),
+ launcher.getAbsolutePath()) != 0) {
+ throw new RuntimeException(MessageFormat.format(
+ I18N.getString("error.version-swap"),
+ executableProperties.getAbsolutePath()));
+ }
}
} finally {
executableFile.toFile().setReadOnly();
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinLauncher.template Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinLauncher.template Tue Feb 26 12:08:20 2019 -0500
@@ -24,15 +24,11 @@
#
#
-Comments=COMMENTS
-CompanyName=COMPANY_NAME
+CompanyName=COMPANY_NAME
FileDescription=FILE_DESCRIPTION
FileVersion=FILE_VERSION
InternalName=INTERNAL_NAME
LegalCopyright=LEGAL_COPYRIGHT
-LegalTrademarks=LEGAL_TRADEMARK
OriginalFilename=ORIGINAL_FILENAME
-PrivateBuild=PRIVATE_BUILD
ProductName=PRODUCT_NAME
ProductVersion=PRODUCT_VERSION
-SpecialBuild=SPECIAL_BUILD
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties Tue Feb 26 12:08:20 2019 -0500
@@ -104,6 +104,7 @@
error.version-string-minor-out-of-range=Minor version must be in the range [0, 255]
error.version-string-part-not-number=Failed to convert version component to int.
error.cannot-walk-directory=Can not walk [{0}] - it is not a valid directory
+error.version-swap=Failed to update version information for {0}.
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_ja.properties Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_ja.properties Tue Feb 26 12:08:20 2019 -0500
@@ -104,6 +104,7 @@
error.version-string-minor-out-of-range=Minor version must be in the range [0, 255]
error.version-string-part-not-number=Failed to convert version component to int.
error.cannot-walk-directory=Can not walk [{0}] - it is not a valid directory
+error.version-swap=Failed to update version information for {0}.
--- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_zh_CN.properties Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_zh_CN.properties Tue Feb 26 12:08:20 2019 -0500
@@ -104,6 +104,7 @@
error.version-string-minor-out-of-range=Minor version must be in the range [0, 255]
error.version-string-part-not-number=Failed to convert version component to int.
error.cannot-walk-directory=Can not walk [{0}] - it is not a valid directory
+error.version-swap=Failed to update version information for {0}.
--- a/src/jdk.jpackage/windows/native/libapplauncher/WindowsPlatform.cpp Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/native/libapplauncher/WindowsPlatform.cpp Tue Feb 26 12:08:20 2019 -0500
@@ -421,23 +421,6 @@
return result;
}
-#ifdef DEBUG
-bool WindowsPlatform::IsNativeDebuggerPresent() {
- bool result = false;
-
- if (IsDebuggerPresent() == TRUE) {
- result = true;
- }
-
- return result;
-}
-
-int WindowsPlatform::GetProcessID() {
- int pid = GetProcessId(GetCurrentProcess());
- return pid;
-}
-#endif //DEBUG
-
FileHandle::FileHandle(std::wstring FileName) {
FHandle = ::CreateFile(FileName.data(), GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
--- a/src/jdk.jpackage/windows/native/libjpackage/VersionInfoSwap.cpp Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/native/libjpackage/VersionInfoSwap.cpp Tue Feb 26 12:08:20 2019 -0500
@@ -64,16 +64,20 @@
}
ByteBuffer buf;
- CreateNewResource(&buf);
+ b = CreateNewResource(&buf);
+ if (!b) {
+ return false;
+ }
+
b = this->UpdateResource(buf.getPtr(), static_cast<DWORD> (buf.getPos()));
if (!b) {
return false;
}
+
return true;
}
bool VersionInfoSwap::LoadFromPropertyFile() {
- bool result = false;
wifstream stream(m_executableProperties.c_str());
const locale empty_locale = locale::empty();
@@ -94,18 +98,14 @@
wstring name = line.substr(0, pos);
wstring value = line.substr(pos + 1);
m_props[name] = value;
- } else {
- printf("Unable to find delimiter at line %d\n", lineNumber);
}
}
lineNumber++;
}
- result = true;
- } else {
- printf("Unable to read property file\n");
+ return true;
}
- return result;
+ return false;
}
/*
@@ -114,7 +114,7 @@
* MSND docs for VS_VERSION_INFO structure
* https://msdn.microsoft.com/en-us/library/ms647001(v=vs.85).aspx
*/
-void VersionInfoSwap::CreateNewResource(ByteBuffer *buf) {
+bool VersionInfoSwap::CreateNewResource(ByteBuffer *buf) {
size_t versionInfoStart = buf->getPos();
buf->AppendWORD(0);
buf->AppendWORD(sizeof VS_FIXEDFILEINFO);
@@ -123,7 +123,9 @@
buf->Align(4);
VS_FIXEDFILEINFO fxi;
- FillFixedFileInfo(&fxi);
+ if (!FillFixedFileInfo(&fxi)) {
+ return false;
+ }
buf->AppendBytes((BYTE*) & fxi, sizeof (VS_FIXEDFILEINFO));
buf->Align(4);
@@ -186,17 +188,19 @@
buf->AppendWORD(0x00);
buf->AppendString(TEXT("Translation"));
buf->Align(4);
- // "040904B0" = LANG_ENGLISH/SUBLANG_ENGLISH_US, Unicode CP
- buf->AppendWORD(0x0409);
+ // "000004B0" = LANG_NEUTRAL/SUBLANG_ENGLISH_US, Unicode CP
+ buf->AppendWORD(0x0000);
buf->AppendWORD(0x04B0);
buf->ReplaceWORD(varFileInfoStart,
static_cast<WORD> (buf->getPos() - varFileInfoStart));
buf->ReplaceWORD(versionInfoStart,
static_cast<WORD> (buf->getPos() - versionInfoStart));
+
+ return true;
}
-void VersionInfoSwap::FillFixedFileInfo(VS_FIXEDFILEINFO *fxi) {
+bool VersionInfoSwap::FillFixedFileInfo(VS_FIXEDFILEINFO *fxi) {
wstring fileVersion;
wstring productVersion;
int ret;
@@ -210,13 +214,13 @@
ret = _stscanf_s(fileVersion.c_str(),
TEXT("%d.%d.%d.%d"), &fv_1, &fv_2, &fv_3, &fv_4);
if (ret <= 0 || ret > 4) {
- printf("Unable to parse FileVersion value\n");
+ return false;
}
ret = _stscanf_s(productVersion.c_str(),
TEXT("%d.%d.%d.%d"), &pv_1, &pv_2, &pv_3, &pv_4);
if (ret <= 0 || ret > 4) {
- printf("Unable to parse ProductVersion value\n");
+ return false;
}
fxi->dwSignature = 0xFEEF04BD;
@@ -229,12 +233,6 @@
fxi->dwFileFlagsMask = 0;
fxi->dwFileFlags = 0;
- if (m_props.count(TEXT("PrivateBuild"))) {
- fxi->dwFileFlags |= VS_FF_PRIVATEBUILD;
- }
- if (m_props.count(TEXT("SpecialBuild"))) {
- fxi->dwFileFlags |= VS_FF_SPECIALBUILD;
- }
fxi->dwFileOS = VOS_NT_WINDOWS32;
wstring exeExt =
@@ -250,6 +248,8 @@
fxi->dwFileDateLS = 0;
fxi->dwFileDateMS = 0;
+
+ return true;
}
/*
@@ -262,24 +262,21 @@
hUpdateRes = ::BeginUpdateResource(m_launcher.c_str(), FALSE);
if (hUpdateRes == NULL) {
- printf("Could not open file for writing\n");
return false;
}
r = ::UpdateResource(hUpdateRes,
RT_VERSION,
MAKEINTRESOURCE(VS_VERSION_INFO),
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
lpResLock,
size);
if (!r) {
- printf("Could not add resource\n");
return false;
}
if (!::EndUpdateResource(hUpdateRes, FALSE)) {
- printf("Could not write changes to file\n");
return false;
}
--- a/src/jdk.jpackage/windows/native/libjpackage/VersionInfoSwap.h Tue Feb 26 12:03:51 2019 -0500
+++ b/src/jdk.jpackage/windows/native/libjpackage/VersionInfoSwap.h Tue Feb 26 12:08:20 2019 -0500
@@ -44,9 +44,9 @@
map<wstring, wstring> m_props;
bool LoadFromPropertyFile();
- void CreateNewResource(ByteBuffer *buf);
+ bool CreateNewResource(ByteBuffer *buf);
bool UpdateResource(LPVOID lpResLock, DWORD size);
- void FillFixedFileInfo(VS_FIXEDFILEINFO *fxi);
+ bool FillFixedFileInfo(VS_FIXEDFILEINFO *fxi);
};
#endif // VERSIONINFOSWAP_H
\ No newline at end of file