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 03:57:43 UTC

[incubator-skywalking] branch asf/5.0-alpha/release updated: Support comments in skywalking-plugin.def

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 0328dd7  Support comments in skywalking-plugin.def
0328dd7 is described below

commit 0328dd71b04e4f728df337b7a3746d59bdea3760
Author: wusheng <wu...@foxmail.com>
AuthorDate: Sat Mar 24 11:57:34 2018 +0800

    Support comments in skywalking-plugin.def
---
 .../apm/agent/core/plugin/PluginCfg.java           | 24 +++++++-----------
 .../apm/agent/core/plugin/PluginDefine.java        | 16 +-----------
 .../exception/IllegalPluginDefineException.java    | 29 ----------------------
 3 files changed, 10 insertions(+), 59 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 c4a61af..2100d86 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,16 +19,15 @@
 
 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;
@@ -39,18 +38,13 @@ public enum PluginCfg {
 
     void load(InputStream input) throws IOException {
         try {
-            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
-            String pluginDefine = null;
-            while ((pluginDefine = reader.readLine()) != null) {
-                try {
-                    if (pluginDefine == null || pluginDefine.trim().length() == 0) {
-                        continue;
-                    }
-                    PluginDefine plugin = PluginDefine.build(pluginDefine);
-                    pluginClassList.add(plugin);
-                } catch (IllegalPluginDefineException e) {
-                    logger.error(e, "Failed to format plugin({}) define.", pluginDefine);
-                }
+            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);
             }
         } 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 573461a..72c5a2e 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,9 +19,6 @@
 
 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.
@@ -38,18 +35,7 @@ public class PluginDefine {
         this.defineClass = 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];
+    public static PluginDefine build(String pluginName, String defineClass) {
         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
deleted file mode 100644
index 8be1e8d..0000000
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/exception/IllegalPluginDefineException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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);
-    }
-}

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