You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gc...@apache.org on 2009/10/23 17:34:46 UTC
svn commit: r829091 - in /incubator/aries/trunk: ./ application/
application/application-utils/ application/application-utils/src/
application/application-utils/src/main/
application/application-utils/src/main/java/
application/application-utils/src/ma...
Author: gcc
Date: Fri Oct 23 15:34:42 2009
New Revision: 829091
URL: http://svn.apache.org/viewvc?rev=829091&view=rev
Log:
ARIES-40
Added application metadata processing code.
Added:
incubator/aries/trunk/application/
incubator/aries/trunk/application/application-utils/
incubator/aries/trunk/application/application-utils/pom.xml
incubator/aries/trunk/application/application-utils/src/
incubator/aries/trunk/application/application-utils/src/main/
incubator/aries/trunk/application/application-utils/src/main/java/
incubator/aries/trunk/application/application-utils/src/main/java/org/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadata.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataFactory.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/Content.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ServiceDeclaration.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/VersionRange.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java (with props)
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java (with props)
incubator/aries/trunk/application/application-utils/src/test/
incubator/aries/trunk/application/application-utils/src/test/java/
incubator/aries/trunk/application/application-utils/src/test/java/org/
incubator/aries/trunk/application/application-utils/src/test/java/org/apache/
incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/
incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/
incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/
incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java (with props)
incubator/aries/trunk/application/application-utils/src/test/resources/
incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/
incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION.MF (with props)
incubator/aries/trunk/application/pom.xml
Modified:
incubator/aries/trunk/pom.xml
Added: incubator/aries/trunk/application/application-utils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/pom.xml?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/pom.xml (added)
+++ incubator/aries/trunk/application/application-utils/pom.xml Fri Oct 23 15:34:42 2009
@@ -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 WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.aries.application</groupId>
+ <artifactId>application</artifactId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>aries-application-utils</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Aries Application Utils</name>
+ <description>
+ Utilities for working with Aries Applications.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.testsupport</groupId>
+ <artifactId>aries-testsupport-unit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.groupId}.core</Bundle-SymbolicName>
+ <Export-Package>
+ org.apache.aries.application;version="${pom.version}",
+ org.apache.aries.application.utils;version="${pom.version}"
+ </Export-Package>
+ <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
+ <_removeheaders>Ignore-Package,Include-Resource,Private-Package,Bundle-DocURL</_removeheaders>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadata.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadata.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadata.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadata.java Fri Oct 23 15:34:42 2009
@@ -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;
+
+import java.util.List;
+
+import org.osgi.framework.Version;
+
+/**
+ * this interface describes the Application.mf file
+ *
+ */
+public interface ApplicationMetadata
+{
+ /**
+ * get the value of the Application-SymbolicName header
+ * @return the value of the Application-SymbolicName header
+ */
+ public String getApplicationSymbolicName();
+
+ /**
+ * get the value of the Application-Version header
+ * @return the value of the Application-Version header
+ */
+ public Version getApplicationVersion();
+
+ /**
+ * get the name of the application
+ * @return the name of the application
+ */
+ public String getApplicationName();
+ /**
+ * get the list of Application contents includes bundle name,
+ * version, directives and attributes
+ * @return the list of the Application contents
+ */
+ public List<Content> getApplicationContents();
+
+ /**
+ * get the value of the Export-Service header
+ * @return the list of ServiceDeclaration
+ */
+ public List<ServiceDeclaration> getApplicationExportServices();
+
+ /**
+ * get the value of the Import-Service header
+ * @return the list of ServiceDeclaration
+ */
+ public List<ServiceDeclaration> getApplicationImportServices();
+
+ /**
+ * get the value of the Application-Scope, which is
+ * calculated from Application-SymbolicName and Application-Version
+ * @return the value of the AppScope
+ */
+ public String getApplicationScope();
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadata.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataFactory.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataFactory.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataFactory.java Fri Oct 23 15:34:42 2009
@@ -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;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.jar.Manifest;
+
+public class ApplicationMetadataFactory {
+
+ private static String implClass = "org.apache.aries.application.impl.ApplicationMetadataImpl";
+
+ /**
+ * Obtain an ApplicationMetadata for the supplied Manifest.
+ *
+ * @param mf The manifest containing application metadata
+ * @return instance of ApplicationMetadata
+ * @throws IllegalArgumentException if the Manifest does not contain application metadata
+ */
+ @SuppressWarnings("unchecked")
+ public static ApplicationMetadata getApplicationMetadata(Manifest mf)
+ throws IllegalArgumentException
+ {
+ try{
+ Class impl = Class.forName(implClass);
+ Constructor c = impl.getConstructor(Manifest.class);
+ return (ApplicationMetadata)c.newInstance(mf);
+ }catch(ClassNotFoundException e){
+ throw new RuntimeException("Unable to find metadata impl class ",e);
+ } catch (SecurityException e) {
+ throw new RuntimeException("Unable to access metadata impl constructor ",e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException("Unable to find metadata impl constructor ",e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException("Unable to create metadata impl constructor ",e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Unable to access metadata impl constructor ",e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Unable to invoke metadata impl constructor ",e);
+ }
+ }
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ApplicationMetadataFactory.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/Content.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/Content.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/Content.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/Content.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,74 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+
+/**
+ * this interface describes the content metadata such as Application-Content, Import-Package, etc
+ *
+ */
+public interface Content
+{
+ /**
+ * get the package name of the content
+ * @return the package name of the content
+ */
+ public String getContentName();
+
+ /**
+ * get the entire content including the content name, directives & attributes
+ * @return the entire content in String format
+ */
+ public String getContent();
+
+ /**
+ * get the attributes of the content
+ * @return the attributes of the content
+ */
+ public Map<String, String> getAttributes();
+
+ /**
+ * get the directives of the content
+ * @return the directives of the content
+ */
+ public Map<String, String> getDirectives();
+
+ /**
+ * get the value of the attribute with the specified key
+ * @param key
+ * @return value of the attribute specified by the key
+ */
+ public String getAttribute(String key);
+
+ /**
+ * get the value of the directive with the specified key
+ * @param key
+ * @return the value of the directive specified by the key
+ */
+ public String getDirective(String key);
+
+ /**
+ * get the version info for the version attribute
+ * @return null if there is no version associated with this content
+ * ASK ALASDAIR: should we return default version 0.0.0 instead of null?
+ */
+ public VersionRange getVersion();
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/Content.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ServiceDeclaration.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ServiceDeclaration.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ServiceDeclaration.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ServiceDeclaration.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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;
+
+import org.osgi.framework.Filter;
+
+public interface ServiceDeclaration {
+
+ /**
+ * get the interface name for the service
+ * @return
+ */
+ public abstract String getInterfaceName();
+
+ /**
+ * get the filter for the service
+ * @return the filter for the service or null if there is no filter defined
+ */
+ public abstract Filter getFilter();
+
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/ServiceDeclaration.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/VersionRange.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/VersionRange.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/VersionRange.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/VersionRange.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+import org.osgi.framework.Version;
+
+public interface VersionRange {
+
+ public abstract String toString();
+
+ /**
+ * this method returns the exact version from the versionInfo obj.
+ * this is used for DeploymentContent only to return a valid exact version
+ * otherwise, null is returned.
+ * @return
+ */
+ public abstract Version getExactVersion();
+
+ /**
+ * get the maximum version
+ * @return the maximum version
+ */
+ public abstract Version getMaximumVersion();
+
+ /**
+ * get the minimum version
+ * @return the minimum version
+ */
+ public abstract Version getMinimumVersion();
+
+ /**
+ * is the maximum version exclusive
+ * @return
+ */
+ public abstract boolean isMaximumExclusive();
+
+ /**
+ * is the maximum version unbounded
+ * @return
+ */
+ public abstract boolean isMaximumUnbounded();
+
+ /**
+ * is the minimum version exclusive
+ * @return
+ */
+ public abstract boolean isMinimumExclusive();
+
+ /**
+ * check if the versioninfo is the exact version
+ * @return
+ */
+ public abstract boolean isExactVersion();
+
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/VersionRange.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,160 @@
+/*
+ * 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.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.osgi.framework.Version;
+
+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;
+
+/**
+ * Implementation of ApplicationMetadata and DeploymentMetadata
+ *
+ */
+public class ApplicationMetadataImpl implements ApplicationMetadata
+{
+ private String appSymbolicName;
+ private Version appVersion;
+ private String appName;
+ private List<Content> appContents;
+ private List<ServiceDeclaration> importServices;
+ private List<ServiceDeclaration> exportServices;
+
+ /**
+ * 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);
+
+ }
+
+ /**
+ * 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).trim();
+ this.appVersion = new Version(appMap.get(AppConstants.APPLICATION_VERSION).trim());
+ this.appName = appMap.get(AppConstants.APPLICATION_NAME);
+
+ 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;
+ }
+
+ @Override
+ public List<Content> getApplicationContents()
+ {
+ return Collections.unmodifiableList(this.appContents);
+ }
+
+ @Override
+ public List<ServiceDeclaration> getApplicationExportServices()
+ {
+ return Collections.unmodifiableList(this.exportServices);
+ }
+
+ @Override
+ public List<ServiceDeclaration> getApplicationImportServices()
+ {
+ return Collections.unmodifiableList(this.importServices);
+ }
+
+ @Override
+ public String getApplicationSymbolicName()
+ {
+ return this.appSymbolicName;
+ }
+
+ @Override
+ public Version getApplicationVersion()
+ {
+ return this.appVersion;
+ }
+
+ @Override
+ public String getApplicationName() {
+ return this.appName;
+ }
+
+ @Override
+ public String getApplicationScope() {
+ return this.appSymbolicName + "_" + this.appVersion.toString();
+ }
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ApplicationMetadataImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,150 @@
+/*
+ * 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;
+
+
+/**
+ * Implementation of Content
+ *
+ */
+public class ContentImpl implements Content
+{
+ private String content;
+ private String contentName;
+ protected Map<String, String> attributes;
+ private Map<String, String> directives;
+
+ /**
+ *
+ * @param content Application-Content, Import-Package content
+ */
+ public ContentImpl(String content) {
+ this.content = content;
+ this.attributes = new HashMap<String, String>();
+ this.directives = new HashMap<String, String>();
+ setup(content, this.attributes, this.directives);
+ }
+
+ @Override
+ public String getContent() {
+ return this.content;
+ }
+
+ @Override
+ public String getContentName() {
+ return this.contentName;
+ }
+
+ @Override
+ public Map<String, String> getAttributes() {
+ return Collections.unmodifiableMap(this.attributes);
+ }
+
+ @Override
+ public Map<String, String> getDirectives() {
+ return Collections.unmodifiableMap(this.directives);
+ }
+
+ @Override
+ 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);
+ }
+
+ @Override
+ public String getDirective(String key) {
+ String toReturn = this.directives.get(key);
+ return toReturn;
+ }
+
+ /**
+ * add key value to the directives map
+ * @param key
+ * @param value
+ */
+ public void addDirective(String key, String value) {
+ this.directives.put(key, value);
+ }
+
+ @Override
+ public VersionRange getVersion() {
+ VersionRange vi = null;
+ if (this.attributes.get("version") != null && this.attributes.get("version").length() > 0) {
+ vi = new VersionRangeImpl(this.attributes.get("version"));
+ }
+ return vi;
+ }
+
+ /**
+ * setup attributes and directives from the Application-Content or Import-Package
+ * @param content
+ * @param attributes
+ * @param directives
+ */
+ protected void setup(String content, Map<String, String> attributes, Map<String, String> directives)
+ {
+ String[] tokens = content.split(";");
+ if (tokens.length < 1) {
+ throw new IllegalArgumentException("Invalid header split: " + content);
+ }
+ this.contentName = tokens[0].trim();
+ for (int i = 1; i < tokens.length; i++) {
+ int pos = tokens[i].indexOf('=');
+ if (pos != -1) {
+ if (pos > 0 && tokens[i].charAt(pos - 1) == ':') {
+ String name = tokens[i].substring(0, pos - 1).trim();
+ String value = tokens[i].substring(pos + 1).trim();
+ directives.put(name, trimDoubleQuotes(value));
+ } else {
+ String name = tokens[i].substring(0, pos).trim();
+ String value = tokens[i].substring(pos + 1).trim();
+ attributes.put(name, trimDoubleQuotes(value));
+ }
+ }
+ }
+ }
+
+ /**
+ * this method trims the double quotes at the beginning and end, for example version="1.0.0"
+ * @param value
+ * @return
+ */
+ private String trimDoubleQuotes(String value) {
+ if (value.startsWith("\"") && value.endsWith("\"")) {
+ value = value.substring(1, value.length() -1);
+ }
+ return value;
+ }
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ContentImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java Fri Oct 23 15:34:42 2009
@@ -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 the service string value of 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;
+ }
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/ServiceDeclarationImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,201 @@
+/*
+ * 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.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.Version;
+
+import org.apache.aries.application.VersionRange;
+
+public class VersionRangeImpl implements VersionRange
+{
+ private String version;
+ /** The minimum desired version for the bundle */
+ private Version minimumVersion;
+ /** The maximum desired version for the bundle */
+ private Version maximumVersion;
+ /** True if the match is exclusive of the minimum version */
+ private boolean minimumExclusive;
+ /** True if the match is exclusive of the maximum version */
+ private boolean maximumExclusive;
+ /** exact version */
+ private boolean exactVersion;
+ /** A regexp to select the version */
+ private static final Pattern versionCapture = Pattern.compile("\"?(.*?)\"?$");
+
+ /**
+ *
+ * @param version version for the verioninfo
+ */
+ public VersionRangeImpl(String version) {
+ this.version = version;
+ this.exactVersion = false;
+ processVersionAttribute(this.version);
+ }
+
+ /**
+ *
+ * @param version version for the verioninfo
+ * @param exactVersion whether this is an exact version
+ */
+ public VersionRangeImpl(String version, boolean exactVersion) {
+ this.version = version;
+ this.exactVersion = exactVersion;
+ if (exactVersion) {
+ processExactVersionAttribute(this.version);
+ } else {
+ processVersionAttribute(this.version);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#toString()
+ */
+@Override
+ public String toString() {
+ return this.version;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#getExactVersion()
+ */
+ public Version getExactVersion() {
+ Version v = null;
+ if (this.exactVersion) {
+ v = getMinimumVersion();
+ }
+ return v;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#getMaximumVersion()
+ */
+ public Version getMaximumVersion()
+ {
+ return maximumVersion;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#getMinimumVersion()
+ */
+ public Version getMinimumVersion()
+ {
+ return minimumVersion;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#isMaximumExclusive()
+ */
+ public boolean isMaximumExclusive()
+ {
+ return maximumExclusive;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#isMaximumUnbounded()
+ */
+ public boolean isMaximumUnbounded()
+ {
+ boolean unbounded = maximumVersion == null;
+ return unbounded;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#isMinimumExclusive()
+ */
+ public boolean isMinimumExclusive()
+ {
+ return minimumExclusive;
+ }
+
+ /**
+ * this is designed for deployed-version as that is the exact version.
+ * @param version
+ * @return
+ * @throws IllegalArgumentException
+ */
+ private boolean processExactVersionAttribute(String version) throws IllegalArgumentException{
+ boolean success = processVersionAttribute(version);
+
+ if (maximumVersion == null) {
+ maximumVersion = minimumVersion;
+ }
+ if (!minimumVersion.equals(maximumVersion)) {
+ throw new IllegalArgumentException("Failed to parse " + version + " for the exact version. Could not parse " + version);
+ }
+
+ return success;
+ }
+ /**
+ * process the version attribute,
+ * @param version the value to be processed
+ * @return
+ * @throws IllegalArgumentException
+ */
+ private boolean processVersionAttribute(String version) throws IllegalArgumentException{
+ boolean success = false;
+
+ Matcher matches = versionCapture.matcher(version);
+
+ if (matches.matches()) {
+ String versions = matches.group(1);
+
+ if ((versions.startsWith("[") || versions.startsWith("(")) &&
+ (versions.endsWith("]") || versions.endsWith(")"))) {
+ if (versions.startsWith("[")) minimumExclusive = false;
+ else if (versions.startsWith("(")) minimumExclusive = true;
+
+ if (versions.endsWith("]")) maximumExclusive = false;
+ else if (versions.endsWith(")")) maximumExclusive = true;
+
+ int index = versions.indexOf(',');
+ String minVersion = versions.substring(1, index);
+ String maxVersion = versions.substring(index + 1, versions.length() - 1);
+
+ try {
+ minimumVersion = new Version(minVersion.trim());
+ maximumVersion = new Version(maxVersion.trim());
+ success = true;
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException("Failed to parse " + version + ". Could not parse " + versions, nfe);
+ }
+ } else {
+ try {
+ minimumVersion = new Version(versions.trim());
+ success = true;
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException("Failed to parse " + version + ". Could not parse " + versions, nfe);
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Failed to parse " + version + ". Could not parse " + version);
+ }
+
+ return success;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.aries.application.impl.VersionRange#isExactVersion()
+ */
+ public boolean isExactVersion() {
+ return this.exactVersion;
+ }
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/impl/VersionRangeImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java Fri Oct 23 15:34:42 2009
@@ -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;
+
+
+/**
+ * Constants for this bundle
+ */
+public interface AppConstants
+{
+ /** Trace group for this bundle */
+ public String TRACE_GROUP = "Aries.app.utils";
+
+ /** 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";
+
+ public static final String MANIFEST_VERSION="1.0";
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/AppConstants.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java (added)
+++ incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java Fri Oct 23 15:34:42 2009
@@ -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.utils.manifest;
+
+import static org.apache.aries.application.utils.AppConstants.TRACE_GROUP;
+import java.util.ArrayList;
+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;
+
+public class ManifestProcessor
+{
+ /**
+ * 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.
+ */
+ public static 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;
+ }
+
+ /**
+ *
+ * Splits a delimiter separated string, tolerating presence of non separator commas
+ * within double quoted segments.
+ *
+ * Eg.
+ * com.ibm.ws.eba.helloWorldService;version="[1.0.0, 1.0.0]" &
+ * com.ibm.ws.eba.helloWorldService;version="1.0.0"
+ * com.ibm.ws.eba.helloWorld;version="2";bundle-version="[2,30)"
+ * com.acme.foo;weirdAttr="one;two;three";weirdDir:="1;2;3"
+ * @param value the value to be split
+ * @param delimiter the delimiter string such as ',' etc.
+ * @return List<String> the components of the split String in a list
+ */
+ public static List<String> split(String value, String delimiter)
+ {
+
+ List<String> result = new ArrayList<String>();
+ if (value != null) {
+ String[] packages = value.split(delimiter);
+
+ for (int i = 0; i < packages.length; ) {
+ String tmp = packages[i++].trim();
+ // if there is a odd number of " in a string, we need to append
+ while (count(tmp, "\"") % 2 == 1) {
+ // check to see if we need to append the next package[i++]
+ tmp = tmp + delimiter + packages[i++].trim();
+ }
+
+ result.add(tmp);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * count the number of characters in a string
+ * @param parent The string to be searched
+ * @param subString The substring to be found
+ * @return the number of occurrence of the subString
+ */
+ private static int count(String parent, String subString) {
+
+ int count = 0 ;
+ int i = parent.indexOf(subString);
+ while (i > -1) {
+ if (parent.length() >= i+1)
+ parent = parent.substring(i+1);
+ count ++;
+ i = parent.indexOf(subString);
+ }
+ return count;
+ }
+}
Propchange: incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/manifest/ManifestProcessor.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java (added)
+++ incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java Fri Oct 23 15:34:42 2009
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+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.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.ApplicationMetadataFactory;
+import org.apache.aries.application.Content;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.utils.manifest.ManifestProcessor;
+
+public class ManifestProcessorTest
+{
+
+ private static final String APP_FOLDER_NAME = "myAppFolder";
+ private static final String META_NAME = "META-INF";
+ private static final String SEP = ": ";
+
+ private static File appFolder = new File(APP_FOLDER_NAME);
+ private static File f = new File(appFolder, APPLICATION_MF);
+ private static File metaFolder = new File(appFolder,META_NAME);
+
+ private static Map<String,String> pairs = null;
+
+ @Before
+ public void setUp() throws Exception{
+
+ //clean up in case of a bad previous run
+ tearDown();
+
+ //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++;
+ }
+
+ appFolder.mkdir();
+ metaFolder.mkdir();
+ f.createNewFile();
+ PrintWriter pw = new PrintWriter(f);
+ //use write line for all but the last line
+ //count so we don't do the last line
+ i = 0;
+ for (String key : keys){
+ if (i < keys.length-1){
+ pw.println(key + SEP + pairs.get(key));
+ }
+ else{
+ //intentionally fail to print a new line at the end of the file
+ pw.print(key + SEP + pairs.get(key));
+ }
+ i++;
+ }
+ pw.write("\n\n");
+
+ //finish writing the file
+ pw.flush();
+ pw.close();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (f.exists()) f.delete();
+ if (metaFolder.exists()) metaFolder.delete();
+ if (appFolder.exists()) appFolder.delete();
+ }
+
+
+ /**
+ * Check a simple manifest can be read.
+ * @throws Exception
+ */
+ @Test
+ public void testSimpleManifest() throws Exception
+ {
+ Manifest mf = new Manifest(new FileInputStream(new File(appFolder,"/META-INF/APPLICATION.MF")));
+ 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 metadata can be extracted from a simple manifest.
+ */
+ @Test
+ public void testManifestMetadata() throws Exception
+ {
+ Manifest mf = new Manifest(new FileInputStream(new File(appFolder,"/META-INF/APPLICATION.MF")));
+ ApplicationMetadata am = ApplicationMetadataFactory.getApplicationMetadata(mf);
+ 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",
+ 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();
+ assertNull(vr);
+ }else fail("Unexepcted content name " + content.getContentName());
+ }
+ }
+
+
+}
Propchange: incubator/aries/trunk/application/application-utils/src/test/java/org/apache/aries/application/utils/ManifestProcessorTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION.MF
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION.MF?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION.MF (added)
+++ incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION.MF Fri Oct 23 15:34:42 2009
@@ -0,0 +1,10 @@
+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)"
+Application-Services: services.xml
+
Propchange: incubator/aries/trunk/application/application-utils/src/test/resources/META-INF/APPLICATION.MF
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/aries/trunk/application/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/pom.xml?rev=829091&view=auto
==============================================================================
--- incubator/aries/trunk/application/pom.xml (added)
+++ incubator/aries/trunk/application/pom.xml Fri Oct 23 15:34:42 2009
@@ -0,0 +1,102 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.apache.aries</groupId>
+ <artifactId>java5-parent</artifactId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.aries.application</groupId>
+ <artifactId>application</artifactId>
+ <name>Apache Aries Application</name>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>
+ Application support for Aries
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/aries/trunk/application</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/aries/trunk/application</developerConnection>
+ <url>http://svn.apache.org/viewvc/incubator/aries/trunk/application</url>
+ </scm>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.application</groupId>
+ <artifactId>application-utils</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.testsupport</groupId>
+ <artifactId>aries-testsupport-unit</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.0.0</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <useReleaseProfile>false</useReleaseProfile>
+ <goals>deploy</goals>
+ <arguments>-Papache-release,deploy</arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <modules>
+ <module>application-utils</module>
+ </modules>
+
+</project>
Modified: incubator/aries/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/pom.xml?rev=829091&r1=829090&r2=829091&view=diff
==============================================================================
--- incubator/aries/trunk/pom.xml (original)
+++ incubator/aries/trunk/pom.xml Fri Oct 23 15:34:42 2009
@@ -41,6 +41,7 @@
<module>blueprint</module>
<module>jndi</module>
<module>transaction</module>
+ <module>application</module>
</modules>
</project>