diff --git a/pom.xml b/pom.xml index 6290330b3457f92ffba26d2a92e23f1959f789b9..62bd142450e12204c5f140f8188a6f3a20086ddf 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.smartboot.flow smart-flow-parent - 1.1.3 + 1.1.4 4.0.0 pom smart-flow @@ -22,7 +22,7 @@ - 1.1.3 + 1.1.4 https://gitee.com/smartboot/smart-flow diff --git a/smart-flow-admin/Dockerfile b/smart-flow-admin/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c26dfe73ddb15533838f5bfaaa2adb573b6bf1fd --- /dev/null +++ b/smart-flow-admin/Dockerfile @@ -0,0 +1,9 @@ +# syntax=docker/dockerfile:1 + +FROM openjdk:jdk-alpine3.8 + +WORKDIR /smart-flow-admin + +COPY smart-flow-admin.jar smart-flow-admin.jar + +CMD ["java", "-jar", "smart-flow-admin.jar"] \ No newline at end of file diff --git a/smart-flow-admin/Makefile b/smart-flow-admin/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..395d4f2798cd9b8c538fefc7159a0a98c3eef9af --- /dev/null +++ b/smart-flow-admin/Makefile @@ -0,0 +1,15 @@ +VERSION=1.1.4 +base: + mvn -f ../pom.xml clean install +init: + docker buildx create --use --name smartbuilder + docker buildx inspect smartbuilder --bootstrap +local: base + mvn clean package + cp target/smart-flow-admin-*.jar smart-flow-admin.jar + docker build --no-cache -t smartboot/smart-flow-admin:${VERSION} -t smartboot/smart-flow-admin:latest . + docker buildx build --no-cache -t smartboot/smart-flow-admin:${VERSION} -t smartboot/smart-flow-admin:latest . --platform=linux/amd64,linux/arm64 . --push + rm -rf smart-flow-admin.jar + +clear: + docker buildx rm smartbuilder \ No newline at end of file diff --git a/smart-flow-admin/pom.xml b/smart-flow-admin/pom.xml index 023f141bf9789ddf452f9551c719dad16232ddb0..cc2cdf3aade83a632ed068fa8ee8e500c060053d 100644 --- a/smart-flow-admin/pom.xml +++ b/smart-flow-admin/pom.xml @@ -5,10 +5,10 @@ smart-flow-parent org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 - 1.1.3 + 1.1.4 smart-flow-admin diff --git a/smart-flow-admin/src/main/resources/application.properties b/smart-flow-admin/src/main/resources/application.properties index 02c9784fc2b78e0c7d29bb293994f7f9bf14c23b..3b86edd5286744327a29bbef7d975d229f334fcc 100644 --- a/smart-flow-admin/src/main/resources/application.properties +++ b/smart-flow-admin/src/main/resources/application.properties @@ -1,4 +1,4 @@ server.port=8076 -# 刪除3天前的数据 -data.period.day=3 \ No newline at end of file +# 刪除30天前的数据 +data.period.day=30 \ No newline at end of file diff --git a/smart-flow-core/pom.xml b/smart-flow-core/pom.xml index f7cf83182d592189382c28187bb2a9f0cfe71ff9..2a77ddb8dee145da5fc8541675b82f7b9e857c60 100644 --- a/smart-flow-core/pom.xml +++ b/smart-flow-core/pom.xml @@ -5,7 +5,7 @@ org.smartboot.flow smart-flow-parent - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java index 339a6eb12b1d5e1e5e4586155a9aec1ecf8bb312..99fc2dd55c20f90777efed7d84609aca947632f1 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListener.java @@ -5,7 +5,7 @@ package org.smartboot.flow.core; * @date 2022-11-25 20:34:35 * @since 1.0.0 */ -public interface ExecutionListener { +public interface ExecutionListener extends Describable { ExecutionListener NOOP = new ExecutionListener() {}; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java index 40dce3831ae5f90c6e835f1acb8177f9385e0539..42f88f640bf0e4ae1422469a027818f739849cd5 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/ExecutionListeners.java @@ -14,6 +14,13 @@ public class ExecutionListeners implements ExecutionListener { private static final Logger LOGGER = LoggerFactory.getLogger(ExecutionListeners.class); + /** + * 记录中断流程的Listener + * + * @since 1.1.4 + */ + private static final ThreadLocal BROKEN = new ThreadLocal<>(); + private final List listeners; public ExecutionListeners(List listeners) { @@ -28,6 +35,15 @@ public class ExecutionListeners implements ExecutionListener { listeners.add(0, listener); } + public static ExecutionListener getBrokenListener() { + return BROKEN.get(); + } + + public static void remove() { + // Remove lastest broken listener. + BROKEN.remove(); + } + @Override public void start(EngineContext context) { for (ExecutionListener listener : listeners) { @@ -55,6 +71,12 @@ public class ExecutionListeners implements ExecutionListener { for (ExecutionListener listener : listeners) { try { listener.beforeExecute(context, object); + // Already broken. + if (context.isBroken()) { + BROKEN.set(listener); + return; + } + } catch (Throwable e) { LOGGER.warn("execute listener {} failed", listener.getClass().getName(), e); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java index 429a1a6303295604e2d11d2eee66db6c849ef691..b724065e05a6963862da3dd1180bdee6e1b48ca8 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/Pipeline.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.invoker.InvokeListener; import org.smartboot.flow.core.invoker.WrappedInvoker; @@ -81,6 +82,13 @@ public class Pipeline implements Rollback, Describable, Validator, M } private void ensureAllDependsExecuted(Component component, EngineContext context) { + + // @since 1.1.4 ensure all async invoke has finished. + if (component.getAttributeValue(Attributes.DEPENDS_ALL, false)) { + context.ensureFinished(); + return; + } + for (String depends : component.getDependsOn()) { AsyncCallResult asyncCall = context.getAsyncCall(depends); if (asyncCall == null) { diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java index 0290bdc7b50cd0a3d05436e602b0fe32c2cef3c8..fceff07a24d31d5c5710db2af57d7ddd13570ab4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/attribute/Attributes.java @@ -92,6 +92,13 @@ public enum Attributes { */ REFERENCED_PIPELINE("referenced-pipeline", "引用子流程", Boolean.class, false), + /** + * 是否等待所有异步组件完成 + * + * @since 1.1.4 + */ + DEPENDS_ALL("dependsAll", "等待前置的所有异步组件完成", Boolean.class), + ; private final String name; diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java index de0c80450860152f7c7248c923bf59152b65fd8f..7a43ee5d3c135578ca51da64066e37fd788b05fc 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/builder/AbstractComponentBuilder.java @@ -64,6 +64,7 @@ public abstract class AbstractComponentBuilder { */ protected void applyValues(Component component) { settings.forEach((k, v) -> k.apply(component, v)); + component.setValueResolver(valueResolver); } /** diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java index c16b7136537091d5e020f766a27f874289f56c88..1b303a9bd02af89187affdfd9ebf7279d03052e4 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/component/Component.java @@ -9,6 +9,8 @@ import org.smartboot.flow.core.Measurable; import org.smartboot.flow.core.Rollback; import org.smartboot.flow.core.Validator; import org.smartboot.flow.core.attribute.AttributeHolder; +import org.smartboot.flow.core.attribute.AttributeValueResolver; +import org.smartboot.flow.core.attribute.Attributes; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.visitor.ComponentVisitor; @@ -37,10 +39,18 @@ public abstract class Component extends AbstractExtensible implements Roll private String name; private boolean enabled = true; private DegradeCallback degradeCallback; + /** + * @since 1.1.4 + */ + private transient AttributeValueResolver valueResolver = AttributeValueResolver.getInstance(); protected final List attributes = new ArrayList<>(8); private volatile boolean validateCalled = false; + public void setValueResolver(AttributeValueResolver valueResolver) { + this.valueResolver = valueResolver; + } + public DegradeCallback getDegradeCallback() { return degradeCallback; } @@ -140,4 +150,19 @@ public abstract class Component extends AbstractExtensible implements Roll /** Returns component's type */ public abstract ComponentType getType(); + + /** + * 获取属性值 + * + * @since 1.1.4 + */ + public R getAttributeValue(Attributes attributes, R defaultValue) { + for (AttributeHolder ah : this.attributes) { + if (ah.getAttribute() == attributes) { + return (R)valueResolver.resolve(attributes.getAccept(), ah.getValue()); + } + } + + return defaultValue; + } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java index eb8d834cc76dbd103dea8d696fbbb73c4156ba2c..d91c70d0d35fa7e91c33d7721c87324980cd8019 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/executable/ExecutableAdapter.java @@ -3,6 +3,7 @@ package org.smartboot.flow.core.executable; import org.smartboot.flow.core.DegradeCallback; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.Key; import org.smartboot.flow.core.Rollback; import org.smartboot.flow.core.common.ComponentType; import org.smartboot.flow.core.component.Component; @@ -34,6 +35,8 @@ public class ExecutableAdapter extends Component implements Rollback< @Override public int invoke(EngineContext context) { try { + // Record executed. + context.putExt(Key.of(this), true); executable.execute(context); } catch (Throwable e) { // 非降级,直接throw @@ -53,9 +56,15 @@ public class ExecutableAdapter extends Component implements Rollback< return 1; } + @Override + public boolean isRollbackable(EngineContext context) { + // Attribute 'rollback' configured and component has executed. + return super.isRollbackable(context) && context.getExt(Key.of(this)) != null; + } @Override public void rollback(EngineContext context) { + context.remove(Key.of(this)); executable.rollback(context); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/WrappedInvoker.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/WrappedInvoker.java index 332f75befe7a521f01d8c08f2ca5780ce9f158d8..6547ce9becac2ea385a778f70518e74c5c1f3de6 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/WrappedInvoker.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/invoker/WrappedInvoker.java @@ -2,6 +2,8 @@ package org.smartboot.flow.core.invoker; import org.smartboot.flow.core.Describable; import org.smartboot.flow.core.EngineContext; +import org.smartboot.flow.core.ExecutionListener; +import org.smartboot.flow.core.ExecutionListeners; import org.smartboot.flow.core.Feature; import org.smartboot.flow.core.component.Component; import org.smartboot.flow.core.component.PipelineComponent; @@ -19,16 +21,18 @@ public class WrappedInvoker { // 兼容ExecutionListener内部的主动broken调用 if (context.isBroken()) { + ExecutionListener brokenListener = ExecutionListeners.getBrokenListener(); int status = context.getExecuting(); context.setExecuting(EngineContext.EXECUTING); if (context.cfg().isConfigured(Feature.BrokenInListenerOnTree)) { - context.enter(Feature.BrokenInListenerOnTree.name()); - context.exit(Feature.BrokenInListenerOnTree.name()); + context.enter(Feature.BrokenInListenerOnTree.name() + "-" + brokenListener.describe()); + context.exit(Feature.BrokenInListenerOnTree.name() + "-" + brokenListener.describe()); } context.setExecuting(status); if (checkTraceable(component)) { context.exit(component, null); } + ExecutionListeners.remove(); return 0; } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java index 8aef0c242217bfc7a427e241db75554e2f5030c8..737c294c52c68b0cc441e0e1ab3a9d1cc016f3c2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/ComponentModel.java @@ -44,7 +44,10 @@ public class ComponentModel extends Uniqueness { } else if (type != ComponentType.BASIC){ Map all = new HashMap<>(32); components.forEach((k, v) -> { - all.putAll(v.collect()); + Map collected = v.collect(); + if (collected != null) { + all.putAll(collected); + } all.put(v.getIdentifier(), v); }); @@ -52,7 +55,7 @@ public class ComponentModel extends Uniqueness { return all; } else { // Basic component. - return new HashMap<>(0); + return null; } } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java index 1022217162e1b13bd386886a44a5a64b650a6947..105d846ffae789ac025a7ba97cc8bc08c49c4c44 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/manager/PipelineModel.java @@ -38,7 +38,10 @@ public class PipelineModel extends Uniqueness { HashMap collected = new HashMap<>(components.size()); for (ComponentModel model : components) { - collected.putAll(model.collect()); + Map subcollected = model.collect(); + if (subcollected != null) { + collected.putAll(subcollected); + } collected.put(model.getIdentifier(), model); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseHelper.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..bda819d04f4b8a16f33ec24d2f688e34f9a31a1c --- /dev/null +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/parser/ParseHelper.java @@ -0,0 +1,174 @@ +package org.smartboot.flow.core.parser; + +import org.smartboot.flow.core.FlowEngine; +import org.smartboot.flow.core.attribute.AttributeValueResolver; +import org.smartboot.flow.core.util.AssertUtil; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * 更便捷的解析入口 + * + *
+ * {@code
+ *
+ * try {
+ *     DefaultParser parser = new DefaultParser();
+ *     parser.parse(this.getClass().getResourceAsStream("/engine.xml");
+ *     FlowEngine engine = parser.get("testEngine");
+ * } catch (Exception e) {
+ *
+ * }
+ * }
+ * 
+ * + * 可以简化为如下代码 + *
+ * {@code
+ * FlowEngine engine
+ *      = ParseHelper.classpath("engine.xml").get("testEngine");
+ *
+ * }
+ * 
+ * + * 或者(仅有一个引擎的情况下) + *
+ * {@code
+ * FlowEngine engine
+ *      = ParseHelper.classpath("engine.xml").unique();
+ *
+ * }
+ * 
+ * + * 当然也提供方法支持多个配置文件以及自定义解析器 + * + * @author qinluo + * @date 2023-10-26 15:00:41 + * @since 1.1.4 + */ +public final class ParseHelper { + + private static final int classpath = 1; + private static final int absolute = 2; + private static final int relative = 3; + + public static ParseHelperBuilder classpath(String config) { + return new ParseHelperBuilder(config, classpath); + } + + public static ParseHelperBuilder absolute(String config) { + return new ParseHelperBuilder(config, absolute); + } + + public static ParseHelperBuilder relative(String config) { + return new ParseHelperBuilder(config, relative); + } + + static InputStream getResource(String config, int type) { + try { + if (type == classpath) { + return ParseHelper.class.getResourceAsStream(config); + } else if (type == absolute || type == relative) { + return new FileInputStream(config); + } + } catch (Exception ignored) { + + } + + return null; + } + + public static class ParseHelperBuilder { + private final List streams = new ArrayList<>(0); + private final int type; + private boolean completed; + private final DefaultParser parser = new DefaultParser(); + private final InputStream mainStream; + + ParseHelperBuilder(String config, int type) { + this.type = type; + AssertUtil.notBlank(config, "config must not be blank"); + + InputStream stream = getResource(config, type); + AssertUtil.notNull(stream, "config " + config + " cannot found."); + this.mainStream = stream; + } + + private void addStream(String config, int type) { + InputStream stream = getResource(config, type); + AssertUtil.notNull(stream, "config " + config + " cannot found."); + this.streams.add(stream); + } + + private void processParse() { + if (!completed) { + parser.parse(mainStream, streams.toArray(new InputStream[0])); + } + completed = true; + } + + /* Engine scene. */ + + public FlowEngine unique() { + processParse(); + AssertUtil.isTrue(parser.getEngines().size() == 1, "Multiple engines."); + List engineNames = parser.getEngineNames(); + return parser.getEngine(engineNames.get(0)); + } + + public FlowEngine first() { + processParse(); + List engineNames = parser.getEngineNames(); + if (engineNames.size() > 0) { + return parser.getEngine(engineNames.get(0)); + } + return null; + } + + public FlowEngine get(String name) { + processParse(); + return parser.getEngine(name); + } + + + /* Customized Parser scene methods */ + public ParseHelperBuilder withObjectCreator(ObjectCreator creator) { + this.parser.setObjectCreator(creator); + return this; + } + + public ParseHelperBuilder withResolver(AttributeValueResolver resolver) { + this.parser.setAttributeValueResolver(resolver); + return this; + } + + public ParseHelperBuilder withScriptLocations(String ...locations) { + this.parser.scriptLoader().locations(locations); + return this; + } + + /* Special multiple config locations scene methods. */ + public ParseHelperBuilder addConfig(String config) { + this.addStream(config, type); + return this; + } + + public ParseHelperBuilder addClasspath(String config) { + this.addStream(config, classpath); + return this; + } + + public ParseHelperBuilder addAbsolute(String config) { + this.addStream(config, absolute); + return this; + } + + public ParseHelperBuilder addRelative(String config) { + this.addStream(config, relative); + return this; + } + } +} diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java index 84f616f7ff917a8d0ca6e04ed0fd580dff979868..8a77dfe9dd2bdb6249b02d78e03d208aae033dbe 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanContext.java @@ -9,18 +9,43 @@ import java.util.List; */ public interface BeanContext { + /** + * Try to find a bean named name. + * + * @param name name. + * @param generic type + * @return bean + */ default T getBean(String name) { throw new UnsupportedOperationException(); } + /** + * Try to find a specified type bean named name. + * + * @param name name. + * @param generic type + * @param type specified type + * @return bean + */ default T getBean(String name, Class type) { throw new UnsupportedOperationException(); } + /** + * Try to find a specified type bean list. + * + * @param generic type + * @param type specified type + * @return bean list + */ default List getBean(Class type) { throw new UnsupportedOperationException(); } + /** + * Make cur bean ctx enabled. + */ default void init() { BeanUtils.init(this); } diff --git a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java index 0b8b6a9347d5f64a3ad18925f7f98cdf3f995f6f..8d1f3ebf1284e04b09741b01196fab9ae9e9bde2 100644 --- a/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java +++ b/smart-flow-core/src/main/java/org/smartboot/flow/core/util/BeanUtils.java @@ -11,6 +11,17 @@ public class BeanUtils { private static BeanContext instance = null; + /** + * Init bean context. + * + * @param ctx bean context + */ + static void init(BeanContext ctx) { + instance = ctx; + } + + /* Static delegate methods */ + public static T getBean(String name) { return instance.getBean(name); } @@ -23,9 +34,4 @@ public class BeanUtils { List beans = instance.getBean(type); return beans != null && beans.size() > 0 ? beans.get(0) : null; } - - static void init(BeanContext ctx) { - instance = ctx; - } - } diff --git a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd index 0e38d956dc1975be778066a070790cb97d6dc119..f42e80698a6a28b1bfee35ee5daa2c4df59c184e 100644 --- a/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd +++ b/smart-flow-core/src/main/resources/smart-flow-1.0.1.xsd @@ -36,6 +36,14 @@ + + + + 等待所有前置异步组件完成 + + + + @@ -61,6 +69,7 @@ + diff --git a/smart-flow-helper/pom.xml b/smart-flow-helper/pom.xml index 23c8f4e1c760b4dd74fa06001f50470ec9d8f56c..f59da36cdaed85e1abc657a6e3dc8ed4ba57ba42 100644 --- a/smart-flow-helper/pom.xml +++ b/smart-flow-helper/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-helper/src/main/java/org/smartboot/flow/helper/view/XmlEngineVisitor.java b/smart-flow-helper/src/main/java/org/smartboot/flow/helper/view/XmlEngineVisitor.java index d10a4fadc067eeea4f6f062218847591efdc7bb0..740ffe3fbffa664b9910e6a6d5b8b749b49551ea 100644 --- a/smart-flow-helper/src/main/java/org/smartboot/flow/helper/view/XmlEngineVisitor.java +++ b/smart-flow-helper/src/main/java/org/smartboot/flow/helper/view/XmlEngineVisitor.java @@ -36,6 +36,17 @@ public class XmlEngineVisitor extends EngineVisitor { */ private String content; + /** + * 是否替换反序列化文本中的换行符、tab等多余空白 + * + * @since 1.1.4 + */ + private boolean compress; + + public void compressContent() { + this.compress = true; + } + public String getContent() { return content; } @@ -64,15 +75,29 @@ public class XmlEngineVisitor extends EngineVisitor { unprocessed = PipelineCollector.getUnprocessed(); } + // Avoid process script. + if (compress) { + this.content = this.content.replace("\n", "") + .replace("\t", "").replace("\r\n", ""); + } + Map> scripts = ScriptCollector.end(); if (scripts != null && scripts.size() > 0) { - scripts.forEach((k, v) -> content.append("\n\t")); + .append("\">").append("").append(""); + }); } - content.append("\n").append(END).append("\n"); - + if (!compress) { + content.append("\n").append(END).append("\n"); + } else { + content.append(END); + } this.content = content.toString(); } diff --git a/smart-flow-integration/pom.xml b/smart-flow-integration/pom.xml index 4b1f46d90d0b929d53fb3c16c03138d54ff71454..e403b036f08a62fac3c6d9e6f2f4e36f5bec9e7b 100644 --- a/smart-flow-integration/pom.xml +++ b/smart-flow-integration/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-integration/smart-flow-integration-nacos/pom.xml b/smart-flow-integration/smart-flow-integration-nacos/pom.xml index aca264249e1dbfd88b7a77d242eb263518b3ad78..02a240bba480bfcddb513bd92f2f0c9106476d20 100644 --- a/smart-flow-integration/smart-flow-integration-nacos/pom.xml +++ b/smart-flow-integration/smart-flow-integration-nacos/pom.xml @@ -5,7 +5,7 @@ smart-flow-integration org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-integration/smart-flow-spring-extension/pom.xml b/smart-flow-integration/smart-flow-spring-extension/pom.xml index fb1a35e713cf17272a45522ee9621efb61b663d8..36ae61c9987d37c9b944fd23ee2b669a98077790 100644 --- a/smart-flow-integration/smart-flow-spring-extension/pom.xml +++ b/smart-flow-integration/smart-flow-spring-extension/pom.xml @@ -5,7 +5,7 @@ smart-flow-integration org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java index f1d9b80fdc2a0fcffdd7cbcde719388156b1b5b1..b733438e13a9c3dcc4ab5d1fab2d11f55fa573e7 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/BeanDefinitionVisitor.java @@ -173,6 +173,7 @@ public class BeanDefinitionVisitor implements DefinitionVisitor, BeanFactoryAwar Attributes attribute = holder.getAttribute(); if (attribute == Attributes.NAME || attribute == Attributes.DEGRADE_CALLBACK + || attribute == Attributes.DEPENDS_ALL || !attribute.isVisible()) { continue; } @@ -392,6 +393,10 @@ public class BeanDefinitionVisitor implements DefinitionVisitor, BeanFactoryAwar PropertyValue name = new PropertyValue("name", ed.getName()); definition.setBeanClass(ed.resolveType()); definition.getPropertyValues().addPropertyValue(name); + + if (ed instanceof ComponentDefinition) { + definition.getPropertyValues().add("valueResolver", new RuntimeBeanReference(SpringAttributeValueResolver.class.getName())); + } return definition; } } diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java index 58d17240732cb05b9e59c91250a2e5f4569482f1..91d9f368c921522ad94752183abe121de0679881 100644 --- a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SmartFlowRegistrar.java @@ -32,6 +32,7 @@ public class SmartFlowRegistrar implements ImportBeanDefinitionRegistrar { registeredClasses.put(SpringObjectCreator.NAME, SpringObjectCreator.class); registeredClasses.put(SpringBeanContextAdapter.NAME, SpringBeanContextAdapter.class); registeredClasses.put(XmlParseReloader.class.getName(), XmlParseReloader.class); + registeredClasses.put(SpringAttributeValueResolver.class.getName(), SpringAttributeValueResolver.class); } @Override diff --git a/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringAttributeValueResolver.java b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringAttributeValueResolver.java new file mode 100644 index 0000000000000000000000000000000000000000..473cd466bf33e9d1b9eecc7114601a2ec646e344 --- /dev/null +++ b/smart-flow-integration/smart-flow-spring-extension/src/main/java/org/smartboot/flow/spring/extension/SpringAttributeValueResolver.java @@ -0,0 +1,25 @@ +package org.smartboot.flow.spring.extension; + +import org.smartboot.flow.core.attribute.AttributeValueResolver; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; + +/** + * @author qinluo + * @date 2023-10-27 15:35:59 + * @since 1.1.4 + */ +public class SpringAttributeValueResolver extends AttributeValueResolver { + + @Autowired + private Environment environment; + + @Override + protected String earlyResolve(String value) { + try { + return environment.resolvePlaceholders(value); + } catch (Exception e) { + return value; + } + } +} diff --git a/smart-flow-integration/smart-flow-springboot-starter/pom.xml b/smart-flow-integration/smart-flow-springboot-starter/pom.xml index 767f59a7d8a96d65ef996b0aadbfa7c26b41aba1..4e679ff3ea0e25148e5143563d0d13d65c179e3a 100644 --- a/smart-flow-integration/smart-flow-springboot-starter/pom.xml +++ b/smart-flow-integration/smart-flow-springboot-starter/pom.xml @@ -5,7 +5,7 @@ smart-flow-integration org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-manager/pom.xml b/smart-flow-manager/pom.xml index 1247b5d0a48bc692733cfb1ea781ccc9e02e91ad..d38f734f2c49413c76cdb3e798b090b1ab22eb2d 100644 --- a/smart-flow-manager/pom.xml +++ b/smart-flow-manager/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/FlatManager.java b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/FlatManager.java index fd9ba0fc5d227c4a4346c19b376949b309fa6778..4c055d00e572a4e7e65e86cbe864d6cd1cc96fda 100644 --- a/smart-flow-manager/src/main/java/org/smartboot/flow/manager/FlatManager.java +++ b/smart-flow-manager/src/main/java/org/smartboot/flow/manager/FlatManager.java @@ -42,6 +42,7 @@ public class FlatManager { engine.setReportContent(true); XmlEngineVisitor visitor = new XmlEngineVisitor(); + visitor.compressContent(); visitor.visit(source); String content = visitor.getContent(); engine.setContent(content); diff --git a/smart-flow-plugin/pom.xml b/smart-flow-plugin/pom.xml index b76abb4969efe75476f5cbf898002d3b0d8ae035..e7cc2542c54f4dd809be0892cb657b25ddf5a8b8 100644 --- a/smart-flow-plugin/pom.xml +++ b/smart-flow-plugin/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-parent - 1.1.3 + 1.1.4 smart-flow-plugin diff --git a/smart-flow-plugin/smart-flow-bootstrap/pom.xml b/smart-flow-plugin/smart-flow-bootstrap/pom.xml index 9ffc1b6509a7b00e4709fe45588f231d747c9759..2cd06faa390ce26db00cef1921fc76b588088f0c 100644 --- a/smart-flow-plugin/smart-flow-bootstrap/pom.xml +++ b/smart-flow-plugin/smart-flow-bootstrap/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-plugin - 1.1.3 + 1.1.4 smart-flow-bootstrap diff --git a/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml b/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml index 22217006949c6ca8b149a287f82858f448cf169b..8bb46b106c826c76e809623ee5248d27579522ce 100644 --- a/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml +++ b/smart-flow-plugin/smart-flow-enhance-plugin/pom.xml @@ -6,7 +6,7 @@ org.smartboot.flow smart-flow-plugin - 1.1.3 + 1.1.4 smart-flow-enhance-plugin diff --git a/smart-flow-script/pom.xml b/smart-flow-script/pom.xml index af5a19dcaccd98d8494bd650a495969cc676c18d..724eb075972307789d7e86e1d4e72d1235a3c0bc 100644 --- a/smart-flow-script/pom.xml +++ b/smart-flow-script/pom.xml @@ -5,7 +5,7 @@ smart-flow-parent org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 pom diff --git a/smart-flow-script/smart-flow-script-groovy/pom.xml b/smart-flow-script/smart-flow-script-groovy/pom.xml index 8febee5d7a28367db7ec31a330e582060594e780..428aef5125c4127880c38a75c7e2a66aa99a114a 100644 --- a/smart-flow-script/smart-flow-script-groovy/pom.xml +++ b/smart-flow-script/smart-flow-script-groovy/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-script/smart-flow-script-ognl/pom.xml b/smart-flow-script/smart-flow-script-ognl/pom.xml index efd7c167d1842163aaea5db2e21fc89f3ff30215..3e0cb220fe65535788c056a70da796be768d967e 100644 --- a/smart-flow-script/smart-flow-script-ognl/pom.xml +++ b/smart-flow-script/smart-flow-script-ognl/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0 diff --git a/smart-flow-script/smart-flow-script-qlexpress/pom.xml b/smart-flow-script/smart-flow-script-qlexpress/pom.xml index 13519f07117359e2ad783e4c3d735ad02230575f..0c970b17657e0cfd02025a3e9ab4cc72b14eb0eb 100644 --- a/smart-flow-script/smart-flow-script-qlexpress/pom.xml +++ b/smart-flow-script/smart-flow-script-qlexpress/pom.xml @@ -5,7 +5,7 @@ smart-flow-script org.smartboot.flow - 1.1.3 + 1.1.4 4.0.0