Author: shawkins
Date: 2010-08-31 14:26:04 -0400 (Tue, 31 Aug 2010)
New Revision: 2510
Modified:
branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
branches/7.1.x/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
Log:
TEIID-1233 fix for version detection
Modified: branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
---
branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2010-08-31
18:24:00 UTC (rev 2509)
+++
branches/7.1.x/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2010-08-31
18:26:04 UTC (rev 2510)
@@ -182,11 +182,11 @@
if (path.endsWith("/")) { //$NON-NLS-1$
path = path.substring(0, path.length() - 1);
}
- String fileName = FileUtils.getBaseFileNameWithoutExtension(path);
- String prefix = getName() + VERSION_DELIM;
- if (StringUtil.startsWithIgnoreCase(fileName, prefix)) {
+ String fileName = StringUtil.getLastToken(path, "/"); //$NON-NLS-1$
+ String[] parts = fileName.split("\\."); //$NON-NLS-1$
+ if (parts[0].equalsIgnoreCase(getName()) && parts.length >= 3) {
try {
- int fileVersion = Integer.parseInt(fileName.substring(prefix.length()));
+ int fileVersion = Integer.parseInt(parts[parts.length - 2]);
this.setVersion(fileVersion);
} catch (NumberFormatException e) {
Modified:
branches/7.1.x/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
---
branches/7.1.x/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-08-31
18:24:00 UTC (rev 2509)
+++
branches/7.1.x/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-08-31
18:26:04 UTC (rev 2510)
@@ -29,6 +29,8 @@
import java.io.StringReader;
import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -192,4 +194,11 @@
assertEquals("http://teiid.org/myvdb.vdb", vdb.getUrl());
}
+
+ @Test public void testSetUrlVersion() throws MalformedURLException {
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("foo");
+ vdb.setUrl(new URL("file:///x/foo.2.vdb"));
+ assertEquals(2, vdb.getVersion());
+ }
}