Wiki source code of Maven XAR Plugin

Last modified by Vincent Massol on 2021/04/09 18:01

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 This build tool allows creating XAR files, expanding XAR files, reformatting them and verifying some best practices.
6
7 = XAR Mojo =
8
9 To configure it:
10
11 * Register a new Maven Lifecycle in your POM:(((
12 {{code language="xml"}}
13 ...
14 <build>
15 <extensions>
16 <extension>
17 <groupId>org.xwiki.commons</groupId>
18 <artifactId>xwiki-commons-tool-xar-handlers</artifactId>
19 <version>...version here...</version>
20 </extension>
21 </extensions>
22 ...
23 {{/code}}
24 )))
25 * Create a Maven POM file with the ##xar## packaging: {{code language="xml"}}<packaging>xar</packaging>{{/code}}
26 * Put the wiki pages as XML files in ##src/main/resources## by having directories matching space names. For example:(((
27 {{image reference="structure.png"/}}
28 )))
29
30 To use it:
31
32 * ##mvn xar:xar## will generate the XAR file
33
34 == Transformations ==
35
36 It is also possible to perform transformations on the XML files. For example:
37
38 === Insert a text value ===
39
40 This can work well, for example, to change skin definitions. E.g.:
41
42 {{code language="xml"}}
43 <plugin>
44 <groupId>org.xwiki.commons</groupId>
45 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
46 <configuration>
47 <transformations>
48 <transformation>
49 <file>Blog/WebHome.xml</file>
50 <xpath>/xwikidoc/object/property/itemsPerPage</xpath>
51 <value>100</value>
52 </transformation>
53 <transformation>
54 <artifact>org.xwiki.platform:xwiki-platform-administration-ui</artifact>
55 <file>XWiki/XWikiPreferences.xml</file>
56 <xpath>/xwikidoc/object/property/colorTheme</xpath>
57 <value>ColorThemes.Mint</value>
58 </transformation>
59 </transformations>
60 </configuration>
61 </plugin>
62 {{/code}}
63
64 === Manipulate XML elements ===
65
66 {{info}}Since 9.5RC1{{/info}} it is possible to remove/replace/insert a complete XML element. Here is an example:
67
68 {{code language="xml"}}
69 <plugin>
70 <groupId>org.xwiki.commons</groupId>
71 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
72 <configuration>
73 <transformations>
74 <!-- Insert the content of file src/xar/transformations/ckeditor.xml
75 as child of xwikidoc element in XWiki/XWikiPreferences.xml -->
76 <transformation>
77 <artifact>org.xwiki.platform:xwiki-platform-distribution-ui-base</artifact>
78 <file>XWiki/XWikiPreferences.xml</file>
79 <xpath>xwikidoc</xpath>
80 <action>INSERT_CHILD</action>
81 <xml>src/xar/transformations/ckeditor.xml</xml>
82 </transformation>
83 <!-- Remove first attachments from XWiki/XWikiPreferences.xml -->
84 <transformation>
85 <artifact>org.xwiki.platform:xwiki-platform-distribution-ui-base</artifact>
86 <xpath>xwikidoc/attachment</xpath>
87 <action>REMOVE</action>
88 </transformation>
89 </transformations>
90 </configuration>
91 </plugin>
92 {{/code}}
93
94 === Insert Text Content of a File ===
95
96 {{info}}Since 11.4RC1{{/info}} it is possible to insert the text of another project file. This works well to insert complex JavaScript, Velocity or CSS files. These files, if they are not named ##.xml## stay within the same directory and will be ignored unless they are inserted and can thus be edited with an integrated development environment (which brings syntax coloring, auto-completion, reformatting, or validation). Here is an example:
97
98 {{code language="xml"}}
99 <plugin>
100 <groupId>org.xwiki.commons</groupId>
101 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
102 <configuration>
103 <transformations>
104 <transformation>
105 <!-- Insert the content of file src/main/resources/MyApp/config.js
106 as the value of the property code in the first object of class
107 XWiki.JavaScriptExtension of the XML file MyApp/Config.xml -->
108 <action>INSERT_TEXT</action>
109 <file>MyApp/Config.xml</file>
110 <xpath>/xwikidoc/object[className[text()='XWiki.JavaScriptExtension']]/property/code</xpath>
111 <content>src/main/resources/MyApp/config.js</content>
112 </transformation>
113 </transformations>
114 </configuration>
115 </plugin>
116 {{/code}}
117
118
119 === Insert an Attachment ===
120
121 {{info}}Since 11.4RC1{{/info}} it is possible to insert the content of another project file as an attachment in Base64 encoding just as XWiki would do it in an XML file of a XAR. You can use this to insert files with the same name edited somewhere else. Doing so, it also updates the filesize attribute. Here is an example:
122
123 {{code language="xml"}}
124 <plugin>
125 <groupId>org.xwiki.commons</groupId>
126 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
127 <configuration>
128 <transformations>
129 <transformation>
130 <!-- Insert the content of file src/main/resources/MyApp/testcolors.xls
131 as the attachment of the page TestDocumentList of the space MyApp -->
132 <action>INSERT_ATTACHMENT_CONTENT</action>
133 <file>MyApp/TestDocumentList.xml</file>
134 <xpath>/xwikidoc/attachment[/filename[text()='testcolors.xls']]</xpath>
135 <content>src/main/resources/MyApp/testcolors.xls</content>
136 </transformation>
137 </transformations>
138 </configuration>
139 </plugin>
140 {{/code}}
141
142 == Documents types ==
143
144 {{info}}
145 Since 10.3
146 {{/info}}
147
148 It's possible to indicate in the pom.xml the [[type>>extensions:Extension.Extension Module.Extensions.XAR||anchor="HStandardtypes"]] of a each document. That way the [[##package.xml##>>extensions:Extension.XAR Module Specifications||anchor="Hpackage.xml"]] will be generated automatically but will take into account information it cannot really deduce from the documents XML files.
149
150 {{code}}
151 <plugin>
152 <groupId>org.xwiki.commons</groupId>
153 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
154 <configuration>
155 <entries>
156 <entry>
157 <document>Main.WebHome</document>
158 <type>home</type>
159 </entry>
160 <entry>
161 <document>Some.Demo.Page</document>
162 <type>demo</type>
163 </entry>
164 <entry>
165 <document>MyApplication.MyConfiguration</document>
166 <type>configuration</type>
167 </entry>
168 </entries>
169 </configuration>
170 </plugin>
171 {{/code}}
172
173 {{info}}Since 12.7{{/info}} You can provide the option {{code}}<defaultEntryType>myEntryType</defaultEntryType>{{/code}} in the configuration of the plugin. When defined, the default enty type will be applied to every entry not being overridden through the {{code}}<entries>...</entries>{{/code}} list in the plugin configuration.
174
175 {{warning}}
176 You should only provide one {{code}}<document>{{/code}} per {{code}}<entry>{{/code}}. For example, the following configuration will not work :
177
178 {{code}}
179 <entries>
180 <entry>
181 <document>MySpace.MyPage1</document>
182 <document>MySpace.MyPage1</document>
183 <type>demo</type>
184 </entry>
185 </entries>
186 {{/code}}
187
188 Instead, you should write :
189
190 {{code}}
191 <entries>
192 <entry>
193 <document>MySpace.MyPage1</document>
194 <type>demo</type>
195 </entry>
196 <entry>
197 <document>MySpace.MyPage2</document>
198 <type>demo</type>
199 </entry>
200 </entries>
201 {{/code}}
202
203 {{/warning}}
204
205 = Format & Verify Mojo =
206
207 {{info}}12.3RC1{{/info}}There are 4 types of pages that can be defined using regexes:
208
209 * Technical Pages: This is the default. It means pages must be hidden and not have any default language set.
210 * Content Pages: These are pages having content and that can have translations. These pages must not be hidden and must have a non-empty default language (so that the XWiki search return results for them when the English language is selected in language facet for example). Example:(((
211 {{code language="xml"}}
212 <plugin>
213 <groupId>org.xwiki.commons</groupId>
214 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
215 <configuration>
216 <contentPages>
217 <contentPage>.*/Space[1-9]*/WebHome\.xml</contentPage>
218 </contentPages>
219 </configuration>
220 </plugin>
221 {{/code}}
222 )))
223 * Translatable Pages: These are technical pages but that can have translations. It means pages must be hidden and have a non-empty default language. When not specified it defaults to ##.*/.*Translations\.xml##, which corresponds to XWiki platform's best practice for naming wiki translation pages. Override example:(((
224 {{code language="xml"}}
225 <plugin>
226 <groupId>org.xwiki.commons</groupId>
227 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
228 <configuration>
229 <translatablePages>
230 <translatablePage>.*/Translations\.xml</translatablePage>
231 </translatablePages>
232 </configuration>
233 </plugin>
234 {{/code}}
235 )))
236 * Visible Technical Pages: These are technical pages but that must be visible but that shouldn't return results in Search. For example, home pages of applications. They must not be hidden but they must have their default language set to empty. Example:(((
237 {{code language="xml"}}
238 <plugin>
239 <groupId>org.xwiki.commons</groupId>
240 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
241 <configuration>
242 <visibleTechnicalPages>
243 <visibleTechnicalPage>.*/Space/WebHome\.xml</visibleTechnicalPage>
244 </visibleTechnicalPages>
245 </configuration>
246 </plugin>
247 {{/code}}
248 )))
249
250 = Format Mojo =
251
252 [[Older documentation for versions < 12.3RC1>>||queryString="rev=30.1#HFormatMojo"]].
253
254 To use the mojo:
255
256 * ##mvn xar:format## will perform some cleaning of your XML files, namely:
257 ** Indent lines (using 2 space characters)
258 ** Set ##author##, ##contentAuthor##, ##creator## and attachment ##author##s to be ##xwiki:XWiki.Admin##
259 ** Set ##version## to be 1.1
260 ** Set ##minorEdit## to be false
261 ** Remove any content of the ##defaultLanguage## element unless the document has translations, or it's marked as a ##translatablePage## or it's marked as a ##contentPage## (see above).
262 ** Remove any content of the ##comment## element
263 ** Add any missing license header by using the license defined in ##xwiki-commons-tool-verification-resources## JAR. License headers will be checked if the ##formatLicense## configuration parameter is set to true:(((
264 {{code language="xml"}}
265 <plugin>
266 <groupId>org.xwiki.commons</groupId>
267 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
268 <version>${commons.version}</version>
269 <configuration>
270 <!-- Add missing license headers by default -->
271 <formatLicense>true</formatLicense>
272 </configuration>
273 </plugin>
274 {{/code}}
275 )))
276 ** Technical pages are marked hidden. Same for translatable pages.
277 ** {{version since="10.8RC1"}}Remove any ##date##, ##creationDate##, ##contentUpdateDate## or attachment ##date## fields, regardless if they have empty values or not. This is done because it's causing confusion for users to install pages that are created in 2005/2009/etc. so we should avoid committing dates on git that users might end up installing.{{/version}}
278 *** Can be disabled for individual pages with either ##-Dxar.dates.skip.documentList=Space1.Subspace2.Page1,Space2.Subspace2.Page2,etc.## (system property) or ##<skipDatesDocumentList>Space1.Subspace2.Page1,Space2.Subspace2.Page2,etc.</skipDatesDocumentList>## (plugin configuration parameter).
279 *** Can be disabled for all pages in the xar with either ##-Dxar.dates.skip=true## (system property) or ##<skipDates>true</skipDates>## (plugin configuration parameter).
280 ** {{version since="13.3RC1"}}Forces the XML version to be 1.1{{/version}}
281
282 = Verify Mojo =
283
284 [[Older documentation for versions < 12.3RC1>>||queryString="rev=30.1#HVerifyMojo"]].
285
286 This is used to fail the build if the XML pages don't conform to the following rules:
287
288 * Verify that the encoding is UTF-8
289 * Verify that ##author##, ##contentAuthor##, ##creator## and attachment ##author##s are set to ##xwiki:XWiki.Admin##
290 * Verify that the ##parent## field is not empty (except for ##Main.WebHome##). This check became optional (and turned off by default) in XWiki 11.10.3 & 12.0RC1.
291 ** To turn if on, set ##<emptyParentSkip>false</emptyParentSkip>## in the POM or pass ##-Dxar.verify.translationVisibility.skip=false## on the Maven command line
292 * Verify that ##version## is set to 1.1
293 * Verify that ##comment## is empty
294 * Verify that ##minorEdit## is set to false
295 * Verify that the ##defaultLanguage## is empty for technical documents and ##visibleTechnicalPage##s (see above).
296 * Verify that the ##defaultLanguage## is not empty for ##contentPage##s and ##translatablePage##s (see above) and it matches the configured language in the mojo (by default ##en##, it's configurable in the ##<configuration>##, for example ##<defaultLanguage>fr</defaultLanguage>##).
297 * (optional) Verify that the XML files contain license headers (if the ##formatLicense## configuration property is set to ##true##).
298 * Verify that technical pages, and ##translatablePage##s are set as hidden, and that ##contentPage##s and ##translatablePage##s are set as npot hidden.
299 * Verify that defined pages have a specific matching title. For example:(((
300 {{code language="xml"}}
301 <plugin>
302 <groupId>org.xwiki.commons</groupId>
303 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
304 ...
305 <configuration>
306 ...
307 <titles>
308 <!-- Verify that all WebPreferences pages have the same title for consistency -->
309 <property>
310 <name>.*WebPreferences</name>
311 <value>\$services\.localization\.render\('admin.preferences.title'\)</value>
312 </property>
313 </titles>
314 </configuration>
315 </plugin>
316 {{/code}}
317 )))
318 * Verify that Translations pages (i.e. documents with a ##XWiki.TranslationDocumentClass## xobject) are using the ##plain/1.0## syntax.
319 * {{info}}New in 10.1RC1{{/info}} Verify that Translations pages don't have a GLOBAL or USER visibility (USER makes no sense and GLOBAL would require Programming Rights, which is an issue in farm-based use cases). This check can be ignore by using the ##translationVisibilitySkip## configuration option (or ##xar.verify.translationVisibility.skip## on the command line).
320 * {{info}}New in 10.6RC1{{/info}} Verify that attachments have a mimetype set. If the mimetype is missing then the attachment won't be filterable in the attachment view in Page Index.
321 * {{info}}New in 10.8RC1{{/info}} Verify that any ##date##, ##creationDate##, ##contentUpdateDate## or attachment ##date## fields are not specified, thus risking to import pages with stale dates.
322 ** Can be disabled for individual pages with either ##-Dxar.dates.skip.documentList=Space1.Subspace2.Page1,Space2.Subspace2.Page2,etc.## (system property) or ##<skipDatesDocumentList>Space1.Subspace2.Page1,Space2.Subspace2.Page2,etc.</skipDatesDocumentList>## (plugin configuration parameter).
323 ** Can be disabled for all pages in the xar with either ##-Dxar.dates.skip=true## (system property) or ##<skipDates>true</skipDates>## (plugin configuration parameter).
324 * {{info}}New in 13.1RC1 and 12.10.4{{/info}} Verify that translated pages don't contain any attachment.
325 * {{info}}New in 13.1RC1 and 12.10.4{{/info}} Verify that translated pages don't contain any object.
326
327 Example usage:
328
329 {{code language="xml"}}
330 <plugin>
331 <groupId>org.xwiki.commons</groupId>
332 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
333 <executions>
334 <execution>
335 <goals>
336 <goal>verify</goal>
337 </goals>
338 </execution>
339 </executions>
340 </plugin>
341 {{/code}}
342
343 To skip the execution of the verify mojo, you can use the property ##xar.verify.skip## with the value ##true##.
344
345 = UnXAR Mojo =
346
347 To configure it:
348
349 {{code language="xml"}}
350 <plugin>
351 <groupId>org.xwiki.commons</groupId>
352 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
353 <configuration>
354 <groupId>...group id of XAR artifact to expand...</groupId>
355 <artifactId>...artifact id of XAR artifact to expand...</artifactId>
356 <outputDirectory>${project.build.outputDirectory}</outputDirectory>
357 <includes>
358 <include>Space/Page.xml</include>
359 ...
360 </includes>
361 <excludes>
362 <exclude>Space/Page.xml</exclude>
363 ...
364 </excludes>
365 </configuration>
366 </plugin>
367 {{/code}}
368
369 To use it:
370
371 * ##mvn unxar## will expand the XAR file

Get Connected