Skip to content
Permalink
Browse files
8255899: Allow uninstallation of jpackage exe bundles
Reviewed-by: almatvee, herrick
  • Loading branch information
Alexey Semenyuk committed Dec 15, 2020
1 parent 65756ab commit d53ee6219bf9a196eb174a98ba98b0c6364f2233
Showing with 2,083 additions and 290 deletions.
  1. +2 −1 src/jdk.jpackage/linux/native/applauncher/LinuxLauncher.cpp
  2. +3 −2 src/jdk.jpackage/macosx/native/applauncher/MacLauncher.cpp
  3. +0 −155 src/jdk.jpackage/share/native/applauncher/AppLauncher.cpp
  4. +0 −12 src/jdk.jpackage/share/native/applauncher/AppLauncher.h
  5. +186 −0 src/jdk.jpackage/share/native/common/app.cpp
  6. +49 −0 src/jdk.jpackage/share/native/common/app.h
  7. +31 −0 src/jdk.jpackage/share/native/common/tstrings.cpp
  8. +14 −0 src/jdk.jpackage/share/native/common/tstrings.h
  9. +3 −102 src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp
  10. +50 −0 src/jdk.jpackage/windows/native/common/Flag.h
  11. +137 −0 src/jdk.jpackage/windows/native/common/Guid.cpp
  12. +75 −0 src/jdk.jpackage/windows/native/common/Guid.h
  13. +282 −0 src/jdk.jpackage/windows/native/common/MsiDb.cpp
  14. +194 −0 src/jdk.jpackage/windows/native/common/MsiDb.h
  15. +420 −0 src/jdk.jpackage/windows/native/common/MsiUtils.cpp
  16. +337 −0 src/jdk.jpackage/windows/native/common/MsiUtils.h
  17. +18 −0 src/jdk.jpackage/windows/native/{msiwrapper → common}/Resources.cpp
  18. +51 −0 src/jdk.jpackage/windows/native/{msiwrapper → common}/Resources.h
  19. +139 −0 src/jdk.jpackage/windows/native/common/WinApp.cpp
  20. +38 −0 src/jdk.jpackage/windows/native/common/WinApp.h
  21. +1 −0 src/jdk.jpackage/windows/native/libjpackage/JniUtils.h
  22. +2 −2 src/jdk.jpackage/windows/native/libjpackage/ResourceEditor.h
  23. +4 −2 src/jdk.jpackage/windows/native/libjpackage/VersionInfo.cpp
  24. +9 −0 src/jdk.jpackage/windows/native/libjpackage/jpackage.cpp
  25. +27 −7 src/jdk.jpackage/windows/native/msiwrapper/MsiWrapper.cpp
  26. +11 −7 test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java
@@ -30,6 +30,7 @@
#include "UnixSysInfo.h"
#include "Package.h"
#include "Log.h"
#include "app.h"
#include "ErrorHandling.h"


@@ -124,5 +125,5 @@ void launchApp() {
int main(int argc, char *argv[]) {
SysInfo::argc = argc;
SysInfo::argv = argv;
return AppLauncher::launch(std::nothrow, launchApp);
return app::launch(std::nothrow, launchApp);
}
@@ -24,6 +24,7 @@
*/

#include "AppLauncher.h"
#include "app.h"
#include "FileUtils.h"
#include "UnixSysInfo.h"
#include "JvmLauncher.h"
@@ -74,10 +75,10 @@ int main(int argc, char *argv[]) {
// Besides we should ignore main() arguments because these are the
// arguments passed into JLI_Launch() call and not the arguments with
// which the launcher was started.
return AppLauncher::launch(std::nothrow, launchJvm);
return app::launch(std::nothrow, launchJvm);
}

SysInfo::argc = argc;
SysInfo::argv = argv;
return AppLauncher::launch(std::nothrow, initJvmLauncher);
return app::launch(std::nothrow, initJvmLauncher);
}
@@ -136,158 +136,3 @@ Jvm* AppLauncher::createJvmLauncher() const {
void AppLauncher::launch() const {
std::unique_ptr<Jvm>(createJvmLauncher())->launch();
}


namespace {
const std::string* theLastErrorMsg = 0;

NopLogAppender nopLogAppender;

class StandardLogAppender : public LogAppender {
public:
virtual void append(const LogEvent& v) {
std::cerr << "[" << v.logLevel << "] "
<< v.fileName
<< ":" << v.lineNum
<< ": " << v.message
<< std::endl;
}
} standardLogAppender;

class LastErrorLogAppender : public LogAppender {
public:
virtual void append(const LogEvent& v) {
std::cerr << AppLauncher::lastErrorMsg() << std::endl;
}
} lastErrorLogAppender;
} // namespace

LogAppender& AppLauncher::defaultLastErrorLogAppender() {
return lastErrorLogAppender;
}


std::string AppLauncher::lastErrorMsg() {
if (theLastErrorMsg) {
return *theLastErrorMsg;
}
return "";
}


bool AppLauncher::isWithLogging() {
// If JPACKAGE_DEBUG environment variable is set to "true"
// logging is enabled.
return SysInfo::getEnvVariable(
std::nothrow, _T("JPACKAGE_DEBUG")) == _T("true");
}


namespace {

class ResetLastErrorMsgAtEndOfScope {
public:
~ResetLastErrorMsgAtEndOfScope() {
JP_NO_THROW(theLastErrorMsg = 0);
}
};

class SetLoggerAtEndOfScope {
public:
SetLoggerAtEndOfScope(
std::unique_ptr<WithExtraLogAppender>& withLogAppender,
LogAppender* lastErrorLogAppender):
withLogAppender(withLogAppender),
lastErrorLogAppender(lastErrorLogAppender) {
}

~SetLoggerAtEndOfScope() {
JP_TRY;
std::unique_ptr<WithExtraLogAppender> other(
new WithExtraLogAppender(*lastErrorLogAppender));
withLogAppender.swap(other);
JP_CATCH_ALL;
}

private:
std::unique_ptr<WithExtraLogAppender>& withLogAppender;
LogAppender* lastErrorLogAppender;
};

} // namespace

int AppLauncher::launch(const std::nothrow_t&,
LauncherFunc func, LogAppender* lastErrorLogAppender) {
if (isWithLogging()) {
Logger::defaultLogger().setAppender(standardLogAppender);
} else {
Logger::defaultLogger().setAppender(nopLogAppender);
}

LOG_TRACE_FUNCTION();

if (!lastErrorLogAppender) {
lastErrorLogAppender = &defaultLastErrorLogAppender();
}
std::unique_ptr<WithExtraLogAppender> withLogAppender;
std::string errorMsg;
const ResetLastErrorMsgAtEndOfScope resetLastErrorMsg;

JP_TRY;

// This will temporary change log appenders of the default logger
// to save log messages in the default and additional log appenders.
// Log appenders config of the default logger will be restored to
// the original state at function exit automatically.
const SetLoggerAtEndOfScope setLogger(withLogAppender, lastErrorLogAppender);
func();
return 0;

// The point of all these redefines is to save the last raw error message in
// 'AppLauncher::theLastErrorMsg' variable.
// By default error messages are saved in exception instances with the details
// of error origin (source file, function name, line number).
// We don't want these details in user error messages. However we still want to
// save full information about the last error in the default log appender.
#undef JP_HANDLE_ERROR
#undef JP_HANDLE_UNKNOWN_ERROR
#undef JP_CATCH_EXCEPTIONS
#define JP_HANDLE_ERROR(e) \
do { \
errorMsg = (tstrings::any() << e.what()).str(); \
theLastErrorMsg = &errorMsg; \
reportError(JP_SOURCE_CODE_POS, e); \
} while(0)
#define JP_HANDLE_UNKNOWN_ERROR \
do { \
errorMsg = "Unknown error"; \
theLastErrorMsg = &errorMsg; \
reportUnknownError(JP_SOURCE_CODE_POS); \
} while(0)
#define JP_CATCH_EXCEPTIONS \
catch (const JpErrorBase& e) { \
errorMsg = (tstrings::any() << e.rawMessage()).str(); \
theLastErrorMsg = &errorMsg; \
try { \
throw; \
} catch (const std::runtime_error& e) { \
reportError(JP_SOURCE_CODE_POS, e); \
} \
} catch (const std::runtime_error& e) { \
errorMsg = lastCRTError(); \
theLastErrorMsg = &errorMsg; \
reportError(JP_SOURCE_CODE_POS, e); \
} \
JP_CATCH_UNKNOWN_EXCEPTION

JP_CATCH_ALL;

#undef JP_HANDLE_ERROR
#undef JP_HANDLE_UNKNOWN_ERROR
#undef JP_CATCH_EXCEPTIONS
#define JP_HANDLE_ERROR(e) JP_REPORT_ERROR(e)
#define JP_HANDLE_UNKNOWN_ERROR JP_REPORT_UNKNOWN_ERROR
#define JP_CATCH_EXCEPTIONS JP_DEFAULT_CATCH_EXCEPTIONS

return 1;
}
@@ -30,7 +30,6 @@
#include "tstrings.h"

class Jvm;
class LogAppender;

class AppLauncher {
public:
@@ -65,17 +64,6 @@ class AppLauncher {

void launch() const;

static LogAppender& defaultLastErrorLogAppender();

static bool isWithLogging();

typedef void (*LauncherFunc) ();

static int launch(const std::nothrow_t&, LauncherFunc func,
LogAppender* lastErrorLogAppender = 0);

static std::string lastErrorMsg();

private:
tstring_array args;
tstring launcherPath;

1 comment on commit d53ee62

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on d53ee62 Dec 15, 2020

Please sign in to comment.