Changes for page Plugin-Entwicklung


From version 1.2
edited by awa
on 25.02.2022, 14:54
Change comment: There is no comment for this version
To version 1.1
edited by gru
on 20.01.2021, 16:18
Change comment: Imported from XAR

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.awa
1 +XWiki.gru
Content
... ... @@ -1,8 +1,8 @@
1 1  {{content/}}
2 2  
3 -Plugins let you extend {{formcycle/}} and add new features. Various different [[plugin type>>doc:Formcycle.PluginDevelopment.Types.WebHome]] exist, such as plugins for adding custom workflow actions ands triggers, or plugins for new form elements.
3 +== Plugins for extending {{formcycle/}} ==
4 4  
5 -A plugin must be a JAR file with the appropriate class files. To create a custom plugin, you need to setup a Java project, such as via Maven.
5 +Many services and functions of {{formcycle/}} can be customized and extended by using plugins. Each [[plugin type>>doc:Formcycle.PluginDevelopment.Types.WebHome]] extends a certain aspect of {{formcycle/}}, such as workflow processing or preprocessing forms. To create a custom plugin, you need to setup a Java project first of all.
6 6  
7 7  == API documentation ==
8 8  
... ... @@ -10,266 +10,134 @@
10 10  
11 11  == Project setup ==
12 12  
13 -To get started with developing plugins, you need to create and configure new project.
13 +Setup a new Java project with the IDE of your choice. {{formcycle/}} uses the build management system [[Apache Maven>>url:https://maven.apache.org/]]) to resolve dependencies. Dependencies are provided by our public artifactory {{code language="none"}}http://artifactory.xima-services.de/artifactory/fc-plugin-dev{{/code}}. It contains all components needed for developing plugins. The main artifact you will need is the artifact [[fc-plugin-common>>url:http://artifactory.xima-services.de/artifactory/fc-plugin-dev/de/xima/fc/fc-plugin-common/]], containing all Java interfaces available for plugins.
14 14  
15 -We recommend the build tool [[Apache Maven>>url:https://maven.apache.org/||rel="__blank"]]. Other build tools such as Gradle are possible, but you will not find any help for those tools here.
15 +Maven uses configuration files named {{code language="none"}}pom.xml{{/code}} (project object model). A pom for plugin development might look as follows:
16 16  
17 -To access the {{formcycle case="dat"/}} dependencies, you need to use the Maven repository [[https:~~/~~/artifactory.xima-services.de/artifactory/fc-plugin-dev>>url:https://artifactory.xima-services.de/artifactory/fc-plugin-dev]]. This contains all Maven artifacts required for developing plugins.
18 -
19 -To get Maven to recognize that repository, add it tot the Maven configuration file //settings.xml//. Usually, you can find this settings file in the //.m2// folder in your home directory, i.e. //~~/.m2/settings.xml// for Linux and //%homepath%\.m2\settings.xml// for Windows:
20 -
21 -{{panel title="~~~~/.m2/settings.xml" fullwidth="true" initial="hidden" triggerable="true"}}
17 +{{panel title="Example for a pom.xml" initial="hidden" triggerable="true" fullwidth="true"}}
22 22  {{code language="xml"}}
23 -<?xml version="1.0" encoding="UTF-8"?>
24 -<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
25 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
19 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
26 26  
27 - <!-- Add XIMA artifactory -->
28 - <profiles>
29 - <profile>
30 - <!-- FORMCYCLE dependencies -->
31 - <repositories>
32 - <repository>
33 - <snapshots>
34 - <enabled>false</enabled>
35 - </snapshots>
36 - <id>xima</id>
37 - <name>fc-plugin-dev</name>
38 - <url>https://artifactory.xima-services.de/artifactory/fc-plugin-dev</url>
39 - </repository>
40 - </repositories>
41 - <!-- Maven plugins for FORMCYCLE -->
42 - <pluginRepositories>
43 - <pluginRepository>
44 - <snapshots>
45 - <enabled>false</enabled>
46 - </snapshots>
47 - <id>xima</id>
48 - <name>fc-plugin-dev</name>
49 - <url>https://artifactory.xima-services.de/artifactory/fc-plugin-dev</url>
50 - </pluginRepository>
51 - </pluginRepositories>
52 - <id>xima-artifactory</id>
53 - </profile>
54 - </profiles>
22 +...
55 55  
56 - <!-- Enable XIMA artifactory by default -->
57 - <activeProfiles>
58 - <activeProfile>xima-artifactory</activeProfile>
59 - </activeProfiles>
24 + <properties>
25 + <!-- Configuration -->
26 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
60 60  
61 - <!-- FORMCYCLE specific Maven plugins provided by XIMA -->
62 - <pluginGroups>
63 - <pluginGroup>de.xima.fc.maven.plugin</pluginGroup>
64 - </pluginGroups>
65 -</settings>
66 -{{/code}}
67 -{{/panel}}
28 + <!-- Dependencies -->
29 + <xfc-version>4.2.3</xfc-version>
68 68  
69 -== Maven project setup
31 + <!-- Plugins -->
32 + <maven-compiler-plugin-version>3.3</maven-compiler-plugin-version>
33 + <maven-jar-plugin-version>2.4</maven-jar-plugin-version>
34 + </properties>
70 70  
71 -The following lists a few important steps required for setting up a Maven project for a {{formcycle/}} plugin, but we assume you have basic knowledge of how to work with Maven.
36 + <repositories>
37 + <repository>
38 + <id>xima</id>
39 + <name>fc-plugin-dev</name>
40 + <url>http://artifactory.xima-services.de/artifactory/fc-plugin-dev</url>
41 + </repository>
42 + </repositories>
72 72  
73 -To get started with a plugin, you can also use of of the available [[Maven archetypes>>||anchor="HMaven-Archetypes"]].
44 + <dependencies>
45 + <dependency>
46 + <groupId>de.xima.fc</groupId>
47 + <artifactId>fc-plugin-common</artifactId>
48 + <version>${xfc-version}</version>
49 + <scope>provided</scope>
50 + </dependency>
51 + </dependencies>
74 74  
75 -=== Artekfakte und Abhängigkeiten
53 + <build>
54 + <plugins>
55 + <plugin>
56 + <groupId>org.apache.maven.plugins</groupId>
57 + <artifactId>maven-compiler-plugin</artifactId>
58 + <version>${maven-compiler-plugin-version}</version>
59 + <configuration>
60 + <source>1.7</source>
61 + <target>1.7</target>
62 + <encoding>UTF-8</encoding>
63 + </configuration>
64 + </plugin>
76 76  
77 -{{info}}
78 -All dependencies to {{formcycle/}} must be declared with the scope //provided//.
79 -{{/info}}
66 + <plugin>
67 + <groupId>org.apache.maven.plugins</groupId>
68 + <artifactId>maven-jar-plugin</artifactId>
69 + <version>${maven-jar-plugin-version}</version>
70 + <configuration>
71 + <archive>
72 + <manifest>
73 + <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
74 + </manifest>
75 + <manifestEntries>
76 + <formcycle-version-requirement>${xfc-version}</formcycle-version-requirement>
77 + <Build-Time>${maven.build.timestamp}</Build-Time>
78 + </manifestEntries>
79 + </archive>
80 + </configuration>
81 + </plugin>
80 80  
81 -You can download a complete //pom.xml// for plugin development [[here>>attach:pom.xml||rel="__blank"]].
83 + </plugins>
84 + </build>
85 +</project>
82 82  
83 -The main artifact you need to include is the artifact [[fc-plugin-common>>url:http://artifactory.xima-services.de/artifactory/fc-plugin-dev/de/xima/fc/fc-plugin-common/]]. It contains all Java interfaces available for plugins.
84 -
85 -Add the following to the //pom.xml// of the plugin project to include that artifact:
86 -
87 -{{code language="xml"}}
88 - <properties>
89 - <xfc.version>7.0.10</xfc.version>
90 - </properties>
91 -
92 - <dependencies>
93 - <dependency>
94 - <groupId>de.xima.fc</groupId>
95 - <artifactId>fc-plugin-common</artifactId>
96 - <version>${xfc.version}</version>
97 - <scope>provided</scope>
98 - </dependency>
99 - </dependencies>
100 100  {{/code}}
88 +{{/panel}}
101 101  
102 -For more complicated plugins, you can also include //fc-logic//, which provides more {{formcycle/}} related classes, such as the database access objects when you need to access the database. If you want to use it, replace dependency to //fc-plugin-common// with:
90 +Certain plugins may require additional classes and functionality of the {{formcycle/}} system, which is provided by the artifact //fc-logic//. To add it as a dependency, modify the pom as follows:
103 103  
104 104  {{code language="xml"}}
93 +...
105 105   <dependency>
106 106   <groupId>de.xima.fc</groupId>
107 107   <artifactId>fc-logic</artifactId>
108 - <version>${xfc.version}</version>
97 + <version>${xfc-version}</version>
109 109   <scope>provided</scope>
110 110   </dependency>
100 +...
111 111  {{/code}}
112 112  
113 -Note that all dependencies must be declared with the //provide// scope. This prevents class path issues and keeps the plugin size small. When possible, use libraries already used by {{formcycle/}}, e.g. certain Apache Common libraries or guava.
103 +This artifact becomes necessary especially when working with databases or the [[workflow processing>>doc:Formcycle.PluginDevelopment.Types.IPluginProcessing.WebHome]]. You can also [[download a template for a pom file>>attach:pom.xml||rel="__blank"]] that includes the //fc-logic// artifact.
114 114  
115 -=== Manifest und Fat JAR
105 +{{info}}
106 +For version of {{formcycle/}} earlier than 4.1.1, you need to exclude the non-public dependency on the //aspose-processor// of the //fc-logic// artifact.
107 +{{/info}}
116 116  
117 -The //META-INF/MANIFEST.MF// file in the plugin JAR should contain the following entries:
109 +Furthermore, note that all dependencies must be declared with the //provide// scope. This prevent class path issues and keeps the plugin size small. When possible, use libraries already in use by {{formcycle/}}, eg. certain Apache Common libraries.
118 118  
119 -; formcycle-version-requirement
120 -: Required. The version of {{formcycle/}} against which the plugin was compiled. This is required for {{formcycle/}} to check the compatibility when the plugin is installed.
121 -; Implementation-Version
122 -: Required. The version of the plugin, which is for example shown in the UI.
123 -; Build-Time oder Build-Timestamp
124 -: Optional. This is displayed in the UI when the plugin version is a SNAPSHOT.
125 -; Implementation-Title
126 -: Optional. This is used e.g. by the deploy plugin to identify the plugin.
111 +{{info}}
112 +All dependencies must be declared with the scope //provided//.
113 +{{/info}}
127 127  
128 -You can use the //maven-assembly-plugin// to add these entries to the manifest.
115 +Developing a plugin for {{formcycle/}} can be as simple as implementing one of the plugin interfaces. To install a plugin, upload them on the administrative interface either as a [[client>>doc:Formcycle.UserInterface.Client.Plugins]] or [[system plugin>>doc:Formcycle.SystemSettings.UserInterface.SystemPlugins]].
129 129  
130 -Furthermore, it is required that you create a fat JAR. Dependencies provided by {{formcycle/}} should be declared with the scope //provided//, as mentioned above. However, any additional dependencies that your plugin needs must be included in the JAR file.
117 +== Demo plugins ==
131 131  
132 -This can be done via the [[maven-assembly-plugin>>url:https://maven.apache.org/plugins/maven-assembly-plugin/]] or via the [[maven-shade-plugin>>url:https://maven.apache.org/plugins/maven-shade-plugin/]]. The latter one is meant for advanced use cases, such as when multiple dependencies have conflicting files and you need to merge those.
119 +As an introduction and to help you getting started with developing plugins, we provide several fully commented demo maven projects for each plugin type [[on our download pages>>url:https://customer.formcycle.eu/index.php/s/PgdMrNOvbYEzhmr]]. After downloading them, you can import them into the IDE of your choice, compile them and upload them to {{formcycle/}}.
133 133  
134 -For many plugins, the //maven-assembly-plugin// is sufficient. You can configure this plugin in the //pom.xml// as follows:
121 +== Special terms ==
135 135  
136 -{{panel title="maven-assembly-plugin in pom.xml" fullwidth="true" initial="hidden" triggerable="true"}}
137 -{{code language="java"}}
138 - <properties>
139 - <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
140 - </properties>
141 - <build>
142 - <finalName>${project.artifactId}</finalName>
143 - <plugins>
144 - <plugin>
145 - <groupId>org.apache.maven.plugins</groupId>
146 - <artifactId>maven-assembly-plugin</artifactId>
147 - <version>${maven-assembly-plugin.version}</version>
148 - <executions>
149 - <execution>
150 - <id>fat-jar</id>
151 - <phase>package</phase>
152 - <goals>
153 - <goal>single</goal>
154 - </goals>
155 - <configuration>
156 - <finalName>${project.artifactId}</finalName>
157 - <appendAssemblyId>false</appendAssemblyId>
158 - <descriptorRefs>
159 - <descriptorRef>jar-with-dependencies</descriptorRef>
160 - </descriptorRefs>
161 - <archive>
162 - <manifest>
163 - <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
164 - </manifest>
165 - <manifestEntries>
166 - <formcycle-version-requirement>${xfc-version}</formcycle-version-requirement>
167 - <Build-Timestamp>${maven.build.timestamp}</Build-Timestamp>
168 - <Implementation-Title>${project.groupId}:${project.artifactId}</Implementation-Title>
169 - <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
170 - <Implementation-Version>${project.version}</Implementation-Version>
171 - </manifestEntries>
172 - </archive>
173 - </configuration>
174 - </execution>
175 - </executions>
176 - </plugin>
177 - </plugins>
178 - </build>
179 -{{/code}}
180 -{{/panel}}
123 +Some Java methods and classes contain German technical terms as used by {{formcycle/}}. For reference, see the following list for their English counterparts.
181 181  
182 -=== Build and install ===
125 +{{table dataTypeAlpha="0-1" preSort="0-asc"}}
183 183  
184 -In general, the command to build the plugin depends on the settings in the //pom.xml//. In most cases, however, the following standard command should be enough:
127 +|=German|=English|=Example
128 +|Mandant|[[Client>>doc:Formcycle.SystemSettings.UserInterface.Clients]]|{{code language="Java"}}public Mandant getMandant(){{/code}} (get client)
129 +|Benutzer|[[User>>doc:Formcycle.UserInterface.UserSettings.WebHome]]|{{code language="Java"}}public Benutzer getCurrentBenutzer(){{/code}} (get user currently logged in)
130 +|Projekt|Project, a former term for a //form// containing files and multiple form versions|{{code language="Java"}}public Projekt getProjekt(){{/code}}
131 +|Aktion|[[Action>>doc:Formcycle.UserInterface.MyForms.WorkflowProcessing.Actions.WebHome]] (workflow)|{{code language="Java"}}public Aktion getFolgeAktion(){{/code}} (get next action)
132 +|Weiterverarbeitung|Further processing|{{code language="Java"}}public EWeiterverarbeitung_Aktion getWeiterverarbeitungBeiFehler(){{/code}} (how to continue when an error has occurred)
133 +|Bedingung|[[Condition>>doc:Formcycle.UserInterface.MyForms.WorkflowProcessing.ActionConditions]] (action)|{{code language="Java"}}public Bedingung getBedingung(){{/code}} (get the condition of an action)
134 +|Datei|[[File>>doc:Formcycle.UserInterface.FilesAndTemplates.Files]]|{{code language="Java"}}public FormEingangDatei getDatei(){{/code}} (get attached file)
135 +|Textbaustein|[[Template>>doc:Formcycle.UserInterface.FilesAndTemplates.WebHome]]|{{code language="Java"}}public ETextbausteinKategorie getKategorie(){{/code}} (get template type)
136 +|Vorgang|Form record|{{code language="Java"}}public Postfach getByVorgang(UserContext uc, Vorgang vorgang){{/code}} (get inbox for form record)
137 +|Postfach|[[Inbox>>doc:Formcycle.Inbox.WebHome]]|{{code language="Java"}}public Postfach getCurrentPostfach(){{/code}} (get current inbox)
138 +|Rolle|[[Role>>doc:Formcycle.UserInterface.UserSettings.Roles]]|{{code language="Java"}}public List<Rolle> getRollen(){{/code}} (get all roles for a user)
139 +|Datenquelle|[[Data source>>doc:.Types.IPluginDataSource]]|{{code language="Java"}}public IPluginDataSourceRetVal executeDatenquelle(...){{/code}} (get serializable JSON array from a data source)
140 +|Beschreibung|Description|{{code language="Java"}}public String getBeschreibung(){{/code}}
141 +|Kategory|Category|{{code language="Java"}}public ETextbausteinKategorie getKategorie(){{/code}}
185 185  
186 -{{code}}
187 -mvn clean install
188 -{{/code}}
189 -
190 -This creates a JAR file in the //target// folder. You can then upload this plugin to a running {{formcycle/}} server, either as a [[client plugin>>doc:Formcycle.UserInterface.Client.Plugins]] or as a [[system plugin>>doc:Formcycle.SystemSettings.UserInterface.SystemPlugins]].
191 -
192 -See the [[deploy plugin>>||anchor="HDeployPlugin"]] to upload the plugin to a running {{formcycle/}} server during the Maven build process.
193 -
194 -See the [[FC server plugin>>||anchor="HFCServerPlugin"]] for starting a simple {{formcycle/}} server.
195 -
196 -== Maven-Archetypes ==
197 -
198 -{{figure image="eclipse-archetype.png" width="500"}}
199 - Hinzufügen des Archetypes-Katalogs in Eclipse
200 -{{/figure}}
201 -
202 -{{figure image="eclipse-archetype-select.png" width="500"}}
203 - Auswahl eines Archetypes beim Erstellen eines Maven-Projekts in Eclipse
204 -{{/figure}}
205 -
206 -Für einige häufig verwendete Plugin-Typen stehen [[Maven-Archetypes>>url:https://maven.apache.org/guides/introduction/introduction-to-archetypes.html||target="_blank"]] bereits, um schnell ein Maven-Projekt aufsetzen zu können.
207 -
208 -Voraussetzung für die Verwendung ist, dass in den //~~/.m2/settings.xml// wie oben beschrieben das XIMA-Artifactory eingerichtet wurde. Dann kann etwa über die Kommandozeile wie folgt eine Archetype generiert werden:
209 -
210 -{{code}}
211 -mvn archetype:generate -DarchetypeArtifactId=plugin-archetype-workflow-element-simple -DarchetypeGroupId=de.xima.fc.archetype -DarchetypeVersion=7.0.4
212 -{{/code}}
213 -
214 -Es werden dann einige wenige Informationen wie die gewünschten Maven-Koordinaten des neuen Plugin-Projekts abgefragt und anschließend ein neues vorkonfiguriertes Projekt erstellt.
215 -
216 -Alle vorhandenen Archetypes und deren Versionen können im [[Archetype-Katalog>>url:https://artifactory.xima-services.de/artifactory/libs-release-local/archetype-catalog.xml||target="_blank"]] eingesehen werden.
217 -
218 -In Eclipse kann der Archetype-Katalog in den Einstellungen hinzugefügt werden. Bei der Erstellung eines neuen Maven-Projekt werden dann alle verfügbaren Archetypes angezeigt:
219 -
220 -{{code language="plaintext"}}https://artifactory.xima-services.de/artifactory/libs-release-local/archetype-catalog.xml{{/code}}
221 -
222 -== Deploy-Plugin
223 -
224 -Um beim Entwickeln nicht jedes Mal eine neue Plugin-Version manuell über die Oberfläche hochladen zu müssen, kann das Deploy-Plugin verwendet werden. Dieses besteht aus 2 Teilen:
225 -
226 -* Ein Maven-Plugin, welches nach dem Bauen das Plugin via HTTP an einen laufenden {{formcycle/}}-Server sendet
227 -* Ein Plugin für {{formcycle/}}, welche die Gegenstelle in {{formcycle/}} bereitstellt und das Plugin aus dem HTTP-Request in {{formcycle/}} installiert.
228 -
229 -Weitere Details können im [[Hilfe-Artikel zum Deploy-Plugin>>doc:Formcycle.PluginDocumentation.FormcycleDeployPluginPlugin]] nachgelesen werden. Für die meisten Fälle reicht folgende Konfiguration in der //pom.xml// des Plugin-Projekts aus:
230 -
231 -{{code language="xml"}}
232 - <properties>
233 - <fc-deploy-plugin-maven-plugin.version>7.0.1<fc-deploy-plugin-maven-plugin.version/>
234 - <build>
235 - <plugins>
236 - <plugin>
237 - <groupId>de.xima.fc.maven.plugin</groupId>
238 - <artifactId>fc-deploy-plugin-maven-plugin</artifactId>
239 - <version>${fc-deploy-plugin-maven-plugin.version}</version>
240 - <executions>
241 - <execution>
242 - <id>upload</id>
243 - <phase>install</phase>
244 - <goals>
245 - <goal>deploy</goal>
246 - </goals>
247 - </execution>
248 - </executions>
249 - </plugin>
250 - </plugins>
251 - </build>
252 -{{/code}}
253 -
254 -Sofern das Deploy-Plugin bereits in {{formcycle/}} installiert ist, kann das Plugin-Projekt dann beim Bauen wie folgt hochgeladen werden:
255 -
256 -{{code language="bash"}}
257 -mvn clean install -DfcDeployUrl=http://localhost:8080/xima-formcycle -DfcDeployToken=admin
258 -{{/code}}
259 -
260 -Wird Eclipse benutzt, kann auch eine Launch-Configuration mit den //fcDeployUrl// und dem //fcDeployToken// angelegt werden.
261 -
262 -== FC-Server-Plugin ==
263 -
264 -Zum Testen eines Plugins ist es erforderlich, einen laufenden {{formcycle/}}-Server zu haben. Zur Vereinfachung der Entwicklung gibt es das //fc-server-maven-plugin//, welches mittels eines einzigen Befehls ein fertig eingerichtetes {{formcycle/}} lokal startet, wo auch bereits das Deploy-Plugin vorinstalliert ist.
265 -
266 -Sofern wie oben beschrieben in //~~/.m2/settings.xml// die //pluginGroup// hinterlegt wurde, kann in einem beliebiegen Verzeichnis wie folgt ein {{formcycle/}}-Server per Maven gestartet werden:
267 -
268 -{{code language="bash"}}
269 -mvn fc-server:run-ms-war -DxfcVersion=7.0.10
270 -{{/code}}
271 -
272 -Nach kurzer Wartezeit (beim ersten Mal kann es länger dauern) ist dann ein {{formcycle/}}-Server gestartet. Die URL steht am Ende in der Kommandozeile, standardmäßig http://localhost:8080/xima-formcycle
273 -
274 -Dies funktioniert auch in einem Ordner ohne Maven-Projekt. Falls keine {{formcycle/}} angegeben ist, wird eine Standard-Version genommen. Wird der Befehl innerhalb eines Plugin-Maven-Projekts ausgeführt, wird versucht, die Version von {{formcycle/}} aus dem Plugin-Projekt auszulesen.
275 -
143 +{{/table}}