package com.ai.cloud.skywalking.plugin;

import com.ai.cloud.skywalking.logging.LogManager;
import com.ai.cloud.skywalking.logging.Logger;
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Map;

/**
 * 替代应用函数的main函数入口，确保在程序入口处运行 <br/>
 * 用于替代-javaagent的另一种模式 <br/>
 * 主要用于插件的本地化调试与运行<br/>
 *
 *
 * @author wusheng
 */
public class TracingBootstrap {
    private static Logger logger = LogManager.getLogger(TracingBootstrap.class);

    private TracingBootstrap() {
    }

    public static void main(String[] args)
            throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
            SecurityException, ClassNotFoundException {
        if (args.length == 0) {
            throw new RuntimeException("bootstrap failure. need args[0] to be main class.");
        }

        PluginBootstrap bootstrap = new PluginBootstrap();
        Map<String, ClassEnhancePluginDefine> pluginDefineMap = bootstrap.loadPlugins();

        for(String enhanceClassName : pluginDefineMap.keySet()){
            //init ctClass
            //enhance class
        }

        String[] newArgs = Arrays.copyOfRange(args, 1, args.length);


        Class.forName(args[0]).getMethod("main", String[].class).invoke(null, new Object[] {newArgs});
    }
}

@@ -135,92 +135,8 @@
 ger;
-%0Aimport com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;
 %0A%0Aim
@@ -213,30 +213,8 @@
 ays;
-%0Aimport java.util.Map;
 %0A%0A/*
@@ -288,34 +288,8 @@
 %0A * 
-%E4%B8%BB%E8%A6%81%E7%94%A8%E4%BA%8E%E6%8F%92%E4%BB%B6%E7%9A%84%E6%9C%AC%E5%9C%B0%E5%8C%96%E8%B0%83%E8%AF%95%E4%B8%8E%E8%BF%90%E8%A1%8C%3Cbr/%3E%0A *%0A *
 %0A * 
@@ -304,16 +304,19 @@
 wusheng%0A
+ *%0A
  */%0Apubl
@@ -343,20 +343,17 @@
 strap %7B%0A
-    
+%09
 private 
@@ -422,20 +422,17 @@
 lass);%0A%0A
-    
+%09
 private 
@@ -452,27 +452,21 @@
 rap() %7B%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 public s
@@ -495,28 +495,16 @@
 %5B%5D args)
-%0A           
  throws 
@@ -526,17 +526,20 @@
 ception,
- 
+%0A%09%09%09
 IllegalA
@@ -582,17 +582,20 @@
 ception,
- 
+%0A%09%09%09
 NoSuchMe
@@ -608,28 +608,16 @@
 ception,
-%0A           
  Securit
@@ -653,24 +653,18 @@
 ption %7B%0A
-        
+%09%09
 if (args
@@ -679,28 +679,19 @@
 == 0) %7B%0A
-            
+%09%09%09
 throw ne
@@ -709,16 +709,22 @@
 ception(
+%0A%09%09%09%09%09
 %22bootstr
@@ -769,35 +769,32 @@
 ass.%22);%0A
-        %7D%0A%0A        
+%09%09%7D%0A%0A%09%09try %7B%0A%09%09%09
 PluginBo
@@ -840,237 +840,123 @@
 ();%0A
-        Map%3CString, ClassEnhancePluginDefine%3E pluginDefineMap = bootstrap.loadPlugins();%0A%0A        for(String enhanceClassName : pluginDefineMap.keySet())%7B%0A            //init ctClass%0A            //enhance class%0A        %7D%0A%0A        
+%09%09%09bootstrap.loadPlugins();%0A%09%09%7D catch (Throwable t) %7B%0A%09%09%09logger.error(%22PluginBootstrap start failure.%22, t);%0A%09%09%7D%0A%0A%09%09
 Stri
@@ -1017,17 +1017,13 @@
 );%0A%0A
-%0A        
+%09%09%0A%09%09
 Clas
@@ -1074,16 +1074,21 @@
 %5D.class)
+%0A%09%09%09%09
 .invoke(
@@ -1105,17 +1105,16 @@
 Object%5B%5D
- 
 %7BnewArgs
@@ -1121,12 +1121,9 @@
 %7D);%0A
-    
+%09
 %7D%0A%7D%0A

Revert "提供一个TracingBootstrap的实现方式的指导"