Skip to content

Commit

Permalink
Merge pull request #251 from lets-blade/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
hellokaton authored Jun 16, 2018
2 parents 2a0dd9f + 781e30e commit 02ddc58
Show file tree
Hide file tree
Showing 48 changed files with 2,462 additions and 955 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ If you think this item is good can [star](https://github.com/biezhi/blade/starga
* [x] High performance, 100 concurrent qps 14w/s
* [x] Run the `JAR` package to open the web service
* [x] Streaming API style
* [x] `CSRF` and `XSS` defense
* [x] `Basic Auth` and `Authorization`
* [x] Supports plug-in extensions
* [x] Support webjars resources
* [x] Based on `cron` expression of tasks
Expand All @@ -62,7 +64,7 @@ Create a basic `Maven` project
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.8-R3</version>
<version>2.0.8.RELEASE</version>
</dependency>
```

Expand All @@ -71,7 +73,7 @@ Create a basic `Maven` project
or `Gradle`:

```sh
compile 'com.bladejava:blade-mvc:2.0.8-R3'
compile 'com.bladejava:blade-mvc:2.0.8.RELEASE'
```

Write `main` method, try `Hello World`
Expand Down
6 changes: 4 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* [x] 模板引擎支持,视图开发更灵活
* [x] 高性能,100并发下qps 14w/s
* [x] 运行 `JAR` 包即可开启 web 服务
* [x] 支持 `CSRF``XSS` 防御
* [x] 支持 `BasicAuth` 和权限管理
* [x] 流式API风格
* [x] 支持插件扩展
* [x] 支持 webjars 资源
Expand All @@ -61,7 +63,7 @@
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.8-R3</version>
<version>2.0.8.RELEASE</version>
</dependency>
```

Expand All @@ -70,7 +72,7 @@
或者 `Gradle`:

```sh
compile 'com.bladejava:blade-mvc:2.0.8-R3'
compile 'com.bladejava:blade-mvc:2.0.8.RELEASE'
```

编写 `main` 函数写一个 `Hello World`
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'eclipse'
apply plugin: 'idea'

group = 'com.bladejava'
version = '2.0.8-R1'
version = '2.0.8-RELEASE'

description = 'blade-mvc'

Expand All @@ -20,7 +20,7 @@ tasks.withType(JavaCompile) {
}

def bladeAsmVersion = '0.0.1'
def bladeLogVersion = '0.1.3'
def bladeLogVersion = '0.1.5'
def junitVersion = '4.12'
def slf4jApiVersion = '1.7.21'
def nettyVersion = '4.1.25.Final'
Expand Down
168 changes: 84 additions & 84 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
7 changes: 3 additions & 4 deletions 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.8-R3</version>
<version>2.0.8.RELEASE</version>
<packaging>jar</packaging>

<name>blade</name>
Expand Down Expand Up @@ -37,8 +37,8 @@
<junit.version>4.12</junit.version>
<slf4j-api.version>1.7.25</slf4j-api.version>
<netty.version>4.1.25.Final</netty.version>
<blade-asm.version>0.0.1</blade-asm.version>
<blade-log.version>0.1.4</blade-log.version>
<blade-asm.version>0.0.2-SNAPSHOT</blade-asm.version>
<blade-log.version>0.1.5</blade-log.version>
<gson.version>2.8.5</gson.version>
<bootstrap.version>4.1.0</bootstrap.version>
<mockito.version>1.10.19</mockito.version>
Expand All @@ -52,7 +52,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down
32 changes: 22 additions & 10 deletions src/main/java/com/blade/Blade.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ public Blade devMode(boolean devMode) {
return this;
}

public boolean isAutoRefreshDir(){
return environment.get(ENV_KEY_AUTO_REFRESH_DIR).isPresent();
public boolean isAutoRefreshDir() {
return environment.get(ENV_KEY_AUTO_REFRESH_DIR).isPresent();
}

public void setAutoRefreshDir(String dir){
public void setAutoRefreshDir(String dir) {
environment.set(ENV_KEY_AUTO_REFRESH_DIR, dir);
}

Expand Down Expand Up @@ -649,7 +649,7 @@ public Blade disableSession() {
return this;
}

public Blade watchEnvChange(boolean watchEnvChange){
public Blade watchEnvChange(boolean watchEnvChange) {
this.environment.set(ENV_KEY_APP_WATCH_ENV, watchEnvChange);
return this;
}
Expand Down Expand Up @@ -711,29 +711,29 @@ public Blade start(Class<?> bootClass, @NonNull String address, int port, String
thread.start();
started = true;

Thread resourceFilesRefreshThread = new Thread(()-> {
Thread resourceFilesRefreshThread = new Thread(() -> {

try {
FileChangeDetector fileChangeDetector = new FileChangeDetector(environment.get(ENV_KEY_AUTO_REFRESH_DIR).get());
fileChangeDetector.processEvent( (event , filePath) ->{
fileChangeDetector.processEvent((event, filePath) -> {
try {
//TODO: add support for Create and Delete
if(event.equals(StandardWatchEventKinds.ENTRY_MODIFY)) {
if (event.equals(StandardWatchEventKinds.ENTRY_MODIFY)) {
Path destPath = FileChangeDetector.getDestPath(filePath, environment);
Files.copy(filePath, destPath, StandardCopyOption.REPLACE_EXISTING);
}
}catch (IOException e){
} catch (IOException e) {
log.error("Exception when trying to copy updated file");
startupExceptionHandler.accept(e);
}
});
}catch (IOException e){
} catch (IOException e) {
startupExceptionHandler.accept(e);
}

});

if (devMode() && isAutoRefreshDir()){
if (devMode() && isAutoRefreshDir()) {
log.info("auto refresh is enabled");
resourceFilesRefreshThread.start();
}
Expand Down Expand Up @@ -840,6 +840,18 @@ public Blade threadName(String threadName) {
return this;
}

/**
* Set context path, default is "/"
*
* @param contextPath context path
* @return return blade instance
* @since 2.0.8-RELEASE
*/
public Blade contextPath(String contextPath) {
environment.set(ENV_KEY_CONTEXT_PATH, contextPath);
return this;
}

/**
* Get WebSocket Handler
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/blade/exception/ValidatorException.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
public class ValidatorException extends RuntimeException {

@Getter
private String code;
private Integer code;

public ValidatorException(String code, String message) {
public ValidatorException(Integer code, String message) {
super(message);
this.code = code;
}
Expand Down
Loading

0 comments on commit 02ddc58

Please sign in to comment.