Improve GeoServer version handling.
This commit is contained in:
parent
a7d3efc6f7
commit
631f3a9ffa
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||
* Copyright (C) 2007,2015 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -147,12 +147,22 @@ public class GSVersionDecoder extends XmlElement {
|
||||
}
|
||||
|
||||
public enum VERSION {
|
||||
UNRECOGNIZED(-1), v22(22), v23(23), v24(24), v25(25), ABOVE(9999);
|
||||
v22(22, "2\\.2([^0-9]|$).*"),
|
||||
v23(23, "2\\.3([^0-9]|$).*"),
|
||||
v24(24, "2\\.4([^0-9]|$).*"),
|
||||
v25(25, "2\\.5([^0-9]|$).*"),
|
||||
v26(26, "2\\.6([^0-9]|$).*"),
|
||||
v27(27, "2\\.7([^0-9]|$).*"),
|
||||
v28(28, "2\\.8([^0-9]|$).*"),
|
||||
ABOVE(9999, "2\\..+"),
|
||||
UNRECOGNIZED(-1, null);
|
||||
|
||||
final private int version;
|
||||
final private String pattern;
|
||||
|
||||
private VERSION(int val) {
|
||||
private VERSION(int val, String pattern) {
|
||||
version = val;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
@ -164,25 +174,27 @@ public class GSVersionDecoder extends XmlElement {
|
||||
}
|
||||
|
||||
public static VERSION getVersion(String v) {
|
||||
if (v==null) {
|
||||
return UNRECOGNIZED;
|
||||
} else if (v.matches("2\\.2.*")) {
|
||||
return v22;
|
||||
} else if (v.matches("2\\.3.*")) {
|
||||
return v23;
|
||||
} else if (v.matches("2\\.4.*")) {
|
||||
return v24;
|
||||
} else if (v.matches("2\\.5.*")) {
|
||||
return v25;
|
||||
} else if (v.matches("2\\..+")) {
|
||||
return ABOVE;
|
||||
} else {
|
||||
if (v == null) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
|
||||
for (VERSION version : VERSION.values()) {
|
||||
if(version.pattern != null && v.matches(version.pattern)) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
|
||||
public static String print(){
|
||||
return "["+v22+", "+v23+", "+v24+", "+v25+", "+ABOVE+", "+UNRECOGNIZED+"]";
|
||||
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
for (VERSION v : VERSION.values()) {
|
||||
sb.append(v.toString()).append(' ');
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2015 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package it.geosolutions.geoserver.rest.decoder.about;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author etj <etj at geo-solutions dot it>
|
||||
*/
|
||||
public class GSVersionDecoderTest {
|
||||
|
||||
@Test
|
||||
public void testGetGeoServer() {
|
||||
|
||||
assertEquals(GSVersionDecoder.VERSION.v22, GSVersionDecoder.VERSION.getVersion("2.2"));
|
||||
assertEquals(GSVersionDecoder.VERSION.v22, GSVersionDecoder.VERSION.getVersion("2.2-SNAPSHOT"));
|
||||
|
||||
assertEquals(GSVersionDecoder.VERSION.v26, GSVersionDecoder.VERSION.getVersion("2.6"));
|
||||
assertEquals(GSVersionDecoder.VERSION.v26, GSVersionDecoder.VERSION.getVersion("2.6-SNAPSHOT"));
|
||||
assertEquals(GSVersionDecoder.VERSION.v26, GSVersionDecoder.VERSION.getVersion("2.6-ENTERPRISE"));
|
||||
assertEquals(GSVersionDecoder.VERSION.v26, GSVersionDecoder.VERSION.getVersion("2.6-ENTERPRISE-SNAPSHOT"));
|
||||
|
||||
assertEquals(GSVersionDecoder.VERSION.ABOVE, GSVersionDecoder.VERSION.getVersion("2.21"));
|
||||
assertEquals(GSVersionDecoder.VERSION.ABOVE, GSVersionDecoder.VERSION.getVersion("2.21-SNAPSHOT"));
|
||||
assertEquals(GSVersionDecoder.VERSION.ABOVE, GSVersionDecoder.VERSION.getVersion("2.42"));
|
||||
assertEquals(GSVersionDecoder.VERSION.ABOVE, GSVersionDecoder.VERSION.getVersion("2.42-SNAPSHOT"));
|
||||
|
||||
assertEquals(GSVersionDecoder.VERSION.UNRECOGNIZED, GSVersionDecoder.VERSION.getVersion("3.0"));
|
||||
assertEquals(GSVersionDecoder.VERSION.UNRECOGNIZED, GSVersionDecoder.VERSION.getVersion("anystring"));
|
||||
assertEquals(GSVersionDecoder.VERSION.UNRECOGNIZED, GSVersionDecoder.VERSION.getVersion(null));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
|
||||
* Copyright (C) 2007 - 2015 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* GPLv3 + Classpath exception
|
||||
@ -104,11 +104,12 @@ public class GSFeatureEncoderTest extends GeoserverRESTTest {
|
||||
fte.addMetadataLinkInfo(metadatalink);
|
||||
|
||||
GSLayerEncoder layerEncoder = null;
|
||||
if (VERSION.getVersion(GS_VERSION).compareTo(VERSION.UNRECOGNIZED) > 0) {
|
||||
layerEncoder = new GSLayerEncoder();
|
||||
} else if (VERSION.getVersion(GS_VERSION).compareTo(VERSION.UNRECOGNIZED) == 0) {
|
||||
if (VERSION.getVersion(GS_VERSION) == VERSION.UNRECOGNIZED ) {
|
||||
layerEncoder = new GSLayerEncoder21();
|
||||
} else {
|
||||
layerEncoder = new GSLayerEncoder();
|
||||
}
|
||||
|
||||
layerEncoder.setEnabled(true);
|
||||
layerEncoder.setQueryable(true);
|
||||
layerEncoder.setAdvertised(true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user