aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r1075127 [4/7] - in /aries/tags/application-0.2.1: ./ application-api/ application-api/src/ application-api/src/main/ application-api/src/main/java/ application-api/src/main/java/org/ application-api/src/main/java/org/apache/ application-ap...
Date Sun, 27 Feb 2011 20:02:56 GMT
Added: aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java (added)
+++ aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/application/management/impl/AriesApplicationManagerImplTest.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,319 @@
+/*
+ * 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 WARRANTIESOR 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.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.ApplicationMetadataFactory;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.DeploymentMetadataFactory;
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.impl.ApplicationMetadataFactoryImpl;
+import org.apache.aries.application.impl.ContentImpl;
+import org.apache.aries.application.impl.DeploymentContentImpl;
+import org.apache.aries.application.impl.DeploymentMetadataFactoryImpl;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationResolver;
+import org.apache.aries.application.management.BundleConversion;
+import org.apache.aries.application.management.BundleConverter;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ConversionException;
+import org.apache.aries.application.management.LocalPlatform;
+import org.apache.aries.application.management.ManagementException;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.filesystem.IOUtils;
+import org.apache.aries.application.utils.management.SimpleBundleInfo;
+import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.unittest.utils.EbaUnitTestUtils;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+/**
+ * Initial, simple test that creates and stores an AriesApplication. No
+ * BundleConverters are used in this test. 
+ */
+public class AriesApplicationManagerImplTest {
+  
+  static class DummyResolver implements AriesApplicationResolver {
+    Set<BundleInfo> nextResult;
+    public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) {
+      Set<BundleInfo> info = new HashSet<BundleInfo>(nextResult);
+      
+      info.addAll(app.getBundleInfo());
+      
+      return info;
+    } 
+    void setNextResult (Set<BundleInfo> r) { 
+      nextResult = r;
+    }
+    public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion)
+    {
+      return null;
+    }
+  }
+  
+  static class DummyLocalPlatform implements LocalPlatform {
+    public File getTemporaryDirectory() throws IOException {
+      File f = File.createTempFile("ebaTmp", null);
+      f.delete();
+      f.mkdir();
+      return f;
+    } 
+    public File getTemporaryFile () throws IOException { 
+      // Not used
+      return File.createTempFile("ebaTmp", null);
+    }
+  }
+  
+  static class DummyConverter implements BundleConverter {
+
+	public BundleConversion convert(IDirectory parentEba, IFile toBeConverted)
+			throws ConversionException {
+		if (toBeConverted.getName().equals("helloWorld.war")) {
+			InputStream is = null;
+            try {
+            	is = new FileInputStream(new File("../src/test/resources/conversion/MANIFEST.MF"));
+            	Manifest warManifest = new Manifest(is);           
+            	final File convertedFile = new File("./ariesApplicationManagerImplTest/conversion/helloWorld.war");
+            	IOUtils.jarUp(new File("../src/test/resources/conversion/conversion.eba/helloWorld.war"), convertedFile, warManifest);            
+                final String location = toBeConverted.toString();                
+            	return new BundleConversion() {
+
+					public BundleInfo getBundleInfo(ApplicationMetadataFactory amf) throws IOException {
+						return new SimpleBundleInfo(amf, BundleManifest.fromBundle(convertedFile), location);
+					}
+
+					public InputStream getInputStream() throws IOException {
+						return new FileInputStream(convertedFile);
+					}
+                	
+                };
+            } catch (IOException e) {
+            	e.printStackTrace();                
+            } finally {
+            	try {
+            	if (is != null)
+            		is.close();
+            	} catch (Exception e) {
+            		e.printStackTrace();
+            	}
+            }
+        }
+
+        return null;
+    }
+	
+	  
+  }
+  
+
+
+  static final String TEST_EBA = "./ariesApplicationManagerImplTest/test.eba";
+  static final String CONVERSION_EBA = "./ariesApplicationManagerImplTest/conversion.eba";
+  @BeforeClass 
+  public static void preTest() throws Exception { 
+    new File("ariesApplicationManagerImplTest/conversion").mkdirs();
+    EbaUnitTestUtils.createEba("../src/test/resources/bundles/test.eba", TEST_EBA);
+    File src = new File ("../src/test/resources/bundles/repository/a.handy.persistence.library.jar");
+    File dest = new File ("ariesApplicationManagerImplTest/a.handy.persistence.library.jar");
+    IOUtils.zipUp(src, dest);
+    EbaUnitTestUtils.createEba("../src/test/resources/conversion/conversion.eba", CONVERSION_EBA);
+  }
+  
+  AriesApplicationManagerImpl _appMgr;
+  ApplicationMetadataFactory _appMetaFactory;
+  DummyResolver _resolver;
+  DummyConverter _converter;
+  @Before
+  public void setup() { 
+    _appMgr = new AriesApplicationManagerImpl ();
+    _appMetaFactory = new ApplicationMetadataFactoryImpl ();
+
+    DeploymentMetadataFactory dmf = new DeploymentMetadataFactoryImpl();
+    _converter = new DummyConverter();
+    List<BundleConverter> bundleConverters = new ArrayList<BundleConverter>();
+    bundleConverters.add(_converter);
+    _resolver = new DummyResolver();    
+    _appMgr.setApplicationMetadataFactory(_appMetaFactory);
+    _appMgr.setDeploymentMetadataFactory(dmf);
+    _appMgr.setBundleConverters(bundleConverters);
+    _appMgr.setResolver(_resolver);
+    _appMgr.setLocalPlatform(new DummyLocalPlatform());
+  }
+  
+  @Test
+  public void testCreate() throws Exception { 
+    AriesApplication app = createApplication (TEST_EBA);
+    
+    ApplicationMetadata appMeta = app.getApplicationMetadata();
+    assertEquals (appMeta.getApplicationName(), "Test application");
+    assertEquals (appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
+    assertEquals (appMeta.getApplicationVersion(), new Version("1.0"));
+    List<Content> appContent = appMeta.getApplicationContents();
+    assertEquals (appContent.size(), 2);
+    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
+    Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
+    assertTrue (appContent.contains(fbw));
+    assertTrue (appContent.contains(mbl));
+    
+    DeploymentMetadata dm = app.getDeploymentMetadata();
+    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
+
+    assertEquals (2, dcList.size());
+    DeploymentContent dc1 = new DeploymentContentImpl ("foo.bar.widgets;deployed-version=1.1.0");
+    DeploymentContent dc2 = new DeploymentContentImpl ("my.business.logic;deployed-version=1.1.0");
+    DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
+    assertTrue (dcList.contains(dc1));
+    assertTrue (dcList.contains(dc2));
+    
+    dcList = dm.getApplicationProvisionBundles();
+    
+    assertEquals(1, dcList.size());
+    assertTrue (dcList.contains(dc3));
+
+  }
+  
+  @Test
+  public void testCreateAndConversion() throws Exception {
+	  	AriesApplication app = createApplication (CONVERSION_EBA);	    
+	    ApplicationMetadata appMeta = app.getApplicationMetadata();	    
+	    assertEquals (appMeta.getApplicationName(), "conversion.eba");	   
+	    assertEquals (appMeta.getApplicationSymbolicName(), "conversion.eba");	    
+	    assertEquals (appMeta.getApplicationVersion(), new Version("0.0"));	    
+	    List<Content> appContent = appMeta.getApplicationContents();
+	    assertEquals (2, appContent.size());
+	    Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
+	    Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
+	    assertTrue (appContent.contains(fbw));
+	    assertTrue (appContent.contains(mbl));
+	    
+	    DeploymentMetadata dm = app.getDeploymentMetadata();
+	    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
+
+	    assertEquals (2, dcList.size());
+	    DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
+	    DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
+	    DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
+	    assertTrue (dcList.contains(dc1));
+	    assertTrue (dcList.contains(dc2));
+	    
+	    dcList = dm.getApplicationProvisionBundles();
+	    
+	    assertEquals(1, dcList.size());
+	    assertTrue (dcList.contains(dc3));
+	    
+	    assertEquals(2, app.getBundleInfo().size());
+	    BundleInfo info;
+	    info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
+	    assertNotNull(info);
+	    assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
+	    
+	    info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
+        assertNotNull(info);
+        assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
+        assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
+  }
+  
+  private BundleInfo findBundleInfo(Set<BundleInfo> infos, String symbolicName) {
+      for (BundleInfo info : infos) {
+          if (symbolicName.equals(info.getSymbolicName())) {
+              return info;
+          }
+      }
+      return null;
+  }
+  
+  @Test
+  public void testStoreAndReload() throws Exception { 
+    AriesApplication app = createApplication (TEST_EBA);
+    File dest = new File ("ariesApplicationManagerImplTest/stored.eba");
+    app.store(dest);
+    
+    /* Dest should be a zip file with four entries:
+     *  /foo.bar.widgets.jar
+     *  /my.business.logic.jar
+     *  /META-INF/APPLICATION.MF
+     *  /META-INF/DEPLOYMENT.MF
+     */
+    
+    IDirectory storedEba = FileSystem.getFSRoot(dest);
+    assertNotNull (storedEba);
+    assertEquals (storedEba.listFiles().size(), 3);
+    IFile ifile = storedEba.getFile("META-INF/APPLICATION.MF");
+    assertNotNull (ifile);
+    ifile = storedEba.getFile ("META-INF/DEPLOYMENT.MF");
+    assertNotNull (ifile);
+    ifile = storedEba.getFile ("foo.bar.widgets.jar");
+    assertNotNull (ifile);
+    ifile = storedEba.getFile ("my.business.logic.jar");
+    assertNotNull (ifile);
+    
+    AriesApplication newApp = _appMgr.createApplication(storedEba);
+    DeploymentMetadata dm = newApp.getDeploymentMetadata();
+    assertEquals (2, dm.getApplicationDeploymentContents().size());
+    assertEquals(1, dm.getApplicationProvisionBundles().size());
+    assertEquals (dm.getApplicationSymbolicName(), app.getApplicationMetadata().getApplicationSymbolicName());
+    assertEquals (dm.getApplicationVersion(), app.getApplicationMetadata().getApplicationVersion());
+  }
+  
+  private AriesApplication createApplication (String fileName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ManagementException, ResolverException {
+    // This next block is a very long winded way of constructing a BundleInfoImpl
+    // against the existing (BundleManifest bm, String location) constructor. If we 
+    // find we need a String-based BundleInfoImpl constructor for other reasons, 
+    // we could change to using it here. 
+    Set<BundleInfo> nextResolverResult = new HashSet<BundleInfo>();
+    String persistenceLibraryLocation = "../src/test/resources/bundles/repository/a.handy.persistence.library.jar";
+    File persistenceLibrary = new File (persistenceLibraryLocation);
+    BundleManifest mf = BundleManifest.fromBundle(persistenceLibrary);
+    BundleInfo resolvedPersistenceLibrary = new SimpleBundleInfo(_appMetaFactory, mf, persistenceLibraryLocation); 
+    Field v = SimpleBundleInfo.class.getDeclaredField("_version");
+    v.setAccessible(true);
+    v.set(resolvedPersistenceLibrary, new Version("1.1.0"));
+    nextResolverResult.add(resolvedPersistenceLibrary);
+    _resolver.setNextResult(nextResolverResult);
+    
+    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));    
+    AriesApplication app = _appMgr.createApplication(testEba);
+    app = _appMgr.resolve(app);
+    return app;
+  }
+}

Added: aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java (added)
+++ aries/tags/application-0.2.1/application-management/src/test/java/org/apache/aries/unittest/utils/EbaUnitTestUtils.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,85 @@
+/*
+ * 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 WARRANTIESOR 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.unittest.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.utils.filesystem.IOUtils;
+
+public class EbaUnitTestUtils {
+
+private static final String TEMP_DIR = "unittest/tmpEbaContent";
+  
+  public static void createEba(String rootFolder, String outputFile) throws IOException
+  {
+    File tempDir = new File(TEMP_DIR);
+    tempDir.mkdirs();
+    
+    createEbaRecursive(new File(rootFolder), tempDir, "");
+    IOUtils.zipUp(tempDir, new File(outputFile));
+    IOUtils.deleteRecursive(tempDir);
+  }
+  
+  private static void createEbaRecursive(File folder, File tempDir, String prefix) throws IOException
+  {
+    File[] files = folder.listFiles();
+    
+    if (files != null) {
+      for (File f : files)
+      {
+        if ((f.getName().endsWith(".jar") || f.getName().endsWith(".war")) && f.isDirectory())
+        {
+          File manifestFile = new File(f, "META-INF/MANIFEST.MF");
+          Manifest m;
+          
+          if (manifestFile.isFile())
+            m = new Manifest(new FileInputStream(manifestFile));
+          else
+          {
+            m = new Manifest();
+            m.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+          }
+            
+          File jarFile = new File(tempDir, prefix + f.getName());
+          jarFile.getParentFile().mkdirs();
+          
+          IOUtils.jarUp(f, jarFile, m); 
+        }
+        else if (f.isFile())
+        {
+          IOUtils.writeOut(tempDir, prefix + f.getName(), new FileInputStream(f));
+        }
+        else if (f.isDirectory())
+        {
+          createEbaRecursive(f, tempDir, prefix + f.getName() + File.separator);
+        }
+      }
+    }
+  }
+  
+  public static void cleanupEba(String outputFile)
+  {
+    new File(outputFile).delete();
+  }
+}

Added: aries/tags/application-0.2.1/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/bundles/repository/a.handy.persistence.library.jar/META-INF/MANIFEST.MF Sun Feb 27 20:02:48 2011
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: HandyPersistenceLibrary
+Bundle-SymbolicName: a.handy.persistence.library
+Bundle-Version: 1.1
+Bundle-Vendor: Apache.org
+Export-Package: org.apache.handy.persistence
+

Added: aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/META-INF/APPLICATION.MF Sun Feb 27 20:02:48 2011
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Application-ManifestVersion: 1.0
+Application-Name: Test application
+Application-SymbolicName: org.apache.aries.application.management.test
+Application-Version: 1.0
+Application-Content: foo.bar.widgets;version=1.0.0,
+ my.business.logic;version=1.0.0
+

Added: aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/foo.bar.widgets.jar/META-INF/MANIFEST.MF Sun Feb 27 20:02:48 2011
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: FooBarWidgets
+Bundle-SymbolicName: foo.bar.widgets
+Bundle-Version: 1.1
+Bundle-Vendor: Apache.org
+Export-Package: foo.bar.widgets
+
+

Added: aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/bundles/test.eba/my.business.logic.jar/META-INF/MANIFEST.MF Sun Feb 27 20:02:48 2011
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: MyBusinessLogic
+Bundle-SymbolicName: my.business.logic
+Bundle-Version: 1.1
+Bundle-Vendor: Apache.org
+Export-Package: my.business.logic

Added: aries/tags/application-0.2.1/application-management/src/test/resources/conversion/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/conversion/MANIFEST.MF?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/conversion/MANIFEST.MF (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/conversion/MANIFEST.MF Sun Feb 27 20:02:48 2011
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: helloWorld.war
+Bundle-SymbolicName: helloWorld.war
+Bundle-Version: 0.0.0
+Bundle-Vendor: Apache.org
+Bundle-ContextPath: /test
+Export-Package: apache.org.helloWorldWar
+
+
+

Added: aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.jar/META-INF/MANIFEST.MF Sun Feb 27 20:02:48 2011
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: HelloWorldJar
+Bundle-SymbolicName: hello.world.jar
+Bundle-Version: 1.1.0
+Bundle-Vendor: Apache.org
+Export-Package: apache.org.helloWorldJar
+
+

Added: aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml (added)
+++ aries/tags/application-0.2.1/application-management/src/test/resources/conversion/conversion.eba/helloWorld.war/WEB-INF/web.xml Sun Feb 27 20:02:48 2011
@@ -0,0 +1,19 @@
+<!--
+    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.
+-->
+<web-app>
+<display-name>Hello World</display-name>
+</web-app> 

Added: aries/tags/application-0.2.1/application-obr-resolver/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/pom.xml?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/pom.xml (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/pom.xml Sun Feb 27 20:02:48 2011
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>application</artifactId>
+        <groupId>org.apache.aries.application</groupId>
+        <version>0.2.1</version>
+    </parent>
+    <artifactId>org.apache.aries.application.resolver.obr</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries Application OBR Resolver</name>
+    <description>
+      Implementation of the AriesApplicationResolver using OBR
+    </description>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.management</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.utils</artifactId>
+            <scope>provided</scope>
+        </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>

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/OBRAriesResolver.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,223 @@
+/*
+ * 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.resolver.obr;
+
+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 javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationResolver;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.resolver.obr.generator.RepositoryDescriptorGenerator;
+import org.apache.aries.application.resolver.obr.impl.ApplicationResourceImpl;
+import org.apache.aries.application.resolver.obr.impl.OBRBundleInfo;
+import org.apache.aries.application.resolver.obr.impl.ResourceWrapper;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+/**
+ * @version $Rev: 964138 $ $Date: 2010-07-14 20:03:40 +0100 (Wed, 14 Jul 2010) $
+ */
+public class OBRAriesResolver implements AriesApplicationResolver
+{
+  private static Logger log = LoggerFactory.getLogger(OBRAriesResolver.class);
+
+  private final RepositoryAdmin repositoryAdmin;  
+  private boolean returnOptionalResources = true;
+  
+  public OBRAriesResolver(RepositoryAdmin repositoryAdmin)
+  {
+    this.repositoryAdmin = repositoryAdmin;
+  }
+
+  public void setReturnOptionalResources(boolean optional) 
+  {
+    this.returnOptionalResources = optional;
+  }
+  
+  public boolean getReturnOptionalResources() 
+  {
+    return returnOptionalResources;
+  }
+    
+  public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException
+  {
+    log.trace("resolving {}", app);
+    DataModelHelper helper = repositoryAdmin.getHelper();
+
+    ApplicationMetadata appMeta = app.getApplicationMetadata();
+
+    String appName = appMeta.getApplicationSymbolicName();
+    Version appVersion = appMeta.getApplicationVersion();
+    List<Content> appContent = appMeta.getApplicationContents();
+
+    Repository appRepo;
+    
+    try {
+      Document doc = RepositoryDescriptorGenerator.generateRepositoryDescriptor(appName + "_" + appVersion, app.getBundleInfo());
+      
+      ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+      
+      TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(bytesOut));
+      
+      appRepo = helper.readRepository(new InputStreamReader(new ByteArrayInputStream(bytesOut.toByteArray())));
+    } catch (Exception e) {
+      throw new ResolverException(e);
+    } 
+        
+    List<Repository> resolveRepos = new ArrayList<Repository>();
+    
+    // add system repository
+    resolveRepos.add(repositoryAdmin.getSystemRepository());
+    
+    // add local repository
+    resolveRepos.add(getLocalRepository(repositoryAdmin));
+    
+    // add application repository
+    resolveRepos.add(appRepo);
+    
+    // add user-defined repositories
+    Repository[] repos = repositoryAdmin.listRepositories();
+    for (Repository r : repos) {
+      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, false);
+        result.add(bundleInfo);
+      }
+      if (returnOptionalResources) {
+        for (Resource resource: obrResolver.getOptionalResources()) {
+          BundleInfo bundleInfo = toBundleInfo(resource, true);
+          result.add(bundleInfo);
+        }
+      }
+      return result;
+    } else {
+      throw new ResolverException("Could not resolve requirements: " + getUnsatisfiedRequirements(obrResolver));
+    }
+  }
+
+  private Repository getLocalRepository(RepositoryAdmin admin) 
+  {
+      Repository localRepository = repositoryAdmin.getLocalRepository();
+      
+      Resource[] resources = localRepository.getResources();
+
+      Resource[] newResources = new Resource[resources.length];
+      for (int i = 0; i < resources.length; i++) {
+          newResources[i] = new ResourceWrapper(resources[i]); 
+      }
+      
+      return repositoryAdmin.getHelper().repository(newResources);
+  }
+  
+  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;
+    try {
+      resources = repositoryAdmin.discoverResources(filterString);
+      if (resources != null && resources.length > 0) {
+        return toBundleInfo(resources[0], false);
+      } else {
+        return null;
+      }
+    } catch (InvalidSyntaxException e) {
+      log.error("Invalid filter", e);
+      return null;
+    }
+  }
+
+  private String getUnsatisfiedRequirements(Resolver resolver)
+  {
+    Reason[] reqs = resolver.getUnsatisfiedRequirements();
+    if (reqs != null) {
+      StringBuilder sb = new StringBuilder();
+      for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
+        sb.append("   " + reqs[reqIdx].getRequirement().getFilter()).append("\n");
+        Resource resource = reqs[reqIdx].getResource();
+        sb.append("      " + resource.getPresentationName()).append("\n");
+      }
+      return sb.toString();
+    }
+    return null;
+  }
+
+  private BundleInfo toBundleInfo(Resource resource, boolean optional)
+  {
+    Map<String, String> directives = null;
+    if (optional) {
+      directives = new HashMap<String, String>();
+      directives.put(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL);
+    }
+    String location = resource.getURI();
+    return new OBRBundleInfo(resource.getSymbolicName(),
+                             resource.getVersion(),
+                             location,
+                             null,
+                             null,
+                             null,
+                             null,
+                             null, 
+                             null,
+                             directives,
+                             null);
+  }
+}

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/generator/RepositoryDescriptorGenerator.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,149 @@
+/*
+ * 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.resolver.obr.generator;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+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.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public final class RepositoryDescriptorGenerator
+{
+  public static Document generateRepositoryDescriptor(String name, Set<BundleInfo> bundles) throws ParserConfigurationException
+  {
+    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+    Element root = doc.createElement("repository");
+    
+    root.setAttribute("name", name);
+    doc.appendChild(root);
+    
+    for (BundleInfo info : bundles) {
+      Element resource = doc.createElement("resource");
+      resource.setAttribute(Resource.VERSION, info.getVersion().toString());
+      resource.setAttribute("uri", info.getLocation());
+      resource.setAttribute(Resource.SYMBOLIC_NAME, info.getSymbolicName());
+      resource.setAttribute(Resource.PRESENTATION_NAME, info.getHeaders().get(Constants.BUNDLE_NAME));
+      resource.setAttribute(Resource.ID, info.getSymbolicName() + "/" + info.getVersion());
+      root.appendChild(resource);
+      
+      addBundleCapability(doc, resource, info);
+      
+      for (Content p : info.getExportPackage()) {
+        addPackageCapability(doc, resource, info, p);
+      }
+      
+      for (Content p : info.getImportPackage()) {
+        addPackageRequirement(doc, resource, info, p);
+      }
+      
+      for (Content p : info.getRequireBundle()) {
+        addBundleRequirement(doc, resource, info, p);
+      }
+    }
+    
+    return doc;
+  }
+
+  private static void addBundleRequirement(Document doc, Element resource, BundleInfo info, Content p)
+  {
+    Element requirement = doc.createElement("require");
+    requirement.setAttribute("name", "bundle");
+    
+    requirement.setAttribute("extend", "false");
+    requirement.setAttribute("multiple", "false");
+    requirement.setAttribute("optional", "false");
+    
+    requirement.setAttribute("filter", ManifestHeaderProcessor.generateFilter("symbolicname", p.getContentName(), p.getAttributes()));
+    
+    resource.appendChild(requirement);
+  }
+
+  private static void addPackageRequirement(Document doc, Element resource, BundleInfo info, Content p)
+  {
+    Element requirement = doc.createElement("require");
+    requirement.setAttribute("name", "package");
+    
+    requirement.setAttribute("extend", "false");
+    requirement.setAttribute("multiple", "false");
+    
+    String optional = p.getDirective("optional");
+    if (optional == null) optional = "false";
+    
+    requirement.setAttribute("optional", optional);
+    
+    requirement.setAttribute("filter", ManifestHeaderProcessor.generateFilter("package", p.getContentName(), p.getAttributes()));
+    
+    resource.appendChild(requirement);
+  }
+
+  private static void addPackageCapability(Document doc, Element resource, BundleInfo info, Content p)
+  {
+    Element capability = doc.createElement("capability");
+    capability.setAttribute("name", "package");
+    resource.appendChild(capability);
+    
+    addProperty(doc, capability, "package", p.getContentName(), null);
+    addProperty(doc, capability, Constants.VERSION_ATTRIBUTE, p.getVersion().toString(), "version");
+    addProperty(doc, capability, Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, info.getSymbolicName(), null);
+    addProperty(doc, capability, Constants.BUNDLE_VERSION_ATTRIBUTE, info.getVersion().toString(), "version");
+    
+    for (Map.Entry<String, String> entry : p.getAttributes().entrySet()) {
+      if (!!!Constants.VERSION_ATTRIBUTE.equals(entry.getKey())) {
+        addProperty(doc, capability, entry.getKey(), entry.getValue(), null);
+      }
+    }
+    
+    String mandatory = p.getDirective(Constants.MANDATORY_DIRECTIVE);
+    if (mandatory == null) mandatory = "";
+    addProperty(doc, capability, Constants.MANDATORY_DIRECTIVE, mandatory, "set");
+  }
+
+  private static void addBundleCapability(Document doc, Element resource, BundleInfo info)
+  {
+    Element capability = doc.createElement("capability");
+    capability.setAttribute("name", "bundle");
+    resource.appendChild(capability);
+    
+    addProperty(doc, capability, Resource.SYMBOLIC_NAME, info.getSymbolicName(), null);
+    addProperty(doc, capability, Constants.VERSION_ATTRIBUTE, info.getVersion().toString(), "version");
+    addProperty(doc, capability, Resource.PRESENTATION_NAME, info.getHeaders().get(Constants.BUNDLE_NAME), null);
+    addProperty(doc, capability, Constants.BUNDLE_MANIFESTVERSION, "2", "version");
+    addProperty(doc, capability, Constants.FRAGMENT_ATTACHMENT_DIRECTIVE, info.getBundleDirectives().get(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE), null);
+    addProperty(doc, capability, Constants.SINGLETON_DIRECTIVE, info.getBundleDirectives().get(Constants.SINGLETON_DIRECTIVE), null);
+  }
+
+  private static void addProperty(Document doc, Element capability, String name,
+      String value, String type)
+  {
+    Element p = doc.createElement("p");
+    p.setAttribute("n", name);
+    p.setAttribute("v", value);
+    if (type != null) p.setAttribute("t", type);
+    capability.appendChild(p);
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ApplicationResourceImpl.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,165 @@
+/*
+ * 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.resolver.obr.impl;
+
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+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
+{
+  private String _symbolicName;
+  private Version _version;
+  private Requirement[] _requirements;
+  
+  private static class FilterWrapper implements Filter
+  {
+    private Filter delgate;
+    
+    public FilterWrapper(Filter f)
+    {
+      delgate = f;
+    }
+    
+    public boolean match(ServiceReference reference)
+    {
+      return delgate.match(reference);
+    }
+
+    public boolean match(Dictionary dictionary)
+    {
+      boolean result = delgate.match(dictionary);
+      return result;
+    }
+
+    public boolean matchCase(Dictionary dictionary)
+    {
+      return delgate.matchCase(dictionary);
+    }
+    
+    public String toString()
+    {
+      return delgate.toString();
+    }
+  }
+  
+  public ApplicationResourceImpl(String appName, Version appVersion, List<Content> appContent)
+  {
+    _symbolicName = appName;
+    _version = appVersion;
+    
+    _requirements = new Requirement[appContent.size()];
+    for (int i = 0; i < _requirements.length; i++) {
+      Content c = appContent.get(i);
+      
+      String comment = "Requires " + Resource.SYMBOLIC_NAME + " " + c.getContentName() + " with attributes " + c.getAttributes();
+      
+      String resolution = c.getDirective("resolution");
+
+      boolean optional = Boolean.valueOf(resolution);
+      
+      String f = ManifestHeaderProcessor.generateFilter(Resource.SYMBOLIC_NAME, c.getContentName(), c.getAttributes());
+      Filter filter;
+      try {
+        filter = FrameworkUtil.createFilter(f);
+        _requirements[i] = new RequirementImpl("bundle", new FilterWrapper(filter), false, optional, false, comment);
+      } catch (InvalidSyntaxException e) {
+        // TODO work out what to do if his happens. If it does our filter generation code is bust.
+      }
+    }
+  }
+  
+  public Capability[] getCapabilities()
+  {
+    return null;
+  }
+
+  public String[] getCategories()
+  {
+    return null;
+  }
+
+  public String getId()
+  {
+    return _symbolicName;
+  }
+
+  public String getPresentationName()
+  {
+    return _symbolicName;
+  }
+
+  public Map getProperties()
+  {
+    return null;
+  }
+
+  public Repository getRepository()
+  {
+    return null;
+  }
+
+  public Requirement[] getRequirements()
+  {
+    return _requirements;
+  }
+
+  public String getSymbolicName()
+  {
+    return _symbolicName;
+  }
+
+  public java.net.URL getURL()
+  {
+    return null;
+  }
+
+  public Version getVersion()
+  {
+    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

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/MapToDictionary.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/MapToDictionary.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/MapToDictionary.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/MapToDictionary.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,123 @@
+/*
+ * 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.resolver.obr.impl;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @version $Rev: 911397 $ $Date: 2010-02-18 13:41:27 +0000 (Thu, 18 Feb 2010) $
+ */
+public class MapToDictionary extends Dictionary
+{
+  /**
+   * Map source.
+   */
+  private final Map m_map;
+
+  public MapToDictionary(Map map)
+  {
+    m_map = map;
+  }
+
+  public Enumeration elements()
+  {
+    if (m_map == null) {
+      return null;
+    }
+    return new IteratorToEnumeration(m_map.values().iterator());
+  }
+
+  public Object get(Object key)
+  {
+    if (m_map == null) {
+      return null;
+    }
+    return m_map.get(key);
+  }
+
+  public boolean isEmpty()
+  {
+    if (m_map == null) {
+      return true;
+    }
+    return m_map.isEmpty();
+  }
+
+  public Enumeration keys()
+  {
+    if (m_map == null) {
+      return null;
+    }
+    return new IteratorToEnumeration(m_map.keySet().iterator());
+  }
+
+  public Object put(Object key, Object value)
+  {
+    throw new UnsupportedOperationException();
+  }
+
+  public Object remove(Object key)
+  {
+    throw new UnsupportedOperationException();
+  }
+
+  public int size()
+  {
+    if (m_map == null) {
+      return 0;
+    }
+    return m_map.size();
+  }
+
+  @Override
+  public String toString()
+  {
+    return m_map != null ? m_map.toString() : "null";
+  }
+
+  private static class IteratorToEnumeration implements Enumeration
+  {
+    private final Iterator m_iter;
+
+    public IteratorToEnumeration(Iterator iter)
+    {
+      m_iter = iter;
+    }
+
+    public boolean hasMoreElements()
+    {
+      if (m_iter == null)
+        return false;
+      return m_iter.hasNext();
+    }
+
+    public Object nextElement()
+    {
+      if (m_iter == null)
+        return null;
+      return m_iter.next();
+    }
+  }
+
+}

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRBundleInfo.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRBundleInfo.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRBundleInfo.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/OBRBundleInfo.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,146 @@
+/*
+ * 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.resolver.obr.impl;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.management.BundleInfo;
+import org.osgi.framework.Version;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @version $Rev: 964138 $ $Date: 2010-07-14 20:03:40 +0100 (Wed, 14 Jul 2010) $
+ */
+public class OBRBundleInfo implements BundleInfo
+{
+
+  private final String symbolicName;
+  private final Version version;
+  private final String location;
+  private final Set<Content> importPackage;
+  private final Set<Content> exportPackage;
+  private final Set<Content> importService;
+  private final Set<Content> exportService;
+  private final Map<String, String> headers;
+  private final Set<Content> requireBundle;
+  private final Map<String, String> attributes;
+  private final Map<String, String> directives;
+
+  public OBRBundleInfo(String symbolicName, Version version, String location,
+                       Set<Content> importPackage, Set<Content> exportPackage,
+                       Set<Content> importService, Set<Content> exportService,
+                       Set<Content> requireBundle, Map<String, String> attributes,
+                       Map<String, String> directives, Map<String, String> headers)
+  {
+    this.symbolicName = symbolicName;
+    this.version = version;
+    this.location = location;
+    this.importPackage = importPackage;
+    this.exportPackage = exportPackage;
+    this.importService = importService;
+    this.exportService = exportService;
+    this.headers = headers;
+    this.requireBundle = requireBundle;
+    this.attributes = attributes;
+    this.directives = directives;
+  }
+
+  public String getSymbolicName()
+  {
+    return symbolicName;
+  }
+
+  public Version getVersion()
+  {
+    return version;
+  }
+
+  public String getLocation()
+  {
+    return location;
+  }
+
+  public Set<Content> getImportPackage()
+  {
+    return importPackage;
+  }
+
+  public Set<Content> getExportPackage()
+  {
+    return exportPackage;
+  }
+
+  public Set<Content> getImportService()
+  {
+    return importService;
+  }
+
+  public Set<Content> getExportService()
+  {
+    return exportService;
+  }
+
+  public Map<String, String> getHeaders()
+  {
+    return headers;
+  }
+
+  public Map<String, String> getBundleAttributes()
+  {
+    return attributes;
+  }
+
+  public Map<String, String> getBundleDirectives()
+  {
+    return directives;
+  }
+
+  public Set<Content> getRequireBundle()
+  {
+    return requireBundle;
+  }
+    
+  public String toString()
+  {
+    return symbolicName + "_" + version;
+  }
+
+  public int hashCode() 
+  {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + symbolicName.hashCode();
+    result = prime * result + version.hashCode();
+    return result;
+  }
+
+  public boolean equals(Object obj) {
+    if (this == obj) return true;
+    if (obj == null) return false;
+    if (getClass() != obj.getClass()) {
+        return false;
+    }
+    OBRBundleInfo other = (OBRBundleInfo) obj;
+    return (symbolicName.equals(other.symbolicName)
+            && version.equals(other.version));
+  }
+  
+}

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/RequirementImpl.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.resolver.obr.impl;
+
+import org.osgi.framework.Filter;
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Requirement;
+
+/**
+ * @version $Rev: 954793 $ $Date: 2010-06-15 11:28:34 +0100 (Tue, 15 Jun 2010) $
+ */
+public class RequirementImpl implements Requirement
+{
+  private final String name;
+  private final Filter filter;
+  private final boolean multiple;
+  private final boolean optional;
+  private final boolean extend;
+  private final String comment;
+
+  public RequirementImpl(String name, Filter filter, boolean multiple, boolean optional, boolean extend, String comment)
+  {
+    this.name = name;
+    this.filter = filter;
+    this.multiple = multiple;
+    this.optional = optional;
+    this.extend = extend;
+    this.comment = comment;
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public String getFilter()
+  {
+    return filter.toString();
+  }
+
+  public boolean isMultiple()
+  {
+    return multiple;
+  }
+
+  public boolean isOptional()
+  {
+    return optional;
+  }
+
+  public boolean isExtend()
+  {
+    return extend;
+  }
+
+  public String getComment()
+  {
+    return comment;
+  }
+
+  public boolean isSatisfied(Capability capability)
+  {
+    return filter.match(new MapToDictionary(capability.getPropertiesAsMap()));
+  }
+}

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ResourceWrapper.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ResourceWrapper.java (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/java/org/apache/aries/application/resolver/obr/impl/ResourceWrapper.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.resolver.obr.impl;
+
+import java.util.Map;
+
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Requirement;
+import org.apache.felix.bundlerepository.Resource;
+import org.osgi.framework.Version;
+
+/**
+ * @version $Rev: 964138 $ $Date: 2010-07-14 20:03:40 +0100 (Wed, 14 Jul 2010) $
+ */
+public class ResourceWrapper implements Resource {
+
+    private final Resource resource;
+    
+    public ResourceWrapper(Resource resource) {
+        this.resource = resource;
+    }
+    
+    public Capability[] getCapabilities() {
+        return resource.getCapabilities();
+    }
+
+    public String[] getCategories() {
+        return resource.getCategories();
+    }
+
+    public String getId() {
+        return resource.getId();
+    }
+
+    public String getPresentationName() {
+        return resource.getPresentationName();
+    }
+
+    public Map getProperties() {
+        return resource.getProperties();
+    }
+
+    public Requirement[] getRequirements() {
+        return resource.getRequirements();
+    }
+
+    public Long getSize() {
+        return resource.getSize();
+    }
+
+    public String getSymbolicName() {
+        return resource.getSymbolicName();
+    }
+
+    public String getURI() {
+        return resource.getURI();
+    }
+
+    public Version getVersion() {
+        return resource.getVersion();
+    }
+
+    public boolean isLocal() {
+        return false;
+    }
+
+}

Added: aries/tags/application-0.2.1/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml (added)
+++ aries/tags/application-0.2.1/application-obr-resolver/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml Sun Feb 27 20:02:48 2011
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <bean id="obr-resolver" class="org.apache.aries.application.resolver.obr.OBRAriesResolver" scope="singleton"
+          activation="eager">
+        <argument>
+            <reference interface="org.apache.felix.bundlerepository.RepositoryAdmin"/>
+        </argument>
+    </bean>
+
+    <service interface="org.apache.aries.application.management.AriesApplicationResolver" ref="obr-resolver"/>
+
+</blueprint>

Added: aries/tags/application-0.2.1/application-runtime/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-runtime/pom.xml?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-runtime/pom.xml (added)
+++ aries/tags/application-0.2.1/application-runtime/pom.xml Sun Feb 27 20:02:48 2011
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
+        <artifactId>application</artifactId>
+        <groupId>org.apache.aries.application</groupId>
+        <version>0.2.1</version>
+    </parent>
+    
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>org.apache.aries.application.runtime</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries Application Runtime</name>
+    <description>
+        A very basic runtime implementation
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.utils</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.testsupport</groupId>
+            <artifactId>org.apache.aries.testsupport.unit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

Added: aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/DefaultLocalPlatform.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/DefaultLocalPlatform.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/DefaultLocalPlatform.java (added)
+++ aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/DefaultLocalPlatform.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.runtime.defaults;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.aries.application.management.LocalPlatform;
+
+public class DefaultLocalPlatform implements LocalPlatform {
+
+  public File getTemporaryDirectory() throws IOException {
+    File f = File.createTempFile("ebaTmp", null);
+    f.delete();
+    f.mkdir();
+    return f;
+  } 
+  public File getTemporaryFile () throws IOException { 
+    return File.createTempFile("ebaTmp", null);
+  }
+}

Added: aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java (added)
+++ aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/defaults/NoOpResolver.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.runtime.defaults;
+
+import java.util.Set;
+
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationResolver;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ResolveConstraint;
+import org.osgi.framework.Version;
+
+/** AriesApplicationManager requires that there be at least one 
+ * AriesApplicationResolver service present. This class provides a null 
+ * implementation: it simply returns the bundles that it was provided with - 
+ * enough to permit the testing of Aries applications that have no external 
+ * dependencies.   
+ */
+public class NoOpResolver implements AriesApplicationResolver {
+
+  public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) {
+    return app.getBundleInfo();
+  }
+
+  public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion)
+  {
+    return null;
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java (added)
+++ aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextImpl.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,210 @@
+/*
+ * 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 WARRANTIESOR 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.runtime.impl;
+
+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 org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationContext;
+import org.apache.aries.application.management.AriesApplicationResolver;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ManagementException;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+public class ApplicationContextImpl implements AriesApplicationContext {
+  
+  private AriesApplication _application;
+  private Map<BundleInfo, Bundle> _bundles;
+  private ApplicationState _state;
+  private BundleContext _bundleContext;
+  
+  public ApplicationContextImpl (BundleContext b, AriesApplication app) throws BundleException, ManagementException { 
+    _bundleContext = b;
+    _application = app;
+    _bundles = new HashMap<BundleInfo, Bundle>();
+    
+    DeploymentMetadata meta = _application.getDeploymentMetadata();
+                
+    AriesApplicationResolver resolver = null;
+    PackageAdmin packageAdmin = null;
+    
+    ServiceReference resolverRef = b.getServiceReference(AriesApplicationResolver.class.getName());
+    ServiceReference packageAdminRef = b.getServiceReference(PackageAdmin.class.getName());
+    
+    try {            
+      resolver = getService(resolverRef, AriesApplicationResolver.class);
+      packageAdmin = getService(packageAdminRef, PackageAdmin.class);
+    
+      List<DeploymentContent> bundlesToInstall = new ArrayList<DeploymentContent>(meta.getApplicationDeploymentContents());
+      bundlesToInstall.addAll(meta.getApplicationProvisionBundles());
+    
+      for (DeploymentContent content : bundlesToInstall) {
+        String bundleSymbolicName = content.getContentName();
+        Version bundleVersion = content.getExactVersion();
+        
+        // Step 1: See if bundle is already installed in the framework
+        if (findBundleInFramework(packageAdmin, bundleSymbolicName, bundleVersion) != null) {
+            continue;
+        }
+        
+        // Step 2: See if the bundle is included in the application
+        BundleInfo bundleInfo = findBundleInfoInApplication(bundleSymbolicName, bundleVersion);
+        if (bundleInfo == null) {
+            // Step 3: Lookup bundle location using the resolver
+            bundleInfo = findBundleInfoUsingResolver(resolver, bundleSymbolicName, bundleVersion);
+        }
+        
+        if (bundleInfo == null) {
+            throw new ManagementException("Cound not find bundles: " + bundleSymbolicName + "_" + bundleVersion);
+        }
+            
+        Bundle bundle = _bundleContext.installBundle(bundleInfo.getLocation());
+            
+        _bundles.put(bundleInfo, bundle);        
+      }
+    } catch (BundleException be) {
+      for (Bundle bundle : _bundles.values()) {
+        bundle.uninstall();
+      }
+      
+      _bundles.clear();
+      
+      throw be;
+    } finally {
+      if (resolver != null) {
+          b.ungetService(resolverRef);
+      }
+      if (packageAdmin != null) {
+          b.ungetService(packageAdminRef);
+      }
+    }
+    
+    _state = ApplicationState.INSTALLED;
+  }
+
+  private <T> T getService(ServiceReference ref, Class<T> type) throws ManagementException {
+      Object service = null;
+      if (ref != null) {
+          service = _bundleContext.getService(ref);
+      }
+      
+      if (service == null) {
+          throw new ManagementException(new ServiceException(type.getName(), ServiceException.UNREGISTERED));
+      }
+      
+      return type.cast(service);
+  }
+  
+  private Bundle findBundleInFramework(PackageAdmin admin, String symbolicName, Version version) {
+      String exactVersion = "[" + version + "," + version + "]";
+      Bundle[] bundles = admin.getBundles(symbolicName, exactVersion);
+      if (bundles != null && bundles.length == 1) {
+          return bundles[0];
+      } else {
+          return null;
+      }
+  }
+  
+  private BundleInfo findBundleInfoInApplication(String symbolicName, Version version) {
+      for (BundleInfo info : _application.getBundleInfo()) {
+          if (info.getSymbolicName().equals(symbolicName)
+              && info.getVersion().equals(version)) {
+              return info;
+          }
+      }
+      return null;
+  }
+  
+  private BundleInfo findBundleInfoUsingResolver(AriesApplicationResolver resolver, String symbolicName, Version version) {
+      return resolver.getBundleInfo(symbolicName, version);
+  }
+  
+  public AriesApplication getApplication() {
+    return _application;
+  }
+  
+  public Set<Bundle> getApplicationContent() {
+    Set<Bundle> result = new HashSet<Bundle>();
+    for (Map.Entry<BundleInfo, Bundle> entry : _bundles.entrySet()) { 
+      result.add (entry.getValue());
+    }
+    return result;
+  } 
+
+  public ApplicationState getApplicationState() {
+    return _state;
+  }
+
+  public void start() throws BundleException 
+  {
+    _state = ApplicationState.STARTING;
+    
+    List<Bundle> bundlesWeStarted = new ArrayList<Bundle>();
+    
+    try {
+      for (Bundle b : _bundles.values()) { 
+        if (b.getState() != Bundle.ACTIVE) { 
+          b.start(Bundle.START_ACTIVATION_POLICY);
+          bundlesWeStarted.add(b);
+        }
+      }
+    } catch (BundleException be) {
+      for (Bundle b : bundlesWeStarted) {
+        try {
+          b.stop();
+        } catch (BundleException be2) {
+          // we are doing tidyup here, so we don't want to replace the bundle exception
+          // that occurred during start with one from stop. We also want to try to stop
+          // all the bundles we started even if some bundles wouldn't stop.
+        }
+      }
+      
+      _state = ApplicationState.INSTALLED;
+      throw be;
+    }
+    _state = ApplicationState.ACTIVE;
+  }
+
+  public void stop() throws BundleException {
+    for (Map.Entry<BundleInfo, Bundle> entry : _bundles.entrySet()) { 
+      Bundle b = entry.getValue();
+      b.stop();
+    }
+    _state = ApplicationState.RESOLVED;
+  }
+
+  public void setState(ApplicationState state)
+  {
+    _state = state;
+  }
+}

Added: aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java?rev=1075127&view=auto
==============================================================================
--- aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java (added)
+++ aries/tags/application-0.2.1/application-runtime/src/main/java/org/apache/aries/application/runtime/impl/ApplicationContextManagerImpl.java Sun Feb 27 20:02:48 2011
@@ -0,0 +1,113 @@
+/*
+ * 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 WARRANTIESOR 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.runtime.impl;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.AriesApplicationContext;
+import org.apache.aries.application.management.AriesApplicationContextManager;
+import org.apache.aries.application.management.ManagementException;
+import org.apache.aries.application.management.AriesApplicationContext.ApplicationState;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class ApplicationContextManagerImpl implements AriesApplicationContextManager {
+
+  private ConcurrentMap<AriesApplication, ApplicationContextImpl> _appToContextMap;
+  private BundleContext _bundleContext;
+  
+  public ApplicationContextManagerImpl () { 
+    _appToContextMap = new ConcurrentHashMap<AriesApplication, ApplicationContextImpl>();
+  }
+  
+  public void setBundleContext (BundleContext b) { 
+    _bundleContext = b;
+  }
+  
+  public AriesApplicationContext getApplicationContext(AriesApplication app) throws BundleException, ManagementException {
+    ApplicationContextImpl result;
+    if (_appToContextMap.containsKey(app)) { 
+      result = _appToContextMap.get(app);
+    } else { 
+      result = new ApplicationContextImpl (_bundleContext, app);
+      ApplicationContextImpl previous = _appToContextMap.putIfAbsent(app, result);
+      if (previous != null) { 
+        result = previous;
+      }
+    }
+    return result;
+  }
+
+  public Set<AriesApplicationContext> getApplicationContexts() {
+    Set<AriesApplicationContext> result = new HashSet<AriesApplicationContext>();
+    for (Map.Entry<AriesApplication, ApplicationContextImpl> entry: _appToContextMap.entrySet()) {
+      result.add (entry.getValue());
+    }
+    return result;
+  }
+
+  public void remove(AriesApplicationContext app)
+  {
+    Iterator<Map.Entry<AriesApplication, ApplicationContextImpl>> it = _appToContextMap.entrySet().iterator();
+    
+    while (it.hasNext()) {
+      Map.Entry<AriesApplication, ApplicationContextImpl> entry = it.next();
+      
+      ApplicationContextImpl potentialMatch = entry.getValue();
+      
+      if (potentialMatch == app) {
+        it.remove();
+
+        uninstall(potentialMatch);
+
+        break;
+      }
+    }
+  }
+
+  private void uninstall(ApplicationContextImpl app)
+  {
+    Set<Bundle> bundles = app.getApplicationContent();
+    for (Bundle b : bundles) {
+      try {
+        b.uninstall();
+      } catch (BundleException be) {
+        // TODO ignoring this feels wrong, but I'm not sure how to communicate to the caller multiple failures. 
+      }
+    }
+    app.setState(ApplicationState.UNINSTALLED);
+  }
+  
+  public void close()
+  {
+    for (ApplicationContextImpl ctx : _appToContextMap.values()) {
+      uninstall(ctx);
+    }
+    
+    _appToContextMap.clear();
+  }
+}
\ No newline at end of file



Mime
View raw message