changeset 55357:360c0955b06b

8219914: Change the environment variable for Java Access Bridge logging to have a directory. Reviewed-by: prr
author kaddepalli
date Thu, 25 Apr 2019 15:19:09 +0530
parents bbc7c176c168
children 1372fbbde8dd
files src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp src/jdk.accessibility/windows/native/common/AccessBridgeDebug.h src/jdk.accessibility/windows/native/libjavaaccessbridge/JavaAccessBridge.cpp src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.cpp
diffstat 4 files changed, 22 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp	Wed Apr 24 09:21:02 2019 -0700
+++ b/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp	Thu Apr 25 15:19:09 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, 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
@@ -41,34 +41,24 @@
 
 static FILE* logFP = nullptr;
 
-void initializeFileLogger(char * suffix) {
-    auto var = "JAVA_ACCESSBRIDGE_LOGFILE";
+void initializeFileLogger(char * fileName) {
+    auto var = "JAVA_ACCESSBRIDGE_LOGDIR";
     const auto envfilePath = getenv(var);
-    if (envfilePath != nullptr) {
-        auto ext = const_cast<char*>(strrchr(envfilePath, '.'));
-        auto filePath = static_cast<char*>(nullptr);
-        auto len = strlen(envfilePath);
-        auto suffixlen = suffix != nullptr ? strlen(suffix) : (decltype(strlen(nullptr)))0;
-
-        if (ext == nullptr) {
-            filePath = new char[len + suffixlen + 5];
-            memset(filePath, 0, len + suffixlen + 5);
-            memcpy(filePath, envfilePath, len);
-            memcpy(filePath + len, suffix, suffixlen);
-            memcpy(filePath + len + suffixlen, ".log", 4);
-        } else {
-            auto extLen = strlen(ext);
-
-            filePath = new char[len + suffixlen + 1];
-            memset(filePath, 0, len + suffixlen + 1);
-            memcpy(filePath, envfilePath, len - extLen);
-            memcpy(filePath + len - extLen, suffix, suffixlen);
-            memcpy(filePath + len + suffixlen - extLen, ext, extLen);
-        }
+    if (envfilePath != nullptr && fileName != nullptr) {
+        auto envFilePathLength = strlen(envfilePath);
+        auto fileNameLength = strlen(fileName);
+        auto filePathSize = envFilePathLength + 1 + fileNameLength + 5; //1 for "/", 5 for ".log" and 0;
+        auto filePath = new char[filePathSize];
+        memset(filePath, 0, filePathSize*sizeof(char));
+        memcpy(filePath, envfilePath, envFilePathLength*sizeof(char));
+        filePath[envFilePathLength] = '/';
+        memcpy(filePath + envFilePathLength + 1, fileName, fileNameLength*sizeof(char));
+        memcpy(filePath + envFilePathLength + 1 + fileNameLength, ".log", 4*sizeof(char));
 
         logFP = fopen(filePath, "w");
         if (logFP == nullptr) {
-            PrintDebugString("couldnot open file %s", filePath);
+            printf("\n%s\n", filePath);
+            PrintDebugString("Could not open file %s", filePath);
         }
 
         delete [] filePath;
@@ -144,7 +134,7 @@
 #endif
 #endif
         if (logFP) {
-            fprintf(logFP, "[%lldu] ", getTimeStamp());
+            fprintf(logFP, "[%llu] ", getTimeStamp());
             va_list args;
             va_start(args, msg);
             vfprintf(logFP, msg, args);
--- a/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.h	Wed Apr 24 09:21:02 2019 -0700
+++ b/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.h	Thu Apr 25 15:19:09 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, 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
@@ -54,7 +54,7 @@
     void PrintJavaDebugString(char *msg, ...);
     void wPrintJavaDebugString(wchar_t *msg, ...);
     void wPrintDebugString(wchar_t *msg, ...);
-    void initializeFileLogger(char * suffix);
+    void initializeFileLogger(char * fileName);
     void finalizeFileLogger();
 
 #ifdef __cplusplus
--- a/src/jdk.accessibility/windows/native/libjavaaccessbridge/JavaAccessBridge.cpp	Wed Apr 24 09:21:02 2019 -0700
+++ b/src/jdk.accessibility/windows/native/libjavaaccessbridge/JavaAccessBridge.cpp	Thu Apr 25 15:19:09 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, 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
@@ -165,7 +165,7 @@
 JavaAccessBridge::JavaAccessBridge(HINSTANCE hInstance) {
     windowsInstance = hInstance;
     ATs = (AccessBridgeATInstance *) 0;
-    initializeFileLogger("_java_access_bridge");
+    initializeFileLogger("java_access_bridge");
     initBroadcastMessageIDs();          // get the unique to us broadcast msg. IDs
 }
 
--- a/src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.cpp	Wed Apr 24 09:21:02 2019 -0700
+++ b/src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.cpp	Thu Apr 25 15:19:09 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, 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
@@ -130,7 +130,7 @@
 
         switch (fdwReason) {
         case DLL_PROCESS_ATTACH:        // A Windows executable loaded us
-            initializeFileLogger("_windows_access_bridge");
+            initializeFileLogger("windows_access_bridge");
             PrintDebugString("[INFO]: DLL_PROCESS_ATTACH");
             theWindowsAccessBridge = new WinAccessBridge(hinstDll);
             break;