mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
support interface
This commit is contained in:
parent
2180260a20
commit
7e8076e075
@ -8,7 +8,7 @@ plugins {
|
|||||||
apply from: '../spotless.gradle'
|
apply from: '../spotless.gradle'
|
||||||
|
|
||||||
group = "org.bdware.sc"
|
group = "org.bdware.sc"
|
||||||
version = "1.9.2"
|
version = "1.9.7"
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
// options.compilerArgs << '-Xlint:none'
|
// options.compilerArgs << '-Xlint:none'
|
||||||
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
||||||
@ -51,8 +51,8 @@ dependencies {
|
|||||||
implementation 'com.sun.mail:javax.mail:1.6.2'
|
implementation 'com.sun.mail:javax.mail:1.6.2'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
|
||||||
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
implementation 'org.bdware.bdcontract:sdk-java:1.0.2'
|
||||||
implementation 'org.bdware.doip:doip-audit-tool:1.3.2'
|
implementation 'org.bdware.doip:doip-audit-tool:1.3.5'
|
||||||
implementation 'org.bdware.doip:doip-sdk:1.4.6'
|
implementation 'org.bdware.doip:doip-sdk:1.4.9'
|
||||||
implementation fileTree(dir: 'lib', include: '*.jar')
|
implementation fileTree(dir: 'lib', include: '*.jar')
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.bdware.sc.compiler;
|
|||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
public abstract class AnnotationProcessor {
|
public abstract class AnnotationProcessor {
|
||||||
public void processContract(AnnotationNode anno, ContractNode contractNode) {
|
public void processContract(AnnotationNode anno, ContractNode contractNode) {
|
||||||
@ -13,4 +14,8 @@ public abstract class AnnotationProcessor {
|
|||||||
FunctionNode functionNode) throws Exception {
|
FunctionNode functionNode) throws Exception {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode functionNode) throws Exception {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ public class YJSCompiler {
|
|||||||
ContractNode contract;
|
ContractNode contract;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(YJSCompiler.class);
|
private static final Logger LOGGER = LogManager.getLogger(YJSCompiler.class);
|
||||||
|
|
||||||
public YJSCompiler() {}
|
public YJSCompiler() {
|
||||||
|
}
|
||||||
|
|
||||||
public static ScriptFunction compileWithGlobal(Source source, Global global, Context context) {
|
public static ScriptFunction compileWithGlobal(Source source, Global global, Context context) {
|
||||||
Global oldGlobal = Context.getGlobal();
|
Global oldGlobal = Context.getGlobal();
|
||||||
@ -67,7 +68,7 @@ public class YJSCompiler {
|
|||||||
final ErrorManager errors = new ErrorManager(werr);
|
final ErrorManager errors = new ErrorManager(werr);
|
||||||
// Set up options.
|
// Set up options.
|
||||||
final Options options = new Options("nashorn", werr);
|
final Options options = new Options("nashorn", werr);
|
||||||
options.process(new String[] {});
|
options.process(new String[]{});
|
||||||
// detect scripting mode by any source's first character being '#'
|
// detect scripting mode by any source's first character being '#'
|
||||||
options.set("persistent.code.cache", true);
|
options.set("persistent.code.cache", true);
|
||||||
options.set("print.code", "true");
|
options.set("print.code", "true");
|
||||||
@ -120,7 +121,7 @@ public class YJSCompiler {
|
|||||||
Set<String> todo = new HashSet<>();
|
Set<String> todo = new HashSet<>();
|
||||||
Set<String> allEntries = new HashSet<>();
|
Set<String> allEntries = new HashSet<>();
|
||||||
Enumeration<? extends ZipEntry> iter = zf.entries();
|
Enumeration<? extends ZipEntry> iter = zf.entries();
|
||||||
for (; iter.hasMoreElements();) {
|
for (; iter.hasMoreElements(); ) {
|
||||||
ZipEntry ele = iter.nextElement();
|
ZipEntry ele = iter.nextElement();
|
||||||
if (ele != null)
|
if (ele != null)
|
||||||
allEntries.add(ele.getName());
|
allEntries.add(ele.getName());
|
||||||
@ -131,21 +132,34 @@ public class YJSCompiler {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ZipEntry entry = zf.getEntry(str.startsWith("/") ? str : "/" + str);
|
ZipEntry entry = zf.getEntry(str.startsWith("/") ? str : "/" + str);
|
||||||
|
LOGGER.info("load yjs:" + str);
|
||||||
if (null == entry) {
|
if (null == entry) {
|
||||||
throw new IllegalStateException("missing import:" + str);
|
throw new IllegalStateException("missing import:" + str);
|
||||||
}
|
}
|
||||||
ContractNode cn = compile(zf.getInputStream(entry), str);
|
ContractNode cn = compile(zf.getInputStream(entry), str);
|
||||||
|
String cnPath = entry.getName();
|
||||||
|
int i = cnPath.lastIndexOf("/");
|
||||||
|
String cnDir = "";
|
||||||
|
if (i != -1) cnDir = cnPath.substring(0, i);
|
||||||
czb.put(str, cn);
|
czb.put(str, cn);
|
||||||
for (ImportNode in : cn.getImports()) {
|
for (ImportNode in : cn.getImports()) {
|
||||||
for (String enstr : allEntries)
|
String path = in.getPath();
|
||||||
if (enstr.startsWith(in.getPath()) && enstr.endsWith(".yjs"))
|
if (!path.startsWith("/"))
|
||||||
todo.add(enstr);
|
path = cnDir + "/" + path;
|
||||||
|
path = path.replaceAll("/\\./", "/");
|
||||||
|
todo.add(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toParse.clear();
|
toParse.clear();
|
||||||
for (String str : todo) {
|
for (String str : todo) {
|
||||||
if (!czb.containsPath(str)) {
|
if (allEntries.contains(str))
|
||||||
toParse.add(str);
|
toParse.add(str);
|
||||||
|
else {
|
||||||
|
//TODO parse manifest.json first?
|
||||||
|
for (String entry : allEntries)
|
||||||
|
if (!czb.containsPath(entry) && entry.startsWith(str) && entry.endsWith(".yjs")) {
|
||||||
|
toParse.add(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
todo.clear();
|
todo.clear();
|
||||||
@ -217,6 +231,16 @@ public class YJSCompiler {
|
|||||||
processor.processFunction(anno, contractNode, functionNode);
|
processor.processFunction(anno, contractNode, functionNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (InterfaceNode interfaceNode : contractNode.getInterfaces()) {
|
||||||
|
List<AnnotationNode> annos = interfaceNode.annotations;// 函数里的annotation
|
||||||
|
if (annos != null)
|
||||||
|
for (AnnotationNode anno : annos) {
|
||||||
|
AnnotationProcessor processor = findProcessor(anno);
|
||||||
|
if (processor != null)
|
||||||
|
processor.processInterface(anno, contractNode, interfaceNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnnotationProcessor findProcessor(AnnotationNode node) {
|
public static AnnotationProcessor findProcessor(AnnotationNode node) {
|
||||||
|
@ -5,6 +5,7 @@ import org.bdware.sc.compiler.AnnotationProcessor;
|
|||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
|
|
||||||
// DOOP is designed for DoipModule which contains specific functions for RepositoryHandler
|
// DOOP is designed for DoipModule which contains specific functions for RepositoryHandler
|
||||||
@ -17,4 +18,10 @@ public class DOOP extends AnnotationProcessor {
|
|||||||
functionNode.setIsDoipOperation(true);
|
functionNode.setIsDoipOperation(true);
|
||||||
functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
|
functionNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode interfaceNode) throws Exception {
|
||||||
|
interfaceNode.setIsDoipOperation(true);
|
||||||
|
interfaceNode.setDoipOperationInfo(DoipOperationInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.bdware.sc.compiler.AnnotationProcessor;
|
|||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
public class Join extends AnnotationProcessor {
|
public class Join extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
@ -14,4 +15,9 @@ public class Join extends AnnotationProcessor {
|
|||||||
// 增加标记,在ContractNode中记录Join相关的函数和Join规则
|
// 增加标记,在ContractNode中记录Join相关的函数和Join规则
|
||||||
functionNode.setJoinInfo(JoinInfo.create(anno, contractNode));
|
functionNode.setJoinInfo(JoinInfo.create(anno, contractNode));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode interfaceNode) {
|
||||||
|
interfaceNode.setJoinInfo(JoinInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.bdware.sc.compiler.AnnotationProcessor;
|
|||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ContractNode;
|
import org.bdware.sc.node.ContractNode;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.node.InterfaceNode;
|
||||||
|
|
||||||
public class Route extends AnnotationProcessor {
|
public class Route extends AnnotationProcessor {
|
||||||
@Override
|
@Override
|
||||||
@ -12,4 +13,9 @@ public class Route extends AnnotationProcessor {
|
|||||||
FunctionNode functionNode) {
|
FunctionNode functionNode) {
|
||||||
functionNode.setRouteInfo(RouteInfo.create(anno, contractNode));
|
functionNode.setRouteInfo(RouteInfo.create(anno, contractNode));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void processInterface(AnnotationNode anno, ContractNode contractNode,
|
||||||
|
InterfaceNode interfaceNode) {
|
||||||
|
interfaceNode.setRouteInfo(RouteInfo.create(anno, contractNode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.google.gson.JsonObject;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.bdware.doip.codec.JsonDoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
||||||
@ -17,6 +18,7 @@ import org.bdware.sc.boundry.JavaScriptEntry;
|
|||||||
import org.bdware.sc.crdt.SharableVarManager;
|
import org.bdware.sc.crdt.SharableVarManager;
|
||||||
import org.bdware.sc.entity.DoipMessagePacker;
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
|
import org.bdware.sc.util.JsonUtil;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
@ -100,6 +102,7 @@ public class DOOPRequestHandler implements DoipRequestHandler {
|
|||||||
cr.setRequester(request.credential.getSigner());
|
cr.setRequester(request.credential.getSigner());
|
||||||
}
|
}
|
||||||
cr.setAction(fn.functionName);
|
cr.setAction(fn.functionName);
|
||||||
|
cr.setArg(JsonUtil.parseObjectAsJsonObject(JsonDoipMessage.fromDoipMessage(request)));
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,23 +80,25 @@ public class DoipLocalSingleton {
|
|||||||
config.privateKey = keyPair.getPrivateKeyStr();
|
config.privateKey = keyPair.getPrivateKeyStr();
|
||||||
config.publicKey = keyPair.getPublicKeyStr();
|
config.publicKey = keyPair.getPublicKeyStr();
|
||||||
}
|
}
|
||||||
if (config.routerURI != null) {
|
if (config.routerURI != null && config.repoName != null) {
|
||||||
AuditIrpClient irpClient = new AuditIrpClient(config);
|
AuditIrpClient irpClient = new AuditIrpClient(config);
|
||||||
EndpointInfo endpointInfo = irpClient.getEndpointInfo();
|
EndpointInfo endpointInfo = irpClient.getEndpointInfo();
|
||||||
repoID = endpointInfo.getDoId();
|
repoID = endpointInfo.getDoId();
|
||||||
owner = endpointInfo.getPubKey();
|
owner = endpointInfo.getPubKey();
|
||||||
infos.clear();
|
infos.clear();
|
||||||
infos.add(new DoipListenerConfig(endpointInfo.getURI(), "2.1"));
|
infos.add(new DoipListenerConfig(endpointInfo.getURI(), "2.1"));
|
||||||
|
port = new URI(endpointInfo.getURI()).getPort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
DoipServiceInfo info = new DoipServiceInfo(repoID, owner, repoType, infos);
|
DoipServiceInfo info = new DoipServiceInfo(repoID, owner, repoType, infos);
|
||||||
server = new DoipServerImpl(info);
|
server = new DoipServerImpl(info);
|
||||||
DOOPRequestHandler handler = ContractProcess.instance.doopRequestHandler;
|
DOOPRequestHandler handler = ContractProcess.instance.doopRequestHandler;
|
||||||
server.setRequestCallback(handler);
|
server.setRequestCallback(handler);
|
||||||
|
if (config != null)
|
||||||
SharableVarManager.initSharableVarManager(info.id, config);
|
SharableVarManager.initSharableVarManager(info.id, config);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
ResultChecker checker = new ResultChecker();
|
ResultChecker checker = new ResultChecker();
|
||||||
server.start(checker);
|
server.start(checker);
|
||||||
checker.waitForResult(1000);
|
checker.waitForResult(1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user