aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r1075118 [5/7] - in /aries/tags/application-0.2-incubating: ./ 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/ appli...
Date Sun, 27 Feb 2011 18:53:06 GMT
Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,196 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.ServiceDeclaration;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.manifest.ManifestProcessor;
+import org.osgi.framework.Version;
+
+/**
+ * Implementation of ApplicationMetadata and DeploymentMetadata
+ *
+ */
+public final class ApplicationMetadataImpl implements ApplicationMetadata
+{
+  private String appSymbolicName;
+  private Version appVersion;
+  private String appName;
+  private String appScope;
+  private List<Content> appContents;
+  private List<ServiceDeclaration> importServices;
+  private List<ServiceDeclaration> exportServices;
+  private Manifest manifest;
+  
+  /**
+   * create the applicationMetadata from appManifest
+   * @param appManifest   the Application.mf manifest
+   */
+  public ApplicationMetadataImpl(Manifest appManifest) {
+
+    this.appContents = new ArrayList<Content>();
+    this.importServices = new ArrayList<ServiceDeclaration>();
+    this.exportServices = new ArrayList<ServiceDeclaration>();
+    setup(appManifest);
+    
+    // As of 7 Jan 2010 we have no setter methods. Hence it's currently 
+    // fine to keep a copy of appManifest, and to use it in the store()
+    // method.
+    manifest = appManifest;
+  }
+  
+  /**
+   * setup the application metadata from the appManifest
+   * @param appManifest     application.mf manifest
+   */
+  private void setup(Manifest appManifest) 
+  {
+    Map<String, String> appMap = readManifestIntoMap(appManifest);
+    
+    // configure the appSymbolicName and appVersion
+    this.appSymbolicName = appMap.get(AppConstants.APPLICATION_SYMBOLIC_NAME);
+    this.appVersion = new Version(appMap.get(AppConstants.APPLICATION_VERSION));
+    this.appName = appMap.get(AppConstants.APPLICATION_NAME);
+    this.appScope = this.appSymbolicName + "_" + this.appVersion.toString();
+    
+    if (this.appSymbolicName == null || this.appVersion == null) {
+      throw new IllegalArgumentException("Failed to create ApplicationMetadataImpl object from Manifest " + appManifest);
+    }
+    
+    // configure appContents
+    String applicationContents = appMap.get(AppConstants.APPLICATION_CONTENT);
+    List<String> appContentsArray = ManifestProcessor.split(applicationContents, ",");
+    for (String content : appContentsArray) {
+      this.appContents.add(new ContentImpl(content));
+    }
+    
+    // TODO: configure importServices + exportServices
+    
+  }
+  
+  /**
+   * Reads a manifest's main attributes into a String->String map.
+   * <p>
+   * Will always return a map, empty if the manifest had no attributes.
+   * 
+   * @param mf The manifest to read.
+   * @return Map of manifest main attributes.
+   */
+  private Map<String, String> readManifestIntoMap(Manifest mf){   
+    HashMap<String, String> props = new HashMap<String, String>();
+    
+    Attributes mainAttrs = mf.getMainAttributes();
+    if (mainAttrs!=null){
+      Set<Entry<Object, Object>> attributeSet =  mainAttrs.entrySet(); 
+      if (attributeSet != null){
+        // Copy all the manifest headers across. The entry set should be a set of
+        // Name to String mappings, by calling String.valueOf we do the conversion
+        // to a string and we do not NPE.
+        for (Map.Entry<Object, Object> entry : attributeSet) {
+          props.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
+        }
+      }    
+    }
+       
+    return props;
+  }  
+    
+  public List<Content> getApplicationContents()
+  {
+    return Collections.unmodifiableList(this.appContents);
+  }
+
+  public List<ServiceDeclaration> getApplicationExportServices()
+  {
+    return Collections.unmodifiableList(this.exportServices);
+  }
+
+  public List<ServiceDeclaration> getApplicationImportServices()
+  {
+    return Collections.unmodifiableList(this.importServices);
+  }
+
+  public String getApplicationSymbolicName()
+  {
+    return this.appSymbolicName;
+  }
+
+  public Version getApplicationVersion()
+  {
+    return this.appVersion;
+  }
+
+  public String getApplicationName() 
+  {
+    return this.appName;
+  }
+  
+  public String getApplicationScope() 
+  {
+    return appScope;
+  }
+  
+  public boolean equals(Object other)
+  {
+    if (other == this) return true;
+    if (other == null) return false;
+    if (other instanceof ApplicationMetadataImpl) {
+      return appScope.equals(((ApplicationMetadataImpl)other).appScope);
+    }
+    
+    return false;
+  }
+  
+  public int hashCode()
+  {
+    return appScope.hashCode();
+  }
+
+  public void store(File f) throws IOException {
+    FileOutputStream fos = new FileOutputStream (f);
+    store(fos);
+    fos.close();
+  }
+
+  public void store(OutputStream out) throws IOException {
+    if (manifest != null) {
+      Attributes att = manifest.getMainAttributes();
+      if ((att.getValue(Attributes.Name.MANIFEST_VERSION.toString())) == null) {
+        att.putValue(Attributes.Name.MANIFEST_VERSION.toString(), AppConstants.MANIFEST_VERSION);
+      }
+      manifest.write(out);
+    }
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,199 @@
+/*
+ * 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.impl;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.utils.internal.MessageUtil;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+
+/**
+ * Implementation of Content
+ *
+ */
+public final class ContentImpl implements Content
+{
+  private String contentName;
+  protected Map<String, String> attributes;
+  private Map<String, String> directives;
+  private NameValueMap<String, String> nameValueMap;
+  
+  /**
+   * 
+   * @param content  Application-Content, Import-Package content
+   */
+  public ContentImpl(String content) {
+    Map<String, NameValueMap<String, String>> appContentsMap = ManifestHeaderProcessor.parseImportString(content);
+    if (appContentsMap.size() != 1) {
+      throw new IllegalArgumentException(MessageUtil.getMessage("APPUTILS0004E",content));
+    }
+    for (Map.Entry<String, NameValueMap<String, String>> entry : appContentsMap.entrySet()) {
+      this.contentName = entry.getKey();
+      this.nameValueMap= entry.getValue();
+      setup();
+      break;
+    }
+  }
+  
+  public ContentImpl (String bundleSymbolicName, Version version) { 
+    this.contentName = bundleSymbolicName;
+    this.nameValueMap = new NameValueMap<String, String>();
+    nameValueMap.put("version", version.toString());
+    setup();
+  }
+  
+  /**
+   * 
+   * @param contentName  
+   * @param nameValueMap
+   */
+  public ContentImpl(String contentName, NameValueMap<String, String> nameValueMap) {
+    this.contentName = contentName;
+    this.nameValueMap= nameValueMap;
+    setup();
+  }
+  
+  public String getContentName() {
+    return this.contentName;
+  }
+  
+  public Map<String, String> getAttributes() {
+    return Collections.unmodifiableMap(this.attributes);
+  }
+  
+  public Map<String, String> getDirectives() {
+    return Collections.unmodifiableMap(this.directives);
+  }
+  
+  public String getAttribute(String key) {
+    String toReturn = this.attributes.get(key);
+    return toReturn;
+  }
+  
+  /**
+   * add key value to the attributes map
+   * @param key
+   * @param value
+   */
+  public void addAttribute(String key, String value) {
+    this.attributes.put(key, value);
+  }
+  
+  public String getDirective(String key) {
+    String toReturn = this.directives.get(key);
+    return toReturn;
+  }
+  
+  public NameValueMap<String, String> getNameValueMap() {
+    NameValueMap<String, String> nvm = new NameValueMap<String, String>();
+    for (String key : this.nameValueMap.keySet()) {
+      nvm.addToCollection(key, this.nameValueMap.get(key));
+    }
+    return nvm;
+  }
+  
+  /**
+   * add key value to the directives map
+   * @param key
+   * @param value
+   */
+  public void addDirective(String key, String value) {
+    this.directives.put(key, value);
+  }
+  
+  public VersionRange getVersion() {
+    VersionRange vi = null;
+    if (this.attributes.get(Constants.VERSION_ATTRIBUTE) != null 
+        && this.attributes.get(Constants.VERSION_ATTRIBUTE).length() > 0) {
+      vi = ManifestHeaderProcessor.parseVersionRange(this.attributes.get(Constants.VERSION_ATTRIBUTE));
+    } else {
+      // what if version is not specified?  let's interpret it as 0.0.0 
+      vi = ManifestHeaderProcessor.parseVersionRange("0.0.0");
+    }
+    return vi;
+  }
+  
+  @Override
+  public String toString()
+  {
+    return this.contentName + ";" + this.nameValueMap.toString();
+  }
+  
+  @Override
+  public boolean equals(Object other)
+  {
+    if (other == this) return true;
+    if (other == null) return false;
+    
+    if (other instanceof ContentImpl) {
+      ContentImpl otherContent = (ContentImpl)other;
+      
+      Map<String,String> attributesWithoutVersion = attributes;
+      
+      if (attributes.containsKey("version")) {
+        attributesWithoutVersion = new HashMap<String, String>(attributes);
+        attributesWithoutVersion.remove("version");
+      }
+      
+      Map<String, String> otherAttributesWithoutVersion = otherContent.attributes;
+      
+      if (otherContent.attributes.containsKey("version")) {
+        otherAttributesWithoutVersion = new HashMap<String, String>(otherContent.attributes);
+        otherAttributesWithoutVersion.remove("version");
+      }
+      
+      return contentName.equals(otherContent.contentName) && 
+             attributesWithoutVersion.equals(otherAttributesWithoutVersion) &&
+             directives.equals(otherContent.directives) &&
+             getVersion().equals(otherContent.getVersion());
+    }
+    
+    return false;
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    return contentName.hashCode();
+  }
+  
+  /**
+   * set up directives and attributes
+   */
+  protected void setup() {
+    this.attributes = new HashMap<String, String>();
+    this.directives = new HashMap<String, String>();
+    
+    for (String key : this.nameValueMap.keySet()) {
+      if (key.endsWith(":")) {
+        this.directives.put(key.substring(0, key.length() - 1), this.nameValueMap.get(key));
+      } else {
+        this.attributes.put(key, this.nameValueMap.get(key));
+      }
+    }
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentContentImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentContentImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentContentImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentContentImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,115 @@
+/*
+ * 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.impl;
+
+import java.util.Map;
+
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
+import org.osgi.framework.Version;
+
+public final class DeploymentContentImpl implements DeploymentContent {
+  
+  private ContentImpl _content;
+  
+  /**
+   * DeploymentContent relates to a bundle at a particular version. 
+   * We can therefore assume that the Version passed into this 
+   * constructor is the exact version in question. 
+   * @param bundleSymbolicName
+   * @param version
+   */
+  public DeploymentContentImpl (String bundleSymbolicName, Version version) {
+    NameValueMap<String, String> nvMap = new NameValueMap<String, String>();
+    nvMap.put(AppConstants.DEPLOYMENT_BUNDLE_VERSION, version.toString());
+    _content = new ContentImpl (bundleSymbolicName, nvMap);
+  }
+  
+  /**
+   * Construct a DeploymentContent from a string of the form, 
+   *   bundle.symbolic.name;deployedContent="1.2.3"
+   * @param deployedContent
+   */
+  public DeploymentContentImpl (String deployedContent) {
+    _content = new ContentImpl (deployedContent);
+  }
+  
+  public Version getExactVersion() {
+    return getVersion().getExactVersion();
+  }
+
+  public String getAttribute(String key) {
+    return _content.getAttribute(key);
+  }
+
+  public Map<String, String> getAttributes() {
+    return _content.getAttributes();
+  }
+
+  public String getContentName() {
+    return _content.getContentName();
+  }
+
+  public String getDirective(String key) {
+    return _content.getDirective(key);
+  }
+
+  public Map<String, String> getDirectives() {
+    return _content.getDirectives();
+  }
+
+  public VersionRange getVersion() {
+    String deployedVersion = _content.getAttribute(AppConstants.DEPLOYMENT_BUNDLE_VERSION);
+    VersionRange vr = null;
+    if (deployedVersion != null && deployedVersion.length() > 0) {
+      vr = ManifestHeaderProcessor.parseVersionRange(deployedVersion, true);
+    }
+    return vr;
+  }
+
+  @Override
+  public boolean equals(Object other) { 
+    if (other == null) 
+      return false;
+    if (this == other) 
+      return true;
+    if (other instanceof DeploymentContentImpl) {
+      return _content.equals(((DeploymentContentImpl) other)._content);
+    } else { 
+      return false;
+    }
+  }
+  
+  public int hashCode() {
+    return _content.hashCode();
+  }
+
+  public Map<String, String> getNameValueMap() {
+    return _content.getNameValueMap();
+  }
+  
+  public String toString()
+  {
+    return _content.toString();
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataFactoryImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataFactoryImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataFactoryImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataFactoryImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.DeploymentMetadataFactory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.utils.manifest.ManifestProcessor;
+
+public class DeploymentMetadataFactoryImpl implements DeploymentMetadataFactory {
+
+  public DeploymentMetadata createDeploymentMetadata(AriesApplication app,
+                                                     Set<BundleInfo> additionalBundlesRequired) throws ResolverException {
+    return new DeploymentMetadataImpl(app, additionalBundlesRequired);
+  }
+  
+  public DeploymentMetadata createDeploymentMetadata(IFile src) throws IOException { 
+    InputStream is = src.open();
+    try { 
+      return createDeploymentMetadata(is);
+    } finally { 
+      is.close();
+    }
+  }
+
+  public DeploymentMetadata createDeploymentMetadata(InputStream in) throws IOException {
+    return createDeploymentMetadata(ManifestProcessor.parseManifest(in));
+  }
+
+  public DeploymentMetadata createDeploymentMetadata(Manifest manifest) throws IOException {
+    return new DeploymentMetadataImpl(manifest);
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/DeploymentMetadataImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,161 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentContent;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.management.ResolverException;
+import org.apache.aries.application.utils.AppConstants;
+import org.apache.aries.application.utils.manifest.ManifestProcessor;
+import org.osgi.framework.Version;
+
+public class DeploymentMetadataImpl implements DeploymentMetadata {
+  private ApplicationMetadata _applicationMetadata;
+  private List<DeploymentContent> _deploymentContent = new ArrayList<DeploymentContent>();
+  private List<DeploymentContent> _provisionSharedContent = new ArrayList<DeploymentContent>();
+  
+  public DeploymentMetadataImpl (AriesApplication app, Set<BundleInfo> bundlesRequired) throws ResolverException
+  {
+    _applicationMetadata = app.getApplicationMetadata();
+    _deploymentContent = new ArrayList<DeploymentContent>();
+    _provisionSharedContent = new ArrayList<DeploymentContent>();
+    
+    Map<String, VersionRange> appContent = new HashMap<String, VersionRange>();
+    
+    for (Content c : app.getApplicationMetadata().getApplicationContents()) {
+      appContent.put(c.getContentName(), c.getVersion());
+    }
+    
+    for (BundleInfo info : bundlesRequired) {
+      
+      VersionRange range = appContent.get(info.getSymbolicName());
+      
+      DeploymentContent dp = new DeploymentContentImpl(info.getSymbolicName(), info.getVersion());
+      
+      if (range == null) {
+        _provisionSharedContent.add(dp);
+      } else if (range.matches(info.getVersion())) {
+        _deploymentContent.add(dp);
+      } else {
+        throw new ResolverException("Bundle " + info.getSymbolicName() + " at version " + info.getVersion() + " is not in the range " + range);
+      }
+    }
+  }
+  
+  /**
+   * Construct a DeploymentMetadata from Manifest
+   * @param src
+   * @throws IOException
+   */
+  public DeploymentMetadataImpl(Manifest mf) { 
+    _applicationMetadata = new ApplicationMetadataImpl (mf);
+
+    Attributes attributes = mf.getMainAttributes();
+      
+    parseContent(attributes.getValue(AppConstants.DEPLOYMENT_CONTENT), _deploymentContent);
+    parseContent(attributes.getValue(AppConstants.PROVISION_CONTENT), _provisionSharedContent);
+  }
+
+  public List<DeploymentContent> getApplicationDeploymentContents() {
+    return Collections.unmodifiableList(_deploymentContent);
+  }
+  
+  public List<DeploymentContent> getApplicationProvisionBundles() {
+    return Collections.unmodifiableList(_provisionSharedContent);
+  }
+
+  public ApplicationMetadata getApplicationMetadata() {
+    return _applicationMetadata;
+  }
+
+  public String getApplicationSymbolicName() {
+    return _applicationMetadata.getApplicationSymbolicName();
+  }
+
+  public Version getApplicationVersion() {
+    return _applicationMetadata.getApplicationVersion();
+  }
+
+
+  public void store(File f) throws FileNotFoundException, IOException{
+    FileOutputStream fos = new FileOutputStream (f);
+    store(fos);
+    fos.close();
+  }
+
+  public void store(OutputStream out) throws IOException {
+    // We weren't built from a Manifest, so construct one. 
+    Manifest mf = new Manifest();
+    Attributes attributes = mf.getMainAttributes();
+    attributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), AppConstants.MANIFEST_VERSION);
+    attributes.putValue(AppConstants.APPLICATION_VERSION, getApplicationVersion().toString());
+    attributes.putValue(AppConstants.APPLICATION_SYMBOLIC_NAME, getApplicationSymbolicName());
+    if (!_deploymentContent.isEmpty()) {
+      attributes.putValue(AppConstants.DEPLOYMENT_CONTENT, getDeploymentContentsAsString(_deploymentContent));
+    }
+    if (!_provisionSharedContent.isEmpty()) {
+      attributes.putValue(AppConstants.PROVISION_CONTENT, getDeploymentContentsAsString(_provisionSharedContent));
+    }
+    mf.write(out);
+  }
+  
+  
+  
+  private String getDeploymentContentsAsString (List<DeploymentContent> content) { 
+    StringBuilder builder = new StringBuilder();
+    for (DeploymentContent dc : content) {
+      builder.append(dc.getContentName());
+      builder.append(';' + AppConstants.DEPLOYMENT_BUNDLE_VERSION + "=");
+      builder.append(dc.getExactVersion());
+      builder.append(",");
+    }
+    if (builder.length() > 0) { 
+      builder.deleteCharAt(builder.length() - 1);
+    }
+    return builder.toString();
+  }
+
+  private void parseContent(String content, List<DeploymentContent> contents)
+  {
+    List<String> pcList = ManifestProcessor.split(content, ",");
+    for (String s : pcList) {
+      contents.add(new DeploymentContentImpl(s));
+    }
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.impl;
+
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.ServiceDeclaration;
+
+/**
+ * this class represents the Import-Services and Export-Services
+ * in the Application.mf file
+ *
+ */
+public class ServiceDeclarationImpl implements ServiceDeclaration
+{
+  private static final String FILTER = "filter";
+  private String interfaceName;
+  private Filter filter;
+  
+  /**
+   * construct the ServiceDeclaration from the service string
+   * @param service A single service string value from the Import-Services or Export-Services header
+   * @throws InvalidSyntaxException
+   */
+  public ServiceDeclarationImpl(String service) throws InvalidSyntaxException 
+  {
+    Content content = new ContentImpl(service);
+    this.interfaceName = content.getContentName();
+    String filterString = content.getAttribute(FILTER);
+    if (filterString != null) {
+      try {
+        this.filter = FrameworkUtil.createFilter(filterString);
+      } catch (InvalidSyntaxException ise) {        
+        throw new InvalidSyntaxException("Failed to create filter for " + service, ise.getFilter(), ise.getCause());
+      }
+    }
+  }
+  
+  /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.ServiceDeclaration#getInterfaceName()
+ */
+  public String getInterfaceName() 
+  {
+    return this.interfaceName;
+  }
+  
+  /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.ServiceDeclaration#getFilter()
+ */
+  public Filter getFilter() 
+  {
+    return this.filter;
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java Sun Feb 27 18:52:58 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 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.impl;
+
+import org.apache.aries.application.VersionRange;
+import org.osgi.framework.Version;
+
+public final class VersionRangeImpl implements VersionRange {
+
+  private org.apache.aries.util.VersionRange versionRange;
+  /**
+   * 
+   * @param version   version for the verioninfo
+   */
+  public VersionRangeImpl(String version) {
+      versionRange = new org.apache.aries.util.VersionRange(version);
+  }
+
+  /**
+   * 
+   * @param version             version for the versioninfo
+   * @param exactVersion        whether this is an exact version
+   */
+  public VersionRangeImpl(String version, boolean exactVersion) {
+      versionRange = new org.apache.aries.util.VersionRange(version, exactVersion);
+  }
+
+  private VersionRangeImpl(org.apache.aries.util.VersionRange versionRange) {
+      this.versionRange = versionRange;
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.aries.application.impl.VersionRange#toString()
+   */
+  @Override
+  public String toString() {
+      return versionRange.toString();
+  }
+
+  @Override
+  public int hashCode() {
+      return versionRange.hashCode();
+  }
+  
+  @Override
+  public boolean equals(Object other) {
+      boolean result = false;
+      if (this == other) {
+          result = true;
+      } else if (other instanceof VersionRangeImpl) {
+          VersionRangeImpl vr = (VersionRangeImpl) other;   
+          result = versionRange.equals(vr.versionRange);
+      }
+      return result;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.aries.application.impl.VersionRange#getExactVersion()
+   */
+  public Version getExactVersion() {
+      return versionRange.getExactVersion();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.aries.application.impl.VersionRange#getMaximumVersion()
+   */
+  public Version getMaximumVersion() {
+      return versionRange.getMaximumVersion();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.aries.application.impl.VersionRange#getMinimumVersion()
+   */
+  public Version getMinimumVersion() {
+      return versionRange.getMinimumVersion();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.aries.application.impl.VersionRange#isMaximumExclusive()
+   */
+  public boolean isMaximumExclusive() {
+      return versionRange.isMaximumExclusive();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.aries.application.impl.VersionRange#isMaximumUnbounded()
+   */
+  public boolean isMaximumUnbounded() {
+      return versionRange.isMaximumUnbounded();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.aries.application.impl.VersionRange#isMinimumExclusive()
+   */
+  public boolean isMinimumExclusive() {
+      return versionRange.isMinimumExclusive();
+  }
+  
+  /**
+   * This method checks that the provided version matches the desired version.
+   * 
+   * @param version
+   *          the version.
+   * @return true if the version matches, false otherwise.
+   */
+  public boolean matches(Version version) {
+      return versionRange.matches(version);
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.aries.application.impl.VersionRange#isExactVersion()
+   */
+  public boolean isExactVersion() {
+      return versionRange.isExactVersion();
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.aries.application.impl.VersionRange#intersect(VersionRange
+   * range)
+   */
+  public VersionRange intersect(VersionRange r) {
+      VersionRangeImpl rr = (VersionRangeImpl) r;      
+      org.apache.aries.util.VersionRange result = versionRange.intersect(rr.versionRange);
+      return (result == null) ? null : new VersionRangeImpl(result);
+  }
+
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,68 @@
+/*
+ * 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.utils;
+
+
+/**
+ * Widely used constants in parsing Aries applications
+ */
+public interface AppConstants
+{
+  /** Trace group for this bundle */
+  public String TRACE_GROUP = "Aries.app.utils";
+
+  /** The Provision-Content header for the deployment.mf */
+  public static final String PROVISION_CONTENT = "Provision-Bundle";
+  
+  /** The application scope (used to find the applications bundle repository */
+  public static final String APPLICATION_SCOPE = "Application-Scope";
+  /** The application content directive for the application manifest */
+  public static final String APPLICATION_CONTENT = "Application-Content";
+  /** The application version directive for the application manifest */
+  public static final String APPLICATION_VERSION = "Application-Version";
+  /** The application name directive for the application manifest */
+  public static final String APPLICATION_NAME = "Application-Name";
+  /** The application symbolic name directive for the application manifest */
+  public static final String APPLICATION_SYMBOLIC_NAME = "Application-SymbolicName";
+  /** The default version for applications that do not have one */
+  public static final String DEFAULT_VERSION = "0.0.0";
+  /** The name of the application manifest in the application */
+  public static final String APPLICATION_MF = "META-INF/APPLICATION.MF";
+  /** The name of the deployment manifest in the application */
+  public static final String DEPLOYMENT_MF = "META-INF/DEPLOYMENT.MF";
+  /** The name of the META-INF directory   */
+  public static final String META_INF = "META-INF";
+  /** The name of an application.xml file which will be used in processing legacy .war files */
+  public static final String APPLICATION_XML = "META-INF/application.xml";
+  /** The expected lower case suffix of a jar file */
+  public static final String LOWER_CASE_JAR_SUFFIX = ".jar";
+  /** The expected lower case suffix of a war file */
+  public static final String LOWER_CASE_WAR_SUFFIX = ".war";
+  /** The attribute used to record the deployed version of a bundle */
+  public static final String DEPLOYMENT_BUNDLE_VERSION = "deployed-version";
+  /** The name of the bundle manifest */
+  public static final String MANIFEST_MF = "META-INF/MANIFEST.MF";
+  
+  public static final String MANIFEST_VERSION="1.0";
+  
+  /* The Deployed-Content header in DEPLOYMENT.MF records all the bundles
+   * to be deployed for a particular application. 
+   */
+  public static final String DEPLOYMENT_CONTENT = "Deployed-Content";
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/FileSystem.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/FileSystem.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/FileSystem.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/FileSystem.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,67 @@
+/*
+ * 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.utils.filesystem;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.utils.filesystem.impl.DirectoryImpl;
+import org.apache.aries.application.utils.filesystem.impl.ZipDirectory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An abstraction of a file system. A file system can be a zip, or a directory.
+ */
+public class FileSystem {
+
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.application.utils");
+
+  /**
+   * This method gets the IDirectory that represents the root of a virtual file
+   * system. The provided file can either identify a directory, or a zip file.
+   * 
+   * @param fs the zip file.
+   * @return   the root of the virtual FS.
+   */
+  public static IDirectory getFSRoot(File fs)
+  {
+    IDirectory dir = null;
+    
+    if (fs.exists()) {
+      if (fs.isDirectory()) {
+        dir = new DirectoryImpl(fs, fs);
+      } else if (fs.isFile()) {
+        try {
+          dir = new ZipDirectory(fs, fs);
+        } catch (IOException e) {
+          _logger.error ("IOException in IDirectory.getFSRoot", e);
+        }
+      }
+    }
+    else {
+      // since this method does not throw an exception but just returns null, make sure we do not lose the error
+      _logger.error("File not found in IDirectory.getFSRoot", new FileNotFoundException(fs.getPath()));
+    }
+    return dir;
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/IOUtils.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/IOUtils.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/IOUtils.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/IOUtils.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,205 @@
+/*
+ * 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.utils.filesystem;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.aries.application.utils.internal.MessageUtil;
+
+public class IOUtils
+{
+  /**
+   * Copy an InputStream to an OutputStream and close the InputStream afterwards.
+   */
+  public static void copy(InputStream in, OutputStream out) throws IOException
+  {
+    try {
+      int len;
+      byte[] b = new byte[1024];
+      while ((len = in.read(b)) != -1)
+        out.write(b,0,len);
+    }
+    finally {
+      close(in);
+    }
+  }
+  
+  /**
+   * Close some xStream for good :)
+   */
+  public static void close(Closeable c)
+  {
+    try {
+      if (c != null)
+        c.close();
+    }
+    catch (IOException e) { c=null; } //in other words do nothing in a language findbugs can understand 
+  }
+  
+  public static OutputStream getOutputStream(File outputDir, String relativePath) throws IOException
+  {
+    int lastSeparatorIndex = relativePath.replace(File.separatorChar,'/').lastIndexOf("/");
+    String dirName = null;
+    String fileName = null;
+    
+    File outputDirectory;
+    if (lastSeparatorIndex != -1)
+    {
+      dirName = relativePath.substring(0, lastSeparatorIndex);
+      fileName = relativePath.substring(lastSeparatorIndex + 1);
+
+      outputDirectory = new File(outputDir, dirName);
+      
+      if (!!!outputDirectory.exists() && !!!outputDirectory.mkdirs())
+        throw new IOException(MessageUtil.getMessage("APPUTILS0012E", relativePath));
+    }
+    else
+    {
+      outputDirectory = outputDir;
+      fileName = relativePath;
+    }
+    
+    File outputFile = new File(outputDirectory, fileName);
+    return new FileOutputStream(outputFile);
+  }
+  
+  /**
+   * Write the given InputStream to a file given by a root directory (outputDir) and a relative directory.
+   * Necessary subdirectories will be created. This method will close the supplied InputStream.
+   */
+  public static void writeOut(File outputDir, String relativePath, InputStream content) throws IOException
+  {
+    OutputStream out = null;
+    try {
+      out = getOutputStream(outputDir, relativePath);
+      IOUtils.copy(content, out);
+    }
+    finally {
+      close(out);
+    }
+  }
+  
+  /** 
+   * Zip up all contents of rootDir (recursively) into targetStream
+   */
+  @SuppressWarnings("unchecked")
+  public static void zipUp (File rootDir, OutputStream targetStream) throws IOException
+  {
+    ZipOutputStream out = null;
+    try { 
+      out = new ZipOutputStream (targetStream);
+      zipUpRecursive(out, "", rootDir, (Set<String>) Collections.EMPTY_SET);
+    } finally { 
+      close(out);
+    }
+  }
+  
+  /**
+   * Zip up all contents of rootDir (recursively) into targetFile
+   */
+  public static void zipUp(File rootDir, File targetFile) throws IOException
+  {
+    zipUp (rootDir, new FileOutputStream (targetFile));
+  }
+  
+  /**
+   * Jar up all the contents of rootDir (recursively) into targetFile and add the manifest
+   */
+  public static void jarUp(File rootDir, File targetFile, Manifest manifest) throws IOException
+  {
+    JarOutputStream out = null;
+    try {
+      out = new JarOutputStream(new FileOutputStream(targetFile), manifest);
+      zipUpRecursive(out, "", rootDir, new HashSet<String>(Arrays.asList("META-INF/MANIFEST.MF")));
+    }
+    finally {
+      close(out);
+    }
+  }
+  
+  /**
+   * Helper method used by zipUp
+   */
+  private static void zipUpRecursive(ZipOutputStream out, String prefix, 
+      File directory, Set<String> filesToExclude) throws IOException
+  {
+    File[] files = directory.listFiles();
+    if (files != null) 
+    {
+      for (File f : files)
+      {        
+        String fileName; 
+        if (f.isDirectory())
+          fileName = prefix + f.getName() + "/";
+        else
+          fileName = prefix + f.getName();
+        
+        if (filesToExclude.contains(fileName))
+          continue;
+        
+        ZipEntry ze = new ZipEntry(fileName);
+        ze.setSize(f.length());
+        ze.setTime(f.lastModified());
+        out.putNextEntry(ze);
+
+        if (f.isDirectory()) 
+          zipUpRecursive(out, fileName, f, filesToExclude);
+        else 
+        {
+          IOUtils.copy(new FileInputStream(f), out);
+        }
+      }
+    }
+  }
+  
+  /**
+   * Do rm -rf
+   */
+  public static boolean deleteRecursive(File root)
+  {
+    if (!!!root.exists())
+      return false;
+    else if (root.isFile())
+      return root.delete();
+    else {
+      boolean result = true;
+      for (File f : root.listFiles())
+      {
+        result = deleteRecursive(f) && result;
+      }
+      return root.delete() && result;
+    }
+  }
+}
+

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/DirectoryImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/DirectoryImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/DirectoryImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/DirectoryImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,121 @@
+/*
+ * 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.utils.filesystem.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.utils.AppConstants;
+
+/**
+ * An IDirectory representing a java.io.File whose isDirectory method returns true.
+ */
+public class DirectoryImpl extends FileImpl implements IDirectory
+{
+  /**
+   * @param dir      the file to represent.
+   * @param rootFile the file that represents the FS root.
+   */
+  public DirectoryImpl(File dir, File rootFile)
+  {
+    super(dir, rootFile);
+  }
+
+  public IFile getFile(String name)
+  {
+    File desiredFile = new File(file, name);
+    IFile result = null;
+    
+    if (desiredFile.exists()) 
+    {
+        if(!desiredFile.isDirectory())
+          result = new FileImpl(desiredFile, rootDirFile);
+        else
+          result = new DirectoryImpl(desiredFile, rootDirFile);
+    }
+    
+    return result;
+  }
+
+  public boolean isRoot()
+  {
+    boolean result = (rootDirFile == file);
+    return result;
+  }
+
+  public List<IFile> listFiles()
+  {
+    List<IFile> files = new ArrayList<IFile>();
+    File[] filesInDir = file.listFiles();
+    if (filesInDir != null) {
+      for (File f : filesInDir) {
+        if (f.isFile()) {
+          files.add(new FileImpl(f, rootDirFile));
+        } else if (f.isDirectory()) {
+          files.add(new DirectoryImpl(f, rootDirFile));
+        }
+      }
+    }
+    return files;
+  }
+
+  public Iterator<IFile> iterator()
+  {
+    Iterator<IFile> result = listFiles().iterator();
+    return result;
+  }
+
+  @Override
+  public IDirectory getParent()
+  {
+    IDirectory result = isRoot() ? null : super.getParent();
+    return result;
+  }
+
+  @Override
+  public IDirectory convert()
+  {
+    return this;
+  }
+
+  @Override
+  public InputStream open() throws IOException
+  {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public long getLastModified()
+  {
+    long result = super.getLastModified();
+    for (IFile aFile : this) {
+      long tmpLastModified = aFile.getLastModified();
+      
+      if (tmpLastModified > result) result = tmpLastModified;
+    }
+    return result;
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/FileImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,143 @@
+/*
+ * 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.utils.filesystem.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+
+/**
+ * An implementation of IFile that represents a java.io.File.
+ */
+public class FileImpl implements IFile
+{
+  
+  /** The name of the root directory of the file system */
+  protected String rootDir;
+  /** This file in the file system */
+  protected File file;
+  /** The root File in the file system */
+  protected File rootDirFile;
+  /** The name of this file in the vFS */
+  private String name;
+  
+  /**
+   * @param f        this file.
+   * @param rootFile the root of the vFS.
+   */
+  public FileImpl(File f, File rootFile)
+  {
+    file = f;
+    this.rootDirFile = rootFile;
+    rootDir = rootFile.getAbsolutePath();
+    
+    if (f == rootFile) name = "";
+    else name = file.getAbsolutePath().substring(rootDir.length() + 1);
+  }
+  
+  public IDirectory convert()
+  {
+    return null;
+  }
+
+  public long getLastModified()
+  {
+    long result = file.lastModified();
+    return result;
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public IDirectory getParent()
+  {
+    IDirectory parent = new DirectoryImpl(file.getParentFile(), rootDirFile);
+    return parent;
+  }
+
+  public long getSize()
+  {
+    long size = file.length();
+    return size;
+  }
+
+  public boolean isDirectory()
+  {
+    boolean result = file.isDirectory();
+    return result;
+  }
+
+  public boolean isFile()
+  {
+    boolean result = file.isFile();
+    return result;
+  }
+
+  public InputStream open() throws IOException
+  {
+    InputStream is = new FileInputStream(file);
+    return is;
+  }
+
+  public IDirectory getRoot()
+  {
+    IDirectory root = new DirectoryImpl(rootDirFile, rootDirFile);
+    return root;
+  }
+
+  public URL toURL() throws MalformedURLException
+  {
+    URL result = file.toURI().toURL();
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (obj == null) return false;
+    if (obj == this) return true;
+    
+    if (obj.getClass() == getClass()) {
+      return file.equals(((FileImpl)obj).file);
+    }
+    
+    return false;
+  }
+
+  @Override
+  public int hashCode()
+  {
+    return file.hashCode();
+  }
+  
+  @Override
+  public String toString()
+  {
+    return file.getAbsolutePath();
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipDirectory.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,232 @@
+/*
+ * 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.utils.filesystem.impl;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+
+/**
+ * A directory in the zip.
+ */
+public class ZipDirectory extends ZipFileImpl implements IDirectory
+{
+  /** The root of the zip FS. */
+  private ZipDirectory root;
+  
+  /**
+   * Constructs a directory in the zip.
+   * 
+   * @param zip1   the zip file.
+   * @param entry1 the entry in the zip representing this dir.
+   * @param parent the parent directory.
+   */
+  public ZipDirectory(File zip1, ZipEntry entry1, ZipDirectory parent)
+  {
+    super(zip1, entry1, parent);
+  }
+
+  /**
+   * This constructor creates the root of the zip.
+   * @param file
+   * @param fs
+   * @throws MalformedURLException 
+   */
+  public ZipDirectory(File file, File fs) throws MalformedURLException
+  {
+    super(file, fs);
+    root = this;
+  }
+
+  public IFile getFile(String name)
+  {
+    IFile result = null;
+    
+    String entryName = isRoot() ? name : getName() + "/" + name;
+    
+    ZipEntry entryFile = getEntry(entryName);
+    
+    if (entryFile != null) {
+      if (!!!entryFile.isDirectory()) {
+        result = new ZipFileImpl(zip, entryFile, buildParent(entryFile));
+      } else {
+        result = new ZipDirectory(zip, entryFile, buildParent(entryFile));
+      }
+    }
+    return result;
+  }
+
+  /**
+   * This method builds the parent directory hierarchy for a file.
+   * @param foundEntry
+   * @return the parent of the entry.
+   */
+  private ZipDirectory buildParent(ZipEntry foundEntry)
+  {
+    ZipDirectory result = this;
+    
+    String name = foundEntry.getName();
+    
+    name = name.substring(getName().length());
+    
+    String[] paths = name.split("/");
+    
+    StringBuilder baseBuilderCrapThingToGetRoundFindBugs = new StringBuilder(getName());
+    
+    if (!!!isRoot()) baseBuilderCrapThingToGetRoundFindBugs.append('/');
+    
+    if (paths != null && paths.length > 1) {
+      for (int i = 0; i < paths.length - 1; i++) {
+        String path = paths[i];
+        baseBuilderCrapThingToGetRoundFindBugs.append(path);
+        ZipEntry dirEntry = getEntry(baseBuilderCrapThingToGetRoundFindBugs.toString());
+        result = new ZipDirectory(zip, dirEntry, result);
+        baseBuilderCrapThingToGetRoundFindBugs.append('/');
+      }
+    }
+    return result;
+  }
+
+  public boolean isRoot()
+  {
+    boolean result = (root == this);
+    return result;
+  }
+
+  public List<IFile> listFiles()
+  {
+    List<IFile> files = new ArrayList<IFile>();
+    
+    ZipFile z = openZipFile();
+    Enumeration<? extends ZipEntry> entries = z.entries();
+    
+    while (entries.hasMoreElements()) {
+      ZipEntry possibleEntry = entries.nextElement();
+      
+      if (isInDir(possibleEntry)) {
+        if (possibleEntry.isDirectory()) {
+          files.add(new ZipDirectory(zip, possibleEntry, this));
+        } else {
+          files.add(new ZipFileImpl(zip, possibleEntry, this));
+        }
+      }
+    }
+    closeZipFile(z);
+    return files;
+  }
+
+  /**
+   * This method works out if the provided entry is inside this directory. It
+   * returns false if it is not, or if it is in a sub-directory.
+   * 
+   * @param possibleEntry
+   * @return true if it is in this directory.
+   */
+  private boolean isInDir(ZipEntry possibleEntry)
+  {
+    boolean result;
+    String name = possibleEntry.getName();
+    String parentDir = getName();
+    if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
+    result = (name.startsWith(parentDir) && !!!name.equals(parentDir) && name.substring(parentDir.length() + 1).indexOf('/') == -1);
+    return result;
+  }
+
+  public Iterator<IFile> iterator()
+  {
+    Iterator<IFile> result = listFiles().iterator();
+    return result;
+  }
+
+  @Override
+  public IDirectory convert()
+  {
+    return this;
+  }
+
+  @Override
+  public IDirectory getParent()
+  {
+    IDirectory result = isRoot() ? null : super.getParent();
+    return result;
+  }
+
+  @Override
+  public boolean isDirectory()
+  {
+    return true;
+  }
+
+  @Override
+  public boolean isFile()
+  {
+    return false;
+  }
+
+  @Override
+  public InputStream open() 
+  {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public IDirectory getRoot()
+  {
+    return root;
+  }
+  
+  // Although we only delegate to our super class if we removed this Findbugs
+  // would correctly point out that we add fields in this class, but do not
+  // take them into account for the equals method. In fact this is not a problem
+  // we do not care about the root when doing an equality check, but by including
+  // an equals or hashCode in here we can clearly document that we did this
+  // on purpose. Hence this comment.
+  @Override
+  public boolean equals(Object other)
+  {
+    return super.equals(other);
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    return super.hashCode();
+  }
+  
+  private ZipEntry getEntry(String entryName){
+    ZipFile z = openZipFile();
+    ZipEntry entryFile = null;
+    
+    if (z != null) {
+      entryFile = z.getEntry(entryName);
+      closeZipFile(z);
+    }
+    return entryFile;
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/filesystem/impl/ZipFileImpl.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,238 @@
+/*
+ * 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.utils.filesystem.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.apache.aries.application.filesystem.IDirectory;
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.utils.AppConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An implementation of IFile that represents a file entry in a zip.
+ */
+public class ZipFileImpl implements IFile
+{
+  /** A logger */
+  private static final Logger logger = LoggerFactory.getLogger("org.apache.aries.application.utils");
+
+  /** The name of the file */
+  private String name = "";
+  /** The size of the file */
+  private final long size;
+  /** The last time the file was updated */
+  private final long lastModified;
+  /** The zip file this is contained in */
+  protected File zip;
+  /** The entry in the zip this IFile represents */
+  protected ZipEntry entry;
+  /** The parent directory */
+  private ZipDirectory parent;
+  /** The URL of the zip file we are looking inside of */
+  private final String url;
+  
+  /**
+   * This constructor is used to create a file entry within the zip.
+   * 
+   * @param zip1    the zip file the entry is in.
+   * @param entry1  the entry this IFile represents.
+   * @param parent1 the parent directory.
+   */
+  public ZipFileImpl(File zip1, ZipEntry entry1, ZipDirectory parent1)
+  {
+    this.zip = zip1;
+    this.entry = entry1;
+    
+    name = entry1.getName();
+    
+    if (entry1.isDirectory()) name = name.substring(0, name.length() - 1);
+    
+    lastModified = entry1.getTime();
+    size = entry1.getSize();
+    
+    url = ((ZipFileImpl)parent1).url;
+    
+    this.parent = parent1;
+  }
+  
+  /**
+   * This is called to construct the root directory of the zip.
+   * 
+   * @param zip1 the zip file this represents.
+   * @param fs   the file on the fs.
+   * @throws MalformedURLException
+   */
+  protected ZipFileImpl(File zip1, File fs) throws MalformedURLException
+  {
+    this.zip = zip1;
+    this.entry = null;
+    name = "";
+    lastModified = fs.lastModified();
+    size = fs.length();
+    url = fs.toURI().toURL().toExternalForm();
+  }
+
+  public IDirectory convert()
+  {
+    return null;
+  }
+
+  public long getLastModified()
+  {
+    return lastModified;
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public IDirectory getParent()
+  {
+    return parent;
+  }
+
+  public long getSize()
+  {
+    return size;
+  }
+
+  public boolean isDirectory()
+  {
+    return false;
+  }
+
+  public boolean isFile()
+  {
+    return true;
+  }
+
+  public InputStream open() throws IOException
+  {
+    InputStream is = new SpecialZipInputStream(entry);
+    return is;
+  }
+  
+  public IDirectory getRoot()
+  {
+    IDirectory root = parent.getRoot();
+    return root;
+  }
+
+  public URL toURL() throws MalformedURLException
+  {
+    String entryURL = "jar:" + url + "!/" + getName();
+    URL result = new URL(entryURL);
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj)
+  {
+    if (obj == null) return false;
+    if (obj == this) return true;
+    
+    if (obj.getClass() == getClass()) {
+      return toString().equals(obj.toString());
+    }
+    
+    return false;
+  }
+
+  @Override
+  public int hashCode()
+  {
+    return toString().hashCode();
+  }
+
+  @Override
+  public String toString()
+  {
+    return url.substring(5)+ "/" + name;
+  }
+  
+  ZipFile openZipFile(){
+    ZipFile z = null;
+    try {
+      z = new ZipFile(zip);
+    } catch (ZipException e) {
+      logger.error ("ZipException in ZipFileImpl.openZipFile", e);
+    } catch (IOException e) {
+      logger.error ("IOException in ZipFileImpl.openZipFile", e);
+    }
+    return z;
+  }
+  
+  void closeZipFile(ZipFile z){
+    try{
+      z.close();
+    }
+    catch (IOException e) {
+      logger.error ("IOException in ZipFileImpl.closeZipFile", e);
+    }
+  }
+  
+  /**
+   * A simple class to delegate to the InputStream of the constructor
+   * and to call close on the zipFile when we close the stream.
+   *
+   */
+  private class SpecialZipInputStream extends InputStream{
+
+    private ZipFile zipFile;
+    private InputStream is;
+    
+    public SpecialZipInputStream(ZipEntry anEntry){
+      try{
+      this.zipFile = openZipFile();
+      this.is = zipFile.getInputStream(anEntry);
+      }
+      catch (ZipException e) {
+        logger.error ("ZipException in SpecialZipInputStream()", e);
+      } catch (IOException e) {
+        logger.error ("IOException in SpecialZipInputStream()", e);        
+      }
+    }
+    
+    @Override
+    public int read() throws IOException
+    {
+      return is.read();
+    }
+    
+    @Override
+    public void close() throws IOException{
+        //call close on the input stream, probably does nothing
+        is.close();
+        //call close on the zip file, important for tidying up
+        closeZipFile(zipFile);
+    }
+    
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/internal/MessageUtil.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/internal/MessageUtil.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/internal/MessageUtil.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/internal/MessageUtil.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.utils.internal;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+public class MessageUtil
+{
+  /** The resource bundle for blueprint messages */
+  private final static ResourceBundle messages = ResourceBundle.getBundle("org.apache.aries.application.utils.messages.APPUTILSmessages");
+  
+  /**
+   * Resolve a message from the bundle, including any necessary formatting.
+   * 
+   * @param key     the message key.
+   * @param inserts any required message inserts.
+   * @return        the message translated into the server local.
+   */
+  public static final String getMessage(String key, Object ... inserts)
+  {
+    String msg = messages.getString(key);
+    
+    if (inserts.length > 0)
+      msg = MessageFormat.format(msg, inserts);
+    
+    return msg;
+  }
+}

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/management/SimpleBundleInfo.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/management/SimpleBundleInfo.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/management/SimpleBundleInfo.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/management/SimpleBundleInfo.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,164 @@
+/*
+ * 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.utils.management;
+
+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.ApplicationMetadataFactory;
+import org.apache.aries.application.Content;
+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 final class SimpleBundleInfo implements BundleInfo {
+  private Content _symbolicName;
+  private Version _version;
+  private Attributes _attributes;
+  private Set<Content> _exportPackages = null;
+  private Set<Content> _importPackages = null;
+  private Set<Content> _exportServices = null;
+  private Set<Content> _importServices = null;
+  private Set<Content> _requireBundle = null;
+  
+  private String _location;
+  private ApplicationMetadataFactory _applicationMetadataFactory;
+  
+  public SimpleBundleInfo(ApplicationMetadataFactory amf, BundleManifest bm, String location) { 
+    _symbolicName = amf.parseContent(bm.getSymbolicName());
+    _version = bm.getVersion();
+    _attributes = bm.getRawAttributes();
+    _location = location;
+    _applicationMetadataFactory = amf;
+  }
+  
+  public Set<Content> getExportPackage() {
+    if (_exportPackages == null) { 
+      _exportPackages = getContentSetFromHeader (_attributes, Constants.EXPORT_PACKAGE);
+    }
+    return _exportPackages;
+  }
+  
+  public Set<Content> getExportService() {
+    if (_exportServices == null) {
+      _exportServices = getContentSetFromHeader (_attributes, Constants.EXPORT_SERVICE);
+    }
+    return _exportPackages;
+  }
+
+  public Map<String, String> getHeaders() {
+    Map<String, String> result = new HashMap<String, String>();
+    for (Entry<Object, Object> h: _attributes.entrySet()) {
+      Attributes.Name name = (Attributes.Name) h.getKey();
+      String value = (String) h.getValue();
+      result.put(name.toString(), value);
+    }
+    return result;
+  }
+
+  public Set<Content> getImportPackage() {
+    if (_importPackages == null) { 
+      _importPackages = getContentSetFromHeader (_attributes, Constants.IMPORT_PACKAGE);
+    }
+    return _importPackages;
+  }
+
+  public Set<Content> getImportService() {
+    if (_importServices == null) {
+      _importServices = getContentSetFromHeader (_attributes, Constants.IMPORT_SERVICE);
+    }
+    return _importServices;
+  }
+
+  public String getLocation() {
+    return _location;
+  }
+
+  public String getSymbolicName() {
+    return _symbolicName.getContentName();
+  }
+
+  public Version getVersion() {
+    return _version;
+  }
+
+  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) { 
+      Content c = _applicationMetadataFactory.parseContent(s);
+      result.add(c);
+    }
+    return result;
+  }
+
+  public Map<String, String> getBundleAttributes()
+  {
+    return _symbolicName.getAttributes();
+  }
+
+  public Map<String, String> getBundleDirectives()
+  {
+    return _symbolicName.getDirectives();
+  }
+
+  public Set<Content> getRequireBundle()
+  {
+    if (_requireBundle == null) {
+      _requireBundle = getContentSetFromHeader(_attributes, Constants.REQUIRE_BUNDLE);
+    }
+    
+    return _requireBundle;
+  }
+  
+  /**
+   * Equality is just based on the location. If you install a bundle from the same location string
+   * you get the same Bundle, even if the underlying bundle had a different symbolic name/version.
+   * This seems reasonable and quick.
+   */
+  public boolean equals(Object other)
+  {
+    if (other == null) return false;
+    if (other == this) return true;
+    if (other instanceof SimpleBundleInfo) {
+      return _location.equals(((SimpleBundleInfo)other)._location);
+    }
+    
+    return false;
+  }
+  
+  public int hashCode()
+  {
+    return _location.hashCode();
+  }
+  
+  public String toString()
+  {
+    return _symbolicName.getContentName() + "_" + getVersion();
+  }
+}
\ No newline at end of file

Added: aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/manifest/BundleManifest.java
URL: http://svn.apache.org/viewvc/aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/manifest/BundleManifest.java?rev=1075118&view=auto
==============================================================================
--- aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/manifest/BundleManifest.java (added)
+++ aries/tags/application-0.2-incubating/application-utils/src/main/java/org/apache/aries/application/utils/manifest/BundleManifest.java Sun Feb 27 18:52:58 2011
@@ -0,0 +1,198 @@
+/*
+ * 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.utils.manifest;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.aries.application.filesystem.IFile;
+import org.apache.aries.application.utils.filesystem.IOUtils;
+import org.apache.aries.application.utils.internal.MessageUtil;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValuePair;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Entity class to retrieve and represent a bundle manifest (valid or invalid).
+ */
+public class BundleManifest
+{
+  private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.application.utils");
+
+  /**
+   * Read a manifest from a jar input stream. This will find the manifest even if it is NOT
+   * the first file in the archive.
+   * 
+   * @param is
+   * @return
+   */
+  public static BundleManifest fromBundle(InputStream is) {
+    JarInputStream jarIs = null;
+    try {
+      jarIs = new JarInputStream(is);
+      Manifest m = jarIs.getManifest();
+      if (m != null)
+        return new BundleManifest(m);
+      else {
+        ZipEntry entry;
+        while ((entry = jarIs.getNextEntry()) != null) {
+          if (entry.getName().equals(MANIFEST_PATH))
+            return new BundleManifest(jarIs);
+        }
+        
+        return null;
+      }
+    }
+    catch (IOException e) {
+      _logger.error ("IOException in BundleManifest()", e);
+      return null;
+    }
+    finally {
+      IOUtils.close(jarIs);
+    }
+  }
+  
+  /**
+   * Retrieve a BundleManifest from the given jar file
+   * 
+   * @param f
+   * @return
+   */
+  public static BundleManifest fromBundle(IFile f) {
+    InputStream is = null;
+    try {
+      if (f.isDirectory()) {
+        IFile manFile = f.convert().getFile(MANIFEST_PATH);
+        if (manFile != null)
+          return new BundleManifest(manFile.open());
+        else
+          return null;
+      } else {
+        is = f.open();
+        return fromBundle(is);
+      }
+    } catch (IOException e) {
+      _logger.error ("IOException in BundleManifest.fromBundle(IFile)", e);
+      return null;
+    }
+    finally {
+      IOUtils.close(is);
+    }
+  }
+  
+  /**
+   * Retrieve a bundle manifest from the given jar file, which can be exploded or compressed
+   * 
+   * @param f
+   * @return
+   */
+  public static BundleManifest fromBundle(File f) {
+    if (f.isDirectory()) {
+      File manifestFile = new File(f, MANIFEST_PATH);
+      if (manifestFile.isFile())
+        try {
+          return new BundleManifest(new FileInputStream(manifestFile));
+        }
+        catch (IOException e) {
+          _logger.error ("IOException in BundleManifest.fromBundle(File)", e);
+          return null;
+        }
+      else
+        return null;
+    }
+    else  if (f.isFile()) {
+      try {
+        return fromBundle(new FileInputStream(f));
+      }
+      catch (IOException e) {
+        _logger.error ("IOException in BundleManifest.fromBundle(File)", e);
+        return null;
+      }
+    }
+    else {
+      throw new IllegalArgumentException(MessageUtil.getMessage("APPUTILS0007E", f.getAbsolutePath()));
+    }
+  }
+  
+  private Manifest manifest;
+  
+  /**
+   * Create a BundleManifest object from the InputStream to the manifest (not to the bundle)
+   * @param manifestIs
+   * @throws IOException
+   */
+  public BundleManifest(InputStream manifestIs) throws IOException {
+    this(ManifestProcessor.parseManifest(manifestIs));
+  }
+  
+  /**
+   * Create a BundleManifest object from a common Manifest object
+   * @param m
+   */
+  public BundleManifest(Manifest m) {
+    manifest = m;
+  }
+  
+  public String getSymbolicName() {
+    String rawSymName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+
+    String result = null;
+    if (rawSymName != null) {
+      NameValuePair<String, NameValueMap<String, String>> info = ManifestHeaderProcessor.parseBundleSymbolicName(rawSymName);
+      result = info.getName();
+    }
+    
+    return result;
+  }
+  
+  public Version getVersion() {
+    String specifiedVersion = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
+    Version result = (specifiedVersion == null) ? Version.emptyVersion : new Version(specifiedVersion);
+    
+    return result;
+  }
+  
+  public String getManifestVersion() {
+    return manifest.getMainAttributes().getValue(Constants.BUNDLE_MANIFESTVERSION);
+  }
+  
+  public Attributes getRawAttributes() {
+    return manifest.getMainAttributes();
+  }
+  
+  public Manifest getRawManifest() {
+    return manifest;
+  }
+  
+  public boolean isValid() {
+    return getManifestVersion() != null && getSymbolicName() != null;
+  }
+}
+



Mime
View raw message