From b5ebeec7c3d93417262ad6dc49970285456ecc2f Mon Sep 17 00:00:00 2001 From: darren Date: Thu, 14 Mar 2019 12:35:30 +0800 Subject: [PATCH 01/11] fix #341 regexp error fix https://github.com/lets-blade/blade/issues/341 --- src/main/java/com/blade/mvc/route/RouteMatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/blade/mvc/route/RouteMatcher.java b/src/main/java/com/blade/mvc/route/RouteMatcher.java index 7eae42945..1ece1476e 100644 --- a/src/main/java/com/blade/mvc/route/RouteMatcher.java +++ b/src/main/java/com/blade/mvc/route/RouteMatcher.java @@ -41,7 +41,7 @@ @Slf4j public class RouteMatcher { - private static final Pattern PATH_VARIABLE_PATTERN = Pattern.compile("/(([^:/]*):([^/]+))|(\\.\\*)"); + private static final Pattern PATH_VARIABLE_PATTERN = Pattern.compile("/(?:([^:/]*):([^/]+))|(\\.\\*)"); private static final String METHOD_NAME = "handle"; // Storage URL and route From 1ad93d57a58ee2f139dba647df3f01dd57d02a33 Mon Sep 17 00:00:00 2001 From: dongm2ez Date: Fri, 15 Mar 2019 19:03:47 +0800 Subject: [PATCH 02/11] :wrench: update github template --- .github/ISSUE_TEMPLATE/bug_report.md | 20 +++++++++++-------- .github/ISSUE_TEMPLATE/documentation_issue.md | 9 +++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 12 +++++------ .github/ISSUE_TEMPLATE/general_question.md | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/documentation_issue.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index d3f5f6309..724db0484 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,14 +1,18 @@ --- -name: Bug report -about: Create a report to help us improve - +name: πŸ› Bug Report +about: Report a general framework issue. help us improve this framework. --- -**Describe the bug** +- System Version (e.g. Mac Os 10.14.3): +- Build tools (e.g. maven/gradle): +- JDK Version (e.g. e.g `2.0.8-R1`): +- Database Version: + +### Describe the bug A clear and concise description of what the bug is. -**To Reproduce** +### To Reproduce Steps to reproduce the behavior: @@ -17,14 +21,14 @@ Steps to reproduce the behavior: 3. JDK version and blade version(e.g `2.0.8-R1`) 4. See error -**Expected behavior** +### Expected behavior: A clear and concise description of what you expected to happen. -**Screenshots** +### Screenshots: If applicable, add screenshots to help explain your problem. -**Additional context** +### Additional context: Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/documentation_issue.md b/.github/ISSUE_TEMPLATE/documentation_issue.md new file mode 100644 index 000000000..2a56a7d30 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation_issue.md @@ -0,0 +1,9 @@ +--- +name: πŸ“š Documentation Issue +about: For documentation issues, open a pull request at https://github.com/lets-blade/lets-blade.github.io + +--- + +The blade documentation has its own dedicated repository. Please open a pull request at https://github.com/lets-blade/lets-blade.github.io to correct the issue you have found. + +Thanks! \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 65322c2e0..b2c7140d9 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,21 +1,21 @@ --- -name: Feature request -about: Suggest an idea for this project +name: ✨ Feature Request +about: For ideas or feature requests --- -**Is your feature request related to a problem? Please describe.** +### Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -**Describe the solution you'd like** +### Describe the solution you'd like A clear and concise description of what you want to happen. -**Describe alternatives you've considered** +### Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. -**Additional context** +### Additional context Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/general_question.md b/.github/ISSUE_TEMPLATE/general_question.md index bc4a2621a..df6ef6322 100644 --- a/.github/ISSUE_TEMPLATE/general_question.md +++ b/.github/ISSUE_TEMPLATE/general_question.md @@ -1,5 +1,5 @@ --- -name: General question +name: 🍻 General Question about: Template for asking question --- From 55bd523129e89c198d5b7e18ee6bdf655946904f Mon Sep 17 00:00:00 2001 From: darren Date: Sat, 16 Mar 2019 00:31:55 +0800 Subject: [PATCH 03/11] fix UnmodifiableMap serialize exception fix UnmodifiableMap(`Collections.UnmodifiableMap(map)` /`Collections.singletonMap("key","value")` ) serialize throw UnsupportedOperationException --- src/main/java/com/blade/kit/json/BeanSerializer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/blade/kit/json/BeanSerializer.java b/src/main/java/com/blade/kit/json/BeanSerializer.java index 4ada657e7..dad661977 100755 --- a/src/main/java/com/blade/kit/json/BeanSerializer.java +++ b/src/main/java/com/blade/kit/json/BeanSerializer.java @@ -42,8 +42,8 @@ public static Object serialize(SerializeMapping serializeMapping, Object bean) t } if (bean instanceof Map) { - Map map = (Map) bean; - map.forEach((Object key, Object value) -> { + Map map = new HashMap(); + ((Map) bean).forEach((Object key, Object value) -> { try { map.put(key, serialize(serializeMapping, value)); } catch (Exception e) { From e38adab6c1d353480046eafc0778d943c18620b0 Mon Sep 17 00:00:00 2001 From: psh686868 <1101311464@qq.com> Date: Sat, 16 Mar 2019 16:24:23 +0800 Subject: [PATCH 04/11] =?UTF-8?q?:BugFix:=20fixed=20TaskManager,=20?= =?UTF-8?q?=E5=BD=93=E4=B8=8D=E5=90=8C=E7=9A=84=E7=BA=BF=E7=A8=8B=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BB=BB=E5=8A=A1=E7=9A=84=E6=97=B6=E5=80=99=E4=BC=9A?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E4=BB=BB=E5=8A=A1=E6=B7=BB=E5=8A=A0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/blade/task/TaskManager.java | 45 ++++++++++++++----- .../java/com/blade/task/TaskManagerTest.java | 27 +++++++++++ 2 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 src/test/java/com/blade/task/TaskManagerTest.java diff --git a/src/main/java/com/blade/task/TaskManager.java b/src/main/java/com/blade/task/TaskManager.java index 14a28719f..08d2e9157 100644 --- a/src/main/java/com/blade/task/TaskManager.java +++ b/src/main/java/com/blade/task/TaskManager.java @@ -19,12 +19,10 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import lombok.var; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; import static com.blade.kit.BladeKit.getStartedSymbol; @@ -41,6 +39,9 @@ public final class TaskManager { private final static Map TASK_MAP = new HashMap<>(8); + private final static ReentrantReadWriteLock rrw = new ReentrantReadWriteLock(); + private final static Lock readLock = rrw.readLock(); + private final static Lock writeLock = rrw.writeLock(); private static CronExecutorService cronExecutorService; @@ -57,21 +58,45 @@ public static CronExecutorService getExecutorService() { } public static void addTask(Task task) { - TASK_MAP.put(task.getName(), task); + writeLock.lock(); + try { + TASK_MAP.put(task.getName(), task); + } finally { + writeLock.unlock(); + } log.info("{}Add task [{}]", getStartedSymbol(), task.getName()); } public static List getTasks() { - return new ArrayList<>(TASK_MAP.values()); + Collection values; + readLock.lock(); + try { + values = Optional.ofNullable(TASK_MAP.values()).orElse(Collections.EMPTY_LIST); + } finally { + readLock.unlock(); + } + return new ArrayList<>(values); } public static Task getTask(String name) { - return TASK_MAP.get(name); + readLock.lock(); + try { + return TASK_MAP.get(name); + } finally { + readLock.unlock(); + } + } public static boolean stopTask(String name) { - var task = TASK_MAP.get(name); - return task.stop(); + Task task; + readLock.lock(); + try { + task = TASK_MAP.get(name); + } finally { + readLock.unlock(); + } + return task == null ? Boolean.FALSE : task.stop(); } } diff --git a/src/test/java/com/blade/task/TaskManagerTest.java b/src/test/java/com/blade/task/TaskManagerTest.java new file mode 100644 index 000000000..350da7973 --- /dev/null +++ b/src/test/java/com/blade/task/TaskManagerTest.java @@ -0,0 +1,27 @@ +package com.blade.task; + +import java.util.concurrent.CountDownLatch; +import java.util.stream.IntStream; + +/** + * @author PSH + * @date 2019/03/16 + */ +public class TaskManagerTest { + public static void main(String[] args) { + CountDownLatch downLatch = new CountDownLatch(500); + IntStream.range(0,500).forEach(i -> { + Task task = new Task("task-" + i, null, Integer.MAX_VALUE); + new Thread(()->{ + TaskManager.addTask(task); + downLatch.countDown(); + }).start(); + }); + try { + downLatch.await(); + System.out.println("TaskManager.getTasks().size() = " + TaskManager.getTasks().size()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} From 2784e378a190177349797d2724c1ef6a469b7e17 Mon Sep 17 00:00:00 2001 From: darren Date: Sun, 17 Mar 2019 10:02:02 +0800 Subject: [PATCH 05/11] improve --- src/main/java/com/blade/kit/json/BeanSerializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/blade/kit/json/BeanSerializer.java b/src/main/java/com/blade/kit/json/BeanSerializer.java index dad661977..57a834824 100755 --- a/src/main/java/com/blade/kit/json/BeanSerializer.java +++ b/src/main/java/com/blade/kit/json/BeanSerializer.java @@ -42,7 +42,7 @@ public static Object serialize(SerializeMapping serializeMapping, Object bean) t } if (bean instanceof Map) { - Map map = new HashMap(); + Map map = new HashMap(((Map) bean).size()); ((Map) bean).forEach((Object key, Object value) -> { try { map.put(key, serialize(serializeMapping, value)); From 08df513e76aec11a06ebc3528b2ecbe751468dc1 Mon Sep 17 00:00:00 2001 From: darren Date: Sun, 17 Mar 2019 10:03:10 +0800 Subject: [PATCH 06/11] refine --- src/main/java/com/blade/kit/json/BeanSerializer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/blade/kit/json/BeanSerializer.java b/src/main/java/com/blade/kit/json/BeanSerializer.java index 57a834824..9d825f58a 100755 --- a/src/main/java/com/blade/kit/json/BeanSerializer.java +++ b/src/main/java/com/blade/kit/json/BeanSerializer.java @@ -42,8 +42,9 @@ public static Object serialize(SerializeMapping serializeMapping, Object bean) t } if (bean instanceof Map) { - Map map = new HashMap(((Map) bean).size()); - ((Map) bean).forEach((Object key, Object value) -> { + Map beanMap = (Map) bean; + Map map = new HashMap(beanMap.size()); + beanMap.forEach((Object key, Object value) -> { try { map.put(key, serialize(serializeMapping, value)); } catch (Exception e) { From 78932f4638af3f74ab55dcce690e1dbf308ec06e Mon Sep 17 00:00:00 2001 From: darren Date: Sun, 17 Mar 2019 10:31:13 +0800 Subject: [PATCH 07/11] Add Enum serialize/deserialize support --- src/main/java/com/blade/kit/ReflectKit.java | 2 ++ src/main/java/com/blade/kit/json/BeanSerializer.java | 6 ++++++ .../java/com/blade/mvc/handler/RouteActionArguments.java | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/blade/kit/ReflectKit.java b/src/main/java/com/blade/kit/ReflectKit.java index 4ca731ec3..32c80f6c7 100644 --- a/src/main/java/com/blade/kit/ReflectKit.java +++ b/src/main/java/com/blade/kit/ReflectKit.java @@ -147,6 +147,8 @@ public static Object convert(Type type, String value) { return DateKit.toLocalDate(value, "yyyy-MM-dd"); } else if (type.equals(LocalDateTime.class)) { return DateKit.toLocalDateTime(value, "yyyy-MM-dd HH:mm:ss"); + } else if (type instanceof Class && ((Class) type).isEnum()){ + return Enum.valueOf((Class)type,value); } return value; } diff --git a/src/main/java/com/blade/kit/json/BeanSerializer.java b/src/main/java/com/blade/kit/json/BeanSerializer.java index 4ada657e7..58ba2a778 100755 --- a/src/main/java/com/blade/kit/json/BeanSerializer.java +++ b/src/main/java/com/blade/kit/json/BeanSerializer.java @@ -25,6 +25,10 @@ public static Object serialize(SerializeMapping serializeMapping, Object bean) t return bean.toString().replaceAll("\"", "\\\\\""); } + if (bean instanceof Enum){ + return bean.toString(); + } + if (ReflectKit.isBasicType(bean.getClass()) || bean instanceof Number || bean instanceof Date || bean instanceof LocalDate || bean instanceof LocalDateTime) { return bean; @@ -337,6 +341,8 @@ public static T deserialize(Class klass, Object object) { } if (ReflectKit.isBasicType(object)) { return (T) ReflectKit.convert(klass, object.toString()); + } else if (klass.isEnum()){ + return (T) Enum.valueOf((Class) klass,object.toString()); } else if (object instanceof Map) { if (Map.class.isAssignableFrom(klass)) { return klass.cast(object); diff --git a/src/main/java/com/blade/mvc/handler/RouteActionArguments.java b/src/main/java/com/blade/mvc/handler/RouteActionArguments.java index 60e7ff9e4..10013cf7d 100644 --- a/src/main/java/com/blade/mvc/handler/RouteActionArguments.java +++ b/src/main/java/com/blade/mvc/handler/RouteActionArguments.java @@ -166,7 +166,7 @@ private static Object getQueryParam(ParamStruct paramStruct) { if (ReflectKit.isBasicType(argType) || argType.equals(Date.class) || argType.equals(BigDecimal.class) || argType.equals(LocalDate.class) - || argType.equals(LocalDateTime.class)) { + || argType.equals(LocalDateTime.class) || (argType instanceof Class && ((Class) argType).isEnum())) { String value = request.query(name).orElseGet(() -> getDefaultValue(param.defaultValue(), argType)); From e937ee4a57e8aafaaf566d7dd2e624b3a963edea Mon Sep 17 00:00:00 2001 From: psh686868 Date: Mon, 18 Mar 2019 13:30:55 +0800 Subject: [PATCH 08/11] :update: update TackManager --- .../java/com/blade/task/TaskManagerTest.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/blade/task/TaskManagerTest.java b/src/test/java/com/blade/task/TaskManagerTest.java index 350da7973..5fea19d00 100644 --- a/src/test/java/com/blade/task/TaskManagerTest.java +++ b/src/test/java/com/blade/task/TaskManagerTest.java @@ -2,26 +2,29 @@ import java.util.concurrent.CountDownLatch; import java.util.stream.IntStream; +import org.junit.Assert; +import org.junit.Test; /** * @author PSH * @date 2019/03/16 */ public class TaskManagerTest { - public static void main(String[] args) { - CountDownLatch downLatch = new CountDownLatch(500); - IntStream.range(0,500).forEach(i -> { + + @Test + public void testAddTaskMultiThreading() throws Exception { + + final int tackCount = 500; + CountDownLatch downLatch = new CountDownLatch(tackCount); + IntStream.range(0, tackCount).forEach(i -> { Task task = new Task("task-" + i, null, Integer.MAX_VALUE); - new Thread(()->{ + new Thread(() -> { TaskManager.addTask(task); downLatch.countDown(); }).start(); }); - try { - downLatch.await(); - System.out.println("TaskManager.getTasks().size() = " + TaskManager.getTasks().size()); - } catch (InterruptedException e) { - e.printStackTrace(); - } + + downLatch.await(); + Assert.assertEquals(tackCount, TaskManager.getTasks().size()); } } From b1ad00161d50c529b28d4c562155d85c705ace04 Mon Sep 17 00:00:00 2001 From: "fishlikewater@126.com" Date: Mon, 1 Apr 2019 15:06:06 +0800 Subject: [PATCH 09/11] add annotation Configuration --- src/main/java/com/blade/ioc/annotation/Bean.java | 2 +- .../com/blade/ioc/annotation/Configuration.java | 15 +++++++++++++++ .../java/com/blade/server/netty/NettyServer.java | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/blade/ioc/annotation/Configuration.java diff --git a/src/main/java/com/blade/ioc/annotation/Bean.java b/src/main/java/com/blade/ioc/annotation/Bean.java index 6342e5602..4bbd238db 100644 --- a/src/main/java/com/blade/ioc/annotation/Bean.java +++ b/src/main/java/com/blade/ioc/annotation/Bean.java @@ -8,7 +8,7 @@ * @author biezhi * @since 1.5 */ -@Target(ElementType.TYPE) +@Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Bean { diff --git a/src/main/java/com/blade/ioc/annotation/Configuration.java b/src/main/java/com/blade/ioc/annotation/Configuration.java new file mode 100644 index 000000000..e884ff055 --- /dev/null +++ b/src/main/java/com/blade/ioc/annotation/Configuration.java @@ -0,0 +1,15 @@ +package com.blade.ioc.annotation; + +import java.lang.annotation.*; + +/** + * @author zhangx + * @since 2.0.15 + **/ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Configuration { + + String name() default ""; +} diff --git a/src/main/java/com/blade/server/netty/NettyServer.java b/src/main/java/com/blade/server/netty/NettyServer.java index 662d9e0cd..aea3736bc 100644 --- a/src/main/java/com/blade/server/netty/NettyServer.java +++ b/src/main/java/com/blade/server/netty/NettyServer.java @@ -23,6 +23,7 @@ import com.blade.ioc.DynamicContext; import com.blade.ioc.Ioc; import com.blade.ioc.annotation.Bean; +import com.blade.ioc.annotation.Configuration; import com.blade.ioc.annotation.Value; import com.blade.ioc.bean.BeanDefine; import com.blade.ioc.bean.ClassInfo; @@ -70,6 +71,7 @@ import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -301,7 +303,18 @@ private void parseAndCreate(Class clazz) { Object controller = blade.getBean(clazz); routeBuilder.addRouter(clazz, controller); } - + if (null != clazz.getAnnotation(Configuration.class) && clazz.getMethods().length > 0) { + Object config = ReflectKit.newInstance(clazz); + Arrays.stream(clazz.getMethods()) + .filter(m -> m.getAnnotation(Bean.class) != null) + .forEach(n -> { + try { + blade.register(n.invoke(config)); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } if (ReflectKit.hasInterface(clazz, WebHook.class) && null != clazz.getAnnotation(Bean.class)) { URLPattern URLPattern = clazz.getAnnotation(URLPattern.class); if (null == URLPattern) { From 70ecb9a3d349438c3ae89c5fca8bdd29b3a6b8a4 Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 10 May 2019 09:35:09 +0800 Subject: [PATCH 10/11] Auto lookup call class --- src/main/java/com/blade/Blade.java | 11 ++- .../java/com/blade/kit/UncheckedFnKit.java | 90 +++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/blade/kit/UncheckedFnKit.java diff --git a/src/main/java/com/blade/Blade.java b/src/main/java/com/blade/Blade.java index 11f6ad4e9..1dea071a4 100644 --- a/src/main/java/com/blade/Blade.java +++ b/src/main/java/com/blade/Blade.java @@ -24,6 +24,7 @@ import com.blade.kit.BladeKit; import com.blade.kit.JsonKit; import com.blade.kit.StringKit; +import com.blade.kit.UncheckedFnKit; import com.blade.kit.reload.FileChangeDetector; import com.blade.loader.BladeLoader; import com.blade.mvc.handler.*; @@ -832,8 +833,14 @@ public Blade watchEnvChange(boolean watchEnvChange) { * * @return return blade instance */ - public Blade start() { - return this.start(null, null); + public Blade start(String... args) { + Class caller = Arrays.stream(Thread.currentThread().getStackTrace()) + .filter(st -> "main".equals(st.getMethodName())) + .findFirst() + .map(StackTraceElement::getClassName) + .map(UncheckedFnKit.function(Class::forName)) + .orElse(null); + return this.start(caller, args); } /** diff --git a/src/main/java/com/blade/kit/UncheckedFnKit.java b/src/main/java/com/blade/kit/UncheckedFnKit.java new file mode 100644 index 000000000..4cf1dd079 --- /dev/null +++ b/src/main/java/com/blade/kit/UncheckedFnKit.java @@ -0,0 +1,90 @@ +package com.blade.kit; + +import com.blade.exception.BladeException; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * @author darren + * @date 2019/3/18 11:47 + */ +public class UncheckedFnKit { + + @FunctionalInterface + public interface Consumer_WithExceptions { + void accept(T t) throws E; + } + + @FunctionalInterface + public interface BiConsumer_WithExceptions { + void accept(T t, U u) throws E; + } + + @FunctionalInterface + public interface Function_WithExceptions { + R apply(T t) throws E; + } + + @FunctionalInterface + public interface Supplier_WithExceptions { + T get() throws E; + } + + @FunctionalInterface + public interface Runnable_WithExceptions { + void run() throws E; + } + + public static Consumer consumer(Consumer_WithExceptions consumer) { + return t -> { + try { + consumer.accept(t); + } catch (Throwable throwable) { + throw new BladeException(throwable); + } + }; + } + + public static BiConsumer biConsumer(BiConsumer_WithExceptions biConsumer) { + return (t, u) -> { + try { + biConsumer.accept(t, u); + } catch (Throwable throwable) { + throw new BladeException(throwable); + } + }; + } + + public static Function function(Function_WithExceptions function) { + return t -> { + try { + return function.apply(t); + } catch (Throwable throwable) { + throw new BladeException(throwable); + } + }; + } + + public static Supplier supplier(Supplier_WithExceptions function) { + return () -> { + try { + return function.get(); + } catch (Throwable throwable) { + throw new BladeException(throwable); + } + }; + } + + public static Runnable runnable(Runnable_WithExceptions t) { + return ()-> { + try { + t.run(); + } catch (Throwable throwable) { + throw new BladeException(throwable); + } + }; + } +} From 4af9cd9622044c6b97af4e92a53ce39534631cce Mon Sep 17 00:00:00 2001 From: biezhi Date: Thu, 26 Sep 2019 11:27:23 +0800 Subject: [PATCH 11/11] :bookmark: release 2.0.15.BETA --- README.md | 4 ++-- README_CN.md | 4 ++-- pom.xml | 2 +- src/main/java/com/blade/mvc/Const.java | 2 +- src/main/java/com/blade/mvc/RouteContext.java | 18 ------------------ 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d82604e88..efcfd2bc8 100644 --- a/README.md +++ b/README.md @@ -65,14 +65,14 @@ Run with `Maven`: com.bladejava blade-mvc - 2.0.15.ALPHA + 2.0.15.BETA ``` or `Gradle`: ```sh -compile 'com.bladejava:blade-mvc:2.0.15.ALPHA' +compile 'com.bladejava:blade-mvc:2.0.15.BETA' ``` Write the `main` method and the `Hello World`: diff --git a/README_CN.md b/README_CN.md index c694aee3e..e90fd8b86 100644 --- a/README_CN.md +++ b/README_CN.md @@ -61,7 +61,7 @@ com.bladejava blade-mvc - 2.0.15.ALPHA + 2.0.15.BETA ``` @@ -70,7 +70,7 @@ ζˆ–θ€… `Gradle`: ```sh -compile 'com.bladejava:blade-mvc:2.0.15.ALPHA' +compile 'com.bladejava:blade-mvc:2.0.15.BETA' ``` 编写 `main` 函数写一δΈͺ `Hello World`: diff --git a/pom.xml b/pom.xml index 989976ccb..9ba7ad0d9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bladejava blade-mvc - 2.0.15.ALPHA + 2.0.15.BETA jar blade diff --git a/src/main/java/com/blade/mvc/Const.java b/src/main/java/com/blade/mvc/Const.java index df2c118dd..a18ce3f21 100644 --- a/src/main/java/com/blade/mvc/Const.java +++ b/src/main/java/com/blade/mvc/Const.java @@ -31,7 +31,7 @@ public interface Const { int DEFAULT_SERVER_PORT = 9000; String DEFAULT_SERVER_ADDRESS = "0.0.0.0"; String LOCAL_IP_ADDRESS = "127.0.0.1"; - String VERSION = "2.0.15.ALPHA"; + String VERSION = "2.0.15.BETA"; String WEB_JARS = "/webjars/"; String CLASSPATH = BladeKit.getCurrentClassPath(); String CONTENT_TYPE_HTML = "text/html; charset=UTF-8"; diff --git a/src/main/java/com/blade/mvc/RouteContext.java b/src/main/java/com/blade/mvc/RouteContext.java index f4195a682..c2b99f8e8 100644 --- a/src/main/java/com/blade/mvc/RouteContext.java +++ b/src/main/java/com/blade/mvc/RouteContext.java @@ -577,24 +577,6 @@ public boolean isAbort() { public void initRoute(Route route) { this.request.initPathParams(route); this.route = route; -// if (null != route.getTarget() && route.getTargetType().equals(RouteHandler.class)) { -// return; -// } -// boolean singleton = IocKit.isSingleton(route.getTargetType()); -// -// if (singleton) { -// BeanDefine beanDefine = WebContext.blade().ioc().getBeanDefine(route.getTargetType()); -// if (beanDefine.isFieldHasPrototype()) { -// // reset initialize -// IocKit.injection(WebContext.blade().ioc(), beanDefine); -// } else { -// Object target = WebContext.blade().ioc().getBean(route.getTargetType()); -// this.route.setTarget(target); -// } -// } else { -// Object target = WebContext.blade().ioc().createBean(route.getTargetType()); -// this.route.setTarget(target); -// } } public void injectParameters() {