You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2010/07/05 11:41:55 UTC
svn commit: r960500 - in /karaf/trunk/features: ./
core/src/main/java/org/apache/karaf/features/internal/
obr/src/main/java/org/apache/karaf/features/obr/internal/
obr/src/test/java/org/apache/karaf/features/obr/internal/
Author: gnodet
Date: Mon Jul 5 09:41:54 2010
New Revision: 960500
URL: http://svn.apache.org/viewvc?rev=960500&view=rev
Log:
KARAF-96: Fix OBR resolver
Added:
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleInfoImpl.java
- copied, changed from r960457, karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/BundleInfoImpl.java
- copied, changed from r960457, karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
Removed:
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java
Modified:
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/ObrResolver.java
karaf/trunk/features/obr/src/test/java/org/apache/karaf/features/obr/internal/ObrResolverTest.java
karaf/trunk/features/pom.xml
Copied: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleInfoImpl.java (from r960457, karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java)
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleInfoImpl.java?p2=karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleInfoImpl.java&p1=karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java&r1=960457&r2=960500&rev=960500&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleInfoImpl.java Mon Jul 5 09:41:54 2010
@@ -21,34 +21,35 @@ import org.apache.karaf.features.BundleI
/**
* A holder of bundle info
*/
-public class BundleImpl implements BundleInfo {
+public class BundleInfoImpl implements BundleInfo {
private int startLevel;
private String location;
private boolean start;
- public BundleImpl() {
+ public BundleInfoImpl() {
}
- public BundleImpl(String location) {
+ public BundleInfoImpl(String location) {
this.location = location;
}
- public BundleImpl(String location, boolean start) {
+ public BundleInfoImpl(String location, boolean start) {
this.location = location;
- this.setStart(start);
+ this.start = start;
}
- public BundleImpl(String location, Integer startLevel) {
+ public BundleInfoImpl(String location, int startLevel) {
this.location = location;
this.startLevel = startLevel;
}
- public BundleImpl(String location, Integer startLevel, boolean start) {
+ public BundleInfoImpl(String location, int startLevel, boolean start) {
this.location = location;
this.startLevel = startLevel;
+ this.start = start;
}
public void setStartLevel(Integer startLevel) {
Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java?rev=960500&r1=960499&r2=960500&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/RepositoryImpl.java Mon Jul 5 09:41:54 2010
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
-import java.rmi.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -177,13 +176,13 @@ public class RepositoryImpl implements R
try {
int bsl = Integer.parseInt(bStartLevel);
- f.addBundle(new BundleImpl(b.getTextContent(), bsl, bs));
+ f.addBundle(new BundleInfoImpl(b.getTextContent(), bsl, bs));
} catch (Exception ex) {
LOGGER.error("The start-level is not an int value for the bundle : " + b.getTextContent());
}
} else {
- f.addBundle(new BundleImpl(b.getTextContent(), bs));
+ f.addBundle(new BundleInfoImpl(b.getTextContent(), bs));
}
}
Copied: karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/BundleInfoImpl.java (from r960457, karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java)
URL: http://svn.apache.org/viewvc/karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/BundleInfoImpl.java?p2=karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/BundleInfoImpl.java&p1=karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java&r1=960457&r2=960500&rev=960500&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/BundleImpl.java (original)
+++ karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/BundleInfoImpl.java Mon Jul 5 09:41:54 2010
@@ -1,77 +1,78 @@
-/*
- * 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.karaf.features.internal;
-
-import org.apache.karaf.features.BundleInfo;
-
-/**
- * A holder of bundle info
- */
-public class BundleImpl implements BundleInfo {
-
- private int startLevel;
- private String location;
- private boolean start;
-
-
- public BundleImpl() {
- }
-
- public BundleImpl(String location) {
- this.location = location;
- }
-
-
- public BundleImpl(String location, boolean start) {
- this.location = location;
- this.setStart(start);
- }
-
- public BundleImpl(String location, Integer startLevel) {
- this.location = location;
- this.startLevel = startLevel;
- }
-
- public BundleImpl(String location, Integer startLevel, boolean start) {
- this.location = location;
- this.startLevel = startLevel;
- }
-
- public void setStartLevel(Integer startLevel) {
- this.startLevel = startLevel;
- }
-
- public int getStartLevel() {
- return this.startLevel;
- }
-
- public void setName(String location) {
- this.location = location;
- }
-
- public String getLocation() {
- return this.location;
- }
-
- public void setStart(boolean start) {
- this.start = start;
- }
-
- public boolean isStart() {
- return start;
- }
-}
+/*
+ * 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.karaf.features.obr.internal;
+
+import org.apache.karaf.features.BundleInfo;
+
+/**
+ * A holder of bundle info
+ */
+public class BundleInfoImpl implements BundleInfo {
+
+ private int startLevel;
+ private String location;
+ private boolean start;
+
+
+ public BundleInfoImpl() {
+ }
+
+ public BundleInfoImpl(String location) {
+ this.location = location;
+ }
+
+
+ public BundleInfoImpl(String location, boolean start) {
+ this.location = location;
+ this.start = start;
+ }
+
+ public BundleInfoImpl(String location, int startLevel) {
+ this.location = location;
+ this.startLevel = startLevel;
+ }
+
+ public BundleInfoImpl(String location, int startLevel, boolean start) {
+ this.location = location;
+ this.startLevel = startLevel;
+ this.start = start;
+ }
+
+ public void setStartLevel(Integer startLevel) {
+ this.startLevel = startLevel;
+ }
+
+ public int getStartLevel() {
+ return this.startLevel;
+ }
+
+ public void setName(String location) {
+ this.location = location;
+ }
+
+ public String getLocation() {
+ return this.location;
+ }
+
+ public void setStart(boolean start) {
+ this.start = start;
+ }
+
+ public boolean isStart() {
+ return start;
+ }
+}
Modified: karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/ObrResolver.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/ObrResolver.java?rev=960500&r1=960499&r2=960500&view=diff
==============================================================================
--- karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/ObrResolver.java (original)
+++ karaf/trunk/features/obr/src/main/java/org/apache/karaf/features/obr/internal/ObrResolver.java Mon Jul 5 09:41:54 2010
@@ -22,13 +22,16 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.felix.bundlerepository.Reason;
import org.apache.felix.bundlerepository.Repository;
import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.bundlerepository.Requirement;
import org.apache.felix.bundlerepository.Resource;
+import org.apache.karaf.features.BundleInfo;
import org.apache.karaf.features.Feature;
import org.apache.karaf.features.Resolver;
import org.osgi.framework.InvalidSyntaxException;
@@ -45,15 +48,20 @@ public class ObrResolver implements Reso
this.repositoryAdmin = repositoryAdmin;
}
- public List<String> resolve(Feature feature) throws Exception {
+ public List<BundleInfo> resolve(Feature feature) throws Exception {
List<Requirement> reqs = new ArrayList<Requirement>();
List<Resource> ress = new ArrayList<Resource>();
- for (String bundleUrl : feature.getBundles()) {
+ Map<Object, BundleInfo> infos = new HashMap<Object, BundleInfo>();
+ for (BundleInfo bundleInfo : feature.getBundles()) {
try {
- URL url = new URL(bundleUrl);
- ress.add(repositoryAdmin.getHelper().createResource(url));
+ URL url = new URL(bundleInfo.getLocation());
+ Resource res = repositoryAdmin.getHelper().createResource(url);
+ ress.add(res);
+ infos.put(res, bundleInfo);
} catch (MalformedURLException e) {
- reqs.add(parseRequirement(bundleUrl));
+ Requirement req = parseRequirement(bundleInfo.getLocation());
+ reqs.add(req);
+ infos.put(req, bundleInfo);
}
}
@@ -90,11 +98,26 @@ public class ObrResolver implements Reso
throw new Exception("Can not resolve feature:\n" + w.toString());
}
- List<String> urls = new ArrayList<String>();
+ List<BundleInfo> bundles = new ArrayList<BundleInfo>();
for (Resource res : resolver.getRequiredResources()) {
- urls.add(res.getURI());
+ BundleInfo info = infos.get(res);
+ if (info == null) {
+ Reason[] reasons = resolver.getReason(res);
+ if (reasons != null) {
+ for (Reason r : reasons) {
+ info = infos.get(r);
+ if (info != null) {
+ break;
+ }
+ }
+ }
+ }
+ if (info == null) {
+ info = new BundleInfoImpl(res.getURI());
+ }
+ bundles.add(info);
}
- return urls;
+ return bundles;
}
protected void printUnderline(PrintWriter out, int length) {
Modified: karaf/trunk/features/obr/src/test/java/org/apache/karaf/features/obr/internal/ObrResolverTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/obr/src/test/java/org/apache/karaf/features/obr/internal/ObrResolverTest.java?rev=960500&r1=960499&r2=960500&view=diff
==============================================================================
--- karaf/trunk/features/obr/src/test/java/org/apache/karaf/features/obr/internal/ObrResolverTest.java (original)
+++ karaf/trunk/features/obr/src/test/java/org/apache/karaf/features/obr/internal/ObrResolverTest.java Mon Jul 5 09:41:54 2010
@@ -18,14 +18,18 @@ package org.apache.karaf.features.obr.in
import java.util.List;
+import org.apache.felix.bundlerepository.Reason;
import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.bundlerepository.Requirement;
import org.apache.felix.bundlerepository.Resolver;
import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.bundlerepository.impl.DataModelHelperImpl;
+import org.apache.felix.bundlerepository.impl.ReasonImpl;
+import org.apache.karaf.features.BundleInfo;
import org.apache.karaf.features.internal.FeatureImpl;
import org.easymock.Capture;
import org.easymock.EasyMock;
+import org.easymock.IAnswer;
import org.junit.Test;
import static org.easymock.EasyMock.createMock;
@@ -39,18 +43,18 @@ public class ObrResolverTest {
@Test
public void testResolver() throws Exception {
- String requirement = "bundle:(&(symbolicname=org.apache.camel.camel-blueprint)(version>=2.4.0)(version<2.4.1))";
+ final String requirement = "bundle:(&(symbolicname=org.apache.camel.camel-blueprint)(version>=2.4.0)(version<2.4.1))";
- FeatureImpl f = new FeatureImpl("f1", "1.0");
+ final FeatureImpl f = new FeatureImpl("f1", "1.0");
f.setResolver("obr");
- f.addBundle(requirement);
- RepositoryAdmin admin = createMock(RepositoryAdmin.class);
- Resolver resolver = createMock(Resolver.class);
- Resource resource = createMock(Resource.class);
- ObrResolver obrResolver = new ObrResolver();
+ f.addBundle(new BundleInfoImpl(requirement));
+ final RepositoryAdmin admin = createMock(RepositoryAdmin.class);
+ final Resolver resolver = createMock(Resolver.class);
+ final Resource resource = createMock(Resource.class);
+ final ObrResolver obrResolver = new ObrResolver();
obrResolver.setRepositoryAdmin(admin);
- Capture<Requirement> captureReq = new Capture<Requirement>();
+ final Capture<Requirement> captureReq = new Capture<Requirement>();
expect(admin.getHelper()).andReturn(new DataModelHelperImpl()).anyTimes();
expect(admin.getSystemRepository()).andReturn(createMock(org.apache.felix.bundlerepository.Repository.class));
@@ -60,13 +64,18 @@ public class ObrResolverTest {
resolver.add(EasyMock.capture(captureReq));
expect(resolver.resolve(Resolver.NO_OPTIONAL_RESOURCES)).andReturn(true);
expect(resolver.getRequiredResources()).andReturn(new Resource[] { resource });
+ expect(resolver.getReason(resource)).andAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return new Reason[] { new ReasonImpl( resource, captureReq.getValue()) };
+ }
+ });
expect(resource.getURI()).andReturn("foo:bar");
replay(admin, resolver, resource);
- List<String> bundles = obrResolver.resolve(f);
+ List<BundleInfo> bundles = obrResolver.resolve(f);
assertNotNull(bundles);
assertEquals(1, bundles.size());
- assertEquals("foo:bar", bundles.get(0));
+ assertEquals("foo:bar", bundles.get(0).getLocation());
assertEquals(obrResolver.parseRequirement(requirement).toString(), captureReq.getValue().toString());
verify(admin, resolver, resource);
}
Modified: karaf/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/features/pom.xml?rev=960500&r1=960499&r2=960500&view=diff
==============================================================================
--- karaf/trunk/features/pom.xml (original)
+++ karaf/trunk/features/pom.xml Mon Jul 5 09:41:54 2010
@@ -36,7 +36,7 @@
<module>core</module>
<module>command</module>
<module>management</module>
- <!-- <module>obr</module> -->
+ <module>obr</module>
</modules>
</project>