CAMEL-8895: camel-swagger should filter out older Camel releases that dont support rest-dsl
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c9f71d51 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c9f71d51 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c9f71d51 Branch: refs/heads/camel-2.15.x Commit: c9f71d5197ae8662017e7155a1f3c97adf411d8c Parents: ae1f201 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jun 24 09:56:34 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jun 24 09:57:26 2015 +0200 ---------------------------------------------------------------------- .../apache/camel/util/CamelVersionHelper.java | 42 ++++++++++++++++++++ .../camel/util/CamelVersionHelperTest.java | 38 ++++++++++++++++++ .../swagger/DefaultCamelSwaggerServlet.scala | 9 ++++- 3 files changed, 87 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c9f71d51/camel-core/src/main/java/org/apache/camel/util/CamelVersionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/CamelVersionHelper.java b/camel-core/src/main/java/org/apache/camel/util/CamelVersionHelper.java new file mode 100644 index 0000000..368b4c7 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/util/CamelVersionHelper.java @@ -0,0 +1,42 @@ +/** + * 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. + */ +package org.apache.camel.util; + +/** + * A simple util to test Camel versions. + */ +public final class CamelVersionHelper { + + /** + * Checks whether other >= base + * + * @param base the base version + * @param other the other version + * @return <tt>true</tt> if GE, <tt>false</tt> otherwise + */ + public static boolean isGE(String base, String other) { + String s1 = base.replaceAll("\\.", ""); + String s2 = other.replaceAll("\\.", ""); + // SNAPSHOT as .0 + s1 = s1.replace("-SNAPSHOT", "0"); + s2 = s2.replace("-SNAPSHOT", "0"); + // then use number comparison + int n1 = Integer.valueOf(s1); + int n2 = Integer.valueOf(s2); + return Integer.compare(n2, n1) >= 0; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c9f71d51/camel-core/src/test/java/org/apache/camel/util/CamelVersionHelperTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/util/CamelVersionHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/CamelVersionHelperTest.java new file mode 100644 index 0000000..bf249ba --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/util/CamelVersionHelperTest.java @@ -0,0 +1,38 @@ +/** + * 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. + */ +package org.apache.camel.util; + +import junit.framework.TestCase; +import org.junit.Test; + +import static org.apache.camel.util.CamelVersionHelper.isGE; + +public class CamelVersionHelperTest extends TestCase { + + @Test + public void testGE() throws Exception { + assertTrue(isGE("2.15.0", "2.15.0")); + assertTrue(isGE("2.15.0", "2.15.1")); + assertTrue(isGE("2.15.0", "2.16.0")); + assertTrue(isGE("2.15.0", "2.16-SNAPSHOT")); + + assertFalse(isGE("2.15.0", "2.14.3")); + assertFalse(isGE("2.15.0", "2.13.0")); + assertFalse(isGE("2.15.0", "2.13.1")); + assertFalse(isGE("2.15.0", "2.14-SNAPSHOT")); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/c9f71d51/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/DefaultCamelSwaggerServlet.scala ---------------------------------------------------------------------- diff --git a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/DefaultCamelSwaggerServlet.scala b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/DefaultCamelSwaggerServlet.scala index 77e9940..a74b276 100644 --- a/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/DefaultCamelSwaggerServlet.scala +++ b/components/camel-swagger/src/main/scala/org/apache/camel/component/swagger/DefaultCamelSwaggerServlet.scala @@ -21,6 +21,7 @@ import javax.management.{MBeanServer, ObjectName} import org.apache.camel.model.ModelHelper import org.apache.camel.model.rest.{RestDefinition, RestsDefinition} +import org.apache.camel.util.CamelVersionHelper import scala.collection.mutable @@ -41,10 +42,14 @@ class DefaultCamelSwaggerServlet extends RestSwaggerApiDeclarationServlet { val on = name.asInstanceOf[ObjectName] var id: String = on.getKeyProperty("name") if (id.startsWith("\"") && id.endsWith("\"")) { - id = id.substring(1, id.length() - 1); + id = id.substring(1, id.length() - 1) } if (camelId == null || camelId.equals(id)) { - found = on + // filter out older Camel versions as this requires Camel 2.15 or better + val version = server.getAttribute(on, "CamelVersion").asInstanceOf[String] + if (CamelVersionHelper.isGE("2.15.0", version)) { + found = on + } } }