39 changed files with 370 additions and 85 deletions
@ -1,3 +1,3 @@ |
|||
application.title=Risk Manager Platform |
|||
application.version=$version |
|||
application.version=@version@ |
|||
application.copyright=Copyright \u00A9 2019\u20132022 |
@ -1,3 +1,3 @@ |
|||
application.title=\u98A8\u96AA\u7BA1\u7406\u5E73\u53F0 |
|||
application.version=$version |
|||
application.version=@version@ |
|||
application.copyright=Copyright \u00A9 2019\u20132022 |
@ -1,3 +1,3 @@ |
|||
application.title=\u98CE\u9669\u7BA1\u7406\u5E73\u53F0 |
|||
application.version=$version |
|||
application.version=@version@ |
|||
application.copyright=Copyright \u00A9 2019\u20132022 |
@ -1,10 +1,10 @@ |
|||
package io.sc.engine.rule.client.spring.service; |
|||
|
|||
import io.sc.engine.rule.client.Loader; |
|||
import io.sc.engine.rule.core.client.Loader; |
|||
|
|||
/** |
|||
* 本地资源定义加载器接口 |
|||
*/ |
|||
public interface LocalLoader extends Loader{ |
|||
public interface LocalLoader extends Loader { |
|||
|
|||
} |
|||
|
@ -1,6 +1,117 @@ |
|||
dependencies { |
|||
api( |
|||
project(":io.sc.engine.rule.core"), |
|||
project(":io.sc.platform.util"), |
|||
project(":io.sc.platform.groovy"), |
|||
) |
|||
} |
|||
|
|||
/** |
|||
* 拷贝依赖工程生成的 jar 包 |
|||
* 1. io.sc.engine.rule.core-xxx.jar |
|||
* 2. io.sc.platform.util-xxx.jar |
|||
*/ |
|||
tasks.register('copyDependenciesProjectJars') { |
|||
dependsOn ':io.sc.engine.rule.core:jar',':io.sc.platform.util:jar',':io.sc.creditreport.core:jar',':io.sc.engine.rule.client.spring:jar' |
|||
doLast { |
|||
println('copy dependencies project jar ......'); |
|||
def targetDir =file('src/main/resources/io/sc/engine/rule/client/jars/').absolutePath; |
|||
delete targetDir; |
|||
file(targetDir).mkdirs(); |
|||
project.getRootProject().subprojects { dependedProject -> |
|||
if( dependedProject.name=='io.sc.engine.rule.core' |
|||
|| dependedProject.name=='io.sc.platform.util' |
|||
|| dependedProject.name=='io.sc.creditreport.core' |
|||
|| dependedProject.name=='io.sc.engine.rule.client.spring' |
|||
){ |
|||
def dir =dependedProject.getBuildDir().absolutePath + '/libs'; |
|||
def source =dir + '/' + dependedProject.name + '-' + dependedProject.version + '.jar'; |
|||
if(file(source).exists() && file(source).isFile()){ |
|||
copy { |
|||
from dir + '/' + dependedProject.name + '-' + dependedProject.version + '.jar' |
|||
into targetDir |
|||
} |
|||
}else{ |
|||
println('>>>>>>>>'); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 拷贝依赖第三方 jar 包 |
|||
*/ |
|||
tasks.register('copyRuntimeClasspathJars') { |
|||
dependsOn 'copyDependenciesProjectJars' |
|||
doLast { |
|||
configurations.runtimeClasspath.each(r ->{ |
|||
println r |
|||
}); |
|||
println('copy runtimeClasspath jar ......'); |
|||
copy { |
|||
from configurations.runtimeClasspath |
|||
into 'src/main/resources/io/sc/engine/rule/client/jars' |
|||
include( |
|||
'jackson-annotations-*.jar', |
|||
'jackson-core-*.jar', |
|||
'jackson-databind-*.jar', |
|||
'slf4j-api-*.jar', |
|||
'jaxb-api-*.jar' |
|||
) |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 替换可导出资源插件文件, 更新版本 |
|||
*/ |
|||
tasks.register('replaceExportableResourcesPlugins') { |
|||
dependsOn 'copyRuntimeClasspathJars' |
|||
doLast { |
|||
println('replace exportable-resources.json ......'); |
|||
File file =file('src/main/resources/META-INF/platform/plugins/exportable-resources.json'); |
|||
String content =file.text; |
|||
// replace io.sc.engine.rule.core-xx.xx.xx.jar |
|||
java.util.regex.Pattern corePattern =java.util.regex.Pattern.compile('io\\.sc\\.engine\\.rule\\.core-(.*)?\\.jar'); |
|||
java.util.regex.Matcher coreMatcher = corePattern.matcher(content); |
|||
while (coreMatcher.find()) { |
|||
content =content.replace(coreMatcher.group(0),"io.sc.engine.rule.core-" + project.version + ".jar"); |
|||
} |
|||
// replace io.sc.platform.util-xx.xx.xx.jar |
|||
java.util.regex.Pattern utilPattern =java.util.regex.Pattern.compile('io\\.sc\\.platform\\.util-(.*)?\\.jar'); |
|||
java.util.regex.Matcher utilMatcher = utilPattern.matcher(content); |
|||
while (utilMatcher.find()) { |
|||
content =content.replace(utilMatcher.group(0),"io.sc.platform.util-" + project.version + ".jar"); |
|||
} |
|||
|
|||
// replace io.sc.creditreport.core-xx.xx.xx.jar |
|||
java.util.regex.Pattern creditreportPattern =java.util.regex.Pattern.compile('io\\.sc\\.creditreport\\.core-(.*)?\\.jar'); |
|||
java.util.regex.Matcher creditreportMatcher = creditreportPattern.matcher(content); |
|||
while (creditreportMatcher.find()) { |
|||
content =content.replace(creditreportMatcher.group(0),"io.sc.creditreport.core-" + project.version + ".jar"); |
|||
} |
|||
|
|||
// replace io.sc.engine.rule.client.spring-xx.xx.xx.jar |
|||
java.util.regex.Pattern clientSpringPattern =java.util.regex.Pattern.compile('io\\.sc\\.engine\\.rule\\.client\\.spring-(.*)?\\.jar'); |
|||
java.util.regex.Matcher clientSpringMatcher = clientSpringPattern.matcher(content); |
|||
while (clientSpringMatcher.find()) { |
|||
content =content.replace(clientSpringMatcher.group(0),"io.sc.engine.rule.client.spring-" + project.version + ".jar"); |
|||
} |
|||
|
|||
file.write(content); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 同步项目, |
|||
*/ |
|||
tasks.register('sync') { |
|||
dependsOn 'replaceExportableResourcesPlugins' |
|||
} |
|||
|
|||
processResources { |
|||
dependsOn sync |
|||
} |
|||
|
|||
|
|||
|
@ -1,3 +1,4 @@ |
|||
[ |
|||
{"name":"dir.engine.rule.compiler","path":"/work/engine/rule/compiler","autoCreate":true} |
|||
{"name":"dir.engine.rule.compiler","path":"/work/engine/rule/compiler","autoCreate":true}, |
|||
{"name":"dir.engine.rule.classpath","path":"/work/engine/rule/jars","autoCreate":true, "deleteFirst":true} |
|||
] |
|||
|
@ -0,0 +1,66 @@ |
|||
[ |
|||
{ |
|||
"type" :"file", |
|||
"name" :"jackson-annotations-2.13.5.jar", |
|||
"description" :"jackson-annotations-2.13.5.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/jackson-annotations-2.13.5.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/jackson-annotations-2.13.5.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"jackson-core-2.13.5.jar", |
|||
"description" :"jackson-core-2.13.5.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/jackson-core-2.13.5.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/jackson-core-2.13.5.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"jackson-databind-2.13.5.jar", |
|||
"description" :"jackson-databind-2.13.5.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/jackson-databind-2.13.5.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/jackson-databind-2.13.5.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"slf4j-api-1.7.36.jar", |
|||
"description" :"slf4j-api-1.7.36.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/slf4j-api-1.7.36.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/slf4j-api-1.7.36.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"io.sc.engine.rule.core-8.2.22.jar", |
|||
"description" :"io.sc.engine.rule.core-8.2.22.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/io.sc.engine.rule.core-8.2.22.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/io.sc.engine.rule.core-8.2.22.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"io.sc.platform.util-8.2.22.jar", |
|||
"description" :"io.sc.platform.util-8.2.22.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/io.sc.platform.util-8.2.22.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/io.sc.platform.util-8.2.22.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"io.sc.creditreport.core-8.2.22.jar", |
|||
"description" :"io.sc.creditreport.core-8.2.22.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/io.sc.creditreport.core-8.2.22.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/io.sc.creditreport.core-8.2.22.jar" |
|||
}, |
|||
{ |
|||
"type" :"file", |
|||
"name" :"io.sc.engine.rule.client.spring-8.2.22.jar", |
|||
"description" :"io.sc.engine.rule.client.spring-8.2.22.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jars/io.sc.engine.rule.client.spring-8.2.22.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/io.sc.engine.rule.client.spring-8.2.22.jar" |
|||
}, |
|||
|
|||
{ |
|||
"type" :"file", |
|||
"name" :"jaxb-api-2.3.1.jar", |
|||
"description" :"jaxb-api-2.3.1.jar", |
|||
"sources" :["classpath:/io/sc/engine/rule/client/jarsother/jaxb-api-2.3.1.jar"], |
|||
"target" :"${dir.engine.rule.classpath}/jaxb-api-2.3.1.jar" |
|||
} |
|||
] |
@ -1,6 +1,5 @@ |
|||
package io.sc.engine.rule.client; |
|||
package io.sc.engine.rule.core.client; |
|||
|
|||
import io.sc.engine.rule.client.enums.GeneratorType; |
|||
import io.sc.engine.rule.core.ExecuteResult; |
|||
|
|||
import java.util.Map; |
@ -1,4 +1,4 @@ |
|||
package io.sc.engine.rule.client.enums; |
|||
package io.sc.engine.rule.core.client; |
|||
|
|||
/** |
|||
* 执行器模式 |
@ -1,4 +1,4 @@ |
|||
package io.sc.engine.rule.client.enums; |
|||
package io.sc.engine.rule.core.client; |
|||
|
|||
public enum GeneratorType { |
|||
GROOVY, |
@ -1,4 +1,4 @@ |
|||
package io.sc.engine.rule.client; |
|||
package io.sc.engine.rule.core.client; |
|||
|
|||
import io.sc.engine.rule.core.code.ExecuteUnit; |
|||
|
@ -1,4 +1,4 @@ |
|||
package io.sc.engine.rule.client.enums; |
|||
package io.sc.engine.rule.core.client; |
|||
|
|||
/** |
|||
* 模型定义加载器模式 |
@ -0,0 +1,22 @@ |
|||
package io.sc.platform.util; |
|||
|
|||
public class OsUtil { |
|||
public static boolean isWindows(){ |
|||
String osName = getOsName(); |
|||
return osName != null && osName.startsWith("Windows"); |
|||
} |
|||
|
|||
public static boolean isMacOs() { |
|||
String osName = getOsName(); |
|||
return osName != null && osName.startsWith("Mac"); |
|||
} |
|||
|
|||
public static boolean isLinux() { |
|||
String osName = getOsName(); |
|||
return (osName != null && osName.startsWith("Linux")) || (!isWindows() && !isMacOs()); |
|||
} |
|||
|
|||
public static String getOsName() { |
|||
return System.getProperty("os.name"); |
|||
} |
|||
} |
@ -1,37 +1,70 @@ |
|||
package io.sc.platform.util.compiler.file; |
|||
|
|||
import io.sc.platform.util.OsUtil; |
|||
import io.sc.platform.util.compiler.memory.JavaCompileException; |
|||
import io.sc.platform.util.compiler.memory.MemoryJavaFileObject; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import javax.tools.*; |
|||
import java.io.File; |
|||
import java.util.Arrays; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
public class FileJavaCompiler { |
|||
private javax.tools.JavaCompiler compiler; |
|||
private StandardJavaFileManager standardFileManager; |
|||
private String classpathJarFileDir; |
|||
|
|||
public FileJavaCompiler() { |
|||
public FileJavaCompiler(String classpathJarFileDir) { |
|||
this.compiler = ToolProvider.getSystemJavaCompiler(); |
|||
this.standardFileManager = compiler.getStandardFileManager(null, null, null); |
|||
this.classpathJarFileDir =classpathJarFileDir; |
|||
} |
|||
|
|||
public void compile(String className, String sourceCode,String targetDir) throws JavaCompileException { |
|||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); |
|||
JavaCompiler.CompilationTask task = compiler.getTask( |
|||
null, |
|||
standardFileManager, |
|||
diagnostics, |
|||
Arrays.asList("-d", targetDir), |
|||
null, |
|||
Arrays.asList(new StringJavaFileObject(className,sourceCode)) |
|||
); |
|||
Boolean result = task.call(); |
|||
if (result == null || !result.booleanValue()) { |
|||
StringBuilder sb =new StringBuilder(); |
|||
diagnostics.getDiagnostics().forEach(d -> sb.append(String.valueOf(d))); |
|||
throw new JavaCompileException(sb.toString()); |
|||
|
|||
String classpath =getClassPath(); |
|||
// 编译选项
|
|||
List<String> options =new ArrayList<>(); |
|||
options.add("-d"); |
|||
options.add(targetDir); |
|||
if(StringUtils.hasText(classpath)){ |
|||
options.add("-cp"); |
|||
options.add(classpath); |
|||
} |
|||
// 编译部件
|
|||
List<JavaFileObject> units =new ArrayList<>(); |
|||
units.add(new StringJavaFileObject(className,sourceCode)); |
|||
|
|||
JavaCompiler.CompilationTask task = compiler.getTask(null,standardFileManager,diagnostics,options,null,units); |
|||
try { |
|||
Boolean result = task.call(); |
|||
if (!result) { |
|||
StringBuilder sb = new StringBuilder(); |
|||
diagnostics.getDiagnostics().forEach(d -> sb.append(String.valueOf(d))); |
|||
throw new JavaCompileException(sb.toString()); |
|||
} |
|||
} catch (Exception e) { |
|||
throw new JavaCompileException(e); |
|||
} |
|||
} |
|||
|
|||
private String getClassPath(){ |
|||
File dir =new File(classpathJarFileDir); |
|||
if(dir.exists() && dir.isDirectory()) { |
|||
File[] jars = dir.listFiles(); |
|||
if(jars!=null && jars.length>0) { |
|||
List<String> paths =new ArrayList<>(jars.length); |
|||
for(File jar : jars){ |
|||
paths.add(jar.getAbsolutePath()); |
|||
} |
|||
if(OsUtil.isWindows()) { |
|||
return String.join(";", paths); |
|||
}else{ |
|||
return String.join(":", paths); |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue