Browse Source

第二课

master
onlyxx 4 years ago
commit
bfa0246528
  1. 127
      build.gradle
  2. 13
      encrypt.xml
  3. BIN
      lib/gson-2.3.1.jar
  4. 0
      lib/report/.gitkeep
  5. 22
      plugin.xml
  6. 3
      readme.md
  7. 50
      src/main/java/com/fr/plugin/FileDef.java
  8. 20
      src/main/java/com/fr/plugin/JSCSSBridge.java
  9. 6
      src/main/java/com/fr/plugin/MyFunctionConstants.java
  10. 1
      src/main/resources/com/fr/plugin/demo.properties
  11. 1
      src/main/resources/com/fr/plugin/demo_zh_CN.properties
  12. 0
      src/main/resources/com/fr/plugin/web/my.css
  13. 98
      src/main/resources/com/fr/plugin/web/my.js

127
build.gradle

@ -0,0 +1,127 @@
apply plugin: 'java'
ext {
/**
* jar的路径
* 1.jar需要打包到zip中,lib根目录下
* 2.jar仅仅是编译时需要lib下子目录下即可
*/
libPath = "$projectDir/../webroot/WEB-INF/lib"
/**
* class进行加密保护
*/
guard = true
def pluginInfo = getPluginInfo()
pluginPre = "fine-plugin"
pluginName = pluginInfo.id
pluginVersion = pluginInfo.version
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes"
}
group = 'com.fr.plugin'
version = '10.0'
sourceCompatibility = '8'
sourceSets {
main {
java.outputDir = file(outputPath)
output.resourcesDir = file(outputPath)
}
}
ant.importBuild("encrypt.xml")
//ant变量
ant.projectDir = projectDir
ant.references["compile.classpath"] = ant.path {
fileset(dir: libPath, includes: '**/*.jar')
fileset(dir: ".",includes:"**/*.jar" )
}
classes.dependsOn('clean')
task copyFiles(type: Copy,dependsOn: 'classes'){
from outputPath
into "$projectDir/classes"
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){
from "$projectDir/classes"
into "$projectDir/transform-classes"
include "**/*.*"
}
jar.dependsOn("preJar")
task makeJar(type: Jar,dependsOn: preJar){
delete file("$projectDir/classes")
delete file("$projectDir/transform-classes")
from fileTree(dir: "$projectDir/transform-classes")
baseName pluginPre
appendix pluginName
version pluginVersion
destinationDir = file("$buildDir/libs")
doLast(){
delete file("$projectDir/classes")
delete file("$projectDir/transform-classes")
}
}
task copyFile(type: Copy,dependsOn: ["makeJar"]){
from "$buildDir/libs"
from("$projectDir/lib") {
include "*.jar"
}
from "$projectDir/plugin.xml"
into file("$buildDir/temp/plugin")
}
task zip(type:Zip,dependsOn:["copyFile"]){
from "$buildDir/temp/plugin"
destinationDir file("$buildDir/install")
baseName pluginPre
appendix pluginName
version pluginVersion
}
//build时包含哪些文件,
processResources {
// exclude everything
// *.css没效果
// exclude '**/*.css'
// except this file
// include 'xx.xml'
}
/*读取plugin.xml中的version*/
def getPluginInfo(){
def xmlFile = file("plugin.xml")
if (!xmlFile.exists()) {
return ["id":"none", "version":"1.0.0"]
}
def plugin = new XmlParser().parse(xmlFile)
def version = plugin.version[0].text()
def id = plugin.id[0].text()
return ["id":id,"version":version]
}
repositories {
mavenLocal()
maven {
url = uri('http://mvn.finedevelop.com/repository/maven-public/')
}
}
dependencies {
//使jar
implementation fileTree(dir: 'lib', include: ['**/*.jar'])
implementation fileTree(dir: libPath, include: ['**/*.jar'])
}

13
encrypt.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<target name="compile_encrypt_javas" depends="copyFiles">
<echo message="加密文件"/>
<echo message="${projectDir}"/>
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask">
<classpath refid="compile.classpath"/>
</taskdef>
<pretreatment baseDir="${projectDir}"/>
</target>
<target name="compile_plain_javas" depends="copyFiles">
</target>
</project>

BIN
lib/gson-2.3.1.jar

Binary file not shown.

0
lib/report/.gitkeep

22
plugin.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.js.css.inject</id>
<name><![CDATA[JS和CSS注入]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>author</vendor>
<description><![CDATA[注入]]></description>
<change-notes><![CDATA[
[2018-08-01]修改一点问题。<br/>
[2018-07-31]初始化插件。<br/>
]]></change-notes>
<extra-decision>
<WebResourceProvider class="com.fr.plugin.JSCSSBridge"/>
</extra-decision>
<!-- <extra-core>-->
<!-- <FunctionDefineProvider class="com.fr.plugin.MyAbs" name="MyAbs" description="求绝对值,支持数组。"/>-->
<!-- <LocaleFinder class="com.fr.plugin.MyLocaleFinder"/>-->
<!-- </extra-core>-->
<function-recorder class="com.fr.plugin.FileDef"/>
</plugin>

3
readme.md

@ -0,0 +1,3 @@
# 函数插件
该函数可以对一组数值求绝对值。

50
src/main/java/com/fr/plugin/FileDef.java

@ -0,0 +1,50 @@
package com.fr.plugin;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.web.struct.Component;
import com.fr.web.struct.Filter;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
@FunctionRecorder
public class FileDef extends Component {
public static final FileDef KEY = new FileDef();
private FileDef(){}
/**
* 返回需要引入的JS脚本路径
* @param client 请求客户端描述
* @return JS脚本路径
*/
public ScriptPath script( RequestClient client ) {
//如果不需要就直接返回 ScriptPath.EMPTY
return ScriptPath.build("com/fr/plugin/web/my.js");
}
/**
* 返回需要引入的CSS样式路径
* @param client 请求客户端描述
* @return CSS样式路径
*/
public StylePath style( RequestClient client ) {
//如果不需要就直接返回 StylePath.EMPTY;
return StylePath.build("com/fr/plugin/web/my.css");
}
/**
* 通过给定的资源过滤器控制是否加载这个资源
* @return 资源过滤器
*/
@ExecuteFunctionRecord
public Filter filter() {
return new Filter(){
@Override
public boolean accept() {
//任何情况下我们都在平台组件加载时加载我们的组件
return true;
}
};
}
}

20
src/main/java/com/fr/plugin/JSCSSBridge.java

@ -0,0 +1,20 @@
package com.fr.plugin;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
public class JSCSSBridge extends AbstractWebResourceProvider {
@Override
public Atom attach() {
//在平台主组件加载时添加我们自己的组件
return MainComponent.KEY;
}
@Override
public Atom client() {
//我们自己要引入的组件
return FileDef.KEY;
}
}

6
src/main/java/com/fr/plugin/MyFunctionConstants.java

@ -0,0 +1,6 @@
package com.fr.plugin;
public class MyFunctionConstants {
public static final String PLUGIN_ID = "com.fr.plugin.js.css.inject";
}

1
src/main/resources/com/fr/plugin/demo.properties

@ -0,0 +1 @@
Plugin-Test_Function_Abs=Test ABS

1
src/main/resources/com/fr/plugin/demo_zh_CN.properties

@ -0,0 +1 @@
Plugin-Test_Function_Abs=测试ABS函数

0
src/main/resources/com/fr/plugin/web/my.css

98
src/main/resources/com/fr/plugin/web/my.js

@ -0,0 +1,98 @@
(function() {
var e = BI.inherit(BI.Widget, {
props: {
baseCls: "",
items: []
},
render: function() {
var e = this.options;
return this.storeValue = BI.deepClone(e.items),
{
type: "bi.vertical",
bgap: 10,
items: this._createItems(e.items)
}
},
_createItems: function(e) {
var n = this
, o = BI.Services.getService("dec.service.data.set")
, s = [DecCst.Common.Parameter.Type.BOOLEAN, DecCst.Common.Parameter.Type.DATE];
return BI.map(e, function(t, e) {
var i = {
width: 150,
cls: BI.contains(s, e.type) ? "" : "bi-border"
};
return {
type: "bi.vertical_adapt",
items: [{
type: "bi.label",
cls: "dec-font-weight-bold",
textAlign: "left",
width: 75,
text: e.name,
title: e.name,
rgap: 5
}, BI.extend(i, o.createParameterValueItem(e, function(e) {
n.storeValue[t].value = e
}))]
}
})
},
getValue: function() {
return this.storeValue
}
});
BI.shortcut("dec.data.set.parameters.popup", e)
}(),
function() {
var e = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-directory-detail-items-add",
columns: 2,
rows: 1,
items: []
},
render: function() {
var e = this.options;
var items=BI.filter(e.items,function (e,t){
if(t!=="dec.directory.right.add.template"){
return true;
}
return false;
});
return {
type: "bi.vertical",
vgap: 15,
hgap: 15,
items: [{
el: {
type: "bi.grid",
columns: e.columns,
rows: 1,
height: 120,
items: BI.map(items, function(e, t) {
return {
column: e,
row: 0,
el: {
type: t
}
}
})
}
}]
}
},
getValue: function() {
return {}
},
populate: function(e) {}
});
BI.shortcut("dec.directory.detail_items.add.zzl", e)
BI.config("dec.directory.detail_items.add", function (options) {
options.type = "dec.directory.detail_items.add.zzl"; // 将组件的type替换为自定义的组件
return options;
});
}());
Loading…
Cancel
Save