Author: gertv
Date: Mon Feb 23 19:54:10 2009
New Revision: 747114
URL: http://svn.apache.org/viewvc?rev=747114&view=rev
Log:
SMX4KNL-207: features/install should use latest feature version for unversioned
dependency
Added:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/internal/
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImplTest.java
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
Modified:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java?rev=747114&r1=747113&r2=747114&view=diff
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
(original)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImpl.java
Mon Feb 23 19:54:10 2009
@@ -152,17 +152,7 @@
}
public void installFeature(String name) throws Exception {
- //if not specify the features version, then use the latest version
- String latestVersion = FeatureImpl.DEFAULT_VERSION;
- Set<String> allVersions = getFeatures().get(name).keySet();
- for (String version : allVersions) {
- Version verlatest = new Version(cleanupVersion(latestVersion));
- Version ver = new Version(cleanupVersion(version));
- if (verlatest.compareTo(ver) < 0) {
- latestVersion = version;
- }
- }
- installFeature(name, latestVersion);
+ installFeature(name, FeatureImpl.DEFAULT_VERSION);
}
public void installFeature(String name, String version) throws Exception {
@@ -312,7 +302,23 @@
}
protected Feature getFeature(String name, String version) throws Exception
{
- return getFeatures().get(name).get(version);
+ Map<String, Feature> versions = getFeatures().get(name);
+ if (versions == null || versions.isEmpty()) {
+ return null;
+ } else {
+ Feature feature = versions.get(version);
+ if (feature == null &&
FeatureImpl.DEFAULT_VERSION.equals(version)) {
+ Version latest = new Version(cleanupVersion(version));
+ for (String available : versions.keySet()) {
+ Version availableVersion = new
Version(cleanupVersion(available));
+ if (availableVersion.compareTo(latest) > 0) {
+ feature = versions.get(available);
+ latest = availableVersion;
+ }
+ }
+ }
+ return feature;
+ }
}
protected Map<String, Map<String, Feature>> getFeatures() throws Exception
{
Added:
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImplTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImplTest.java?rev=747114&view=auto
==============================================================================
---
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImplTest.java
(added)
+++
servicemix/smx4/kernel/trunk/gshell/gshell-features/src/test/java/org/apache/servicemix/kernel/gshell/features/internal/FeaturesServiceImplTest.java
Mon Feb 23 19:54:10 2009
@@ -0,0 +1,74 @@
+/*
+ * 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.servicemix.kernel.gshell.features.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.servicemix.kernel.gshell.features.Feature;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {...@link FeaturesServiceImpl}
+ */
+public class FeaturesServiceImplTest extends TestCase {
+
+ public void testGetFeature() throws Exception {
+ final Map<String, Map<String, Feature>> features = new HashMap<String,
Map<String,Feature>>();
+ Map<String, Feature> versions = new HashMap<String, Feature>();
+ FeatureImpl feature = new FeatureImpl("transaction");
+ versions.put("1.0.0", feature);
+ features.put("transaction", versions);
+ final FeaturesServiceImpl impl = new FeaturesServiceImpl() {
+ protected Map<String,Map<String,Feature>> getFeatures() throws
Exception {
+ return features;
+ };
+ };
+ assertNotNull(impl.getFeature("transaction",
FeatureImpl.DEFAULT_VERSION));
+ assertSame(feature, impl.getFeature("transaction",
FeatureImpl.DEFAULT_VERSION));
+ }
+
+ public void testGetFeatureNotAvailable() throws Exception {
+ final Map<String, Map<String, Feature>> features = new HashMap<String,
Map<String,Feature>>();
+ Map<String, Feature> versions = new HashMap<String, Feature>();
+ versions.put("1.0.0", new FeatureImpl("transaction"));
+ features.put("transaction", versions);
+ final FeaturesServiceImpl impl = new FeaturesServiceImpl() {
+ protected Map<String,Map<String,Feature>> getFeatures() throws
Exception {
+ return features;
+ };
+ };
+ assertNull(impl.getFeature("activemq", FeatureImpl.DEFAULT_VERSION));
+ }
+
+ public void testGetFeatureHighestAvailable() throws Exception {
+ final Map<String, Map<String, Feature>> features = new HashMap<String,
Map<String,Feature>>();
+ Map<String, Feature> versions = new HashMap<String, Feature>();
+ versions.put("1.0.0", new FeatureImpl("transaction", "1.0.0"));
+ versions.put("2.0.0", new FeatureImpl("transaction", "2.0.0"));
+ features.put("transaction", versions);
+ final FeaturesServiceImpl impl = new FeaturesServiceImpl() {
+ protected Map<String,Map<String,Feature>> getFeatures() throws
Exception {
+ return features;
+ };
+ };
+ assertNotNull(impl.getFeature("transaction",
FeatureImpl.DEFAULT_VERSION));
+ assertSame("2.0.0", impl.getFeature("transaction",
FeatureImpl.DEFAULT_VERSION).getVersion());
+ }
+
+}