8211299: Output of System.out is not printed to CMD on Windows JDK-8200758-branch
authorherrick
Thu, 11 Oct 2018 20:48:26 -0400
branchJDK-8200758-branch
changeset 56957 2f01969ed7cb
parent 56949 b06759b804fc
child 56958 8880b21d458d
8211299: Output of System.out is not printed to CMD on Windows Submitten-by: almatvee Reviewed-by: herrick, kcr
make/lib/Lib-jdk.packager.gmk
src/jdk.packager/share/classes/jdk/packager/internal/Arguments.java
src/jdk.packager/share/classes/jdk/packager/internal/SecondaryLauncherArguments.java
src/jdk.packager/share/classes/jdk/packager/internal/ValidOptions.java
src/jdk.packager/share/classes/jdk/packager/internal/resources/CLIHelp.properties
src/jdk.packager/windows/classes/jdk/packager/internal/builders/windows/WindowsAppImageBuilder.java
src/jdk.packager/windows/classes/jdk/packager/internal/resources/builders/windows/WindowsAppImageBuilder.properties
src/jdk.packager/windows/native/launcher/WinLauncher.cpp
--- a/make/lib/Lib-jdk.packager.gmk	Tue Oct 09 18:33:25 2018 -0400
+++ b/make/lib/Lib-jdk.packager.gmk	Thu Oct 11 20:48:26 2018 -0400
@@ -96,6 +96,31 @@
 
 TARGETS += $(BUILD_PACKAGERAPPLAUNCHEREXE)
 
+# Build console version of launcher
+ifeq ($(OPENJDK_TARGET_OS), windows)
+
+PACKAGERAPPLAUNCHERCEXE_SRC := $(TOPDIR)/src/jdk.packager/$(OPENJDK_TARGET_OS)/native/launcher
+
+# Output executable and debug symbols files in the same directory as .obj files.
+$(eval $(call SetupJdkExecutable, BUILD_PACKAGERAPPLAUNCHERCEXE, \
+    NAME := papplauncherc, \
+    SRC := $(PACKAGERAPPLAUNCHERCEXE_SRC), \
+    OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/papplauncherc, \
+    TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
+    OPTIMIZATION := LOW, \
+    CFLAGS := $(CXXFLAGS_JDKEXE) -DFULL, \
+    CFLAGS_release := -DPRODUCT, \
+    CFLAGS_windows :=  -nologo -EHsc -DLAUNCHERC -D_WINDOWS -DUNICODE -D_UNICODE -DWIN32 -D_LITTLE_ENDIAN -DWIN32_LEAN_AND_MEAN, \
+    LDFLAGS := $(LDFLAGS_JDKEXE) $(LDFLAGS_CXX_JDK) \
+        $(call SET_SHARED_LIBRARY_ORIGIN), \
+    LIBS := $(LIBCXX), \
+    LIBS_windows :=  user32.lib shell32.lib advapi32.lib, \
+    VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
+))
+
+TARGETS += $(BUILD_PACKAGERAPPLAUNCHERCEXE)
+endif
+
 ################################################################################
 
 
@@ -123,3 +148,7 @@
 
 $(call SetupCopyTargetFiles,BUILD_LIBPACKAGER)
 $(call SetupCopyTargetFiles,BUILD_PACKAGERAPPLAUNCHEREXE)
+
+ifeq ($(OPENJDK_TARGET_OS), windows)
+$(call SetupCopyTargetFiles,BUILD_PACKAGERAPPLAUNCHERCEXE)
+endif
--- a/src/jdk.packager/share/classes/jdk/packager/internal/Arguments.java	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/Arguments.java	Thu Oct 11 20:48:26 2018 -0400
@@ -82,7 +82,7 @@
                     p -> Boolean.FALSE,
                     (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
                             true : Boolean.valueOf(s));
-    
+
     public static final BundlerParamInfo<Boolean> CREATE_JRE_INSTALLER =
             new StandardBundlerParam<>(
                     I18N.getString("param.create-jre-installer.name"),
@@ -117,7 +117,7 @@
     private boolean hasAppImage = false;
 
     private String mainJarPath = null;
-    
+
     private static boolean echo = false;
     private static boolean verbose = false;
     private static boolean jreInstaller = false;
@@ -167,7 +167,7 @@
             }
             context().deployParams.setTargetFormat(format);
         }),
-        
+
         CREATE_JRE_INSTALLER(JRE_INSTALLER_MODE, OptionCategories.MODE, () -> {
             setOptionValue(JRE_INSTALLER_MODE, true);
             context().bundleType = Bundler.BundleType.INSTALLER;
@@ -293,7 +293,7 @@
         }),
 
         BUILD_ROOT ("build-root", OptionCategories.PROPERTY),
-        
+
         INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
 
         ECHO_MODE ("echo-mode", OptionCategories.PROPERTY, () -> {
@@ -305,7 +305,7 @@
             setOptionValue("app-image", popArg());
             context().hasAppImage = true;
         }),
-        
+
         PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
 
         MAIN_JAR ("main-jar", "j", OptionCategories.PROPERTY, () -> {
@@ -322,7 +322,7 @@
         ADD_MODULES ("add-modules", OptionCategories.MODULAR),
 
         MODULE_PATH ("module-path", "p", OptionCategories.MODULAR),
-        
+
         LIMIT_MODULES ("limit-modules", OptionCategories.MODULAR),
 
         MAC_SIGN ("mac-sign", "s", OptionCategories.PLATFORM_MAC, () -> {
@@ -330,7 +330,7 @@
         }),
 
         MAC_BUNDLE_NAME ("mac-bundle-name", OptionCategories.PLATFORM_MAC),
-        
+
         MAC_BUNDLE_IDENTIFIER("mac-bundle-identifier",
                     OptionCategories.PLATFORM_MAC),
 
@@ -367,14 +367,18 @@
 
         WIN_DIR_CHOOSER ("win-dir-chooser",
                 OptionCategories.PLATFORM_WIN, () -> {
-            setOptionValue("win-dir-chooser", true); 
+            setOptionValue("win-dir-chooser", true);
         }),
 
         WIN_REGISTRY_NAME ("win-registry-name", OptionCategories.PLATFORM_WIN),
 
         WIN_MSI_UPGRADE_UUID ("win-upgrade-uuid",
                 OptionCategories.PLATFORM_WIN),
-        
+
+        WIN_CONSOLE_HINT ("win-console", OptionCategories.PLATFORM_WIN, () -> {
+            setOptionValue("win-console", true);
+        }),
+
         LINUX_BUNDLE_NAME ("linux-bundle-name",
                 OptionCategories.PLATFORM_LINUX),
 
@@ -505,7 +509,7 @@
         bundleType = Bundler.BundleType.NONE;
 
         allOptions = new ArrayList<>();
-        
+
         secondaryLaunchers = new ArrayList<>();
     }
 
@@ -595,7 +599,7 @@
             if(!ValidOptions.checkIfSupported(mode, option)) {
               System.out.println("WARNING: argument ["
                       + option.getId() + "] is not "
-                      + "supported for current configuration.");  
+                      + "supported for current configuration.");
             }
         }
     }
@@ -610,7 +614,7 @@
         for (jdk.packager.internal.Bundler bundler :
                 Bundlers.createBundlersInstance().getBundlers(
                         bundleType.toString())) {
-            if (hasTargetFormat && deployParams.getTargetFormat() != null && 
+            if (hasTargetFormat && deployParams.getTargetFormat() != null &&
                     !deployParams.getTargetFormat().equalsIgnoreCase(
                     bundler.getID())) {
                 continue;
@@ -743,7 +747,7 @@
         } catch (IOException e) {
             Log.info("Exception: " + e.getMessage());
         }
-        
+
         for (final String name: properties.stringPropertyNames()) {
             map.put(name, properties.getProperty(name));
         }
@@ -817,8 +821,8 @@
         if (mainJarPath == null ||
             input == null ) {
             return null;
-        } 
-            
+        }
+
         JarFile jf;
         try {
             File file = new File(input, mainJarPath);
--- a/src/jdk.packager/share/classes/jdk/packager/internal/SecondaryLauncherArguments.java	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/SecondaryLauncherArguments.java	Thu Oct 11 20:48:26 2018 -0400
@@ -45,9 +45,9 @@
         if (bundleParams != null) {
             return;
         }
-        
+
         allArgs = Arguments.getPropertiesFromFile(filename);
-        
+
         bundleParams = new HashMap<>();
         String mainClass = getOptionValue(CLIOptions.APPCLASS);
         String module = getOptionValue(CLIOptions.MODULE);
@@ -60,27 +60,29 @@
                     module);
         } else if (mainClass != null) {
             putUnlessNull(bundleParams, Arguments.CLIOptions.APPCLASS.getId(),
-                    mainClass); 
+                    mainClass);
         }
-        
+
         putUnlessNull(bundleParams, Arguments.CLIOptions.NAME.getId(),
                 getOptionValue(CLIOptions.NAME));
         putUnlessNull(bundleParams, Arguments.CLIOptions.VERSION.getId(),
                 getOptionValue(CLIOptions.VERSION));
-        
-        // 3 boolean values:
+
+        // 4 boolean values:
         putUnlessNull(bundleParams, Arguments.CLIOptions.WIN_MENU_HINT.getId(),
                 getOptionValue(CLIOptions.WIN_MENU_HINT));
         putUnlessNull(bundleParams,
                 Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(),
                 getOptionValue(CLIOptions.WIN_SHORTCUT_HINT));
+        putUnlessNull(bundleParams, Arguments.CLIOptions.WIN_CONSOLE_HINT.getId(),
+                getOptionValue(CLIOptions.WIN_CONSOLE_HINT));
         putUnlessNull(bundleParams, Arguments.CLIOptions.SINGLETON.getId(),
                 getOptionValue(CLIOptions.SINGLETON));
 
         String value = getOptionValue(CLIOptions.ICON);
         putUnlessNull(bundleParams, Arguments.CLIOptions.ICON.getId(),
                 (value == null) ? null : new File(value));
-        
+
         String argumentStr = getOptionValue(CLIOptions.ARGUMENTS);
         putUnlessNullOrEmpty(bundleParams,
                 CLIOptions.ARGUMENTS.getId(),
--- a/src/jdk.packager/share/classes/jdk/packager/internal/ValidOptions.java	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/ValidOptions.java	Thu Oct 11 20:48:26 2018 -0400
@@ -47,9 +47,9 @@
             return;
         }
 
-        // add options for CREATE_IMAGE   
+        // add options for CREATE_IMAGE
         add(CLIOptions.CREATE_IMAGE, CLIOptions.INPUT);
-        add(CLIOptions.CREATE_IMAGE, CLIOptions.OUTPUT); 
+        add(CLIOptions.CREATE_IMAGE, CLIOptions.OUTPUT);
         add(CLIOptions.CREATE_IMAGE, CLIOptions.APPCLASS);
         add(CLIOptions.CREATE_IMAGE, CLIOptions.SINGLETON);
         add(CLIOptions.CREATE_IMAGE, CLIOptions.NAME);
@@ -86,6 +86,7 @@
             add(CLIOptions.CREATE_IMAGE, CLIOptions.DESCRIPTION);
             add(CLIOptions.CREATE_IMAGE, CLIOptions.VENDOR);
             add(CLIOptions.CREATE_IMAGE, CLIOptions.COPYRIGHT);
+            add(CLIOptions.CREATE_IMAGE, CLIOptions.WIN_CONSOLE_HINT);
         }
 
         // add options for CREATE_INSTALLER
@@ -127,14 +128,15 @@
             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_REGISTRY_NAME);
             add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_MSI_UPGRADE_UUID);
             add(CLIOptions.CREATE_INSTALLER, CLIOptions.CATEGORY);
+            add(CLIOptions.CREATE_INSTALLER, CLIOptions.WIN_CONSOLE_HINT);
         }
 
         // add options for CREATE_JRE_INSTALLER
-        
+
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.INPUT);
-        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.OUTPUT); 
+        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.OUTPUT);
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.NAME);
-        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.VERBOSE);        
+        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.VERBOSE);
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.FILES);
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.STRIP_NATIVE_COMMANDS);
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.LICENSE_FILE);
@@ -144,8 +146,8 @@
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.ECHO_MODE);
         add(CLIOptions.CREATE_JRE_INSTALLER,
                     CLIOptions.PREDEFINED_RUNTIME_IMAGE);
-        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.ADD_MODULES); 
-        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.MODULE_PATH); 
+        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.ADD_MODULES);
+        add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.MODULE_PATH);
         add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.LIMIT_MODULES);
 
         if (Platform.getPlatform() == Platform.MAC) {
@@ -169,12 +171,12 @@
                     CLIOptions.WIN_MSI_UPGRADE_UUID);
             add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.DESCRIPTION);
             add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.VENDOR);
-        }        
+        }
 
         if (Platform.getPlatform() == Platform.LINUX) {
             add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.LINUX_BUNDLE_NAME);
             add(CLIOptions.CREATE_JRE_INSTALLER,
-                    CLIOptions.LINUX_DEB_MAINTAINER); 
+                    CLIOptions.LINUX_DEB_MAINTAINER);
             add(CLIOptions.CREATE_JRE_INSTALLER,
                     CLIOptions.LINUX_PACKAGE_DEPENDENCIES);
             add(CLIOptions.CREATE_JRE_INSTALLER, CLIOptions.DESCRIPTION);
--- a/src/jdk.packager/share/classes/jdk/packager/internal/resources/CLIHelp.properties	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/resources/CLIHelp.properties	Thu Oct 11 20:48:26 2018 -0400
@@ -166,3 +166,6 @@
 \          UUID associated with upgrades for this package.\n\
 \  --win-shortcut\n\
 \          Creates a desktop shortcut for the application.\n\
+\  --win-console\n\
+\          Creates a console launcher for the application. Should be specified for\n\
+\          application which requires console interactions.\n\
--- a/src/jdk.packager/windows/classes/jdk/packager/internal/builders/windows/WindowsAppImageBuilder.java	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/windows/classes/jdk/packager/internal/builders/windows/WindowsAppImageBuilder.java	Thu Oct 11 20:48:26 2018 -0400
@@ -59,6 +59,7 @@
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Pattern;
 import java.util.stream.Stream;
+import jdk.packager.internal.Arguments;
 
 import static jdk.packager.internal.StandardBundlerParam.*;
 import jdk.packager.internal.windows.WindowsDefender;
@@ -133,7 +134,17 @@
             },
             (s, p) -> new File(s));
 
-
+    public static final StandardBundlerParam<Boolean> CONSOLE_HINT =
+            new WindowsBundlerParam<>(
+            I18N.getString("param.console-hint.name"),
+            I18N.getString("param.console-hint.description"),
+            Arguments.CLIOptions.WIN_CONSOLE_HINT.getId(),
+            Boolean.class,
+            params -> false,
+            // valueOf(null) is false,
+            // and we actually do want null in some cases
+            (s, p) -> (s == null
+            || "null".equalsIgnoreCase(s)) ? true : Boolean.valueOf(s));
 
     public WindowsAppImageBuilder(Map<String, Object> config, Path imageOutDir)
             throws IOException {
@@ -214,6 +225,15 @@
         return APP_FS_NAME.fetchFrom(p) + ".exe";
     }
 
+    // Returns launcher resource name for launcher we need to use.
+    public static String getLauncherResourceName(Map<String, ? super Object> p) {
+        if (CONSOLE_HINT.fetchFrom(p)) {
+            return "papplauncherc.exe";
+        }
+
+        return "papplauncher.exe";
+    }
+
     public static String getLauncherCfgName(Map<String, ? super Object> p) {
         return "app/" + APP_FS_NAME.fetchFrom(p) +".cfg";
     }
@@ -273,7 +293,7 @@
             copyMSVCDLLs();
 
             // create the secondary launchers, if any
-            List<Map<String, ? super Object>> entryPoints = 
+            List<Map<String, ? super Object>> entryPoints =
                     StandardBundlerParam.SECONDARY_LAUNCHERS.fetchFrom(params);
             for (Map<String, ? super Object> entryPoint : entryPoints) {
                 Map<String, ? super Object> tmp = new HashMap<>(originalParams);
@@ -310,7 +330,7 @@
                         Files.copy(p, root.resolve((p.toFile().getName())));
                     } catch (IOException e) {
                         ioe.set(e);
-                    } 
+                    }
                 });
         }
 
@@ -411,10 +431,10 @@
         // Copy executable root folder
         Path executableFile = root.resolve(getLauncherName(p));
         try (InputStream is_launcher =
-                getResourceAsStream("papplauncher.exe")) {
+                getResourceAsStream(getLauncherResourceName(p))) {
             writeEntry(is_launcher, executableFile);
         }
-        
+
         File launcher = executableFile.toFile();
         launcher.setWritable(true, true);
 
--- a/src/jdk.packager/windows/classes/jdk/packager/internal/resources/builders/windows/WindowsAppImageBuilder.properties	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/windows/classes/jdk/packager/internal/resources/builders/windows/WindowsAppImageBuilder.properties	Thu Oct 11 20:48:26 2018 -0400
@@ -4,6 +4,9 @@
 param.icon-ico.name=.ico Icon
 param.icon-ico.description=Icon for the application, in ICO format.
 
+param.console-hint.name=Console Hint
+param.console-hint.description=Indicates if the bundler should use console launcher
+
 param.config-root.name=
 param.config-root.description=
 
--- a/src/jdk.packager/windows/native/launcher/WinLauncher.cpp	Tue Oct 09 18:33:25 2018 -0400
+++ b/src/jdk.packager/windows/native/launcher/WinLauncher.cpp	Thu Oct 11 20:48:26 2018 -0400
@@ -48,8 +48,12 @@
     return result;
 }
 
+#ifdef LAUNCHERC
+int main(int argc0, char *argv0[]) {
+#else // LAUNCHERC
 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        LPTSTR lpCmdLine, int nCmdShow) {
+#endif // LAUNCHERC
     int result = 1;
     TCHAR **argv;
     int argc;