You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/03/24 08:12:27 UTC

[GitHub] wu-sheng closed pull request #984: revert code

wu-sheng closed pull request #984: revert code
URL: https://github.com/apache/incubator-skywalking/pull/984
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 2100d86e6..29de3124a 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 @@
 
     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 72c5a2ee9..573461ac4 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 @@ private PluginDefine(String name, String defineClass) {
         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/exception/IllegalPluginDefineException.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java
new file mode 100644
index 000000000..8be1e8d93
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+package org.apache.skywalking.apm.agent.core.plugin.exception;
+
+/**
+ * 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);
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services