incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r954793 - in /incubator/aries/trunk/application: application-itests/ application-itests/src/test/java/org/apache/aries/application/runtime/itests/ application-obr-resolver/ application-obr-resolver/src/main/java/org/apache/aries/application...
Date Tue, 15 Jun 2010 10:28:35 GMT
Author: not
Date: Tue Jun 15 10:28:34 2010
New Revision: 954793

URL: http://svn.apache.org/viewvc?rev=954793&view=rev
Log:
ARIES-335 Updated to make use of bundlerepository 1.6 rather than 1.4. This means we can remove
the synchronized and resolve multiple apps at once without them interfering with each other.

Removed:
    incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/CapabilityImpl.java
    incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ResourceImpl.java
Modified:
    incubator/aries/trunk/application/application-itests/pom.xml
    incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRAppManagerTest.java
    incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java
    incubator/aries/trunk/application/application-obr-resolver/pom.xml
    incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
    incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java
    incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java
    incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java
    incubator/aries/trunk/application/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml

Modified: incubator/aries/trunk/application/application-itests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-itests/pom.xml?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-itests/pom.xml (original)
+++ incubator/aries/trunk/application/application-itests/pom.xml Tue Jun 15 10:28:34 2010
@@ -89,11 +89,6 @@
             <artifactId>org.apache.felix.bundlerepository</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.osgi.service.obr</artifactId>
-            <scope>test</scope>
-        </dependency>
 
         <dependency>
             <groupId>org.osgi</groupId>

Modified: incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRAppManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRAppManagerTest.java?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRAppManagerTest.java
(original)
+++ incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRAppManagerTest.java
Tue Jun 15 10:28:34 2010
@@ -38,10 +38,10 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.service.obr.Capability;
-import org.osgi.service.obr.Repository;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Resource;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Resource;
 
 @RunWith(JUnit4TestRunner.class)
 public class OBRAppManagerTest extends AbstractIntegrationTest {

Modified: incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java
(original)
+++ incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/OBRResolverTest.java
Tue Jun 15 10:28:34 2010
@@ -58,8 +58,8 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
-import org.osgi.service.obr.Repository;
-import org.osgi.service.obr.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.w3c.dom.Document;
 
 @RunWith(JUnit4TestRunner.class)
@@ -150,7 +150,7 @@ public class OBRResolverTest extends Abs
     
     Repository[] repos = repositoryAdmin.listRepositories();
     for (Repository repo : repos) {
-      repositoryAdmin.removeRepository(repo.getURL());
+      repositoryAdmin.removeRepository(repo.getURI());
     }
     
     repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
@@ -173,7 +173,7 @@ public class OBRResolverTest extends Abs
     
     Repository[] repos = repositoryAdmin.listRepositories();
     for (Repository repo : repos) {
-      repositoryAdmin.removeRepository(repo.getURL());
+      repositoryAdmin.removeRepository(repo.getURI());
     }
     
     repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());

Modified: incubator/aries/trunk/application/application-obr-resolver/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-obr-resolver/pom.xml?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-obr-resolver/pom.xml (original)
+++ incubator/aries/trunk/application/application-obr-resolver/pom.xml Tue Jun 15 10:28:34
2010
@@ -50,15 +50,14 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.osgi.service.obr</artifactId>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.apache.felix.bundlerepository</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

Modified: incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
(original)
+++ incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
Tue Jun 15 10:28:34 2010
@@ -20,13 +20,16 @@
 
 package org.apache.aries.application.resolver.obr;
 
-import java.io.File;
-import java.net.URL;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.jar.Attributes;
 
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
@@ -43,11 +46,15 @@ import org.apache.aries.application.reso
 import org.apache.aries.application.resolver.obr.impl.ApplicationResourceImpl;
 import org.apache.aries.application.resolver.obr.impl.OBRBundleInfo;
 import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.felix.bundlerepository.DataModelHelper;
+import org.apache.felix.bundlerepository.Reason;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Resolver;
+import org.apache.felix.bundlerepository.Resource;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.Version;
-import org.osgi.service.obr.RepositoryAdmin;
-import org.osgi.service.obr.Requirement;
-import org.osgi.service.obr.Resolver;
-import org.osgi.service.obr.Resource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -70,82 +77,96 @@ public class OBRAriesResolver implements
    * This method is synchronized because it changes the repositories understood by OBR, and
we don't
    * want one apps by value content being used to resolve another. I'll ask for an OBR enhancement.
    */
-  public synchronized Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint...
constraints) throws ResolverException
+  public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints)
throws ResolverException
   {
     log.trace("resolving {}", app);
-    Resolver obrResolver = repositoryAdmin.resolver();
-    
+    DataModelHelper helper = repositoryAdmin.getHelper();
+
     ApplicationMetadata appMeta = app.getApplicationMetadata();
-    
+
     String appName = appMeta.getApplicationSymbolicName();
     Version appVersion = appMeta.getApplicationVersion();
     List<Content> appContent = appMeta.getApplicationContents();
 
-    // add a resource describing the requirements of the application metadata.
-    obrResolver.add(new ApplicationResourceImpl(appName, appVersion, appContent));
-
-    URL appRepoURL = null;
+    Repository appRepo;
     
     try {
       Document doc = RepositoryDescriptorGenerator.generateRepositoryDescriptor(appName +
"_" + appVersion, app.getBundleInfo());
       
-      File f = File.createTempFile(appName + "_" + appVersion, "repository.xml");
-      TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new
StreamResult(f));
+      ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
       
-      appRepoURL = f.toURI().toURL();
+      TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new
StreamResult(bytesOut));
       
-      repositoryAdmin.addRepository(appRepoURL);
-      f.delete();
+      appRepo = helper.readRepository(new InputStreamReader(new ByteArrayInputStream(bytesOut.toByteArray())));
     } catch (Exception e) {
       throw new ResolverException(e);
     } 
     
-    try {
-      if (obrResolver.resolve()) {
-        Set<BundleInfo> result = new HashSet<BundleInfo>();
-        for (Resource resource: obrResolver.getRequiredResources()) {
-          BundleInfo bundleInfo = toBundleInfo(resource);
-          result.add(bundleInfo);
-        }
-        for (Resource resource: obrResolver.getOptionalResources()) {
-          BundleInfo bundleInfo = toBundleInfo(resource);
-          result.add(bundleInfo);
-        }
-        return result;
-      } else {
-        throw new ResolverException("Could not resolve requirements: " + getUnsatisfiedRequirements(obrResolver));
+    Repository[] repos = repositoryAdmin.listRepositories();
+    
+    List<Repository> resolveRepos = new ArrayList<Repository>();
+    resolveRepos.add(appRepo);
+    
+    for (Repository r : repos) {
+      if (!!!Repository.LOCAL.equals(r.getURI())) {
+        resolveRepos.add(r);
+      }
+    }
+    
+    Resolver obrResolver = repositoryAdmin.resolver(resolveRepos.toArray(new Repository[resolveRepos.size()]));
+    // add a resource describing the requirements of the application metadata.
+    obrResolver.add(createApplicationResource(helper, appName, appVersion, appContent));
+    if (obrResolver.resolve()) {
+      Set<BundleInfo> result = new HashSet<BundleInfo>();
+      for (Resource resource: obrResolver.getRequiredResources()) {
+        BundleInfo bundleInfo = toBundleInfo(resource);
+        result.add(bundleInfo);
       }
-    } finally {
-      if (appRepoURL != null) {
-        repositoryAdmin.removeRepository(appRepoURL);
+      for (Resource resource: obrResolver.getOptionalResources()) {
+        BundleInfo bundleInfo = toBundleInfo(resource);
+        result.add(bundleInfo);
       }
+      return result;
+    } else {
+      throw new ResolverException("Could not resolve requirements: " + getUnsatisfiedRequirements(obrResolver));
     }
   }
 
+  private Resource createApplicationResource(DataModelHelper helper, String appName, Version
appVersion,
+      List<Content> appContent)
+  {
+    return new ApplicationResourceImpl(appName, appVersion, appContent);
+  }
+
   public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion)
   {
     Map<String, String> attribs = new HashMap<String, String>();
     attribs.put(Resource.VERSION, bundleVersion.toString());
     String filterString = ManifestHeaderProcessor.generateFilter(Resource.SYMBOLIC_NAME,
bundleSymbolicName, attribs);
-    Resource[] resources = repositoryAdmin.discoverResources(filterString);
-    if (resources != null && resources.length > 0) {
-      return toBundleInfo(resources[0]);
-    } else {
+    Resource[] resources;
+    try {
+      resources = repositoryAdmin.discoverResources(filterString);
+      if (resources != null && resources.length > 0) {
+        return toBundleInfo(resources[0]);
+      } else {
+        return null;
+      }
+    } catch (InvalidSyntaxException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
       return null;
     }
   }
 
   private String getUnsatisfiedRequirements(Resolver resolver)
   {
-    Requirement[] reqs = resolver.getUnsatisfiedRequirements();
+    Reason[] reqs = resolver.getUnsatisfiedRequirements();
     if (reqs != null) {
       StringBuilder sb = new StringBuilder();
       for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
-        sb.append("   " + reqs[reqIdx].getFilter()).append("\n");
-        Resource[] resources = resolver.getResources(reqs[reqIdx]);
-        for (int resIdx = 0; resIdx < resources.length; resIdx++) {
-          sb.append("      " + resources[resIdx].getPresentationName()).append("\n");
-        }
+        sb.append("   " + reqs[reqIdx].getRequirement().getFilter()).append("\n");
+        Resource resource = reqs[reqIdx].getResource();
+        sb.append("      " + resource.getPresentationName()).append("\n");
       }
       return sb.toString();
     }
@@ -154,7 +175,7 @@ public class OBRAriesResolver implements
 
   private BundleInfo toBundleInfo(Resource resource)
   {
-    String location = resource.getURL().toExternalForm();
+    String location = resource.getURI();
     return new OBRBundleInfo(resource.getSymbolicName(),
             resource.getVersion(),
             location,

Modified: incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java
(original)
+++ incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java
Tue Jun 15 10:28:34 2010
@@ -27,8 +27,8 @@ import javax.xml.parsers.ParserConfigura
 import org.apache.aries.application.Content;
 import org.apache.aries.application.management.BundleInfo;
 import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.felix.bundlerepository.Resource;
 import org.osgi.framework.Constants;
-import org.osgi.service.obr.Resource;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 

Modified: incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java
(original)
+++ incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java
Tue Jun 15 10:28:34 2010
@@ -29,10 +29,10 @@ import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
-import org.osgi.service.obr.Capability;
-import org.osgi.service.obr.Repository;
-import org.osgi.service.obr.Requirement;
-import org.osgi.service.obr.Resource;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Repository;
+import org.apache.felix.bundlerepository.Requirement;
+import org.apache.felix.bundlerepository.Resource;
 
 public class ApplicationResourceImpl implements Resource
 {
@@ -146,4 +146,20 @@ public class ApplicationResourceImpl imp
   {
     return _version;
   }
+
+  public Long getSize()
+  {
+    return 0l;
+  }
+
+  public String getURI()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public boolean isLocal()
+  {
+    return false;
+  }
 }
\ No newline at end of file

Modified: incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java
(original)
+++ incubator/aries/trunk/application/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java
Tue Jun 15 10:28:34 2010
@@ -21,8 +21,8 @@
 package org.apache.aries.application.resolver.obr.impl;
 
 import org.osgi.framework.Filter;
-import org.osgi.service.obr.Capability;
-import org.osgi.service.obr.Requirement;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Requirement;
 
 /**
  * @version $Rev$ $Date$
@@ -78,6 +78,6 @@ public class RequirementImpl implements 
 
   public boolean isSatisfied(Capability capability)
   {
-    return filter.match(new MapToDictionary(capability.getProperties()));
+    return filter.match(new MapToDictionary(capability.getPropertiesAsMap()));
   }
 }

Modified: incubator/aries/trunk/application/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml?rev=954793&r1=954792&r2=954793&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
(original)
+++ incubator/aries/trunk/application/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
Tue Jun 15 10:28:34 2010
@@ -22,7 +22,7 @@
     <bean id="obr-resolver" class="org.apache.aries.application.resolver.obr.OBRAriesResolver"
scope="singleton"
           activation="eager">
         <argument>
-            <reference interface="org.osgi.service.obr.RepositoryAdmin"/>
+            <reference interface="org.apache.felix.bundlerepository.RepositoryAdmin"/>
         </argument>
     </bean>
 



Mime
View raw message