aries-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alasdair Nottingham <...@apache.org>
Subject Re: svn commit: r887889 - in /incubator/aries/trunk/application/application-utils/src: main/java/org/apache/aries/application/ main/java/org/apache/aries/application/impl/ main/java/org/apache/aries/application/utils/manifest/ test/java/org/apache/ar
Date Mon, 07 Dec 2009 14:35:06 GMT
Oops,

2009/12/7 Lin Sun <linsun.unc@gmail.com>:
> Hi Alasdair,
>
> The newly added ApplicationMetadataImplTest file has an incompatible
> license, could you update that?
>
> Thx
>
> Lin
>
> On Mon, Dec 7, 2009 at 6:32 AM,  <not@apache.org> wrote:
>> Author: not
>> Date: Mon Dec  7 11:32:47 2009
>> New Revision: 887889
>>
>> URL: http://svn.apache.org/viewvc?rev=887889&view=rev
>> Log:
>> ARIES-52 improvements to manifest tests and bug fixes for parsing
>>
>> Added:
>>    incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ApplicationMetadataImplTest.java
>>    incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION2.MF
>>    incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION3.MF
>> Modified:
>>    incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataManager.java
>>    incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java
>>    incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerImpl.java
>>    incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerServiceImpl.java
>>    incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java
>>    incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java
>>    incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataManager.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataManager.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataManager.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataManager.java
Mon Dec  7 11:32:47 2009
>> @@ -40,6 +40,8 @@
>>    * @throws IOException if an IOException occurs reading from the stream.
>>    */
>>   public ApplicationMetadata parseApplication(InputStream in) throws IOException;
>> +  public Content parseContent(String content);
>> +  public VersionRange parseVersionRange(String versionRange);
>>   /**
>>    * Create the application metadata from the provided Manifest. This is provided
>>    * so application metadata can be created from within the JVM. When reading
>> @@ -71,4 +73,13 @@
>>    * @return    true if the application was registered, false otherwise.
>>    */
>>   public boolean registerApplication(ApplicationMetadata app);
>> +
>> +  /**
>> +   * This method is used to remove a previously registered application. An
>> +   * application can only be removed by the bundle that registered the application.
>> +   *
>> +   * @param app the application to remove.
>> +   * @return    true if the application was removed, false otherwise.
>> +   */
>> +  public boolean unregisterApplication(ApplicationMetadata app);
>>  }
>> \ No newline at end of file
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java
Mon Dec  7 11:32:47 2009
>> @@ -40,11 +40,12 @@
>>  * Implementation of ApplicationMetadata and DeploymentMetadata
>>  *
>>  */
>> -public class ApplicationMetadataImpl implements ApplicationMetadata
>> +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;
>> @@ -66,15 +67,15 @@
>>    * setup the application metadata from the appManifest
>>    * @param appManifest     application.mf manifest
>>    */
>> -  private void setup(Manifest appManifest) {
>> -
>> -
>> +  private void setup(Manifest appManifest)
>> +  {
>>     Map<String, String> appMap = readManifestIntoMap(appManifest);
>>
>>     // configure the appSymbolicName and appVersion
>> -    this.appSymbolicName = appMap.get(AppConstants.APPLICATION_SYMBOLIC_NAME).trim();
>> -    this.appVersion = new Version(appMap.get(AppConstants.APPLICATION_VERSION).trim());
>> +    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);
>> @@ -143,11 +144,29 @@
>>     return this.appVersion;
>>   }
>>
>> -  public String getApplicationName() {
>> +  public String getApplicationName()
>> +  {
>>     return this.appName;
>>   }
>>
>> -  public String getApplicationScope() {
>> -    return this.appSymbolicName + "_" + this.appVersion.toString();
>> +  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();
>>   }
>> -}
>> +}
>> \ No newline at end of file
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerImpl.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerImpl.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerImpl.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerImpl.java
Mon Dec  7 11:32:47 2009
>> @@ -26,6 +26,8 @@
>>
>>  import org.apache.aries.application.ApplicationMetadata;
>>  import org.apache.aries.application.ApplicationMetadataManager;
>> +import org.apache.aries.application.Content;
>> +import org.apache.aries.application.VersionRange;
>>  import org.apache.aries.application.utils.manifest.ManifestProcessor;
>>  import org.osgi.framework.Version;
>>
>> @@ -56,9 +58,7 @@
>>
>>   public boolean registerApplication(ApplicationMetadata app)
>>   {
>> -    String key = app.getApplicationSymbolicName() + "_" + app.getApplicationVersion();
>> -
>> -    ApplicationMetadata existingApp = applications.putIfAbsent(key, app);
>> +    ApplicationMetadata existingApp = applications.putIfAbsent(app.getApplicationScope(),
app);
>>
>>     return existingApp == null;
>>   }
>> @@ -68,16 +68,19 @@
>>     return new ApplicationMetadataImpl(man);
>>   }
>>
>> -  /**
>> -   * This method is called by the service facade to remove applications when
>> -   * the client bundle releases the service. It is not public.
>> -   *
>> -   * @param app the application to remove.
>> -   */
>> -  public void removeApplication(ApplicationMetadata app)
>> +  public boolean unregisterApplication(ApplicationMetadata app)
>> +  {
>> +    return applications.remove(app.getApplicationScope()) != null;
>> +  }
>> +
>> +  public Content parseContent(String content)
>> +  {
>> +    return new ContentImpl(content);
>> +  }
>> +
>> +  public VersionRange parseVersionRange(String versionRange)
>>   {
>> -    String key = app.getApplicationSymbolicName() + "_" + app.getApplicationVersion();
>> -    applications.remove(key);
>> +    return new VersionRangeImpl(versionRange);
>>   }
>>
>>  }
>> \ No newline at end of file
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerServiceImpl.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerServiceImpl.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerServiceImpl.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataManagerServiceImpl.java
Mon Dec  7 11:32:47 2009
>> @@ -20,12 +20,17 @@
>>
>>  import java.io.IOException;
>>  import java.io.InputStream;
>> -import java.util.ArrayList;
>> -import java.util.List;
>> +import java.util.HashSet;
>> +import java.util.Set;
>>  import java.util.jar.Manifest;
>>
>>  import org.apache.aries.application.ApplicationMetadata;
>>  import org.apache.aries.application.ApplicationMetadataManager;
>> +import org.apache.aries.application.Content;
>> +import org.apache.aries.application.VersionRange;
>> +import org.osgi.framework.Bundle;
>> +import org.osgi.framework.ServiceFactory;
>> +import org.osgi.framework.ServiceRegistration;
>>  import org.osgi.framework.Version;
>>
>>  /**
>> @@ -33,61 +38,103 @@
>>  * remove registered applications when the requesting bundle releases the service.
>>  * There is one instance of this class per requesting bundle.
>>  */
>> -public class ApplicationMetadataManagerServiceImpl implements ApplicationMetadataManager
>> +public class ApplicationMetadataManagerServiceImpl implements ServiceFactory
>>  {
>> -  /** The core application metadata manager */
>> -  private ApplicationMetadataManagerImpl manager;
>> -  /** A list of all applications registered via this service instance */
>> -  private List<ApplicationMetadata> appMetaData = new ArrayList<ApplicationMetadata>();
>> +  private static class RealApplicationMetadataManagerServiceImpl implements ApplicationMetadataManager
>> +  {
>> +    /** The core application metadata manager */
>> +    private ApplicationMetadataManager manager;
>> +    /** A list of all applications registered via this service instance */
>> +    private Set<ApplicationMetadata> appMetaData = new HashSet<ApplicationMetadata>();
>> +
>> +    public RealApplicationMetadataManagerServiceImpl(ApplicationMetadataManager
man)
>> +    {
>> +      manager = man;
>> +    }
>> +
>> +    public ApplicationMetadata getApplication(String applicationSymbolicName,
Version version)
>> +    {
>> +      return manager.getApplication(applicationSymbolicName, version);
>> +    }
>> +
>> +    public ApplicationMetadata parseApplication(InputStream in) throws IOException
>> +    {
>> +      return manager.parseApplication(in);
>> +    }
>> +
>> +    public ApplicationMetadata createApplication(Manifest man)
>> +    {
>> +      return manager.createApplication(man);
>> +    }
>> +
>> +    public boolean registerApplication(ApplicationMetadata app)
>> +    {
>> +      if (manager.registerApplication(app)) {
>> +        synchronized (appMetaData) {
>> +          appMetaData.add(app);
>> +        }
>> +        return true;
>> +      }
>> +      return false;
>> +    }
>> +
>> +    public boolean unregisterApplication(ApplicationMetadata app)
>> +    {
>> +      boolean remove = false;
>> +      synchronized (appMetaData) {
>> +        remove = appMetaData.contains(app);
>> +      }
>> +
>> +      if (remove) return manager.unregisterApplication(app);
>> +
>> +      return false;
>> +    }
>> +
>> +    /**
>> +     * This method is called by blueprint when the calling bundle releases the
>> +     * service. It removes all the registered applications from the core manager.
>> +     */
>> +    public void close()
>> +    {
>> +      synchronized (appMetaData) {
>> +        for (ApplicationMetadata app : appMetaData) {
>> +          manager.unregisterApplication(app);
>> +        }
>> +
>> +        appMetaData.clear();
>> +      }
>> +    }
>> +
>> +    public Content parseContent(String content)
>> +    {
>> +      return manager.parseContent(content);
>> +    }
>>
>> +    public VersionRange parseVersionRange(String versionRange)
>> +    {
>> +      return manager.parseVersionRange(versionRange);
>> +    }
>> +  }
>> +
>> +  private ApplicationMetadataManager manager;
>> +
>>   /**
>>    * Called by blueprint.
>>    *
>>    * @param appManager the core app metadata manager.
>>    */
>> -  public void setManager(ApplicationMetadataManagerImpl appManager)
>> +  public void setManager(ApplicationMetadataManager appManager)
>>   {
>>     manager = appManager;
>>   }
>>
>> -  public ApplicationMetadata getApplication(String applicationSymbolicName, Version
version)
>> +  public Object getService(Bundle bundle, ServiceRegistration registration)
>>   {
>> -    return manager.getApplication(applicationSymbolicName, version);
>> +    return new RealApplicationMetadataManagerServiceImpl(manager);
>>   }
>>
>> -  public ApplicationMetadata parseApplication(InputStream in) throws IOException
>> +  public void ungetService(Bundle bundle, ServiceRegistration registration, Object
service)
>>   {
>> -    return manager.parseApplication(in);
>> -  }
>> -
>> -  public ApplicationMetadata createApplication(Manifest man)
>> -  {
>> -    return manager.createApplication(man);
>> -  }
>> -
>> -  public boolean registerApplication(ApplicationMetadata app)
>> -  {
>> -    if (manager.registerApplication(app)) {
>> -      synchronized (appMetaData) {
>> -        appMetaData.add(app);
>> -      }
>> -      return true;
>> -    }
>> -    return false;
>> -  }
>> -
>> -  /**
>> -   * This method is called by blueprint when the calling bundle releases the
>> -   * service. It removes all the registered applications from the core manager.
>> -   */
>> -  public void close()
>> -  {
>> -    synchronized (appMetaData) {
>> -      for (ApplicationMetadata app : appMetaData) {
>> -        manager.removeApplication(app);
>> -      }
>> -
>> -      appMetaData.clear();
>> -    }
>> +    ((RealApplicationMetadataManagerServiceImpl)service).close();
>>   }
>>  }
>> \ No newline at end of file
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java
Mon Dec  7 11:32:47 2009
>> @@ -24,13 +24,15 @@
>>
>>  import org.apache.aries.application.Content;
>>  import org.apache.aries.application.VersionRange;
>> +import org.apache.aries.application.utils.AppConstants;
>> +import org.osgi.framework.Constants;
>>
>>
>>  /**
>>  * Implementation of Content
>>  *
>>  */
>> -public class ContentImpl implements Content
>> +public final class ContentImpl implements Content
>>  {
>>   private String content;
>>   private String contentName;
>> @@ -46,6 +48,10 @@
>>     this.attributes = new HashMap<String, String>();
>>     this.directives = new HashMap<String, String>();
>>     setup(content, this.attributes, this.directives);
>> +
>> +    if (!!!attributes.containsKey(Constants.VERSION_ATTRIBUTE)) {
>> +      attributes.put(Constants.VERSION_ATTRIBUTE, AppConstants.DEFAULT_VERSION);
>> +    }
>>   }
>>
>>   public String getContent() {
>> @@ -100,6 +106,34 @@
>>     return vi;
>>   }
>>
>> +  @Override
>> +  public String toString()
>> +  {
>> +    return content;
>> +  }
>> +
>> +  @Override
>> +  public boolean equals(Object other)
>> +  {
>> +    if (other == this) return true;
>> +    if (other == null) return false;
>> +
>> +    if (other instanceof ContentImpl) {
>> +      ContentImpl otherContent = (ContentImpl)other;
>> +      return contentName.equals(otherContent.contentName) &&
>> +             attributes.equals(otherContent.attributes) &&
>> +             directives.equals(otherContent.directives);
>> +    }
>> +
>> +    return false;
>> +  }
>> +
>> +  @Override
>> +  public int hashCode()
>> +  {
>> +    return contentName.hashCode();
>> +  }
>> +
>>   /**
>>    * setup attributes and directives from the Application-Content or Import-Package
>>    * @param content
>> @@ -110,7 +144,7 @@
>>   {
>>     String[] tokens = content.split(";");
>>     if (tokens.length < 1) {
>> -      throw new IllegalArgumentException("Invalid header split: " + content);
>> +      throw new IllegalArgumentException("Invalid content: " + content);
>>     }
>>     this.contentName = tokens[0].trim();
>>     for (int i = 1; i < tokens.length; i++) {
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java
Mon Dec  7 11:32:47 2009
>> @@ -87,50 +87,40 @@
>>
>>     String namedAttribute = null;
>>
>> -    while ((line = reader.readLine()) != null) {
>> -      String trimmedLine = line.trim();
>> +    do {
>> +      line = reader.readLine();
>> +
>>       // if we get a blank line skip to the next one
>> -      if (trimmedLine.length() == 0) continue;
>> -      if (line.charAt(0) == ' ' && attribute != null) {
>> +      if (line != null && line.trim().length() == 0) continue;
>> +      if (line != null && line.charAt(0) == ' ' && attribute
!= null) {
>>         // we have a continuation line, so add to the builder, ignoring the
>>         // first character
>> -        attribute.append(trimmedLine);
>> +        attribute.append(line.trim());
>>       } else if (attribute == null) {
>> -        attribute = new StringBuilder(trimmedLine);
>> +        attribute = new StringBuilder(line.trim());
>>       } else if (attribute != null) {
>>         // We have fully parsed an attribute
>> -        namedAttribute = setAttribute(man, namedAttribute, attribute);
>> +        int index = attribute.indexOf(":");
>> +        String attributeName = attribute.substring(0, index).trim();
>> +        // TODO cope with index + 1 being after the end of attribute
>> +        String attributeValue = attribute.substring(index + 1).trim();
>>
>> -        attribute = new StringBuilder(trimmedLine);
>> -      }
>> -    }
>> -
>> -    if (attribute != null) {
>> -        setAttribute(man, namedAttribute, attribute);
>> -    }
>> -
>> -    return man;
>> -  }
>> -
>> -  private static String setAttribute(Manifest man, String namedAttribute, StringBuilder
attribute)
>> -  {
>> -      int index = attribute.indexOf(":");
>> -      String attributeName = attribute.substring(0, index).trim();
>> -      // TODO cope with index + 1 being after the end of attribute
>> -      String attributeValue = attribute.substring(index + 1).trim();
>> -
>> -      if ("Name".equals(attributeName)) {
>> -        man.getEntries().put(attributeValue, new Attributes());
>> -        namedAttribute = attributeValue;
>> -      } else {
>> -        if (namedAttribute == null) {
>> -          man.getMainAttributes().put(new Attributes.Name(attributeName), attributeValue);
>> +        if ("Name".equals(attributeName)) {
>> +          man.getEntries().put(attributeValue, new Attributes());
>> +          namedAttribute = attributeValue;
>>         } else {
>> -          man.getAttributes(namedAttribute).put(new Attributes.Name(attributeName),
attributeValue);
>> +          if (namedAttribute == null) {
>> +            man.getMainAttributes().put(new Attributes.Name(attributeName),
attributeValue);
>> +          } else {
>> +            man.getAttributes(namedAttribute).put(new Attributes.Name(attributeName),
attributeValue);
>> +          }
>>         }
>> +
>> +        if (line != null) attribute = new StringBuilder(line.trim());
>>       }
>> -
>> -      return namedAttribute;
>> +    } while (line != null);
>> +
>> +    return man;
>>   }
>>
>>   /**
>>
>> Added: incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ApplicationMetadataImplTest.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ApplicationMetadataImplTest.java?rev=887889&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ApplicationMetadataImplTest.java
(added)
>> +++ incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ApplicationMetadataImplTest.java
Mon Dec  7 11:32:47 2009
>> @@ -0,0 +1,38 @@
>> +/*
>> + * IBM Confidential
>> + *
>> + * OCO Source Materials
>> + *
>> + * Copyright IBM Corp. 2009
>> + *
>> + * The source code for this program is not published or other-
>> + * wise divested of its trade secrets, irrespective of what has
>> + * been deposited with the U.S. Copyright Office.
>> + *
>> + * Change activity:
>> + *
>> + * Issue       Date        Name     Description
>> + * ----------- ----------- -------- ------------------------------------
>> + */
>> +package org.apache.aries.application.utils;
>> +
>> +import java.io.IOException;
>> +
>> +import junit.framework.Assert;
>> +
>> +import org.apache.aries.application.ApplicationMetadata;
>> +import org.apache.aries.application.ApplicationMetadataManager;
>> +import org.apache.aries.application.impl.ApplicationMetadataManagerImpl;
>> +import org.junit.Test;
>> +
>> +public class ApplicationMetadataImplTest
>> +{
>> +  @Test
>> +  public void testBasicMetadataCreation() throws IOException
>> +  {
>> +    ApplicationMetadataManager manager = new ApplicationMetadataManagerImpl();
>> +    ApplicationMetadata app = manager.parseApplication(getClass().getResourceAsStream("/META-INF/APPLICATION.MF"));
>> +
>> +    Assert.assertEquals("Travel Reservation", app.getApplicationName());
>> +  }
>> +}
>> \ No newline at end of file
>>
>> Modified: incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java?rev=887889&r1=887888&r2=887889&view=diff
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java
(original)
>> +++ incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java
Mon Dec  7 11:32:47 2009
>> @@ -18,75 +18,30 @@
>>  */
>>  package org.apache.aries.application.utils;
>>
>> -import static org.apache.aries.application.utils.AppConstants.APPLICATION_MF;
>>  import static org.junit.Assert.assertEquals;
>>  import static org.junit.Assert.assertNotNull;
>> -import static org.junit.Assert.assertNull;
>>  import static org.junit.Assert.assertTrue;
>>  import static org.junit.Assert.fail;
>>
>> -import java.io.File;
>> -import java.io.FileInputStream;
>> -import java.io.PrintWriter;
>> +import java.io.InputStream;
>>  import java.util.HashMap;
>>  import java.util.List;
>>  import java.util.Map;
>>  import java.util.jar.Manifest;
>>
>> -import org.junit.After;
>> -import org.junit.Before;
>> -import org.junit.Test;
>> -import org.osgi.framework.Version;
>> -
>>  import org.apache.aries.application.ApplicationMetadata;
>>  import org.apache.aries.application.Content;
>>  import org.apache.aries.application.VersionRange;
>>  import org.apache.aries.application.impl.ApplicationMetadataManagerImpl;
>>  import org.apache.aries.application.utils.manifest.ManifestProcessor;
>> +import org.junit.Test;
>> +import org.osgi.framework.Version;
>>
>>  public class ManifestProcessorTest
>>  {
>>
>> -  private static Map<String,String> pairs = null;
>> -
>> -  @Before
>> -  public void setUp() throws Exception{
>> -
>> -    //enforce ordering of the keys
>> -    String[] keys = new String[]{
>> -        "Manifest-Version",
>> -        "Application-ManifestVersion",
>> -        "Application-Name",
>> -        "Application-SymbolicName",
>> -        "Application-Version",
>> -        "Application-Content",
>> -        "Export-Package",
>> -        "Import-Package",
>> -        "Application-Services"
>> -    };
>> -
>> -    String [] values = new String[]{
>> -        "1.0",
>> -        "1.0",
>> -        "Travel Reservation",
>> -        "com.travel.reservation",
>> -        "1.2",
>> -        "com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
>> -        "com.travel.reservation.api;version=1.2",
>> -        "com.travel.flight.api;version=\"[2.1.1,3.0.0)\",com.travel.rail.api;version=\"[1.0.0,2.0.0)\"",
>> -        "services.xml"
>> -    };
>> -
>> -    //the values of the manifest
>> -    //intentionally include a couple of long lines
>> -    pairs = new HashMap<String, String>();
>> -    int i = 0;
>> -    for (String key : keys){
>> -      pairs.put(key, values[i]);
>> -      i++;
>> -    }
>> -  }
>> -
>> +  private String appName = "Travel Reservation";
>> +
>>   /**
>>    * Check a simple manifest can be read.
>>    * @throws Exception
>> @@ -94,49 +49,77 @@
>>   @Test
>>   public void testSimpleManifest() throws Exception
>>   {
>> -       Manifest mf = new Manifest(getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF"));
>> -       checkManifest(mf);
>> +    //the values of the manifest
>> +    //intentionally include a couple of long lines
>> +    Map<String, String> pairs = new HashMap<String, String>();
>> +    pairs.put("Manifest-Version", "1.0");
>> +    pairs.put("Application-ManifestVersion", "1.0");
>> +    pairs.put("Application-Name", appName );
>> +    pairs.put("Application-SymbolicName", "com.travel.reservation");
>> +    pairs.put("Application-Version", "1.2");
>> +    pairs.put("Application-Content", "com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business");
>> +    pairs.put("Export-Package", "com.travel.reservation.api;version=1.2");
>> +    pairs.put("Import-Package", "com.travel.flight.api;version=\"[2.1.1,3.0.0)\",com.travel.rail.api;version=\"[1.0.0,2.0.0)\"");
>> +    pairs.put("Application-Services", "services.xml");
>> +
>> +    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF");
>> +    Manifest mf = new Manifest(in);
>> +    Map<String, String> map = ManifestProcessor.readManifestIntoMap(mf);
>> +    assertNotNull(map);
>> +
>> +    //check all the expected keys and values
>> +    for (String key : pairs.keySet()){
>> +      assertTrue("Key: " + key + " was not found",map.containsKey(key));
>> +      String value = map.get(key);
>> +      assertNotNull("Value was not present for key: " + key ,value);
>> +      assertEquals("Value was not correct for key: " + key ,pairs.get(key),value);
>> +    }
>> +    //check there aren't any extra entries in the map that weren't expected
>> +    assertEquals("The maps did not match",pairs,map);
>>   }
>>
>>   /**
>> -   * Check a simple manifest can be parsed.
>> -   * @throws Exception
>> +   * Check metadata can be extracted from a simple manifest.
>>    */
>>   @Test
>> -  public void testParseManifest() throws Exception
>> -  {
>> -    Manifest mf = ManifestProcessor.parseManifest(getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF"));
>> -    checkManifest(mf);
>> -  }
>> -
>> -  private void checkManifest(Manifest mf) throws Exception
>> +  public void testManifestMetadata() throws Exception
>>   {
>> -      Map<String, String> map = ManifestProcessor.readManifestIntoMap(mf);
>> -      assertNotNull(map);
>> +    ApplicationMetadataManagerImpl manager = new ApplicationMetadataManagerImpl();
>> +    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF");
>> +    ApplicationMetadata am = manager.parseApplication(in);
>> +    assertNotNull(am);
>> +
>> +    assertEquals(am.getApplicationName(),appName);
>>
>> -      assertEquals("Unexpected number of manifest entires", pairs.size(), map.size());
>> -
>> -      //check all the expected keys and values
>> -      for (String key : pairs.keySet()){
>> -        assertTrue("Key: " + key + " was not found",map.containsKey(key));
>> -        String value = map.get(key);
>> -        assertNotNull("Value was not present for key: " + key ,value);
>> -        assertEquals("Value was not correct for key: " + key ,pairs.get(key),value);
>> -      }
>> -      //check there aren't any extra entries in the map that weren't expected
>> -      assertEquals("The maps did not match",pairs,map);
>> +    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
>> +    List<Content> contents = am.getApplicationContents();
>> +    for (Content content : contents){
>> +      if ("com.travel.reservation.web".equals(content.getContentName())){
>> +        VersionRange vr = content.getVersion();
>> +        assertEquals(vr.getMinimumVersion(),new Version("1.1.0"));
>> +        assertEquals(vr.getMaximumVersion(),new Version("1.2.0"));
>> +      } else if("com.travel.reservation.business".equals(content.getContentName())){
>> +        VersionRange vr = content.getVersion();
>> +        assertEquals(new Version(0,0,0), vr.getMinimumVersion());
>> +      } else
>> +        fail("Unexepcted content name " + content.getContentName());
>> +    }
>>   }
>> +
>>   /**
>> -   * Check metadata can be extracted from a simple manifest.
>> +   * Check metadata can be extracted from a manifest that uses multiple lines
>> +   * for a single manifest attribute.
>>    */
>>   @Test
>> -  public void testManifestMetadata() throws Exception
>> +  public void testManifestMetadataWithMultiLineEntries() throws Exception
>>   {
>>     ApplicationMetadataManagerImpl manager = new ApplicationMetadataManagerImpl();
>> -    ApplicationMetadata am = manager.parseApplication(getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF"));
>> +
>> +    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION2.MF");
>> +
>> +    ApplicationMetadata am = manager.parseApplication(in);
>>     assertNotNull(am);
>>
>> -    String appName = pairs.get("Application-Name");
>>     assertEquals(am.getApplicationName(),appName);
>>
>>     //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
>> @@ -148,9 +131,23 @@
>>         assertEquals(vr.getMaximumVersion(),new Version("1.2.0"));
>>       } else if("com.travel.reservation.business".equals(content.getContentName())){
>>         VersionRange vr = content.getVersion();
>> -        assertNull(vr);
>> +        assertEquals(new Version(0,0,0), vr.getMinimumVersion());
>>       } else
>>         fail("Unexepcted content name " + content.getContentName());
>>     }
>>   }
>> +
>> +  @Test
>> +  public void testManifestWithoutEndingInNewLine() throws Exception
>> +  {
>> +    ApplicationMetadataManagerImpl manager = new ApplicationMetadataManagerImpl();
>> +
>> +    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION3.MF");
>> +
>> +    ApplicationMetadata am = manager.parseApplication(in);
>> +    assertNotNull(am);
>> +
>> +    assertEquals("Wrong number of bundles are in the application", 1, am.getApplicationContents().size());
>> +    assertEquals("Wrong bundle name", "org.apache.aries.applications.test.bundle",
am.getApplicationContents().get(0).getContentName());
>> +  }
>>  }
>> \ No newline at end of file
>>
>> Added: incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION2.MF
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION2.MF?rev=887889&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION2.MF
(added)
>> +++ incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION2.MF
Mon Dec  7 11:32:47 2009
>> @@ -0,0 +1,13 @@
>> +Manifest-Version: 1.0
>> +Application-ManifestVersion: 1.0
>> +Application-Name: Travel Reservation
>> +Application-SymbolicName: com.travel.reservation
>> +Application-Version: 1.2
>> +Application-Content: com.travel.reservation.web;version="[1.1.0,1.2.0)",
>> +                     com.travel.reservation.business,
>> +Export-Package: com.travel.reservation.api;version=1.2
>> +Import-Package: com.travel.flight.api;version="[2.1.1,3.0.0)",
>> +                com.travel.rail.api;version="[1.0.0,2.0.0)",
>> +                com.travel.credit.api;version="[2.1.0,2.1.0]",
>> +                com.travel.hotel.api;version="[1.5.0,2.0.0)"
>> +Application-Services: services.xml
>>
>> Added: incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION3.MF
>> URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION3.MF?rev=887889&view=auto
>> ==============================================================================
>> --- incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION3.MF
(added)
>> +++ incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION3.MF
Mon Dec  7 11:32:47 2009
>> @@ -0,0 +1,3 @@
>> +Application-SymbolicName: org.apache.aries.applications.test.app
>> +Application-Version: 1.4.0
>> +Application-Content: org.apache.aries.applications.test.bundle
>>
>>
>>
>



-- 
Alasdair Nottingham
not@apache.org

Mime
View raw message