Wiki source code of Development Practices

Version 157.1 by Vincent Massol on 2018/05/03 11:18

Show last authors
1 XWiki development follows several rules listed below. If you're a Committer or if you simply wish to contribute please take the time to read them as you're expected to follow these rules.
2
3 {{toc/}}
4
5 = General Development Flow =
6
7 (% class="centered" %)
8 [[image:xwiki:[email protected]||style="max-width: 1024px; width: 100%;" title="Tools used in XWiki's development process and their relationship"]]
9
10 * Whenever we start working on a topic (a sufficiently important one), we send a proposal email to the list to explain what we're going to work on, to gather feedback and to get agreement.
11 * In the proposal email we propose a roadmap, i.e. dates that are in sync with project roadmaps (for example, say: "this feature is planned to be finished for XE 1.7M2). We also usually create a [[Design page>>design:Main.WebHome]] and link it in the mail.
12 * Once we get the agreement, we create a JIRA issue and assign oneself (we don't forget to set the fix for version)
13 * If it takes long (say more than 1 week) we regularly publish feedback on the progress and possibly revise the dates if need be. We should absolutely warn if there's a risk of not delivering as planned. This is crucial.
14 * Commits should be done regularly and more than once per week (the more the better, ideally several times per day).
15
16 The goals are several:
17
18 * Provide visibility to others
19 * Ensure agreement on the work being done (it's too stupid to do a lot of work and only find when it's finished that it wasn't the right way to do it and it has to be all redone again)
20 * Allow us to have product roadmaps
21 * Provide the ability to help someone if he's lagging behind or has issues
22
23 = Development Workflow =
24
25 When you work on some XWiki code here's the typical workflow depending on what you're working on:
26
27 * If you're working on Java classes, you develop in your IDE and [[unit tests>>Testing]] there. Then you build your module with Maven and this generates some JAR file in ##target/##. Then to test functionally you write some [[functional tests>>Testing]]. Running the functional tests generates a ##target/xwiki## instance containing an XWiki instance that you can start manually if you wish to perform some additional manual tests. If you don't have any functional tests, you can use a standard XWiki standalone instance and copy the generated JAR file to that it replaces the original one in ##WEB-INF/lib## (if you're changing an installed Extension, you need to replace the JAR in the ##/data/extension/repository## folder).
28 * If you're working on ##vm##/##js##/##css## files, then you create/modify them directly in your XWiki standalone instance in the ##template/##, ##resource/## or ##skin/## folders and just refresh the page using them (you may also need to clear browser cache for ##js##/##css##). When it works you copy paste your modifications in the source tree. Note that you can also write functional tests as for the Java use case above.
29 * If you're working on wiki pages, you also modify them directly in your running XWiki instance, and when you are happy with the result you export the pages as a XAR which you then unzip in the source tree (and you run ##mvn xar:format## on them, see [[XAR plugin>>XARPlugin]]).
30
31 = Automated Builds =
32
33 XWiki has an automated build system and developers are asked to use it on their local machines to prove that their changes work before committing them to the [[Source Repository>>SourceRepository]]. See the [[Building page>>Building]] for more details.
34
35 = Continuous Integration =
36
37 See the [[Continuous Build page>>ContinuousBuild]].
38
39 = Release Manager Role =
40
41 Role definition:
42
43 * In charge of performing a Release of XWiki (usually XWiki Commons/Rendering/Platform/XE).
44 * Is responsible to ensure that the dates defined in the Roadmap are achieved
45 * Needs to coordinate with developers so that they are ready on the release day, this means warning several days ahead and shepherding them to finish their stuff on time or push stuff to the next release
46 * Needs to follow the [[Release Plan Process>>ReleasePlans.WebHome]]. This app creates a release plan for releasing a version, listing all steps to be executed. It also keeps track of past Release Managers (and future ones) and of all past releases.
47
48 Process:
49
50 * We have a [[list of declared Release Managers>>ReleasePlans.WebHome#HNextReleaseManagers]]. Any committer willing to help the project is free to ask to perform a release!
51 * We take turns, following the order (from top to bottom). When a newcomer is added he's inserted at the bottom of the list.
52 * If a committer cannot do the release for a reason or another (sick, holiday, workload, etc) he’s still responsible for the release and he/she needs to find a replacement. He also has the option to propose changing the release date but that needs to be accepted by the project. If he/she finds a replacement, it’s up to them to decide together who will do the release the next time that replacement’s time comes.
53 * All releases are included in this process: milestones, RCs, final, bugfix releases.
54 * We switch Release Manager at each release (be it a milestone, RC, final or bugfix release).
55 * Once a Release is done, the Release Manager updates the [[Release Manager order>>ReleasePlans.WebHome#HNextReleaseManagers]] by moving himself/herself at the bottom of the pile.
56
57 = Build Manager Role =
58
59 {{info}}
60 This is not a role we have all the time. We do it from time to time when our build quality starts to deteriorate and we want to get it back on track
61 {{/info}}
62
63 Role definition:
64
65 * Every week we have a different Build Manager chosen amongst the Committers
66 * The Build Manager has the **responsibility** to get the build fixed ASAP whenever it's failing. His priority #1 during the week becomes monitoring and having the Build in working order (i.e. no failure)
67 * By "Build" we mean the CI Build on http://ci.xwiki.org and by "failing" we mean anything that makes the build fail: tests, compilation, backward-compatibility checks, etc.
68 * In order to fix build issues the Build Manager has several possibilities:
69 ** find out who caused the build to break and ask that person to fix it. That person cannot refuse that and must consider it his/her priority to fix it (or rollback the change that caused the build to fail)
70 ** rollback the issue that caused the build to fail
71 ** fix it himself/herself
72 ** find someone knowledgable in the failing domain and get him/her to fix the build.
73 * There's a [[Build Manager Roster>>BuildManagerRoster]] to log past Build Managers (and possibly future ones if some have expressed the wish to be the Build Manager for a specific week).
74 * At the end of the Week the Build Manager must find the next Build Manager and hand over his duty. If he doesn't find anyone else, he remains the Build Manager. Note that for fairness the oldest Build Managers on the [[Roster>>BuildManagerRoster]] need to accept to be the next Build Manager.
75 * All committers must perform this duty and take turns
76
77 Some examples of things that break the build and for which we need someone "owning" the build to fix them:
78
79 * Agents stop working. For ex some morning there were 2 jobs stuck because of a failure to start Firefox. This happens from time to time. Someone needs to investigate and at the very least kill the job to free the agent.
80 * New versions of Jenkins fixing bugs. Someone needs to check and upgrade the build when a new version has interesting stuff for us and when it fixes some of our issues.
81 * The most important ones: flickering tests. Of course we always test locally before committing and we even check that it works on Jenkins. But flickering don't fail immediately, they might run fine for 50 or 100 iterations and suddenly start to fail. It's not always easy to find who's the culprit on flickering tests.
82 * Various issues with filesystem locks, permissions on agents, memory settings, number of allowed open files, etc that make the build fail
83
84 = Versioning & Release Practices =
85
86 Check the [[Versioning and Release Practices page>>VersioningAndReleasePractices]].
87
88 = Copyright header in source files =
89
90 All files (including configuration files) must have the following copyright statement.
91
92 == For Java & Javascript files ==
93
94 {{code language="none"}}
95 /*
96 * See the NOTICE file distributed with this work for additional
97 * information regarding copyright ownership.
98 *
99 * This is free software; you can redistribute it and/or modify it
100 * under the terms of the GNU Lesser General Public License as
101 * published by the Free Software Foundation; either version 2.1 of
102 * the License, or (at your option) any later version.
103 *
104 * This software is distributed in the hope that it will be useful,
105 * but WITHOUT ANY WARRANTY; without even the implied warranty of
106 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
107 * Lesser General Public License for more details.
108 *
109 * You should have received a copy of the GNU Lesser General Public
110 * License along with this software; if not, write to the Free
111 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
112 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
113 */
114 {{/code}}
115
116 == For XML files ==
117
118 {{code language="none"}}
119 <!--
120 * See the NOTICE file distributed with this work for additional
121 * information regarding copyright ownership.
122 *
123 * This is free software; you can redistribute it and/or modify it
124 * under the terms of the GNU Lesser General Public License as
125 * published by the Free Software Foundation; either version 2.1 of
126 * the License, or (at your option) any later version.
127 *
128 * This software is distributed in the hope that it will be useful,
129 * but WITHOUT ANY WARRANTY; without even the implied warranty of
130 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
131 * Lesser General Public License for more details.
132 *
133 * You should have received a copy of the GNU Lesser General Public
134 * License along with this software; if not, write to the Free
135 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
136 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
137 -->
138 {{/code}}
139
140 == For Shell scripts and Properties files ==
141
142 {{code language="none"}}
143 # ---------------------------------------------------------------------------
144 # See the NOTICE file distributed with this work for additional
145 # information regarding copyright ownership.
146 #
147 # This is free software; you can redistribute it and/or modify it
148 # under the terms of the GNU Lesser General Public License as
149 # published by the Free Software Foundation; either version 2.1 of
150 # the License, or (at your option) any later version.
151 #
152 # This software is distributed in the hope that it will be useful,
153 # but WITHOUT ANY WARRANTY; without even the implied warranty of
154 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
155 # Lesser General Public License for more details.
156 #
157 # You should have received a copy of the GNU Lesser General Public
158 # License along with this software; if not, write to the Free
159 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
160 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
161 # ---------------------------------------------------------------------------
162 {{/code}}
163
164 == For Bat files ==
165
166 {{code language="none"}}
167 REM -------------------------------------------------------------------------
168 REM See the NOTICE file distributed with this work for additional
169 REM information regarding copyright ownership.
170 REM
171 REM This is free software; you can redistribute it and/or modify it
172 REM under the terms of the GNU Lesser General Public License as
173 REM published by the Free Software Foundation; either version 2.1 of
174 REM the License, or (at your option) any later version.
175 REM
176 REM This software is distributed in the hope that it will be useful,
177 REM but WITHOUT ANY WARRANTY; without even the implied warranty of
178 REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
179 REM Lesser General Public License for more details.
180 REM
181 REM You should have received a copy of the GNU Lesser General Public
182 REM License along with this software; if not, write to the Free
183 REM Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
184 REM 02110-1301 USA, or see the FSF site: http://www.fsf.org.
185 REM -------------------------------------------------------------------------
186 {{/code}}
187
188 = Coding Conventions =
189
190 See the [[Code Style page>>CodeStyle]].
191
192 = File encoding =
193
194 The following rules must be taken into account when the need for writing non-ASCII content in the XWiki sources arises:
195
196 * All Java source files must contain only ASCII chars, Unicode escapes inside strings when needed, and XML entities in javadocs. Since we don't use @author tags, this should not be a problem.
197 * All translation files must contain only ASCII chars and Unicode escapes (stronger than the Java properties specification).
198 * All wiki documents sources must be stored in UTF-8.
199 * Other XML files should always specify their encoding in the **{{{<?xml>}}}** header, and it should be UTF-8 as often as possible.
200 * All other textual resources must be stored in UTF-8, minimizing the use of non-ASCII chars.
201
202 Currently, only the XML rules are broken, but this is not a serious problem since the XML reader can detect and use the charset/encoding specified in the XML header.
203
204 = Creating a JIRA project =
205
206 When creating a new Contrib JIRA project on https://jira.xwiki.org make sure to use the XWiki Contrib template ({{scm project="xwiki-dev-tools" path="xwiki-jira-template-plugin"}}source code here{{/scm}}):
207
208 {{image reference="jira-contrib-template.png"/}}
209
210 In addition perform the following steps:
211
212 * Put as Project Lead the person requesting the project
213 * Make sure to fill the URL part. Ideally it should point to documentation on extensions.xwiki.org. Failing that it should point to the GitHub project's page.
214 * Create the appropriate versions. If the project has already had releases, recreate the versions and release them in JIRA with the correct release dates
215
216 For information this is what this template automates:
217
218 * Creating a "JIRA Classic" project type
219 * Selecting the proper "Category". For Contrib projects, it's "XWiki Contributed Projects".
220 * Setting Workflows to use the "XWiki Workflow Scheme"
221 * Setting Screens to use the "Basic Issue Creation Scheme"
222 * Setting Fields to use the "XWiki Open Field Configuration Scheme"
223 * Making sure that the default assignee is "Unassigned" and that it's not the Project Lead by default
224 * Setting Permissions to use the "XWiki Open" scheme
225 * Setting Issue Security to use the "XWiki" scheme
226 * Setting Notifications to use the "XWiki Notification Scheme"
227
228 = JIRA Best Practices =
229
230 Here are some rules on how to use JIRA for XWiki projects.
231
232 == Rule: Always put a JIRA issue reference in commit messages ==
233
234 The rationale behind this:
235
236 * One consistent way to manage all the work to be done on the XWiki project. It also means there's no unaccounted work, meaning anyone can go to JIRA and query it and see what everyone has been working on.
237 * Automated release notes/change logs. When we release a version we can simply do a JIRA extract and it'll give the full change log of what happened. This is really important for our users to see what has been done when in XWiki.
238 * Traceability. When you use the JIRA issue number in your commit, the JIRA DVCS Connector Plugin can show the modified files directly from JIRA. This is quite useful later on, when someone is looking at a JIRA issue and wants to see what was modified. In addition Fisheye is also integrated with JIRA and when you browse the source repository you can see the JIRA issue associated with files.
239
240 Of course this shouldn't be done for any trivial things like adding a small javadoc, renaming a single variable, cosmetic changes, ignore files, etc.
241
242 JIRA issues can be marked "confidential", e.g. to hide the details of a security issue until it is fixed. Such issues should also be referenced in the commit message. However, avoid exposing the details of the issue in the commit message (some time will pass until the code is released) by choosing a more neutral description.
243
244 The general strategy goes like this:
245
246 * When you plan to work on something, create a JIRA issue and assign it to yourself or simply assign an existing JIRA issue to yourself if one already exists
247 * Implement it
248 * Commit it with the JIRA issue number in the commit message. The format we follow is:(((
249 {{code language="none"}}
250 <JIRA ID, e.g. XWIKI-1000>: <JIRA issue description>
251 * <details>
252 ...
253 * <details>
254 {{/code}}
255 )))
256 * Close the JIRA issue
257
258 * Another acceptable variation is:
259 ** Implement something
260 ** When you want to commit it you realize you don't have any JIRA issue to put in the commit message so don't commit.
261 ** Create the JIRA issue
262 ** Commit with the JIRA number in the commit message
263
264 == Rule: Don't create unnecessary issues ==
265
266 * If you want to know whether you should create a JIRA issue or not, ask yourself the question: "is my change going to affect any user or any extension developer in any way"? If the answer is yes then you must create a JIRA issue
267 * If you're fixing something related to build then it's not mandatory to create an issue. However if you do, make sure you use the special component usually labeled "Development Issues only" in our JIRA projects. We're excluding issues in this category from our release notes.
268 * Note that if you're upgrading a third-party dependency used by XWiki at runtime then you must create a JIRA issue using the special component usually labeled "Dependency Upgrades" and this needs to make it in the Release notes since it impacts XWiki users. If you're upgrading a third-party dependency only used at build time (for example the Selenium dependency) then you should use the "Development Issues only" component.
269 * If you're fixing or reporting an issue related to code that's been introduced in the current version being developed, you shouldn't create a JIRA issue. Actually, if you did, you'd be hard-pressed to find the correct "Affects version" to use! :). Instead, use (or reopen) the existing JIRA that affects the current version being developed. If you're fixing it yourself, just use the same issue key. If you're reporting a problem, just reopen the issue and add a comment for the developer to see and fix before releasing.
270 * If you're adding some translations on l10n.xwiki.org it's not necessary to create an issue in the [[l10n Project's JIRA>>https://jira.xwiki.org/browse/XINFRA/component/12646]]. It would cause too much overhead.
271
272 == Rule: Use nice user-friendly titles ==
273
274 When you create a JIRA issue always take the time to put a nice title for the issue. The title must be understandable by a user so don't describe the issue technically but rather in what way it affects users. For example don't say "Fix the addXXX API to return an Array List" but rather "Allow creating several pages at once".
275
276 == Rule: Don't set a "Fix For" field for invalid issues ==
277
278 Issues that are closed with "Won't fix", "Duplicate", "Cannot reproduce" or "Incomplete" must have a "Fix For" field set to "unknown" so that they don't appear in the Release Notes, as JIRA doesn't make the distinction visible and this causes confusion.
279
280 == Rule: Close issues that XWiki committers don't plan to implement ==
281
282 * We close issues that we know we won't fix (using a "Fix For" value of "Duplicate", "Incomplete", "Cannot Reproduce" or "Won't Fix"). We might not want to fix them for several reasons but one reason is that the issue is for an old XWiki project version.
283 ** This is especially true since [[XWiki committers are only officially supporting a few branches>>xwiki:Main.Support]]. Of course, any committer wanting to
284 fix any old issue is free to do it.
285 * Leaving these issues open is not a good idea since:
286 ** It sends the wrong signals that we're going to fix the issue
287 ** The issue can still be found with a search even if closed
288 ** When we close it then the reporter can explain why it's so important for him/her, or not. Which we wouldn't know if we hadn't closed it
289 ** Contributors can reopen issues and attach a patch or just create a new issue
290 ** It means that for all other issues we plan to fix them at some point
291
292 = Retiring a JIRA project =
293
294 Eventually, some XWiki projects will reach their end-of-life. This is often a good thing as new approaches or technologies have developed which reduce the need for the project. When a project retires, it is best to clean up loose ends to make sure outstanding users still have access to the code and the valuable project history is captured for future researchers.
295
296 Retiring steps:
297
298 * Make the project 'Read-Only' by using the "XWiki Retired Project Scheme" permission scheme.
299 * Change the name of the project by prepending it with the ##{Retired}## label (e.g. ##Forum Application## -> ##{Retired} Forum Application##).
300 * Move the project to the [["XWiki Retired Projects" category>>https://jira.xwiki.org/secure/BrowseProjects.jspa#10060]]. Edit the project and set its new category.
301 * Update the project's description accordingly, informing the users that the project is no longer active.
302
303 = Documentation Best Practices =
304
305 The strategy is that when closing an issue in JIRA we make sure that there's documentation for it on xwiki.org (reference documentation) and on the Release Notes for the version corresponding to the JIRA ##Fix Version(s)## field. This is done by filling the 2 corresponding fields in JIRA on the issue that is being closed. This allows two things:
306
307 * Have up to date documentation on xwiki.org
308 * Build Release Notes progressively so that when we perform the Release we don't have to wait a few more days to have everyone try to remember all the stuff they've done for the release...
309
310 == Documentation of young API modifications ==
311
312 When an API is considered as "young" (it has the ##@Unstable## annotation), some changes can be made to its methods declarations. In order for those changes to not be considered as breakages, please mention clearly that the API you just modified is still considered as unstable when you report an API change in the {{scm path="xwiki-platform-core/pom.xml"}}##xwiki-platform-core## POM file{{/scm}} (something like "##Young API, FooBarClass#getSomething() now takes … argument.##" will perfectly do the work).
313
314 This is important mostly because changes that concerns young APIs are not especially differentiated from standard API breakages in the [[release notes>>xwiki:ReleaseNotes.WebHome]].
315
316 = Using bird names for Skins =
317
318 We have decided to name XWiki official skins using bird names. We are currently renaming the existing skins. Any new skin must use a bird name. It's recommended to send a proposal to the list whenever a new skin has to be named.
319
320 Here are some potential ideas for future names:
321
322 * Dove
323 * Emu
324 * Kiwi
325 * Grasswren
326 * Condor
327 * Warbler
328 * Kestrel
329 * Redtail
330 * Pigeon
331 * Booby
332 * Sparrow
333 * Blackbird
334 * Parrot
335 * Peacock
336 * Finch
337 * Wren
338 * Crow
339 * Turkey
340 * Thunderbird
341 * Piasa (a local phenomenon, from a primitive painting on the cliffs on the eastern shore of the Mississippi, attributed to the Piasa tribe, which looks rather like a griffin)
342 * Thunder Chicken
343 * Kingfisher
344 * Swallow
345
346 = SCM Practices =
347
348 == Applying a contributor's patch ==
349
350 Please use the following commit log message template:
351
352 {{code}}
353 XWIKI-XXX: <description of issue here>
354 Patch submitted by <contributor's name>
355 Reviewed by <reviewer's name>
356
357 <additional comments here>
358 {{/code}}
359
360 This gives credit to the contributor.
361
362 Also make sure to add the contributor's name to the [[Contribution page>>HallOfFame#HContributors]].
363
364 This is important to give proper recognition to our contributors.
365
366 = Back-end Development Practices =
367
368 == Component Development ==
369
370 Read the [[Component Module documentation>>extensions:Extension.Component Module]] for details on how to write components.
371
372 == Backward Compatibility ==
373
374 We pay a lot of attention to backward compatibility. This is why we're using the [[Revapi Maven plugin>>http://revapi.org/modules/revapi-maven-plugin/index.html]] in our builds to ensure we don't break public APIs.
375
376 Since it takes time to stabilize an API we've introduced an annotation named ##@Unstable## (see below).
377
378 We follow 2 steps when it comes to deprecating code:
379
380 * **First step**: We start by deprecating it using the ##@deprecate## and ##@Deprecated## Javadoc and java annotations. The code remains where it was before the deprecation happens.
381 * **Second step**: When our own code doesn't use any of the deprecated APIs anymore then move the code to a **legacy** module. This can be done as soon as the deprecation is added.
382
383 This has the following advantages:
384
385 * Our code remains clean of old deprecated APIs
386 * Deprecated code is cleanly separated from new ways of doing things
387 * When new users download the our code they see the new ways (same for javadoc generation)
388 * Users wanting to use the old APIs can still do so
389 * We never remove APIs from the legacy modules by default. However if we really need to do so (for some technical reason for example), we do it on a case by case basis with a VOTE.
390
391 {{info}}
392 In the future, our distribution may not package legacy JARs by default and users wanting to use older APIs may need to install the legacy modules. This is an effort to move users to the newest API as soon as possible while still allowing them to use the old API it they're not ready to move yet (but at least they'll be aware of the changes and about what they have to fix). However in order to provide a good user experience, before doing this we need to add support for Legacy jars in the Extension Manager.
393 {{/info}}
394
395 {{warning}}
396 When you need to add a new method to an interface there are 2 solutions to preserve backward compatibility:
397
398 * Create a new interface with the new method and deprecate the old one. This means that code using the old interface must be modified to support the 2 interfaces, and that's not easy.
399 * (Recommended) Use [[Default Methods>>https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html]] (introduced in Java 8).
400 {{/warning}}
401
402 === Deprecation Rules ===
403
404 For details and rationale about those rules below see [[this thread>>http://markmail.org/thread/cljbqwbrrmunlmar]].
405
406 * Rule: **Location of Legacy modules**
407 ** Each Git repository needing legacy modules provides a ##*-legacy## module for holding legacy modules. For example:
408 *** For Commons, ##xwiki-commons-core/xwiki-commons-legacy/##
409 *** For Platform, ##xwiki-platform-core/xwiki-platform-legacy/##
410 *** For Rendering, ##xwiki-rendering-legacy/##
411 * Rule: **Use AspectJ to move deprecated APIs to Legacy modules**
412 ** This idea was found in this [[blog post>>http://www.sonatype.com/people/2007/11/two-fantastic-uses-for-aspectj-part-one-backward-compatibility/]].
413 ** Here's an {{scm path="xwiki-platform-core/xwiki-platform-legacy/xwiki-platform-legacy-oldcore/src/main/aspect/com/xpn/xwiki/XWikiCompatibilityAspect.aj"}}example of such an Aspect{{/scm}}.
414 * Rule: **Legacy modules replace modules from where they come from**
415 ** Each Legacy module replace the non-legacy module it corresponds to. This means that the user must have only 1 JAR for a given module: either its legacy version or it's non-legacy version but should never have both.
416 * Rule: **Annotate code with version to show deprecations**
417 ** Use both ##@Deprecated## annotation and the ##@deprecated## javadoc tag **and** specify the version when the deprecation was added. For example:(((
418 {{code language="java"}}
419 /**
420 * @param time the time in milliseconds
421 * @return the time delta in milliseconds between the current date and the time passed as parameter
422 * @deprecated replaced by {@link com.xpn.xwiki.api.Util#getTimeDelta(long)} since 1.3M2
423 */
424 @Deprecated
425 public int XWiki.getTimeDelta(long time)
426 {
427 return this.util.getTimeDelta(time);
428 }
429 {{/code}}
430 )))
431
432 === ##@Unstable## Annotation ===
433
434 This annotation can (and should) be used by developers whenever new code is introduced (in addition to also adding a ##@since## annotation). This annotation means that the code is subject to change at any time (in which case it'll appear in the backward-compatibility reports but with the explanation that it's an Unstable API). From a user point of view, it means they should use classes or methods annotated with the ##@Unstable## annotation with caution. It means they need to be prepared to modify their code. Alternatively they can decide to not use classes/methods annotated with ##@Unstable## and wait for them to come out of unstability.
435
436 In order to prevent code to remain annotated with ##@Unstable## forever, we've defined some rule;
437
438 * Any code annotated with ##@Unstable## can only remain in this state for a maximum of 1 full [[cycle>>VersioningAndReleasePractices]]. For example if a unstable API is introduced in 4.4, it'll have to come out of unstability before 6.0M1 is released (thus having 1 full cycle, i.e. the 5.x cycle). This means that the worse that can happen is for an unstable API added in N.1 which will have to be removed before N+2 Milestone 1 is released.
439 * However, the previous rule is only a maximum and developers are encouraged to remove the unstable annotation whenever they feel that the API should come out of unstability. When this happens the standard deprecation mechanism then kicks in.
440
441 The following automated checks related to the ##@Unstable## annotation are performed in the [[build>>Building]]:
442
443 * {{scm project="xwiki-commons" path="xwiki-commons-tools/xwiki-commons-tool-verification-resources/src/main/java/org/xwiki/tool/checkstyle/UnstableAnnotationCheck.java"}}Automatically enforce the removal of the @Unstable annotation{{/scm}}. Also verifies that a ##@since## annotation is present.
444 * {{scm project="xwiki-commons" path="xwiki-commons-tools/xwiki-commons-tool-verification-resources/src/main/java/org/xwiki/tool/checkstyle/SinceFormatCheck.java"}}Automatically verify the format of the ##@since## annotation{{/scm}} (used in the previous check to verify the age of the ##@Unstable## annotation.
445
446 == Configuration Property Naming ==
447
448 XWiki uses 2 configuration files at the moment:
449
450 * An old one, named ##xwiki.cfg## for old core code and which eventually will go away when all code will have been rewritten using component and extracted as separate modules
451 * A more recent one that must be used for new configuration properties required by new code, named ##xwiki.properties##
452
453 The naming rule for ##xwiki.properties## is:
454
455 * Use ##<module>.<propertyName>##. Ex: ##rendering.linkLabelFormat##
456 * For submodules use ##<module>.<submodule>.<propertyName>##. Ex: ##rendering.macro.velocity.filter##
457 ** Note: Unfortunately you'll find some properties not following this rule in ##xwiki.properties##. This is because we've been bad in following this rule and doing code review to ensure it was followed. It was also voted on the mailing list but not documented here in the past.
458 * Use camelcase for the property name itself. ex: ##linkLabelFormat##
459
460 == Translation Best Practices ==
461
462 === General ===
463
464 * The XWiki Core committers maintain one version, the English one and more precisely the ##en_US## one. This means:
465 ** The ##ApplicationResources.properties## file (without any language suffix) represents the ##en_US## version
466 ** We should use "customize" instead of "customise" or "color" instead of "colour" ;)
467 * Other translations are maintained by the community at large on [[l10n>>http://l10n.xwiki.org]].
468
469 === Translation Property Naming ===
470
471 When content requires localization you should use the following rules:
472
473 * If the content is inside a wiki page, then create a wiki page named ##Translations## (or ##*Translations## if there's a need to have several translation pages) in the space of the application containing the content to translate. This page must be registered using a ##XWiki.TranslationDocumentClass## xobject.
474 * If the content is inside some ##.vm## files or in Java, then create an ##ApplicationResources.properties## file in the ##src/main/resources## directory of the module using the translation (so that it's packaged at the root of the JAR).
475 * Generally speaking the translations must be part of the extension containing the content to translate.
476 * New translation resource must be added on http://l10.xwiki.org and in the release scripts.
477 * Special case for extensions containing only wiki Macros which go in the ##Macros## space: the ##Translations## file should be located in the same space as the macro.
478 * Follow the [[L10N Conventions]] for naming the translation keys
479
480 === Translation Property Deprecations ===
481
482 * When deleting a key, it should be moved to the deprecated section at the end of the file, linked to the first version in which it started to be deprecated. If there's no such section in your translation file you must add one, using the following syntax:(((
483 {{code language="properties"}}
484 #@deprecatedstart
485 ...
486 ##################################################
487 ## until <version that deprecated the keys below>
488 ##################################################
489 ...
490 {{/code}}
491 )))
492 * When renaming a key, it should be moved to the same deprecated section and a comment should be added with the following syntax:(((
493 {{code language="properties"}}
494 #@deprecated new.key.name
495 old.key.name=Some translation
496 {{/code}}
497 )))
498
499 === Moving Translations ===
500
501 When moving translations from one location to another (resource properties file to wiki page, to another properties file, etc) then you need to be careful to not loose existing translations. There's a tool existing on [[l10n>>http://l10n.xwiki.org]] for this restricted for administrators. See [[http://l10n.xwiki.org/xwiki/bin/view/L10N/Refactoring]].
502
503 == Migrating away from the Old Core ==
504
505 Starting in 2006 we've started to work on splitting the code that's currently located in the ##xwiki-platform-oldcore## module into various modules, each one specific to a given domain. Before 2006 the whole of XWiki was located in that ##oldcore##. The work isn't over and the current strategy is the following:
506
507 * Continue extracting code from ##oldcore## and put it in its own domain modules
508 * We allow new modules to depend on ##oldcore## provided that ##oldcore## itself doesn't depend on these new modules obviously (as otherwise it would create a cyclic dependency). When that happen it usually means we need to move the code in ##oldcore## that uses thee new module outside of ##oldcore## in an existing module or in a new one.
509 * At some point all that should remain in ##oldcore## is the old Model itself.
510 * We need to continue the work we started about writing the [[New Model>>Design.XWikiModel20]] and put it in some new module, at which point we'll need to migrate our code to use the new Model progressively and then the last step will be to remove ##oldcore## altogether.
511
512 {{warning}}
513 It's important that we stop adding new stuff to ##oldcore## and instead always try to extract stuff outside of it as otherwise this means accruing even more our technical debt and making it harder to completely remove ##oldcore##.
514 {{/warning}}
515
516 = Front-end Development Practices =
517
518 == JavaScript Best Practices ==
519
520 * [[All javascript should be in the HTML ##<head>## of the document>>http://xwiki.markmail.org/message/7bgqcfx5hgnxqtjm]] (as much as possible).
521 ** Reason 1: Moving all script into the head makes it easier to find and makes impossible bad (and often non WCAG-compliant) practices such as attaching script to xml attributes. It makes it less of a jungle.
522 ** Reason 2: If we have no script in the body of any documents then users can implement filters which remove any script after the ##</head>## tag. This makes script injection certifiably impossible.
523 See [[this email thread>>http://xwiki.markmail.org/message/7bgqcfx5hgnxqtjm]]
524 * Avoid using javascript in attributes such as ##onload##, ##onmouseover##, etc. Doing this can cause problems with event handlers and is sometimes [[WCAG>>http://en.wikipedia.org/wiki/Web_Content_Accessibility_Guidelines]] invalid.
525 * Whether features should work or not when Javascript is turned off is a [[discussion in progress>>http://markmail.org/message/emzpfs6bdyu5f2e5]].
526
527 === External libraries ===
528
529 XWiki bundles several libraries to ease the development of front-end components. Amongst them are:
530
531 * [[Prototype.js>>http://prototypejs.org/]] (DOM manipulation, AJAX library, OOP-style classes)
532 * [[Smartclient>>http://www.smartclient.com/]] (Rich AJAX widgets)
533 * [[Scriptaculous>>http://script.aculo.us/]] (Drag and drop, animation framework, AJAX controls, DOM utilities and unit testing. Add-on for the Prototype library.)
534
535 For an exhaustive list, including XWiki internal libraries, see [[platform:DevGuide.FrontendResources]]
536
537 Front-end components should rely on components provided by those libraries as much as possible.
538
539 The introduction of new libraries should go through a vote on XWiki devs list. Only libraries which bring functionalities that none of the already provided external or internal libraries do are likely to be considered.
540
541 === XWiki Namespacing ===
542
543 All XWiki's JavaScript code should be under the **XWiki** namespace. The preferred way to namespace a module's code is to use the [[Module Pattern>>http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html]], in particular loose augmentation and sub-modules.
544
545 Methods, classes and properties that have sense only in one module should be created under a module object of the XWiki object.
546
547 Example:
548
549 {{code}}
550 var XWiki = (function(XWiki) {
551
552 // sub-module object lazy creation
553 var dataEditors = XWiki.dataEditors = XWiki.dataEditors || {};
554
555 // sub-module augmentation
556 dataEditors.XPropertyOrdering = Class.create({
557 // [snip]
558 });
559
560 return XWiki;
561
562 })(XWiki || {});
563 {{/code}}
564
565 Methods, classes and properties that have sense in all XWiki pages can be considered generic and be create directly under the XWiki object.
566
567 Example:
568
569 {{code}}
570 var XWiki = (function(XWiki){
571 /**
572 * Build a resource object from a wiki resource descriptor (aka fullName).
573 */
574 XWiki.getResource = function(fullName) {
575 // [snip]
576 }
577
578 return XWiki;
579
580 })(XWiki || {});
581 {{/code}}
582
583 === Backward compatibility and deprecation ===
584
585 As for back-end development, we should take care of backward compatibility. There are applications developed on top of XWiki that use their own JavaScript APIs. The rule for deprecating a JavaScript API (be it an object or a method of an object) is to move or write code to maintain compatibility in the compatibility.js file under the xwiki folder. We should always wrap deprecated code to log its usages. This will make the life of applications developers much easier.
586
587 Example of deprecation code:
588
589 {{code language="javascript"}}
590 /**
591 * Deprecated since 1.9M2
592 */
593 window.displayDocExtra = XWiki.displayDocExtra;
594 window.displayDocExtra = window.displayDocExtra.wrap(
595 function(){
596 warn("window.displayDocExtra is deprecated since XWiki 1.9M2. Use XWiki.displayDocExtra instead.");
597 var args = $A(arguments), proceed = args.shift();
598 return proceed.apply(window, args);
599 }
600 );
601 {{/code}}
602
603 {{warning}}
604 XE should **always** work fine when running without the compatibility file. Before deprecating a method or object, we should ensure it is not used anywhere any longer in XE standard distribution.
605 {{/warning}}
606
607 = Bug Reporting =
608
609 The bug reporting system resides at https://jira.xwiki.org/
610
611 = XWiki.org Rules =
612
613 Some rules to follow when making modifications on xwiki.org.
614
615 == Don't remove important pages when they are moved ==
616
617 Rationale: Users will save links and when they navigate to them later on these links will be broken.
618 Solution: Add a redirect script to redirect to the new page
619 Implementation: Use this script:
620
621 {{code language="none"}}
622 {{velocity}}
623 $response.sendRedirect($xwiki.getURL("newSpace.newPage"))
624 {{/velocity}}
625 {{/code}}
626
627 == Don't use URLs for links to *.xwiki.org ==
628
629 Rationale: If we change the URL format or the domain the links will be broken
630 Solution: Use the ##wiki:Space.Name## notation
631
632 = XWiki Days =
633
634 See [[XWiki Days>>XWikiDays]].
635
636 = Application Development =
637
638 See [[Application Development Best Practices>>ApplicationDevelopmentBestPractices]].
639
640 = Build Best Practices =
641
642 * For the general directory structure, see [[dev:Community.SourceRepository]].
643 * **Directory names**: We're currently using the a directory name corresponding to the Maven ##artifactId##. For example: ##xwiki-platform-watchlist-ui## for a ##pom.xml## having(((
644 <artifactId>xwiki-platform-watchlist-ui</artifactId>##{{warning}}Note that this scheme is causing some issues on Windows since it generates long path names and Windows usually supports only 255 characters. It's possible that we'll change this in the future... or not, since you can use Cygwin on Windows to have longer path names.{{/warning}}##
645 )))
646 * Maven **groupId**s: ##org.xwiki.<short name of top level project>##. For example ##org.xwiki.commons## for XWiki Commons, ##org.xwiki.rendering## for XWiki Rendering, ##org.xwiki.platform## for XWiki Platform and ##org.xwiki.enterprise## for XWiki Enterprise
647 * Maven **artifactId**s: ##xwiki-<short name of top level project this module belongs to>-<module name>-<qualifiers>##. For example:##xwiki-platform-watchlist-ui##. There are some conventions used: ##-api## for modules providing APIs, ##-ui## for modules generating XARs, ##-test## for functional test parent POM, ##-test-pageobjects## for functional test Page Objects modules, ##-test-tests## for modules containing and executing the functional tests.
648
649 = Top Level Extensions =
650
651 Rationale/Need:
652
653 * Be able to extract some apps from ##xwiki-contrib## that the XWiki Dev Team would like to maintain. Example: File Manager app developed by Marius when it’ll have had some releases and tests (if it doesn’t have some already!), GitHub Stats app used on xwiki.org, Meeting Manager App, Forum App, etc
654 * Be able to extract some extensions currently located in ##xwiki-platform## but not released with XE so that they can have a different release cycle (examples: FAQ app, IRCBot extension, JIRA macro, etc). Having different release cycle allow to release new versions quicker to our users (bug fixes, new features).
655
656 Governance:
657
658 * Extensions are VOTEd in on a case by case basis.
659 * Each voted extension has its own Git Repository in the “xwiki” organization (so that each extension can be released independently of each other).
660 * When moving an extension either from ##xwiki-contrib## or from ##xwiki-platform##, keep its Git history as much as possible or simply donate the repo to the ##xwiki## organization.
661 * FTM extensions bundled by default with XE still remain in XWiki Commons/Rendering/Platform/Enterprise.
662 * The Git repository name must be of the form ##xwiki-<short project name>##. ##<short project name>## must be part of the VOTE.
663 * All [[XWiki Development rules>>dev:Main.WebHome]] apply
664 * Each extension has a Release Manager defined and he’s responsible for defining its own Roadmap/Release notes (if need be), on the extension page on e.x.o and perform the releases or ensure the extension is released regularly when there are changes.
665 * Each extension must follow these criteria for being VOTEd:
666 ** A Release Manager needs to be defined in the proposal
667 ** The extension must have had several releases already (i.e. someone wanting to propose a new extensions that doesn’t exist would start in ##xwiki-contrib## for ex and prove that his extension works and is useful by doing several releases and creating the pages on e.x.o)
668 ** It must follow [[our best practices>>dev:Main.WebHome]] (coding practices, tests, etc) and follow the [[apps best practices (for apps)>>dev:Community.ApplicationDevelopmentBestPractices]].
669 ** It must have one or several integration or functional tests (for apps) to prove that it works. This allows to prove the app continues working when XWiki progresses
670 ** The main contributors of the extensions must agree about the move. If they have the “level" to be an xwiki dev [[committer>>dev:Community.Committership]] then they should be voted in. If not then either they’re ok to send Pull Requests or the extension should not be moved.
671 * If an extension ceases to work or if its quality becomes too low, it can be moved to ##xwiki-contrib## with a VOTE
672 * We create one JIRA project per extension
673 * We create a new JIRA Category called “XWiki Extensions”
674 * We put the extensions in our CI at http://ci.xwiki.org
675 * The Java package must follow the same rule as for XWiki Platform, i.e. ##org.xwiki.<short project name>##. Exceptions would need to be discussed.
676 * The group id for extensions having their own repo must be ##org.xwiki.<short project name>##. The ##<short project name>## needs to be part of the VOTE when proposing a new extensions.
677
678 = Extracting out a core module =
679
680 Non-core modules should be moved to XWiki Contrib. Here are some instruction for doing so without loosing the git history. For example for extracting out ##xwiki-platform-blog##:
681
682 * Create the new target repo in https://github.com/xwiki-contrib/, e.g. https://github.com/xwiki-contrib/application-blog
683 * Inside ##xwiki-platform## (you need to be at the root), run: {{code language="bash"}}git subtree split -P xwiki-platform-core/xwiki-platform-blog -b split{{/code}}
684 * Push the ##split## branch into the new repo: {{code language="bash"}}git push https://github.com/xwiki-contrib/application-blog.git split:master{{/code}}
685 * Remove the ##split## branch: {{code language="bash"}}git branch -D split{{/code}}
686 * Remove the code from ##xwiki-platform## and commit

Get Connected