aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjwat...@apache.org
Subject svn commit: r1797109 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/ subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ subsystem-itests/src/test/resources/nobsn/ subs...
Date Wed, 31 May 2017 21:09:33 GMT
Author: tjwatson
Date: Wed May 31 21:09:33 2017
New Revision: 1797109

URL: http://svn.apache.org/viewvc?rev=1797109&view=rev
Log:
ARIES-1729 - Including resources with no manifest or bundle symbolic names causes NPE

Added:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/NoBSNTest.java
    aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/
    aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/OSGI-INF/
    aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/OSGI-INF/SUBSYSTEM.MF
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
    aries/trunk/subsystem/subsystem-itests/pom.xml

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java?rev=1797109&r1=1797108&r2=1797109&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
Wed May 31 21:09:33 2017
@@ -28,6 +28,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
 
 import org.apache.aries.subsystem.core.archive.BundleManifest;
 import org.apache.aries.subsystem.core.archive.BundleRequiredExecutionEnvironmentHeader;
@@ -49,6 +50,7 @@ import org.apache.aries.subsystem.core.a
 import org.apache.aries.util.filesystem.IDirectory;
 import org.apache.aries.util.filesystem.IFile;
 import org.apache.aries.util.io.IOUtils;
+import org.osgi.framework.Constants;
 import org.osgi.namespace.service.ServiceNamespace;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
@@ -56,10 +58,18 @@ import org.osgi.resource.Resource;
 import org.osgi.service.subsystem.SubsystemException;
 
 public class BundleResource implements Resource, org.apache.aries.subsystem.core.repository.RepositoryContent
{
-	private static BundleManifest computeManifest(IDirectory directory) {
-		return new BundleManifest(org.apache.aries.util.manifest.BundleManifest
-				.fromBundle(directory)
-				.getRawManifest());
+	private static BundleManifest computeManifest(IDirectory directory, IFile content) {
+		org.apache.aries.util.manifest.BundleManifest bm = 
+				org.apache.aries.util.manifest.BundleManifest.fromBundle(directory);
+		if (bm == null) {
+			throw new IllegalArgumentException("File \"" + content.getName() + "\" contains no bundle
manifest META-INF/MANIFEST.MF.");
+		}
+		Manifest m = bm.getRawManifest();
+		BundleManifest result = new BundleManifest(m);
+		if (result.getHeader(Constants.BUNDLE_SYMBOLICNAME) == null) {
+			throw new IllegalArgumentException("File \"" + content.getName() + "\" has a META-INF/MANIFEST.MF
with no Bundle-SymbolicName header.");
+		}
+		return result;
 	}
 	
 	private final List<Capability> capabilities = new ArrayList<Capability>();
@@ -70,7 +80,7 @@ public class BundleResource implements R
 	public BundleResource(IFile content) {
 		this.content = content;
 		IDirectory dir = content.isDirectory() ? content.convert() : content.convertNested();
-		manifest = computeManifest(dir);
+		manifest = computeManifest(dir, content);
 		computeRequirementsAndCapabilities(dir);
 	}
 

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java?rev=1797109&r1=1797108&r2=1797109&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
Wed May 31 21:09:33 2017
@@ -467,9 +467,16 @@ public class RawSubsystemResource implem
             IOException, ResolutionException, MalformedURLException {
         String name = file.getName();
         if (name.endsWith(".esa")) {
-        	result.add(new RawSubsystemResource(convertFileToLocation(file), content, parentSubsystem));
+            result.add(new RawSubsystemResource(convertFileToLocation(file), content, parentSubsystem));
         } else if (name.endsWith(".jar")) {
-            result.add(new BundleResource(file));
+            try {
+                result.add(new BundleResource(file));
+            } catch (IllegalArgumentException e) {
+                // Ignore if the resource is an invalid bundle or not a bundle at all.
+                if (logger.isDebugEnabled()) {
+                    logger.debug("File \"" + file.getName() + "\" in subsystem with location
\"" + location + "\" will be ignored because it is not recognized as a supported resource.",
e);
+                }
+            }
         } else {
             // This is a different type of file. Add a file resource for it if there is a
custom content handler for it.
             FileResource fr = new FileResource(file);
@@ -493,7 +500,7 @@ public class RawSubsystemResource implem
             } catch (Exception e) {
                 // Ignore if the resource is an invalid bundle or not a bundle at all.
                 if (logger.isDebugEnabled()) {
-                    logger.debug("File \"" + file.getName() + "\" in subsystem with location
\"" + location + "\" will be ignored because it is not recognized as a supported resource",
e);
+                    logger.debug("File \"" + file.getName() + "\" in subsystem with location
\"" + location + "\" will be ignored because it is not recognized as a supported resource.",
e);
                 }
             }
         }

Modified: aries/trunk/subsystem/subsystem-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/pom.xml?rev=1797109&r1=1797108&r2=1797109&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-itests/pom.xml Wed May 31 21:09:33 2017
@@ -332,6 +332,21 @@
                 <artifactId>maven-jar-plugin</artifactId>
                 <version>2.3</version>
                 <executions>
+                     <execution>
+                        <id>tb1-nobsn</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                        <configuration>
+                            <excludes>
+                                <exclude>**/*</exclude>
+                            </excludes>
+                            <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+                            <outputDirectory>${project.build.directory}/test-classes/nobsn</outputDirectory>
+                            <finalName>tb1</finalName>
+                        </configuration>
+                        <phase>process-test-classes</phase>
+                    </execution>
                     <execution>
                         <id>tb1-application1</id>
                         <goals>

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/NoBSNTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/NoBSNTest.java?rev=1797109&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/NoBSNTest.java
(added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/NoBSNTest.java
Wed May 31 21:09:33 2017
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.subsystem.itests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.aries.subsystem.itests.util.TestCapability;
+import org.apache.aries.subsystem.itests.util.TestRepository;
+import org.apache.aries.subsystem.itests.util.TestRepositoryContent;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.resource.Resource;
+import org.osgi.service.repository.Repository;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+public class NoBSNTest extends SubsystemTest {
+	
+	@Override
+	public void createApplications() throws Exception {
+		createApplication("nobsn", "tb1.jar");
+	}
+	
+
+    
+	/*
+	 * Subsystem application1 has content bundle tb1.jar.
+	 * Bundle tb1.jar has an import package dependency on org.apache.aries.subsystem.itests.tb3.
+	 */
+    @Test
+    public void testApplication1() throws Exception {
+        Subsystem nobsn = installSubsystemFromFile("nobsn.esa");
+        try {
+            assertSymbolicName("org.apache.aries.subsystem.nobsn", nobsn);
+            assertVersion("0.0.0", nobsn);
+            assertType(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, nobsn);
+            assertChildren(0, nobsn);
+            assertConstituents(1, nobsn);
+            startSubsystem(nobsn);
+        }
+        finally {
+           stopSubsystemSilently(nobsn);
+           uninstallSubsystemSilently(nobsn);
+        }
+    }
+    
+}

Added: aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/OSGI-INF/SUBSYSTEM.MF
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/OSGI-INF/SUBSYSTEM.MF?rev=1797109&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/OSGI-INF/SUBSYSTEM.MF
(added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/resources/nobsn/OSGI-INF/SUBSYSTEM.MF
Wed May 31 21:09:33 2017
@@ -0,0 +1 @@
+Subsystem-SymbolicName: org.apache.aries.subsystem.nobsn



Mime
View raw message