ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject incubator-ignite git commit: IGNITE-843: Minor fix for getting agent home folder.
Date Tue, 18 Aug 2015 17:03:34 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 24af0422a -> bd4499f5b


IGNITE-843: Minor fix for getting agent home folder.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bd4499f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bd4499f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bd4499f5

Branch: refs/heads/ignite-843
Commit: bd4499f5b2518daf57f421349a3b14e91139b42e
Parents: 24af042
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Wed Aug 19 00:03:23 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Wed Aug 19 00:03:23 2015 +0700

----------------------------------------------------------------------
 .../org/apache/ignite/agent/AgentUtils.java     | 22 +++--------------
 .../handlers/DatabaseMetadataExtractor.java     | 26 ++++++++++++++------
 2 files changed, 22 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd4499f5/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentUtils.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentUtils.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentUtils.java
index 0675e3f..9ab952a 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentUtils.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentUtils.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.agent;
 
 import java.io.*;
-import java.net.*;
+import java.nio.file.*;
 
 /**
  * Utility methods.
@@ -32,25 +32,9 @@ public class AgentUtils {
     }
 
     /**
-     * @return Folder where agent.jar is located.
+     * @return App folder.
      */
     public static File getAgentHome() {
-        URL jarLogCfgUrl = AgentLauncher.class.getResource("/logging.properties");
-
-        String path = jarLogCfgUrl.getFile();
-
-        int jarSeparatorIdx = path.lastIndexOf("!/");
-
-        if (jarSeparatorIdx == -1)
-            return null;
-
-        path = path.substring(0, jarSeparatorIdx);
-
-        if (path.startsWith("file:"))
-            path = path.substring("file:".length());
-
-        File jarFile = new File(path);
-
-        return jarFile.getParentFile();
+        return Paths.get("").toAbsolutePath().toFile();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bd4499f5/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
index a4dfc60..b01bdc5 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/DatabaseMetadataExtractor.java
@@ -58,7 +58,6 @@ public class DatabaseMetadataExtractor {
      * @param jdbcDriverCls JDBC driver class.
      * @param jdbcUrl JDBC URL.
      * @param jdbcInfo Properties to connect to database.
-     *
      * @return Collection of tables.
      */
     @Remote
@@ -98,20 +97,30 @@ public class DatabaseMetadataExtractor {
     }
 
     /**
+     * @param path Path to normalize.
+     * @return Normalized file path.
+     */
+    private String normalizePath(String path) {
+        return path != null ? path.replace('\\', '/') : null;
+    }
+
+    /**
      * @return Drivers in drivers folder
      * @see AgentConfiguration#driversFolder
      */
     @Remote
     public List<JdbcDriver> availableDrivers() {
-        log.log(Level.INFO, "Collecting JDBC drivers in folder: " + driversFolder);
+        String drvFolder = normalizePath(driversFolder);
 
-        if (driversFolder == null) {
+        log.log(Level.INFO, "Collecting JDBC drivers in folder: " + drvFolder);
+
+        if (drvFolder == null) {
             log.log(Level.INFO, "JDBC drivers folder not specified, returning empty list");
 
             return Collections.emptyList();
         }
 
-        String[] list = new File(driversFolder).list();
+        String[] list = new File(drvFolder).list();
 
         if (list == null) {
             log.log(Level.INFO, "JDBC drivers folder has no files, returning empty list");
@@ -124,17 +133,20 @@ public class DatabaseMetadataExtractor {
         for (String fileName : list) {
             if (fileName.endsWith(".jar")) {
                 try {
-                    String spec = "jar:file:/" + driversFolder + '/' + fileName + "!/META-INF/services/java.sql.Driver";
+                    String spec = normalizePath("jar:file:/" + drvFolder + '/' + fileName
+
+                        "!/META-INF/services/java.sql.Driver");
 
-                    URL url = new URL(spec.replace('\\', '/'));
+                    URL url = new URL(spec);
 
                     try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())))
{
                         String jdbcDriverClass = reader.readLine();
+
                         res.add(new JdbcDriver(jdbcDriverClass, fileName));
 
                         log.log(Level.INFO, "Found: [driver=" + fileName + ", class=" + jdbcDriverClass
+ "]");
                     }
-                } catch (IOException e) {
+                }
+                catch (IOException e) {
                     res.add(new JdbcDriver(null, fileName));
 
                     log.log(Level.INFO, "Found: [driver=" + fileName + "]");


Mime
View raw message