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 <content>src/main/resources/MyApp/testcolors.xls</content>
135 </transformation>
136 </transformations>
137 </configuration>
138 </plugin>
139 {{/code}}
140
141 == Documents types ==
142
143 {{info}}
144 Since 10.3
145 {{/info}}
146
147 It's possible to indicate in the pom.xml the type 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.
148
149 {{code}}
150 <plugin>
151 <groupId>org.xwiki.commons</groupId>
152 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
153 <configuration>
154 <entries>
155 <entry>
156 <document>Main.WebHome</document>
157 <type>home</type>
158 </entry>
159 <entry>
160 <document>Some.Demo.Page</document>
161 <type>demo</type>
162 </entry>
163 <entry>
164 <document>MyApplication.MyConfiguration</document>
165 <type>configuration</type>
166 </entry>
167 </entries>
168 </configuration>
169 </plugin>
170 {{/code}}
171
172 {{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.
173
174 {{warning}}
175 You should only provide one {{code}}<document>{{/code}} per {{code}}<entry>{{/code}}. For example, the following configuration will not work :
176
177 {{code}}
178 <entries>
179 <entry>
180 <document>MySpace.MyPage1</document>
181 <document>MySpace.MyPage1</document>
182 <type>demo</type>
183 </entry>
184 </entries>
185 {{/code}}
186
187 Instead, you should write :
188
189 {{code}}
190 <entries>
191 <entry>
192 <document>MySpace.MyPage1</document>
193 <type>demo</type>
194 </entry>
195 <entry>
196 <document>MySpace.MyPage2</document>
197 <type>demo</type>
198 </entry>
199 </entries>
200 {{/code}}
201
202 {{/warning}}
203
204 = Format & Verify Mojo =
205
206 {{info}}12.3RC1{{/info}}There are 4 types of pages that can be defined using regexes:
207 * Technical Pages: This is the default. It means pages must be hidden and not have any default language set.
208 * 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:(((
209 {{code language="xml"}}
210 <plugin>
211 <groupId>org.xwiki.commons</groupId>
212 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
213 <configuration>
214 <contentPages>
215 <contentPage>.*/Space[1-9]*/WebHome\.xml</contentPage>
216 </contentPages>
217 </configuration>
218 </plugin>
219 {{/code}}
220 )))
221 * 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:(((
222 {{code language="xml"}}
223 <plugin>
224 <groupId>org.xwiki.commons</groupId>
225 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
226 <configuration>
227 <translatablePages>
228 <translatablePage>.*/Translations\.xml</translatablePage>
229 </translatablePages>
230 </configuration>
231 </plugin>
232 {{/code}}
233 )))
234 * 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:(((
235 {{code language="xml"}}
236 <plugin>
237 <groupId>org.xwiki.commons</groupId>
238 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
239 <configuration>
240 <visibleTechnicalPages>
241 <visibleTechnicalPage>.*/Space/WebHome\.xml</visibleTechnicalPages>
242 </visibleTechnicalPages>
243 </configuration>
244 </plugin>
245 {{/code}}
246 )))
247
248 = Format Mojo =
249
250 [[Older documentation for versions < 12.3RC1>>||path:$doc.getURL('viewrev', queryString="rev=30.1#HFormatMojo")]].
251
252 To use the mojo:
253
254 * ##mvn xar:format## will perform some cleaning of your XML files, namely:
255 ** Indent lines (using 2 space characters)
256 ** Set ##author##, ##contentAuthor##, ##creator## and attachment ##author##s to be ##xwiki:XWiki.Admin##
257 ** Set ##version## to be 1.1
258 ** Set ##minorEdit## to be false
259 ** 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).
260 ** Remove any content of the ##comment## element
261 ** 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:(((
262 {{code language="xml"}}
263 <plugin>
264 <groupId>org.xwiki.commons</groupId>
265 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
266 <version>${commons.version}</version>
267 <configuration>
268 <!-- Add missing license headers by default -->
269 <formatLicense>true</formatLicense>
270 </configuration>
271 </plugin>
272 {{/code}}
273 )))
274 ** Technical pages are marked hidden. Same for translatable pages.
275 ** {{info}}New in 10.8RC1{{/info}} 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.
276 *** 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).
277 *** Can be disabled for all pages in the xar with either ##-Dxar.dates.skip=true## (system property) or ##<skipDates>true</skipDates>## (plugin configuration parameter).
278
279 = Verify Mojo =
280
281 [[Older documentation for versions < 12.3RC1>>||path:$doc.getURL('viewrev', queryString="rev=30.1#HVerifyMojo")]].
282
283 This is used to fail the build if the XML pages don't conform to the following rules:
284
285 * Verify that the encoding is UTF-8
286 * Verify that ##author##, ##contentAuthor##, ##creator## and attachment ##author##s are set to ##xwiki:XWiki.Admin##
287 * 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.
288 ** To turn if on, set ##<emptyParentSkip>false</emptyParentSkip>## in the POM or pass ##-Dxar.verify.translationVisibility.skip=false## on the Maven command line
289 * Verify that ##version## is set to 1.1
290 * Verify that ##comment## is empty
291 * Verify that ##minorEdit## is set to false
292 * Verify that the ##defaultLanguage## is empty for technical documents and ##visibleTechnicalPage##s (see above).
293 * 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>##).
294 * (optional) Verify that the XML files contain license headers (if the ##formatLicense## configuration property is set to ##true##).
295 * Verify that technical pages, and ##translatablePage##s are set as hidden, and that ##contentPage##s and ##translatablePage##s are set as npot hidden.
296 * Verify that defined pages have a specific matching title. For example:(((
297 {{code language="xml"}}
298 <plugin>
299 <groupId>org.xwiki.commons</groupId>
300 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
301 ...
302 <configuration>
303 ...
304 <titles>
305 <!-- Verify that all WebPreferences pages have the same title for consistency -->
306 <property>
307 <name>.*WebPreferences</name>
308 <value>\$services\.localization\.render\('admin.preferences.title'\)</value>
309 </property>
310 </titles>
311 </configuration>
312 </plugin>
313 {{/code}}
314 )))
315 * Verify that Translations pages (i.e. documents with a ##XWiki.TranslationDocumentClass## xobject) are using the ##plain/1.0## syntax.
316 * {{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).
317 * {{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.
318 * {{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.
319 ** 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).
320 ** Can be disabled for all pages in the xar with either ##-Dxar.dates.skip=true## (system property) or ##<skipDates>true</skipDates>## (plugin configuration parameter).
321
322 Example usage:
323
324 {{code language="xml"}}
325 <plugin>
326 <groupId>org.xwiki.commons</groupId>
327 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
328 <executions>
329 <execution>
330 <goals>
331 <goal>verify</goal>
332 </goals>
333 </execution>
334 </executions>
335 </plugin>
336 {{/code}}
337
338 To skip the execution of the verify mojo, you can use the property ##xar.verify.skip## with the value ##true##.
339
340 = UnXAR Mojo =
341
342 To configure it:
343
344 {{code language="xml"}}
345 <plugin>
346 <groupId>org.xwiki.commons</groupId>
347 <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
348 <configuration>
349 <groupId>...group id of XAR artifact to expand...</groupId>
350 <artifactId>...artifact id of XAR artifact to expand...</artifactId>
351 <outputDirectory>${project.build.outputDirectory}</outputDirectory>
352 <includes>
353 <include>Space/Page.xml</include>
354 ...
355 </includes>
356 <excludes>
357 <exclude>Space/Page.xml</exclude>
358 ...
359 </excludes>
360 </configuration>
361 </plugin>
362 {{/code}}
363
364 To use it:
365
366 * ##mvn unxar## will expand the XAR file

Get Connected