├── .github
└── workflows
│ ├── build.yaml
│ ├── milestone.yaml
│ └── release.yaml
├── .gitignore
├── .mvn
├── jvm.config
└── wrapper
│ └── maven-wrapper.properties
├── Jenkinsfile
├── LICENSE.txt
├── README.markdown
├── core
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── springframework
│ │ └── plugin
│ │ └── core
│ │ ├── OrderAwarePluginRegistry.java
│ │ ├── Plugin.java
│ │ ├── PluginRegistry.java
│ │ ├── PluginRegistrySupport.java
│ │ ├── SimplePluginRegistry.java
│ │ ├── config
│ │ ├── EnablePluginRegistries.java
│ │ ├── PluginRegistriesBeanDefinitionRegistrar.java
│ │ └── package-info.java
│ │ ├── package-info.java
│ │ └── support
│ │ ├── PluginRegistryFactoryBean.java
│ │ └── package-info.java
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── plugin
│ │ └── core
│ │ ├── OrderAwarePluginRegistryUnitTest.java
│ │ ├── SamplePlugin.java
│ │ ├── SamplePluginHost.java
│ │ ├── SamplePluginImplementation.java
│ │ ├── SimplePluginRegistryUnitTest.java
│ │ ├── config
│ │ ├── EnablePluginRegistriesIntegrationTest.java
│ │ └── PluginConfigurationIntegrationTest.java
│ │ └── support
│ │ └── OrderAwarePluginRegistryIntegrationTest.java
│ └── resources
│ └── logback.xml
├── etc
└── mappings.txt
├── mvnw
├── mvnw.cmd
├── pom.xml
├── settings.xml
└── src
└── main
└── resources
├── license.txt
└── notice.txt
/.github/workflows/build.yaml:
--------------------------------------------------------------------------------
1 | name: CI Build
2 |
3 | on:
4 | push:
5 | branches: [ main, 4.0.x ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | build:
11 | name: Build project
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 |
16 | - name: Check out sources
17 | uses: actions/checkout@v4
18 |
19 | - name: Set up JDK 23
20 | uses: actions/setup-java@v4
21 | with:
22 | distribution: 'temurin'
23 | java-version: 23
24 | cache: 'maven'
25 |
26 | - name: Build and deploy to Artifactory
27 | env:
28 | ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
29 | ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
30 | run: ./mvnw -B clean deploy -Pci,artifactory,nullaway
31 |
--------------------------------------------------------------------------------
/.github/workflows/milestone.yaml:
--------------------------------------------------------------------------------
1 | name: Release Milestones
2 |
3 | on:
4 | push:
5 | branches: [ release/milestone ]
6 |
7 | jobs:
8 | build:
9 | name: Release project
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 |
14 | - name: Check out sources
15 | uses: actions/checkout@v2
16 |
17 | - name: Set up JDK 17
18 | uses: actions/setup-java@v2
19 | with:
20 | distribution: 'temurin'
21 | java-version: 17
22 | cache: 'maven'
23 |
24 | - name: Build with Maven
25 | run: ./mvnw -B clean verify
26 |
27 | - name: Deploy to Artifactory
28 | env:
29 | ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
30 | ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
31 | run: ./mvnw -B clean deploy -Pci,artifactory
32 |
--------------------------------------------------------------------------------
/.github/workflows/release.yaml:
--------------------------------------------------------------------------------
1 | name: Release to Maven Central
2 |
3 | on:
4 | push:
5 | branches: [ release/release ]
6 |
7 | jobs:
8 | build:
9 | name: Release project
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 |
14 | - name: Check out sources
15 | uses: actions/checkout@v4
16 |
17 | - name: Set up JDK 17
18 | uses: actions/setup-java@v4
19 | with:
20 | distribution: 'temurin'
21 | java-version: 17
22 | cache: 'maven'
23 |
24 | - name: Install GPG key
25 | run: |
26 | echo "${{ secrets.GPG_PRIVATE_KEY }}" > gpg.asc
27 | echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --passphrase-fd 0 --import gpg.asc
28 |
29 | - name: Release to Sonatype OSSRH
30 | env:
31 | SONATYPE_USER: ${{ secrets.OSSRH_S01_TOKEN_USERNAME }}
32 | SONATYPE_PASSWORD: ${{ secrets.OSSRH_S01_TOKEN_PASSWORD }}
33 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
34 | run: |
35 | ./mvnw -B clean install -DskipTests
36 | ./mvnw -B clean deploy -Pci,sonatype -s settings.xml
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings/
4 | .springBeans
5 | target/
6 | .idea
7 | *.iml
8 | .flattened-pom.xml
9 |
--------------------------------------------------------------------------------
/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2 | --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3 | --add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4 | --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5 | --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6 | --add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7 | --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8 | --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9 | --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10 | --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
11 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | wrapperVersion=3.3.2
18 | distributionType=only-script
19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
20 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent none
3 |
4 | triggers {
5 | pollSCM 'H/10 * * * *'
6 | }
7 |
8 | options {
9 | disableConcurrentBuilds()
10 | buildDiscarder(logRotator(numToKeepStr: '14'))
11 | }
12 |
13 | stages {
14 | stage("test: baseline (JDK 17)") {
15 | agent {
16 | docker {
17 | image 'openjdk:17'
18 | args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
19 | }
20 | }
21 | options { timeout(time: 30, unit: 'MINUTES') }
22 | steps {
23 | sh 'rm -rf ?'
24 | sh 'PROFILE=none ci/test.sh'
25 | }
26 | }
27 |
28 | stage('Deploy to Artifactory') {
29 | agent {
30 | docker {
31 | image 'openjdk:17'
32 | args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
33 | }
34 | }
35 | options { timeout(time: 20, unit: 'MINUTES') }
36 |
37 | environment {
38 | ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
39 | }
40 |
41 | steps {
42 | script {
43 | sh 'rm -rf ?'
44 |
45 | // Warm up this plugin quietly before using it.
46 | sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'
47 |
48 | // Extract project's version number
49 | PROJECT_VERSION = sh(
50 | script: 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO',
51 | returnStdout: true
52 | ).trim()
53 |
54 | RELEASE_TYPE = 'milestone' // .RC? or .M?
55 |
56 | if (PROJECT_VERSION.endsWith('SNAPSHOT')) {
57 | RELEASE_TYPE = 'snapshot'
58 | } else if (PROJECT_VERSION.endsWith('RELEASE')) {
59 | RELEASE_TYPE = 'release'
60 | }
61 |
62 | // Capture build output...
63 | OUTPUT = sh(
64 | script: "PROFILE=ci,${RELEASE_TYPE} ci/build.sh",
65 | returnStdout: true
66 | ).trim()
67 |
68 | echo "$OUTPUT"
69 |
70 | // ...to extract artifactory build info
71 | build_info_path = OUTPUT.split('\n')
72 | .find { it.contains('Artifactory Build Info Recorder') }
73 | .split('Saving Build Info to ')[1]
74 | .trim()[1..-2]
75 |
76 | // Stash the JSON build info to support promotion to bintray
77 | dir(build_info_path + '/..') {
78 | stash name: 'build_info', includes: "*.json"
79 | }
80 | }
81 | }
82 | }
83 | stage('Promote to Bintray') {
84 | when {
85 | branch 'release'
86 | }
87 | agent {
88 | docker {
89 | image 'openjdk:17'
90 | args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
91 | }
92 | }
93 | options { timeout(time: 20, unit: 'MINUTES') }
94 |
95 | environment {
96 | ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
97 | }
98 |
99 | steps {
100 | script {
101 | sh 'rm -rf ?'
102 |
103 | // Warm up this plugin quietly before using it.
104 | sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'
105 |
106 | PROJECT_VERSION = sh(
107 | script: 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO',
108 | returnStdout: true
109 | ).trim()
110 |
111 | if (PROJECT_VERSION.endsWith('RELEASE')) {
112 | unstash name: 'build_info'
113 | sh "ci/promote-to-bintray.sh"
114 | } else {
115 | echo "${PROJECT_VERSION} is not a candidate for promotion to Bintray."
116 | }
117 | }
118 | }
119 | }
120 | stage('Sync to Maven Central') {
121 | when {
122 | branch 'release'
123 | }
124 | agent {
125 | docker {
126 | image 'openjdk:17'
127 | args '-v $HOME/.m2:/tmp/jenkins-home/.m2'
128 | }
129 | }
130 | options { timeout(time: 20, unit: 'MINUTES') }
131 |
132 | environment {
133 | BINTRAY = credentials('Bintray-spring-operator')
134 | SONATYPE = credentials('oss-token')
135 | }
136 |
137 | steps {
138 | script {
139 | sh 'rm -rf ?'
140 |
141 | // Warm up this plugin quietly before using it.
142 | sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version'
143 |
144 | PROJECT_VERSION = sh(
145 | script: 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO',
146 | returnStdout: true
147 | ).trim()
148 |
149 | if (PROJECT_VERSION.endsWith('RELEASE')) {
150 | unstash name: 'build_info'
151 | sh "ci/sync-to-maven-central.sh"
152 | } else {
153 | echo "${PROJECT_VERSION} is not a candidate for syncing to Maven Central."
154 | }
155 | }
156 | }
157 | }
158 | }
159 |
160 | post {
161 | changed {
162 | script {
163 | slackSend(
164 | color: (currentBuild.currentResult == 'SUCCESS') ? 'good' : 'danger',
165 | channel: '#spring-hateoas',
166 | message: "${currentBuild.fullDisplayName} - `${currentBuild.currentResult}`\n${env.BUILD_URL}")
167 | emailext(
168 | subject: "[${currentBuild.fullDisplayName}] ${currentBuild.currentResult}",
169 | mimeType: 'text/html',
170 | recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']],
171 | body: "${currentBuild.fullDisplayName} is reported as ${currentBuild.currentResult}")
172 | }
173 | }
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | https://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | https://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 | =======================================================================
204 |
205 | To the extent any open source subcomponents are licensed under the EPL and/or other
206 | similar licenses that require the source code and/or modifications to
207 | source code to be made available (as would be noted above), you may obtain a
208 | copy of the source code corresponding to the binaries for such open source
209 | components and modifications thereto, if any, (the "Source Files"), by
210 | downloading the Source Files from https://www.springsource.org/download,
211 | or by sending a request, with your name and address to: VMware, Inc., 3401 Hillview
212 | Avenue, Palo Alto, CA 94304, United States of America or email info@vmware.com. All
213 | such requests should clearly specify: OPEN SOURCE FILES REQUEST, Attention General
214 | Counsel. VMware shall mail a copy of the Source Files to you on a CD or equivalent
215 | physical medium. This offer to obtain a copy of the Source Files is valid for three
216 | years from the date you acquired this Software product.
217 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # The smallest plugin system ever
2 |
3 | ## Preface
4 |
5 | ### Introduction
6 |
7 | Building extensible architectures nowadays is a core principle to create maintainable applications. This is why fully fledged plugin environments like *OSGi* are so popular these days. Unfortunately the introduction of *OSGi* introduces a lot of complexity to projects.
8 |
9 | Spring Plugin provides a more pragmatic approach to plugin development by providing the core flexibility of having plugin implementations extending a core system's functionality but of course not delivering core OSGi features like dynamic class loading or runtime installation and deployment of plugins. Although Spring Plugin thus is not nearly as powerful as OSGi, it serves a poor man's requirements to build a modular
10 | extensible application.
11 |
12 | ### Context
13 |
14 | - You want to build an extensible architecture minimizing overhead as much as possible
15 | - You cannot use OSGi as fully fledged plugin architecture for whatever reasons
16 | - You want to express extensibility by providing dedicated plugin interfaces
17 | - You want to extend the core system by simply providing an implementation of the plugin interface bundled in a JAR file and available in the classpath
18 | - (You use Spring in your application)
19 |
20 | The last point actually is not essential although Spring Plugin gains a
21 | lot of momentum in collaborative use with Spring.
22 |
23 | ### Technologies
24 |
25 | #### Spring
26 |
27 | Spring is the de-facto standard application framework for Java applications. Its consistent programming model, easy configuration and wide support for all kinds of third party libraries makes it the first class citizen of application frameworks. Spring Plugin tightly integrates into Spring's component model and extends the core container
28 | with some custom functionality.
29 |
30 | ## Core
31 |
32 | ### Introduction
33 |
34 | Host system provides a plugin interface providers have to implement.
35 | Core system is build to hold a container of instances of this interface
36 | and works with them.
37 |
38 | **Example 1.1. Basic example of plugin interface and host**
39 |
40 | ```java
41 | /**
42 | * Interface contract for the providers to be implemented.
43 | */
44 | public interface MyPluginInterface {
45 | public void bar();
46 | }
47 |
48 |
49 | /**
50 | * A host application class working with instances of the plugin
51 | * interface.
52 | */
53 | public class HostImpl implements Host {
54 |
55 | private final List plugins;
56 |
57 | public HostImpl(List plugins) {
58 | Assert.notNull(plugins);
59 | this.plugins = plugins;
60 | }
61 |
62 | /**
63 | * Some business method actually working with the given plugins.
64 | */
65 | public void someBusinessMethod() {
66 | for (MyPluginInterface plugin : plugins) {
67 | plugin.bar();
68 | }
69 | }
70 | }
71 | ```
72 |
73 | This is the way you would typically construct a host component in general. Leveraging dependency injection via setters allows flexible usage in a variety of environments. Thus you could easily provide a factory class that is able to lookup `MyPluginInterface`
74 | implementations from the classpath, instantiate them and inject them into `HostImpl`.
75 |
76 | Using Spring as component container you could configure something like this:
77 |
78 | **Example 1.2. Configuring HostImpl with Spring**
79 |
80 | ```xml
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | ```
89 |
90 | This is pretty much well known to Spring developers and let's us face the wall that this is rather static. Everytime you want to add a new plugin implementation instance you have to modify configuration of the core. Let's see how we can get this dance a little more.
91 |
92 | ### Collecting Spring beans dynamically
93 |
94 | With the `BeanListBeanFactory` Spring Plugin provides a Spring container extension, that allows to lookup beans of a given type in the current `ApplicationContext` and register them as list under a given name. Take a look at the configuration now:
95 |
96 | **Example 1.3. Host and plugin configuration with Spring Plugin
97 | support**
98 |
99 | ```xml
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
111 |
112 |
113 | ```
114 |
115 | ```xml
116 |
117 |
118 | ```
119 |
120 | You can see that we include a wildcarded configuration file that allows plugin projects to easily contribute plugin implementations by declaring them as beans in configuration files matching the wildcarded path. If you use Spring 2.5 component scanning you don't have to use the import trick at all as Spring would detect the implementation automatically as long as it is annotated with `@Component`, `@Service` a.s.o.
121 |
122 | The `BeanListBeanFactory` in turn allows registering a map of lists to be created, where the maps entry key is the id under which the list will be registered and the entry's value is the type to be looked up.
123 |
124 | > #### Note
125 | >
126 | > The design of the `BeanListBeanFactory` might seem a little confusing at first
127 | > (especially to set a map on a property named lists). This is due to the possibility to
128 | > register more than one list to be looked up. We think about dropping this
129 | > functionality for the sake of simplicity in future versions.
130 |
131 | ### A whole lotta XML - namespace to help!
132 |
133 | Actually this already serves a lot of requirements we listed in [Section “Context”](#context). Nevertheless the amount of XML to be written is quite large. Furthermore it's rather not intuitive to configure a bean id as key, and a type as value. We can heavily shrink the XML required to a single line by providing a Spring namespace boiling configuration down to this:
134 |
135 | **Example 1.4. Host configuration using the plugin namespace**
136 |
137 | ```xml
138 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 | ```
153 |
154 | Assuming you have added the namespace XSD into Eclipse and installed Spring IDE, you should get code completion on filling the class attribute.
155 |
156 | ### Using inner beans
157 |
158 | The listing above features an indirection for the `plugin` bean definition. Defining the plugin list as top level bean can have advantages: you easily could place all plugin lists in a dedicated configuration file, presenting all application extension points in one single place. Nevertheless you also might choose to define the list directly in the property declaration:
159 |
160 | **Example 1.5. Using inner bean definition**
161 |
162 | ```xml
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 | ```
171 |
172 | This way you have a more compact configuration, paying the prica of tangling all extention points though possibly various config files.
173 |
174 | #### Plugin beans
175 |
176 | Using plain interfaces and `BeanListBeanFactory` offers an easy way to dynamically lookup beans in Spring environments. Nevertheless, very often you face the situation that you want to have dedicated access to a subset of all plugins, choose plugins by a given criteria or use a decent default plugin or the like. Thus we need a basic infrastructure interface for plugin interfaces to extend and a more sophisticated plugin container.
177 |
178 | #### Plugin
179 |
180 | Hera's central infrastructure interfacte is `Plugin`, where `S` defines the delimiter type you want to let implementations decide on, whether they shall be invoked or not. Thus the plugin implementation have to implement `supports(S delimiter)` to come to the decision. Consider the following example:
181 |
182 | **Example 1.6. Usage of Plugin interface**
183 |
184 | ```java
185 | public enum ProductType {
186 | SOFTWARE, HARDWARE;
187 | }
188 |
189 | public interface ProductProcessor extends Plugin {
190 | public void process(Product product);
191 | }
192 | ```
193 |
194 | This design would allow plugin providers to implement `supports(ProductType productType)` to decide which product types they want to process and provide actual processing logic in `process(Product product)`.
195 |
196 | #### PluginRegistry
197 |
198 | Using a `List` as plugin container as well as the `Plugin` interface you can now select plugins supporting the given delimiter. To not reimplement the lookup logic for common
199 | cases Spring Plugin provides a `PluginRegistry, S>` interface that provides sophisticated methods to access certain plugins:
200 |
201 | **Example 1.7. Usage of the PluginRegistry**
202 |
203 | ```java
204 | PluginRegistry registry = SimplePluginRegistry.of(new FooImplementation());
205 |
206 | // Returns the first plugin supporting SOFTWARE if available
207 | Optional plugin = registry.getPluginFor(ProductType.SOFTWARE);
208 | // Returns the first plugin supporting SOFTWARE, or DefaultPlugin if none found
209 | ProductProcessor plugin = registry.getPluginOrDefaultFor(ProductType.SOFTWARE, () -> new DefaultPlugin());
210 | // Returns all plugins supporting HARDWARE, throwing the given exception if none found
211 | List plugin = registry.getPluginsFor(ProductType.HARDWARE, () -> new MyException("Damn!");
212 | ```
213 |
214 | #### Configuration, XML namespace and @EnablePluginRegistries
215 |
216 | Similar to the `BeanListBeanFactory` described in [Collecting Spring beans
217 | dynamically](#core.beans-dynamically) Spring Plugin provides a `PluginRegistryBeanFactory` to automatically lookup beans of a dedicated type to be aggregated in a `PluginRegistry`. Note that the type has to be assignable to `Plugin` to let the registry work as expected.
218 |
219 | Furthermore there is also an element in the namespace to shrink down configuration XML:
220 |
221 | **Example 1.8. Using the XML namespace to configure a registry**
222 |
223 | ```xml
224 |
225 | ```
226 |
227 | As of version 0.8 creating a `PluginRegistry` can also be achieved using the `@EnablePluginRegistries` annotation:
228 |
229 | ```java
230 | @Configuration
231 | @EnablePluginRegistries(MyPluginInterface.class)
232 | class ApplicationConfiguration { … }
233 | ```
234 |
235 | This configuration snippet will register a `OrderAwarePluginRegistry` for `MyPluginInterface` within the `ApplicationContext` and thus make it available for injection into client beans. The registered bean will be named `myPluginInterfaceRegistry` so that it can be explicitly referenced on the client side using the `@Qualifier` annotation if necessary. The bean name can be customized using `@Qualifier` on the plugin interface definition.
236 |
237 | ### Ordering plugins
238 |
239 | Declaring plugin beans sometimes it is necessary to preserve a certain order of plugins. Suppose you have a plugin host that already defines one plugin that shall always be executed after all plugins declared by extensions. Actually the Spring container typically returns beans in the order they were declared, so that you could import you wildcarded config files right before declaring the default plugin. Unfortunately the order of the beans is not contracted to be preserved for the Spring container. Thus we need a different solution.
240 |
241 | Spring provides two ways to order beans. First, you can implement `Ordered` interface and implement `getOrder` to place a plugin at a certain point in the list. Secondly you can user the `@Order` annotation. For more information on ordering capabilities of Spring see the [section on this topic in the Spring reference documentation](https://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/core/Ordered.html).
242 |
243 | Using the Spring Plugin namespace you will get a `PluginRegistry` instance that is capable of preserving the order defined by the mentioned means. Using Spring Plugin
244 | programmatically use `OrderAwarePluginRegistry`.
245 |
246 | ## Metadata
247 |
248 | For plugin architectures it is essential to capture metadata information about plugin instances. A very core set of metadata (name, version) also serves as identifier of a plugin and thus can be used. The Spring Plugin metadata module provides support to capture metadata.
249 |
250 | ### Core concepts
251 |
252 | The metadata module actually builds around two core interfaces, `PluginMetadata` and `MetadataProvider`:
253 |
254 | **Example 2.1. Core concepts**
255 |
256 | ```java
257 | public interface PluginMetadata {
258 | String getName();
259 | String getVersion();
260 | }
261 |
262 | public interface MetadataProvider {
263 | PluginMetadata getMetadata();
264 | }
265 | ```
266 |
267 | The `PluginMetadata` interface captures the required properties to define an identifiable plugin. This means, that implementations should ensure uniqueness through these two properties. With `SimplePluginMetadata` Spring Plugin provides a Java bean style class to capture metadata. Of course applications can and should provide extended metadata information according to their needs. The very narrow interface is only targeted at integrating the metadata concept with the `PluginRegistry` (see [the section called “PluginRegistry”](#core.plugin-registry)) without bothering developers with too much information required.
268 |
269 | The `MetadataProvider` interface is to be used in application plugin interfaces to indicate that they can provide metadata. To ease plugin implementation we provide
270 | `AbstractMetadataBasedPlugin` that uses the internal metadata to implement `supports(…)` method of `Plugin`. Extending this base class plugins with metadata as selection criteria can easily be build. This way you could store the metadata in user specific configuration files and use this to select a distinct plugin specific to a given user.
271 |
272 | ## Glossary
273 |
274 |
275 | ### O
276 |
277 | OSGi
278 |
279 | * Open Services Gateway Initiative - a fully fledged plugin runtime environment on top of the Java VM - [https://en.wikipedia.org/wiki/OSGi](https://en.wikipedia.org/wiki/OSGi).
280 |
281 | ### X
282 |
283 | XML
284 |
285 | * eXtensible Markup Language
286 |
287 | XSD
288 |
289 | * Xml Schema Definition
290 |
--------------------------------------------------------------------------------
/core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | spring-plugin-core
6 |
7 | Spring Plugin - Core
8 | Core plugin infrastructure
9 |
10 |
11 | org.springframework.plugin
12 | spring-plugin
13 | 4.0.0-SNAPSHOT
14 |
15 |
16 |
17 | spring.plugin.core
18 |
19 |
20 |
21 |
22 |
23 | src/main/resources
24 | true
25 |
26 |
27 | ../src/main/resources
28 | true
29 | META-INF
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework
38 | spring-beans
39 | ${spring.version}
40 |
41 |
42 |
43 | org.springframework
44 | spring-context
45 | ${spring.version}
46 |
47 |
48 |
49 | org.springframework
50 | spring-aop
51 | ${spring.version}
52 |
53 |
54 |
55 | org.springframework
56 | spring-test
57 | ${spring.version}
58 | test
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/core/src/main/java/org/springframework/plugin/core/OrderAwarePluginRegistry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.springframework.plugin.core;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.Collections;
21 | import java.util.Comparator;
22 | import java.util.List;
23 | import java.util.function.Supplier;
24 |
25 | import org.springframework.core.annotation.AnnotationAwareOrderComparator;
26 | import org.springframework.util.Assert;
27 | import org.springframework.util.function.SingletonSupplier;
28 |
29 | /**
30 | * {@link PluginRegistry} implementation that be made aware of a certain ordering of {@link Plugin}s. By default it
31 | * orders {@link Plugin}s by regarding {@link org.springframework.core.Ordered} interface or
32 | * {@link org.springframework.core.annotation.Order} annotation. To alter ordering behaviour use one of the factory
33 | * methods accepting a {@link Comparator} as parameter.
34 | *
35 | * @author Oliver Gierke
36 | */
37 | public class OrderAwarePluginRegistry, S> extends SimplePluginRegistry {
38 |
39 | /**
40 | * Comparator regarding {@link org.springframework.core.Ordered} interface or
41 | * {@link org.springframework.core.annotation.Order} annotation.
42 | */
43 | static final Comparator