From 48f60a30284e7a3af5d5d2ea5a1094e1d652f7b4 Mon Sep 17 00:00:00 2001 From: "zongbo.wu" Date: Thu, 11 Jun 2020 18:16:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=B2=E6=AD=A2=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rudolph-compiler/build.gradle | 4 ++-- .../java/cn/wzbos/android/rudolph/Rudolph.java | 17 ++++++++++++++--- .../android/rudolph/router/FragmentRouter.java | 4 +++- .../android/rudolph/router/MethodRouter.java | 3 ++- .../android/rudolph/router/RouteBuilder.java | 4 ++-- .../android/rudolph/router/ServiceRouter.java | 14 ++++++++++++-- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/rudolph-compiler/build.gradle b/rudolph-compiler/build.gradle index 30b5233..ff17c49 100755 --- a/rudolph-compiler/build.gradle +++ b/rudolph-compiler/build.gradle @@ -20,8 +20,8 @@ dependencies { annotationProcessor 'com.google.auto.service:auto-service:1.0-rc7' implementation 'org.apache.commons:commons-lang3:3.5' implementation 'org.apache.commons:commons-collections4:4.1' - implementation project(':rudolph-annotations') -// implementation "${publishedGroupId}:rudolph-annotations:${rudolph_version}" +// implementation project(':rudolph-annotations') + implementation "${publishedGroupId}:rudolph-annotations:${rudolph_version}" } apply from: '../install.gradle' diff --git a/rudolph/src/main/java/cn/wzbos/android/rudolph/Rudolph.java b/rudolph/src/main/java/cn/wzbos/android/rudolph/Rudolph.java index fb1af1f..e0df2dc 100755 --- a/rudolph/src/main/java/cn/wzbos/android/rudolph/Rudolph.java +++ b/rudolph/src/main/java/cn/wzbos/android/rudolph/Rudolph.java @@ -26,6 +26,7 @@ public class Rudolph { private static List routes = new ArrayList<>(); private static Application app; private static String scheme; + private static Boolean initialized = false; public static Application getApplication() { return app; @@ -40,6 +41,9 @@ public static String getScheme() { */ public static void init(Application application) { Log.v(TAG, "init"); + if (initialized) + return; + app = application; AssetManager assetManager = application.getResources().getAssets(); try { @@ -53,16 +57,23 @@ public static void init(Application application) { iGroupInstance.init(application); } } catch (ClassNotFoundException e) { - Log.e(TAG, "初始化\"" + className + "\"组件失败,请检查包名是否正确!"); - e.printStackTrace(); + Log.e(TAG, "初始化\"" + className + "\"组件失败,请检查包名是否正确!", e); } } } + initialized = true; } catch (Exception e) { - e.printStackTrace(); + Log.e(TAG, "路由初始化异常!", e); } } + /** + * 获取是否已初始化路由表 + */ + public static Boolean isInitialized() { + return initialized; + } + public static void setScheme(String schemeStr) { scheme = schemeStr; } diff --git a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/FragmentRouter.java b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/FragmentRouter.java index 29cc014..8d5c08a 100755 --- a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/FragmentRouter.java +++ b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/FragmentRouter.java @@ -1,5 +1,7 @@ package cn.wzbos.android.rudolph.router; +import android.util.Log; + import cn.wzbos.android.rudolph.exception.RudolphException; public class FragmentRouter extends Router { @@ -34,7 +36,7 @@ public R open() { return (R) instance; } catch (Exception e) { - e.printStackTrace(); + Log.e("rudolph", "open fragment error!", e); if (callback != null) callback.onFailed(e); } diff --git a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/MethodRouter.java b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/MethodRouter.java index b35585c..ac24186 100755 --- a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/MethodRouter.java +++ b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/MethodRouter.java @@ -2,6 +2,7 @@ import android.app.Application; import android.content.Context; +import android.util.Log; import cn.wzbos.android.rudolph.Rudolph; import cn.wzbos.android.rudolph.Consts; @@ -79,7 +80,7 @@ public Object open(Context context) { } } catch (Exception e) { - e.printStackTrace(); + Log.e("rudolph", "方法调用异常!", e); if (null != callback) callback.onFailed(e); } diff --git a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/RouteBuilder.java b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/RouteBuilder.java index 20b7eae..1da8f62 100755 --- a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/RouteBuilder.java +++ b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/RouteBuilder.java @@ -331,7 +331,7 @@ private List getSegments() { segments.add(URLDecoder.decode(val, "utf-8")); } } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.e("rudolph", "getSegments failed!", e); } } return segments; @@ -385,7 +385,7 @@ Map getUriAllParams() { String value = URLDecoder.decode(kv[1], "utf-8"); params.put(name, value); } catch (Exception e) { - e.printStackTrace(); + Log.e("rudolph", "getUriAllParams failed!", e); } } } diff --git a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/ServiceRouter.java b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/ServiceRouter.java index eedcc93..a8aba2f 100755 --- a/rudolph/src/main/java/cn/wzbos/android/rudolph/router/ServiceRouter.java +++ b/rudolph/src/main/java/cn/wzbos/android/rudolph/router/ServiceRouter.java @@ -1,6 +1,10 @@ package cn.wzbos.android.rudolph.router; +import android.util.Log; + +import java.lang.reflect.Constructor; + import cn.wzbos.android.rudolph.IRouteService; public class ServiceRouter extends Router { @@ -13,13 +17,19 @@ protected ServiceRouter(Builder builder) { super(builder); } + @Override public R open() { if (super.intercept(null)) return null; try { - Object instance = target.getConstructor().newInstance(); + Constructor constructor = target.getConstructor(); + if (!constructor.isAccessible()) { + Log.w("rudolph", target.getName() + " constructor method is private!"); + constructor.setAccessible(true); + } + Object instance = constructor.newInstance(); if (instance instanceof IRouteService) { IRouteService component = ((IRouteService) instance); component.init(this.bundle); @@ -28,7 +38,7 @@ public R open() { return (R) component; } } catch (Exception e) { - e.printStackTrace(); + Log.e("rudolph", "open service failed!"); if (callback != null) callback.onFailed(e); }