Author: ozizka(a)redhat.com
Date: 2009-11-11 13:06:00 -0500 (Wed, 11 Nov 2009)
New Revision: 854
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java
Log:
* Version comparison finished.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java 2009-11-11
17:05:38 UTC (rev 853)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EjtsSelfTest.java 2009-11-11
18:06:00 UTC (rev 854)
@@ -22,12 +22,15 @@
*/
public class EjtsSelfTest extends ServletTestCase {
+ public static void main( String[] args ){
+ new EjtsSelfTest().testVersionComparison();
+ }
+
private static final Logger log = Logger.getLogger( EjtsSelfTest.class.getName() );
/** */
- public void testEnvironmentInfo() throws EmbJoprTestException, Exception {
+ public void XtestEnvironmentInfo() throws EmbJoprTestException, Exception {
-
EjtsEnvironmentInfo eei = EjtsEnvironmentInfo.createFromLocalServer();
log.info( eei.toString() );
@@ -42,8 +45,12 @@
log.info("Manifest loaded: ");
logManifest( new Manifest( is ) );
+ }
+
+
+
+ public void testVersionComparison(){
-
boolean succ = true;
succ &= doCompareVersions("2.3.0.GA", "2.4.0-SNAPSHOT", -1);
succ &= doCompareVersions("2.4.0.GA", "2.4.0-SNAPSHOT", 1);
@@ -61,7 +68,7 @@
private boolean doCompareVersions( String v1, String v2, int expectedSignum ){
int compared = EjtsEnvironmentInfo.compareVersions(v1, v2);
- log.info( String.format("Comparing versions: %s and %s produces: %d,
expected: %d", v1, v2, compared, expectedSignum ) );
+ log.info( String.format("Comparing versions: %s and %s produces: %d,
expected: %d\n", v1, v2, compared, expectedSignum ) );
return Integer.signum(expectedSignum) == Integer.signum( compared );
}
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java 2009-11-11
17:05:38 UTC (rev 853)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EjtsEnvironmentInfo.java 2009-11-11
18:06:00 UTC (rev 854)
@@ -24,7 +24,6 @@
import java.util.jar.Manifest;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.jboss.jopr.jsfunit.JMXUtils;
import org.jboss.logging.Logger;
@@ -171,17 +170,20 @@
*/
public static int compareVersions(String aStr, String bStr){
- //*
+ log.info( String.format(" ----- Comparing versions: %s and %s ... ------
", aStr, bStr) );
+
final String[] aParts = StringUtils.split(aStr.toUpperCase(), ".-_");
final String[] bParts = StringUtils.split(bStr.toUpperCase(), ".-_");
+ log.info( String.format(" aLen = %d, bLen = %d", aParts.length,
bParts.length) );
+
int aOff = 0;
int bOff = 0;
//int longer = 0;
//for( int i = v1parts.length-1; i >= 0; i--){ }
- do {
+ parts: do {
String a = aParts[aOff];
String b = bParts[bOff];
@@ -197,20 +199,18 @@
boolean aIsLast = aOff >= aParts.length - 1;
boolean bIsLast = bOff >= bParts.length - 1;
-
log.debug( String.format("A[%d] = '%s', B[%d] = '%s'", aOff,
a, bOff, b) );
- evaluation: {
+ thisPart: do {
+
if( aIsNum && bIsNum ){
log.debug("aIsNum && bIsNum");
int diff = aNum - bNum;
// Different numbers - return the diff.
if( diff != 0 ) return diff;
// The same numbers - skip to next position.
- if( !aIsLast ) aOff++;
- if( !bIsLast ) bOff++;
- continue;
+ break thisPart;
}
else if( aIsNum ^ bIsNum ){
@@ -218,21 +218,18 @@
if( aIsNum ){
// Skip aditional "decimal" zeros - e.g. 2.0.0.FOO vs. 2.0.BAR .
if ( aNum == 0 ){
- if( ! aIsLast ){ aOff++; continue; }
+ if( ! aIsLast ){ aOff++; continue parts; }
return compareStrings("0", b); // or: +getStringLevel(a);
}
- // 2.0.0.1 vs. 2.0.0.SNAPSHOT
return 1;
}
else /* vice versa for ( bIsNum ) */ {
// Skip aditional "decimal" zeros - e.g. 2.0.0.FOO vs. 2.0.BAR .
if ( bNum == 0 ){
- if( ! bIsLast ){ bOff++; continue; }
+ if( ! bIsLast ){ bOff++; continue parts; }
return compareStrings(a, "0"); // or: -getStringLevel(b);
}
- // 2.0.0.1 vs. 2.0.0.SNAPSHOT
- // 2.0.0.1 vs. 2.0.0.SP2
return -1;
}
}
@@ -252,15 +249,21 @@
return strDiff;
}
- }// label evaluation:
+ } while( false ); // label thisPart:
// Advance to the next part, unless we're at the last one..
- if( aOff < aParts.length -1 ) aOff++;
- if( bOff < bParts.length -1 ) bOff++;
+ //if( aOff < aParts.length -1 ) aOff++;
+ //if( bOff < bParts.length -1 ) bOff++;
+ log.debug( String.format("Incrementing... %s %s", aIsLast, bIsLast) );
+ if( ! aIsLast ) aOff++;
+ if( ! bIsLast ) bOff++;
+ if( aIsLast && bIsLast ) break;
+
// End when we reached the last parts of both versions.
- } while( aOff < aParts.length || bOff < bParts.length );
+ } while ( true );
+ //} while( aOff < aParts.length -1 || bOff < bParts.length -1 );
log.debug("Reached comparison loop end.");
@@ -273,7 +276,39 @@
return v1.compareTo(v2);
/**/
+ }// compareVersions();
+
+
+
+
+
+
+ public static void main( String[] arge ){
+
+ boolean succ = true;
+ succ &= doCompareVersions("2.3.0.GA", "2.4.0-SNAPSHOT", -1);
+ succ &= doCompareVersions("2.4.0.GA", "2.4.0-SNAPSHOT", 1);
+ succ &= doCompareVersions("2.4.1.GA", "2.4.0-SNAPSHOT", 1);
+ succ &= doCompareVersions("2.4.1", "2.4.0-SNAPSHOT", 1);
+ succ &= doCompareVersions("2.4.0", "2.4.0-SNAPSHOT", 1);
+ succ &= doCompareVersions("2.4.0", "2.4.0.GA", 0);
+ succ &= doCompareVersions("2.4.0.CR1", "2.4.0.GA", -1);
+ succ &= doCompareVersions("2.4.CR1", "2.4.0.GA", -1);
+ succ &= doCompareVersions("2.4.CR1", "2.4.0", -1);
+ succ &= doCompareVersions("2.0.0.0", "2.0.0.SNAPSHOT", 1);
+ succ &= doCompareVersions("2.0.0.1", "2.0.0.SNAPSHOT", -1);
+ succ &= doCompareVersions("2.0.0.1", "2.0.0.SP2", 1);
+ succ &= doCompareVersions("2.0.0.1", "2.0.SP2", 1);
+
}
+
+ private static boolean doCompareVersions( String v1, String v2, int expectedSignum ){
+ int compared = EjtsEnvironmentInfo.compareVersions(v1, v2);
+ log.info( String.format("Comparing versions: %s and %s produces: %d,
expected: %d\n", v1, v2, compared, expectedSignum ) );
+ return Integer.signum(expectedSignum) == Integer.signum( compared );
+ }
+
+
}// class