diff --git a/.classpath b/.classpath index 251fd2f..1d327b6 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,10 @@ - - - - - - + + + + + + + + + + diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..344d0e0 --- /dev/null +++ b/build.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/Achievements.jar b/lib/Achievements.jar new file mode 100644 index 0000000..0d5caa8 Binary files /dev/null and b/lib/Achievements.jar differ diff --git a/lib/EssentialsGroupManager.jar b/lib/EssentialsGroupManager.jar new file mode 100644 index 0000000..c852822 Binary files /dev/null and b/lib/EssentialsGroupManager.jar differ diff --git a/lib/Permissions.jar b/lib/Permissions.jar new file mode 100644 index 0000000..c0fe57c Binary files /dev/null and b/lib/Permissions.jar differ diff --git a/lib/craftbukkit-0.0.1-SNAPSHOT.jar b/lib/craftbukkit-0.0.1-SNAPSHOT.jar new file mode 100644 index 0000000..5e0ccde Binary files /dev/null and b/lib/craftbukkit-0.0.1-SNAPSHOT.jar differ diff --git a/src/plugin.yml b/resources/plugin.yml similarity index 77% rename from src/plugin.yml rename to resources/plugin.yml index b18574f..6201432 100644 --- a/src/plugin.yml +++ b/resources/plugin.yml @@ -1,7 +1,7 @@ -name: Stats -main: com.nidefawl.Stats.Stats -version: 0.99 -author: nidefawl +name: @NAME@ +main: com.@AUTHOR@.@NAME@.@NAME@ +version: @VERSION@ +author: @AUTHOR@ commands: stats: description: Stats command diff --git a/src/com/nidefawl/Stats/ItemResolver/hModItemResolver.java b/src/com/nidefawl/Stats/ItemResolver/hModItemResolver.java index 6a3beca..fc5aac4 100644 --- a/src/com/nidefawl/Stats/ItemResolver/hModItemResolver.java +++ b/src/com/nidefawl/Stats/ItemResolver/hModItemResolver.java @@ -64,7 +64,6 @@ public class hModItemResolver implements itemResolver { writer.write("dispenser:23\r\n"); writer.write("sandstone:24\r\n"); writer.write("musicblock:25\r\n"); - writer.write("noteblock:25\r\n"); writer.write("bedblock:26\r\n"); writer.write("wool:35\r\n"); writer.write("cloth:35\r\n"); @@ -141,6 +140,32 @@ public class hModItemResolver implements itemResolver { writer.write("cakeblock:92\r\n"); writer.write("repeateron:93\r\n"); writer.write("repeateroff:94\r\n"); + writer.write("lockedchest:95\r\n"); + writer.write("trapdoor:96\r\n"); + writer.write("hiddensilverfish:97\r\n"); + writer.write("stonebricks:98\r\n"); + writer.write("hugebrownmushroom:99\r\n"); + writer.write("hugeredmushroom:100\r\n"); + writer.write("ironbars:101\r\n"); + writer.write("glasspane:102\r\n"); + writer.write("melon:103\r\n"); + writer.write("pumpkinstem:104\r\n"); + writer.write("melonstem:105\r\n"); + writer.write("vines:106\r\n"); + writer.write("fencegate:107\r\n"); + writer.write("brickstairs:108\r\n"); + writer.write("stonebrickstairs:109\r\n"); + writer.write("mycelium:110\r\n"); + writer.write("lilypad:111\r\n"); + writer.write("netherbrick:112\r\n"); + writer.write("netherbrickfence:113\r\n"); + writer.write("netherbrickstairs:114\r\n"); + writer.write("netherwartblock:115\r\n"); + writer.write("enchantmenttable:116\r\n"); + writer.write("brewingstandblock:117\r\n"); + writer.write("cauldronblock:118\r\n"); + writer.write("airportal:119\r\n"); + writer.write("airportalframe:120\r\n"); writer.write("ironshovel:256\r\n"); writer.write("ironspade:256\r\n"); writer.write("ironpickaxe:257\r\n"); @@ -260,6 +285,31 @@ public class hModItemResolver implements itemResolver { writer.write("cake:354\r\n"); writer.write("bed:355\r\n"); writer.write("repeater:356\r\n"); + writer.write("cookie:357\r\n"); + writer.write("map:358\r\n"); + writer.write("shears:359\r\n"); + writer.write("melonslice:360\r\n"); + writer.write("pumpkinseeds:361\r\n"); + writer.write("melonseeds:362\r\n"); + writer.write("rawbeef:363\r\n"); + writer.write("steak:364\r\n"); + writer.write("rawchicken:365\r\n"); + writer.write("cookedchicken:366\r\n"); + writer.write("rottenflesh:367\r\n"); + writer.write("enderpearl:368\r\n"); + writer.write("blazerod:369\r\n"); + writer.write("ghasttear:370\r\n"); + writer.write("goldnugget:371\r\n"); + writer.write("netherwart:372\r\n"); + writer.write("potion:373\r\n"); + writer.write("glassbottle:374\r\n"); + writer.write("spidereye:375\r\n"); + writer.write("fermentedspidereye:376\r\n"); + writer.write("blazepowder:377\r\n"); + writer.write("magmacream:378\r\n"); + writer.write("brewingstand:379\r\n"); + writer.write("cauldron:380\r\n"); + writer.write("eyeofender:381\r\n"); writer.write("goldrecord:2256\r\n"); writer.write("greenrecord:2257\r\n"); } catch (Exception e) { diff --git a/src/com/nidefawl/Stats/Permissions/BukkitPermissionsResolver.java b/src/com/nidefawl/Stats/Permissions/BukkitPermissionsResolver.java new file mode 100644 index 0000000..439ac2c --- /dev/null +++ b/src/com/nidefawl/Stats/Permissions/BukkitPermissionsResolver.java @@ -0,0 +1,60 @@ +/** + * + */ +package com.nidefawl.Stats.Permissions; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +/** + * @author socrates + * + */ +public class BukkitPermissionsResolver implements PermissionsResolver { + + /* (non-Javadoc) + * @see com.nidefawl.Stats.Permissions.PermissionsResolver#load() + */ + @Override + public boolean load() { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see com.nidefawl.Stats.Permissions.PermissionsResolver#permission(org.bukkit.command.CommandSender, java.lang.String) + */ + @Override + public boolean permission(CommandSender player, String permCmd) { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see com.nidefawl.Stats.Permissions.PermissionsResolver#getGroup(org.bukkit.entity.Player) + */ + @Override + public String getGroup(Player player) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.nidefawl.Stats.Permissions.PermissionsResolver#inGroup(org.bukkit.entity.Player, java.lang.String) + */ + @Override + public boolean inGroup(Player player, String group) { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see com.nidefawl.Stats.Permissions.PermissionsResolver#reloadPerms() + */ + @Override + public void reloadPerms() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/com/nidefawl/Stats/Stats.java b/src/com/nidefawl/Stats/Stats.java index 0004e0f..de52dab 100644 --- a/src/com/nidefawl/Stats/Stats.java +++ b/src/com/nidefawl/Stats/Stats.java @@ -41,8 +41,8 @@ import com.nidefawl.Stats.util.Updater; public class Stats extends JavaPlugin { public final static Logger log = Logger.getLogger("Minecraft"); - public final static double version = 0.99; - public final static String logprefix = "[Stats-" + version + "]"; + public static final String version = "0.99.1"; + public static final String logprefix = "[Stats-" + version + "]"; public final static String defaultCategory = "stats"; public boolean enabled = false; public boolean updated = false; @@ -80,7 +80,7 @@ public class Stats extends JavaPlugin { perms.reloadPerms(); } } - + public static void LogError(String Message) { log.log(Level.SEVERE, logprefix + " " + Message); } @@ -414,6 +414,7 @@ public class Stats extends JavaPlugin { } public void onEnable() { + getDataFolder().mkdirs(); File statsDirectory = new File("stats"); if (statsDirectory.exists() && statsDirectory.isDirectory()) { diff --git a/src/com/nidefawl/Stats/util/UpdaterFile.java b/src/com/nidefawl/Stats/util/UpdaterFile.java index 8d0ea4a..92a85f8 100644 --- a/src/com/nidefawl/Stats/util/UpdaterFile.java +++ b/src/com/nidefawl/Stats/util/UpdaterFile.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import com.nidefawl.Stats.Stats; @@ -37,15 +38,27 @@ public class UpdaterFile { * The local url location */ private String localLocation; - private double localVersion; - private double remoteVersion; + private String localVersion; + private String remoteVersion; - public UpdaterFile(String remoteLocation, String localLocation, double localVersion, double remoteVersion) { + public UpdaterFile(String remoteLocation, String localLocation, String localVersion, String remoteVersion) { this.remoteLocation = remoteLocation; this.localLocation = localLocation; this.localVersion = localVersion; this.remoteVersion = remoteVersion; } + + public UpdaterFile(String remoteLocation, String localLocation, double localVersion, double remoteVersion){ + this(remoteLocation, localLocation, String.valueOf(localVersion), String.valueOf(remoteVersion)); + } + + public UpdaterFile(String remoteLocation, String localLocation, String localVersion, double remoteVersion){ + this(remoteLocation, localLocation, localVersion, String.valueOf(remoteVersion)); + } + + public UpdaterFile(String remoteLocation, String localLocation, double localVersion, String remoteVersion){ + this(remoteLocation, localLocation, String.valueOf(localVersion), remoteVersion); + } /** * @return the local file location @@ -89,7 +102,10 @@ public class UpdaterFile { } public boolean update(boolean autoUpdate) throws Exception { - if (remoteVersion > localVersion) { + DefaultArtifactVersion remoteVersion = new DefaultArtifactVersion(String.valueOf(this.remoteVersion)); + DefaultArtifactVersion localVersion = new DefaultArtifactVersion(this.localVersion); + + if (localVersion.compareTo(remoteVersion) < 0) { if (autoUpdate) { try { Stats.LogInfo("Newer version of "+localLocation+" found. local: "+localVersion+" remote: "+remoteVersion); diff --git a/src/org/apache/maven/artifact/versioning/ArtifactVersion.java b/src/org/apache/maven/artifact/versioning/ArtifactVersion.java new file mode 100644 index 0000000..9098c3a --- /dev/null +++ b/src/org/apache/maven/artifact/versioning/ArtifactVersion.java @@ -0,0 +1,43 @@ +package org.apache.maven.artifact.versioning; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Describes an artifact version in terms of its components, converts it to/from a string and + * compares two versions. + * + * @author Brett Porter + * @version $Id: ArtifactVersion.java 828793 2009-10-22 17:34:20Z bentmann $ + */ +public interface ArtifactVersion + extends Comparable +{ + int getMajorVersion(); + + int getMinorVersion(); + + int getIncrementalVersion(); + + int getBuildNumber(); + + String getQualifier(); + + void parseVersion( String version ); +} diff --git a/src/org/apache/maven/artifact/versioning/ComparableVersion.java b/src/org/apache/maven/artifact/versioning/ComparableVersion.java new file mode 100644 index 0000000..41c43bd --- /dev/null +++ b/src/org/apache/maven/artifact/versioning/ComparableVersion.java @@ -0,0 +1,466 @@ +package org.apache.maven.artifact.versioning; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Locale; +import java.util.Properties; +import java.util.Stack; + +/** + * Generic implementation of version comparison. Features: + * + * + * @see "Versioning" on Maven Wiki + * @author Kenney Westerhof + * @author Hervé Boutemy + * @version $Id: ComparableVersion.java 958295 2010-06-26 23:16:18Z hboutemy $ + */ +public class ComparableVersion + implements Comparable +{ + private String value; + + private String canonical; + + private ListItem items; + + private interface Item + { + final int INTEGER_ITEM = 0; + final int STRING_ITEM = 1; + final int LIST_ITEM = 2; + + int compareTo( Item item ); + + int getType(); + + boolean isNull(); + } + + /** + * Represents a numeric item in the version item list. + */ + private static class IntegerItem + implements Item + { + private static final BigInteger BigInteger_ZERO = new BigInteger( "0" ); + + private final BigInteger value; + + public static final IntegerItem ZERO = new IntegerItem(); + + private IntegerItem() + { + this.value = BigInteger_ZERO; + } + + public IntegerItem( String str ) + { + this.value = new BigInteger( str ); + } + + public int getType() + { + return INTEGER_ITEM; + } + + public boolean isNull() + { + return BigInteger_ZERO.equals( value ); + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + return BigInteger_ZERO.equals( value ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + } + + switch ( item.getType() ) + { + case INTEGER_ITEM: + return value.compareTo( ( (IntegerItem) item ).value ); + + case STRING_ITEM: + return 1; // 1.1 > 1-sp + + case LIST_ITEM: + return 1; // 1.1 > 1-1 + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + return value.toString(); + } + } + + /** + * Represents a string in the version item list, usually a qualifier. + */ + private static class StringItem + implements Item + { + private static final String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" }; + + private static final List _QUALIFIERS = Arrays.asList( QUALIFIERS ); + + private static final Properties ALIASES = new Properties(); + static + { + ALIASES.put( "ga", "" ); + ALIASES.put( "final", "" ); + ALIASES.put( "cr", "rc" ); + } + + /** + * A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes + * the version older than one without a qualifier, or more recent. + */ + private static final String RELEASE_VERSION_INDEX = String.valueOf( _QUALIFIERS.indexOf( "" ) ); + + private String value; + + public StringItem( String value, boolean followedByDigit ) + { + if ( followedByDigit && value.length() == 1 ) + { + // a1 = alpha-1, b1 = beta-1, m1 = milestone-1 + switch ( value.charAt( 0 ) ) + { + case 'a': + value = "alpha"; + break; + case 'b': + value = "beta"; + break; + case 'm': + value = "milestone"; + break; + } + } + this.value = ALIASES.getProperty( value , value ); + } + + public int getType() + { + return STRING_ITEM; + } + + public boolean isNull() + { + return ( comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ) == 0 ); + } + + /** + * Returns a comparable value for a qualifier. + * + * This method both takes into account the ordering of known qualifiers as well as lexical ordering for unknown + * qualifiers. + * + * just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1 + * or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character, + * so this is still fast. If more characters are needed then it requires a lexical sort anyway. + * + * @param qualifier + * @return an equivalent value that can be used with lexical comparison + */ + public static String comparableQualifier( String qualifier ) + { + int i = _QUALIFIERS.indexOf( qualifier ); + + return i == -1 ? _QUALIFIERS.size() + "-" + qualifier : String.valueOf( i ); + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + // 1-rc < 1, 1-ga > 1 + return comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ); + } + switch ( item.getType() ) + { + case INTEGER_ITEM: + return -1; // 1.any < 1.1 ? + + case STRING_ITEM: + return comparableQualifier( value ).compareTo( comparableQualifier( ( (StringItem) item ).value ) ); + + case LIST_ITEM: + return -1; // 1.any < 1-1 + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + return value; + } + } + + /** + * Represents a version list item. This class is used both for the global item list and for sub-lists (which start + * with '-(number)' in the version specification). + */ + private static class ListItem + extends ArrayList + implements Item + { + public int getType() + { + return LIST_ITEM; + } + + public boolean isNull() + { + return ( size() == 0 ); + } + + void normalize() + { + for( ListIterator iterator = listIterator( size() ); iterator.hasPrevious(); ) + { + Item item = iterator.previous(); + if ( item.isNull() ) + { + iterator.remove(); // remove null trailing items: 0, "", empty list + } + else + { + break; + } + } + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + if ( size() == 0 ) + { + return 0; // 1-0 = 1- (normalize) = 1 + } + Item first = get( 0 ); + return first.compareTo( null ); + } + switch ( item.getType() ) + { + case INTEGER_ITEM: + return -1; // 1-1 < 1.0.x + + case STRING_ITEM: + return 1; // 1-1 > 1-sp + + case LIST_ITEM: + Iterator left = iterator(); + Iterator right = ( (ListItem) item ).iterator(); + + while ( left.hasNext() || right.hasNext() ) + { + Item l = left.hasNext() ? left.next() : null; + Item r = right.hasNext() ? right.next() : null; + + // if this is shorter, then invert the compare and mul with -1 + int result = l == null ? -1 * r.compareTo( l ) : l.compareTo( r ); + + if ( result != 0 ) + { + return result; + } + } + + return 0; + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + StringBuilder buffer = new StringBuilder( "(" ); + for( Iterator iter = iterator(); iter.hasNext(); ) + { + buffer.append( iter.next() ); + if ( iter.hasNext() ) + { + buffer.append( ',' ); + } + } + buffer.append( ')' ); + return buffer.toString(); + } + } + + public ComparableVersion( String version ) + { + parseVersion( version ); + } + + public final void parseVersion( String version ) + { + this.value = version; + + items = new ListItem(); + + version = version.toLowerCase( Locale.ENGLISH ); + + ListItem list = items; + + Stack stack = new Stack(); + stack.push( list ); + + boolean isDigit = false; + + int startIndex = 0; + + for ( int i = 0; i < version.length(); i++ ) + { + char c = version.charAt( i ); + + if ( c == '.' ) + { + if ( i == startIndex ) + { + list.add( IntegerItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + } + else if ( c == '-' ) + { + if ( i == startIndex ) + { + list.add( IntegerItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + + if ( isDigit ) + { + list.normalize(); // 1.0-* = 1-* + + if ( ( i + 1 < version.length() ) && Character.isDigit( version.charAt( i + 1 ) ) ) + { + // new ListItem only if previous were digits and new char is a digit, + // ie need to differentiate only 1.1 from 1-1 + list.add( list = new ListItem() ); + + stack.push( list ); + } + } + } + else if ( Character.isDigit( c ) ) + { + if ( !isDigit && i > startIndex ) + { + list.add( new StringItem( version.substring( startIndex, i ), true ) ); + startIndex = i; + } + + isDigit = true; + } + else + { + if ( isDigit && i > startIndex ) + { + list.add( parseItem( true, version.substring( startIndex, i ) ) ); + startIndex = i; + } + + isDigit = false; + } + } + + if ( version.length() > startIndex ) + { + list.add( parseItem( isDigit, version.substring( startIndex ) ) ); + } + + while ( !stack.isEmpty() ) + { + list = (ListItem) stack.pop(); + list.normalize(); + } + + canonical = items.toString(); + } + + private static Item parseItem( boolean isDigit, String buf ) + { + return isDigit ? new IntegerItem( buf ) : new StringItem( buf, false ); + } + + public int compareTo( ComparableVersion o ) + { + return items.compareTo( o.items ); + } + + public String toString() + { + return value; + } + + public boolean equals( Object o ) + { + return ( o instanceof ComparableVersion ) && canonical.equals( ( (ComparableVersion) o ).canonical ); + } + + public int hashCode() + { + return canonical.hashCode(); + } +} diff --git a/src/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java b/src/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java new file mode 100644 index 0000000..c4038d2 --- /dev/null +++ b/src/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java @@ -0,0 +1,241 @@ +package org.apache.maven.artifact.versioning; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.StringTokenizer; + +/** + * Default implementation of artifact versioning. + * + * @author Brett Porter + * @version $Id: DefaultArtifactVersion.java 828793 2009-10-22 17:34:20Z bentmann $ + */ +public class DefaultArtifactVersion + implements ArtifactVersion +{ + private Integer majorVersion; + + private Integer minorVersion; + + private Integer incrementalVersion; + + private Integer buildNumber; + + private String qualifier; + + private ComparableVersion comparable; + + public DefaultArtifactVersion( String version ) + { + parseVersion( version ); + } + + @Override + public int hashCode() + { + return 11 + comparable.hashCode(); + } + + @Override + public boolean equals( Object other ) + { + if ( this == other ) + { + return true; + } + + if ( !( other instanceof ArtifactVersion ) ) + { + return false; + } + + return compareTo( other ) == 0; + } + + public int compareTo( Object o ) + { + DefaultArtifactVersion otherVersion = (DefaultArtifactVersion) o; + return this.comparable.compareTo( otherVersion.comparable ); + } + + public int getMajorVersion() + { + return majorVersion != null ? majorVersion : 0; + } + + public int getMinorVersion() + { + return minorVersion != null ? minorVersion : 0; + } + + public int getIncrementalVersion() + { + return incrementalVersion != null ? incrementalVersion : 0; + } + + public int getBuildNumber() + { + return buildNumber != null ? buildNumber : 0; + } + + public String getQualifier() + { + return qualifier; + } + + public final void parseVersion( String version ) + { + comparable = new ComparableVersion( version ); + + int index = version.indexOf( "-" ); + + String part1; + String part2 = null; + + if ( index < 0 ) + { + part1 = version; + } + else + { + part1 = version.substring( 0, index ); + part2 = version.substring( index + 1 ); + } + + if ( part2 != null ) + { + try + { + if ( ( part2.length() == 1 ) || !part2.startsWith( "0" ) ) + { + buildNumber = Integer.valueOf( part2 ); + } + else + { + qualifier = part2; + } + } + catch ( NumberFormatException e ) + { + qualifier = part2; + } + } + + if ( ( part1.indexOf( "." ) < 0 ) && !part1.startsWith( "0" ) ) + { + try + { + majorVersion = Integer.valueOf( part1 ); + } + catch ( NumberFormatException e ) + { + // qualifier is the whole version, including "-" + qualifier = version; + buildNumber = null; + } + } + else + { + boolean fallback = false; + + StringTokenizer tok = new StringTokenizer( part1, "." ); + try + { + majorVersion = getNextIntegerToken( tok ); + if ( tok.hasMoreTokens() ) + { + minorVersion = getNextIntegerToken( tok ); + } + if ( tok.hasMoreTokens() ) + { + incrementalVersion = getNextIntegerToken( tok ); + } + if ( tok.hasMoreTokens() ) + { + fallback = true; + } + + // string tokenzier won't detect these and ignores them + if ( part1.indexOf( ".." ) >= 0 || part1.startsWith( "." ) || part1.endsWith( "." ) ) + { + fallback = true; + } + } + catch ( NumberFormatException e ) + { + fallback = true; + } + + if ( fallback ) + { + // qualifier is the whole version, including "-" + qualifier = version; + majorVersion = null; + minorVersion = null; + incrementalVersion = null; + buildNumber = null; + } + } + } + + private static Integer getNextIntegerToken( StringTokenizer tok ) + { + String s = tok.nextToken(); + if ( ( s.length() > 1 ) && s.startsWith( "0" ) ) + { + throw new NumberFormatException( "Number part has a leading 0: '" + s + "'" ); + } + return Integer.valueOf( s ); + } + + @Override + public String toString() + { + StringBuilder buf = new StringBuilder(); + if ( majorVersion != null ) + { + buf.append( majorVersion ); + } + if ( minorVersion != null ) + { + buf.append( "." ); + buf.append( minorVersion ); + } + if ( incrementalVersion != null ) + { + buf.append( "." ); + buf.append( incrementalVersion ); + } + if ( buildNumber != null ) + { + buf.append( "-" ); + buf.append( buildNumber ); + } + else if ( qualifier != null ) + { + if ( buf.length() > 0 ) + { + buf.append( "-" ); + } + buf.append( qualifier ); + } + return buf.toString(); + } +} \ No newline at end of file