branch develop updated (c3bc8c3 -> e8f49cd)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-utils. See https://gitlab.nuiton.org/nuiton/nuiton-utils.git from c3bc8c3 Ajout du calcul de jours ouvrés (avec par l'implantation pour les vacances pour la france) new e8f49cd Remove deprecated code Do not use deprecated code anymore The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit e8f49cd5fecb81f14767740950cf574d2f9df219 Author: jcouteau <couteau@codelutin.com> Date: Fri Sep 13 17:36:25 2019 +0200 Remove deprecated code Do not use deprecated code anymore Summary of changes: pom.xml | 10 +- src/main/java/org/nuiton/util/AliasMap.java | 31 +- src/main/java/org/nuiton/util/FileUtil.java | 338 +---------- src/main/java/org/nuiton/util/ObjectUtil.java | 166 ----- src/main/java/org/nuiton/util/PagerBean.java | 122 ---- src/main/java/org/nuiton/util/PagerBeanUtil.java | 131 ---- src/main/java/org/nuiton/util/SemVer.java | 676 --------------------- src/main/java/org/nuiton/util/Version.java | 350 ----------- src/main/java/org/nuiton/util/VersionUtil.java | 568 ----------------- src/main/java/org/nuiton/util/ZipUtil.java | 3 +- src/main/java/org/nuiton/util/beans/Binder.java | 7 +- .../org/nuiton/util/converter/ColorConverter.java | 81 --- .../org/nuiton/util/converter/ConverterUtil.java | 206 ------- .../org/nuiton/util/converter/EnumConverter.java | 152 ----- .../org/nuiton/util/converter/FormatConverter.java | 94 --- .../util/converter/FormatConverterFactory.java | 192 ------ .../java/org/nuiton/util/converter/FormatMap.java | 191 ------ .../nuiton/util/converter/KeyStrokeConverter.java | 75 --- .../org/nuiton/util/converter/URIConverter.java | 93 --- .../org/nuiton/util/converter/URLConverter.java | 95 --- .../nuiton/util/converter/VersionConverter.java | 88 --- .../org/nuiton/util/converter/package-info.java | 40 -- src/main/java/org/nuiton/util/version/SemVer.java | 644 -------------------- src/main/java/org/nuiton/util/version/Version.java | 486 --------------- .../org/nuiton/util/version/VersionBuilder.java | 428 ------------- .../org/nuiton/util/version/VersionComparator.java | 222 ------- .../org/nuiton/util/version/VersionConverter.java | 87 --- .../java/org/nuiton/util/version/Versions.java | 280 --------- src/test/java/org/nuiton/util/AliasMapTest.java | 1 + src/test/java/org/nuiton/util/ObjectUtilTest.java | 25 - .../java/org/nuiton/util/PagerBeanUtilTest.java | 78 --- src/test/java/org/nuiton/util/ResourceTest.java | 6 +- src/test/java/org/nuiton/util/SemVerTest.java | 231 ------- src/test/java/org/nuiton/util/VersionTest.java | 156 ----- src/test/java/org/nuiton/util/VersionUtilTest.java | 471 -------------- .../nuiton/util/converter/ConverterUtilTest.java | 81 --- .../util/converter/UnregistreableConverter.java | 41 -- .../util/converter/VersionConverterTest.java | 101 --- .../java/org/nuiton/util/version/SemVerTest.java | 223 ------- .../nuiton/util/version/VersionBuilderTest.java | 87 --- .../nuiton/util/version/VersionComparatorTest.java | 74 --- .../java/org/nuiton/util/version/VersionTest.java | 69 --- .../java/org/nuiton/util/version/VersionsTest.java | 117 ---- 43 files changed, 33 insertions(+), 7584 deletions(-) delete mode 100644 src/main/java/org/nuiton/util/PagerBean.java delete mode 100644 src/main/java/org/nuiton/util/PagerBeanUtil.java delete mode 100644 src/main/java/org/nuiton/util/SemVer.java delete mode 100644 src/main/java/org/nuiton/util/Version.java delete mode 100644 src/main/java/org/nuiton/util/VersionUtil.java delete mode 100644 src/main/java/org/nuiton/util/converter/ColorConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/ConverterUtil.java delete mode 100644 src/main/java/org/nuiton/util/converter/EnumConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/FormatConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/FormatConverterFactory.java delete mode 100644 src/main/java/org/nuiton/util/converter/FormatMap.java delete mode 100644 src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/URIConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/URLConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/VersionConverter.java delete mode 100644 src/main/java/org/nuiton/util/converter/package-info.java delete mode 100644 src/main/java/org/nuiton/util/version/SemVer.java delete mode 100644 src/main/java/org/nuiton/util/version/Version.java delete mode 100644 src/main/java/org/nuiton/util/version/VersionBuilder.java delete mode 100644 src/main/java/org/nuiton/util/version/VersionComparator.java delete mode 100644 src/main/java/org/nuiton/util/version/VersionConverter.java delete mode 100644 src/main/java/org/nuiton/util/version/Versions.java delete mode 100644 src/test/java/org/nuiton/util/PagerBeanUtilTest.java delete mode 100644 src/test/java/org/nuiton/util/SemVerTest.java delete mode 100644 src/test/java/org/nuiton/util/VersionTest.java delete mode 100644 src/test/java/org/nuiton/util/VersionUtilTest.java delete mode 100644 src/test/java/org/nuiton/util/converter/ConverterUtilTest.java delete mode 100644 src/test/java/org/nuiton/util/converter/UnregistreableConverter.java delete mode 100644 src/test/java/org/nuiton/util/converter/VersionConverterTest.java delete mode 100644 src/test/java/org/nuiton/util/version/SemVerTest.java delete mode 100644 src/test/java/org/nuiton/util/version/VersionBuilderTest.java delete mode 100644 src/test/java/org/nuiton/util/version/VersionComparatorTest.java delete mode 100644 src/test/java/org/nuiton/util/version/VersionTest.java delete mode 100644 src/test/java/org/nuiton/util/version/VersionsTest.java -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-utils. See https://gitlab.nuiton.org/nuiton/nuiton-utils.git commit e8f49cd5fecb81f14767740950cf574d2f9df219 Author: jcouteau <couteau@codelutin.com> Date: Fri Sep 13 17:36:25 2019 +0200 Remove deprecated code Do not use deprecated code anymore --- pom.xml | 10 +- src/main/java/org/nuiton/util/AliasMap.java | 31 +- src/main/java/org/nuiton/util/FileUtil.java | 338 +---------- src/main/java/org/nuiton/util/ObjectUtil.java | 166 ----- src/main/java/org/nuiton/util/PagerBean.java | 122 ---- src/main/java/org/nuiton/util/PagerBeanUtil.java | 131 ---- src/main/java/org/nuiton/util/SemVer.java | 676 --------------------- src/main/java/org/nuiton/util/Version.java | 350 ----------- src/main/java/org/nuiton/util/VersionUtil.java | 568 ----------------- src/main/java/org/nuiton/util/ZipUtil.java | 3 +- src/main/java/org/nuiton/util/beans/Binder.java | 7 +- .../org/nuiton/util/converter/ColorConverter.java | 81 --- .../org/nuiton/util/converter/ConverterUtil.java | 206 ------- .../org/nuiton/util/converter/EnumConverter.java | 152 ----- .../org/nuiton/util/converter/FormatConverter.java | 94 --- .../util/converter/FormatConverterFactory.java | 192 ------ .../java/org/nuiton/util/converter/FormatMap.java | 191 ------ .../nuiton/util/converter/KeyStrokeConverter.java | 75 --- .../org/nuiton/util/converter/URIConverter.java | 93 --- .../org/nuiton/util/converter/URLConverter.java | 95 --- .../nuiton/util/converter/VersionConverter.java | 88 --- .../org/nuiton/util/converter/package-info.java | 40 -- src/main/java/org/nuiton/util/version/SemVer.java | 644 -------------------- src/main/java/org/nuiton/util/version/Version.java | 486 --------------- .../org/nuiton/util/version/VersionBuilder.java | 428 ------------- .../org/nuiton/util/version/VersionComparator.java | 222 ------- .../org/nuiton/util/version/VersionConverter.java | 87 --- .../java/org/nuiton/util/version/Versions.java | 280 --------- src/test/java/org/nuiton/util/AliasMapTest.java | 1 + src/test/java/org/nuiton/util/ObjectUtilTest.java | 25 - .../java/org/nuiton/util/PagerBeanUtilTest.java | 78 --- src/test/java/org/nuiton/util/ResourceTest.java | 6 +- src/test/java/org/nuiton/util/SemVerTest.java | 231 ------- src/test/java/org/nuiton/util/VersionTest.java | 156 ----- src/test/java/org/nuiton/util/VersionUtilTest.java | 471 -------------- .../nuiton/util/converter/ConverterUtilTest.java | 81 --- .../util/converter/UnregistreableConverter.java | 41 -- .../util/converter/VersionConverterTest.java | 101 --- .../java/org/nuiton/util/version/SemVerTest.java | 223 ------- .../nuiton/util/version/VersionBuilderTest.java | 87 --- .../nuiton/util/version/VersionComparatorTest.java | 74 --- .../java/org/nuiton/util/version/VersionTest.java | 69 --- .../java/org/nuiton/util/version/VersionsTest.java | 117 ---- 43 files changed, 33 insertions(+), 7584 deletions(-) diff --git a/pom.xml b/pom.xml index cd130cb..7075a63 100644 --- a/pom.xml +++ b/pom.xml @@ -25,8 +25,8 @@ <parent> <groupId>org.nuiton</groupId> - <artifactId>mop</artifactId> - <version>1-SNAPSHOT</version> + <artifactId>nuitonpom</artifactId> + <version>10.5</version> </parent> <artifactId>nuiton-utils</artifactId> @@ -130,6 +130,8 @@ <!-- redmine project Id --> <projectName>nuiton-utils</projectName> <projectGroup>nuiton</projectGroup> + <projectId>nuiton-utils</projectId> + <ciViewId>nuiton-utils</ciViewId> <!-- Java level --> <javaVersion>1.8</javaVersion> @@ -189,7 +191,7 @@ <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - <version>23.0</version> + <version>28.1-jre</version> </dependency> <dependency> @@ -237,7 +239,7 @@ <dependency> <groupId>org.nuiton.jrst</groupId> <artifactId>doxia-module-jrst</artifactId> - <version>2.3-SNAPSHOT</version> + <version>2.3</version> </dependency> </dependencies> </plugin> diff --git a/src/main/java/org/nuiton/util/AliasMap.java b/src/main/java/org/nuiton/util/AliasMap.java index 7e6c9b1..0212621 100644 --- a/src/main/java/org/nuiton/util/AliasMap.java +++ b/src/main/java/org/nuiton/util/AliasMap.java @@ -24,7 +24,8 @@ package org.nuiton.util; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.map.MultiValueMap; +import org.apache.commons.collections4.MultiValuedMap; +import org.apache.commons.collections4.multimap.HashSetValuedHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,13 +63,13 @@ public class AliasMap<K, V, A> extends HashMap<K, V> { private static final long serialVersionUID = 1L; /** key: alias, value: key */ - protected MultiValueMap aliases; + protected MultiValuedMap<A, K> aliases; /** key: key, value: alias */ - protected MultiValueMap keys; + protected MultiValuedMap<K, A> keys; public AliasMap() { - aliases = MultiValueMap.multiValueMap(new HashMap(), HashSet.class); - keys = MultiValueMap.multiValueMap(new HashMap(), HashSet.class); + aliases = new HashSetValuedHashMap<>(); + keys = new HashSetValuedHashMap<>(); } /** @@ -96,7 +97,7 @@ public class AliasMap<K, V, A> extends HashMap<K, V> { protected void putAlias(K key, A alias1, A ... alias) { aliases.put(alias1, key); keys.put(key, alias1); - for (Object a : alias) { + for (A a : alias) { aliases.put(a, key); keys.put(key, a); } @@ -123,8 +124,8 @@ public class AliasMap<K, V, A> extends HashMap<K, V> { */ public Collection<K> getKeyAlias(A ... alias) { Collection result = null; - for (Object a : alias) { - Collection tmp = aliases.getCollection(a); + for (A a : alias) { + Collection tmp = aliases.get(a); if (tmp != null) { if (result == null) { result = new HashSet(tmp); @@ -184,7 +185,7 @@ public class AliasMap<K, V, A> extends HashMap<K, V> { * @return FIXME */ public Collection<A> getAlias(K key) { - Collection result = keys.getCollection(key); + Collection<A> result = keys.get(key); if (result == null) { result = Collections.emptySet(); } @@ -208,16 +209,16 @@ public class AliasMap<K, V, A> extends HashMap<K, V> { @Override public V remove(Object key) { V result = super.remove(key); - Collection alias = getAlias((K)key); - keys.remove(key); + Collection<A> alias = getAlias((K)key); if (alias != null) { - for (Object a : alias) { + for (A a : alias) { aliases.removeMapping(a, key); - if (CollectionUtils.isEmpty(aliases.getCollection(a))) { + if (CollectionUtils.isEmpty(aliases.get(a))) { aliases.remove(a); } } } + keys.remove(key); return result; } @@ -260,8 +261,8 @@ public class AliasMap<K, V, A> extends HashMap<K, V> { * @param alias FIXME */ public void removeAlias(A ... alias) { - for (Object a : alias) { - Collection ks = aliases.getCollection(a); + for (A a : alias) { + Collection ks = aliases.get(a); aliases.remove(a); if (ks != null) { for (Object k : ks) { diff --git a/src/main/java/org/nuiton/util/FileUtil.java b/src/main/java/org/nuiton/util/FileUtil.java index 9d09354..ac1b076 100644 --- a/src/main/java/org/nuiton/util/FileUtil.java +++ b/src/main/java/org/nuiton/util/FileUtil.java @@ -86,292 +86,6 @@ public class FileUtil { // FileUtil // TODO fdesbois 2011-04-16 : Perhaps change ISO encoding by UTF-8 public static String ENCODING = "ISO-8859-1"; - /** - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - protected static File currentDirectory = new File("."); - - /** - * @param dir FIXME - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static void setCurrentDirectory(File dir) { - currentDirectory = dir; - } - - /** - * @return FIXME - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getCurrentDirectory() { - return currentDirectory; - } - - /** - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static class PatternChooserFilter extends javax.swing.filechooser.FileFilter { - protected String pattern; - - protected String description; - - public PatternChooserFilter(String pattern, String description) { - this.pattern = pattern; - this.description = description; - } - - @Override - public boolean accept(File f) { - return f.isDirectory() || f.getAbsolutePath().matches(pattern); - } - - @Override - public String getDescription() { - return description; - } - - } - - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. - * - * @param patternOrDescriptionFilters les filtres a utiliser, les chaines doivent etre données - * par deux, le pattern du filtre + la description du filtre - * @return le fichier accepté, ou null si rien n'est chois ou l'utilisateur a annulé - * @see #getFile(javax.swing.filechooser.FileFilter...) - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getFile(String... patternOrDescriptionFilters) { - File result; - result = getFile(null, patternOrDescriptionFilters); - return result; - } - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. - * - * @param filters les filtres a ajouter - * @return le fichier accepté, ou null si rien n'est chois ou l'utilisateur a annulé - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getFile(javax.swing.filechooser.FileFilter... filters) { - File result = getFile(null, filters); - return result; - } - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. - * - * @param parent le component parent du dialog - * @param patternOrDescriptionFilters les filtres a utiliser, les chaines doivent etre données - * par deux, le pattern du filtre + la description du filtre - * @return le fichier accepté, ou null si rien n'est chois ou l'utilisateur a annulé - * @see #getFile(javax.swing.filechooser.FileFilter...) - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getFile(Component parent, - String... patternOrDescriptionFilters) { - File result; - result = getFile("Ok", "Ok", parent, patternOrDescriptionFilters); - return result; - } - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. - * - * @param title le titre de la boite de dialogue - * @param approvalText le label du boutton d'acceptation - * @param parent le component parent du dialog - * @param patternOrDescriptionFilters les filtres a utiliser, les chaines doivent etre données - * par deux, le pattern du filtre + la description du filtre - * @return le fichier accepté, ou null si rien n'est chois ou l'utilisateur a annulé - * @see #getFile(javax.swing.filechooser.FileFilter...) - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getFile(String title, - String approvalText, - Component parent, - String... patternOrDescriptionFilters) { - - if (patternOrDescriptionFilters.length % 2 != 0) { - throw new IllegalArgumentException( - "Arguments must be (pattern, description) couple"); - } - javax.swing.filechooser.FileFilter[] filters = - new javax.swing.filechooser.FileFilter[ - patternOrDescriptionFilters.length / 2]; - for (int i = 0; i < filters.length; i++) { - String pattern = patternOrDescriptionFilters[i * 2]; - String description = patternOrDescriptionFilters[i * 2 + 1]; - filters[i] = new PatternChooserFilter(pattern, description); - } - File result; - result = getFile(title, approvalText, parent, filters); - return result; - } - - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. - * - * @param parent le component parent du dialog - * @param filters les filtres a ajouter - * @return le fichier accepté, ou null si rien n'est chois ou l'utilisateur a annulé - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getFile(Component parent, - javax.swing.filechooser.FileFilter... filters) { - File result = getFile("Ok", "Ok", parent, filters); - return result; - } - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. - * - * @param title le titre de la boite de dialogue - * @param approvalText le label du boutton d'acceptation - * @param parent le component parent du dialog - * @param filters les filtres a ajouter - * @return le fichier accepté, ou null si rien n'est chois ou l'utilisateur a annulé - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static File getFile(String title, - String approvalText, - Component parent, - javax.swing.filechooser.FileFilter... filters) { - try { - JFileChooser chooser = new JFileChooser(currentDirectory); - - chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); - if (filters.length > 0) { - if (filters.length == 1) { - chooser.setFileFilter(filters[0]); - } else { - for (javax.swing.filechooser.FileFilter filter : filters) { - chooser.addChoosableFileFilter(filter); - } - } - } - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - chooser.setDialogTitle(title); - int returnVal = chooser.showDialog(parent, approvalText); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File theFile = chooser.getSelectedFile(); - if (theFile != null) { - currentDirectory = theFile; - return theFile.getAbsoluteFile(); - } - } - } catch (Exception eee) { - log.warn("Erreur:", eee); - } - return null; - } - - /** - * @return le nom du repertoire entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne - * null. - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static String getDirectory() { - return getDirectory(null, "Ok", "Ok"); - } - - /** - * @param title le nom de la boite de dialogue - * @param approvalText le texte de l'action d'acceptation du répertoire dans le file chooser - * @return le nom du repertoire entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne - * null. - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static String getDirectory(String title, String approvalText) { - String result = getDirectory(null, title, approvalText); - return result; - } - - /** - * @param parent le component parent du dialog - * @param title le nom de la boite de dialogue - * @param approvalText le texte de l'action d'acceptation du répertoire dans le file chooser - * @return le nom du repertoire entre dans la boite de dialogue. - * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne - * null. - * @deprecated since 2.6.13, prefer use same method in - * jaxx.runtime.FileChooserUtil class in jaxx-runtime project - * (see http://svn.nuiton.org/svn/jaxx/trunk/jaxx-runtime/src/main/java/jaxx/runtime/FileChooserUtil} - */ - @Deprecated - public static String getDirectory(Component parent, - String title, - String approvalText) { - try { - JFileChooser chooser = new JFileChooser(currentDirectory); - chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setDialogTitle(title); - int returnVal = chooser.showDialog(parent, approvalText); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File theFile = chooser.getSelectedFile(); - if (theFile != null) { - currentDirectory = theFile; - if (theFile.isDirectory()) { - return theFile.getAbsolutePath(); - } - } - } else { - return null; - } - } catch (Exception eee) { - log.warn("Erreur:", eee); - } - return null; - } - /** * Permet de convertir des bytes en fichier, le fichier sera automatiquement * supprimé a la fin de la JVM. @@ -382,28 +96,7 @@ public class FileUtil { // FileUtil */ public static File byteToFile(byte[] bytes) throws IOException { File file = File.createTempFile("FileUtil-byteToFile", ".tmp"); - byteToFile(bytes, file); - return file; - } - - /** - * Permet de convertir des bytes en fichier - * - * @param bytes the array of bytes to put in the given destination file - * @param file le fichier dans lequel il faut ecrire les bytes - * @return le fichier passé en parametre - * @throws IOException if any io pb - * @deprecated since 2.4.6, prefer use method {@link FileUtils#writeByteArrayToFile(File, byte[])} - */ - @Deprecated - public static File byteToFile(byte[] bytes, - File file) throws IOException { - OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); - try { - out.write(bytes); - } finally { - out.close(); - } + FileUtils.writeByteArrayToFile(file, bytes); return file; } @@ -505,33 +198,6 @@ public class FileUtil { // FileUtil return createTempDirectory(prefix, suffix, null); } - /** - * Permet de sauver une chaine directement dans un fichier - * - * @param file Le fichier dans lequel il faut ecrire la chaine - * @param content Le texte a ecrire dans le fichier - * @param encoding encoding to use - * @throws IOException if any pb while writing - * @deprecated since 2.4.6, prefer use method {@link FileUtils#writeStringToFile(File, String, String)}. - */ - @Deprecated - public static void writeString(File file, - String content, - String encoding) throws IOException { - //fixme on doit tester le retour de la méthode, car il se peut que le répertoire - // ne puisse être crée. - File parentFile = file.getParentFile(); - //TODO tchemit 2011-05-15 Must test if directory was created (use - // the #createDirectoryIfNecessary method). - if (parentFile != null) { - parentFile.mkdirs(); - } - - BufferedWriter out = getWriter(file, encoding); - out.write(content); - out.close(); - } - /** * Permet de donner une representation fichier pour une chaine de caractere. * Le fichier sera automatiquement effacé à la fin de la JVM. @@ -558,7 +224,7 @@ public class FileUtil { // FileUtil File result = File.createTempFile("tmp-" + FileUtil.class.getName(), fileSuffix); result.deleteOnExit(); - FileUtils.write(result, content); + FileUtils.write(result, content, Charset.defaultCharset()); return result; } diff --git a/src/main/java/org/nuiton/util/ObjectUtil.java b/src/main/java/org/nuiton/util/ObjectUtil.java index 5ba6297..6eecb7a 100644 --- a/src/main/java/org/nuiton/util/ObjectUtil.java +++ b/src/main/java/org/nuiton/util/ObjectUtil.java @@ -555,172 +555,6 @@ public class ObjectUtil { // ObjectUtil return result; } - /** - * Method toObject - * - * @param o Object to transform - * @return the same object - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(Object o) { - return o; - } - - /** - * Method toObject - * - * transform a char to a Character Object - * - * @param c the char to transform - * @return the Charactere object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(char c) { - return new Character(c); - } - - /** - * Method toObject - * - * transform a byte to a Byte Object - * - * @param b the byte to transform - * @return the byte object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(byte b) { - return new Byte(b); - } - - /** - * Method toObject - * - * transform a short to a Short object - * - * @param s the short to transform - * @return the Short object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(short s) { - return new Short(s); - } - - /** - * Method toObject - * - * transform an int to an Integer object - * - * @param i the int to transform - * @return the Integer Object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(int i) { - return new Integer(i); - } - - /** - * Method toObject - * - * transform a long to a Long object - * - * @param l the long to transform - * @return the Long Object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(long l) { - return new Long(l); - } - - /** - * Method toObject - * - * transform a float to a Float Object - * - * @param f the float to transform - * @return the Float Object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(float f) { - return new Float(f); - } - - /** - * Method toObject - * - * transform a double to a Double object - * - * @param d the double to transform - * @return the Double object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(double d) { - return new Double(d); - } - - /** - * Method toObject - * - * transform a boolean to a Boolean object - * - * @param b the boolean to transform - * @return the Boolean object corresponding - * @deprecated since 2.6 (since java 5 boxing-unboxing does it for you) - */ - @Deprecated - public static Object toObject(boolean b) { - return b ? Boolean.TRUE : Boolean.FALSE; - } - - /** - * Obtains the null value for the given type (works too with primitive - * types). - * - * @param type the type to test - * @return the {@code null} value or default value for primitive types - * @see com.google.common.base.Defaults - * @since 1.1.5 - * @deprecated since 2.6 (there is some other library which does it - */ - @Deprecated - public static Object getNullValue(Class<?> type) { - if (type == null) { - throw new NullPointerException("parameter 'type' can not be null"); - } - if (type.isPrimitive()) { - type = MethodUtils.getPrimitiveWrapper(type); - if (Boolean.class.isAssignableFrom(type)) { - return Boolean.FALSE; - } - if (Integer.class.isAssignableFrom(type)) { - return ZERO; - } - if (Character.class.isAssignableFrom(type)) { - return ZEROC; - } - if (Float.class.isAssignableFrom(type)) { - return ZEROF; - } - if (Long.class.isAssignableFrom(type)) { - return ZEROL; - } - if (Double.class.isAssignableFrom(type)) { - return ZEROD; - } - if (Byte.class.isAssignableFrom(type)) { - return ZEROB; - } - } - return null; - } - /** * Tests if the given value is null according to default value for * primitive types if nedded. diff --git a/src/main/java/org/nuiton/util/PagerBean.java b/src/main/java/org/nuiton/util/PagerBean.java deleted file mode 100644 index 5d9374f..0000000 --- a/src/main/java/org/nuiton/util/PagerBean.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.nuiton.util; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.lang3.builder.ToStringBuilder; - -import java.io.Serializable; - -/** - * A pager bean. - * - * Was previously {@code org.nuiton.util.PagerUtil.PagerBean}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.6.2 - * @deprecated since 3.0, prefer using {@link org.nuiton.util.pagination.PaginationParameter}. - */ -@Deprecated -public class PagerBean implements Serializable { - - private static final long serialVersionUID = 1L; - - /** Number of records (says numbers of rows displayable. */ - protected long records; - - /** Index of the first record in this page. */ - protected long recordStartIndex; - - /** Index of the last record in this page. */ - protected long recordEndIndex; - - /** Index of the page. */ - protected int pageIndex; - - /** Page size, says number of records in a page. */ - protected int pageSize; - - /** Number of pages. */ - protected long pagesNumber; - - public long getRecords() { - return records; - } - - public long getRecordStartIndex() { - return recordStartIndex; - } - - public long getRecordEndIndex() { - return recordEndIndex; - } - - public int getPageIndex() { - return pageIndex; - } - - public int getPageSize() { - return pageSize; - } - - public long getPagesNumber() { - return pagesNumber; - } - - public void setRecords(long records) { - this.records = records; - } - - public void setRecordStartIndex(long recordStartIndex) { - this.recordStartIndex = recordStartIndex; - } - - public void setRecordEndIndex(long recordEndIndex) { - this.recordEndIndex = recordEndIndex; - } - - public void setPageIndex(int pageIndex) { - this.pageIndex = pageIndex; - } - - public void setPageSize(int pageSize) { - this.pageSize = pageSize; - } - - public void setPagesNumber(long pagesNumber) { - this.pagesNumber = pagesNumber; - } - - @Override - public String toString() { - String result = new ToStringBuilder(this) - .append("records", records) - .append("recordStartIndex", recordStartIndex) - .append("recordEndIndex", recordEndIndex) - .append("pageIndex", pageIndex) - .append("pageSize", pageSize) - .append("pagesNumber", pagesNumber) - .toString(); - return result; - } - -} diff --git a/src/main/java/org/nuiton/util/PagerBeanUtil.java b/src/main/java/org/nuiton/util/PagerBeanUtil.java deleted file mode 100644 index 8838717..0000000 --- a/src/main/java/org/nuiton/util/PagerBeanUtil.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.nuiton.util; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.lang3.tuple.Pair; - -import java.util.ArrayList; -import java.util.List; - -/** - * Useful method around {@link PagerBean}. - * - * Was previously {@code org.nuiton.util.PagerUtil}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.6.2 - */ -public class PagerBeanUtil { - - /** - * Given a total count of elements and a page size, compute the number of - * pages available. - * - * @param totalCount total count of elements in the pager - * @param pageSize size of a page - * @return the number of available pages - */ - public static long getTotalPage(long totalCount, int pageSize) { - long result = (long) Math.ceil((double) totalCount / (double) pageSize); - return result; - } - - /** - * Compute the pager bound given his datas: - * <ul> - * <li>{@code totalCount}: count of all elements of the pager</li> - * <li>{@code pageSize}: number of elements in a page</li> - * <li>{@code page}: the requested page number starting at {@code 1}</li> - * </ul> - * - * @param totalCount total count of elements in the pager - * @param page pager page number (starting at {@code 1}) - * @param pageSize number of elements in a page - * @return the bound of start and end index of the requested elements of the pager - */ - public static Pair<Long, Long> getPageBound(long totalCount, - int page, - int pageSize) { - - page = Math.max(page, 1); - long pageSize2 = pageSize == -1 ? totalCount : Math.max(pageSize, 1); - - long start = (page - 1l) * pageSize2; - long end = page * pageSize2; // End in subList is exclusive - - end = Math.min(end, totalCount); //To be sure that end will not be out of bound in subList - - Pair<Long, Long> result = Pair.of(start, end); - return result; - } - - /** - * Get the elements of the lists using the pager datas: - * - * <ul> - * <li>{@code elements}:all elements of the pager</li> - * <li>{@code pageSize}: number of elements in a page</li> - * <li>{@code page}: the requested page number starting at {@code 1}</li> - * </ul> - * - * @param elements all pager elements - * @param page pager page number (starting at {@code 1}) - * @param pageSize number of elements in a page - * @param <E> n'importe quel type - * @return la liste une fois filtrée - */ - public static <E> List<E> getPage(List<E> elements, int page, int pageSize) { - - Pair<Long, Long> bound = getPageBound(elements.size(), page, pageSize); - - long start = bound.getLeft(); - long end = bound.getRight(); - - List<E> subList = elements.subList((int) start, (int) end); - List<E> result = new ArrayList<E>(subList); - - return result; - } - - /** - * Given a pagerBean, compute his {@link PagerBean#recordStartIndex}, - * {@link PagerBean#recordEndIndex} and {@link PagerBean#pagesNumber}. - * - * @param bean the pagerBean to fill - * @since 2.4.3 - */ - public static void computeRecordIndexesAndPagesNumber(PagerBean bean) { - long records = bean.getRecords(); - int pageSize = bean.getPageSize(); - - Pair<Long, Long> pageBound = - getPageBound(records, bean.getPageIndex(), pageSize); - bean.setRecordStartIndex(pageBound.getLeft()); - bean.setRecordEndIndex(pageBound.getRight()); - bean.setPagesNumber(getTotalPage(records, pageSize)); - } - - public static PagerBean newPagerBean() { - return new PagerBean(); - } -} diff --git a/src/main/java/org/nuiton/util/SemVer.java b/src/main/java/org/nuiton/util/SemVer.java deleted file mode 100644 index 8ce2c4e..0000000 --- a/src/main/java/org/nuiton/util/SemVer.java +++ /dev/null @@ -1,676 +0,0 @@ -package org.nuiton.util; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.Validate; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Implantation de http://semver.org/. - * <p> - * Cette objet est immutable, Il faut utiliser {@link #getCreator()} - * pour modifier un de ses elements - * <p> - * Quelques changement par rapport au site: - * <ul> - * <li> le numero de version peut avoir entre 1 et N element, et non pas 3 obligatoirement - * <li> on peut avoir un -SNAPSHOT ajoute en toute fin de la version - * </ul> - * <p> - * Un SemVer est en plusieurs elements dont chaque element peut avoir plusieurs - * composant. Les composants sont utilise le meme separateur '.'. - * <ul> - * <li> version: 1 à N composant numerique, les 3 premiers sont nomme - * <ul> - * <li> major - * <li> minor - * <li> patch - * </ul> - * <li> prerelease: 0 à N composant alphanumerique, le prefix est '-' - * <li> build: 0 à N composant alphanumerique, le prefix est '+' - * <li> SNAPSHOT: 0 ou 1 composant dont le nom est fixe le prefix est '-' - * </ul> - * Le mieux pour construire ou modifier un SemVer est d'utilise une methode creator: - * <ul> - * <li> SemVer.creator(1,2,3).done() → "1.2.3" - * <li> SemVer.creator("1.2.3","rc2").done() → "1.2.3-rc2" - * <li> SemVer.creator().setVersion(2.3.4).setBuild("r223").done() → "2.3.4+r223" - * <li> SemVer.creator().setVersion(2.3.4).setSnapshot(true).done() → "2.3.4-SNAPSHOT" - * <li> SemVer.creator(new SemVer("1.2.3")).incMajor().done() → "2.2.2" - * <li> new SemVer("1.2.3").getCreator().incMinor().setPrerelease(beta).done() → "1.3.3-beta" - * </ul> - * - * @author Benjamin Poussin - poussin@codelutin.com - * @since 2.6.7 - * @deprecated since 3.0 (use now {@link org.nuiton.util.version.SemVer}). - */ -@Deprecated -public class SemVer implements Comparable<SemVer> { - - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(SemVer.class); - - /** - * Separateur utiliser entre chaque element d'une partie - */ - final static public String SERIES_SEPARATOR = "."; // le separateur - /** - * Seperateur entre la version et l'element prerelease - */ - final static public String PRERELEASE_SEPARATOR = "-"; // le separateur de Prerelease - /** - * Separateur utiliser devant l'element build - */ - final static public String BUILD_SEPARATOR = "+"; // le separateur de build - - /** - * pattern pour une partie de l'element version - */ - final static public String PATTERN_VERSION = "[0-9]+"; // le version ne sont que des nombres - /** - * pattern pour une partie de l'element prerelease - */ - final static public String PATTERN_PRERELEASE = "[0-9A-Za-z-]+"; // les Prerelease sont des chiffre, lettre ou '-' - /** - * pattern pour une partir de l'element build - */ - final static public String PATTERN_BUILD = "[0-9A-Za-z-]+";// les Build sont des chiffre, lettre ou '-' - - /** - * Separateur de SNAPSHOT - */ - final static public String SNAPSHOT_SEPARATOR = "-"; - /** - * la chaine de caractere representant le SNAPSHOT - */ - final static public String SNAPSHOT = "SNAPSHOT"; - - // "(1.20.300)(-alpha-1.20)?(+r123.20130126)?" - // version prerelease build - /** - * pattern qui permet de separer les 3 constituante d'une version, ne - * supporte pas le SNAPSHOT, il faut donc que le SNAPSHOT ait ete retirer - * avant d'appliquer le pattern - */ - final static Pattern PATTERN_ALL = Pattern.compile( - "(" + PATTERN_VERSION + "(?:" + Pattern.quote(SERIES_SEPARATOR) + PATTERN_VERSION + ")*)" + - "(" + Pattern.quote(PRERELEASE_SEPARATOR) + PATTERN_PRERELEASE + "(?:" + Pattern.quote(SERIES_SEPARATOR) + PATTERN_PRERELEASE + ")*)?" + - "(" + Pattern.quote(BUILD_SEPARATOR) + PATTERN_BUILD + "(?:" + Pattern.quote(SERIES_SEPARATOR) + PATTERN_BUILD + ")*)?"); - - protected String version; - protected String prerelease; - protected String build; - protected String snapshot; - - /** - * Create new Version object, strip is done on argument to remove extra space - * - * @param versionString FIXME - * @throws IllegalArgumentException if argument isn't valid version string - */ - public SemVer(String versionString) { - String v = StringUtils.strip(versionString); // on conserve versionString intact pour le message d'erreur - if (StringUtils.endsWithIgnoreCase(v, SNAPSHOT_SEPARATOR + SNAPSHOT)) { - snapshot = SNAPSHOT; - v = StringUtils.substringBeforeLast(v, SNAPSHOT_SEPARATOR); - } - Matcher matcher = PATTERN_ALL.matcher(v); - boolean match = matcher.matches(); - if (match) { - version = matcher.group(1); - prerelease = StringUtils.removeStart(matcher.group(2), PRERELEASE_SEPARATOR); - build = StringUtils.removeStart(matcher.group(3), BUILD_SEPARATOR); - } else { - throw new IllegalArgumentException(String.format("Bad version string: '%s'", versionString)); - } - } - - /** - * @param o the other version to test - * @return {@code true} if current version is before the given one - */ - public boolean before(SemVer o) { - int result = compareTo(o); - return result < 0; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is after the given one - */ - public boolean after(SemVer o) { - int result = compareTo(o); - return result > 0; - } - - public int compareTo(SemVer other) { - int result = compare(this.getVersion(), other.getVersion(), false); - if (result == 0) { - result = compare(this.getPrerelease(), other.getPrerelease(), true); - if (result == 0) { - result = compare(this.getBuild(), other.getBuild(), false); - if (result == 0) { - result = compare(this.getSnapshot(), other.getSnapshot(), true); - } - } - } - return result; - } - - /** - * Compare deux elements de meme semantique (version, prerelease, build, snapshot) - * sinon le comportement est non predictible - * - * @param a FIXME - * @param b FIXME - * @param nullIsHigh indique si un des elements est null, s'il est plus - * grand ou plus petit que l'autre - * @return negatif si a inferieur b, 0 si a == b, positif si a superieur a b - */ - protected int compare(String a, String b, boolean nullIsHigh) { - int result; - if (nullIsHigh) { - result = nullIsHigh(a, b); - } else { - result = nullIsLow(a, b); - } - - if (result == 0 && a != null && b != null) { - // on decoupe suivant le '.' - String[] aSeries = StringUtils.split(a, SERIES_SEPARATOR); - String[] bSeries = StringUtils.split(b, SERIES_SEPARATOR); - - int length = Math.max(aSeries.length, bSeries.length); - for (int i = 0; result == 0 & i < length; i++) { - // s'il y en a un qui est plus court, on prend par defaut "" - String va = i < aSeries.length ? aSeries[i] : ""; - String vb = i < bSeries.length ? bSeries[i] : ""; - - // s'il n'y a que des nombres pour une valeur on ajoute des espaces - // devant pour qu'il est la meme longueur que l'autre et ainsi - // pouvoir les comparer lexicographiquement - int pad = Math.max(va.length(), vb.length()); - if (StringUtils.isNumeric(va)) { - va = StringUtils.leftPad(va, pad); - } - if (StringUtils.isNumeric(vb)) { - vb = StringUtils.leftPad(vb, pad); - } - - // on compare les deux valeurs - result = va.compareTo(vb); - } - } - return result; - } - - /** - * Ne compare par le chaine, seulement la nullite, si un des arguments - * est null, alors il est plus grand que l'autre. - * <p> - * 1.0 est plus grand que 1.0-Beta - * - * @param a FIXME - * @param b FIXME - * @return FIXME - */ - protected int nullIsHigh(String a, String b) { - int result = 0; - if (a == null ^ b == null) { - if (a == null) { - result = 1; - } else { - result = -1; - } - } - return result; - } - - /** - * Ne compare par le chaine, seulement la nullite, si un des arguments - * est null, alors il est plus petit que l'autre. - * <p> - * 1.0+r123 est plus grand que 1.0 - * - * @param a FIXME - * @param b FIXME - * @return FIXME - */ - protected int nullIsLow(String a, String b) { - int result = 0; - if (a == null ^ b == null) { - if (a == null) { - result = -1; - } else { - result = 1; - } - } - return result; - } - - /** - * Donne le nombre de composante de l'element - * <ul> - * <li>1.2.3 retourne 3 - * <li>99.100 retourne 2 - * </ul> - * - * @param element FIXME - * @return FIXME - */ - protected int getComposantCount(String element) { - int result = 0; - if (StringUtils.isNotBlank(element)) { - result = 1 + StringUtils.countMatches(element, SERIES_SEPARATOR); - } - return result; - } - - /** - * Retourne un des composants de l'element version - * - * @param element FIXME - * @param i FIXME - * @return FIXME - */ - protected String getComposant(String element, int i) { - String[] v = StringUtils.split(element, SERIES_SEPARATOR); - Validate.validIndex(v, i, - "Ask '%s', element '%s' don't have enought composant", i, element); - - String s = v[i]; - return s; - } - - - public String getVersion() { - return version; - } - - /** - * Donne le nombre de composante de la version - * <ul> - * <li>1.2.3 retourne 3 - * <li>99.100 retourne 2 - * </ul> - * - * @return FIXME - */ - public int getVersionCount() { - int result = getComposantCount(getVersion()); - return result; - } - - /** - * Retourne un des composants de l'element version - * - * @param i FIXME - * @return FIXME - */ - public String getVersion(int i) { - String s = getComposant(getVersion(), i); - return s; - } - - public String getMajor() { - String result = getVersion(0); - return result; - } - - public String getMinor() { - String result = getVersion(1); - return result; - } - - public String getPatch() { - String result = getVersion(2); - return result; - } - - public String getPrerelease() { - return prerelease; - } - - /** - * Donne le nombre de composante de la Prerelease - * <ul> - * <li>1.2.3 retourne 3 - * <li>99.100 retourne 2 - * </ul> - * - * @return FIXME - */ - public int getPrereleaseCount() { - int result = getComposantCount(getPrerelease()); - return result; - } - - /** - * Retourne un des composants de l'element version - * - * @param i FIXME - * @return FIXME - */ - public String getPrerelease(int i) { - String s = getComposant(getPrerelease(), i); - return s; - } - - public String getBuild() { - return build; - } - - /** - * Donne le nombre de composante de la Prerelease - * <ul> - * <li>1.2.3 retourne 3 - * <li>99.100 retourne 2 - * </ul> - * - * @return FIXME - */ - public int getBuildCount() { - int result = getComposantCount(getBuild()); - return result; - } - - /** - * Retourne un des composants de l'element version - * - * @param i FIXME - * @return FIXME - */ - public String getBuild(int i) { - String s = getComposant(getBuild(), i); - return s; - } - - public String getSnapshot() { - return snapshot; - } - - public boolean isSnapshot() { - return StringUtils.isNotBlank(snapshot); - } - - static protected String ifNotNull(String prefix, String s) { - String result = ""; - if (StringUtils.isNotBlank(s)) { - result = prefix + s; - } - return result; - } - - @Override - public boolean equals(Object o) { - boolean result = o instanceof SemVer && this.compareTo((SemVer) o) == 0; - return result; - } - - @Override - public int hashCode() { - return toString().hashCode(); - } - - /** - * Convertit la representation textuelle de la version en identifiant java valide : - * - en java : "-" "." "+" interdit - * - * @return la valeur ou les carateres interdits sont remplaces par '_' - */ - public String toJavaIdentifier() { - String result = toString(); - - // attention dans les crochets le '-' a une signification, il faut donc le mettre en 1er - result = result.replaceAll("[-+.]", "_"); - - return result; - } - - @Override - public String toString() { - return getVersion() - + ifNotNull(PRERELEASE_SEPARATOR, getPrerelease()) - + ifNotNull(BUILD_SEPARATOR, getBuild()) - + ifNotNull(SNAPSHOT_SEPARATOR, getSnapshot()); - } - - /** - * Retourne un objet creator initialise avec les donnees de ce SemVer - * ce qui permet de creer un nouveau SemVer en modifiant un des elements - * - * @return FIXME - */ - public SemVerCreator getCreator() { - return creator(this); - } - - /** - * Indique si la chaine represente bien une version au format SemVer - * - * @param version FIXME - * @return FIXME - */ - static public boolean isSemVer(String version) { - if (StringUtils.endsWithIgnoreCase(version, SNAPSHOT)) { - version = StringUtils.substringBeforeLast(version, SNAPSHOT); - } - Matcher matcher = PATTERN_ALL.matcher(version); - boolean result = matcher.matches(); - return result; - } - - /** - * Permet de creer un objet version. Si des arguments sont passer en parametre - * ils sont pris dans l'ordre pour: la version, la prerelease, le build, le snapshot - * <pre> - * SemVer v = SemVer.creator().setVersion("1.2").setPrerelease("beta.1").setBuild("r123").done(); - * SemVer v = SemVer.creator("1.2", "beta.1","r123", SemVer.SNAPSHOT).done(); - * </pre> - * - * @param v FIXME - * @return FIXME - */ - static public SemVerCreator creator(String... v) { - SemVerCreator result = new SemVerCreator(); - if (v != null) { - if (v.length > 0) { - result.setVersion(v[0]); - if (v.length > 1) { - result.setPrerelease(v[1]); - if (v.length > 2) { - result.setBuild(v[2]); - if (v.length > 3) { - if (v[3] == null) { - result.setSnapshot(false); - } else if (StringUtils.equalsIgnoreCase(SNAPSHOT, v[3])) { - result.setSnapshot(true); - } else { - throw new IllegalArgumentException(String.format( - "Illegal SNAPSHOT string '%s'", - v[3])); - } - if (v.length > 4) { - throw new IllegalArgumentException(String.format( - "too many string arguments '%s' maximum 4", - v.length)); - } - } - } - } - } - } - return result; - } - - /** - * Createur qui permet de passer en parametre les different composante de - * l'element version - * - * @param v FIXME - * @return FIXME - */ - static public SemVerCreator creator(int... v) { - SemVerCreator result = creator(StringUtils.join(v, SERIES_SEPARATOR)); - return result; - } - - /** - * Create creator initialized with SemVer value, you can change some Element - * by puting null value. - * <p> - * SemVer n = SemVer.creator(v).setBuild("r123").setSnapshot(false).done(); - * - * @param v FIXME - * @return FIXME - */ - static public SemVerCreator creator(SemVer v) { - SemVerCreator result = creator( - v.getVersion(), v.getPrerelease(), v.getBuild(), v.getSnapshot()); - return result; - } - - /** - * Retourne un Createur sans aucune information. Cette methode permet - * aussi de desambiguise les deux autres methode creator qui si elle - * n'ont pas de parametre sont semblable - * - * @return FIXME - */ - static public SemVerCreator creator() { - SemVerCreator result = new SemVerCreator(); - return result; - } - - /** - * Construit un objet version, la verification de la coherence est faite lors - * de l'appel du create. - */ - static public class SemVerCreator { - protected String version; - protected String prerelease; - protected String build; - protected String snapshot; - - public SemVerCreator setVersion(Integer... v) { - // l'argument est bien Integer, car join ne travail qu'avec des objets :( - version = StringUtils.join(v, SERIES_SEPARATOR); - return this; - } - - public SemVerCreator setVersion(String v) { - version = v; - return this; - } - - public SemVerCreator setPrerelease(String v) { - prerelease = v; - return this; - } - - public SemVerCreator setBuild(String v) { - build = v; - return this; - } - - public SemVerCreator setSnapshot(boolean b) { - if (b) { - snapshot = SNAPSHOT; - } else { - snapshot = null; - } - return this; - } - - /** - * Incremente la composante 'indice' de l'element version de 'inc', la composante - * doit representer un entier sinon une exception est leve - * - * @param indice la composante de la version a incrementer - * @param inc le nombre a lui ajouter - * @return new instance, this SemVer is not modified - */ - public SemVerCreator incVersion(int indice, int inc) { - String[] v = StringUtils.split(version, SERIES_SEPARATOR); - Validate.validIndex(v, indice, "Version don't have enought composant"); - - String s = v[indice]; - - Validate.isTrue(StringUtils.isNumeric(s), "String '%s' must be numeric", s); - int i = Integer.parseInt(s); - i += inc; - s = String.valueOf(i); - - v[indice] = s; - version = StringUtils.join(v, SERIES_SEPARATOR); - - return this; - } - - /** - * Return new instance, this SemVer is not modified - * - * @return new instance where major version number is incremented by 1 - */ - public SemVerCreator incMajor() { - return incVersion(0, 1); - } - - /** - * Return new instance, this SemVer is not modified - * - * @return new instance where major version number is incremented by 1 - */ - public SemVerCreator incMinor() { - return incVersion(1, 1); - } - - /** - * Return new instance, this SemVer is not modified - * - * @return new instance where major version number is incremented by 1 - */ - public SemVerCreator incPatch() { - return incVersion(2, 1); - } - - public SemVer done() { - SemVer result = new SemVer( - StringUtils.defaultString(version) + - ifNotNull(PRERELEASE_SEPARATOR, prerelease) + - ifNotNull(BUILD_SEPARATOR, build) + - ifNotNull(SNAPSHOT_SEPARATOR, snapshot) - ); - return result; - } - } - -} diff --git a/src/main/java/org/nuiton/util/Version.java b/src/main/java/org/nuiton/util/Version.java deleted file mode 100644 index a3aa90b..0000000 --- a/src/main/java/org/nuiton/util/Version.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.lang3.ObjectUtils; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.regex.Matcher; - -import static org.nuiton.i18n.I18n.t; - -/** - * A class to represent an application version with possible classifier. - * - * Replace previously org.nuiton.util.VersionNumber class. - * - * Simple version number is defined like this : - * <pre> - * 1.0.0 or 1 - * </pre> - * - * A version can be more complex, with a classifier like this : - * <pre> - * 1.0.0-alpha-1, 1.0.0-beta-2, 1.0.0-rc-1 - * </pre> - * - * A classifier (alpha, beta, rc, ...) must be follwed by a classifier number. - * - * Note : - * - * - initial value is 0 - * - * - the equals order is defined on {@link #getVersion()} property. - * - * - the class is comparable, using the natural version order : - * - * <pre>0 <0.1 <1 <1.0 <1.1-alpha-0 <1.1-alpha-1 <1.1-beta-0 < 1.1-rc-1 <1.1 </pre> - * - * - the class is immutable, you should not instanciate directly a Version, - * but prefer use the factory static methods - * {@code VersionUtil.valueOf(...)} instead. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.1.0 - * @deprecated since 3.0 (use now {@link org.nuiton.util.version.Version}). - */ -@Deprecated -public class Version implements Comparable<Version>, Serializable { - - private static final long serialVersionUID = 1L; - - /** Version V0 */ - public static final Version VZERO = new Version(); - - /** optional classifier */ - protected final String classifier; - - /** optional classifier number (if no classifier should be null) */ - protected final Integer classifierNumber; - - /** main numbers of the version */ - protected final int[] numbers; - - /** - * boolean to define if version is a snapshot (if so a -SNAPSHOT is - * added at the end of the textual representation of the version). - * - * @since 2.4.3 - */ - protected final boolean snapshot; - - /** - * A flag to attach or not the classifier with his number. - * - * If set to false (the default cas then a - will be used to separe them). - * - * Even if the {@link Version} class is immutable, this state can be change - * since it is only used to build the string representation of a version. - * - * Notes that this state is NOT used to test equality of two version, - * neither for the comparaison. - * - * @since 2.4.3 - */ - protected boolean classifierNumberAttached; - - /** - * representation textuelle de la version (celle utilisee dans le - * {@link #toString()}. - */ - protected transient String version; - - /** Constructeur par defaut, definit la version par defaut, i.e 0 */ - public Version() { - this(0); - } - - /** - * Constructeur d'une version simple (sans classifier). - * - * @param numbers les nombres de la version - */ - public Version(int... numbers) { - this(null, null, false, numbers); - } - - /** - * Constructeur d'une version (simple ou avec classifier) - * - * @param classifier le classifier (peut-être null) - * @param classiferNumber la version du classifier (doit etre null si le - * classifier est null) - * @param numbers les nombres de la version - */ - public Version(String classifier, Integer classiferNumber, int... numbers) { - this(classifier, classiferNumber, false, numbers); - } - - /** - * Constructeur d'une version (simple ou avec classifier) - * - * @param classifier le classifier (peut-être null) - * @param classiferNumber la version du classifier (doit etre null si le - * classifier est null) - * @param snapshot boolean pour renseigner le champ {@link #snapshot}. - * @param numbers les nombres de la version - * @since 2.4.3 - */ - public Version(String classifier, Integer classiferNumber, - boolean snapshot, int... numbers) { - this.numbers = numbers.length == 0 ? new int[]{0} : numbers; - // always keep a lower case classifier - this.classifier = classifier == null ? null : - classifier.trim().toLowerCase(); - classifierNumber = classiferNumber; - this.snapshot = snapshot; - } - - /** - * Constructeur de version a partir de sa representation textuelle - * - * @param version la represention de la version a instancier - * @throws IllegalArgumentException si la version n'est pas valide - */ - public Version(String version) throws IllegalArgumentException { - if (version == null || version.trim().isEmpty()) { - // version par defaut - version = "0"; - } - - Matcher matcher = VersionUtil.VERSION_PATTERN.matcher(version); - - if (!matcher.matches()) { - - // try with classifier number attached to classifier - matcher = VersionUtil.VERSION_PATTERN2.matcher(version); - classifierNumberAttached = true; - } - - if (!matcher.matches()) { - // not a known pattern - throw new IllegalArgumentException( - t("nuitonutil.error.version.pattern", version)); - } - - // get numbers as string - String[] strNumbers = matcher.group(1).split("\\."); - String strClassifier = matcher.group(2); - String strClassifierNumber = matcher.group(3); - String strSnapshot = matcher.group(4); - Integer intClassifierNumber = null; - - if (strClassifier != null) { - - // possede un classifier - - // classifier number - intClassifierNumber = Integer.valueOf(strClassifierNumber); - } - - snapshot = strSnapshot != null; - - // numbers - numbers = new int[strNumbers.length]; - - for (int i = 0, j = strNumbers.length; i < j; i++) { - String number = strNumbers[i].trim(); - numbers[i] = Integer.valueOf(number); - } - - // classifier - classifier = strClassifier; - - // classifier number - classifierNumber = intClassifierNumber; - } - - public int[] getNumbers() { - return numbers; - } - - public String getClassifier() { - return classifier; - } - - public boolean hasClassifier() { - return classifier != null && !classifier.isEmpty(); - } - - public Integer getClassifierNumber() { - return classifierNumber; - } - - public boolean isSnapshot() { - return snapshot; - } - - public int getNbComponents() { - return numbers.length; - } - - public boolean isClassifierNumberAttached() { - return classifierNumberAttached; - } - - public int getNumber(int level) { - if (level < 0 || level >= numbers.length) { - throw new IllegalArgumentException( - "not a valid level " + level + " for the VersionNumber " + - this); - } - return numbers[level]; - } - - public String getVersion() { - if (version == null) { - StringBuilder sb = new StringBuilder(); - for (int number : numbers) { - sb.append('.').append(number); - } - if (hasClassifier()) { - sb.append('-'); - sb.append(classifier); - if (!classifierNumberAttached) { - sb.append('-'); - } - sb.append(classifierNumber); - } - if (isSnapshot()) { - sb.append(VersionUtil.SNAPSHOT_SUFFIX); - } - version = sb.substring(1); - } - return version; - } - - /** - * Convertit la representation textuelle de la version en identifiant java valide : - * - en java : "." interdit - * - en mysql, h2 ... : "." interdit - * - * @return la valeur ou les carateres interdits sont remplaces par '_' - */ - public String getValidName() { - String validName = getVersion(); - - // replace ". et -" - validName = validName.replaceAll("\\.|-", "_"); - - return validName; - } - - /** - * Change the internal state {@link #classifierNumberAttached}. - * - * @param classifierNumberAttached the new value of the classifierNumberAttached state - */ - public void setClassifierNumberAttached(boolean classifierNumberAttached) { - if (version != null) { - // will force - version = null; - } - this.classifierNumberAttached = classifierNumberAttached; - } - - @Override - public String toString() { - String t = getVersion(); - return t; - } - - @Override - public int compareTo(Version o) { - int result = VersionUtil.DEFAULT_VERSION_COMPARATOR.compare(this, o); - return result; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is before the given one - */ - public boolean before(Version o) { - int result = compareTo(o); - return result < 0; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is after the given one - */ - public boolean after(Version o) { - int result = compareTo(o); - return result > 0; - } - - @Override - public boolean equals(Object obj) { - return obj != null && obj instanceof Version && - Arrays.equals(numbers, ((Version) obj).numbers) && - ObjectUtils.equals(classifier, ((Version) obj).classifier) && - ObjectUtils.equals(classifierNumber, ((Version) obj).classifierNumber) && - ObjectUtils.equals(snapshot, ((Version) obj).snapshot); - } - - @Override - public int hashCode() { - return getVersion().hashCode(); - } -} diff --git a/src/main/java/org/nuiton/util/VersionUtil.java b/src/main/java/org/nuiton/util/VersionUtil.java deleted file mode 100644 index e829643..0000000 --- a/src/main/java/org/nuiton/util/VersionUtil.java +++ /dev/null @@ -1,568 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Set; -import java.util.regex.Pattern; - -/** - * Class of usefull methods on {@link Version} objects. - * - * There is some factory methods : {@code valueOf(XXX)} to obtain a new - * version. - * - * Some methods to transform a version (since version are immutable, we can not - * modify Version's property) : - * <pre> - * - inc(Version) : to increment a version - * - dec(Version) : to decrement a version - * - addClassifier(Version, String, Integer) : to add a classifier to a version - * - removeClassifier(Version) : to remove a classifier from a version - * </pre> - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.1.0 - * @deprecated since 3.0 (use now {@link org.nuiton.util.version.Version}). - */ -@Deprecated -public class VersionUtil { - - /** - * Pattern pour detecter une version (avec si classifier et numéro de - * classifier séparé par un -, par exemple : 1.0-beta-1). - * - * Le pattern possède toujours 4 groupes de captures. - * - * - Le groupe 1 est le nombre de la version - * - Le groupe 2 est le classifier (peut-etre null) - * - Le groupe 3 est le numéro de classifier (peut-etre null) - * - Le groupe 4 est le suffix -SNAPSHOT (peut-etre null) - * - * Dans le cas d'une version simple (sans classifier), le groupe 2, 3 et - * 4 sont null. - * - * Dans le cas d'une version non snapshot, le groupe 4 est null. - */ - public static final Pattern VERSION_PATTERN = - Pattern.compile("^(\\d+(?:\\.(?:\\d+))*)(?:-(\\w+?)-(\\d+?)){0,1}(-SNAPSHOT){0,1}$"); - - /** - * Pattern pour detecter une version (avec si classifier et numéro de - * classifier collé, par exemple : 1.0-rc1). - * - * Le pattern possède toujours 4 groupes de captures. - * - * - Le groupe 1 est le nombre de la version - * - Le groupe 2 est le classifier (peut-etre null) - * - Le groupe 3 est le numéro de classifier (peut-etre null) - * - Le groupe 4 est le suffix -SNAPSHOT (peut-etre null) - * - * Dans le cas d'une version simple (sans classifier), le groupe 2, 3 et - * 4 sont null. - * - * Dans le cas d'une version non snapshot, le groupe 4 est null. - */ - public static final Pattern VERSION_PATTERN2 = - Pattern.compile("^(\\d+(?:\\.(?:\\d+))*)(?:-(\\w+?)(\\d+?)){0,1}(-SNAPSHOT){0,1}$"); - - /** - * Shared instance of default version comparator. - * - * @see VersionComparator - */ - public static final VersionComparator DEFAULT_VERSION_COMPARATOR = - new VersionComparator(); - - /** The snapshot suffix. */ - public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; - - /** - * Recuperation d'une instance de version simple (sans classifier). - * - * @param numbers les nombres de la version - * @param snapshot boolean pour indiquer que la version es une snapshot ou pas - * @return l'instance de la version requise - */ - public static Version valueOf(boolean snapshot, int... numbers) { - Version version = valueOf(null, null, snapshot, numbers); - return version; - } - - /** - * Recuperation d'une instance de version simple (sans classifier). - * - * @param numbers les nombres de la version - * @return l'instance de la version requise - */ - public static Version valueOf(int... numbers) { - Version version = valueOf(null, null, false, numbers); - return version; - } - - /** - * Recuperation d'une instance de version. - * - * @param classifier le classifier (peut-etre null) - * @param classifierNumber la version du classifier (doit etre null si le - * classifier est null) - * @param numbers les nombres de la version - * @return l'instance de la version requise - */ - public static Version valueOf(String classifier, - Integer classifierNumber, int... numbers) { - Version v = valueOf(classifier, classifierNumber, false, numbers); - return v; - } - - /** - * Recuperation d'une instance de version. - * - * @param classifier le classifier (peut-etre null) - * @param classifierNumber la version du classifier (doit etre null si le - * classifier est null) - * @param snapshot boolean pour indiquer que la version es une snapshot ou pas - * @param numbers les nombres de la version - * @return l'instance de la version requise - */ - public static Version valueOf(String classifier, - Integer classifierNumber, - boolean snapshot, - int... numbers) { - Version v = new Version(classifier, classifierNumber, snapshot, numbers); - return v; - } - - /** - * Recuperation d'une instance de version a partir de sa version textuelle. - * - * @param version la representation textuelle de la version - * @return l'instance de la version requise - */ - public static Version valueOf(String version) { - Version v = new Version(version); - return v; - } - - /** - * Construction d'une nouvelle version avec un classifier a partir d'une - * version donnee. - * - * @param version la version de base (sans classifier) - * @param classifier le classifier a ajouter - * @param classifierNumber la version du classifier a ajouter - * @return l'instance de la version requise - * @throws NullPointerException si le classifier ou le - * classifierNumber est null. - * @throws IllegalArgumentException si la version donnee contient deja un - * classifier. - */ - public static Version addClassifier(Version version, - String classifier, - Integer classifierNumber) - throws NullPointerException, IllegalArgumentException { - Version result; - if (classifier == null) { - throw new NullPointerException("classifier can not be null"); - } - if (classifierNumber == null) { - throw new NullPointerException("classifierNumber can not be null"); - } - if (version.hasClassifier()) { - throw new IllegalArgumentException( - "version " + version + "contains already a classifier "); - } - result = valueOf(classifier, - classifierNumber, - version.isSnapshot(), - version.getNumbers()); - return result; - } - - /** - * Construction d'une nouvelle version sans classifier a partir d'une - * version donnee (sans classifier). - * - * @param version la version de base (avec classifier) - * @return l'instance de la version requise - * @throws IllegalArgumentException si la version donnee contient deja - * un classifier. - */ - public static Version removeClassifier(Version version) - throws IllegalArgumentException { - Version result; - if (!version.hasClassifier()) { - throw new IllegalArgumentException( - "version " + version + "does no contain a classifier "); - } - result = valueOf(version.isSnapshot(), version.getNumbers()); - return result; - } - - public static Version addSnapshot(Version version) { - if (version.isSnapshot()) { - throw new IllegalArgumentException( - "version " + version + "is already a snapshot"); - } - Version result = valueOf(version.getClassifier(), version.getClassifierNumber(), true, version.getNumbers()); - return result; - } - - public static Version removeSnapshot(Version version) { - if (!version.isSnapshot()) { - throw new IllegalArgumentException( - "version " + version + "is already a snapshot"); - } - Version result = valueOf(version.getClassifier(), version.getClassifierNumber(), false, version.getNumbers()); - return result; - } - - /** - * Incremente le numero de version donnee, seul le dernier constituant est - * incremente: 1.2.3.4 → 1.2.3.5; null → 1; 0 → 1. - * - * Si la version a un classifier, alors c'est la version du classifier qui - * change : 1.1-alpha-12 → 1.1-alpha-13 - * - * @param v la version a incrementer - * @return la nouvelle version - */ - public static Version inc(Version v) { - int nbComponents = v.getNbComponents(); - int[] newNumbers = Arrays.copyOf(v.numbers, nbComponents); - String newClassifier = v.classifier; - Integer newClassifierNumber = v.classifierNumber; - - if (v.hasClassifier()) { - newClassifierNumber++; - } else { - newNumbers[nbComponents - 1] = newNumbers[nbComponents - 1] + 1; - } - - Version result = valueOf(newClassifier, newClassifierNumber, - v.isSnapshot(), - newNumbers); - return result; - } - - /** - * Remove the suffix {@code -SNAPSHOT} stamp from a version (if any). - * - * @param version the string representation of the version - * @return the string representation of the given version - * without the {@code -SNAPSHOT} suffix (if any). - * @throws NullPointerException if version is null - */ - public static String removeSnapshot(String version) - throws NullPointerException { - if (version == null) { - throw new NullPointerException("version parameter can not be null"); - } - int index = version.indexOf(SNAPSHOT_SUFFIX); - if (index > -1) { - version = version.substring(0, index); - } - return version; - } - - /** - * Filter versions. - * - * @param versions versions to filter - * @param min min version to accept - * @param max max version to accept - * @param includeMin flag to include min version - * @param includeMax flag to include max version - * @return versions between min and max - */ - public static List<Version> filterVersions(Set<Version> versions, - Version min, - Version max, - boolean includeMin, - boolean includeMax) { - List<Version> toApply = new ArrayList<Version>(); - for (Version v : versions) { - int t; - if (min != null) { - t = v.compareTo(min); - if (t < 0 || t == 0 && !includeMin) { - // version trop ancienne - continue; - } - } - if (max != null) { - t = v.compareTo(max); - if (t > 0 || t == 0 && !includeMax) { - // version trop recente - continue; - } - } - toApply.add(v); - } - return toApply; - } - - /** - * L'implantation d'un comparateur de versions permettant de controler - * l'ordre du numero de version, classifier et numero de classifer. - * - * Toute implementation de ce contrat devrait suivre cet algorithme : - * - * 1) Si versions égales, on quitte. - * - * 2) On teste l'ordre des nombres {@link #compareNumbers(Version, Version)} - * - * Si différent, alors versions différentes, on quitte - * - * 3) On teste l'ordre des classifiers - * {@link #compareClassifier(Version, Version)} - * - * Si différent, alors versions différentes, on quitte - * - * 4) On teste l'ordre des versions de classifiers - * {@link #compareClassifierNumber(Version, Version)}. - */ - public static class VersionComparator implements Comparator<Version> { - - @Override - public int compare(Version o1, Version o2) { - - if (o1.equals(o2)) { - - // versions are equals - return 0; - } - - // compare on numbers - - int result = compareNumbers(o1, o2); - - if (result != 0) { - - // compare snapshot - return result; - } - - // numbers are equals - - // compare on classifier - - result = compareClassifier(o1, o2); - - if (result != 0) { - return result; - } - - // classifier are equals - - // compare on classifierNumber - - result = compareClassifierNumber(o1, o2); - - if (result != 0) { - return result; - } - - // classifierNumber are equals - - // compare on snapshot - result = compareSnapshot(o1, o2); - - return result; - } - - public int compareNumbers(Version o1, Version o2) { - int nbComponents1 = o1.numbers.length; - int nbComponents2 = o2.numbers.length; - int minlen = Math.min(nbComponents1, nbComponents2); - for (int i = 0; i < minlen; i++) { - int t1 = o1.numbers[i]; - int t2 = o2.numbers[i]; - if (t1 == t2) { - continue; - } - return t1 - t2; - } - - // common version are equals - - // the longer number wins - // example : 1.0.0 > 1.0 > 1 - - return nbComponents1 - nbComponents2; - } - - public int compareClassifier(Version o1, Version o2) { - if (o1.hasClassifier() && o2.hasClassifier()) { - // o1 et o2 ont un classifier - return o1.classifier.compareTo(o2.classifier); - } - - if (!o1.hasClassifier() && !o2.hasClassifier()) { - // o1 et o2 n'ont un classifier - return 0; - } - - if (!o1.hasClassifier()) { - // o1 n'a pas de classifier, o1 est donc plus recent - return 1; - } - - if (!o2.hasClassifier()) { - // o2 n'a pas de classifier, o2 est donc plus recent - return -1; - } - - // o1 et o2 n'ont pas de classifier, il sont donc egaux - return 0; - - } - - public int compareClassifierNumber(Version o1, Version o2) { - - if (!o1.hasClassifier() && !o2.hasClassifier()) { - // o1 et o2 n'ont un classifier - return 0; - } - return o1.classifierNumber - o2.classifierNumber; - } - - public int compareSnapshot(Version o1, Version o2) { - - boolean snapshot1 = o1.isSnapshot(); - boolean snapshot2 = o2.isSnapshot(); - if ((snapshot1 && snapshot2) || (!snapshot1 && !snapshot2)) { - // equals - return 0; - } - if (snapshot1) { - // !snapshot2, so v1 est before v2 - return -1; - } - return 1; - } - } - - /** - * Tests if two versions are equals. - * - * @param version0 the first version - * @param version1 the second version - * @return {@code true} if versions are equals, {@code false} otherwise. - */ - public static boolean equals(String version0, String version1) { - Version v0 = valueOf(version0); - Version v1 = valueOf(version1); - boolean result = v0.equals(v1); - return result; - } - - /** - * Tests if the first version is smaller than the second version. - * - * @param version0 the first version - * @param version1 the second version - * @return {@code true} if {@code version0} is before {@code version1}, - * {@code false} otherwise. - */ - public static boolean smallerThan(String version0, String version1) { - Version v0 = valueOf(version0); - Version v1 = valueOf(version1); - boolean result = v0.before(v1); - return result; - } - - /** - * Tests if the first version is greater than the second version. - * - * @param version0 the first version - * @param version1 the second version - * @return {@code true} if {@code version0} is after {@code version1}, - * {@code false} otherwise. - */ - public static boolean greaterThan(String version0, String version1) { - Version v0 = valueOf(version0); - Version v1 = valueOf(version1); - boolean result = v0.after(v1); - return result; - } - - /** - * Trier un ensemble de versions données en entrees - * - * On affiche le resultat dans la console - * - * @param args les versions - */ - public static void main(String... args) { - - List<Version> list = new ArrayList<Version>(); - List<Version> snapshots = new ArrayList<Version>(); - - for (String a : args) { - if (a.endsWith(SNAPSHOT_SUFFIX)) { - snapshots.add(valueOf( - a.substring(0, a.length() - VersionUtil.SNAPSHOT_SUFFIX.length()))); - continue; - } - Version v = valueOf(a); - list.add(v); - } - Collections.sort(list); - List<String> asString = new ArrayList<String>(); - for (Version v : list) { - asString.add(v.toString()); - } - // repositionnement des snapshots - for (Version snap : snapshots) { - String v = snap.toString(); - if (list.contains(snap)) { - // on ajoute juste avant - int index = asString.indexOf(v); - asString.add(index, v + SNAPSHOT_SUFFIX); - } else { - // ajout dans la liste initiale - list.add(snap); - Collections.sort(list); - int index = list.indexOf(snap); - if (index == 0) { - asString.add(0, v + SNAPSHOT_SUFFIX); - } else { - Version v2 = list.get(index - 1); - index = asString.indexOf(v2.toString()); - asString.add(index + 1, v + SNAPSHOT_SUFFIX); - } - list.remove(snap); - } - } - StringBuilder buffer = new StringBuilder(); - for (String s : asString) { - buffer.append(s).append("\n"); - } - System.out.println(buffer.toString()); - } -} diff --git a/src/main/java/org/nuiton/util/ZipUtil.java b/src/main/java/org/nuiton/util/ZipUtil.java index 0ba98ad..69d6210 100644 --- a/src/main/java/org/nuiton/util/ZipUtil.java +++ b/src/main/java/org/nuiton/util/ZipUtil.java @@ -35,6 +35,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; @@ -258,7 +259,7 @@ public class ZipUtil { if (createMD5) { String md5hash = StringUtil.asHex(((MD5OutputStream) oStream).hash()); File md5File = new File(zipFile.getAbsoluteFile() + ".md5"); - FileUtils.write(md5File, md5hash); + FileUtils.write(md5File, md5hash, Charset.defaultCharset()); } } finally { oStream.close(); diff --git a/src/main/java/org/nuiton/util/beans/Binder.java b/src/main/java/org/nuiton/util/beans/Binder.java index 2f9d559..57e996c 100644 --- a/src/main/java/org/nuiton/util/beans/Binder.java +++ b/src/main/java/org/nuiton/util/beans/Binder.java @@ -28,7 +28,6 @@ import com.google.common.base.Preconditions; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.util.ObjectUtil; import java.beans.PropertyDescriptor; import java.io.Serializable; @@ -200,7 +199,7 @@ public class Binder<I, O> implements Serializable { } if (readMethod.getReturnType().isPrimitive() && !keepPrimitiveDefaultValues - && ObjectUtil.getNullValue(readMethod.getReturnType()).equals(read)) { + && Defaults.defaultValue(readMethod.getReturnType()).equals(read)) { // for primitive type case, force nullity read = null; } @@ -545,7 +544,7 @@ public class Binder<I, O> implements Serializable { // obtain acceptable null value (for primitive types, use // default values). if (read == null) { - read = ObjectUtil.getNullValue(readMethod.getReturnType()); + read = Defaults.defaultValue(readMethod.getReturnType()); } if (log.isDebugEnabled()) { log.debug("property " + sourceProperty + ", type : " + @@ -589,7 +588,7 @@ public class Binder<I, O> implements Serializable { // obtain acceptable null value (for primitive types, use // default values). if (read == null) { - read = ObjectUtil.getNullValue(readMethod.getReturnType()); + read = Defaults.defaultValue(readMethod.getReturnType()); } if (log.isDebugEnabled()) { log.debug("property " + sourceProperty + ", type : " + diff --git a/src/main/java/org/nuiton/util/converter/ColorConverter.java b/src/main/java/org/nuiton/util/converter/ColorConverter.java deleted file mode 100644 index 20aa2ea..0000000 --- a/src/main/java/org/nuiton/util/converter/ColorConverter.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.nuiton.util.converter; -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; - -import java.awt.Color; -import java.util.Scanner; - -/** - * Converter of {@link Color}. - * - * @author Matthieu Allon - * @author Tony Chemit - chemit@codelutin.com - * @since 2.5.3 - * @deprecated since 3.0 use instead {@link org.nuiton.converter.ColorConverter} (<strong>Note:</strong> This converter is no more loaded by the {@link ConverterUtil#initConverters()}) - */ -@Deprecated -public class ColorConverter implements Converter { - - @Override - public Object convert(Class aClass, Object value) { - if (!isEnabled(aClass)) { - throw new ConversionException("unsupported type: " + aClass); - } - - String valueToString = (String) value; - /* - * To get color from a formatted string - * Two formatting cases : - * - 'java.awt.Color[r=255,g=51,b=51]', for example - * - hexa, like '#000000' - */ - Color result; - try { - if (valueToString.length() == 7 && valueToString.charAt(0) == '#') { - result = new Color(Integer.parseInt(valueToString.substring(1), 16)); - } else { - Scanner sc = new Scanner(valueToString); - sc.useDelimiter("\\D+"); - result = new Color(sc.nextInt(), sc.nextInt(), sc.nextInt()); - } - return result; - } catch (Exception e) { - throw new ConversionException( - "colors must be of the form #xxxxxx ('#' followed by " + - "six hexadecimal digits), or the name of a constant " + - "field in java.awt.Color (found: '" + valueToString + "')", - e); - } - } - - protected boolean isEnabled(Class<?> aClass) { - return Color.class.equals(aClass); - } - - public Class<?> getType() { - return Color.class; - } -} diff --git a/src/main/java/org/nuiton/util/converter/ConverterUtil.java b/src/main/java/org/nuiton/util/converter/ConverterUtil.java deleted file mode 100644 index dd7671a..0000000 --- a/src/main/java/org/nuiton/util/converter/ConverterUtil.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConvertUtils; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.lang.reflect.Method; -import java.util.ServiceLoader; - -/** - * Une classe contenant des méthodes utiles sur les converters et les conversions - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 (replace {@code org.nuiton.util.ConverterUtil}). - * @deprecated since 3.0 use instead {@link org.nuiton.converter.ConverterUtil} - */ -@Deprecated -public class ConverterUtil { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ConverterUtil.class); - - /** - * le paquetage où chercher les implentations de Converter, si non présents - * dans le système - */ - protected static final String CONVERTER_PACKAGE = "org.nuiton.util.converter"; - - /** un drapeau pour savoir si on doit charger les converters specifiques */ - protected static Boolean WAS_INIT = Boolean.FALSE; - - /** - * Cherche un converter pour un {@code type} donné. - * - * Recherche dans un premier temps dans les converteurs déjà connus. - * - * Si le type est une énum et qu'aucun converter, n'a été trouvé, on - * enregistre un nouveau convert d'enum. - * - * Sinon on tente d'instancier un converteur dans le paquetage dédié aux - * converteurs {@link #CONVERTER_PACKAGE}. - * - * @param <T> le type a convertir - * @param type le type a convertir - * @return le converter trouvé, ou null si non trouvé - */ - public static <T> Converter getConverter(Class<T> type) { - if (!WAS_INIT) { - initConverters(); - } - Converter converter = ConvertUtils.lookup(type); - if (converter != null) { - return converter; - } - if (type.isEnum()) { - registerEnumConverter(type); - return ConvertUtils.lookup(type); - } - // on essaye de trouver un converter dans le paquetage des converters - try { - registerConverter0(type); - converter = ConvertUtils.lookup(type); - } catch (Exception e) { - throw new RuntimeException(e); - } - return converter; - } - - /** - * Convertir une valeur! - * - * @param <T> le type de donnee recherchee - * @param type le type de donnee recherchee - * @param toConvert l'object a convertir - * @return la nouvelle instance de l'objet converti type ou null - */ - @SuppressWarnings({"unchecked"}) - public static <T> T convert(Class<T> type, Object toConvert) { - if (!WAS_INIT) { - initConverters(); - } - T result = null; - Converter converter = getConverter(type); - if (converter != null) { - return converter.convert(type, toConvert); - } - return result; - } - - public static void registerConverter(Class<?> type) - throws IllegalAccessException, - InstantiationException, - ClassNotFoundException { - if (ConvertUtils.lookup(type) == null) { - registerConverter0(type); - } - } - - protected static void registerConverter0(Class<?> type) - throws IllegalAccessException, - InstantiationException, - ClassNotFoundException { - Class<?> aClass = Class.forName( - CONVERTER_PACKAGE + "." + type.getSimpleName() + "Converter"); - Converter converter = (Converter) aClass.newInstance(); - log.info("for type : " + type + " : " + converter); - ConvertUtils.register(converter, type); - } - - /** - * Enregistre un nouveau converter pour un type d'enum donné, avec une - * valeur par defaut. - * - * @param type le type d'enum à convertir - * @param defaultValue la valeur par defaut. - */ - public static void registerEnumConverter(Class<?> type, - Object defaultValue) { - if (EnumConverter.isEnabled(type, type) && - ConvertUtils.lookup(type) == null) { - Converter converter = new EnumConverter(type, defaultValue); - log.info("for type : " + type + " : " + converter); - ConvertUtils.register(converter, type); - } - } - - /** - * Enregistre un nouveau converter pour un type d'enum donné, sans utiliser - * de valeur par defaut. - * - * @param type le type d'enum à convertir - */ - public static void registerEnumConverter(Class<?> type) { - registerEnumConverter(type, null); - } - - public static byte[] convert(char[] chars) { - byte[] bytes = new byte[chars.length]; - for (int i = 0; i < chars.length; i++) { - bytes[i] = (byte) (chars[i] & 0xff); - } - return bytes; - } - - public static synchronized void deregister() { - ConvertUtils.deregister(); - WAS_INIT = false; - } - - public static synchronized void initConverters() { - if (WAS_INIT != null && WAS_INIT) { - return; - } - ServiceLoader<Converter> converters = - ServiceLoader.load(Converter.class); - for (Converter converter : converters) { - if (log.isDebugEnabled()) { - log.debug("discovered converter " + converter); - } - try { - Method m = converter.getClass().getDeclaredMethod("getType"); - m.setAccessible(true); - try { - Class<?> returnType = (Class<?>) m.invoke(converter); - log.info("register converter " + converter); - ConvertUtils.register(converter, returnType); - } catch (Exception ex) { - log.warn("could not obtain type of converter " + - converter + " for reason : " + ex.getMessage(), - ex); - } - } catch (NoSuchMethodException ex) { - log.warn("could not find method getType on converter " + - converter + ", will not be registred..."); - } catch (SecurityException ex) { - log.warn("could not find method getType on converter " + - converter + ", will not be registred..."); - } - - } - WAS_INIT = true; - } -} diff --git a/src/main/java/org/nuiton/util/converter/EnumConverter.java b/src/main/java/org/nuiton/util/converter/EnumConverter.java deleted file mode 100644 index db7250f..0000000 --- a/src/main/java/org/nuiton/util/converter/EnumConverter.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -import java.util.EnumSet; - -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n.t; - -/** - * classe pour convertir une chaine en un objet Enum type-safe en - * connaissant le type d'enumération utilisée {@link #enumType}. - * - * Il est possible aussi de convertir une Enum à partir de sa valeur ordinal. - * - * Pour enregister un nouveau convertissemnt pour un type d'Enum utiliser les - * méthodes * {@link ConverterUtil#registerEnumConverter(Class)}, - * et {@link ConverterUtil#registerEnumConverter(Class, Object)} . - * - * @author Tony Chemit - chemit@codelutin.com - * @see Enum - * @see Enum#ordinal() - * @deprecated since 3.0 use instead {@link org.nuiton.converter.EnumConverter} - */ -@Deprecated -public class EnumConverter implements Converter { - - /** Logger. */ - private static final Log log = getLog(EnumConverter.class); - - /** valeur par default à utiliser, si pas non trouvée et {@link #useDefault} actif. */ - protected Object defaultValue; - - /** flag pour utiliser la valeur par defaut {@link #defaultValue} si non trouvé. */ - protected boolean useDefault; - - /** le type de l'énumération à convertir */ - protected Class<?> enumType; - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - if (useDefault) { - return defaultValue; - } - throw new ConversionException( - t("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass, enumType)) { - Object result; - if (isEnabled(value.getClass(), enumType)) { - result = value; - return result; - } - if (value instanceof String) { - try { - result = valueOf(aClass, value); - } catch (IllegalArgumentException e) { - // try an ordinal conversion - result = convertFromOrdinal(aClass, value); - } - return result; - } - if (value instanceof Integer) { - // try a ordinal conversion - result = convertFromOrdinal(aClass, value); - return result; - } - } - throw new ConversionException( - t("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - public EnumConverter(Class<?> enumType, Object defaultValue) { - this.enumType = enumType; - this.defaultValue = defaultValue; - useDefault = defaultValue != null; - if (log.isDebugEnabled()) { - log.debug(toString() + '<' + enumType + '>'); - } - } - - public EnumConverter(Class<?> enumType) { - this(enumType, null); - } - - protected static boolean isEnabled(Class<?> aClass, Class<?> enumType) { - return aClass != null && aClass.isEnum() && aClass == enumType; - } - - protected Object convertFromOrdinal(Class<?> aClass, Object value) { - Object result = null; - try { - int ordinal = Integer.valueOf(value + ""); - EnumSet<?> vals = allOf(aClass); - if (ordinal > -1 && ordinal < vals.size()) { - for (Enum<?> val : vals) { - if (val.ordinal() == ordinal) { - result = val; - break; - } - } - } - } catch (NumberFormatException e1) { - // quiet conversion - result = null; - } - return result; - } - - protected Object valueOf(Class<?> aClass, Object value) { - Object result; - result = Enum.valueOf((Class<Enum>) aClass, (String) value); - return result; - } - - protected EnumSet<?> allOf(Class<?> aClass) { - EnumSet<?> vals; - vals = EnumSet.allOf((Class<Enum>) aClass); - return vals; - } - - public Class<?> getType() { - return enumType; - } - - -} diff --git a/src/main/java/org/nuiton/util/converter/FormatConverter.java b/src/main/java/org/nuiton/util/converter/FormatConverter.java deleted file mode 100644 index 5476531..0000000 --- a/src/main/java/org/nuiton/util/converter/FormatConverter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.nuiton.util.converter.FormatMap.Format; - -/** - * Created: 14 septembre 2005 00:55:19 CEST - * <p> - * Un converter est un objet qui permet de passé d'une representation d'un - * objet vers une autre representation. Le mininum que converter doit savoir - * faire, est de converter une representation Java vers le format qu'il - * gère et inversement. Pour des raisons d'optimisation, il est possible - * qu'un converter sache passé d'un autre type que java vers sa representation - * pour eviter une conversion supplémentaire qui pourrait-etre couteuse. - * - * @param <A> le type de l'objet a convertir - * @author Benjamin Poussin - poussin@codelutin.com - * @deprecated since 3.0, will not pe replaced by anything (see https://forge.nuiton.org/issues/3326); will be removed later - */ -@Deprecated -public interface FormatConverter<A> { // FormatConverter - - Format FORMAT_JAVA = new Format("Format Java"); - - /** - * Convertie une valeur vers la representation FORMAT géré par cette classe - * - * @param factory la factory utilisable pour rechercher d'autre converter - * si la representation Java n'est pas presente dans values et que l'on - * en a besoin - * @param format le format souhaité en sortie - * @param values une map contenant les différentes representation de la - * meme valeur. Les cles de la map sont les valeurs retournés par la - * methode getFormat(). - * @param args des arguments qui peuvent-être utile pour la conversion. - * par exemple si dans une application on a construit son propre - * converter et que pour la conversion, on a besoin d'un Context applicatif - * il peut-etre passé dans les args. Si le converter a besoin d'autre - * converter les memes args lui seront passé. - * @return l'objet dans la representation demandés par type - * @throws IllegalArgumentException si auncun moyen n'est trouve pour - * convertir une des valeurs de values dans le format géré par cette classe. - * Ou s'il manque dans les args des objets utils pour la conversion. - */ - A convert(FormatConverterFactory factory, - Format format, FormatMap values, Object... args); - - /** - * Convertie une valeur vers le Java - * - * @param factory la factory utilisable pour rechercher d'autre converter - * si la representation Java n'est pas presente dans values et que l'on - * en a besoin - * @param format le format à utiliser comme valeur d'entré - * @param values une map contenant les différentes representation de la - * meme valeur. La valeur interessante dans la map pour cette methode - * est celle retournée par values.get(getFormat()) si cet appel, ne - * retourne pas quelque chose de valid, la methode doit lever une exception - * @param args des arguments qui peuvent-être utile pour la conversion. - * par exemple si dans une application on a construit son propre - * converter et que pour la conversion, on a besoin d'un Context applicatif - * il peut-etre passé dans les args. Si le converter a besoin d'autre - * converter les memes args lui seront passé. - * @return la valeur java - * @throws IllegalArgumentException si le format géré par cette classe n'est - * pas trouvé dans les values. Ou s'il manque dans les args des objets utils - * pour la conversion. - */ - Object unconvert(FormatConverterFactory factory, - Format format, FormatMap values, Object... args); - -} // FormatConverter - diff --git a/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java b/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java deleted file mode 100644 index eae3e07..0000000 --- a/src/main/java/org/nuiton/util/converter/FormatConverterFactory.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.collections4.map.MultiKeyMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.converter.FormatMap.Format; - -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; - -/** - * Factory permet d'enregistrer des objets de changement de format, et de - * les recupérer pour les utiliser. - * Les objets converter doivent au moins savoir convertir les objets depuis - * une representation Java. Pour des raisons d'optimisation, il est possible - * qu'il sache aussi convertir a partir d'autre representation, qui si elle - * existe sont moins couteuse a convertir. - * Il faut aussi que les converter sache convertir de leur representation vers - * un objet Java. - * par exemple si on enregistre les convertiseurs suivant: - * <pre> - * addConverter(new MatrixToXMLFormatConverter()); - * addConverter(new MatrixToSQLFormatConverter()); - * FormatConverterFactory.convert(Matrix.class, MatrixToXMLFormatConverter.TYPE, - * values, AppContext); - * </pre> - * Dans ce cas pour des raisons d'optimisation - * - * Created: 14 septembre 2005 00:19:51 CEST - * - * @author Benjamin Poussin - poussin@codelutin.com - * @since 1.3 replace the class {@code org.nuiton.util.FormatConverterFactory}. - * @deprecated since 3.0, will not pe replaced by anything (see https://forge.nuiton.org/issues/3326); will be removed later - */ -@Deprecated -public class FormatConverterFactory { // FormatConverterFactory - - /** Logger. */ - private static final Log log = LogFactory.getLog(FormatConverterFactory.class); - - static protected FormatConverterFactory instance; - - /** <Class, from, to → FormatConverter> */ - protected MultiKeyMap converters = new MultiKeyMap(); - - synchronized public static FormatConverterFactory getInstance() { - if (instance == null) { - instance = new FormatConverterFactory(); - } - return instance; - } - - /** - * Permet d'enregitrer un converter pour permettre la convertion d'une - * certain type Java d'une representation vers une autre. - * par exemple le type String d'un objet Java vers une chaine XML - * - * @param clazz la class de la representation Java de l'objet - * @param format le format géré par le FormatConverter - * @param c le converter a enregistrer - */ - public void addConverter(Class<?> clazz, Format format, FormatConverter<?> c) { - converters.put(clazz, format, c); - } - - /** - * permet de recupere le converter pour la classe souhaitée. - * - * @param clazz la classe de l'objet dont on souhaite le converter - * @param format qui doit être géré par le converter - * @param defaultConverter si aucun converter trouvé, ce converter est - * retourné - * @return le converter souhaité ou defaultConverter - */ - public FormatConverter<?> getConverter(Class<?> clazz, Format format, - FormatConverter<?> defaultConverter) { - FormatConverter<?> result = (FormatConverter<?>) converters.get(clazz, format); - if (result == null) { - result = defaultConverter; - } - return result; - } - - /** - * @param clazz FIXME - * @param format FIXME - * @return retourne null si aucun converter trouvé - */ - public FormatConverter<?> getConverter(Class<?> clazz, Format format) { - return getConverter(clazz, format, null); - } - - /** - * Permet de retrouver le meilleur converter disponible pour l'argument - * clazz - * - * @param clazz la classe de l'objet dont on souhaite le converter - * @param format qui doit être géré par le converter - * @param defaultConverter si aucun converter trouvé, ce converter est - * retourné - * @return le converter souhaité ou defaultConverter - */ - public FormatConverter<?> findConverter(Class<?> clazz, Format format, - FormatConverter<?> defaultConverter) { - FormatConverter<?> result = null; - - LinkedList<Class<?>> interfaces = new LinkedList<Class<?>>(); - // On recherche la le transformer le plus spécifique sur les Class - Class<?> parent = clazz; - while (result == null && parent != null) { - Collections.addAll(interfaces, parent.getInterfaces()); - result = getConverter(parent, format); - parent = parent.getSuperclass(); - } - - // Si on a pas encore trouve de transformer on recherche - // un encodeur/decodeur pour les interfaces - for (Iterator<Class<?>> i = interfaces.iterator(); result == null && i.hasNext(); ) { - result = getConverter(i.next(), format); - } - - if (result == null) { - log.warn("Aucun converter trouvé pour le type: " + clazz); - result = defaultConverter; - } - log.debug("converter " + result + " utilisé pour le type: " + clazz); - - return result; - } - - /** - * @param clazz FIXME - * @param format FIXME - * @return retourne null si aucun converter trouvé - */ - public FormatConverter<?> findConverter(Class<?> clazz, Format format) { - return findConverter(clazz, format, null); - } - - public Object convert(Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format); - if (c == null) { - throw new IllegalArgumentException("Aucun converter utilisable pour les arguments donnés class: " + values.getType().getName() + " format: " + format); - } - return c.convert(this, format, values, args); - } - - public Object unconvert(Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format); - if (c == null) { - throw new IllegalArgumentException("Aucun converter utilisable pour les arguments donnés"); - } - return c.unconvert(this, format, values, args); - } - - public Object convert(FormatConverter<?> defaultConverter, - Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format, defaultConverter); - return c.convert(this, format, values, args); - } - - public Object unconvert(FormatConverter<?> defaultConverter, - Format format, FormatMap values, Object... args) { - FormatConverter<?> c = findConverter(values.getType(), format, defaultConverter); - return c.unconvert(this, format, values, args); - } - -} // FormatConverterFactory - diff --git a/src/main/java/org/nuiton/util/converter/FormatMap.java b/src/main/java/org/nuiton/util/converter/FormatMap.java deleted file mode 100644 index c16d1b8..0000000 --- a/src/main/java/org/nuiton/util/converter/FormatMap.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.util.converter; - -import java.util.HashMap; -import java.util.Map; - -/** - * Classe servant de conteneur pour les différentes representation d'un objet - * Les representations doivents être des instances de {@link Format}. Le mieux - * est lors de l'ecriture des convertisseurs pour un nouveau format est de - * créer une instance final static de {@link Format} Format pour representer - * ce format - * - * <h2>Utilisation</h2> - * <pre> - * FormatMap values = new FormatMap(MonObject.class); - * values.put(FormatConverter.FORMAT_JAVA, monInstance); - * Element xml = (Element)values.convert(XMLConverter.FORMAT_XML); - * Object sql = values.convert(SQLConverter.FORMAT_SQL); - * </pre> - * <pre> - * FormatMap values = new FormatMap(MonObject.class); - * values.put(FormatConverter.FORMAT_XML, monInstanceEnXML); - * Object sql = values.convert(SQLConverter.FORMAT_SQL); - * </pre> - * Dans ce second cas, la demande de la version SQL, transforme automatiquement - * la representation XML qui est la seul presente en Java, puis a partir de - * cette representation Java, on recupere la representation SQL. Bien sur - * Si le convertisseur SQL, peut directement convertir le XML en SQL, alors - * la conversion Java ne sera pas faite. - * - * Il est souvent plus simple de faire une petite classe avec les methodes - * getSQL() et getXML(), qui retourne les valeurs directement dans le bon type - * et qui n'ont pas besoin d'argument. - * - * - * Created: 16 septembre 2005 10:41:58 CEST - * - * @author Benjamin Poussin - poussin@codelutin.com - * @since 1.3 (replace {@code org.nuiton.util.FormatMap} class). - * @deprecated since 3.0, will not pe replaced by anything (see https://forge.nuiton.org/issues/3326); will be removed later - */ -@Deprecated -public class FormatMap extends HashMap<FormatMap.Format, Object> { // FormatMap - - private static final long serialVersionUID = 1L; - - public static class Format { - - protected String name; - - public Format(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - } - - protected Class<?> clazz; - - public FormatMap(Class<?> clazz) { - this.clazz = clazz; - } - - public Class<?> getType() { - return clazz; - } - - /** - * Met a jour la valeur de l'objet. Toutes les autres valeurs calculées - * sont oubliées et seront recalculé en fonction de cette nouvelle valeur - * - * @param format le format a utiliser - * @param value FIXME - */ - public void setValue(Format format, Object value) { - clear(); - put(format, value); - } - - /** - * Utilise le FormatConverterFactory par defaut pour la conversion - * - * @param format le format a utiliser - * @param args les arguments - * @return l'objet converti - */ - public Object convert(Format format, Object... args) { - return convert(FormatConverterFactory.getInstance(), format, args); - } - - /** - * Recupere la valeur dans le format demandé - * - * @param factory la FormatConverterFactory a utiliser - * @param format le format souhaité - * @param args des arguments facultatifs en fonction du context d'utilisation - * @return l'objet converti - */ - public Object convert(FormatConverterFactory factory, Format format, - Object... args) { - Object result; - Map<Format, Object> values = this; - //if (!values.containsKey(format) || - // !format.equals(FormatConverter.FORMAT_JAVA)) { - // throw new IllegalArgumentException("Aucun valeur disponible"); - //} - - if (values.containsKey(format)) { - result = values.get(format); - } else if (format.equals(FormatConverter.FORMAT_JAVA)) { - // on recherche une representation, que l'on convertie en Java - if (values.isEmpty()) { - throw new IllegalArgumentException("Aucun valeur disponible"); - } - Format otherFormat = values.keySet().iterator().next(); - result = unconvert(factory, otherFormat, args); - values.put(format, result); - } else { - result = factory.convert(format, this, args); - // on stocke la valeur trouver pour les prochaines fois - values.put(format, result); - } - - return result; - } - - /** - * Utilise le FormatConverterFactory par defaut pour la conversion - * - * @param format le format utilise - * @param args FIXME - * @return l'objet java - */ - public Object unconvert(Format format, Object... args) { - return unconvert(FormatConverterFactory.getInstance(), format, args); - } - - /** - * Donne la representation Java de l'objet en essayant de partir de la - * representation passé en parametre. - * - * @param factory la factory a utiliser - * @param format le format de départ souhaité - * @param args des arguments facultatifs en fonction du context d'utilisation - * @return l'objet java - */ - public Object unconvert(FormatConverterFactory factory, Format format, - Object... args) { - Object result = null; - Map<Format, Object> values = this; - if (!values.containsKey(format) && - !values.containsKey(FormatConverter.FORMAT_JAVA)) { - throw new IllegalArgumentException("Aucun valeur disponible"); - } - - // si on a deja la representation Java on la retourne tout de suite - if (values.containsKey(FormatConverter.FORMAT_JAVA)) { - result = values.get(FormatConverter.FORMAT_JAVA); - } else if (values.containsKey(format)) { - result = factory.unconvert(format, this, args); - values.put(FormatConverter.FORMAT_JAVA, result); - } - - return result; - } -} // FormatMap - diff --git a/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java b/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java deleted file mode 100644 index daa35c2..0000000 --- a/src/main/java/org/nuiton/util/converter/KeyStrokeConverter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -import javax.swing.KeyStroke; - -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n.t; - -/** - * Used to convert a {@link String} to {@link KeyStroke}. - * - * @author Sylvain Letellier - * @since 2.5.1 - * @deprecated since 3.0 use instead {@link org.nuiton.converter.KeyStrokeConverter} (<strong>Note:</strong> This converter is no more loaded by the {@link ConverterUtil#initConverters()}) - */ -@Deprecated -public class KeyStrokeConverter implements Converter { - - - /** Logger. */ - private static final Log log = getLog(KeyStrokeConverter.class); - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException( - t("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = KeyStroke.getKeyStroke((String) value); - return result; - } - } - throw new ConversionException( - t("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - protected boolean isEnabled(Class<?> aClass) { - return KeyStroke.class.equals(aClass); - } - - public Class<?> getType() { - return KeyStroke.class; - } -} diff --git a/src/main/java/org/nuiton/util/converter/URIConverter.java b/src/main/java/org/nuiton/util/converter/URIConverter.java deleted file mode 100644 index 4d80cc9..0000000 --- a/src/main/java/org/nuiton/util/converter/URIConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -import java.net.URI; -import java.net.URISyntaxException; - -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n.t; - -/** - * classe pour convertir une chaine en un objet URI. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 (replace {@code org.nuiton.util.URIConverter}). - * @deprecated since 3.0 use instead {@link org.nuiton.converter.URIConverter} (<strong>Note:</strong> This converter is no more loaded by the {@link ConverterUtil#initConverters()}) - */ -@Deprecated -public class URIConverter implements Converter { - - /** Logger. */ - private static final Log log = getLog(URIConverter.class); - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException( - t("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = valueOf((String) value); - return result; - } - } - throw new ConversionException( - t("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - protected URI valueOf(String value) { - try { - URI result; - result = new URI(value); - return result; - } catch (URISyntaxException e) { - throw new ConversionException( - t("nuitonutil.error.url.convertor", value, this, e.getMessage())); - } - } - - public URIConverter() { - if (log.isDebugEnabled()) { - log.debug("init uri converter " + this); - } - } - - protected boolean isEnabled(Class<?> aClass) { - return URI.class.equals(aClass); - } - - public Class<?> getType() { - return URI.class; - } -} diff --git a/src/main/java/org/nuiton/util/converter/URLConverter.java b/src/main/java/org/nuiton/util/converter/URLConverter.java deleted file mode 100644 index 84f067f..0000000 --- a/src/main/java/org/nuiton/util/converter/URLConverter.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; - -import java.net.MalformedURLException; -import java.net.URL; - -import static org.apache.commons.logging.LogFactory.getLog; -import static org.nuiton.i18n.I18n.t; - -/** - * classe pour convertir une chaine en un objet URL. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 (replace {@code org.nuiton.util.URLConverter}). - * @deprecated since 3.0 use instead {@link org.nuiton.converter.URLConverter} (<strong>Note:</strong> This converter is no more loaded by the {@link ConverterUtil#initConverters()}) - */ -@Deprecated -public class URLConverter implements Converter { - - /** Logger. */ - private static final Log log = getLog(URLConverter.class); - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException( - t("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = valueOf((String) value); - return result; - } - } - throw new ConversionException( - t("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - protected URL valueOf(String value) { - try { - URL result; - result = new URL(value); - return result; - } catch (MalformedURLException e) { - throw new ConversionException( - t("nuitonutil.error.url.convertor", value, this, e.getMessage())); - } - } - - public URLConverter() { - if (log.isDebugEnabled()) { - log.debug("init url converter " + this); - } - } - - protected boolean isEnabled(Class<?> aClass) { - return URL.class.equals(aClass); - } - - public Class<?> getType() { - return URL.class; - } - - -} diff --git a/src/main/java/org/nuiton/util/converter/VersionConverter.java b/src/main/java/org/nuiton/util/converter/VersionConverter.java deleted file mode 100644 index 6d12f5a..0000000 --- a/src/main/java/org/nuiton/util/converter/VersionConverter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.converter.NuitonConverter; -import org.nuiton.util.Version; -import org.nuiton.util.VersionUtil; - -import static org.nuiton.i18n.I18n.t; - -/** - * classe pour convertir une chaine en un objet Version. - * - * @author Tony Chemit - chemit@codelutin.com - * @see Version - * @since 1.3 (replace {@code org.nuiton.util.VersionConverter}). - * @deprecated since 3.0, prefer use the {@link org.nuiton.util.version.VersionConverter}. - */ -@Deprecated -public class VersionConverter implements NuitonConverter<Version> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(VersionConverter.class); - - public VersionConverter() { - if (log.isDebugEnabled()) { - log.debug("init version converter " + this); - } - } - - @Override - public <T> T convert(Class<T> aClass, Object value) { - if (value == null) { - throw new ConversionException( - t("nuitonutil.error.convertor.noValue", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return aClass.cast(result); - } - if (value instanceof String) { - try { - result = VersionUtil.valueOf((String) value); - return aClass.cast(result); - } catch (IllegalArgumentException e) { - throw new ConversionException( - t("nuitonutil.error.version.convertor", value, this, e.getMessage()), e); - } - } - } - throw new ConversionException( - t("nuitonutil.error.no.convertor", aClass.getName(), value)); - } - - @Override - public Class<Version> getType() { - return Version.class; - } - - protected boolean isEnabled(Class<?> aClass) { - return Version.class.equals(aClass); - } -} diff --git a/src/main/java/org/nuiton/util/converter/package-info.java b/src/main/java/org/nuiton/util/converter/package-info.java deleted file mode 100644 index 8a430c9..0000000 --- a/src/main/java/org/nuiton/util/converter/package-info.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -/** - * - * This package contains the converter api + the format api. - * - * <h1>Converter api</h1> - * This converter api is based on the - * http://commons.apache.org/beanutils {@code commons-beanutils}. - * - * Use the {@link org.nuiton.util.converter.ConverterUtil} to register or obtain a - * converter. - * - * <h1>Format api</h1> - * see {@link org.nuiton.util.converter.FormatConverter} and others - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 - * @deprecated since 3.0 (see https://forge.nuiton.org/issues/3320), will be removed after version 3.0 - */ -package org.nuiton.util.converter; diff --git a/src/main/java/org/nuiton/util/version/SemVer.java b/src/main/java/org/nuiton/util/version/SemVer.java deleted file mode 100644 index ad1928e..0000000 --- a/src/main/java/org/nuiton/util/version/SemVer.java +++ /dev/null @@ -1,644 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.Validate; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Implantation de http://semver.org/. - * - * Cette objet est immutable, Il faut utiliser {@link #getCreator()} - * pour modifier un de ses elements - * - * Quelques changement par rapport au site: - * <ul> - * <li> le numero de version peut avoir entre 1 et N element, et non pas 3 obligatoirement - * <li> on peut avoir un -SNAPSHOT ajoute en toute fin de la version - * </ul> - * Un SemVer est en plusieurs elements dont chaque element peut avoir plusieurs - * composant. Les composants sont utilise le meme separateur '.'. - * <ul> - * <li> version: 1 à N composant numerique, les 3 premiers sont nomme - * <ul> - * <li> major - * <li> minor - * <li> patch - * </ul> - * <li> prerelease: 0 à N composant alphanumerique, le prefix est '-' - * <li> build: 0 à N composant alphanumerique, le prefix est '+' - * <li> SNAPSHOT: 0 ou 1 composant dont le nom est fixe le prefix est '-' - * </ul> - * Le mieux pour construire ou modifier un SemVer est d'utilise une methode creator: - * <ul> - * <li> SemVer.creator(1,2,3).done() → "1.2.3" - * <li> SemVer.creator("1.2.3","rc2").done() → "1.2.3-rc2" - * <li> SemVer.creator().setVersion(2.3.4).setBuild("r223").done() → "2.3.4+r223" - * <li> SemVer.creator().setVersion(2.3.4).setSnapshot(true).done() → "2.3.4-SNAPSHOT" - * <li> SemVer.creator(new SemVer("1.2.3")).incMajor().done() → "2.2.2" - * <li> new SemVer("1.2.3").getCreator().incMinor().setPrerelease(beta).done() → "1.3.3-beta" - * </ul> - * - * @author Benjamin Poussin - poussin@codelutin.com - * @since 2.6.7 - * @deprecated since 3.0, use now <a href="https://gitlab.nuiton.org/nuiton/nuiton-version/blob/develop/src/main/java/org/nuiton/version/SemVer.java">Nuiton version</a> - */ -@Deprecated -public class SemVer implements Comparable<SemVer> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(SemVer.class); - - /** Separateur utiliser entre chaque element d'une partie */ - final static public String SERIES_SEPARATOR = "."; // le separateur - /** Seperateur entre la version et l'element prerelease */ - final static public String PRERELEASE_SEPARATOR = "-"; // le separateur de Prerelease - /** Separateur utiliser devant l'element build */ - final static public String BUILD_SEPARATOR = "+"; // le separateur de build - - /** pattern pour une partie de l'element version */ - final static public String PATTERN_VERSION = "[0-9]+"; // le version ne sont que des nombres - /** pattern pour une partie de l'element prerelease */ - final static public String PATTERN_PRERELEASE = "[0-9A-Za-z-]+"; // les Prerelease sont des chiffre, lettre ou '-' - /** pattern pour une partir de l'element build */ - final static public String PATTERN_BUILD = "[0-9A-Za-z-]+";// les Build sont des chiffre, lettre ou '-' - - /** Separateur de SNAPSHOT */ - final static public String SNAPSHOT_SEPARATOR = "-"; - /** la chaine de caractere representant le SNAPSHOT */ - final static public String SNAPSHOT = "SNAPSHOT"; - - // "(1.20.300)(-alpha-1.20)?(+r123.20130126)?" - // version prerelease build - /** pattern qui permet de separer les 3 constituante d'une version, ne - * supporte pas le SNAPSHOT, il faut donc que le SNAPSHOT ait ete retirer - * avant d'appliquer le pattern - */ - final static Pattern PATTERN_ALL = Pattern.compile( - "("+PATTERN_VERSION+"(?:"+Pattern.quote(SERIES_SEPARATOR)+PATTERN_VERSION+")*)" + - "("+Pattern.quote(PRERELEASE_SEPARATOR)+ PATTERN_PRERELEASE+"(?:"+Pattern.quote(SERIES_SEPARATOR)+PATTERN_PRERELEASE+")*)?" + - "("+Pattern.quote(BUILD_SEPARATOR)+ PATTERN_BUILD+"(?:"+Pattern.quote(SERIES_SEPARATOR)+PATTERN_BUILD+")*)?"); - - protected String version; - protected String prerelease; - protected String build; - protected String snapshot; - - /** - * Create new Version object, strip is done on argument to remove extra space - * @param versionString FIXME - * @exception IllegalArgumentException if argument isn't valid version string - */ - public SemVer(String versionString) { - String v = StringUtils.strip(versionString); // on conserve versionString intact pour le message d'erreur - if (StringUtils.endsWithIgnoreCase(v, SNAPSHOT_SEPARATOR + SNAPSHOT)) { - snapshot = SNAPSHOT; - v = StringUtils.substringBeforeLast(v, SNAPSHOT_SEPARATOR); - } - Matcher matcher = PATTERN_ALL.matcher(v); - boolean match = matcher.matches(); - if (match) { - version = matcher.group(1); - prerelease = StringUtils.removeStart(matcher.group(2), PRERELEASE_SEPARATOR); - build = StringUtils.removeStart(matcher.group(3), BUILD_SEPARATOR); - } else { - throw new IllegalArgumentException(String.format("Bad version string: '%s'", versionString)); - } - } - - /** - * @param o the other version to test - * @return {@code true} if current version is before the given one - */ - public boolean before(SemVer o) { - int result = compareTo(o); - return result < 0; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is after the given one - */ - public boolean after(SemVer o) { - int result = compareTo(o); - return result > 0; - } - - public int compareTo(SemVer other) { - int result = compare(this.getVersion(), other.getVersion(), false); - if (result == 0) { - result = compare(this.getPrerelease(), other.getPrerelease(), true); - if (result == 0) { - result = compare(this.getBuild(), other.getBuild(), false); - if (result == 0) { - result = compare(this.getSnapshot(), other.getSnapshot(), true); - } - } - } - return result; - } - - /** - * Compare deux elements de meme semantique (version, prerelease, build, snapshot) - * sinon le comportement est non predictible - * @param a FIXME - * @param b FIXME - * @param nullIsHigh indique si un des elements est null, s'il est plus - * grand ou plus petit que l'autre - * @return negatif si a inferieur b, 0 si a == b, positif si a superieur a b - */ - protected int compare(String a, String b, boolean nullIsHigh) { - int result; - if (nullIsHigh) { - result = nullIsHigh(a, b); - } else { - result = nullIsLow(a, b); - } - - if (result == 0 && a != null && b != null) { - // on decoupe suivant le '.' - String[] aSeries = StringUtils.split(a, SERIES_SEPARATOR); - String[] bSeries = StringUtils.split(b, SERIES_SEPARATOR); - - int length = Math.max(aSeries.length, bSeries.length); - for (int i=0; result==0 & i<length; i++) { - // s'il y en a un qui est plus court, on prend par defaut "" - String va = i < aSeries.length ? aSeries[i] : ""; - String vb = i < bSeries.length ? bSeries[i] : ""; - - // s'il n'y a que des nombres pour une valeur on ajoute des espaces - // devant pour qu'il est la meme longueur que l'autre et ainsi - // pouvoir les comparer lexicographiquement - int pad = Math.max(va.length(), vb.length()); - if (StringUtils.isNumeric(va)) { - va = StringUtils.leftPad(va, pad); - } - if (StringUtils.isNumeric(vb)) { - vb = StringUtils.leftPad(vb, pad); - } - - // on compare les deux valeurs - result = va.compareTo(vb); - } - } - return result; - } - - /** - * Ne compare par le chaine, seulement la nullite, si un des arguments - * est null, alors il est plus grand que l'autre. - * - * 1.0 est plus grand que 1.0-Beta - * - * @param a FIXME - * @param b FIXME - * @return FIXME - */ - protected int nullIsHigh(String a, String b) { - int result = 0; - if (a == null ^ b == null) { - if (a == null) { - result = 1; - } else { - result = -1; - } - } - return result; - } - - /** - * Ne compare par le chaine, seulement la nullite, si un des arguments - * est null, alors il est plus petit que l'autre. - * - * 1.0+r123 est plus grand que 1.0 - * - * @param a FIXME - * @param b FIXME - * @return FIXME - */ - protected int nullIsLow(String a, String b) { - int result = 0; - if (a == null ^ b == null) { - if (a == null) { - result = -1; - } else { - result = 1; - } - } - return result; - } - - /** - * Donne le nombre de composante de l'element - * <ul> - * <li>1.2.3 retourne 3</li> - * <li>99.100 retourne 2</li> - * </ul> - * - * @param element FIXME - * @return FIXME - */ - protected int getComposantCount(String element) { - int result = 0; - if (StringUtils.isNotBlank(element)) { - result = 1 + StringUtils.countMatches(element, SERIES_SEPARATOR); - } - return result; - } - - /** - * Retourne un des composants de l'element version - * @param element FIXME - * @param i FIXME - * @return FIXME - */ - protected String getComposant(String element, int i) { - String[] v = StringUtils.split(element, SERIES_SEPARATOR); - Validate.validIndex(v, i, - "Ask '%s', element '%s' don't have enought composant", i, element); - - String s = v[i]; - return s; - } - - - - public String getVersion() { - return version; - } - - /** - * Donne le nombre de composante de la version - * <ul> - * <li>1.2.3 retourne 3</li> - * <li>99.100 retourne 2</li> - * </ul> - * - * @return FIXME - */ - public int getVersionCount() { - int result = getComposantCount(getVersion()); - return result; - } - - /** - * Retourne un des composants de l'element version - * @param i FIXME - * @return FIXME - */ - public String getVersion(int i) { - String s = getComposant(getVersion(), i); - return s; - } - - public String getMajor() { - String result = getVersion(0); - return result; - } - - public String getMinor() { - String result = getVersion(1); - return result; - } - - public String getPatch() { - String result = getVersion(2); - return result; - } - - public String getPrerelease() { - return prerelease; - } - - /** - * Donne le nombre de composante de la Prerelease - * <ul> - * <li>1.2.3 retourne 3</li> - * <li>99.100 retourne 2</li> - * </ul> - * - * @return FIXME - */ - public int getPrereleaseCount() { - int result = getComposantCount(getPrerelease()); - return result; - } - - /** - * Retourne un des composants de l'element version - * @param i FIXME - * @return FIXME - */ - public String getPrerelease(int i) { - String s = getComposant(getPrerelease(), i); - return s; - } - - public String getBuild() { - return build; - } - - /** - * Donne le nombre de composante de la Prerelease - * <ul> - * <li>1.2.3 retourne 3</li> - * <li>99.100 retourne 2</li> - * </ul> - * - * @return FIXME - */ - public int getBuildCount() { - int result = getComposantCount(getBuild()); - return result; - } - - /** - * Retourne un des composants de l'element version - * @param i FIXME - * @return FIXME - */ - public String getBuild(int i) { - String s = getComposant(getBuild(), i); - return s; - } - - public String getSnapshot() { - return snapshot; - } - - public boolean isSnapshot() { - return StringUtils.isNotBlank(snapshot); - } - - static protected String ifNotNull(String prefix, String s) { - String result = ""; - if (StringUtils.isNotBlank(s)) { - result = prefix + s; - } - return result; - } - - @Override - public boolean equals(Object o) { - boolean result = o instanceof SemVer && this.compareTo((SemVer)o) == 0; - return result; - } - - @Override - public int hashCode() { - return toString().hashCode(); - } - - /** - * Convertit la representation textuelle de la version en identifiant java valide : - * - en java : "-" "." "+" interdit - * - * @return la valeur ou les carateres interdits sont remplaces par '_' - */ - public String toJavaIdentifier() { - String result = toString(); - - // attention dans les crochets le '-' a une signification, il faut donc le mettre en 1er - result = result.replaceAll("[-+.]", "_"); - - return result; - } - - @Override - public String toString() { - return getVersion() - + ifNotNull(PRERELEASE_SEPARATOR, getPrerelease()) - + ifNotNull(BUILD_SEPARATOR, getBuild()) - + ifNotNull(SNAPSHOT_SEPARATOR, getSnapshot()); - } - - /** - * Retourne un objet creator initialise avec les donnees de ce SemVer - * ce qui permet de creer un nouveau SemVer en modifiant un des elements - * @return FIXME - */ - public SemVerCreator getCreator() { - return creator(this); - } - - /** - * Indique si la chaine represente bien une version au format SemVer - * @param version FIXME - * @return FIXME - */ - static public boolean isSemVer(String version) { - if (StringUtils.endsWithIgnoreCase(version, SNAPSHOT)) { - version = StringUtils.substringBeforeLast(version, SNAPSHOT); - } - Matcher matcher = PATTERN_ALL.matcher(version); - boolean result = matcher.matches(); - return result; - } - - /** - * Permet de creer un objet version. Si des arguments sont passer en parametre - * ils sont pris dans l'ordre pour: la version, la prerelease, le build, le snapshot - * <pre> - * SemVer v = SemVer.creator().setVersion("1.2").setPrerelease("beta.1").setBuild("r123").done(); - * SemVer v = SemVer.creator("1.2", "beta.1","r123", SemVer.SNAPSHOT).done(); - * </pre> - * @param v FIXME - * @return FIXME - */ - static public SemVerCreator creator(String ... v) { - SemVerCreator result = new SemVerCreator(); - if (v != null) { - if (v.length > 0) { - result.setVersion(v[0]); - if (v.length > 1) { - result.setPrerelease(v[1]); - if (v.length > 2) { - result.setBuild(v[2]); - if (v.length > 3) { - if (v[3] == null) { - result.setSnapshot(false); - } else if (StringUtils.equalsIgnoreCase(SNAPSHOT, v[3])) { - result.setSnapshot(true); - } else { - throw new IllegalArgumentException(String.format( - "Illegal SNAPSHOT string '%s'", - v[3])); - } - if (v.length > 4) { - throw new IllegalArgumentException(String.format( - "too many string arguments '%s' maximum 4", - v.length)); - } - } - } - } - } - } - return result; - } - - /** - * Createur qui permet de passer en parametre les different composante de - * l'element version - * @param v FIXME - * @return FIXME - */ - static public SemVerCreator creator(int ... v) { - SemVerCreator result = creator(StringUtils.join(v, SERIES_SEPARATOR)); - return result; - } - - /** - * Create creator initialized with SemVer value, you can change some Element - * by puting null value. - * - * SemVer n = SemVer.creator(v).setBuild("r123").setSnapshot(false).done(); - * - * @param v FIXME - * @return FIXME - */ - static public SemVerCreator creator(SemVer v) { - SemVerCreator result = creator( - v.getVersion(), v.getPrerelease(), v.getBuild(), v.getSnapshot()); - return result; - } - - /** - * Retourne un Createur sans aucune information. Cette methode permet - * aussi de desambiguise les deux autres methode creator qui si elle - * n'ont pas de parametre sont semblable - * - * @return FIXME - */ - static public SemVerCreator creator() { - SemVerCreator result = new SemVerCreator(); - return result; - } - - /** - * Construit un objet version, la verification de la coherence est faite lors - * de l'appel du create. - */ - static public class SemVerCreator { - protected String version; - protected String prerelease; - protected String build; - protected String snapshot; - - public SemVerCreator setVersion(Integer... v) { - // l'argument est bien Integer, car join ne travail qu'avec des objets :( - version = StringUtils.join(v, SERIES_SEPARATOR); - return this; - } - - public SemVerCreator setVersion(String v) { - version = v; - return this; - } - - public SemVerCreator setPrerelease(String v) { - prerelease = v; - return this; - } - - public SemVerCreator setBuild(String v) { - build = v; - return this; - } - - public SemVerCreator setSnapshot(boolean b) { - if (b) { - snapshot = SNAPSHOT; - } else { - snapshot = null; - } - return this; - } - - /** - * Incremente la composante 'indice' de l'element version de 'inc', la composante - * doit representer un entier sinon une exception est leve - * - * @param indice la composante de la version a incrementer - * @param inc le nombre a lui ajouter - * @return new instance, this SemVer is not modified - */ - public SemVerCreator incVersion(int indice, int inc) { - String[] v = StringUtils.split(version, SERIES_SEPARATOR); - Validate.validIndex(v, indice, "Version don't have enought composant"); - - String s = v[indice]; - - Validate.isTrue(StringUtils.isNumeric(s), "String '%s' must be numeric", s); - int i = Integer.parseInt(s); - i += inc; - s = String.valueOf(i); - - v[indice] = s; - version = StringUtils.join(v, SERIES_SEPARATOR); - - return this; - } - - /** - * Return new instance, this SemVer is not modified - * @return new instance where major version number is incremented by 1 - */ - public SemVerCreator incMajor() { - return incVersion(0, 1); - } - - /** - * Return new instance, this SemVer is not modified - * @return new instance where major version number is incremented by 1 - */ - public SemVerCreator incMinor() { - return incVersion(1, 1); - } - - /** - * Return new instance, this SemVer is not modified - * @return new instance where major version number is incremented by 1 - */ - public SemVerCreator incPatch() { - return incVersion(2, 1); - } - - public SemVer done() { - SemVer result = new SemVer( - StringUtils.defaultString(version) + - ifNotNull(PRERELEASE_SEPARATOR, prerelease) + - ifNotNull(BUILD_SEPARATOR, build) + - ifNotNull(SNAPSHOT_SEPARATOR, snapshot) - ); - return result; - } - } - -} diff --git a/src/main/java/org/nuiton/util/version/Version.java b/src/main/java/org/nuiton/util/version/Version.java deleted file mode 100644 index c26b1d9..0000000 --- a/src/main/java/org/nuiton/util/version/Version.java +++ /dev/null @@ -1,486 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.version; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.ObjectUtils; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * <p>A class to represent a version.</p> - * <p>Replace previously {@code org.nuiton.util.Version} class.</p> - * <h3>Definition</h3> - * A version is defined of n {@code componants} separated by {@code componantSeparator}. - * <h4>Componants</h4> - * Componants can be of two types: - * <ul> - * <li>Number componant: a strict positive integer value</li> - * <li>String componant: a sequence of characters which can't be either number nor componant separators</li> - * </ul> - * <h4>Componant separators</h4> - * <p> - * Componant separator are characters which can't be alphanumeric and can be {@code empty character}. - * </p> - * <p> - * Componant separators are optional and componants will be detected as soon as a character changed from a numeric string sequence to a alpha (none numeric!) sequence. - * </p> - * <p> - * For example, version {@code 1a2} is composed of three componants: {code 1}, {@code a} and {@code 3}. - * </p> - * <h4>Snapshot flag</h4> - * Additionnaly version can be qualifed as a {@code SNAPSHOT} (see below section about ordering). - * <h3>Examples</h3> - * <pre> - * 0 (one componant 0) - * 0-SNAPSHOT (one componant 0 + SNAPSHOT flag) - * 1.0 (two componants 1,0) - * 1.1 (two componants 1,1) - * 1.1-alpha-1 (four componants 1,1,alpha,1) - * 1.1-beta (three componants 1,1,beta) - * 1.1-rc-1 (four componants 1,1,rc,1) - * 1.1-a (three componants 1,1,a) - * 1.1-a12-4.45_6432 (seven componants 1,1,a,12,4,45,643) - * </pre> - * <h3>Ordering</h3> - * A version is comparable, to have all the detail of order see {@link VersionComparator}. - * <h3>Immutability</h3> - * The version is immutable, to create or modify a version, use the {@link VersionBuilder} API - * or shortcut methods in {@link Versions}. - * - * @author Tony Chemit - chemit@codelutin.com - * @see VersionBuilder - * @see VersionComparator - * @since 3.0 - * @deprecated since 3.0, use now <a href="https://gitlab.nuiton.org/nuiton/nuiton-version/blob/develop/src/main/java/org/nuiton/version/Version.java">Nuiton version</a> - */ -@Deprecated -public class Version implements Comparable<Version>, Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Suffix of a {@code SNAPSHOT} version in the text representation. - */ - public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; - - /** - * Version V0. - */ - public static final Version VZERO = VersionBuilder.create().build(); - - /** - * Comparator of version used internaly to fulfill the compoarator contract. - */ - protected static final VersionComparator VERSION_COMPARATOR = new VersionComparator(); - - public static final char DEFAULT_JOIN_COMPONANT_SEPARATOR = '.'; - - /** - * List of componants of the version. - */ - protected final List<VersionComponant> componants; - - /** - * List of separators of the version. - */ - protected final List<String> componantSeparators; - - /** - * flag to define if version is a snapshot (if so a -SNAPSHOT is - * added at the end of the textual representation of the version). - */ - protected final boolean snapshot; - - /** - * string represention of the version. - */ - protected transient String version; - - protected Version(List<VersionComponant> componants, List<String> componantSeparators, boolean snapshot) { - this.componantSeparators = Collections.unmodifiableList(new ArrayList<String>(componantSeparators)); - this.componants = Collections.unmodifiableList(new ArrayList<VersionComponant>(componants)); - this.snapshot = snapshot; - } - - public List<VersionComponant> getComponants() { - return componants; - } - - public List<String> getComponantSeparators() { - return componantSeparators; - } - - public boolean isSnapshot() { - return snapshot; - } - - public int getComponantCount() { - return componants.size(); - } - - public int getNumberComponant(int componantPosition) { - - VersionComponant comparable = getComponant(componantPosition); - Preconditions.checkState(comparable instanceof NumberVersionComponant, "componant at " + componantPosition + " for version " + this + " is not a number (" + comparable + ")"); - return (Integer) comparable.getValue(); - - } - - public String getTextComponant(int componantPosition) { - - VersionComponant comparable = getComponant(componantPosition); - Preconditions.checkState(comparable instanceof StringVersionComponant, "componant at " + componantPosition + " for version " + this + " is not a string (" + comparable + ")"); - return (String) comparable.getValue(); - - } - - public VersionComponant getComponant(int level) { - - Preconditions.checkArgument(level > 0 || level < getComponantCount(), "not a valid level " + level + " for the Version " + this); - return componants.get(level); - - } - - /** - * @return the string represention value of the version - */ - public String getVersion() { - if (version == null) { - - version = String.valueOf(componants.get(0).getValue()); - - for (int i = 0, nb = componantSeparators.size(); i < nb; i++) { - - version += componantSeparators.get(i); - version += componants.get(i + 1).getValue(); - - } - - if (snapshot) { - version += SNAPSHOT_SUFFIX; - } - - } - return version; - } - - /** - * Convert the string representation to a java identifier compliant. - * - * <ul> - * <li>in java: {@code .} is forbidden</li> - * <li>in database (mysql, h2 ...): {@code .} is forbidden</li> - * </ul> - * - * Forbidden values are replaced by {@code _} character. - * - * @return the java compilant string representation of the version - */ - public String getValidName() { - - String validName = getVersion(); - - // replace ". et -" - validName = validName.replaceAll("\\.|-", "_"); - - return validName; - - } - - /** - * Creates a new version from this one incremented. - * - * If the last componant is a number, then just increments this number; otherwise add a new - * number componant with value 1. - * - * Example: - * <ul> - * <li>1 → 2</li> - * <li>1-a → 1-a.1</li> - * </ul> - * - * @return the incremented version - * @deprecated use instead {@link Versions#increments(Version)} - */ - @Deprecated - public Version increments() { - - Version newVersion = Versions.increments(this); - return newVersion; - - } - - /** - * Creates a new version from this one incremented. - * - * If the last componant is a number, then just increments this number; otherwise add a new - * number componant with value 1. - * - * Example: - * <ul> - * <li>1 → 2</li> - * <li>1-a → 1-a.1</li> - * </ul> - * - * @param componantSeperator the componant separator to use the last componant is a classifier - * @return the incremented version - * @deprecated use instead {@link Versions#increments(Version, char)} - */ - @Deprecated - public Version increments(char componantSeperator) { - - Version newVersion = Versions.increments(this, componantSeperator); - return newVersion; - - } - - /** - * Creates a new version from this one with the number componant incremented at the given position. - * - * <strong>Note:</strong> - * Will fail if the componant at the required position is not a number. - * - * @param componantPosition position of the version componant to increment - * @return the incremented version - * @deprecated use instead {@link Versions#increments(Version, int)} - */ - @Deprecated - public Version increments(int componantPosition) { - - Version newVersion = Versions.increments(this, componantPosition); - return newVersion; - - } - - /** - * Creates a new version from this one with the number componant decremented at the given position. - * - * <strong>Note:</strong> - * Will fail if the componant at the required position is not a number, or his value is 0. - * - * @param componantPosition position of the version componant to increment - * @return the decremented version - * @deprecated use {@link Versions#decrements(Version, int)} instead - */ - @Deprecated - public Version decrements(int componantPosition) { - - Version newVersion = Versions.decrements(this, componantPosition); - return newVersion; - - } - - @Override - public int compareTo(Version o) { - int result = VERSION_COMPARATOR.compare(this, o); - return result; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is before or equals the given one - */ - public boolean beforeOrequals(Version o) { - int result = compareTo(o); - return result <= 0; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is before the given one - */ - public boolean before(Version o) { - int result = compareTo(o); - return result < 0; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is after or equals the given one - */ - public boolean afterOrEquals(Version o) { - int result = compareTo(o); - return result >= 0; - } - - /** - * @param o the other version to test - * @return {@code true} if current version is after the given one - */ - public boolean after(Version o) { - int result = compareTo(o); - return result > 0; - } - - @Override - public String toString() { - return getVersion(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Version)) return false; - - return compareTo((Version) o) == 0; - - } - - @Override - public int hashCode() { - int result = componants.hashCode(); - result = 31 * result + (snapshot ? 1 : 0); - return result; - } - - protected VersionComponant getLastComponant() { - - return componants.get(getComponantCount() - 1); - - } - - - public interface VersionComponant<C extends Comparable<C>, V extends VersionComponant> extends Serializable, Comparable<V> { - - C getValue(); - - } - - - public static class NumberVersionComponant implements VersionComponant<Integer, NumberVersionComponant> { - - private static final long serialVersionUID = 1L; - - protected final Integer value; - - public NumberVersionComponant(Integer value) { - this.value = value; - } - - @Override - public Integer getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - - if (this == o) return true; - if (!(o instanceof NumberVersionComponant)) return false; - - return compareTo((NumberVersionComponant) o) == 0; - - } - - @Override - public int hashCode() { - return value.hashCode(); - } - - @Override - public int compareTo(NumberVersionComponant o) { - return value.compareTo(o.value); - } - } - - public static class StringVersionComponant implements VersionComponant<String, StringVersionComponant> { - - private static final long serialVersionUID = 1L; - - protected final boolean preRelease; - - protected final String value; - - protected final String lowerCaseValue; - - public StringVersionComponant(boolean preRelease, String value) { - this.preRelease = preRelease; - this.value = value; - this.lowerCaseValue = value.toLowerCase(); - } - - @Override - public String getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - - if (this == o) return true; - if (!(o instanceof StringVersionComponant)) return false; - - return compareTo((StringVersionComponant) o) == 0; - - } - - @Override - public int hashCode() { - - int result = preRelease ? 1 : 0; - result = 31 * result + value.hashCode(); - return result; - - } - - public boolean isPreRelease() { - return preRelease; - } - - @Override - public int compareTo(StringVersionComponant o) { - - int result; - - if (ObjectUtils.notEqual(preRelease, o.preRelease)) { - - // compare on preRelease flag - - if (preRelease) { - - // preRelease is before any other string componant - result = -1; - - } else { - - result = 1; - - } - - } else { - - // on same preRelease flag - // compare on lowerCaseValue - result = lowerCaseValue.compareTo(o.lowerCaseValue); - - } - - return result; - - } - } -} diff --git a/src/main/java/org/nuiton/util/version/VersionBuilder.java b/src/main/java/org/nuiton/util/version/VersionBuilder.java deleted file mode 100644 index 5c8a2af..0000000 --- a/src/main/java/org/nuiton/util/version/VersionBuilder.java +++ /dev/null @@ -1,428 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.CharUtils; -import org.apache.commons.lang3.StringUtils; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * To build some {@link Version}. - * - * <h3>General usage</h3> - * Use one the {@code create} methods, custom what you need on build, and finally - * use {@link #build()} method to obtain a version. - * <h3>Options details</h3> - * TODO - * <ul> - * <li>{@code preReleaseClassifiers}</li> - * <li>{@code splitSeparators}</li> - * <li>{@code joinSeparator}</li> - * <li>{@code snapshot}</li> - * </ul> - * <h3>Customize componants</h3> - * TODO - * - * Created on 7/11/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.0 - * @deprecated since 3.0, use now <a href="https://gitlab.nuiton.org/nuiton/nuiton-version/blob/develop/src/main/java/org/nuiton/version/VersionBuilder.java">Nuiton version</a> - */ -@Deprecated -public class VersionBuilder { - - /** - * Classifiers known as pre-release classifiers. - */ - protected Set<String> preReleaseClassifiers; - - /** - * Set of characters used to split componants. - */ - protected Set<Character> splitSeparators; - - /** - * The character to join componant in a string representation. - */ - protected Character joinSeparator; - - /** - * The string represention of the version. - */ - protected String version; - - /** - * List of componants of the version. - */ - protected List<Comparable> componants; - - /** - * List of componants separators explicitly definied (used as {@link Version#componantSeparators}. - */ - protected List<String> componantSeparators; - - /** - * Is the version a snapshot ? In a such case, the {@link #version} ends with {@code -SNAPSHOT}. - */ - protected boolean snapshot; - - public static VersionBuilder create() { - return new VersionBuilder(); - } - - public static VersionBuilder create(String version) { - return new VersionBuilder().setVersion(version); - } - - public static VersionBuilder create(Version version) { - - List<Comparable> componants = toComparableList(version.getComponants()); - List<String> componantSeparators = new ArrayList<String>(version.getComponantSeparators()); - boolean snapshot = version.isSnapshot(); - return new VersionBuilder().setComponants(componants).setComponantSeparators(componantSeparators).setSnapshot(snapshot); - - } - - public static VersionBuilder create(List<Comparable> componants) { - return new VersionBuilder().setComponants(componants); - } - - public VersionBuilder() { - splitSeparators = new HashSet<Character>(); - splitSeparators.add('-'); - splitSeparators.add('.'); - splitSeparators.add('_'); - joinSeparator = '.'; - preReleaseClassifiers = new HashSet<String>(); - preReleaseClassifiers.add("alpha"); - preReleaseClassifiers.add("beta"); - preReleaseClassifiers.add("rc"); - } - - public VersionBuilder setVersion(String version) { - Preconditions.checkState(!fromComponants(), "Can't set version if componants are filled"); - this.version = version; - return this; - } - - public VersionBuilder setComponants(List<Comparable> componants) { - Preconditions.checkState(!fromStringRepresentation(), "Can't set componants if version is filled"); - this.componants = componants; - return this; - } - - public VersionBuilder setComponant(int level, Comparable value) { - - Preconditions.checkState(!fromStringRepresentation(), "Can't set componants if version is filled"); - int size = componants.size(); - Preconditions.checkArgument(level >= 0 && level < size, "level should be in [0, " + (size - 1) + "]"); - - componants.set(level, value); - return this; - - } - - public VersionBuilder addComponant(Comparable value) { - - Preconditions.checkState(!fromStringRepresentation(), "Can't set componants if version is filled"); - componants.add(value); - return this; - - } - - public VersionBuilder addComponant(Comparable value, char componantSeparator) { - - addComponant(value); - - if (componantSeparators == null) { - - // init it with join separator - componantSeparators = new ArrayList<String>(componants.size() - 1); - - initSeparatorList(componantSeparators, componants.size() - 2); - - } - - componantSeparators.add(componantSeparator + ""); - - return this; - - } - - public VersionBuilder removeComponant(int level) { - - Preconditions.checkState(!fromStringRepresentation(), "Can't set componants if version is filled"); - int size = componants.size(); - Preconditions.checkArgument(level >= 0 && level < size, "level should be in [0, " + (size - 1) + "]"); - this.componants.remove(level); - if (componantSeparators != null) { - - // remove this separator - this.componantSeparators.remove(level - 1); - - } - return this; - - } - - public VersionBuilder setComponantSeparators(List<String> componantSeparators) { - - Preconditions.checkState(!fromStringRepresentation(), "Can't set componants if version is filled"); - Preconditions.checkArgument(componantSeparators.size() == componants.size() - 1, "Must have n-1 componant separators if you have n componants"); - this.componantSeparators = componantSeparators; - return this; - - } - - public VersionBuilder setComponantSeparator(int level, char value) { - - Preconditions.checkState(!fromStringRepresentation(), "Can't set componants if version is filled"); - int size = componants.size(); - Preconditions.checkArgument(level >= 0 && level < size, "level should be in [0, " + (size - 2) + "]"); - this.componantSeparators.set(level, value + ""); - return this; - - } - - public VersionBuilder setSnapshot(boolean snapshot) { - - Preconditions.checkState(!fromStringRepresentation(), "Can't set snapshot if version is filled"); - this.snapshot = snapshot; - return this; - - } - - public VersionBuilder setSplitSeparators(Set<Character> splitSeparators) { - - for (Character splitSeparator : splitSeparators) { - Preconditions.checkState(!CharUtils.isAsciiAlphanumeric(splitSeparator), "Can't use a alphanumeric splitseparator"); - } - this.splitSeparators = splitSeparators; - return this; - - } - - public VersionBuilder setJoinSeparator(Character joinSeparator) { - this.joinSeparator = joinSeparator; - return this; - } - - public VersionBuilder setPreReleaseClassifiers(Set<String> preReleaseClassifiers) { - this.preReleaseClassifiers = preReleaseClassifiers; - return this; - } - - protected boolean fromStringRepresentation() { - return version != null; - } - - protected boolean fromComponants() { - return componants != null; - } - - public Version build() { - - List<Version.VersionComponant> finalComponants = new ArrayList<Version.VersionComponant>(); - List<String> finalComponantSeparators = new ArrayList<String>(); - - boolean finalSnapshot; - - if (fromComponants()) { - - finalSnapshot = snapshot; - - for (Comparable componant : componants) { - - boolean number = componant instanceof Integer; - Version.VersionComponant v = toVersionComponant(number, String.valueOf(componant)); - finalComponants.add(v); - - } - - if (CollectionUtils.isNotEmpty(componantSeparators)) { - - finalComponantSeparators = new ArrayList<String>(componantSeparators); - - } else { - - initSeparatorList(finalComponantSeparators, finalComponants.size() - 1); - - } - - } else if (fromStringRepresentation()) { - - // compute componants + snapshot from version - - finalSnapshot = this.version.endsWith(Version.SNAPSHOT_SUFFIX); - - String versionPart = StringUtils.substringBeforeLast(this.version, Version.SNAPSHOT_SUFFIX); - - // --- split by splitSeparator --- // - - boolean numberState = false; - - String currentComponantStr = null; - - for (int i = 0, l = versionPart.length(); i < l; i++) { - - char currentChar = versionPart.charAt(i); - - if (splitSeparators.contains(currentChar)) { - - // end of a componant - - finalComponantSeparators.add(currentChar + ""); - - if (currentComponantStr != null) { - - // register new componant - - Version.VersionComponant componant = toVersionComponant(numberState, currentComponantStr); - - finalComponants.add(componant); - - currentComponantStr = null; - - } - - } else { - - boolean number = CharUtils.isAsciiNumeric(currentChar); - - if (currentComponantStr == null) { - - // start a new componant - currentComponantStr = "" + currentChar; - numberState = number; - - } else if (numberState == number) { - - // still on same type - // concat to current componant - currentComponantStr += currentChar; - - } else { - - // new componant detected - // finalize the current componant - - Version.VersionComponant componant = toVersionComponant(numberState, currentComponantStr); - finalComponants.add(componant); - finalComponantSeparators.add(""); - - // start the new componant - - numberState = number; - currentComponantStr = "" + currentChar; - - } - - } - - } - - if (currentComponantStr != null) { - - // flush last componant - - Version.VersionComponant componant = toVersionComponant(numberState, currentComponantStr); - finalComponants.add(componant); - - } - - } else { - - // empty version - - finalSnapshot = snapshot; - finalComponants.add(new Version.NumberVersionComponant(0)); - - } - - if (finalComponantSeparators.isEmpty() && finalComponants.size() > 1) { - - // use componant join separator - - initSeparatorList(finalComponantSeparators, finalComponants.size() - 1); - - } - - Version result = new Version(finalComponants, finalComponantSeparators, finalSnapshot); - return result; - - } - - protected void initSeparatorList(List<String> list, int size) { - - for (int i = 0; i < size; i++) { - - list.add("" + joinSeparator); - - } - - } - - protected Version.VersionComponant toVersionComponant(boolean numberState, String currentComponantStr) { - - Version.VersionComponant componant; - - if (numberState) { - - // was a number - componant = new Version.NumberVersionComponant(Integer.valueOf(currentComponantStr)); - - } else { - - // was a string - boolean preRelease = preReleaseClassifiers.contains(currentComponantStr.toLowerCase()); - - componant = new Version.StringVersionComponant(preRelease, currentComponantStr); - - } - return componant; - - } - - protected static List<Comparable> toComparableList(List<Version.VersionComponant> componants) { - - List<Comparable> result = Lists.newArrayList(Lists.transform(componants, new Function<Version.VersionComponant, Comparable>() { - @Override - public Comparable apply(Version.VersionComponant input) { - return input.getValue(); - } - })); - - return result; - - } - -} diff --git a/src/main/java/org/nuiton/util/version/VersionComparator.java b/src/main/java/org/nuiton/util/version/VersionComparator.java deleted file mode 100644 index 8b19d01..0000000 --- a/src/main/java/org/nuiton/util/version/VersionComparator.java +++ /dev/null @@ -1,222 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Joiner; -import org.apache.commons.lang3.ObjectUtils; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Comparator of {@link Version}. - * - * You may be before this the documentation of {@link Version} object... - * <h1>Version componant ordering</h1> - * We can compare only componants of same type. - * - * Number componants use natural number ordering (0<1<2,...) (see {@link Version.NumberVersionComponant}). - * - * String componants use {@code preRelease} flag order (preRelease is before any other string componant) then natural character ordering of the {@code lowerCase} componant value. (see {@link Version.StringVersionComponant}). - * <pre>alpha == Alpha, aa > rc</pre> - * <h2>Snapshot ordering</h2> - * A {@code snapshot} version is before the exact same version without the flag. - * <pre>1.1-SNAPSHOT < 1.1</pre> - * <h2>General ordering algorithm</h2> - * We compare version componants at same position until there is a difference. - * - * If common componants of version are both equals, have a look to the next componant of the longuest version - * (if the version have the same componants size, Versions are equals!). - * - * If the next componant is a number, the longuest version is after the other one: - * <pre>1 < 1.0</pre> - * If the next componant is a classifier, we consider the componant {@code preRelease} flag, - * if setted then the longuest version is before the other one, if no, after: - * <pre>1-alpha < 1 < 1-aa</pre> - * <h2>Examples</h2> - * Here is a list of ordered versions: - * <pre> - * 0-SNAPSHOT - * 0 - * 0.1 - * 0.2 - * 0.2-alpha - * 0.2-alpha-1 - * 0.2-alpha-2-SNAPSHOT - * 0.2-alpha-2 - * 0.2-beta - * 0.2-beta-1 - * 0.2-rc-1 - * 0.2 - * 0.2-aa - * </pre> - * Created on 7/11/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @see Version - * @since 3.0 - * @deprecated since 3.0, use now <a href="https://gitlab.nuiton.org/nuiton/nuiton-version/blob/develop/src/main/java/org/nuiton/version/VersionComparator.java">Nuiton version</a> - */ -@Deprecated -public class VersionComparator implements Comparator<Version>, Serializable { - - private static final long serialVersionUID = 1L; - - @Override - public int compare(Version o1, Version o2) { - - int o1NbComponants = o1.getComponantCount(); - int o2NbComponants = o2.getComponantCount(); - int minComponantSize = Math.min(o1NbComponants, o2NbComponants); - int maxComponantSize = Math.max(o1NbComponants, o2NbComponants); - - int result = 0; - - for (int i = 0; result == 0 && i < minComponantSize; i++) { - - Version.VersionComponant o1Componant = o1.getComponant(i); - Version.VersionComponant o2Componant = o2.getComponant(i); - - if (ObjectUtils.equals(o1Componant.getClass(), o2Componant.getClass())) { - - // same componant type, using natural order - result = o1Componant.compareTo(o2Componant); - - } else { - - // different componant type - // classifier is always lower than number componant - if (o1Componant instanceof Version.NumberVersionComponant) { - - result = 1; - } else { - - result = -1; - } - } - } - - if (result == 0 && minComponantSize != maxComponantSize) { - - // same value base on common componants - // check type of next componant on the longuest version - if (o2NbComponants == minComponantSize) { - - // o1 has more componants - Version.VersionComponant componant = o1.getComponant(minComponantSize); - if (componant instanceof Version.StringVersionComponant) { - - // o1 has a string - Version.StringVersionComponant stringVersionComponant = (Version.StringVersionComponant) componant; - if (stringVersionComponant.isPreRelease()) { - - // o1 is pre-release so before o2 - result = -1; - - } else { - - // o1 is post release so after o2 - result = 1; - - } - } else { - - // o1 has one more number componant: after o2 - result = 1; - - } - - } else { - - // o2 has more componants - Version.VersionComponant componant = o2.getComponant(minComponantSize); - - if (componant instanceof Version.StringVersionComponant) { - - // o2 has a string - Version.StringVersionComponant stringVersionComponant = (Version.StringVersionComponant) componant; - if (stringVersionComponant.isPreRelease()) { - - // o2 is pre-release so before o1 - result = 1; - - } else { - - // o2 is post release so after o1 - result = -1; - - } - } else { - - // o2 has one more number componant: after o1 - result = -1; - - } - - } - - } - - if (result == 0 && ObjectUtils.notEqual(o1.isSnapshot(), o2.isSnapshot())) { - - // snapshot is lower than none snapshot - - if (o2.isSnapshot()) { - - // o2 is snapshot - result = 1; - - } else { - - // o1 is snapshot - result = -1; - - } - } - - return result; - - } - - /** - * Sort in reverse order the given versions and print them to the standard output. - * - * @param args versions to sort - */ - public static void main(String... args) { - - List<Version> versions = new ArrayList<Version>(); - for (String arg : args) { - Version version = Versions.valueOf(arg); - versions.add(version); - } - Collections.sort(versions, Collections.reverseOrder(new VersionComparator())); - String join = Joiner.on(' ').join(versions); - System.out.println(join); - - } - -} diff --git a/src/main/java/org/nuiton/util/version/VersionConverter.java b/src/main/java/org/nuiton/util/version/VersionConverter.java deleted file mode 100644 index 3723974..0000000 --- a/src/main/java/org/nuiton/util/version/VersionConverter.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.converter.NuitonConverter; - -/** - * To convert {@link Version} using {@link Converter} API. - * - * Created on 7/11/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @see Version - * @since 3.0 - * @deprecated since 3.0, use now <a href="https://gitlab.nuiton.org/nuiton/nuiton-version/blob/develop/src/main/java/org/nuiton/version/VersionConverter.java">Nuiton version</a> - */ -@Deprecated -public class VersionConverter implements NuitonConverter<Version> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(VersionConverter.class); - - public VersionConverter() { - if (log.isDebugEnabled()) { - log.debug("init version converter " + this); - } - } - - @Override - public Class<Version> getType() { - return Version.class; - } - - @Override - public <T> T convert(Class<T> aClass, Object value) { - if (value == null) { - throw new ConversionException( - String.format("No value specified for converter %s", this)); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return aClass.cast(result); - } - if (value instanceof String) { - try { - result = VersionBuilder.create((String) value).build(); - return aClass.cast(result); - } catch (IllegalArgumentException e) { - throw new ConversionException( - String.format("Could not convert version %1$s with converter %2$s for reason \\: %3$s", value, this, e.getMessage()), e); - } - } - } - throw new ConversionException( - String.format("no convertor found for type %2$s and objet '%1$s'", aClass.getName(), value)); - } - - protected boolean isEnabled(Class<?> aClass) { - return Version.class.equals(aClass); - } -} diff --git a/src/main/java/org/nuiton/util/version/Versions.java b/src/main/java/org/nuiton/util/version/Versions.java deleted file mode 100644 index 0258cfb..0000000 --- a/src/main/java/org/nuiton/util/version/Versions.java +++ /dev/null @@ -1,280 +0,0 @@ -package org.nuiton.util.version; - -import com.google.common.base.Preconditions; - -import java.util.ArrayList; -import java.util.List; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Useful class around {@link Version}. - * <p> - * Created on 8/23/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.0-rc-6 - * @deprecated since 3.0, use now <a href="https://gitlab.nuiton.org/nuiton/nuiton-version/blob/develop/src/main/java/org/nuiton/version/Versions.java">Nuiton version</a> - */ -@Deprecated -public class Versions { - - /** - * Shortcut method to get a version from his string representation. - * - * @param version string representation of the version - * @return converted version from the string representation - */ - public static Version valueOf(String version) { - Version v = VersionBuilder.create(version).build(); - return v; - } - - /** - * Tests if two versions are equals. - * - * @param version0 the first version - * @param version1 the second version - * @return {@code true} if versions are equals, {@code false} otherwise. - */ - public static boolean equals(String version0, String version1) { - Version v0 = valueOf(version0); - Version v1 = valueOf(version1); - boolean result = v0.equals(v1); - return result; - } - - /** - * Tests if the first version is smaller than the second version. - * - * @param version0 the first version - * @param version1 the second version - * @return {@code true} if {@code version0} is before {@code version1}, - * {@code false} otherwise. - */ - public static boolean smallerThan(String version0, String version1) { - Version v0 = valueOf(version0); - Version v1 = valueOf(version1); - boolean result = v0.before(v1); - return result; - } - - /** - * Tests if the first version is greater than the second version. - * - * @param version0 the first version - * @param version1 the second version - * @return {@code true} if {@code version0} is after {@code version1}, - * {@code false} otherwise. - */ - public static boolean greaterThan(String version0, String version1) { - Version v0 = valueOf(version0); - Version v1 = valueOf(version1); - boolean result = v0.after(v1); - return result; - } - - /** - * Create a version from the given one and set to it the {@code snapshot} state to {@code true}. - * - * @param version version to clone - * @return the cloned version with the {@code snapshot} state to {@code true} - * @throws IllegalArgumentException if {@code snapshot} state is already set to {@code true} on - * the given {@code version}. - */ - public static Version addSnapshot(Version version) { - if (version.isSnapshot()) { - throw new IllegalArgumentException( - "version " + version + "is already a snapshot"); - } - Version result = VersionBuilder.create(version).setSnapshot(true).build(); - return result; - } - - /** - * Create a version from the given one and set to it the {@code snapshot} state to {@code false}. - * - * @param version version to clone - * @return the cloned version with the {@code snapshot} state to {@code true} - * @throws IllegalArgumentException if {@code snapshot} state is already set to {@code false} on - * the given {@code version} - */ - public static Version removeSnapshot(Version version) { - if (!version.isSnapshot()) { - throw new IllegalArgumentException( - "version " + version + "is already a snapshot"); - } - Version result = VersionBuilder.create(version).setSnapshot(false).build(); - return result; - } - - /** - * Create a new version containing a single component from a given version. - * - * @param version original version - * @param component component index to extract - * @return new {@link Version} with a single component - */ - public static Version extractVersion(Version version, int component) { - Version result = extractVersion(version, component, component); - return result; - } - - /** - * Create a new version containing a sub set of component from a given version. - * - * @param version original version - * @param firstComponent first component index - * @param lastComponent last component index - * @return new {@link Version} with a components sub set - */ - public static Version extractVersion(Version version, int firstComponent, int lastComponent) { - if (lastComponent < firstComponent) { - throw new IllegalArgumentException("lastComponent must be greater or equals to firstComponent"); - } - - // extract components - List<Comparable> componants = new ArrayList<Comparable>(); - for (int index = firstComponent; index <= lastComponent; index++) { - Comparable component = version.getComponant(index).getValue(); - componants.add(component); - } - - Version result = VersionBuilder.create().setComponants(componants).build(); - return result; - } - - /** - * Creates a new version from this one incremented. - * <p> - * If the last componant is a number, then just increments this number; otherwise add a new - * number componant with value 1. - * <p> - * Example: - * <ul> - * <li>1 → 2</li> - * <li>1-a → 1-a.1</li> - * </ul> - * - * @param version FIXME - * @return the incremented version - */ - public static Version increments(Version version) { - - Version result = increments(version, Version.DEFAULT_JOIN_COMPONANT_SEPARATOR); - return result; - - } - - /** - * Creates a new version from this one incremented. - * <p> - * If the last componant is a number, then just increments this number; otherwise add a new - * number componant with value 1. - * <p> - * Example: - * <ul> - * <li>1 → 2</li> - * <li>1-a → 1-a.1</li> - * </ul> - * - * @param version FIXME - * @param componantSeperator the componant separator to use the last componant is a classifier - * @return the incremented version - */ - public static Version increments(Version version, char componantSeperator) { - - Version newVersion; - - Version.VersionComponant lastComponant = version.getLastComponant(); - - if (lastComponant instanceof Version.StringVersionComponant) { - - // must then add new number componant with value 1 - - newVersion = VersionBuilder - .create(version) - .addComponant(1, componantSeperator) - .build(); - - } else { - - // increments it - int numberComponant = ((Version.NumberVersionComponant) lastComponant).getValue(); - - newVersion = VersionBuilder - .create(version) - .setComponant(version.getComponantCount() - 1, numberComponant + 1) - .build(); - } - - return newVersion; - - } - - /** - * Creates a new version from this one with the number componant incremented at the given position. - * <p> - * <strong>Note:</strong> - * Will fail if the componant at the required position is not a number. - * - * @param version FIXME - * @param componantPosition position of the version componant to increment - * @return the incremented version - */ - public static Version increments(Version version, int componantPosition) { - - int numberComponant = version.getNumberComponant(componantPosition); - - Version newVersion = VersionBuilder - .create(version) - .setComponant(componantPosition, numberComponant + 1) - .build(); - - return newVersion; - - } - - /** - * Creates a new version from this one with the number componant decremented at the given position. - * <p> - * <strong>Note:</strong> - * Will fail if the componant at the required position is not a number, or his value is 0. - * - * @param version FIXME - * @param componantPosition position of the version componant to increment - * @return the decremented version - */ - public static Version decrements(Version version, int componantPosition) { - - int numberComponant = version.getNumberComponant(componantPosition); - Preconditions.checkArgument(componantPosition > 0, "Componant at position " + componantPosition + " values 0, can't decrement it."); - Version newVersion = VersionBuilder - .create(version) - .setComponant(componantPosition, numberComponant - 1) - .build(); - - return newVersion; - - } -} diff --git a/src/test/java/org/nuiton/util/AliasMapTest.java b/src/test/java/org/nuiton/util/AliasMapTest.java index 8f80b15..644ee9c 100644 --- a/src/test/java/org/nuiton/util/AliasMapTest.java +++ b/src/test/java/org/nuiton/util/AliasMapTest.java @@ -58,6 +58,7 @@ public class AliasMapTest { Assert.assertEquals("E", v); Assert.assertArrayEquals(new String[]{}, toArray(map.getAlias("e"))); Assert.assertArrayEquals(new String[]{"ebis"}, toArray(map.getKeyAlias("é"))); + Assert.assertArrayEquals(new String[]{"ebis"}, toArray(map.getKeyAlias("é"))); Collection<String> cr = map.removeValue("à", "é"); Assert.assertArrayEquals(new String[]{}, toArray(cr)); diff --git a/src/test/java/org/nuiton/util/ObjectUtilTest.java b/src/test/java/org/nuiton/util/ObjectUtilTest.java index 622c265..8c396a6 100644 --- a/src/test/java/org/nuiton/util/ObjectUtilTest.java +++ b/src/test/java/org/nuiton/util/ObjectUtilTest.java @@ -96,31 +96,6 @@ public class ObjectUtilTest extends Assert { assertEquals(new File("/tmp/fileTest"), dummy.getFile()); } - @Test - public void testGetNullValue() throws Exception { - - try { - assertNull(ObjectUtil.getNullValue(null)); - fail(); - } catch (Exception e) { - assertTrue(true); - } - - assertEquals(false, ObjectUtil.getNullValue(boolean.class)); - assertEquals(0, ObjectUtil.getNullValue(int.class)); - assertEquals((char) 0, ObjectUtil.getNullValue(char.class)); - assertEquals(0f, ObjectUtil.getNullValue(float.class)); - assertEquals(0d, ObjectUtil.getNullValue(double.class)); - assertEquals((byte) 0, ObjectUtil.getNullValue(byte.class)); - - assertNull(ObjectUtil.getNullValue(Boolean.class)); - assertNull(ObjectUtil.getNullValue(Integer.class)); - assertNull(ObjectUtil.getNullValue(Character.class)); - assertNull(ObjectUtil.getNullValue(Float.class)); - assertNull(ObjectUtil.getNullValue(Double.class)); - assertNull(ObjectUtil.getNullValue(Byte.class)); - } - @Test public void testIsNullValue() throws Exception { diff --git a/src/test/java/org/nuiton/util/PagerBeanUtilTest.java b/src/test/java/org/nuiton/util/PagerBeanUtilTest.java deleted file mode 100644 index 08e58d0..0000000 --- a/src/test/java/org/nuiton/util/PagerBeanUtilTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.nuiton.util; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.lang3.tuple.Pair; -import org.junit.Assert; -import org.junit.Test; - -/** - * Test {@link PagerBeanUtil}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.6.6 - */ -public class PagerBeanUtilTest { - - @Test - public void getPageBound() throws Exception { - - Pair<Long, Long> actualBound; - - // page size is greater than total count, only returns that is available - actualBound = PagerBeanUtil.getPageBound((long) Integer.MAX_VALUE * 2l, 1, 11); - Assert.assertEquals(Pair.of(0l, 11l), actualBound); - - } - - @Test - public void getPageBoundWithInfinityPageSize() throws Exception { - - Pair<Long, Long> actualBound; - - // page size is -1, get all content - long totalCount = (long) Integer.MAX_VALUE * 2L; - actualBound = PagerBeanUtil.getPageBound(totalCount, 1, -1); - Assert.assertEquals(Pair.of(0L, totalCount), actualBound); - - } - - @Test - public void getTotalPage() throws Exception { - long totalPage; - - totalPage = PagerBeanUtil.getTotalPage(9, 10); - Assert.assertEquals(1, totalPage); - - totalPage = PagerBeanUtil.getTotalPage(10, 10); - Assert.assertEquals(1, totalPage); - - totalPage = PagerBeanUtil.getTotalPage(11, 10); - Assert.assertEquals(2, totalPage); - - totalPage = PagerBeanUtil.getTotalPage( - (long) Integer.MAX_VALUE * 20, 10); - Assert.assertEquals(Integer.MAX_VALUE * 2l, totalPage); - - } -} diff --git a/src/test/java/org/nuiton/util/ResourceTest.java b/src/test/java/org/nuiton/util/ResourceTest.java index 3f4800a..0727198 100644 --- a/src/test/java/org/nuiton/util/ResourceTest.java +++ b/src/test/java/org/nuiton/util/ResourceTest.java @@ -208,9 +208,9 @@ public class ResourceTest { // ResourceTest assumeNotUnderWindows(getClass(), testName); // ce test peut echoué a chaque changement dans les dépendances - List<URL> urlsPattern = Resource.getResources("org/nuiton/util/Version.*Test\\.class"); - List<URL> urlsClass1 = Resource.getResources("org/nuiton/util/VersionTest.class"); - List<URL> urlsClass2 = Resource.getResources("org/nuiton/util/VersionUtilTest.class"); + List<URL> urlsPattern = Resource.getResources("org/nuiton/util/beans/Bean.*Test\\.class"); + List<URL> urlsClass1 = Resource.getResources("org/nuiton/util/beans/BeanMonitorTest.class"); + List<URL> urlsClass2 = Resource.getResources("org/nuiton/util/beans/BeanUtilTest.class"); Assert.assertEquals(2, urlsPattern.size()); Assert.assertEquals(urlsPattern.size(), urlsClass1.size() + urlsClass2.size()); diff --git a/src/test/java/org/nuiton/util/SemVerTest.java b/src/test/java/org/nuiton/util/SemVerTest.java deleted file mode 100644 index 1d1cc70..0000000 --- a/src/test/java/org/nuiton/util/SemVerTest.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.nuiton.util; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author Benjamin Poussin - poussin@codelutin.com - * @deprecated since 3.0 (use now {@link org.nuiton.util.version.SemVerTest}. - */ -@Deprecated -public class SemVerTest { - - /** - * Logger. - */ - private static final Log log = LogFactory.getLog(SemVerTest.class); - - /** - * Liste de toutes les versions a tester, de la plus petite a la plus grande - */ - String[] versions = { - "0", - "0.0.0-SNAPSHOT", - "0.0.0", - "1.0.0-alpha-SNAPSHOT", - "1.0.0-alpha", - "1.0.0-alpha.1", - "1.0.0-beta.2 ", - " 1.0.0-beta.11 ", - " 1.0.0-rc.1 ", - " 1.0.0-rc.1+build.1-SNAPSHOT ", - " 1.0.0-rc.1+build.1 ", - " 1.0.0 ", - " 1.0.0+0.3.7 ", - " 1.0.0.23 ", - " 1.3.7+build ", - " 1.3.7+build.2.b8f12d7 ", - " 1.3.7+build.11.e0f985a", - "99.100-20130127+r123", - }; - - // on doit avoir ici les memes entrees que versions dans le meme ordre - String[][] versionSplits = { - {"0", null, null, null}, - {"0.0.0", null, null, "SNAPSHOT"}, - {"0.0.0", null, null, null}, - {"1.0.0", "alpha", null, "SNAPSHOT"}, - {"1.0.0", "alpha", null, null}, - {"1.0.0", "alpha.1", null, null}, - {"1.0.0", "beta.2", null, null}, - {"1.0.0", "beta.11", null, null}, - {"1.0.0", "rc.1", null, null}, - {"1.0.0", "rc.1", "build.1", "SNAPSHOT"}, - {"1.0.0", "rc.1", "build.1", null}, - {"1.0.0", null, null, null}, - {"1.0.0", null, "0.3.7", null}, - {"1.0.0.23", null, null, null}, - {"1.3.7", null, "build", null}, - {"1.3.7", null, "build.2.b8f12d7", null}, - {"1.3.7", null, "build.11.e0f985a", null}, - {"99.100", "20130127", "r123", null}, - }; - - @Test - public void testCreation() { - for (int i = 0; i < versions.length; i++) { - SemVer v = new SemVer(versions[i]); - SemVer vs = SemVer.creator(versionSplits[i]).done(); - Assert.assertEquals(v, vs); - - Assert.assertEquals(versionSplits[i][0], v.getVersion()); - Assert.assertEquals(versionSplits[i][1], v.getPrerelease()); - Assert.assertEquals(versionSplits[i][2], v.getBuild()); - Assert.assertEquals(versionSplits[i][3], v.getSnapshot()); - } - } - - @Test - public void testCreator() { - SemVer v = new SemVer(" 1.0.0-rc.1+build.1-SNAPSHOT "); - SemVer n = SemVer.creator(v).setVersion(1, 1, 3).setPrerelease("rc.2").setBuild("r123").setSnapshot(false).done(); - Assert.assertEquals("1.1.3-rc.2+r123", n.toString()); - } - - @Test - public void testInc() { - - String[][] testIncValue = { - {"0", "1"}, - {"0.0.0-SNAPSHOT", "1.0.0-SNAPSHOT", "0.1.0-SNAPSHOT", "0.0.1-SNAPSHOT"}, - {"0.0.0", "1.0.0", "0.1.0", "0.0.1"}, - {"1.0.0-alpha-SNAPSHOT", "2.0.0-alpha-SNAPSHOT", "1.1.0-alpha-SNAPSHOT", "1.0.1-alpha-SNAPSHOT"}, - {"1.0.0-alpha", "2.0.0-alpha", "1.1.0-alpha", "1.0.1-alpha"}, - {"1.0.0-alpha.1", "2.0.0-alpha.1", "1.1.0-alpha.1", "1.0.1-alpha.1"}, - {" 1.0.0.23 ", " 2.0.0.23 ", " 1.1.0.23 ", " 1.0.1.23 ", " 1.0.0.24 "}, - {"99.100-20130127+r123", "100.100-20130127+r123", "99.101-20130127+r123"}, - }; - - for (int i = 1; i < testIncValue.length; i++) { - SemVer version = new SemVer(testIncValue[i][0]); - Assert.assertEquals(String.format( - "Le nombre de composante doit correspondre au nombre de test a faire %s", - Arrays.toString(testIncValue[i])), - testIncValue[i].length - 1, version.getVersionCount()); - for (int x = 1; x < testIncValue[i].length; x++) { - SemVer expected = new SemVer(testIncValue[i][x]); - SemVer inc = SemVer.creator(version).incVersion(x - 1, 1).done(); - Assert.assertEquals(expected, inc); - } - } - } - - @Test - public void testIncMajorMinorPatch() { - // on test seulement sur un exemple, les autres cas sont gere par le testInc - SemVer version = new SemVer(" 1.0.0.23 "); - - SemVer incMajor = SemVer.creator(version).incMajor().done(); - Assert.assertEquals(new SemVer(" 2.0.0.23 "), incMajor); - - SemVer incMinor = SemVer.creator(version).incMinor().done(); - Assert.assertEquals(new SemVer(" 1.1.0.23 "), incMinor); - - SemVer incPatch = SemVer.creator(version).incPatch().done(); - Assert.assertEquals(new SemVer(" 1.0.1.23 "), incPatch); - } - - @Test - public void testGetComposant() { - SemVer v = new SemVer(" 1.0.3-rc.1+build.1-SNAPSHOT "); - Assert.assertEquals("1", v.getMajor()); - Assert.assertEquals("0", v.getMinor()); - Assert.assertEquals("3", v.getPatch()); - - Assert.assertEquals("rc", v.getPrerelease(0)); - Assert.assertEquals("1", v.getPrerelease(1)); - - Assert.assertEquals("build", v.getBuild(0)); - Assert.assertEquals("1", v.getBuild(1)); - - Assert.assertEquals("SNAPSHOT", v.getSnapshot()); - - } - - @Test - public void testToJavaIdentifier() { - SemVer v = new SemVer(" 1.0.3-rc.1+build.1-SNAPSHOT "); - Assert.assertEquals("1_0_3_rc_1_build_1_SNAPSHOT", v.toJavaIdentifier()); - } - - /** - * Ce test ne sert pas vraiment en temps normale, mais lorsqu'il y a un - * test qui fail dans testAll, il est pratique de remettre le test qui - * echoue plus specifiquement ici pour le debug - */ - @Test - public void testOne() { - SemVer vi = new SemVer(" 1.0.0+0.3.7 "); - SemVer vj = new SemVer(" 1.0.0.23 "); - - int result = normalize(vi.compareTo(vj)); - int expected = -1; - - Assert.assertTrue(String.format( - "Bad compare: Compare(%s, %s) = %s, expected %s", - vi, vj, result, expected), - expected == result); -// System.out.println(String.format( -// "Good compare: Compare(%s, %s) = %s, expected %s", -// vi, vj, result, expected)); - } - - @Test - public void testAll() { - for (int i = 0; i < versions.length; i++) { - for (int j = 0; j < versions.length; j++) { - SemVer vi = new SemVer(versions[i]); - SemVer vj = new SemVer(versions[j]); - - int result = normalize(vi.compareTo(vj)); - int expected = Integer.valueOf(i).compareTo(j); // AThimel 2013/02/26 Rewritten for JDK6 compatibility. Was: Integer.compare(i, j); - - Assert.assertTrue(String.format( - "Bad compare: Compare(%s, %s) = %s, expected %s", - vi, vj, result, expected), - expected == result); - } - } - } - - /** - * Si le comparator ne renvoi pas -1, 0, 1 on normalize pour avoir -1, 0, 1 - * - * @param v ? - * @return ? - */ - protected int normalize(int v) { - int result = v; - if (v != 0) { - result = v / Math.abs(v); - } - return result; - } -} diff --git a/src/test/java/org/nuiton/util/VersionTest.java b/src/test/java/org/nuiton/util/VersionTest.java deleted file mode 100644 index cb6f3a1..0000000 --- a/src/test/java/org/nuiton/util/VersionTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.nuiton.util.VersionUtilTest.VERSIONS; -import static org.nuiton.util.VersionUtilTest.compareVersions; - -/** - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.1.0 - * @deprecated since 3.0 (use now {@link org.nuiton.util.version.VersionTest}). - */ -@Deprecated -public class VersionTest { - - /** - * Test of hasClassifier method, of class Version. - */ - @Test - public void testHasClassifier() { - Version instance = new Version(); - boolean expResult = false; - boolean result = instance.hasClassifier(); - assertEquals(expResult, result); - instance = new Version("yo", 1); - expResult = true; - result = instance.hasClassifier(); - assertEquals(expResult, result); - } - - /** - * Test of getValidName method, of class Version. - */ - @Test - public void testGetValidName() { - - getValidName("0", Version.VZERO, new Version(), new Version(0), new Version("0")); - getValidName("1", new Version(1), new Version("1")); - getValidName("1_1", new Version(1, 1), new Version("1.1")); - getValidName("1_1_alpha_1", new Version("alpha", 1, 1, 1), new Version("ALPHA", 1, 1, 1)); - getValidName("1_1_beta_1", new Version("BETA", 1, 1, 1), new Version("beta", 1, 1, 1)); - getValidName("2_1_rc_1", new Version("rC", 1, 2, 1), new Version("Rc", 1, 2, 1)); - } - - /** - * Test of getVersion method, of class Version. - */ - @Test - public void testGetVersion() { - - getVersion("0", Version.VZERO, new Version(), new Version(0), new Version("0")); - getVersion("1", new Version(1), new Version("1")); - getVersion("1.1", new Version(1, 1), new Version("1.1")); - getVersion("1.1-alpha-1", new Version("alpha", 1, 1, 1), new Version("ALPHA", 1, 1, 1), new Version("alPHA", 1, 1, 1)); - getVersion("1.1-beta-1", new Version("BETA", 1, 1, 1), new Version("beta", 1, 1, 1), new Version("BeTa", 1, 1, 1)); - getVersion("2.1-rc-1", new Version("rC", 1, 2, 1), new Version("Rc", 1, 2, 1)); - } - - /** - * Test of compareTo method, of class Version. - */ - @Test - public void testCompareTo() { - - // ------- - // o1 = o2 - // ------- - - compareVersions(0, Arrays.asList(Version.VZERO, new Version(), new Version(0), new Version("0"))); - compareVersions(0, Arrays.asList(new Version(1), new Version("1"))); - compareVersions(0, Arrays.asList(new Version(1, 1), new Version("1.1"))); - compareVersions(0, Arrays.asList(new Version("alpha", 1, 1, 1), new Version("ALPHA", 1, 1, 1))); - compareVersions(0, Arrays.asList(new Version("BETA", 1, 1, 1), new Version("beta", 1, 1, 1))); - compareVersions(0, Arrays.asList(new Version("rC", 1, 2, 1), new Version("Rc", 1, 2, 1))); - - - // ------- - // o1 > o2 - // ------- - - List<Version> sortedVersions = new ArrayList<Version>(VERSIONS); - - Collections.sort(sortedVersions); - - assertEquals(VERSIONS, sortedVersions); - - compareVersions(-1, sortedVersions); - - // ------- - // o1 < o2 - // ------- - - List<Version> reversedVersions = new ArrayList<Version>(VERSIONS); - Collections.reverse(reversedVersions); - Collections.reverse(sortedVersions); - - assertEquals(sortedVersions, reversedVersions); - - compareVersions(1, reversedVersions); - - } - - /** - * Test of equals method, of class Version. - */ - @Test - public void testEquals() { - - compareVersions(0, Arrays.asList(new Version(1), new Version("1"))); - compareVersions(0, Arrays.asList(new Version(1, 1), new Version("1.1"))); - compareVersions(0, Arrays.asList(new Version("alpha", 1, 1, 1), new Version("AlpHa", 1, 1, 1), new Version("ALPHA", 1, 1, 1))); - compareVersions(0, Arrays.asList(new Version("BETA", 1, 1, 1), new Version("beta", 1, 1, 1), new Version("BEtA", 1, 1, 1))); - compareVersions(0, Arrays.asList(new Version("rC", 1, 2, 1), new Version("Rc", 1, 2, 1))); - } - - protected void getValidName(String expected, Version... versions) { - for (Version v : versions) { - assertEquals(expected, v.getValidName()); - } - } - - protected void getVersion(String expected, Version... versions) { - for (Version v : versions) { - assertEquals(expected, v.getVersion()); - } - } -} diff --git a/src/test/java/org/nuiton/util/VersionUtilTest.java b/src/test/java/org/nuiton/util/VersionUtilTest.java deleted file mode 100644 index 983af76..0000000 --- a/src/test/java/org/nuiton/util/VersionUtilTest.java +++ /dev/null @@ -1,471 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.regex.Matcher; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Tony Chemit - chemit@codelutin.com - * @since 1.1.0 - * @deprecated since 3.0 (use now {@link org.nuiton.util.version.VersionTest}). - */ -@Deprecated -public class VersionUtilTest { - - /** Logger. */ - private static final Log log = LogFactory.getLog(VersionUtilTest.class); - - protected static final List<Version> VERSIONS = Collections.unmodifiableList(Arrays.asList( - new Version(), - new Version(0, 0, 1), - new Version(0, 1), - new Version(1), - new Version(1, 0), - new Version(1, 0, 0), - new Version(1, 1), - new Version("alPha", 0, 1, 1, 0), - new Version("alpHa", 1, 1, 1, 0), - new Version("alphA", 2, 1, 1, 0), - new Version("betA", 0, 1, 1, 0), - new Version("beTa", 1, 1, 1, 0), - new Version("bEta", 2, 1, 1, 0), - new Version("rc", 0, 1, 1, 0), - new Version("rC", 1, 1, 1, 0), - new Version("Rc", 2, 1, 1, 0), - new Version(1, 1, 0))); - protected static final List<Version> VERSIONS_INC = Collections.unmodifiableList(Arrays.asList( - new Version(1), - new Version(0, 0, 2), - new Version(0, 2), - new Version(2), - new Version(1, 1), - new Version(1, 0, 1), - new Version(1, 2), - new Version("alPha", 1, 1, 1, 0), - new Version("alpHa", 2, 1, 1, 0), - new Version("alphA", 3, 1, 1, 0), - new Version("betA", 1, 1, 1, 0), - new Version("beTa", 2, 1, 1, 0), - new Version("bEta", 3, 1, 1, 0), - new Version("rc", 1, 1, 1, 0), - new Version("rC", 2, 1, 1, 0), - new Version("Rc", 3, 1, 1, 0), - new Version(1, 1, 1))); - - @Test - public void testPatterns() { - - assertPattern("1-2.3.4", false); - assertPattern("1.a", false); - assertPattern("1.alpha", false); - assertPattern("1.alpha-", false); - assertPattern("1.alpha-4", false); - assertPattern("1-alpha", false); - assertPattern("1-alpha-", false); - assertPattern("1--3", false); - assertPattern("-alpha-1", false); - assertPattern("a-alpha-1", false); - assertPattern("-alpha-1-", false); - - assertPattern("1.2.3.4", true, "1.2.3.4", null, null, null); - assertPattern("1.2.3.4-SNAPSHOT", true, "1.2.3.4", null, null, "-SNAPSHOT"); - - assertPattern("1.2.3.4-alpha-1", true, "1.2.3.4", "alpha", "1", null); - assertPattern("1.2.3.4-alpha-1-SNAPSHOT", true, "1.2.3.4", "alpha", "1", "-SNAPSHOT"); - - assertPattern("1.2.3.4-classifier-9", true, "1.2.3.4", "classifier", "9", null); - assertPattern("1.2.3.4-classifier-9-SNAPSHOT", true, "1.2.3.4", "classifier", "9", "-SNAPSHOT"); - } - - @Test - public void testPatterns2() { - - assertPattern2("1-2.3.4", false); - assertPattern2("1.a", false); - assertPattern2("1.alpha", false); - assertPattern2("1.alpha-", false); - assertPattern2("1.alpha4", false); - assertPattern2("1-alpha", false); - assertPattern2("1-alpha-", false); - assertPattern2("1--3", false); - assertPattern2("-alpha1", false); - assertPattern2("a-alpha1", false); - assertPattern2("-alpha1-", false); - - assertPattern2("1.2.3.4", true, "1.2.3.4", null, null, null); - assertPattern2("1.2.3.4-SNAPSHOT", true, "1.2.3.4", null, null, "-SNAPSHOT"); - - assertPattern2("1.2.3.4-alpha1", true, "1.2.3.4", "alpha", "1", null); - assertPattern2("1.2.3.4-alpha1-SNAPSHOT", true, "1.2.3.4", "alpha", "1", "-SNAPSHOT"); - - assertPattern2("1.2.3.4-classifier9", true, "1.2.3.4", "classifier", "9", null); - assertPattern2("1.2.3.4-classifier9-SNAPSHOT", true, "1.2.3.4", "classifier", "9", "-SNAPSHOT"); - } - - /** Test of the {@link VersionUtil#DEFAULT_VERSION_COMPARATOR}. */ - @Test - public void testVersionComparotor() { - - // ------- - // o1 = o2 - // ------- - - compareVersions(0, Arrays.asList(Version.VZERO, new Version(), new Version(0), new Version("0"))); - - compareVersions(0, Arrays.asList(new Version(1), new Version("1"))); - compareVersions(0, Arrays.asList(new Version(1, 1), new Version("1.1"))); - compareVersions(0, Arrays.asList(new Version("alpha", 1, 1, 1), new Version("AlpHa", 1, 1, 1), new Version("ALPHA", 1, 1, 1))); - compareVersions(0, Arrays.asList(new Version("BETA", 1, 1, 1), new Version("beta", 1, 1, 1), new Version("BEtA", 1, 1, 1))); - compareVersions(0, Arrays.asList(new Version("rC", 1, 2, 1), new Version("Rc", 1, 2, 1))); - - // ------- - // o1 > o2 - // ------- - - List<Version> sortedVersions = new ArrayList<Version>(VERSIONS); - - Collections.sort(sortedVersions, VersionUtil.DEFAULT_VERSION_COMPARATOR); - - assertEquals(VERSIONS, sortedVersions); - - compareVersions(-1, sortedVersions); - - // ------- - // o1 < o2 - // ------- - - Collections.reverse(sortedVersions); - - compareVersions(1, sortedVersions); - - } - - @Test - public void testInc() { - int i = 0; - for (Version v : VERSIONS) { - Version incV = VERSIONS_INC.get(i++); - assertFalse(v.equals(incV)); - assertTrue(incV.compareTo(v) > 0); - assertTrue(v.compareTo(incV) < 0); - } - } - - @Test - public void testAddClassifier() { - String classifier = "test"; - Integer classifierNumber = 1; - - try { - VersionUtil.addClassifier(null, null, null); - fail(); - } catch (NullPointerException e) { - assertTrue(true); - } - try { - VersionUtil.addClassifier(Version.VZERO, null, null); - fail(); - } catch (NullPointerException e) { - assertTrue(true); - } - try { - VersionUtil.addClassifier(Version.VZERO, classifier, null); - fail(); - } catch (NullPointerException e) { - assertTrue(true); - } - - for (Version v : VERSIONS) { - - - if (v.hasClassifier()) { - // on ne peut pas ajouter un classifier si deja present - try { - VersionUtil.addClassifier(v, classifier, classifierNumber); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - continue; - } - - Version incV = VersionUtil.addClassifier(v, classifier, classifierNumber); - - assertFalse(v.equals(incV)); - - assertEquals(v.toString() + "-" + classifier + "-" + classifierNumber, incV.toString()); - - // classifier version est toujours plus ancienne - assertTrue(incV.compareTo(v) < 0); - assertTrue(v.compareTo(incV) > 0); - } - } - - @Test - public void testRemoveClassifier() { - - try { - VersionUtil.removeClassifier(null); - fail(); - } catch (NullPointerException e) { - assertTrue(true); - } - - for (Version v : VERSIONS) { - - - if (!v.hasClassifier()) { - // on ne peut pas supprimer le classifier non present - try { - VersionUtil.removeClassifier(v); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - continue; - } - - Version incV = VersionUtil.removeClassifier(v); - - assertFalse(v.equals(incV)); - - assertEquals(v.toString().substring(0, v.toString().indexOf("-")), incV.toString()); - - // classifier version est toujours plus ancienne - assertTrue(incV.compareTo(v) > 0); - assertTrue(v.compareTo(incV) < 0); - } - } - - /** Test of filterVersions method, of class VersionUtil. */ - @Test - public void testFilterVersions() { - - Set<Version> versions = new TreeSet<Version>(); - Version v1 = new Version(1); - Version v2 = new Version(2); - Version v3 = new Version(3); - Version v4 = new Version(4); - Version v5 = new Version(5); - versions.add(v1); - versions.add(v2); - versions.add(v3); - versions.add(v4); - versions.add(v5); - - List<Version> actual; - - // filter [0,0] = [] - actual = VersionUtil.filterVersions(versions, Version.VZERO, Version.VZERO, true, true); - assertVersionsEquals(actual); - - // filter [0,1[ = [] - actual = VersionUtil.filterVersions(versions, Version.VZERO, v1, true, false); - assertVersionsEquals(actual); - - // filter [0,1] = [1] - actual = VersionUtil.filterVersions(versions, Version.VZERO, v1, true, true); - assertVersionsEquals(actual, v1); - - // filter [0,2[ = [1] - actual = VersionUtil.filterVersions(versions, Version.VZERO, v2, true, false); - assertVersionsEquals(actual, v1); - - // filter [0,2] = [1,2] - actual = VersionUtil.filterVersions(versions, Version.VZERO, v2, true, true); - assertVersionsEquals(actual, v1, v2); - - // filter [1,2] = [1,2] - actual = VersionUtil.filterVersions(versions, v1, v2, true, true); - assertVersionsEquals(actual, v1, v2); - - // filter ]1,2] = [2] - actual = VersionUtil.filterVersions(versions, v1, v2, false, true); - assertVersionsEquals(actual, v2); - - // filter [2,2] = [2] - actual = VersionUtil.filterVersions(versions, v2, v2, true, true); - assertVersionsEquals(actual, v2); - - // filter ]2,2] = [2] - actual = VersionUtil.filterVersions(versions, v2, v2, false, true); - assertVersionsEquals(actual); - - // filter ]2,2[ = [] - actual = VersionUtil.filterVersions(versions, v2, v2, false, false); - assertVersionsEquals(actual); - - // filter ]Null,2[ = [1] - actual = VersionUtil.filterVersions(versions, null, v2, false, false); - assertVersionsEquals(actual, v1); - - // filter [Null,2[ = [1] - actual = VersionUtil.filterVersions(versions, null, v2, true, false); - assertVersionsEquals(actual, v1); - - // filter ]Null,2] = [1,2] - actual = VersionUtil.filterVersions(versions, null, v2, false, true); - assertVersionsEquals(actual, v1, v2); - - // filter ]Null,Null[ = [1,2,3,4,5] - actual = VersionUtil.filterVersions(versions, null, null, false, false); - assertVersionsEquals(actual, v1, v2, v3, v4, v5); - - // filter ]2,Null[ = [3,4,5] - actual = VersionUtil.filterVersions(versions, v2, null, false, false); - assertVersionsEquals(actual, v3, v4, v5); - - // filter [2,Null[ = [2,3,4,5] - actual = VersionUtil.filterVersions(versions, v2, null, true, false); - assertVersionsEquals(actual, v2, v3, v4, v5); - } - - @Test - public void testSnapshot() { - Version v = VersionUtil.valueOf("1"); - Assert.assertFalse(v.isSnapshot()); - - Version v2 = VersionUtil.addSnapshot(v); - Assert.assertTrue(v2.isSnapshot()); - - Assert.assertTrue(v2.before(v)); - - Version v3 = VersionUtil.removeSnapshot(v2); - Assert.assertFalse(v3.isSnapshot()); - - Version v4 = VersionUtil.addClassifier(v2, "a", 1); - - Assert.assertTrue(v4.isSnapshot()); - Assert.assertTrue(v4.before(v2)); - } - - @Test - public void testAnomalie1629() { - Version v1 = VersionUtil.valueOf("1-beta1"); - Version v2 = VersionUtil.valueOf("1-beta-1"); - Assert.assertEquals(v1, v2); - Assert.assertFalse(v1.toString().equals(v2.toString())); - v1.setClassifierNumberAttached(false); - Assert.assertEquals(v1, v2); - Assert.assertEquals(v1.toString(), v2.toString()); - - } - - protected static void compareVersions(int order, Iterable<Version> versions) { - - Iterator<Version> iterator = versions.iterator(); - - Version previous = iterator.next(); - - while (iterator.hasNext()) { - Version current = iterator.next(); - - int result = previous.compareTo(current); - int result2 = current.compareTo(previous); - - assertTrue(order != 0 || result == 0); - assertTrue(order != 0 || result2 == 0); - if (order != 0) { - assertTrue("not good order : required = " + order + " but find " + result + " between " + previous + " and " + current, order * result > 0); - assertTrue("not good order : required = " + -order + " but find " + result2 + " between " + current + " and " + previous, order * result2 < 0); - if (order > 0) { - assertTrue(current.before(previous)); - } else { - assertTrue(current.after(previous)); - } - } - - previous = current; - } - } - - protected void assertPattern(String t, boolean match, String... groups) { - if (log.isDebugEnabled()) { - log.debug("convert " + t + ", mustMatch : " + match); - } - Matcher m = VersionUtil.VERSION_PATTERN.matcher(t); - - assertEquals(match, m.matches()); - - if (match) { - assertEquals(groups.length, m.groupCount()); - for (int i = 1; i <= m.groupCount(); i++) { - String group = m.group(i); - assertEquals(groups[i - 1], group); - if (group != null) { - if (log.isDebugEnabled()) { - log.debug("group " + i + " : " + group); - } - } - } - } - } - - protected void assertPattern2(String t, boolean match, String... groups) { - if (log.isDebugEnabled()) { - log.debug("convert " + t + ", mustMatch : " + match); - } - Matcher m = VersionUtil.VERSION_PATTERN2.matcher(t); - - assertEquals(match, m.matches()); - - if (match) { - assertEquals(groups.length, m.groupCount()); - for (int i = 1; i <= m.groupCount(); i++) { - String group = m.group(i); - assertEquals(groups[i - 1], group); - if (group != null) { - if (log.isDebugEnabled()) { - log.debug("group " + i + " : " + group); - } - } - } - } - } - - private void assertVersionsEquals(List<Version> actual, Version... expected) { - assertEquals(expected.length, actual.size()); - int i = 0; - for (Version a : actual) { - Version e = expected[i++]; - assertEquals(a, e); - } - } -} diff --git a/src/test/java/org/nuiton/util/converter/ConverterUtilTest.java b/src/test/java/org/nuiton/util/converter/ConverterUtilTest.java deleted file mode 100644 index d9b5d04..0000000 --- a/src/test/java/org/nuiton/util/converter/ConverterUtilTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.ConvertUtils; -import org.apache.commons.beanutils.Converter; -import org.junit.Assert; -import org.junit.Test; -import org.nuiton.util.Version; - -/** - * ConverterUtil Tester. - * - * @author Tony Chemit - chemit@codelutin.com - * @version 1.3 (replace class {@code org.nuiton.util.ConverterUtilTest}). - * @since <pre>02/13/2008</pre> - */ -@Deprecated -public class ConverterUtilTest { - - @Test - public void testInitConverters() { - - ConverterUtil.deregister(); - - Converter t = ConvertUtils.lookup(Version.class); - Assert.assertNull(t); - ConverterUtil.initConverters(); - t = ConvertUtils.lookup(Version.class); - Assert.assertNotNull(t); - } - - @Test - public void testConvert() throws Exception { - String s; - s = ""; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - s = "a"; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - s = "kZZFIOFEIOFEfdskdfmldsfjklsfjldfldfjdsfiosabcd4567'''`~teAZEst"; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - s = "]{}{}{{[#{[{#[#]{][{^#][^]#{^[]{#][#]{]@[{#][^#{][^]#{teAZEst"; - Assert.assertEquals( - new String(s.getBytes()), - new String(ConverterUtil.convert(s.toCharArray()))); - - // FIXME following test won't pass - //s = "éééééé]{}{}{{[#{[{#[#]{][{^#][^]#{^[]{#][#]{]@[{#][^#{][^]#{teAZEst"; - //assertEquals(new String(s.getBytes()), new String(ConverterUtil.convert(s.toCharArray()))); - - } -} diff --git a/src/test/java/org/nuiton/util/converter/UnregistreableConverter.java b/src/test/java/org/nuiton/util/converter/UnregistreableConverter.java deleted file mode 100644 index db6b182..0000000 --- a/src/test/java/org/nuiton/util/converter/UnregistreableConverter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.apache.commons.beanutils.Converter; - -/** - * A converter with no getType method, so not registreable via {@link ConverterUtil#initConverters()} - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 (replace class {@code org.nuiton.util.UnregistreableConverter}). - */ -@Deprecated -public class UnregistreableConverter implements Converter{ - - @Override - public Object convert(Class type, Object value) { - return value; - } - -} diff --git a/src/test/java/org/nuiton/util/converter/VersionConverterTest.java b/src/test/java/org/nuiton/util/converter/VersionConverterTest.java deleted file mode 100644 index 6e68090..0000000 --- a/src/test/java/org/nuiton/util/converter/VersionConverterTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -package org.nuiton.util.converter; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.util.Version; - -import static org.junit.Assert.*; - -/** - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 (replace class {@code org.nuiton.util.VersionConverterTest}). - */ -@Deprecated -public class VersionConverterTest { - - VersionConverter converter; - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - converter = new VersionConverter(); - } - - @After - public void tearDown() { - } - - /** - * Test of convert method, of class VersionConverter. - */ - @Test - public void testConvert() { - Object value; - Object expResult; - Object result; - - value = ""; - expResult = new Version(); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - - value = "0"; - expResult = new Version(); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - - value = "1.2.3.4"; - expResult = new Version(1, 2, 3, 4); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - - value = "1.2.3.4-alpha-11"; - expResult = new Version("alpha", 11, 1, 2, 3, 4); - result = converter.convert(Version.class, value); - assertEquals(expResult, result); - } - - /** - * Test of isEnabled method, of class VersionConverter. - */ - @Test - public void testIsEnabled() { - - boolean expResult = true; - boolean result = converter.isEnabled(Version.class); - assertEquals(expResult, result); - } -} diff --git a/src/test/java/org/nuiton/util/version/SemVerTest.java b/src/test/java/org/nuiton/util/version/SemVerTest.java deleted file mode 100644 index e2a1523..0000000 --- a/src/test/java/org/nuiton/util/version/SemVerTest.java +++ /dev/null @@ -1,223 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2004 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; - -/** - * @author Benjamin Poussin - poussin@codelutin.com - */ -@Deprecated -public class SemVerTest { - - /** - * Liste de toutes les versions a tester, de la plus petite a la plus grande - */ - String[] versions = { - "0", - "0.0.0-SNAPSHOT", - "0.0.0", - "1.0.0-alpha-SNAPSHOT", - "1.0.0-alpha", - "1.0.0-alpha.1", - "1.0.0-beta.2 ", - " 1.0.0-beta.11 ", - " 1.0.0-rc.1 ", - " 1.0.0-rc.1+build.1-SNAPSHOT ", - " 1.0.0-rc.1+build.1 ", - " 1.0.0 ", - " 1.0.0+0.3.7 ", - " 1.0.0.23 ", - " 1.3.7+build ", - " 1.3.7+build.2.b8f12d7 ", - " 1.3.7+build.11.e0f985a", - "99.100-20130127+r123", - }; - - // on doit avoir ici les memes entrees que versions dans le meme ordre - String[][] versionSplits = { - {"0", null, null, null}, - {"0.0.0", null, null, "SNAPSHOT"}, - {"0.0.0", null, null, null}, - {"1.0.0", "alpha", null, "SNAPSHOT"}, - {"1.0.0", "alpha", null, null}, - {"1.0.0", "alpha.1", null, null}, - {"1.0.0", "beta.2", null, null}, - {"1.0.0", "beta.11", null, null}, - {"1.0.0", "rc.1", null, null}, - {"1.0.0", "rc.1", "build.1", "SNAPSHOT"}, - {"1.0.0", "rc.1", "build.1", null}, - {"1.0.0", null, null, null}, - {"1.0.0", null, "0.3.7", null}, - {"1.0.0.23", null, null, null}, - {"1.3.7", null, "build", null}, - {"1.3.7", null, "build.2.b8f12d7", null}, - {"1.3.7", null, "build.11.e0f985a", null}, - {"99.100", "20130127", "r123", null}, - }; - - @Test - public void testCreation() { - for (int i = 0; i < versions.length; i++) { - SemVer v = new SemVer(versions[i]); - SemVer vs = SemVer.creator(versionSplits[i]).done(); - Assert.assertEquals(v, vs); - - Assert.assertEquals(versionSplits[i][0], v.getVersion()); - Assert.assertEquals(versionSplits[i][1], v.getPrerelease()); - Assert.assertEquals(versionSplits[i][2], v.getBuild()); - Assert.assertEquals(versionSplits[i][3], v.getSnapshot()); - } - } - - @Test - public void testCreator() { - SemVer v = new SemVer(" 1.0.0-rc.1+build.1-SNAPSHOT "); - SemVer n = SemVer.creator(v).setVersion(1, 1, 3).setPrerelease("rc.2").setBuild("r123").setSnapshot(false).done(); - Assert.assertEquals("1.1.3-rc.2+r123", n.toString()); - } - - @Test - public void testInc() { - - String[][] testIncValue = { - {"0", "1"}, - {"0.0.0-SNAPSHOT", "1.0.0-SNAPSHOT", "0.1.0-SNAPSHOT", "0.0.1-SNAPSHOT"}, - {"0.0.0", "1.0.0", "0.1.0", "0.0.1"}, - {"1.0.0-alpha-SNAPSHOT", "2.0.0-alpha-SNAPSHOT", "1.1.0-alpha-SNAPSHOT", "1.0.1-alpha-SNAPSHOT"}, - {"1.0.0-alpha", "2.0.0-alpha", "1.1.0-alpha", "1.0.1-alpha"}, - {"1.0.0-alpha.1", "2.0.0-alpha.1", "1.1.0-alpha.1", "1.0.1-alpha.1"}, - {" 1.0.0.23 ", " 2.0.0.23 ", " 1.1.0.23 ", " 1.0.1.23 ", " 1.0.0.24 "}, - {"99.100-20130127+r123", "100.100-20130127+r123", "99.101-20130127+r123"}, - }; - - for (int i = 1; i < testIncValue.length; i++) { - SemVer version = new SemVer(testIncValue[i][0]); - Assert.assertEquals(String.format( - "Le nombre de composante doit correspondre au nombre de test a faire %s", - Arrays.toString(testIncValue[i])), - testIncValue[i].length - 1, version.getVersionCount()); - for (int x = 1; x < testIncValue[i].length; x++) { - SemVer expected = new SemVer(testIncValue[i][x]); - SemVer inc = SemVer.creator(version).incVersion(x - 1, 1).done(); - Assert.assertEquals(expected, inc); - } - } - } - - @Test - public void testIncMajorMinorPatch() { - // on test seulement sur un exemple, les autres cas sont gere par le testInc - SemVer version = new SemVer(" 1.0.0.23 "); - - SemVer incMajor = SemVer.creator(version).incMajor().done(); - Assert.assertEquals(new SemVer(" 2.0.0.23 "), incMajor); - - SemVer incMinor = SemVer.creator(version).incMinor().done(); - Assert.assertEquals(new SemVer(" 1.1.0.23 "), incMinor); - - SemVer incPatch = SemVer.creator(version).incPatch().done(); - Assert.assertEquals(new SemVer(" 1.0.1.23 "), incPatch); - } - - @Test - public void testGetComposant() { - SemVer v = new SemVer(" 1.0.3-rc.1+build.1-SNAPSHOT "); - Assert.assertEquals("1", v.getMajor()); - Assert.assertEquals("0", v.getMinor()); - Assert.assertEquals("3", v.getPatch()); - - Assert.assertEquals("rc", v.getPrerelease(0)); - Assert.assertEquals("1", v.getPrerelease(1)); - - Assert.assertEquals("build", v.getBuild(0)); - Assert.assertEquals("1", v.getBuild(1)); - - Assert.assertEquals("SNAPSHOT", v.getSnapshot()); - - } - - @Test - public void testToJavaIdentifier() { - SemVer v = new SemVer(" 1.0.3-rc.1+build.1-SNAPSHOT "); - Assert.assertEquals("1_0_3_rc_1_build_1_SNAPSHOT", v.toJavaIdentifier()); - } - - /** - * Ce test ne sert pas vraiment en temps normale, mais lorsqu'il y a un - * test qui fail dans testAll, il est pratique de remettre le test qui - * echoue plus specifiquement ici pour le debug - */ - @Test - public void testOne() { - SemVer vi = new SemVer(" 1.0.0+0.3.7 "); - SemVer vj = new SemVer(" 1.0.0.23 "); - - int result = normalize(vi.compareTo(vj)); - int expected = -1; - - Assert.assertTrue(String.format( - "Bad compare: Compare(%s, %s) = %s, expected %s", - vi, vj, result, expected), - expected == result); -// System.out.println(String.format( -// "Good compare: Compare(%s, %s) = %s, expected %s", -// vi, vj, result, expected)); - } - - @Test - public void testAll() { - for (int i = 0; i < versions.length; i++) { - for (int j = 0; j < versions.length; j++) { - SemVer vi = new SemVer(versions[i]); - SemVer vj = new SemVer(versions[j]); - - int result = normalize(vi.compareTo(vj)); - int expected = Integer.valueOf(i).compareTo(j); // AThimel 2013/02/26 Rewritten for JDK6 compatibility. Was: Integer.compare(i, j); - - Assert.assertTrue(String.format( - "Bad compare: Compare(%s, %s) = %s, expected %s", - vi, vj, result, expected), - expected == result); - } - } - } - - /** - * Si le comparator ne renvoi pas -1, 0, 1 on normalize pour avoir -1, 0, 1 - * - * @param v ? - * @return ? - */ - protected int normalize(int v) { - int result = v; - if (v != 0) { - result = v / Math.abs(v); - } - return result; - } -} diff --git a/src/test/java/org/nuiton/util/version/VersionBuilderTest.java b/src/test/java/org/nuiton/util/version/VersionBuilderTest.java deleted file mode 100644 index eb1c652..0000000 --- a/src/test/java/org/nuiton/util/version/VersionBuilderTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import org.junit.Assert; -import org.junit.Test; - -/** - * Created on 7/10/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.0 - */ -@Deprecated -public class VersionBuilderTest { - - @Test - public void testBuildVersionFromString() { - - buildVersion(VersionBuilder.create().build(), "0", 1, false, 0); - buildVersion(VersionBuilder.create().setSnapshot(true).build(), "0-SNAPSHOT", 1, true, 0); - buildVersion(VersionBuilder.create("0").build(), "0", 1, false, 0); - buildVersion(VersionBuilder.create("1").build(), "1", 1, false, 1); - buildVersion(VersionBuilder.create("12.3").build(), "12.3", 2, false, 12, 3); - buildVersion(VersionBuilder.create("12.34-alpha-56").build(), "12.34-alpha-56", 4, false, 12, 34, "alpha", 56); - buildVersion(VersionBuilder.create("1.1-beta-1").build(), "1.1-beta-1", 4, false, 1, 1, "beta", 1); - buildVersion(VersionBuilder.create("1.1-rc-1").build(), "1.1-rc-1", 4, false, 1, 1, "rc", 1); - buildVersion(VersionBuilder.create("1.1-rc-1-SNAPSHOT").build(), "1.1-rc-1-SNAPSHOT", 4, true, 1, 1, "rc", 1); - buildVersion(VersionBuilder.create("1.1-rc2").build(), "1.1-rc2", 4, false, 1, 1, "rc", 2); - buildVersion(VersionBuilder.create("1.1-rc2a").build(), "1.1-rc2a", 5, false, 1, 1, "rc", 2, "a"); - - } - - @Test - public void testBuildVersionFromComponants() { - - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(0)).build(), "0", 1, false, 0); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1)).build(), "1", 1, false, 1); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(12, 3)).build(), "12.3", 2, false, 12, 3); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(12, 34, "alpha", 56)).build(), "12.34.alpha.56", 4, false, 12, 34, "alpha", 56); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "beta", 1)).build(), "1.1.beta.1", 4, false, 1, 1, "beta", 1); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 1)).build(), "1.1.rc.1", 4, false, 1, 1, "rc", 1); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 1)).setSnapshot(true).build(), "1.1.rc.1-SNAPSHOT", 4, true, 1, 1, "rc", 1); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 2)).build(), "1.1.rc.2", 4, false, 1, 1, "rc", 2); - buildVersion(VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1, "rc", 2, "a")).build(), "1.1.rc.2.a", 5, false, 1, 1, "rc", 2, "a"); - - } - - - protected void buildVersion(Version version, - String stringRepresentation, - int nbComponants, - boolean snapshot, - Comparable... componants) { - - Assert.assertEquals("Bad string represetion", stringRepresentation, version.getVersion()); - Assert.assertEquals("Bad number of componants", nbComponants, version.getComponantCount()); - Assert.assertEquals("Bad snapshot value", snapshot, version.isSnapshot()); - for (int i = 0; i < componants.length; i++) { - Comparable componant = componants[i]; - Assert.assertEquals("Bad componant value at index " + i, componant, version.getComponant(i).getValue()); - } - - } - -} diff --git a/src/test/java/org/nuiton/util/version/VersionComparatorTest.java b/src/test/java/org/nuiton/util/version/VersionComparatorTest.java deleted file mode 100644 index 1374a55..0000000 --- a/src/test/java/org/nuiton/util/version/VersionComparatorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.junit.Assert; -import org.junit.Test; - -/** - * Created on 7/11/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.0 - */ -@Deprecated -public class VersionComparatorTest { - - @Test - public void testCompareVersions() { - - VersionComparator comparator = new VersionComparator(); - - Version[] versions = new Version[]{ - VersionBuilder.create().setSnapshot(true).build(), - VersionBuilder.create().build(), - VersionBuilder.create("1").build(), - VersionBuilder.create("1.1-alpha-1").build(), - VersionBuilder.create("1.1-alpha-2").build(), - VersionBuilder.create("1.1-beta-1").build(), - VersionBuilder.create("1.1-rc-1-SNAPSHOT").build(), - VersionBuilder.create("1.1-rc-1").build(), - VersionBuilder.create("1.1-rc2").build(), - VersionBuilder.create("1.1").build(), - VersionBuilder.create("1.1.1").build(), - VersionBuilder.create("1.1.1-blablah").build(), - VersionBuilder.create("1.1.1-blablah1-SNAPSHOT").build(), - VersionBuilder.create("1.1.1-blablah1").build(), - VersionBuilder.create("1.1.1-blablah1a").build(), - VersionBuilder.create("1.1.1-blablah1b").build(), - VersionBuilder.create("2-rc-1").build(), - VersionBuilder.create("2").build(), - VersionBuilder.create("2-aa-1").build(), - }; - - for (int i = 0, l = versions.length - 1; i < l; i++) { - - Version v0 = versions[i]; - Version v1 = versions[i + 1]; - Assert.assertTrue(v0 + " < " + v1, comparator.compare(v0, v1) < 0); - - } - - } - -} diff --git a/src/test/java/org/nuiton/util/version/VersionTest.java b/src/test/java/org/nuiton/util/version/VersionTest.java deleted file mode 100644 index 4bfcbb7..0000000 --- a/src/test/java/org/nuiton/util/version/VersionTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.nuiton.util.version; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import org.junit.Assert; -import org.junit.Test; - -/** - * Created on 7/10/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.0 - */ -@Deprecated -public class VersionTest { - - @Test - public void testEquals() { - - // Ignore case on string componants - assertEquals(Versions.valueOf("1.1-rc"), Versions.valueOf("1.1-Rc")); - - // Ignore componants join separator - assertEquals(Versions.valueOf("1.1"), VersionBuilder.create(Lists.<Comparable>newArrayList(1, 1)).setJoinSeparator(' ').build()); - - } - - protected void buildVersion(Version version, - String stringRepresentation, - int nbComponants, - boolean snapshot, - Comparable... componants) { - - Assert.assertEquals("Bad string represetion", stringRepresentation, version.getVersion()); - Assert.assertEquals("Bad number of componants", nbComponants, version.getComponantCount()); - Assert.assertEquals("Bad snapshot value", snapshot, version.isSnapshot()); - for (int i = 0; i < componants.length; i++) { - Comparable componant = componants[i]; - Assert.assertEquals("Bad componant value at index " + i, componant, version.getComponant(i).getValue()); - } - - } - - protected void assertEquals(Version v1, Version v2) { - Assert.assertTrue(v1 + " equals to " + v2, v1.equals(v2)); - } - -} diff --git a/src/test/java/org/nuiton/util/version/VersionsTest.java b/src/test/java/org/nuiton/util/version/VersionsTest.java deleted file mode 100644 index a2f74c4..0000000 --- a/src/test/java/org/nuiton/util/version/VersionsTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.nuiton.util.version; - -import org.junit.Assert; -import org.junit.Test; - -/* - * #%L - * Nuiton Utils - * %% - * Copyright (C) 2014 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Test about {@link Versions} utility class. - * - * @author Eric Chatellier - */ -@Deprecated -public class VersionsTest { - - /** - * Test to create a new version by extracting a single component. - */ - @Test - public void testExtractSingleComponent() { - Version initVersion = Versions.valueOf("10.20.30.40"); - Version subVersion = Versions.extractVersion(initVersion, 2); - Assert.assertEquals(Versions.valueOf("30"), subVersion); - } - - /** - * Test to create a new version by extracting a components sub set. - */ - @Test - public void testExtractTwoComponents() { - Version initVersion = Versions.valueOf("10.20.30.40"); - Version subVersion = Versions.extractVersion(initVersion, 2, 3); - Assert.assertEquals(Versions.valueOf("30.40"), subVersion); - } - - /** - * Test to create a new version by extracting with illegal parameters. - */ - @Test(expected=IllegalArgumentException.class) - public void testExtractIllegalParams() { - Version initVersion = Versions.valueOf("10.20.30.40"); - Version subVersion = Versions.extractVersion(initVersion, 3, 2); - } - - @Test - public void testIncrements() { - - Version[] versions = new Version[]{ - VersionBuilder.create().setSnapshot(true).build(), - VersionBuilder.create().build(), - Versions.valueOf("1"), - Versions.valueOf("1.1-alpha-1"), - Versions.valueOf("1.1-alpha-2"), - Versions.valueOf("1.1-beta-1"), - Versions.valueOf("1.1-rc-1-SNAPSHOT"), - Versions.valueOf("1.1-rc-1"), - Versions.valueOf("1.1-rc2"), - Versions.valueOf("1.1"), - Versions.valueOf("1.1.1"), - Versions.valueOf("1.1.1-blablah"), - Versions.valueOf("1.1.1-blablah1-SNAPSHOT"), - Versions.valueOf("1.1.1-blablah1"), - Versions.valueOf("1.1.1-blablah1a"), - Versions.valueOf("1.1.1-blablah1b") - }; - - Version[] versionsIncrements = new Version[]{ - Versions.valueOf("1-SNAPSHOT"), - Versions.valueOf("1"), - Versions.valueOf("2"), - Versions.valueOf("1.1-alpha-2"), - Versions.valueOf("1.1-alpha-3"), - Versions.valueOf("1.1-beta-2"), - Versions.valueOf("1.1-rc-2-SNAPSHOT"), - Versions.valueOf("1.1-rc-2"), - Versions.valueOf("1.1-rc3"), - Versions.valueOf("1.2"), - Versions.valueOf("1.1.2"), - Versions.valueOf("1.1.1-blablah.1"), - Versions.valueOf("1.1.1-blablah2-SNAPSHOT"), - Versions.valueOf("1.1.1-blablah2"), - Versions.valueOf("1.1.1-blablah1a.1"), - Versions.valueOf("1.1.1-blablah1b.1") - }; - - for (int i = 0, l = versions.length; i < l; i++) { - - Version v = versions[i]; - Version vIncrements = versionsIncrements[i]; - Version increments = Versions.increments(v); - Assert.assertTrue(v + " + 1 = " + increments + " should be " + vIncrements, increments.equals(vIncrements)); - Assert.assertTrue(v + " + 1 = " + increments + " should be " + vIncrements, increments.getVersion().equals(vIncrements.getVersion())); - - } - - } -} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm