You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ma...@apache.org on 2010/09/03 16:19:26 UTC
svn commit: r992307 - in /incubator/aries/trunk/application:
application-api/src/main/java/org/apache/aries/application/management/
application-management/src/main/java/org/apache/aries/application/management/repository/
application-management/src/test...
Author: mahrwald
Date: Fri Sep 3 14:19:26 2010
New Revision: 992307
URL: http://svn.apache.org/viewvc?rev=992307&view=rev
Log:
ARIES-398: Support applications that pull in a bundle from a global repository.
Added:
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/repository/
incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java
Modified:
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleRepository.java
incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java
incubator/aries/trunk/application/application-runtime-repository/src/main/java/org/apache/aries/application/runtime/repository/BundleRepositoryManagerImpl.java
Modified: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleRepository.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleRepository.java?rev=992307&r1=992306&r2=992307&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleRepository.java (original)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/BundleRepository.java Fri Sep 3 14:19:26 2010
@@ -29,7 +29,16 @@ import org.osgi.framework.BundleExceptio
import org.osgi.framework.Version;
public interface BundleRepository {
-
+ /**
+ * Service property denoting the scope of the bundle repository. This can
+ * <ul>
+ * <li>global</li>
+ * <li><app symbolic name>_<app version></li>
+ * </ul>
+ */
+ public static final String REPOSITORY_SCOPE = "repositoryScope";
+ public static final String GLOBAL_SCOPE = "global";
+
/**
* A suggested bundle to use.
*/
Modified: incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java?rev=992307&r1=992306&r2=992307&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java (original)
+++ incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/repository/ApplicationRepository.java Fri Sep 3 14:19:26 2010
@@ -18,7 +18,6 @@
*/
package org.apache.aries.application.management.repository;
-import java.util.Collections;
import java.util.Set;
import org.apache.aries.application.Content;
@@ -35,7 +34,7 @@ import org.osgi.framework.Version;
public class ApplicationRepository implements BundleRepository
{
private static final int REPOSITORY_COST = 0;
- public static final String REPOSITORY_SCOPE = "repositoryScope";
+
private AriesApplication app;
AriesApplicationResolver resolver;
@@ -51,23 +50,30 @@ public class ApplicationRepository imple
public BundleSuggestion suggestBundleToUse(DeploymentContent content)
{
- return new BundleSuggestionImpl(content);
+ BundleInfo bundleInfo = null;
+ if ((app.getBundleInfo() != null) && (!app.getBundleInfo().isEmpty())) {
+ for (BundleInfo bi : app.getBundleInfo()) {
+ if (bi.getSymbolicName().equals(content.getContentName()) && (bi.getVersion().equals(content.getVersion().getExactVersion()))) {
+ bundleInfo = bi;
+ break;
+ }
+ }
+ }
+
+ if (bundleInfo != null) {
+ return new BundleSuggestionImpl(bundleInfo);
+ } else {
+ return null;
+ }
}
private class BundleSuggestionImpl implements BundleSuggestion
{
- private BundleInfo bundleInfo = null;
+ private final BundleInfo bundleInfo;
- BundleSuggestionImpl(DeploymentContent content)
+ BundleSuggestionImpl(BundleInfo bundleInfo)
{
- if ((app.getBundleInfo() != null) && (!app.getBundleInfo().isEmpty())) {
- for (BundleInfo bi : app.getBundleInfo()) {
- if (bi.getSymbolicName().equals(content.getContentName()) && (bi.getVersion().equals(content.getVersion().getExactVersion()))) {
- bundleInfo = bi;
- break;
- }
- }
- }
+ this.bundleInfo = bundleInfo;
}
public int getCost()
Added: incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java?rev=992307&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java (added)
+++ incubator/aries/trunk/application/application-management/src/test/java/org/apache/aries/application/management/repository/ApplicationRepositoryTest.java Fri Sep 3 14:19:26 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.aries.application.management.repository;
+
+import java.util.HashSet;
+import java.util.Map;
+
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.impl.DeploymentContentImpl;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.BundleRepository.BundleSuggestion;
+import org.apache.aries.unittest.mocks.MethodCall;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import static org.junit.Assert.*;
+
+public class ApplicationRepositoryTest {
+ @Test
+ public void testBundleNotInApp() {
+ AriesApplication app = Skeleton.newMock(AriesApplication.class);
+
+ BundleInfo bi = Skeleton.newMock(BundleInfo.class);
+ Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getSymbolicName"), "test.bundle");
+ Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getVersion"), new Version("1.0.0"));
+
+ Skeleton.getSkeleton(app).setReturnValue(
+ new MethodCall(AriesApplication.class, "getBundleInfo"),
+ new HashSet<BundleInfo>());
+
+ ApplicationRepository rep = new ApplicationRepository(app);
+ BundleSuggestion sug = rep.suggestBundleToUse(new DeploymentContentImpl("test.bundle", new Version("2.0.0")));
+
+ assertNull("We have apparently found a bundle that is not in the application in the ApplicationRepository", sug);
+ }
+}
Modified: incubator/aries/trunk/application/application-runtime-repository/src/main/java/org/apache/aries/application/runtime/repository/BundleRepositoryManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-repository/src/main/java/org/apache/aries/application/runtime/repository/BundleRepositoryManagerImpl.java?rev=992307&r1=992306&r2=992307&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-repository/src/main/java/org/apache/aries/application/runtime/repository/BundleRepositoryManagerImpl.java (original)
+++ incubator/aries/trunk/application/application-runtime-repository/src/main/java/org/apache/aries/application/runtime/repository/BundleRepositoryManagerImpl.java Fri Sep 3 14:19:26 2010
@@ -48,7 +48,6 @@ import org.slf4j.LoggerFactory;
public class BundleRepositoryManagerImpl implements BundleRepositoryManager
{
private static final Logger LOGGER = LoggerFactory.getLogger(BundleRepositoryManagerImpl.class);
- public static final String REPOSITORY_SCOPE = "repositoryScope";
private BundleContext bc;
@@ -94,7 +93,7 @@ public class BundleRepositoryManagerImpl
String appScope = appName + "_" + appVersion;
- String filter = "(|(" + REPOSITORY_SCOPE + "=global)(" + REPOSITORY_SCOPE + "="
+ String filter = "(|(" + BundleRepository.REPOSITORY_SCOPE + "=" + BundleRepository.GLOBAL_SCOPE + ")(" + BundleRepository.REPOSITORY_SCOPE + "="
+ appScope + "))";
try {
ServiceReference[] refs = bc.getServiceReferences(
@@ -149,14 +148,16 @@ public class BundleRepositoryManagerImpl
List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
- Collections.sort(thoughts, new Comparator<BundleSuggestion>() {
- public int compare(BundleSuggestion o1, BundleSuggestion o2)
- {
- return o1.getCost() - o2.getCost();
- }
- });
-
- suggestion = thoughts.get(0);
+ if (thoughts != null) {
+ Collections.sort(thoughts, new Comparator<BundleSuggestion>() {
+ public int compare(BundleSuggestion o1, BundleSuggestion o2)
+ {
+ return o1.getCost() - o2.getCost();
+ }
+ });
+
+ suggestion = thoughts.get(0);
+ }
}
// add the suggestion to the list
@@ -164,7 +165,7 @@ public class BundleRepositoryManagerImpl
urlToBeInstalled.put(bundleToFind, suggestion);
it.remove();
} else {
- throw new ContextException("Unable to find bundle based on bundle URL " + suggestion);
+ throw new ContextException("Unable to find bundle "+bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
}
}