Author: fdesbois Date: 2011-04-16 23:21:26 +0200 (Sat, 16 Apr 2011) New Revision: 2266 Url: http://nuiton.org/repositories/revision/topia/2266 Log: #1465 : Include topia-tutorial module in release build of project Add initialization for i18n + update doc Added: trunk/topia-tutorial/LICENSE.txt trunk/topia-tutorial/README.txt trunk/topia-tutorial/changelog.txt trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/StartTest.java Removed: trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/MainTest.java Modified: trunk/pom.xml trunk/topia-persistence/src/site/rst/user/start_using_api.rst trunk/topia-tutorial/pom.xml trunk/topia-tutorial/src/main/java/org/nuiton/topia/tutorial/library/LibraryConfig.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-04-16 21:18:53 UTC (rev 2265) +++ trunk/pom.xml 2011-04-16 21:21:26 UTC (rev 2266) @@ -105,11 +105,13 @@ <version>1.6.1</version> </dependency> - <!-- hibernate-core only include api, need core --> + <!-- hibernate-core only include api, need implementation, + binding with log4j will be used + --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> - <version>1.5.8</version> + <version>1.6.1</version> <scope>test</scope> </dependency> @@ -260,7 +262,7 @@ <nuitonI18nVersion>2.3.2</nuitonI18nVersion> <xmlrpcVersion>3.1.2</xmlrpcVersion> <hibernateVersion>3.3.2.GA</hibernateVersion> - + </properties> <build> @@ -328,6 +330,13 @@ </configuration> </plugin> + <plugin> + <artifactId>maven-release-plugin</artifactId> + <configuration> + <prepareVerifyArgs>-Ptutorial</prepareVerifyArgs> + </configuration> + </plugin> + </plugins> </pluginManagement> @@ -338,6 +347,35 @@ <excludeDefaults>true</excludeDefaults> </reporting> + <profiles> + + <!-- Build tutorial --> + <profile> + <id>tutorial</id> + <modules> + <module>topia-tutorial</module> + </modules> + </profile> + + <!-- This profile is here just to make more automatic release. + This profile will be use to do a releasse:prepare, this modules are not + in default build but need to be release + --> + <profile> + <id>extra-modules</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + <modules> + <module>topia-tutorial</module> + </modules> + </profile> + + </profiles> + <!-- ************************************************************* --> <!-- *** Build Environment ************************************** --> <!-- ************************************************************* --> Modified: trunk/topia-persistence/src/site/rst/user/start_using_api.rst =================================================================== --- trunk/topia-persistence/src/site/rst/user/start_using_api.rst 2011-04-16 21:18:53 UTC (rev 2265) +++ trunk/topia-persistence/src/site/rst/user/start_using_api.rst 2011-04-16 21:21:26 UTC (rev 2266) @@ -12,7 +12,6 @@ nécessaire. Dans le fichier ``src/main/resources/library-config.properties``, on définit - :: # Pour démarrer, on utilisera une base H2 @@ -32,7 +31,29 @@ # affiche toutes les requêtes effectuées sur la base dans la console hibernate.show_sql=true +Sans oublier les dépendances nécessaires à l'exécution :: + <dependencies> + ... + + <!-- Implémentation pour les logger --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>${sl4jVersion}</version> + <scope>runtime</scope> + </dependency> + + <!-- Driver pour la base de données H2 --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${h2Version}</version> + </dependency> + + </dependencies> + + Développer un premier service ============================= @@ -104,9 +125,49 @@ Suppression d'une entité. +Configuration I18n +------------------ + +ToPIA contient une internationnalisation des messages utilisateurs (logs). +Il est préférable d'initialiser I18n pour accélérer la recherche des messages. +Deux choses sont nécessaire : + + * Au démarrage de l'application :: + + I18nInitializer i18nInitializer = new DefaultI18nInitializer("library-bundle"); + I18n.init(i18nInitializer, new Locale("fr", "FR")); + + * Configuration maven :: + + <!-- Plugin i18n pour gérer le bundle de messages --> + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>maven-i18n-plugin</artifactId> + <version>${nuitonI18nVersion}</version> + <executions> + <!-- Cette exécution permet de rassembler tous les messages i18n + dans un seul 'properties bundle' nommé library-bundle + --> + <execution> + <id>make-bundle</id> + <configuration> + <bundleOutputName>library-bundle</bundleOutputName> + </configuration> + <goals> + <goal>bundle</goal> + </goals> + </execution> + </executions> + </plugin> + +Vous pourrez également utiliser `nuiton-i18n`_ pour l'internationnalisation de +votre application. + +.. _nuiton-i18n: http://maven-site.nuiton.org/i18n/ + Exemple complet --------------- -Un exemple complet dans MainTest_. +Un exemple complet dans StartTest_. -.. _MainTest: http://svn.nuiton.org/svn/topia/trunk/topia-tutorial/src/test/java/org/nuito... \ No newline at end of file +.. _StartTest: http://svn.nuiton.org/svn/topia/trunk/topia-tutorial/src/test/java/org/nuito... \ No newline at end of file Added: trunk/topia-tutorial/LICENSE.txt =================================================================== --- trunk/topia-tutorial/LICENSE.txt (rev 0) +++ trunk/topia-tutorial/LICENSE.txt 2011-04-16 21:21:26 UTC (rev 2266) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: trunk/topia-tutorial/README.txt =================================================================== --- trunk/topia-tutorial/README.txt (rev 0) +++ trunk/topia-tutorial/README.txt 2011-04-16 21:21:26 UTC (rev 2266) @@ -0,0 +1,3 @@ +Tutorial for topia + +see documentation : http://maven-site.nuiton.org/topia/topia-persistence/index.html Added: trunk/topia-tutorial/changelog.txt =================================================================== --- trunk/topia-tutorial/changelog.txt (rev 0) +++ trunk/topia-tutorial/changelog.txt 2011-04-16 21:21:26 UTC (rev 2266) @@ -0,0 +1,3 @@ +Changelog is no more maintained + +see nuiton.org forge for changes : http://nuiton.org/projects/show/topia Modified: trunk/topia-tutorial/pom.xml =================================================================== --- trunk/topia-tutorial/pom.xml 2011-04-16 21:18:53 UTC (rev 2265) +++ trunk/topia-tutorial/pom.xml 2011-04-16 21:21:26 UTC (rev 2266) @@ -2,55 +2,48 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.nuiton</groupId> + <artifactId>topia</artifactId> + <version>2.5.4-SNAPSHOT</version> + </parent> + <groupId>org.nuiton.topia</groupId> <artifactId>topia-tutorial</artifactId> - <version>1.0</version> - <packaging>jar</packaging> - <properties> + <dependencies> - <maven.compiler.source>1.6</maven.compiler.source> - <maven.compiler.target>1.6</maven.compiler.target> + <dependency> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-persistence</artifactId> + <version>${project.version}</version> + </dependency> - <topiaVersion>2.5.4-SNAPSHOT</topiaVersion> - <eugeneVersion>2.3.3</eugeneVersion> - <nuitonUtilsVersion>2.1.1</nuitonUtilsVersion> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> - </properties> - - <dependencies> - + <!--Used for ApplicationConfig --> <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> - <version>${nuitonUtilsVersion}</version> </dependency> <dependency> - <groupId>org.nuiton.topia</groupId> - <artifactId>topia-persistence</artifactId> - <version>${topiaVersion}</version> - </dependency> - - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> - <version>1.5.8</version> </dependency> - <!-- BD H2 for testing --> + <!-- H2 database --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> - <version>1.2.128</version> - <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.8.2</version> - <scope>test</scope> </dependency> </dependencies> @@ -97,6 +90,8 @@ <!-- *** Build Settings ****************************************** --> <!-- ************************************************************* --> + <packaging>jar</packaging> + <build> <plugins> @@ -129,6 +124,24 @@ </executions> </plugin> + <!-- I18n plugin to manage library bundle --> + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>maven-i18n-plugin</artifactId> + <executions> + <execution> + <id>make-bundle</id> + <configuration> + <bundleOutputName>library-bundle</bundleOutputName> + </configuration> + <goals> + <!-- This goal will simply push all existing I18n messages from nuiton to library-bundle files --> + <goal>bundle</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> </build> Modified: trunk/topia-tutorial/src/main/java/org/nuiton/topia/tutorial/library/LibraryConfig.java =================================================================== --- trunk/topia-tutorial/src/main/java/org/nuiton/topia/tutorial/library/LibraryConfig.java 2011-04-16 21:18:53 UTC (rev 2265) +++ trunk/topia-tutorial/src/main/java/org/nuiton/topia/tutorial/library/LibraryConfig.java 2011-04-16 21:21:26 UTC (rev 2266) @@ -1,10 +1,14 @@ package org.nuiton.topia.tutorial.library; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.init.DefaultI18nInitializer; +import org.nuiton.i18n.init.I18nInitializer; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.tutorial.library.model.LibraryDAOHelper; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; +import java.util.Locale; import java.util.Properties; /** @@ -19,6 +23,8 @@ protected ApplicationConfig config; + protected Locale locale; + public LibraryConfig() throws ArgumentsParserException { // New ApplicationConfig @@ -33,6 +39,10 @@ // It's a prerequisite otherwise entities will be unknown config.setOption(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, LibraryDAOHelper.getImplementationClassesAsString()); + + // Initialize I18n to display Topia log messages + I18nInitializer i18nInitializer = new DefaultI18nInitializer("library-bundle"); + I18n.init(i18nInitializer, getLocale()); } /** @@ -42,4 +52,11 @@ return config.getFlatOptions(); } + public Locale getLocale() { + if (locale == null) { + locale = new Locale("en", "GB"); + } + return locale; + } + } Deleted: trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/MainTest.java =================================================================== --- trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/MainTest.java 2011-04-16 21:18:53 UTC (rev 2265) +++ trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/MainTest.java 2011-04-16 21:21:26 UTC (rev 2266) @@ -1,115 +0,0 @@ -package org.nuiton.topia.tutorial.library; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.tutorial.library.model.Book; -import org.nuiton.topia.tutorial.library.model.BookDAO; -import org.nuiton.topia.tutorial.library.model.BookImpl; -import org.nuiton.topia.tutorial.library.model.LibraryDAOHelper; - -/** - * Created: 16/04/11 - * - * @author fdesbois <desbois@codelutin.com> - * $Id$ - */ -public class MainTest { - - protected TopiaContext rootContext; - - protected TopiaContext transaction; - - @Before - public void setUp() throws Exception { - - // Retrieve config and initialize TopiaContext root with Properties - LibraryConfig config = new LibraryConfig(); - rootContext = TopiaContextFactory.getContext(config.getProperties()); - - // Start the transaction - transaction = rootContext.beginTransaction(); - } - - @After - public void tearDown() throws Exception { - - // Close the transaction - transaction.closeContext(); - - // Drop the database (Work only with H2 database) - rootContext.clear(true); - } - - @Test - public void testCreateBook() throws Exception { - - // ---- PREPARE DATA ---- // - - Book book = new BookImpl(); - book.setName("Topia for dummies"); - book.setIsbn("T12"); - - // ---- EXECUTE ---- // - - BookDAO dao = LibraryDAOHelper.getBookDAO(transaction); - - dao.create(book); - - // Commit current transaction to save the entity in the database - transaction.commitTransaction(); - - // ---- CHECK DATA ---- // - - // Close current transaction to ensure database result - transaction.closeContext(); - - // Reopen a new transaction to retrieve the previously saved book - transaction = rootContext.beginTransaction(); - dao = LibraryDAOHelper.getBookDAO(transaction); - - // Retrieve the book from its topiaId (primary key) - Book bookLoaded = dao.findByTopiaId(book.getTopiaId()); - - // It is the same value ! - Assert.assertEquals(bookLoaded, book); - } - - @Test - public void testCreateBookUniqueConstraint() throws Exception { - - // ---- PREPARE DATA ---- // - - Book book = new BookImpl(); - book.setName("Topia for dummies"); - book.setIsbn("T12"); - - BookDAO dao = LibraryDAOHelper.getBookDAO(transaction); - dao.create(book); - - // ---- EXECUTE ---- // - - Book bookError = new BookImpl(); - bookError.setIsbn("T12"); - dao.create(bookError); - - try { - transaction.commitTransaction(); - Assert.fail("TopiaException is expected"); - } catch (TopiaException ex) { - - // Rollback the transaction, the book T12 will not be persisted - transaction.rollbackTransaction(); - } - - // ---- CHECK DATA ---- // - - // no book exists - Assert.assertEquals(0, dao.count()); - } - -} Copied: trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/StartTest.java (from rev 2263, trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/MainTest.java) =================================================================== --- trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/StartTest.java (rev 0) +++ trunk/topia-tutorial/src/test/java/org/nuiton/topia/tutorial/library/StartTest.java 2011-04-16 21:21:26 UTC (rev 2266) @@ -0,0 +1,115 @@ +package org.nuiton.topia.tutorial.library; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.tutorial.library.model.Book; +import org.nuiton.topia.tutorial.library.model.BookDAO; +import org.nuiton.topia.tutorial.library.model.BookImpl; +import org.nuiton.topia.tutorial.library.model.LibraryDAOHelper; + +/** + * Created: 16/04/11 + * + * @author fdesbois <desbois@codelutin.com> + * $Id$ + */ +public class StartTest { + + protected TopiaContext rootContext; + + protected TopiaContext transaction; + + @Before + public void setUp() throws Exception { + + // Retrieve config and initialize TopiaContext root with Properties + LibraryConfig config = new LibraryConfig(); + rootContext = TopiaContextFactory.getContext(config.getProperties()); + + // Start the transaction + transaction = rootContext.beginTransaction(); + } + + @After + public void tearDown() throws Exception { + + // Close the transaction + transaction.closeContext(); + + // Close rootContext and drop the database (Work only with H2 database) + rootContext.clear(true); + } + + @Test + public void testCreateBook() throws Exception { + + // ---- PREPARE DATA ---- // + + Book book = new BookImpl(); + book.setName("Topia for dummies"); + book.setIsbn("T12"); + + // ---- EXECUTE ---- // + + BookDAO dao = LibraryDAOHelper.getBookDAO(transaction); + + dao.create(book); + + // Commit current transaction to save the entity in the database + transaction.commitTransaction(); + + // ---- CHECK DATA ---- // + + // Close current transaction to ensure database result + transaction.closeContext(); + + // Reopen a new transaction to retrieve the previously saved book + transaction = rootContext.beginTransaction(); + dao = LibraryDAOHelper.getBookDAO(transaction); + + // Retrieve the book from its topiaId (primary key) + Book bookLoaded = dao.findByTopiaId(book.getTopiaId()); + + // It is the same value ! + Assert.assertEquals(bookLoaded, book); + } + + @Test + public void testCreateBookUniqueConstraint() throws Exception { + + // ---- PREPARE DATA ---- // + + Book book = new BookImpl(); + book.setName("Topia for dummies"); + book.setIsbn("T12"); + + BookDAO dao = LibraryDAOHelper.getBookDAO(transaction); + dao.create(book); + + // ---- EXECUTE ---- // + + Book bookError = new BookImpl(); + bookError.setIsbn("T12"); + dao.create(bookError); + + try { + transaction.commitTransaction(); + Assert.fail("TopiaException is expected"); + } catch (TopiaException ex) { + + // Rollback the transaction, the book T12 will not be persisted + transaction.rollbackTransaction(); + } + + // ---- CHECK DATA ---- // + + // no book exists + Assert.assertEquals(0, dao.count()); + } + +}