You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2018/03/24 08:12:28 UTC

[incubator-skywalking] branch asf/5.0-alpha/release updated: revert code (#984)

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

wusheng pushed a commit to branch asf/5.0-alpha/release
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git


The following commit(s) were added to refs/heads/asf/5.0-alpha/release by this push:
     new 4e41ee0  revert code (#984)
4e41ee0 is described below

commit 4e41ee0c1f03a8e18e29e3e7ca971dd9b45edec8
Author: Xin,Zhang <zh...@apache.org>
AuthorDate: Sat Mar 24 16:12:26 2018 +0800

    revert code (#984)
---
 .../apm/agent/core/plugin/PluginCfg.java           | 24 ++++++++++------
 .../apm/agent/core/plugin/PluginDefine.java        | 16 ++++++++++-
 .../IllegalPluginDefineException.java}             | 32 +++++-----------------
 3 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java
index 2100d86..29de312 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginCfg.java
@@ -19,15 +19,16 @@
 
 package org.apache.skywalking.apm.agent.core.plugin;
 
+import org.apache.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException;
 import org.apache.skywalking.apm.agent.core.logging.api.ILog;
 import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
-import java.util.Properties;
 
 public enum PluginCfg {
     INSTANCE;
@@ -38,13 +39,18 @@ public enum PluginCfg {
 
     void load(InputStream input) throws IOException {
         try {
-            Properties properties = new Properties();
-            properties.load(input);
-            for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) {
-                String pluginName = String.valueOf(objectObjectEntry.getKey());
-                String defineClass = String.valueOf(objectObjectEntry.getValue());
-                PluginDefine plugin = PluginDefine.build(pluginName, defineClass);
-                pluginClassList.add(plugin);
+            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
+            String pluginDefine = null;
+            while ((pluginDefine = reader.readLine()) != null) {
+                try {
+                    if (pluginDefine == null || pluginDefine.trim().length() == 0 || pluginDefine.startsWith("#")) {
+                        continue;
+                    }
+                    PluginDefine plugin = PluginDefine.build(pluginDefine);
+                    pluginClassList.add(plugin);
+                } catch (IllegalPluginDefineException e) {
+                    logger.error(e, "Failed to format plugin({}) define.", pluginDefine);
+                }
             }
         } finally {
             input.close();
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java
index 72c5a2e..573461a 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java
@@ -19,6 +19,9 @@
 
 package org.apache.skywalking.apm.agent.core.plugin;
 
+import org.apache.skywalking.apm.agent.core.plugin.exception.IllegalPluginDefineException;
+import org.apache.skywalking.apm.util.StringUtil;
+
 public class PluginDefine {
     /**
      * Plugin name.
@@ -35,7 +38,18 @@ public class PluginDefine {
         this.defineClass = defineClass;
     }
 
-    public static PluginDefine build(String pluginName, String defineClass) {
+    public static PluginDefine build(String define) throws IllegalPluginDefineException {
+        if (StringUtil.isEmpty(define)) {
+            throw new IllegalPluginDefineException(define);
+        }
+
+        String[] pluginDefine = define.split("=");
+        if (pluginDefine.length != 2) {
+            throw new IllegalPluginDefineException(define);
+        }
+
+        String pluginName = pluginDefine[0];
+        String defineClass = pluginDefine[1];
         return new PluginDefine(pluginName, defineClass);
     }
 
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java
similarity index 58%
copy from apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java
copy to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java
index 72c5a2e..8be1e8d 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/PluginDefine.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java
@@ -17,31 +17,13 @@
  */
 
 
-package org.apache.skywalking.apm.agent.core.plugin;
+package org.apache.skywalking.apm.agent.core.plugin.exception;
 
-public class PluginDefine {
-    /**
-     * Plugin name.
-     */
-    private String name;
-
-    /**
-     * The class name of plugin defined.
-     */
-    private String defineClass;
-
-    private PluginDefine(String name, String defineClass) {
-        this.name = name;
-        this.defineClass = defineClass;
-    }
-
-    public static PluginDefine build(String pluginName, String defineClass) {
-        return new PluginDefine(pluginName, defineClass);
-    }
-
-    public String getDefineClass() {
-        return defineClass;
+/**
+ * Thrown to indicate that a illegal format plugin definition has been defined in skywalking-plugin.define.
+ */
+public class IllegalPluginDefineException extends Exception {
+    public IllegalPluginDefineException(String define) {
+        super("Illegal plugin define : " + define);
     }
 }
-
-

-- 
To stop receiving notification emails like this one, please contact
wusheng@apache.org.