Development tools: Subversion, Ant, Maven, and ...

5 downloads 82 Views 1MB Size Report
Development tools. # 2. Introduction—Context ... Development tools. # 3. Outline ..... GNU/Linux package or Windows TortoiseSVN (http://tortoisesvn.tigris.org/).
Development tools: Subversion, Ant, Maven, and Eclipse D. Conan, M. Simatic, S. Leriche Projet Fin d’Étude ASR November 2007

Development tools

Introduction—Context

¥ Source code management (sharing in a repository) = Subversion or CVS ¥ Automation of project build (compilation, tests, distribution) = Makefile or Ant or Maven ¥ Development in Java (with an Integrated Development Environment) = Eclipse

¥ Motivations and objectives ¨ This is a first presentation ¨ Keep practising during the project for autonomy and efficiency

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

2/65

Development tools

Outline

1 Source control management with Subversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 2 Project build with Ant and Maven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3 Java programming with Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

3/65

Development tools

1 Source control management with Subversion

1.1 1.2 1.3 1.4

Questions récurrentes lors d’un développement de logiciel . . . . . . . . . . . . . . . . . . . . . . . . 5 Travail en parallèle sur la même version. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Travail en parallèle sur plusieurs versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Presentation of Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

4/65

Development tools

1 Source control management with Subversion

1.1 Questions récurrentes lors d’un développement de logiciel ¥ Quels sont les besoins pris en compte par la version 1.0 ? ¥ Les développeurs travaillent sur la même version Comment garantir qu’aucun travail n’est perdu ? ¥ De quoi est faite la version 1.0 de ce logiciel ? ¥ Quelles sont les anomalies/demandes de changement prises en compte par la version 2.0 ? ¥ L’équipe travaille sur la version 2.0. Un client demande une correction sur la version 1.0: ¨ Comment développer une version 1.1 ? ¨ Comment reporter le travail effectué en 1.1 vers 2.0 ? ¥ Comment résoudre les problèmes liés au fait que les développeurs sont répartis sur plusieurs sites ? D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

5/65

Development tools

1 Source control management with Subversion

1.2 Travail en parallèle sur la même version

1.2.1 1.2.2 1.2.3 1.2.4

Multi-developer—Position du problème . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Multi-developer—Copy-Modify-Merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Multi-developer—Lock-Modify-Unlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

6/65

1 Source control management with Subversion

1.2 Travail en parallèle sur la même version

1.2.1 Multi-developer—Position du problème ¥ 2 développeurs peuvent simultanément mettre à jour le même fichier et donc perdre l’une des mises-à-jour Module A

1. modify

User X

2. modify

User Y

3. commit changes

3. commit changes

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

7/65

1 Source control management with Subversion

1.2 Travail en parallèle sur la même version

1.2.2 Multi-developer—Copy-Modify-Merge Module A

2. checkout

1. checkout

3. MAJ

4. MAJ

6. commit refused

5. commit

7. update

8. commit

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

8/65

1 Source control management with Subversion

1.2 Travail en parallèle sur la même version

1.2.3 Multi-developer—Lock-Modify-Unlock Module A

2. lock (refused)

1. lock

3. MAJ

4. commit (implicit unlock)

5. lock

6. MAJ

7. commit (implicit unlock)

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

9/65

1 Source control management with Subversion

1.2 Travail en parallèle sur la même version

1.2.4 Discussion

¥ Le mode Lock-Modify-Unlock n’est imposé que pour certains types de fichiers ¥ Sinon le choix entre les 2 modes est une question de... choix :-) ¥ Quelques constantes: ¨ Affecter la responsabilité d’un module à une personne ¨ Si conflits fréquents sur un module, le scinder en morceaux plus petits ¨ La communication/synchronisation entre développeurs est fondamentale

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

10/65

Development tools

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.1 Multiversion—Problem statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.3.2 Multiversion—Éléments de réponse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.3.3 Multiversion—Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

11/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.1 Multiversion—Problem statement

¥ Développements en parallèle ¥ Reports d’une version à l’autre

Module A

Module B

Module C

1

1

1

2

2

V1.0

3

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

12/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.1 Multiversion—Problem statement

Module A

Module B

Module C

1

1

1

2

2

2

3

3

3

4

4

V1.0

V2.0

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

12/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.1 Multiversion—Problem statement

Module A

Module B

Module C

1

1

1

2

2

2

3

3

3

4

4

4

V2.0

5

V1.1

V1.0

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

12/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.1 Multiversion—Problem statement

Module A

Module B

Module C

1

1

1

2

2

2

3

3

3

4

4

4

V2.0

5

V1.1

6

V2.1

V1.0

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

12/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.2 Multiversion—Éléments de réponse

¥ Étiquette (“label” ou “tag” sur une version)

Module A

Module B

Module C

1

1

1

2

2

2

3

3

3

4

4

V1.0

V2.0

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

13/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.2 Multiversion—Éléments de réponse

¥ Branches

Module A

Module B

Module C

1

1

1

2

2

2

3

3

3

4

4

Maintenance 1

V1.0

V2.0

Maintenance 1

V1.1

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

13/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.2 Multiversion—Éléments de réponse ¥ Merge

Module A

Module B

Module C

1

1

1

2

2

2

3

3

3

4

4

Maintenance 1

V2.0

Maintenance V1.1

1 4

V1.0

5

V3.0

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

13/65

1 Source control management with Subversion

1.3 Travail en parallèle sur plusieurs versions

1.3.3 Multiversion—Discussion ¥ Why making branches? ¨ 1 branch per version? Module A V1

V2

¨ 1 branch per logical function? Module A f1

f2

...

Integration (Σ i )

¨ 1 branch per developper? Module A dev1 dev2

...

Integration (Σ devi )

¥ Depending upon the software developed! D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

14/65

Development tools

1 Source control management with Subversion

1.4 Presentation of Subversion 1.4.1 References and principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.4.2 Checking out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.4.3 Publishing or committing or checking in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.4.4 Updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.4.5 Adding a file or directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.4.6 Deleting or removing a file or a directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 1.4.7 Copying a file or a directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.4.8 Moving or renaming a file or a directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 1.4.9 Undoing or reverting changes *. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 1.4.10 Checking the status of a working file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.4.11 Displaying the differences and Examining histories * . . . . . . . . . . . . . . . . . . . . . . . . . 27 1.4.12 Basic work cycle with Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1.4.13 More on Subversion * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

15/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.1 References and principles ¥ GNU/Linux package or Windows TortoiseSVN (http://tortoisesvn.tigris.org/) ¥ Documentation ¨ Web site: http://subversion.tigris.org/ ¨ Free download of the svn book [Collins-Sussman et al., 2007] http://svnbook.red-bean.com/, see sanbotest/trunk/Docs ¥ For those who are accustomed to using CVS, CVS to SVN Crossover Guide: http://svn.collab.net/repos/svn/trunk/doc/user/cvs-crossover-guide.html

¥ Repository Vs. personal working copy, and record/track changes over time ¥ Enable collaborative editing and sharing of files ¨ Copy-Modify-Merge solution I Private work area: svn will never incorporate other people’s changes, nor make your own changes available to others, until you explicitly tell it to do so I You can have multiple working copies of the same project I Administrative area in .svn directories which contain meta-data ¨ Lock-Modify-Unlock solution: Provided in svn, but not shown here D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

16/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.2 Checking out ¥ Get a working copy ¥ Main repository access URL ¨ http://: Access via WebDAV protocol to svn-aware Apache server ¨ https://: Same as http://, but with SSL encryption ¨ svn://: Access via custom protocol to an svnserve server I E.g., svn checkout svn://svn.forge.objectweb.org/svnroot/fractal ¨ svn+ssh://: Same as svn://, but through an SSH tunnel I E.g., svn co svn+ssh://[email protected]/sandbotest ¥ Standard directory structure ¨ trunk: The “main line” of development ¨ branches: Branch copies —i.e., secondary line of developments ¨ tags: Tag copies —i.e., previous distinguished revisions ¨ sandbox: Developers’ sandboxes—i.e., “kind of private” area before contributing to branches or the trunk D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

17/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.3 Publishing or committing or checking in

¥ Report your local changes to the central (public) repository ¥ Either specify which files to commit Or rely on svn to know which files and directories need to be committed (using meta-data in the .svn directory) ¨ Atomic transaction: All the changes or none of them I In face of program crashes, systems crashes, network problems... ¥ E.g., svn commit -m"message..." File.java ¥ Each commit creates a new revision number (which applies to the entire tree) ¨ The last revision is called the HEAD

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

18/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.4 Updating ¥ Bring your working copy into sync with the latest revision in the central repository ¥ E.g., svn update SomeDir ¨ The most common “update codes” I U: No local changes, so updated with public changes from the repository I G: Local changes successfully merged with public changes I C: Conflicts —i.e., local changes overlap public changes ¥ Attempt to merge the public changes with the local ones ¨ If not possible, svn leaves it to the user to resolve the conflict I svn places three extra unversioned files in your working directory F filename.mine: working file before updating F filename.rOLDREV : revision file before local changes (in .svn) F filename.rNEWREV : HEAD revision of the repository I svn does not allow a commit until these three temporary files are removed F Resolve the conflict and next apply svn resolved filename =⇒ svn resolved removes these temporary files D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

19/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.5 Adding a file or directory

¥ Schedule a file or directory to be added at next commit ¥ The unversioned file or directory to add is in versioned tree of files ¥ E.g., svn add File.java, svn add NewDir ¥ NewDir =⇒ by default, recursive addition ¨ -N to only add NewDir —i.e., non-recursive

¥ svn mkdir NewDir = ( mkdir NewDir ; svn add NewDir )

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

20/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.6 Deleting or removing a file or a directory

¥ Schedule a file or directory to be deleted at next commit ¥ Files and directories that have not been committed are immediately removed from the working copy ¥ Files and directories locally changed are not removed ¨ Either commit first or force (option –force) ¥ Of course, nothing is ever totally deleted from the repository ¨ Just removed from the HEAD ¥ E.g., svn delete File.java or svn remove File.java

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

21/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.7 Copying a file or a directory ¥ Create a new item as a duplicate and automatically schedule it for addition ¥ The new item’s history is recorded as having originally come from the original item ¥ The two items are in the same repository —i.e., no cross-repository copying ¥ E.g., svn copy Original.java New.java

¥ The easiest way to “tag” a revision = svn copy the HEAD revision into the directory tags ¨ E.g., svn copy trunk tags/NewTag ¥ The easiest way to make a branch = svn copy the HEAD revision into the directory branches ¨ E.g., svn copy trunk branches/NewBranch

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

22/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.8 Moving or renaming a file or a directory

¥ Equivalent to a svn copy followed by svn delete ¨ The new item scheduled for addition as a copy of the original one at next commit ¨ The original item is scheduled for removal at next commit ¥ Only within a single repository —i.e., no cross-repository moving ¥ E.g., svn mv OrigDir/OrigFile.java TargetDir/NewName.java or svn rename OrigDir/OrigFile.java TargetDir/NewName.java

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

23/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.9 Undoing or reverting changes *

¥ Revert a working file or directory to their pre-modified state ¥ You don’t need to have any network access to the repository ¨ Subversion does this by keeping private caches of versioned file inside .svn =⇒ Undoing = retrieving the cache version in .svn ¥ E.g., svn revert File.java, svn revert SomeDir

¥ You can revert items mistakenly added or removed ¨ E.g., svn add File.java ; svn revert File.java ¨ E.g., svn remove File.java ; svn revert File.java

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

24/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.10 Checking the status of a working file ¥ File AND directories are versioned

¥ Different status—reminder: ¨ Unchanged and current: svn commit and svn update will do nothing ¨ Locally changed and current: svn commit will commit local changes and svn update will do nothing ¨ Unchanged and out-of-date: svn commit will do nothing and svn update will fold the latest public changes ¨ Locally changed and out-of-date: svn commit will fail with an “out-of-date” error and svn update will attempt to merge the public changes with the local ones I If update not possible, svn leaves it to the user to resolve the conflict

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

25/65

1 Source control management with Subversion

1.4 Presentation of Subversion

¥ E.g., svn status File.java ¨ The most common status codes I I I I I I

A: C: D: M: ?: L:

Scheduled for addition In a state of conflict (update overlap with local changes) Scheduled for deletion Locally changed Item not already versioned (before a add) Item locked (interruption of a svn command due to a problem)

¨ -u to contact the repository and add information about out-of-date items ¥ You don’t need to have any network access to the repository ¨ Subversion does this by keeping private caches of versioned file inside .svn

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

26/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.11 Displaying the differences and Examining histories * ¥ Displaying the differences ¨ Dig into the details of the changes you have made I In the unified diff format (Unix diff command) ¨ E.g., svn diff File.java or svn diff SomeDir ¨ You don’t need to have any network access to the repository I Subversion does this by keeping private caches of versioned file inside .svn ¥ Examining histories ¨ Display the history of changes up to the revision number of the working copy, that might not be up-to-date I E.g., svn log File.java F Who made the changes, at what revision/time/date, and the log message F More information with -v: copy, move... ¨ Any given version: E.g., svn cat -r 9999 File.java ¨ Files in a directory for any given revision: E.g., svn list -r 9999 SomeDir D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

27/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.12 Basic work cycle with Subversion

¥ Initial checkout: svn co repositoryName ¥ Begin cycle ¨ Update your working copy: svn update ¨ Make changes: svn add, svn delete, svn copy, svn move ¨ Examine your changes: svn status, svn diff ¨ Possibly undo some changes: svn revert ¨ Resolve conflicts (Merge other’s changes): svn update, svn resolved ¨ Commit your changes: svn commit ¥ End cycle

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

28/65

1 Source control management with Subversion

1.4 Presentation of Subversion

1.4.13 More on Subversion *

¥ Versioning symbolic links ¥ Importing = Copying an unversioned tree of files into a repository ¨ After the import, the original copy is not converted into a working directory ¨ To start working, you need to checkout a fresh copy of the tree ¨ E.g., svn import and then svn checkout ¥ Exporting = Bundle up your files tree without .svn directories ¨ E.g., svn export URL ¥ Branches: Copying changes between branches, merging a whole branch to another ¥ In case of problem, unlocking files with svn cleanup ¥ Changing the repository without having a working copy

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

29/65

Development tools

2 Project build with Ant and Maven

2.1 Motivations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 2.2 Presentation of Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.3 Presentation of Maven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

30/65

Development tools

2 Project build with Ant and Maven

2.1 Motivations

2.1.1 Ant beyond make-like tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.1.2 Maven beyond Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.1.3 Jar hell and plug-in hell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

31/65

2 Project build with Ant and Maven

2.1 Motivations

2.1.1 Ant beyond make-like tools ¥ Make was a marked improvement over shell script ¨ Abstraction of specific shell commands into a more general and consistent syntax ¨ Determines automatically which pieces of a large program need to be rebuilt and issues the commands ¥ But... ¨ Make mainly/historically targets the language C et C++ I Implicit rules and pattern rules F Execute make -p in a directory with no Makefile F Default suffixes: .out .a .ln .o .c .cc .C .cpp .p .f .F .r .y .l .s .S .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo .w .ch .web .sh .elc .el ¨ Make mainly/historically targets Unix-like operating systems I Machine-specific aspects of Make =⇒ less portable than the code to build ¥ Thus... ¨ Ant builds software across multiple platforms with plug-ins for Java D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

32/65

2 Project build with Ant and Maven

2.1 Motivations

2.1.2 Maven beyond Ant

¥ And finally... Maven ¨ Simplification of builds, documentation, distribution and deployment I Declarative model for software projects: Project Object Model (POM) F Reuse of build logic and default strategies for the most common tasks I Tools/plug-ins that interact with the declarative model F There already exists a very long list of such plug-ins I Organisation of dependencies F Management the of JAR hell F Management the of plug-in hell ¨ Written in Java, dedicated for writing in Java ¨ Access to all the Ant tasks

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

33/65

2 Project build with Ant and Maven

2.1 Motivations

2.1.3 Jar hell and plug-in hell cosmos−saje saje

cosmos−lib cosmos−core

dream−adl fscript

xerces

fractal−adl

dream−annotation

fractal−spoonlet

fractal−util

antlr

perseus−cache

julia−mixins julia−asm

dream−core

easymock aval

fractal−rmi log4j

task−deployment

dom4j

ast−core spoon−core

task−framework

xstream

jdom

commons−lang

joda−time

asm

dtdparser

junit

julia−runtime monolog−api

jsap ant eclipse.jdt.core

xml−writer stax wstw−asl

oro jmock jettison cglib_nodep

stax−api xom xpp3_min

fractal−api D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

34/65

Development tools

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7

References and principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 XML-based build file structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Example build file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Running Ant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Path-like structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Some Ant tasks * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 More on Ant * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

35/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.1 References and principles ¥ References ¨ Web site: http://ant.apache.org ¨ A short guide [Edlich, 2002] ¨ Manual pages: http://ant.apache.org/manual ¨ Tutorials: http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html http://supportweb.cs.bham.ac.uk/docs/tutorials/docsystem/build/ tutorials/ant/ant.html

¥ Principles ¨ Build files are “procedural” ¨ XML-based build and configuration files ¨ Pure Java =⇒ Extensible using Java classes I Target tree where various tasks get executed I Each task is run by an object that implements a Task interface ¨ Organisation of source code and other artefacts: src, build, dist... D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

36/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.2 XML-based build file structure ¥ Project: Upper most XML element containing targets ¨ name, default target, and basedir for path calculations ¥ Targets: Set of tasks you want to be executed ¨ The depends attribute specifies the order in which targets should be executed I Automatic management of the chain of dependencies I Can be condition-based (see if and unless attributes) ¥ Task: A piece of code that can be executed ¨ Can have multiple attributes (or arguments) ¨ Common structure: ¨ Catalog of predefined tasks + you can build specific tasks ¥ Properties of the project ¨ A name and a value ¨ ¨ ${product.name}=${buildir} D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

37/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.3 Example build file D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

38/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.4 Running Ant

¥ No argument =⇒ build.xml file in the current directory ¨ Use a build file other than build.xml: -buildfile file ¥ Assign properties on the command line: -Dproperty=value ¥ Execute a target different from the default one ¨ First, ant -p or ant help ¨ Next, ant targetName

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

39/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.5 Path-like structure ¥ path id, path refid, and pathelement D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

40/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.6 Some Ant tasks * ¥ Archive tasks: BUnzip2, BZip2, GUnzip, GZip, Tar, Untar, etc. ¥ Compile tasks: Depend, Javac, Rmic, etc. ¥ Deployment tasks: ServerDeploy... ¥ Documentation tasks: Javadoc/Javadoc2, etc. ¥ Execution tasks: Ant, AntCall, Exec, Java, Subant, etc. ¥ File tasks: Chmod, Chown, Concat, Copy, Delete, Filter, Get, Mkdir, Move, Patch, Touch, etc. ¥ Property tasks: Available, Basename, Condition, Dirname, Echoproperties, LoadProperties, Property, Uptodate, etc. ¥ Remote tasks: FTP, Scp, Sshexec, Telnet, etc. ¥ SCM tasks for CVS, Suversion, etc. ¥ Testing tasks: Junit, JunitReport D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

41/65

2 Project build with Ant and Maven

2.2 Presentation of Ant

2.2.7 More on Ant *

¥ Plug-in mechanism for using third party external tasks ¨ Writing Tasks http://ant.apache.org/manual/tutorial-writing-tasks.html ¥ filesets and patternsets: Bundling files by inclusion/exclusion ¥ Tasks using properties, filesets and paths http://ant.apache.org/manual/tutorial-tasks-filesets-properties.html

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

42/65

Development tools

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.1 References and principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.3.2 Standard directory structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 2.3.3 POM files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.3.4 Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.3.5 More on dependencies: Using snapshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 2.3.6 Default life-cycle for jar packaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.3.7 Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.3.8 Unit tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.3.9 Packaging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52 2.3.10 Default life-cycle for project’s web site generation * . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.3.11 More on Maven * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

43/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.1 References and principles ¥ Documentation ¨ Web site: http://maven.apache.org ¨ Free book (license GPL) [Sonatype, Inc., 2007] http://www.sonatype.com/book ¨ Another Free book (after registration) [Casey et al., 2006] ¨ Articles and tutorials: http://maven.apache.org/plugins ¥ Principles ¨ Single project producing a single output ¨ Standard naming conventions ¨ Version management and dependency management I groupId: Fully qualified domain name such as eu.int-edu I Artifact name of the form -. ¨ Repositories: Several remote and one local (~/.m2/repository populated from remote ones) I No more externals or lib and no more jars in developer’s directories D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

44/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.2 Standard directory structure ¥ pom.xml: Maven POM (Project Object Model) file always at the top-level ¥ LICENSE.txt: License file is encouraged ¥ README.txt: Simple note to start with the project ¥ src/main/java: Source code of the project ¥ src/main/filters: Filters (properties files) of the project for the build ¥ src/main/resources: Project non-source code (resources) ¥ src/main/config: Project source code filters ¥ src/main/filters: Project resource filters ¥ src/main/assembly: Project assembly filters ¥ src/test/java: Source code of the unit tests ¥ src/test/resources: non-source code (resources) of the unit tests ¥ src/test/filters: Resource filters of the tests ¥ src/site: Resources used to generate the web site ¥ target: Target for all generated output: classes, web site... D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

45/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.3 POM files ¥ Main values are inherited from the Super POM file ¥ Multi-module build and inheritance mechanism helloworld/pom.xml eu.int-evry helloworld pom 0.1-SNAPSHOT Hello world example first-sub-module second-sub-module ...

helloworld/first-sub-module/pom.xml

eu.int-evry helloworld 0.1-SNAPSHOT jar first-sub-module The first sub-module ...

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

46/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.4 Dependencies ¥ Add a dependency in the dependency graph (with or without specifying a version) eu.int-evry.first-helloworld an-artifact

¥ Share the same version of a dependency in all sub-modules ¨ Use the dependency management section in the top-level POM I State only the preference for a version, does not affect the dependency graph eu.int-evry.first-helloworld first-sub-module ${project.version} D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

47/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.5 More on dependencies: Using snapshots ¥ Version number = major.minor.bug fix-qualifier-build number ¨ E.g., 1.0.1-20070514-1 ¥ A snapshot in Maven is an artifact that has been prepared using the most recent sources available ¥ Snapshot dependencies are assumed to be changing ¥ Specifying a snapshot version for a dependency = Maven looks for new versions ¨ By default, on a daily basis ¨ -U command line option to force for updates ¨ interval:60 ¥ Specifying a non-snapshot version of a dependency = download that dependency only once

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

48/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.6 Default life-cycle for jar packaging

1. process-resources: Copy files and filter variable ¥ maven-resources-plugin 2. compile: Compile project source code ¥ maven-compile-plugin 3. process-test-resources: Copy non-source-code for unit test ¥ maven-resources-plugin 4. test-compile: Compile unit-test source code ¥ maven-compiler-pluging

5. test: Execute project unit tests ¥ maven-surfire-pluging 6. package: Create the jar of the project ¥ maven-jar-plugin 7. install: Install the jar into local Maven repository ¥ maven-install-plugin 8. deploy: Deploy the jar into a remote Maven repository ¥ maven-deploy-plugin

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

49/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.7 Compilation

¥ mvn compile ¥ To allow JDK 5.0 source code org.apache.maven.plugins maven-compiler-plugin 2.0 1.5 1.5

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

50/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.8 Unit tests

¥ Surfire plug-in: mvn test ¥ By default, the following tests are included ¨ **/*Test.java ¨ **/Test*.java ¨ **/*TestCase.java ¥ The following tests are excluded ¨ **/Abstract*Test.java ¨ **/Abstract*TestCase.java

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

51/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.9 Packaging ¥ mvn package ¥ Include project classes in target/classes ¥ Include project resources in src/main/resources ¥ Insert a manifest automatically generated by Maven ¥ Insert a pom.xml and a pom.properties files ¨ To be self-describing and to utilise meta-data during project execution ¥ To override the manifest file, in pom.xml of the project org.apache.maven.plugins maven-jar-plugin META-INF/MANIFEST.MF D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

52/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.10 Default life-cycle for project’s web site generation *

1. mvn site: Generate all configured project reports ¥ maven-site-plugin 2. site-deploy: Deploy the generated web site to the web server path specified in the POM distribution Management section ¥ maven-site-plugin

¥ Lots of web site reports: Javadoc, JXR (source code cross reference), Checkstyle/PMD (source code formatting rules), Tag list (track TODO items), Cobertura (unit test’s and execution’s coverage), Surefire Report (visual result of unit tests) Clirr (compare jars for binary compatibility), Changes, etc.

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

53/65

2 Project build with Ant and Maven

2.3 Presentation of Maven

2.3.11 More on Maven * ¥ Filtering resources: Parse some files to fill value to be supplied at build time ¥ Artifact deployment ¥ More on dependency management ¥ Creating plug-ins and inserting them in the build or site life-cycles ¥ Migrating from Ant to Maven ¥ Team collaboration ¨ Creating a shared repository ¨ Creating an organisation POM ¨ Continuous integration ¨ Team dependency management using snapshots ¨ Creating a standard project archetype

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

54/65

Development tools

3 Java programming with Eclipse

3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8

References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Motivations and principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Managing a project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61 Writing Java code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 More on Eclipse * . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

55/65

Development tools

3 Java programming with Eclipse

3.1 References ¥ Documentation ¨ Web site: http://www.eclipse.org ¨ A short guide [Burnette, 2005] ¨ The welcome screen proposes to explore introductory materials, including examples and tutorials I After the first execution, available in Help/Welcome ¥ Installation: debian package or package from the website ¨ Different flavors: I Java is the standard one I J2EE adds tools and wizards for enterprise development I RCP/Plugin allows to build your own Eclipse plugins I Classic contains developpment tools and source code for customizing Eclipse ¥ Plugins: http://www.eclipseplugincentral.com ¥ Tutorials: http://eclipse-tutorial.dev.java.net ¥ Eclipse help: http://help.eclipse.org D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

56/65

Development tools

3 Java programming with Eclipse

3.2 Motivations and principles

¥ Widely used IDE for Java (and made in Java), but not only ! ¥ Eclipse needs a JRE (1.4+) ¨ A specific Java compiler is embedded, no need for a JDK ¨ Suggestion: Use latest Sun’s JRE (some distrib use gcj, not recommended) ¥ Everything is a plugin ¨ Very extensible (UML, Test, GUI. . . ) and customizable ¨ A plugin can add new wizards/functionalities/. . . ¨ If you have boring/dirty work to do, search for a plugin ¨ Plugins can be installed by a simple ’unzip’ in the Plugins sub-directory

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

57/65

Development tools

3 Java programming with Eclipse

3.3 Terminology ¥ Workspace = location where settings will be stored ¨ Suggestion: Do not manually install your source code in your workspace ¥ Workbench = main window, composed of views and editors ¥ Perspective = a set of views, editors and toolbars = a configuration ¨ Resource: Arrange your files and projects ¨ Java: Develop programs in the Java language ¨ Debug: Diagnose and debug at runtime ¨ Java type hierarchy: Explore your code based on class relationships ¥ Main views ¨ Package explorer: All projects, Java packages and files ¨ Hierarchy: Class and interface relationships for the selected object ¨ Outline: Structure of the currently open file ¨ Problems: Compiler errors and warnings ¨ Console: Output of program executions D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

58/65

Development tools

3 Java programming with Eclipse

3.4 Workbench ¥ Open a view: Window/Show View ¥ Switch to a perspective: Window/Open Perspective or icon to the right of the main toolbar ¨ You can save your favourite window arrangements as named perspectives ¥ Configure the Java perspective ¨ Editor (emacs): Windows/Preferences/General/Editors/Keys/Modify/Scheme

¨ Text encoding (ISO-8859-1): Windows/Preferences/Workspace/Text file encoding

¨ Show line numbers and print margin (80 columns) Windows/Preferences/General/Editors/Text editors

¨ Code folding/unfolding (unfolding) Windows/Preferences/Java/Editor/Folding D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

59/65

Development tools

3 Java programming with Eclipse

¨ Code formating (eclipse 2.1 built-in) Windows/Preferences/Java/CodeStyle/Formatter

¨ Java JRE (do not choose gcj for Java 1.5) Windows/Preferences/Java/Installed JREs... Add... Browse...

¨ XML plug-in (for Fractal ADL files) I XML Buddy: http://www.xmlbuddy.com I unzip in the directory eclipse/plugins I Close and open eclipse, check for the new plug-in in Help/About Eclipse SDK... Plug-in Details

I Parse *.fractal files as XML files Windows/Preferences/General/Editors/File association... Add *.fractal and associate XMLBuddy

I Disable XML validation by XMLBuddy since the Fractal DTD is not a “true” DTD

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

60/65

Development tools

3 Java programming with Eclipse

3.5 Managing a project ¥ A project = a directory structure ¨ Hidden config files (.project and .classpath) ¥ Create a project, a package, a class ¥ Configure a project ¨ Compiler options Project/Properties/Java Compiler...

¨ Code templates (Java files header) Project/Properties/Java Code Style/Code Templates... Enable project specific settings... Comments... Files

¨ Indicate where is the source code Project/Properties... Java build path... Source

¨ Default output folder (eclipse-build instead of build) Project/Properties... Java build path... Source

¨ jar dependencies Project/Properties... Java build path... Libraries D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

61/65

Development tools

3 Java programming with Eclipse

3.6 Writing Java code

¥ Automatic insertion of “imports” ¥ “Content assist” for a list of suggested completions for partially entered strings ¨ Ctrl+Space or invoke Edit/Content Assist ¥ “Java assist” for automatic completion and documentation ¨ E.g., sysout → System.out.println(); ¨ E.g., for → proposes four forms ¥ Quick fix of errors and warnings ¨ Right click in the Problems view on the warning/error and chose Quick fix ¨ Click on the bubble of the warning/error, and select the correction

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

62/65

Development tools

3 Java programming with Eclipse

3.7 Tips and Tricks

¥ Ctrl+Shift+L: List of current key definitions for shortcuts ¨ Window/Preferences/General/Keys ¥ Ctrl+Shift+F: Reformat (beautify) your code ¥ Shift+Ctrl+O: Automatically add “imports” ¥ Ctrl+click on class name: Go to that source code ¥ Shift+Alt+/: Call to Java assist ¥ Ctrl+Space: Call to Content assist ¥ Shift+Alt+J: Add Javadoc comments ¥ Shift+Ctrl+/: Comment/Uncomment a line or a region

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

63/65

Development tools

3 Java programming with Eclipse

3.8 More on Eclipse *

¥ Execute Ant tasks: Windows/Show view/Ant and drag&drop the build.xml file ¥ Debugging ¥ Unit testing with JUnit ¥ Installing the plug-in subclipse to use Subversion http://subclipse.tigris.org/install.html

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

64/65

Development tools

References

[Burnette, 2005] Burnette, E. (2005). Eclipse IDE: Pocket Guide. O’Reilly. [Casey et al., 2006] Casey, J., Massol, V., Porter, B., Sanchez, C., and van Zyl, J. (2006). Better Builds with Maven: The How-To Guide for maven 2.0. Mergere Library Press. [Collins-Sussman et al., 2007] Collins-Sussman, B., Fitzpatrick, B., and Pilato, C. (2007). Version Control with Subversion: For Suversion 1.4. Creative Commons License. [Edlich, 2002] Edlich, S. (2002). Ant: Pocket Guide. O’Reilly. [Sonatype, Inc., 2007] Sonatype, Inc. (2007). Maven: The Definitive Guide (1.0 Alpha 2). http://www.sonatype.com/book/. Creative Commons License.

D. Conan, M. Simatic, S. Leriche — November 2007 — Projet Fin d’Étude ASR

65/65