Browse Source

S3云存储配置插件

master 1.1.0
richie 5 years ago
commit
d7adb2318d
  1. 10
      .gitignore
  2. 122
      build.gradle
  3. 13
      encrypt.xml
  4. 22
      plugin.xml
  5. 25
      readme.md
  6. BIN
      screenshots/s3cloud.png
  7. 22
      src/main/java/com/fanruan/cloud/s3/shared/S3CloudSharedInitializer.java
  8. 15
      src/main/java/com/fanruan/cloud/s3/shared/S3CloudSharedLocaleFinder.java
  9. 126
      src/main/java/com/fanruan/cloud/s3/shared/config/S3CloudSharedConfig.java
  10. 5
      src/main/resources/com/fanruan/cloud/s3/shared/locale/s3cloud.properties
  11. 5
      src/main/resources/com/fanruan/cloud/s3/shared/locale/s3cloud_en_US.properties
  12. 5
      src/main/resources/com/fanruan/cloud/s3/shared/locale/s3cloud_zh_CN.properties

10
.gitignore vendored

@ -0,0 +1,10 @@
*.iml
.idea/
lib/report/*.jar
target/
.DS_Store
.gradle
build
local.properties
classes/
transform-classes/

122
build.gradle

@ -0,0 +1,122 @@
apply plugin: 'java'
ext {
/**
* jar的路径
* 1.jar需要打包到zip中,lib根目录下
* 2.jar仅仅是编译时需要lib下子目录下即可
*/
libPath = "$projectDir/../webroot/WEB-INF/lib"
/**
* class进行加密保护
*/
guard = false
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"
}
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){
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>

22
plugin.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fanruan.cloud.s3.shared.config</id>
<name><![CDATA[S3资源仓库]]></name>
<main-package>com.fanruan.cloud</main-package>
<active>yes</active>
<hidden>no</hidden>
<version>1.1.0</version>
<env-version>10.0</env-version>
<jartime>2020-01-27</jartime>
<vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储共享配置。]]></description>
<change-notes><![CDATA[
[2020-06-18]初始化插件。<br/>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fanruan.cloud.s3.shared.S3CloudSharedLocaleFinder"/>
</extra-core>
<lifecycle-monitor class="com.fanruan.cloud.s3.shared.S3CloudSharedInitializer"/>
<!--功能记录点类-->
<function-recorder class="com.fanruan.cloud.s3.shared.config.S3CloudSharedConfig"/>
</plugin>

25
readme.md

@ -0,0 +1,25 @@
# S3共享配置
## 插件依赖
当其他插件也需要配置S3云存储时,就可以直接依赖该插件,只需要在plugin.xml中声明依赖关系:
```
<dependence>
<item type="plugin" key="com.fanruan.cloud.s3.shared.config">
</dependence>
```
## API接口
```
S3CloudSharedConfig config = com.fanruan.cloud.s3.shared.config.S3CloudSharedConfig.getInstance();
// 获取EndPoint
config.getEndpoint();
// 获取AccessKeyId
config.getAccessKeyId();
// 获取AccessKeySecret
config.getRealAccessKeySecret();
```
进入 决策平台->管理系统->系统管理->常规 设置界面,可以配置S3云存储相关参数。
![s3cloud](screenshots/s3cloud.png)

BIN
screenshots/s3cloud.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

22
src/main/java/com/fanruan/cloud/s3/shared/S3CloudSharedInitializer.java

@ -0,0 +1,22 @@
package com.fanruan.cloud.s3.shared;
import com.fanruan.cloud.s3.shared.config.S3CloudSharedConfig;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/18
*/
public class S3CloudSharedInitializer extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
S3CloudSharedConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

15
src/main/java/com/fanruan/cloud/s3/shared/S3CloudSharedLocaleFinder.java

@ -0,0 +1,15 @@
package com.fanruan.cloud.s3.shared;
import com.fr.stable.fun.impl.AbstractLocaleFinder;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/18
*/
public class S3CloudSharedLocaleFinder extends AbstractLocaleFinder {
@Override
public String find() {
return "com/fanruan/cloud/s3/shared/locale/s3cloud";
}
}

126
src/main/java/com/fanruan/cloud/s3/shared/config/S3CloudSharedConfig.java

@ -0,0 +1,126 @@
package com.fanruan.cloud.s3.shared.config;
import com.fr.config.ConfigContext;
import com.fr.config.DefaultConfiguration;
import com.fr.config.Identifier;
import com.fr.config.Status;
import com.fr.config.Visualization;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.intelli.record.Focus;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.StringUtils;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/18
* 共享的S3配置包括EndpointaccessKeyaccessSecretKey
*/
@Visualization(category = "Plugin-S3Cloud_Shared_Config")
@SuppressWarnings("all")
@EnableMetrics
public class S3CloudSharedConfig extends DefaultConfiguration {
private static final String PASSWORD_HOLDER = "*************";
private static volatile S3CloudSharedConfig config = null;
public static S3CloudSharedConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(S3CloudSharedConfig.class);
}
return config;
}
@Identifier(value = "region", name = "Region", description = "Plugin-S3Cloud_Shared_Region", status = Status.SHOW)
private Conf<String> region = Holders.simple(StringUtils.EMPTY);
// 地域节点配置信息
@Identifier(value = "endpoint", name = "Endpoint", description = "Plugin-S3Cloud_Shared_End_Point", status = Status.SHOW)
private Conf<String> endpoint = Holders.simple(StringUtils.EMPTY);
@Identifier(value = "accessKeyId", name = "AccessKeyId", description = "Plugin-S3Cloud_Shared_AccessKeyId", status = Status.SHOW)
private Conf<String> accessKeyId = Holders.simple(StringUtils.EMPTY);
@Identifier(value = "accessKeySecret", name = "AccessKeySecret", description = "Plugin-S3Cloud_Shared_AccessKeySecret", status = Status.SHOW)
private Conf<String> accessKeySecret = Holders.simple(StringUtils.EMPTY);
public String getRegion() {
return region.get();
}
public void setRegion(String region) {
this.region.set(region);
}
/**
* 获取地域信息
* @return 地域信息
*/
public String getEndpoint() {
return endpoint.get();
}
/**
* 设置地域信息
* @param endpoint S3存储所在的地域
*/
@Focus(id="com.fanruan.cloud.s3.shared.config", text = "Plugin-S3Cloud_Shared_Config")
public void setEndpoint(String endpoint) {
this.endpoint.set(endpoint);
}
/**
* 获取账号
* @return 账号
*/
public String getAccessKeyId() {
return accessKeyId.get();
}
/**
* 设置账号
* @param accessKeyId 账号
*/
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId.set(accessKeyId);
}
/**
* 获取密码
* @return 密码
*/
public String getRealAccessKeySecret() {
return accessKeySecret.get();
}
/**
* 获取密码
* @return 密码
*/
public String getAccessKeySecret() {
return PASSWORD_HOLDER;
}
/**
* 设置密码
* @param accessKeySecret 密码
*/
public void setAccessKeySecret(String accessKeySecret) {
if (PASSWORD_HOLDER.equals(accessKeySecret)) {
return;
}
this.accessKeySecret.set(accessKeySecret);
}
@Override
public Object clone() throws CloneNotSupportedException {
S3CloudSharedConfig cloned = (S3CloudSharedConfig) super.clone();
cloned.region = (Conf<String>) region.clone();
cloned.endpoint = (Conf<String>) endpoint.clone();
cloned.accessKeyId = (Conf<String>) accessKeyId.clone();
cloned.accessKeySecret = (Conf<String>) accessKeySecret.clone();
return cloned;
}
}

5
src/main/resources/com/fanruan/cloud/s3/shared/locale/s3cloud.properties

@ -0,0 +1,5 @@
Plugin-S3Cloud_Shared_Config=S3 Shared Config
Plugin-S3Cloud_Shared_Region=Region
Plugin-S3Cloud_Shared_End_Point=Endpoint
Plugin-S3Cloud_Shared_AccessKeyId=AccessKeyId
Plugin-S3Cloud_Shared_AccessKeySecret=AccessKeySecret

5
src/main/resources/com/fanruan/cloud/s3/shared/locale/s3cloud_en_US.properties

@ -0,0 +1,5 @@
Plugin-S3Cloud_Shared_Config=S3 Shared Config
Plugin-S3Cloud_Shared_Region=Region
Plugin-S3Cloud_Shared_End_Point=Endpoint
Plugin-S3Cloud_Shared_AccessKeyId=AccessKeyId
Plugin-S3Cloud_Shared_AccessKeySecret=AccessKeySecret

5
src/main/resources/com/fanruan/cloud/s3/shared/locale/s3cloud_zh_CN.properties

@ -0,0 +1,5 @@
Plugin-S3Cloud_Shared_Config=S3\u5171\u4EAB\u914D\u7F6E
Plugin-S3Cloud_Shared_Region=Region
Plugin-S3Cloud_Shared_End_Point=Endpoint
Plugin-S3Cloud_Shared_AccessKeyId=AccessKeyId
Plugin-S3Cloud_Shared_AccessKeySecret=AccessKeySecret
Loading…
Cancel
Save