You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2021/10/17 01:12:30 UTC

[incubator-eventmesh] branch develop updated: [ISSUE #550] Deduplicate plugin jar (#558)

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/develop by this push:
     new a4a4a9f  [ISSUE #550] Deduplicate plugin jar (#558)
a4a4a9f is described below

commit a4a4a9f90998c905f72f1505375fd75e08f98cb5
Author: Wenjun Ruan <we...@apache.org>
AuthorDate: Sun Oct 17 09:12:22 2021 +0800

    [ISSUE #550] Deduplicate plugin jar (#558)
    
    * Deduplicate plugin jar
    
    * Remove example in dist
    
    * Add DuplicatesStrategy.EXCLUDE when copy dist/conf
    
    * Remove eventmesh lib from lib
---
 build.gradle                                       | 153 +++++++++++----------
 .../instructions/eventmesh-runtime-quickstart.md   |  28 ++--
 .../instructions/eventmesh-runtime-quickstart.md   |  24 +++-
 .../eventmesh-connector-api/build.gradle           |   4 +-
 .../eventmesh-connector-rocketmq/build.gradle      |   2 +-
 .../eventmesh-connector-standalone/build.gradle    |   2 +-
 .../eventmesh-registry-api/build.gradle            |   2 +-
 .../eventmesh-registry-namesrv/build.gradle        |   2 +-
 .../eventmesh-security-acl/build.gradle            |   2 +-
 .../eventmesh-security-api/build.gradle            |   2 +-
 10 files changed, 127 insertions(+), 94 deletions(-)

diff --git a/build.gradle b/build.gradle
index 32efd44..f39914f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -99,6 +99,45 @@ task zip(type: Zip) {
     }
 }
 
+task installPlugin() {
+    if (!new File("${rootDir}/dist").exists()) {
+        return
+    }
+    // pluginType -> [pluginInstanceName -> moduleName]
+    Map<String, Map<String, String>> pluginTypeMap = [
+            "connector": ["rocketmq": "eventmesh-connector-rocketmq", "standalone": "eventmesh-connector-standalone",],
+            "security" : ["acl": "eventmesh-security-acl",],
+            "registry" : ["namesrv": "eventmesh-registry-namesrv",]
+    ]
+    String[] libJars = java.util.Optional.ofNullable(new File("${rootDir}/dist/lib").list()).orElseGet(() -> new String[0])
+    getAllprojects().forEach(subProject -> {
+        pluginTypeMap.forEach((pluginType, pluginInstanceMap) -> {
+            pluginInstanceMap.forEach((pluginInstanceName, moduleName) -> {
+                if (moduleName == subProject.name) {
+                    println String.format("install plugin, pluginType: %s, pluginInstanceName: %s, module: %s",
+                            pluginType, pluginInstanceName, moduleName)
+
+                    new File("${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}").mkdirs()
+                    copy {
+                        into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
+                        from "${subProject.getProjectDir()}/dist/apps"
+                    }
+                    copy {
+                        into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
+                        from "${subProject.getProjectDir()}/dist/lib/"
+                        exclude(libJars)
+                    }
+                    copy {
+                        into "${rootDir}/dist/conf"
+                        from "${subProject.getProjectDir()}/dist/conf"
+                        exclude 'META-INF'
+                    }
+                }
+            })
+        })
+    })
+}
+
 subprojects {
 
     apply plugin: "io.spring.dependency-management"
@@ -187,90 +226,62 @@ subprojects {
         }
     }
 
-    // pluginType:
-    //      pluginInstanceName:
-    //            moduleName
-    Map<String, Map<String, String>> pluginTypeMap = [
-            "connector": [
-                    "rocketmq"  : "eventmesh-connector-rocketmq",
-                    "standalone": "eventmesh-connector-standalone",
-            ],
-            "security" : [
-                    "acl": "eventmesh-security-acl",
-            ],
-            "registry" : [
-                    "namesrv": "eventmesh-registry-namesrv",
-            ]
-    ]
-
     task dist(dependsOn: ['jar']) {
         doFirst {
-            new File(projectDir, '../dist/bin').mkdirs()
-            new File(projectDir, '../dist/apps').mkdirs()
-            new File(projectDir, '../dist/conf').mkdirs()
-            new File(projectDir, '../dist/lib').mkdirs()
+            new File("${projectDir}/dist/bin").mkdirs()
+            new File("${projectDir}/dist/apps").mkdirs()
+            new File("${projectDir}/dist/conf").mkdirs()
+            new File("${projectDir}/dist/lib").mkdirs()
         }
-
+        Set<String> rootProject = ["eventmesh-admin",
+                                   "eventmesh-common",
+                                   "eventmesh-connector-api",
+                                   "eventmesh-registry-api",
+                                   "eventmesh-runtime",
+                                   "eventmesh-security-api",
+                                   "eventmesh-starter",
+                                   "eventmesh-spi"]
         doLast {
-            pluginTypeMap.forEach((pluginType, pluginInstanceMap) -> {
-                pluginInstanceMap.forEach((pluginInstanceName, moduleName) -> {
-                    if (moduleName == project.name) {
-                        println String.format("install plugin, pluginType: %s, pluginInstanceName: %s, module: %s",
-                                pluginType, pluginInstanceName, moduleName)
-                        new File("${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}").mkdirs()
-                        copy {
-                            into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
-                            from project.jar.getArchivePath()
-                        }
-                        copy {
-                            into "${rootDir}/dist/plugin/${pluginType}/${pluginInstanceName}"
-                            from project.configurations.runtimeClasspath
-                        }
-                        copy {
-                            into "${rootDir}/dist/conf"
-                            from sourceSets.main.resources.srcDirs
-                            exclude 'META-INF'
-                        }
-                    }
-                })
-            })
-
             copy {
-                into('../dist/apps/')
+                into("${projectDir}/dist/apps")
                 from project.jar.getArchivePath()
-//                exclude 'eventmesh-common*.jar'
-//                exclude 'eventmesh-connector-api*.jar'
-//                exclude 'eventmesh-connector-plugin*.jar'
-//                exclude 'eventmesh-admin*.jar'
-//                exclude 'eventmesh-starter*.jar'
-//                exclude 'eventmesh-test*.jar'
-//                exclude 'eventmesh-sdk*.jar'
             }
             copy {
-                into '../dist/lib'
+                into("${projectDir}/dist/lib")
                 from project.configurations.runtimeClasspath
-                exclude '**/*.properties*'
-                exclude '**/*testng*.jar'
-                exclude '**/*powermock*.jar'
-                exclude '**/*mockito*.jar'
-                exclude '**/*junit*.jar'
-                exclude '**/*jacoco*.jar'
-                exclude '**/*log4j2.xml*'
-                exclude '**/spring-boot-devtools*.jar'
-                exclude '**/mumble-sdk-test*.jar'
-                exclude 'eventmesh*.jar'
-//                exclude 'eventmesh-runtime*.jar'
-                exclude 'commons-collections-3.2.2.jar'
             }
-
             copy {
-                into '../dist/bin'
-                from '../eventmesh-runtime/bin'
+                into("${projectDir}/dist/bin")
+                from 'bin'
             }
-
             copy {
-                into '../dist/conf'
-                from '../eventmesh-runtime/conf'
+                into("${projectDir}/dist/conf")
+                from 'conf', sourceSets.main.resources.srcDirs
+                setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
+                exclude 'META-INF'
+            }
+            if (rootProject.contains(project.name)) {
+                new File("${rootDir}/dist/apps").mkdirs()
+                new File("${rootDir}/dist/lib").mkdirs()
+                new File("${rootDir}/dist/bin").mkdirs()
+                new File("${rootDir}/dist/conf").mkdirs()
+                copy {
+                    into("${rootDir}/dist/apps")
+                    from "${projectDir}/dist/apps"
+                }
+                copy {
+                    into "${rootDir}/dist/lib"
+                    from "${projectDir}/dist/lib"
+                    exclude "eventmesh-*"
+                }
+                copy {
+                    into "${rootDir}/dist/bin"
+                    from "${projectDir}/dist/bin"
+                }
+                copy {
+                    into "${rootDir}/dist/conf"
+                    from "${projectDir}/dist/conf"
+                }
             }
         }
     }
diff --git a/docs/cn/instructions/eventmesh-runtime-quickstart.md b/docs/cn/instructions/eventmesh-runtime-quickstart.md
index 684a0f6..d0982a7 100644
--- a/docs/cn/instructions/eventmesh-runtime-quickstart.md
+++ b/docs/cn/instructions/eventmesh-runtime-quickstart.md
@@ -68,22 +68,26 @@ sh start.sh
 > 插件实例需要在对应模块中的/main/resources/META-INF/eventmesh 下配置相关接口与实现类的映射文件,文件名为SPI接口全类名.
 > 文件内容为插件实例名到插件实例的映射, 具体可以参考eventmesh-connector-rocketmq插件模块
 
-插件可以从classpath和插件目录下面加载. 在本地开发阶段可以将使用的插件在eventmesh-starter模块build.gradle中进行声明,或者执行gradle的dist任务
-将插件拷贝至dist/plugin目录下, eventmesh默认会加载项目下dist/plugin目录下的插件, 加载目录可以通过-DeventMeshPluginDir=your_plugin_directory来改变插件目录.
-运行时需要使用的插件实例可以在eventmesh.properties中进行配置.如果需要使用rocketmq插件实行快速启动,需要在eventmesh-starter模块build.gradle中进行如下声明
-```
-   implementation project(":eventmesh-connector-plugin:eventmesh-connector-rocketmq")
-```
+**2.3.2 插件说明**
 
-**2.3.2 配置插件**
+***2.3.2.1 安装插件***
 
-在`eventMesh.properties`配置文件通过声明式的方式来指定项目启动后需要加载的插件
-
-修改`confPath`目录下面的`eventMesh.properties`文件
+有两种方式安装插件
+- classpath加载:本地开发可以通过在eventmesh-starter模块build.gradle中进行声明,例如声明使用rocketmq插件
+```java
+   implementation project(":eventmesh-connector-plugin:eventmesh-connector-rocketmq")
+```
+- 文件加载:通过将插件安装到插件目录,EventMesh在运行时会根据条件自动加载插件目录下的插件,可以通过执行以下命令安装插件
+```shell
+./gradlew clean jar dist
+./gradlew installPlugin
+```
 
-加载**RocketMQ Connector**插件配置:
+***2.3.2.2 使用插件***
 
-```java
+EventMesh会默认加载dist/plugin目录下的插件,可以通过`-DeventMeshPluginDir=your_plugin_directory`来改变插件目录。运行时需要使用的插件实例可以在
+`confPath`目录下面的`eventmesh.properties`中进行配置。例如通过以下设置声明在运行时使用rocketmq插件。
+```properties
 #connector plugin
 eventMesh.connector.plugin.type=rocketmq
 ```
diff --git a/docs/en/instructions/eventmesh-runtime-quickstart.md b/docs/en/instructions/eventmesh-runtime-quickstart.md
index dd33e72..a35ebbd 100644
--- a/docs/en/instructions/eventmesh-runtime-quickstart.md
+++ b/docs/en/instructions/eventmesh-runtime-quickstart.md
@@ -57,13 +57,31 @@ Same with 1.2
 
 **2.3.1 Configure plugin**
 
-Specify the connector plugin that will be loaded after the project start by declaring in `eventMesh.properties`
+***2.3.1.1 Install Plugin***
 
-Modify the `eventMesh.properties` file in the `confPath` directory
+There are two ways to install the plugin:
+- Install from classpath: Local development can be done by declaring in the eventmesh-starter module build.gradle, for example
+ by declaring the use of rocketmq plugin
+```java
+   implementation project(":eventmesh-connector-plugin:eventmesh-connector-rocketmq")
+```
+
+- Install from files: By installing the plugin into the plugin directory, EventMesh will automatically load the plugins in the plugin directory
+ according to the conditions when EventMesh running, you can install the plugins by executing the following command.
+```shell
+./gradlew clean jar dist
+./gradlew installPlugin
+```
+
+***2.3.1.2 Use Plugin***
+
+EventMesh will default load plugins installed in `dist/plugin`, you can change the plugin directory by `-DeventMeshPluginDir=your_plugin_directory`.
+The plugin instance to be used at runtime can be configured in the `eventmesh.properties` at the `confPath` directory.
+Example you can declare use rocketmq by following config. 
 
 ```java
 #connector plugin, default standalone, can be rocketmq
-eventMesh.connector.plugin.type=standalone
+eventMesh.connector.plugin.type=rocketmq
 ```
 
 **2.3.2 Configure VM Options**
diff --git a/eventmesh-connector-plugin/eventmesh-connector-api/build.gradle b/eventmesh-connector-plugin/eventmesh-connector-api/build.gradle
index 962a46a..19cb54c 100644
--- a/eventmesh-connector-plugin/eventmesh-connector-api/build.gradle
+++ b/eventmesh-connector-plugin/eventmesh-connector-api/build.gradle
@@ -16,8 +16,8 @@
  */
 
 dependencies {
-    compileOnly project(":eventmesh-spi")
-    compileOnly project(":eventmesh-common")
+    implementation project(":eventmesh-spi")
+    implementation project(":eventmesh-common")
     api 'io.openmessaging:openmessaging-api'
     api 'io.dropwizard.metrics:metrics-core'
     api "io.dropwizard.metrics:metrics-healthchecks"
diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/build.gradle b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/build.gradle
index 7f603d8..52f4c31 100644
--- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/build.gradle
+++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/build.gradle
@@ -45,7 +45,7 @@ List rocketmq = [
 
 dependencies {
     compileOnly project(":eventmesh-common")
-    implementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
+    compileOnly project(":eventmesh-connector-plugin:eventmesh-connector-api")
     implementation rocketmq
 
     testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/build.gradle b/eventmesh-connector-plugin/eventmesh-connector-standalone/build.gradle
index 74fec4d..6152c89 100644
--- a/eventmesh-connector-plugin/eventmesh-connector-standalone/build.gradle
+++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/build.gradle
@@ -17,7 +17,7 @@
 
 dependencies {
     compileOnly project(":eventmesh-common")
-    implementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
+    compileOnly project(":eventmesh-connector-plugin:eventmesh-connector-api")
 
     testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
     testImplementation project(":eventmesh-common")
diff --git a/eventmesh-registry-plugin/eventmesh-registry-api/build.gradle b/eventmesh-registry-plugin/eventmesh-registry-api/build.gradle
index 926cdba..594503e 100644
--- a/eventmesh-registry-plugin/eventmesh-registry-api/build.gradle
+++ b/eventmesh-registry-plugin/eventmesh-registry-api/build.gradle
@@ -16,7 +16,7 @@
  */
 
 dependencies {
-    compileOnly project(":eventmesh-spi")
+    implementation project(":eventmesh-spi")
 
     testImplementation project(":eventmesh-spi")
 }
diff --git a/eventmesh-registry-plugin/eventmesh-registry-namesrv/build.gradle b/eventmesh-registry-plugin/eventmesh-registry-namesrv/build.gradle
index 33422de..8471545 100644
--- a/eventmesh-registry-plugin/eventmesh-registry-namesrv/build.gradle
+++ b/eventmesh-registry-plugin/eventmesh-registry-namesrv/build.gradle
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 dependencies {
-    implementation project(":eventmesh-registry-plugin:eventmesh-registry-api")
+    compileOnly project(":eventmesh-registry-plugin:eventmesh-registry-api")
 
     testImplementation project(":eventmesh-registry-plugin:eventmesh-registry-api")
 }
\ No newline at end of file
diff --git a/eventmesh-security-plugin/eventmesh-security-acl/build.gradle b/eventmesh-security-plugin/eventmesh-security-acl/build.gradle
index 1ee3c75..af9362e 100644
--- a/eventmesh-security-plugin/eventmesh-security-acl/build.gradle
+++ b/eventmesh-security-plugin/eventmesh-security-acl/build.gradle
@@ -16,7 +16,7 @@
  */
 
 dependencies {
-    implementation project(":eventmesh-security-plugin:eventmesh-security-api")
+    compileOnly project(":eventmesh-security-plugin:eventmesh-security-api")
 
     testImplementation project(":eventmesh-security-plugin:eventmesh-security-api")
 }
diff --git a/eventmesh-security-plugin/eventmesh-security-api/build.gradle b/eventmesh-security-plugin/eventmesh-security-api/build.gradle
index 926cdba..594503e 100644
--- a/eventmesh-security-plugin/eventmesh-security-api/build.gradle
+++ b/eventmesh-security-plugin/eventmesh-security-api/build.gradle
@@ -16,7 +16,7 @@
  */
 
 dependencies {
-    compileOnly project(":eventmesh-spi")
+    implementation project(":eventmesh-spi")
 
     testImplementation project(":eventmesh-spi")
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org