lidongy
4 years ago
commit
fe12744038
10 changed files with 238 additions and 0 deletions
@ -0,0 +1,121 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||||
|
<project basedir="." default="jar" name="plugin"> |
||||||
|
<!-- JDK路径,根据自己机器上实际位置修改--> |
||||||
|
<property name="jdk.home" value="C:\Program Files\Java\jdk1.8.0_121"/> |
||||||
|
|
||||||
|
<property name="libs" value="${basedir}/lib"/> |
||||||
|
<property name="publicLibs" value=""/> |
||||||
|
<property name="destLoc" value="."/> |
||||||
|
<property name="classes" value="classes"/> |
||||||
|
<xmlproperty file="${basedir}/plugin.xml"/> |
||||||
|
<property name="current-version" value="${plugin.version}"/> |
||||||
|
|
||||||
|
<!-- 插件版本--> |
||||||
|
<property name="plugin-version" value="${current-version}"/> |
||||||
|
<!-- 插件名字--> |
||||||
|
<property name="plugin-name" value="demo-data-transfer-process"/> |
||||||
|
<property name="plugin-jar" value="fr-plugin-${plugin-name}-${plugin-version}.jar"/> |
||||||
|
|
||||||
|
<target name="prepare"> |
||||||
|
<delete dir="${classes}"/> |
||||||
|
<delete dir="fr-plugin-${plugin-name}-${plugin-version}"/> |
||||||
|
<xmlproperty file="${basedir}/plugin.xml"/> |
||||||
|
<delete dir="${destLoc}/${plugin.name}"/> |
||||||
|
</target> |
||||||
|
<path id="compile.classpath"> |
||||||
|
<fileset dir="${libs}"> |
||||||
|
<include name="**/*.jar"/> |
||||||
|
</fileset> |
||||||
|
<fileset dir="${publicLibs}"> |
||||||
|
<include name="**/*.jar"/> |
||||||
|
</fileset> |
||||||
|
</path> |
||||||
|
<patternset id="resources4Jar"> |
||||||
|
<exclude name="**/.settings/**"/> |
||||||
|
<exclude name=".classpath"/> |
||||||
|
<exclude name=".project"/> |
||||||
|
|
||||||
|
<exclude name="**/*.java"/> |
||||||
|
<exclude name="**/*.db"/> |
||||||
|
<exclude name="**/*.g"/> |
||||||
|
<exclude name="**/package.html"/> |
||||||
|
</patternset> |
||||||
|
<target name="copy_resources"> |
||||||
|
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/> |
||||||
|
<delete dir="tmp"/> |
||||||
|
<copy todir="tmp"> |
||||||
|
<fileset dir="${resources_from}\src\resource"> |
||||||
|
<patternset refid="resources4Jar"/> |
||||||
|
</fileset> |
||||||
|
</copy> |
||||||
|
<copy todir="${classes}"> |
||||||
|
<fileset dir="tmp"/> |
||||||
|
</copy> |
||||||
|
<delete dir="tmp"/> |
||||||
|
</target> |
||||||
|
<target name="compile_javas"> |
||||||
|
<echo message="编译${compile_files}下的Java文件"/> |
||||||
|
<javac destdir="${classes}" debug="false" optimize="on" source="${source_jdk_version}" |
||||||
|
target="${target_jdk_version}" |
||||||
|
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}" |
||||||
|
executable="${compile_jdk_version}/bin/javac"> |
||||||
|
<src path="${basedir}/src/java"/> |
||||||
|
<exclude name="**/.svn/**"/> |
||||||
|
<compilerarg line="-encoding UTF8 "/> |
||||||
|
<classpath refid="compile.classpath"/> |
||||||
|
</javac> |
||||||
|
</target> |
||||||
|
|
||||||
|
<target name="jar_classes"> |
||||||
|
<echo message="打Jar包:${jar_name}"/> |
||||||
|
<delete file="${basedir}/${jar_name}"/> |
||||||
|
<jar jarfile="${basedir}/${jar_name}"> |
||||||
|
<fileset dir="${classes}"> |
||||||
|
</fileset> |
||||||
|
</jar> |
||||||
|
</target> |
||||||
|
|
||||||
|
<target name="super_jar" depends="prepare"> |
||||||
|
<antcall target="copy_resources"> |
||||||
|
<param name="resources_from" value="${basedir}"/> |
||||||
|
</antcall> |
||||||
|
<antcall target="compile_javas"> |
||||||
|
<param name="source_jdk_version" value="1.8"/> |
||||||
|
<param name="target_jdk_version" value="1.8"/> |
||||||
|
<param name="compile_jdk_version" value="${jdk.home}"/> |
||||||
|
<param name="compile_files" value="${basedir}/src"/> |
||||||
|
</antcall> |
||||||
|
<echo message="compile plugin success!"/> |
||||||
|
|
||||||
|
<antcall target="jar_classes"> |
||||||
|
<param name="jar_name" value="${plugin-jar}"/> |
||||||
|
</antcall> |
||||||
|
<delete dir="${classes}"/> |
||||||
|
|
||||||
|
</target> |
||||||
|
<target name="jar" depends="super_jar"> |
||||||
|
<antcall target="zip"/> |
||||||
|
</target> |
||||||
|
|
||||||
|
<target name="zip"> |
||||||
|
<property name="plugin-folder" value="fr-plugin-${plugin-name}-${plugin-version}"/> |
||||||
|
<echo message="----------zip files----------"/> |
||||||
|
<mkdir dir="${plugin-folder}"/> |
||||||
|
<copy todir="${plugin-folder}"> |
||||||
|
<fileset dir="."> |
||||||
|
<include name="${plugin-jar}"/> |
||||||
|
<include name="plugin.xml"/> |
||||||
|
</fileset> |
||||||
|
<fileset dir="lib"> |
||||||
|
<include name="*"/> |
||||||
|
</fileset> |
||||||
|
</copy> |
||||||
|
<zip destfile="${basedir}/${plugin-folder}.zip" basedir="."> |
||||||
|
<include name="${plugin-folder}/*.jar"/> |
||||||
|
<include name="${plugin-folder}/plugin.xml"/> |
||||||
|
</zip> |
||||||
|
<xmlproperty file="${basedir}/plugin.xml"/> |
||||||
|
<move file="${plugin-folder}.zip" todir="${destLoc}/${plugin.name}"/> |
||||||
|
<delete file="fr-plugin-${plugin-name}-${plugin-version}.jar"/> |
||||||
|
</target> |
||||||
|
</project> |
Binary file not shown.
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||||
|
<plugin> |
||||||
|
<id>com.fr.plugin.demo.data.transfer.process</id> |
||||||
|
<name><![CDATA[迁移过程示例插件]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<hidden>no</hidden> |
||||||
|
<version>1.0.0</version> |
||||||
|
<env-version>10.0</env-version> |
||||||
|
<jartime>2021-02-01</jartime> |
||||||
|
<vendor>lidongy</vendor> |
||||||
|
<description><![CDATA[迁移过程示例插件]]></description> |
||||||
|
<change-notes><![CDATA[ |
||||||
|
<p>[2021-03-31]第一版</p> |
||||||
|
]]></change-notes> |
||||||
|
<extra-decision> |
||||||
|
<DataTransferProcessProvider |
||||||
|
class="com.fr.plugin.demo.data.transfer.DemoTransferProcess"/> |
||||||
|
</extra-decision> |
||||||
|
<function-recorder class="com.fr.plugin.demo.data.transfer.DemoTransferProcess"/> |
||||||
|
</plugin> |
@ -0,0 +1,19 @@ |
|||||||
|
# 帆软资源迁移过程demo插件 |
||||||
|
# 这个插件演示了在资源导出、导入时做拦截。 |
||||||
|
# 使用举例: |
||||||
|
## 1,资源导出 |
||||||
|
![1](screenshots/export1.png) |
||||||
|
![1](screenshots/export2.png) |
||||||
|
|
||||||
|
## 2,查看日志,里面有迁移的内容 |
||||||
|
|
||||||
|
![1](screenshots/log1.png) |
||||||
|
|
||||||
|
## 3,查看资源文件,有定义的额外导出内容extra.txt |
||||||
|
|
||||||
|
![1](screenshots/resource.png) |
||||||
|
|
||||||
|
## 4,导入时查看日志,可以识别到extra.txt的内容 |
||||||
|
|
||||||
|
|
||||||
|
![1](screenshots/log2.png) |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 50 KiB |
@ -0,0 +1,78 @@ |
|||||||
|
package com.fr.plugin.demo.data.transfer; |
||||||
|
|
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.runtime.ResourceKit; |
||||||
|
import com.fanruan.api.util.GeneralKit; |
||||||
|
import com.fr.decision.fun.impl.AbstractDataTransferProcessProvider; |
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.third.fasterxml.jackson.databind.ObjectMapper; |
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author lidongy |
||||||
|
* @version 10.0 |
||||||
|
* Created by lidongy on 2021/3/31 |
||||||
|
*/ |
||||||
|
@EnableMetrics |
||||||
|
public class DemoTransferProcess extends AbstractDataTransferProcessProvider { |
||||||
|
private static final String EXPORT_TEMP_DIR = "export_temp_dir"; |
||||||
|
private static final String IMPORT_TEMP_DIR = "import_temp_dir"; |
||||||
|
|
||||||
|
@Override |
||||||
|
@Focus(id = "com.fr.plugin.demo.data.transfer.process", text = "", source = Original.PLUGIN) |
||||||
|
public void afterBuildExportData(Map<Integer, Set<String>> allResource) { |
||||||
|
printAllResource(allResource); |
||||||
|
ResourceKit.write(GeneralKit.pathJoin(EXPORT_TEMP_DIR, "extra.txt"), "resource"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void afterImport(Map<Integer, Set<String>> allResource) { |
||||||
|
printAllResource(allResource); |
||||||
|
ByteArrayOutputStream outputStream = null; |
||||||
|
InputStream inputStream = null; |
||||||
|
try { |
||||||
|
inputStream = ResourceKit.read(GeneralKit.pathJoin(IMPORT_TEMP_DIR, EXPORT_TEMP_DIR, "extra.txt")); |
||||||
|
outputStream = new ByteArrayOutputStream(); |
||||||
|
byte[] buffer = new byte[1024]; |
||||||
|
int len = -1; |
||||||
|
while ((len = inputStream.read(buffer)) != -1) { |
||||||
|
outputStream.write(buffer, 0, len); |
||||||
|
} |
||||||
|
} catch (IOException e) { |
||||||
|
LogKit.error(e, e.getMessage()); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (outputStream != null) { |
||||||
|
outputStream.close(); |
||||||
|
} |
||||||
|
if (inputStream != null) { |
||||||
|
inputStream.close(); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
LogKit.error(e, e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
LogKit.info("读到了资源为" + outputStream.toString()); |
||||||
|
} |
||||||
|
|
||||||
|
private void printAllResource(Map<Integer, Set<String>> allResource) { |
||||||
|
try { |
||||||
|
Iterator<Map.Entry<Integer, Set<String>>> it = allResource.entrySet().iterator(); |
||||||
|
while (it.hasNext()) { |
||||||
|
Map.Entry<Integer, Set<String>> entry = it.next(); |
||||||
|
LogKit.info("导出数据类型:" + entry.getKey()); |
||||||
|
LogKit.info("id集合:" + new ObjectMapper().writeValueAsString(entry.getValue())); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
LogKit.error(e, e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue