This is an automated email from the ASF dual-hosted git repository.

skygo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-native-installers.git

commit 953b554960f6048d876a05a88826c91f53980f47
Author: Peter Hull <[email protected]>
AuthorDate: Mon Mar 6 15:37:41 2023 +0000

    Search for Java on executable path
---
 src/main/cpp/launcher/windows/src/JavaUtils.c   | 36 ++++++++++++++++++++++++-
 src/main/cpp/launcher/windows/src/StringUtils.c | 15 +++++++++++
 src/main/cpp/launcher/windows/src/StringUtils.h |  1 +
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/main/cpp/launcher/windows/src/JavaUtils.c 
b/src/main/cpp/launcher/windows/src/JavaUtils.c
index e0a8c11..0f01ca4 100644
--- a/src/main/cpp/launcher/windows/src/JavaUtils.c
+++ b/src/main/cpp/launcher/windows/src/JavaUtils.c
@@ -36,6 +36,7 @@ const WCHAR * UNPACK200_EXE_SUFFIX = L"\\bin\\unpack200.exe";
 const WCHAR * JAVA_LIB_SUFFIX = L"\\lib";
 const WCHAR * PACK_GZ_SUFFIX  = L".pack.gz";
 const WCHAR * JAR_PACK_GZ_SUFFIX = L".jar.pack.gz";
+const WCHAR * PATH_ENV = L"PATH";
 
 const DWORD JVM_EXTRACTION_TIMEOUT = 180000;  //180sec
 
@@ -734,6 +735,34 @@ void searchJavaSystemLocations(LauncherProperties * props) 
{
         }        
     }
 }
+static void searchJavaOnPath(LauncherProperties * props) {
+  // Find the correct size first, then allocate
+  DWORD size = GetEnvironmentVariableW(PATH_ENV, NULL, 0);
+  WCHAR * str = newpWCHAR(size);
+  GetEnvironmentVariableW(PATH_ENV, str, size);
+  StringListEntry * list = splitStringToList(NULL, str, L';');
+  StringListEntry * iter = list;
+  while (iter) {
+    // Quickly check for java.exe ...
+    WCHAR * javaExecutable = appendStringW(NULL, iter->string);
+    javaExecutable = appendStringW(javaExecutable, L"\\java.exe");
+    if (fileExists(javaExecutable)) {
+      // ... then check properly with trySetCompatibleJava
+      WCHAR* msg = appendStringW(NULL, L"A potential path is ");
+      msg = appendStringW(msg, iter->string);
+      writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, msg, 1);
+      WCHAR * javaHome = getParentDirectory(iter->string);
+      trySetCompatibleJava(javaHome, props);
+      FREE(javaHome);
+      FREE(msg);
+    }
+    FREE(javaExecutable);
+    iter = iter->next;
+  }
+  freeStringList(&list);
+  FREE(str);
+}
+
 void findSystemJava(LauncherProperties *props) {
     // install bundled JVMs if any
     if(isTerminated(props)) return;
@@ -756,7 +785,12 @@ void findSystemJava(LauncherProperties *props) {
         writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "Search java in 
environment variables", 1);
         searchJavaFromEnvVariables(props);
     }
-    
+
+    if (isTerminated(props)) return;
+    if (props->java == NULL) {
+      writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "Search java in executable 
paths", 1);
+      searchJavaOnPath(props);
+    }
     // search JVM in the registry
     if(isTerminated(props)) return;
     if(props->java==NULL) {        
diff --git a/src/main/cpp/launcher/windows/src/StringUtils.c 
b/src/main/cpp/launcher/windows/src/StringUtils.c
index 08f7f7c..5c501cb 100644
--- a/src/main/cpp/launcher/windows/src/StringUtils.c
+++ b/src/main/cpp/launcher/windows/src/StringUtils.c
@@ -539,6 +539,21 @@ StringListEntry * addStringToList(StringListEntry * top, 
WCHAR * str) {
 }
 
 
+StringListEntry * splitStringToList(StringListEntry * top, WCHAR * strlist, 
WCHAR sep) {
+  if (strlist != NULL) {
+    WCHAR * start = strlist;
+    while (*strlist != 0) {
+      if (*strlist == 0 || *strlist == sep) {
+       top = addStringToList(top, appendStringNW(NULL, 0, start, strlist - 
start));
+       start = ++strlist;
+      } else {
+       ++strlist;
+      }
+    }
+  }
+  return top;
+}
+
 DWORD getLineSeparatorNumber(char *str) {
     DWORD result = 0;
     char *ptr = str;
diff --git a/src/main/cpp/launcher/windows/src/StringUtils.h 
b/src/main/cpp/launcher/windows/src/StringUtils.h
index 9cf775c..ae50d7a 100644
--- a/src/main/cpp/launcher/windows/src/StringUtils.h
+++ b/src/main/cpp/launcher/windows/src/StringUtils.h
@@ -94,6 +94,7 @@ extern const char * MAIN_WINDOW_TITLE;
     
     void freeStringList(StringListEntry **s);
     StringListEntry * addStringToList(StringListEntry * top, WCHAR * str);
+    StringListEntry * splitStringToList(StringListEntry * top, WCHAR * str, 
WCHAR sep);
     DWORD inList(StringListEntry * top, WCHAR * str);
     
     char *toChar(const WCHAR * string);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to