changeset 196:c13a38af15f4

Bug 3261: Cannot start FXAnalyzer when HeapStatsFXAnalyzer.main() is called directly Reviewed-by: ykubota https://github.com/HeapStats/heapstats/pull/59
author Yasumasa Suenaga <yasuenag@gmail.com>
date Mon, 12 Dec 2016 22:27:51 +0900
parents 09afe400f30a
children 41c8a64e510e
files ChangeLog analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/WindowController.java analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/utils/HeapStatsUtils.java
diffstat 3 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Dec 12 22:16:54 2016 +0900
+++ b/ChangeLog	Mon Dec 12 22:27:51 2016 +0900
@@ -2,6 +2,7 @@
 
 	* Bug 3247: Refactoring chart legends and tooltip
 	* Bug 3260: Cannot run FXAnalyzer via Maven task without NetBeans
+	* Bug 3261: Cannot start FXAnalyzer when HeapStatsFXAnalyzer.main() is called directly 
 
 2016-12-07  Yasumasa Suenaga <yasuenag@gmail.com>
 
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/WindowController.java	Mon Dec 12 22:16:54 2016 +0900
+++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/WindowController.java	Mon Dec 12 22:27:51 2016 +0900
@@ -279,14 +279,7 @@
         this.hostServices = hostServices;
     }
 
-    /**
-     * Load plugins which is defined in heapstats.properties.
-     */
-    public void loadPlugin(){
-        String resourceName = "/" + this.getClass().getName().replace('.', '/') + ".class";
-        String appJarString = this.getClass().getResource(resourceName).getPath();
-        appJarString = appJarString.substring(0, appJarString.indexOf('!')).replaceFirst("file:", "");
-
+    private ClassLoader createPluginClassLoader(String appJarString){
         Path appJarPath;
 
         try{
@@ -317,7 +310,19 @@
             Logger.getLogger(WindowController.class.getName()).log(Level.SEVERE, null, ex);
         }
 
-        pluginClassLoader = (jarURLList == null) ? WindowController.class.getClassLoader() : new URLClassLoader(jarURLList);
+        return (jarURLList == null) ? WindowController.class.getClassLoader() : new URLClassLoader(jarURLList);
+    }
+
+    /**
+     * Load plugins which is defined in heapstats.properties.
+     */
+    public void loadPlugin(){
+        String resourceName = "/" + this.getClass().getName().replace('.', '/') + ".class";
+        String appJarString = this.getClass().getResource(resourceName).getPath();
+
+        pluginClassLoader = appJarString.contains("!") ? createPluginClassLoader(appJarString.substring(0, appJarString.indexOf('!')).replaceFirst("file:", ""))
+                                                       : WindowController.class.getClassLoader();
+
         FXMLLoader.setDefaultClassLoader(pluginClassLoader);
 
         List<String> plugins = HeapStatsUtils.getPlugins();
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/utils/HeapStatsUtils.java	Mon Dec 12 22:16:54 2016 +0900
+++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/utils/HeapStatsUtils.java	Mon Dec 12 22:27:51 2016 +0900
@@ -78,7 +78,7 @@
             String appJar = Stream.of(System.getProperty("java.class.path").split(System.getProperty("path.separator")))
                     .filter(s -> s.endsWith("heapstats-analyzer.jar"))
                     .findFirst()
-                    .get();
+                    .orElse(".");
             currentPath = Paths.get(appJar).toAbsolutePath().getParent();
         }
 
@@ -102,7 +102,7 @@
         }
 
         /* Load resource bundle */
-        resource = ResourceBundle.getBundle("HeapStatsResources", new Locale(prop.getProperty("language")));
+        resource = ResourceBundle.getBundle("HeapStatsResources");
 
         /* Validate values in properties. */
 
@@ -114,6 +114,9 @@
             throw new HeapStatsConfigException(resource.getString("invalid.option") + " language=" + language);
         }
 
+        /* Load resource bundle again */
+        resource = ResourceBundle.getBundle("HeapStatsResources", new Locale(prop.getProperty("language")));
+
         /* RankLevel */
         String rankLevelStr = prop.getProperty("ranklevel");
         if (rankLevelStr == null) {