Skip to content

Commit

Permalink
Merge pull request #376 from lets-blade/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hellokaton authored Sep 26, 2019
2 parents d32a3ea + 4af9cd9 commit dfb5817
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 57 deletions.
20 changes: 12 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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.
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation_issue.md
Original file line number Diff line number Diff line change
@@ -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!
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/general_question.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: General question
name: 🍻 General Question
about: Template for asking question

---
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ Run with `Maven`:
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.15.ALPHA</version>
<version>2.0.15.BETA</version>
</dependency>
```

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`:
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.15.ALPHA</version>
<version>2.0.15.BETA</version>
</dependency>
```

Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.15.ALPHA</version>
<version>2.0.15.BETA</version>
<packaging>jar</packaging>

<name>blade</name>
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/blade/Blade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/blade/ioc/annotation/Bean.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author <a href="mailto:[email protected]" target="_blank">biezhi</a>
* @since 1.5
*/
@Target(ElementType.TYPE)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Bean {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/blade/ioc/annotation/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.blade.ioc.annotation;

import java.lang.annotation.*;

/**
* @author <a href="mailto:[email protected]" target="_blank">zhangx</a>
* @since 2.0.15
**/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Configuration {

String name() default "";
}
2 changes: 2 additions & 0 deletions src/main/java/com/blade/kit/ReflectKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/com/blade/kit/UncheckedFnKit.java
Original file line number Diff line number Diff line change
@@ -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<T, E extends Throwable> {
void accept(T t) throws E;
}

@FunctionalInterface
public interface BiConsumer_WithExceptions<T, U, E extends Throwable> {
void accept(T t, U u) throws E;
}

@FunctionalInterface
public interface Function_WithExceptions<T, R, E extends Throwable> {
R apply(T t) throws E;
}

@FunctionalInterface
public interface Supplier_WithExceptions<T, E extends Throwable> {
T get() throws E;
}

@FunctionalInterface
public interface Runnable_WithExceptions<E extends Throwable> {
void run() throws E;
}

public static <T> Consumer<T> consumer(Consumer_WithExceptions<T, Throwable> consumer) {
return t -> {
try {
consumer.accept(t);
} catch (Throwable throwable) {
throw new BladeException(throwable);
}
};
}

public static <T, U> BiConsumer<T, U> biConsumer(BiConsumer_WithExceptions<T, U, Throwable> biConsumer) {
return (t, u) -> {
try {
biConsumer.accept(t, u);
} catch (Throwable throwable) {
throw new BladeException(throwable);
}
};
}

public static <T, R> Function<T, R> function(Function_WithExceptions<T, R, Throwable> function) {
return t -> {
try {
return function.apply(t);
} catch (Throwable throwable) {
throw new BladeException(throwable);
}
};
}

public static <T> Supplier<T> supplier(Supplier_WithExceptions<T, Throwable> 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);
}
};
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/blade/kit/json/BeanSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,8 +46,9 @@ public static Object serialize(SerializeMapping serializeMapping, Object bean) t
}

if (bean instanceof Map) {
Map map = (Map) bean;
map.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) {
Expand Down Expand Up @@ -337,6 +342,8 @@ public static <T> T deserialize(Class<T> klass, Object object) {
}
if (ReflectKit.isBasicType(object)) {
return (T) ReflectKit.convert(klass, object.toString());
} else if (klass.isEnum()){
return (T) Enum.valueOf((Class<? extends Enum>) klass,object.toString());
} else if (object instanceof Map) {
if (Map.class.isAssignableFrom(klass)) {
return klass.cast(object);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/blade/mvc/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/blade/mvc/RouteContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/blade/mvc/route/RouteMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit dfb5817

Please sign in to comment.