incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mnutt...@apache.org
Subject svn commit: r894899 - in /incubator/aries/trunk/application/application-management/src/main: java/org/apache/aries/application/management/impl/ resources/OSGI-INF/blueprint/
Date Thu, 31 Dec 2009 17:26:20 GMT
Author: mnuttall
Date: Thu Dec 31 17:26:19 2009
New Revision: 894899

URL: http://svn.apache.org/viewvc?rev=894899&view=rev
Log:
ARIES-89: Implement application support: More work on AriesApplicationManager.createApplication

Added:
    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/BundleInfoImpl.java
Modified:
    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
    incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
    incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml

Modified: incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java?rev=894899&r1=894898&r2=894899&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
(original)
+++ incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationImpl.java
Thu Dec 31 17:26:19 2009
@@ -21,7 +21,6 @@
 
 import java.io.File;
 import java.io.OutputStream;
-import java.net.URL;
 import java.util.List;
 import java.util.Set;
 
@@ -29,21 +28,26 @@
 import org.apache.aries.application.DeploymentMetadata;
 import org.apache.aries.application.management.AriesApplication;
 import org.apache.aries.application.management.BundleInfo;
-import org.osgi.framework.Bundle;
 
 public class AriesApplicationImpl implements AriesApplication {
 
-  public AriesApplicationImpl(ApplicationMetadata meta, List<Bundle> bundles) {}
-  public AriesApplicationImpl () {}
+  private Set<BundleInfo> _bundleInfo;
+  private ApplicationMetadata _applicationMetadata;
+  private DeploymentMetadata _deploymentMetadata;
+  
+  public AriesApplicationImpl(ApplicationMetadata meta, Set<BundleInfo> bundleInfo)
{
+    _applicationMetadata = meta;
+    _bundleInfo = bundleInfo;
+    _deploymentMetadata = null;
+    
+  }
   
   public ApplicationMetadata getApplicationMetadata() {
-    // TODO Auto-generated method stub
-    return null;
+    return _applicationMetadata;
   }
 
   public Set<BundleInfo> getBundles() {
-    // TODO Auto-generated method stub
-    return null;
+    return _bundleInfo;
   }
 
   public DeploymentMetadata getDeploymentMetadata() {
@@ -60,5 +64,9 @@
     // TODO Auto-generated method stub
 
   }
+  
+  public void setDeploymentMetadata (DeploymentMetadata dm) { 
+    _deploymentMetadata = dm;
+  }
 
 }

Modified: incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java?rev=894899&r1=894898&r2=894899&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
(original)
+++ incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java
Thu Dec 31 17:26:19 2009
@@ -21,34 +21,61 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
-import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import java.util.jar.Attributes;
 import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
 
 import org.apache.aries.application.ApplicationMetadata;
 import org.apache.aries.application.ApplicationMetadataManager;
+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.management.ApplicationContext;
 import org.apache.aries.application.management.ApplicationListener;
 import org.apache.aries.application.management.AriesApplication;
 import org.apache.aries.application.management.AriesApplicationManager;
+import org.apache.aries.application.management.AriesApplicationResolver;
+import org.apache.aries.application.management.BundleConverter;
+import org.apache.aries.application.management.BundleInfo;
 import org.apache.aries.application.management.ManagementException;
 import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.filesystem.FileSystem;
+import org.apache.aries.application.utils.manifest.BundleManifest;
 import org.apache.aries.application.utils.manifest.ManifestDefaultsInjector;
 import org.apache.aries.application.utils.manifest.ManifestProcessor;
-import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceException;
 
 public class AriesApplicationManagerImpl implements AriesApplicationManager {
 
   private ApplicationMetadataManager _applicationMetadataManager;
+  private DeploymentMetadataFactory _deploymentMetadataFactory;
+  private List<BundleConverter> _bundleConverters;
+  private AriesApplicationResolver _resolver;
 
   public void setApplicationMetadataManager (ApplicationMetadataManager amm) { 
     _applicationMetadataManager = amm;
   }
   
+  public void setDeploymentMetadataFactory (DeploymentMetadataFactory dmf) { 
+    _deploymentMetadataFactory = dmf;
+  }
+  
+  public void setBundleConverters (List<BundleConverter> bcs) { 
+    _bundleConverters = bcs;
+  }
+  
+  public void setResolver (AriesApplicationResolver resolver) { 
+    _resolver = resolver;
+  }
+  
   
   
   /**
@@ -61,52 +88,79 @@
      */    
 
     ApplicationMetadata applicationMetadata;
-    List<Bundle> bundlesInEba;
+    DeploymentMetadata deploymentMetadata;
+    Map<String, InputStream> modifiedBundles = new HashMap<String, InputStream>();
+    AriesApplicationImpl application = null;
     
     try { 
       if (!ebaFile.isFile()) { 
+        // TODO: NLS this, and implement create-from-directory
         throw new ManagementException ("Cannot create .eba from directory yet");
       }
-      ZipFile zipFile = new ZipFile(ebaFile);
-      Manifest applicationManifest = new Manifest();
       
-      // TODO: If there's a deployment.mf we can ignore the rest of the content
-      
-      // Locate META-INF/APPLICATION.MF
-      ZipEntry entry = null;
-      Enumeration<? extends ZipEntry> entries = zipFile.entries();
-      while (entries.hasMoreElements()) {
-        entry = entries.nextElement();
-        if (entry.getName().replace("\\", "/").equalsIgnoreCase(AppConstants.APPLICATION_MF))
{
-          applicationManifest = ManifestProcessor.parseManifest(zipFile.getInputStream(entry));
-          break;
-        }
-        // Also look for application.xml to support .war file migration
-      }
-
-      // Ensure that the manifest has the necessary fields set 
+      // Locate META-INF/APPLICATION.MF and ensure that the 
+      // manifest has the necessary fields set 
+      Manifest applicationManifest = parseManifest (ebaFile, AppConstants.APPLICATION_MF);
       boolean manifestChanged = ManifestDefaultsInjector.updateManifest(applicationManifest,
ebaFile.getName(), ebaFile); 
-      
       applicationMetadata = _applicationMetadataManager.createApplicationMetadata(applicationManifest);
+
+      Manifest deploymentManifest = parseManifest (ebaFile, AppConstants.DEPLOYMENT_MF);
+      if (deploymentManifest != null) {
+        // If there's a deployment.mf present, check it matches applicationManifest, and
if so, use it
+      } else { 
+        //   -- Look for application.xml to support .war file migration
+        //   -- Process any other files in the .eba, i.e. migrate wars to wabs, plain jars
to bundles
+        IDirectory eba = FileSystem.getFSRoot(ebaFile);
+        IFile appXml = eba.getFile(AppConstants.APPLICATION_XML);
+        Set<BundleInfo> bundleInfo = new HashSet<BundleInfo>();
+        for (IFile f : eba) { 
+          BundleManifest bm = getBundleManifest (f);
+          if (bm != null) {
+            Attributes bundleAttributes;
+            if (bm.isValid()) {
+              bundleInfo.add(new BundleInfoImpl(bm, null));
+            } else { 
+              // We have a jar that needs converting to a bundle, or a war to migrate to
a WAB
+              InputStream is = null;
+              try { 
+                is = f.open();
+                InputStream convertedBinary = null;
+                Iterator<BundleConverter> converters = _bundleConverters.iterator();
+                while (converters.hasNext() && convertedBinary == null) { 
+                  try { 
+                    convertedBinary = converters.next().convert(is, f.getName());
+                  } catch (ServiceException sx) {
+                    // We'll get this if our optional BundleConverter has not been injected.

+                  }
+                }
+                if (convertedBinary != null) { 
+                  modifiedBundles.put (f.getName(), convertedBinary); // I expect I'll need
the filename in a bit
+                  bm = BundleManifest.fromBundle(is);
+                  bundleInfo.add(new BundleInfoImpl(bm, null));
+                }
+              } finally { 
+                try { 
+                  if (is != null) is.close();
+                } catch (IOException iox) {}
+              }
+            }
+          }
+        }
+        application = new AriesApplicationImpl (applicationMetadata, bundleInfo);
+        Set<BundleInfo> resolvedBundles = _resolver.resolve(application);
+        deploymentMetadata = _deploymentMetadataFactory.createDeploymentMetadata(application,
resolvedBundles);
+        application.setDeploymentMetadata(deploymentMetadata);
+      }
       
-      // Process any other files in the .eba
-      // i.e. migrate wars to wabs
-      
-      // Validate contents
-      
-      // Perform provisioning
-      
-      // Create deployment.mf if missing
-      
-      // Write out updated .eba if we changed its contents
+      // We may have changed parts of its content. The application's store()
+      // method needs to be able to work. Do something with modifiedBundles 
+      // and manifestChanged
       
     } catch (IOException iox) { 
       throw new ManagementException(iox);
     }
     
-    
-    // AriesApplication ariesApp = new AriesApplicationImpl (appMeta, bundlesInEba);
-    return null; // ariesApp
+    return application;
   }
 
   public AriesApplication createApplication(URL url) throws ManagementException {
@@ -144,4 +198,56 @@
 
 
 
+  /**
+   * Locate and parse an application or deployment.mf in an eba
+   * @param ebaFile An aries application file
+   * @param fileName META-INF/APPLICATION.MF or META-INF/DEPLOYMENT.MF
+   * @return parsed manifest, or null
+   * @throws IOException
+   */
+  private Manifest parseManifest (File ebaFile, String fileName) throws IOException {
+    Manifest result = null;
+    IDirectory eba = FileSystem.getFSRoot(ebaFile);
+    List<IFile> files = eba.listFiles();
+    for (IFile f : files) { 
+      if (f.getName().equalsIgnoreCase(fileName)) {
+        InputStream is = null;
+        try { 
+          is = f.open();
+          result = ManifestProcessor.parseManifest(is);
+          is.close();
+        } catch (IOException iox) { 
+          // TODO: log error
+          throw iox;
+        } finally { 
+          try { 
+            if (is != null) is.close();
+          } catch (IOException iox) {}
+        }
+        break;
+      }
+    }
+    return result;
+  }
+  
+  /**
+   * Extract a bundle manifest from an IFile representing a bundle
+   * @param file The bundle to extract the manifest from
+   * @return bundle manifest
+   */
+  private BundleManifest getBundleManifest(IFile file) throws IOException {
+    BundleManifest mf = null;
+    InputStream in = null;
+    try { 
+      in = file.open();
+      mf = BundleManifest.fromBundle(in);
+    } finally { 
+      try { 
+        if (in != null) in.close();
+      } catch (IOException iox) {}
+    }    
+    return mf;
+  } 
+  
+  
 }

Added: incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/BundleInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/BundleInfoImpl.java?rev=894899&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/BundleInfoImpl.java
(added)
+++ incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/BundleInfoImpl.java
Thu Dec 31 17:26:19 2009
@@ -0,0 +1,98 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.jar.Attributes;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.impl.ContentImpl;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+public class BundleInfoImpl implements BundleInfo {
+
+  private BundleManifest _bundleManifest;
+  private Attributes _attributes;
+  private Set<Content> _exportPackages = null;
+  private Set<Content> _importPackages = null;
+  private String _location;
+  
+  public BundleInfoImpl (BundleManifest bm, String location) { 
+    _bundleManifest = bm;
+    _attributes = _bundleManifest.getRawAttributes();
+    _location = location;
+  }
+  
+  public Set<Content> getExportPackage() {
+    if (_exportPackages == null) { 
+      _exportPackages = getContentSetFromHeader (_attributes, Constants.EXPORT_PACKAGE);
+    
+    }
+    return _exportPackages;
+  }
+  
+  public Map<String, String> getHeaders() {
+    Set<Entry<Object, Object>> headers = _attributes.entrySet();
+    Map<String, String> result = new HashMap<String, String>();
+    for (Entry<Object, Object> h: headers) { 
+      result.put((String)h.getKey(), (String)h.getValue());
+    }
+    return result;
+  }
+
+  public Set<Content> getImportPackage() {
+    if (_importPackages == null) { 
+      _importPackages = getContentSetFromHeader (_attributes, Constants.IMPORT_PACKAGE);
+    
+    }
+    return _importPackages;
+  }
+
+  public String getLocation() {
+    return _location;
+  }
+
+  public String getSymbolicName() {
+    return _bundleManifest.getSymbolicName();
+  }
+
+  public Version getVersion() {
+    return _bundleManifest.getVersion();
+  }
+
+  private Set<Content> getContentSetFromHeader (Attributes attributes, String key)
{ 
+    String header = _attributes.getValue(key);
+    List<String> splitHeader = ManifestHeaderProcessor.split(header, ",");
+    HashSet<Content> result = new HashSet<Content>();
+    for (String s: splitHeader) { 
+      result.add(new ContentImpl(s));
+    }
+    return result;
+  }
+}

Modified: incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml?rev=894899&r1=894898&r2=894899&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
(original)
+++ incubator/aries/trunk/application/application-management/src/main/resources/OSGI-INF/blueprint/app-management.xml
Thu Dec 31 17:26:19 2009
@@ -21,9 +21,20 @@
   
   <bean id="app-manager" class="org.apache.aries.application.management.impl.AriesApplicationManagerImpl"
scope="singleton" activation="lazy">
     <property name="applicationMetadataManager" ref="app-metadata-manager"/>
+    <property name="deploymentMetadataFactory" ref="deployment-metadata-factory"/>
+    <property name="bundleConverters" ref="bundle-converters"/>
+    <property name="resolver" ref="resolver"/>
   </bean>
   
-  <reference id="app-metadata-manager" interface="ApplicationMetadataManager"/>
+  <reference id="app-metadata-manager" interface="org.apache.aries.application.ApplicationMetadataManager"/>
+  <reference id="deployment-metadata-factory" interface="org.apache.aries.application.DeploymentMetadataFactory"/>
+  <reference-list id="bundle-converters" 
+                  interface="org.apache.aries.application.management.BundleConverter"
+                  availability="optional"/>
+  <reference id="resolver" interface="org.apache.aries.application.management.AriesApplicationResolver"/>
+             
   
+    
   <service interface="org.apache.aries.application.management.AriesApplicationManager"
ref="manager-service" />
+  
 </blueprint>



Mime
View raw message