29 changed files with 296 additions and 161 deletions
@ -0,0 +1,19 @@ |
|||
/** |
|||
* 设置打包文件的运行时目标环境(target) |
|||
* 设置方式: 通过命令行 -D 传入目标环境参数 |
|||
* 打包命令如下: |
|||
* 1. gradle bootwar # 默认, target=tomcat |
|||
* 2. gradle bootwar -Dtarget=undertow # undertow, target=undertow |
|||
* 3. gradle bootwar -Dtarget=jetty # jetty, target=jetty |
|||
*/ |
|||
def target =System.getProperty("target") ?: "undertow"; |
|||
System.setProperty('target',target); |
|||
|
|||
// 根据 targetRuntime 变量的值执行实际的 build.gradle |
|||
apply from: "build-${target}.gradle" |
|||
|
|||
// 应用启动项目无需发布到仓库中 |
|||
publishPublicationPublicationToMavenRepository.enabled=false |
|||
|
|||
// 开启 docker 镜像生成任务 |
|||
jibBuildTar.enabled =true |
@ -0,0 +1,15 @@ |
|||
println "[Jetty] 环境 ......" |
|||
|
|||
configurations { |
|||
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-core" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-websocket" |
|||
} |
|||
|
|||
dependencies { |
|||
implementation("org.springframework.boot:spring-boot-starter-jetty") |
|||
|
|||
providedRuntime( |
|||
"org.springframework.boot:spring-boot-starter-jetty", |
|||
) |
|||
} |
@ -0,0 +1,7 @@ |
|||
println "[Tomcat] 环境 ......" |
|||
|
|||
dependencies { |
|||
providedRuntime( |
|||
"org.springframework.boot:spring-boot-starter-tomcat", |
|||
) |
|||
} |
@ -0,0 +1,15 @@ |
|||
println "[Undertow] 环境 ......" |
|||
|
|||
configurations { |
|||
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-core" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-websocket" |
|||
} |
|||
|
|||
dependencies { |
|||
implementation("org.springframework.boot:spring-boot-starter-undertow") |
|||
|
|||
providedRuntime( |
|||
"org.springframework.boot:spring-boot-starter-undertow", |
|||
) |
|||
} |
@ -0,0 +1,99 @@ |
|||
apply plugin: 'war' |
|||
apply plugin: 'com.google.cloud.tools.jib' |
|||
|
|||
apply from: "build-common.gradle" |
|||
|
|||
dependencies { |
|||
implementation("org.springframework.boot:spring-boot-starter-web"){ |
|||
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" |
|||
} |
|||
} |
|||
|
|||
dependencies { |
|||
implementation ( |
|||
project(":io.sc.platform.scheduler.executor"), |
|||
) |
|||
} |
|||
|
|||
/** |
|||
* replace [application.version] in i18n message file |
|||
*/ |
|||
processResources { |
|||
filesMatching('**/messages*.properties') { |
|||
println 'replace ${version} in [' + it + ']' |
|||
filteringCharset = 'iso8859-1' |
|||
filter(org.apache.tools.ant.filters.ReplaceTokens, beginToken: '$version', endToken: '',tokens: [version: '' + project.version]) |
|||
} |
|||
|
|||
doLast{ |
|||
// 为了能够兼容 eclipse 和 idea 两种开发环境,调整如下: |
|||
// 1. 将 environment.properties 文件放在了 src/main/resources 目录中 |
|||
// 2. 在打包时,将该文件删除 |
|||
delete "$buildDir/resources/main/running-mode.properties" |
|||
} |
|||
|
|||
} |
|||
|
|||
bootWar{ |
|||
mainClass = "${project.name}.Application" |
|||
//launchScript() |
|||
manifest { |
|||
attributes 'Implementation-Version': archiveVersion, |
|||
'Implementation-Title': project.name |
|||
} |
|||
} |
|||
|
|||
bootJar{ |
|||
mainClass = "${project.name}.Application" |
|||
//launchScript() |
|||
manifest { |
|||
attributes 'Implementation-Version': archiveVersion, |
|||
'Implementation-Title': project.name |
|||
} |
|||
} |
|||
|
|||
|
|||
jib { |
|||
outputPaths { |
|||
tar = "build/libs/${project.name}-${project.version}-image.tar" |
|||
} |
|||
from { |
|||
image = "openjdk:8u342-slim" |
|||
//image = "eclipse-temurin:8u382-b05-jdk-focal" |
|||
platforms { |
|||
platform { |
|||
architecture ="arm64" |
|||
os ="linux" |
|||
} |
|||
} |
|||
} |
|||
to { |
|||
image = "${project.name}:${project.version}" |
|||
} |
|||
extraDirectories { |
|||
paths { |
|||
path { |
|||
from = "build/libs/" |
|||
into = "/opt/${project.name}/" |
|||
includes = ["${project.name}-${project.version}.war"] |
|||
} |
|||
} |
|||
} |
|||
container { |
|||
/** |
|||
* 设置jvm的启动参数 |
|||
* user.timezone - 解决Java程序的时区问题 |
|||
*/ |
|||
jvmFlags = ["-Duser.timezone=Asia/Shanghai"] |
|||
creationTime = "USE_CURRENT_TIMESTAMP" |
|||
ports = ["8080"] |
|||
entrypoint = [ |
|||
"java", |
|||
"-jar", |
|||
"/opt/" + project.name + "/" + project.name + "-" + project.version + ".war", |
|||
"--" + project.name + ".home.dir=" + "/opt/" + project.name |
|||
] |
|||
//entrypoint = "java -version" |
|||
//appRoot = "/usr/local/tomcat/webapps/ROOT" |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
// 在浏览器 window 对象中新建名为 APP 的容器变量, 用于存放平台的全局变量
|
|||
window.APP = {}; |
|||
// 全局配置
|
|||
window.APP.configure ={ |
|||
// 应用上下文路径
|
|||
webContextPath: '[(@{/})]'.startsWith('[')? '/' : '[(@{/})]', |
|||
// 默认后端 API 请求的服务地址前缀
|
|||
apiContextPaths: { |
|||
DEFAULT: '[(@{/})]'.startsWith('[') ? 'http://localhost:8080/' : '[(@{/})]' |
|||
} |
|||
}; |
@ -0,0 +1,19 @@ |
|||
/** |
|||
* 设置打包文件的运行时目标环境(target) |
|||
* 设置方式: 通过命令行 -D 传入目标环境参数 |
|||
* 打包命令如下: |
|||
* 1. gradle bootwar # 默认, target=tomcat |
|||
* 2. gradle bootwar -Dtarget=undertow # undertow, target=undertow |
|||
* 3. gradle bootwar -Dtarget=jetty # jetty, target=jetty |
|||
*/ |
|||
def target =System.getProperty("target") ?: "undertow"; |
|||
System.setProperty('target',target); |
|||
|
|||
// 根据 targetRuntime 变量的值执行实际的 build.gradle |
|||
apply from: "build-${target}.gradle" |
|||
|
|||
// 应用启动项目无需发布到仓库中 |
|||
publishPublicationPublicationToMavenRepository.enabled=false |
|||
|
|||
// 开启 docker 镜像生成任务 |
|||
jibBuildTar.enabled =true |
@ -0,0 +1,15 @@ |
|||
println "[Jetty] 环境 ......" |
|||
|
|||
configurations { |
|||
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-core" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-websocket" |
|||
} |
|||
|
|||
dependencies { |
|||
implementation("org.springframework.boot:spring-boot-starter-jetty") |
|||
|
|||
providedRuntime( |
|||
"org.springframework.boot:spring-boot-starter-jetty", |
|||
) |
|||
} |
@ -0,0 +1,7 @@ |
|||
println "[Tomcat] 环境 ......" |
|||
|
|||
dependencies { |
|||
providedRuntime( |
|||
"org.springframework.boot:spring-boot-starter-tomcat", |
|||
) |
|||
} |
@ -0,0 +1,15 @@ |
|||
println "[Undertow] 环境 ......" |
|||
|
|||
configurations { |
|||
all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-core" |
|||
all*.exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-websocket" |
|||
} |
|||
|
|||
dependencies { |
|||
implementation("org.springframework.boot:spring-boot-starter-undertow") |
|||
|
|||
providedRuntime( |
|||
"org.springframework.boot:spring-boot-starter-undertow", |
|||
) |
|||
} |
@ -0,0 +1,11 @@ |
|||
// 在浏览器 window 对象中新建名为 APP 的容器变量, 用于存放平台的全局变量
|
|||
window.APP = {}; |
|||
// 全局配置
|
|||
window.APP.configure ={ |
|||
// 应用上下文路径
|
|||
webContextPath: '[(@{/})]'.startsWith('[')? '/' : '[(@{/})]', |
|||
// 默认后端 API 请求的服务地址前缀
|
|||
apiContextPaths: { |
|||
DEFAULT: '[(@{/})]'.startsWith('[') ? 'http://localhost:8080/' : '[(@{/})]' |
|||
} |
|||
}; |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,156 +0,0 @@ |
|||
package io.sc.platform.scheduler.executor.util; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
import java.text.DateFormat; |
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Calendar; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* date util |
|||
* |
|||
* @author xuxueli 2018-08-19 01:24:11 |
|||
*/ |
|||
public class DateUtil { |
|||
|
|||
// ---------------------- format parse ----------------------
|
|||
private static Logger logger = LoggerFactory.getLogger(DateUtil.class); |
|||
|
|||
private static final String DATE_FORMAT = "yyyy-MM-dd"; |
|||
private static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
|||
|
|||
private static final ThreadLocal<Map<String, DateFormat>> dateFormatThreadLocal = new ThreadLocal<Map<String, DateFormat>>(); |
|||
private static DateFormat getDateFormat(String pattern) { |
|||
if (pattern==null || pattern.trim().length()==0) { |
|||
throw new IllegalArgumentException("pattern cannot be empty."); |
|||
} |
|||
|
|||
Map<String, DateFormat> dateFormatMap = dateFormatThreadLocal.get(); |
|||
if(dateFormatMap!=null && dateFormatMap.containsKey(pattern)){ |
|||
return dateFormatMap.get(pattern); |
|||
} |
|||
|
|||
synchronized (dateFormatThreadLocal) { |
|||
if (dateFormatMap == null) { |
|||
dateFormatMap = new HashMap<String, DateFormat>(); |
|||
} |
|||
dateFormatMap.put(pattern, new SimpleDateFormat(pattern)); |
|||
dateFormatThreadLocal.set(dateFormatMap); |
|||
} |
|||
|
|||
return dateFormatMap.get(pattern); |
|||
} |
|||
|
|||
/** |
|||
* format datetime. like "yyyy-MM-dd" |
|||
* |
|||
* @param date |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static String formatDate(Date date) { |
|||
return format(date, DATE_FORMAT); |
|||
} |
|||
|
|||
/** |
|||
* format date. like "yyyy-MM-dd HH:mm:ss" |
|||
* |
|||
* @param date |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static String formatDateTime(Date date) { |
|||
return format(date, DATETIME_FORMAT); |
|||
} |
|||
|
|||
/** |
|||
* format date |
|||
* |
|||
* @param date |
|||
* @param patten |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static String format(Date date, String patten) { |
|||
return getDateFormat(patten).format(date); |
|||
} |
|||
|
|||
/** |
|||
* parse date string, like "yyyy-MM-dd HH:mm:s" |
|||
* |
|||
* @param dateString |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date parseDate(String dateString){ |
|||
return parse(dateString, DATE_FORMAT); |
|||
} |
|||
|
|||
/** |
|||
* parse datetime string, like "yyyy-MM-dd HH:mm:ss" |
|||
* |
|||
* @param dateString |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date parseDateTime(String dateString) { |
|||
return parse(dateString, DATETIME_FORMAT); |
|||
} |
|||
|
|||
/** |
|||
* parse date |
|||
* |
|||
* @param dateString |
|||
* @param pattern |
|||
* @return |
|||
* @throws ParseException |
|||
*/ |
|||
public static Date parse(String dateString, String pattern) { |
|||
try { |
|||
Date date = getDateFormat(pattern).parse(dateString); |
|||
return date; |
|||
} catch (Exception e) { |
|||
logger.warn("parse date error, dateString = {}, pattern={}; errorMsg = {}", dateString, pattern, e.getMessage()); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
|
|||
// ---------------------- add date ----------------------
|
|||
|
|||
public static Date addYears(final Date date, final int amount) { |
|||
return add(date, Calendar.YEAR, amount); |
|||
} |
|||
|
|||
public static Date addMonths(final Date date, final int amount) { |
|||
return add(date, Calendar.MONTH, amount); |
|||
} |
|||
|
|||
public static Date addDays(final Date date, final int amount) { |
|||
return add(date, Calendar.DAY_OF_MONTH, amount); |
|||
} |
|||
|
|||
public static Date addHours(final Date date, final int amount) { |
|||
return add(date, Calendar.HOUR_OF_DAY, amount); |
|||
} |
|||
|
|||
public static Date addMinutes(final Date date, final int amount) { |
|||
return add(date, Calendar.MINUTE, amount); |
|||
} |
|||
|
|||
private static Date add(final Date date, final int calendarField, final int amount) { |
|||
if (date == null) { |
|||
return null; |
|||
} |
|||
final Calendar c = Calendar.getInstance(); |
|||
c.setTime(date); |
|||
c.add(calendarField, amount); |
|||
return c.getTime(); |
|||
} |
|||
|
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue