You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2015/11/16 17:42:24 UTC

svn commit: r1714627 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1451Test.java

Author: jwross
Date: Mon Nov 16 16:42:24 2015
New Revision: 1714627

URL: http://svn.apache.org/viewvc?rev=1714627&view=rev
Log:
[ARIES-1451] BundleResourceInstaller.installBundle() throws IllegalAccessException

Applying patch on behalf of user sbratton. Make sure accesible is set to true on the getContent method.

Added:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1451Test.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java?rev=1714627&r1=1714626&r2=1714627&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java Mon Nov 16 16:42:24 2015
@@ -14,6 +14,7 @@
 package org.apache.aries.subsystem.core.internal;
 
 import java.io.InputStream;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -191,7 +192,9 @@ public class BundleResourceInstaller ext
 	
 	private BundleRevision installBundle() throws Exception {
 		final Bundle bundle;
-		InputStream is = (InputStream)resource.getClass().getMethod("getContent").invoke(resource);
+		Method getContent = resource.getClass().getMethod("getContent");
+		getContent.setAccessible(true);
+		InputStream is = (InputStream)getContent.invoke(resource);
 		ThreadLocalSubsystem.set(provisionTo);
 		try {
 			bundle = provisionTo.getRegion().installBundleAtLocation(getLocation(), is);

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1451Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1451Test.java?rev=1714627&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1451Test.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1451Test.java Mon Nov 16 16:42:24 2015
@@ -0,0 +1,170 @@
+/*
+ * 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.defect;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+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.SubsystemTest;
+import org.apache.aries.subsystem.itests.util.TestCapability;
+import org.apache.aries.subsystem.itests.util.TestRepository;
+import org.apache.aries.subsystem.itests.util.TestRequirement;
+import org.apache.aries.subsystem.itests.util.TestResource;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+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.repository.RepositoryContent;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+public class Aries1451Test extends SubsystemTest {
+
+    private static final String APPLICATION_A = "application.a.esa";
+    private static final String BUNDLE_A = "bundle.a.jar";
+    private static final String BUNDLE_B = "bundle.b.jar";
+    private static final String PACKAGE_REQUIREMENT = "org.apache.aries.test.bundlebrequirement";
+
+    private static boolean createdTestFiles;
+
+    @Before
+    public void createTestFiles() throws Exception {
+        if (createdTestFiles)
+            return;
+        createBundleA();
+        createApplicationA();
+        createdTestFiles = true;
+
+        //set up repository to satisfy BUNDLE_A's package requirement for a package in BUNDLE_B use
+        // a RepositoryContent test with implementation that is private. 
+        try {
+            serviceRegistrations.add(
+                    bundleContext.registerService(
+                            Repository.class, 
+                            createTestRepository(), 
+                            null));
+        }
+        catch (IOException e) {
+            throw new RuntimeException(e);
+        }        
+    }
+
+    private void createBundleA() throws IOException {
+        createBundle(name(BUNDLE_A), importPackage(PACKAGE_REQUIREMENT));
+    }
+
+    private void createApplicationA() throws IOException {
+        createApplicationAManifest();
+        createSubsystem(APPLICATION_A, BUNDLE_A);
+    }
+
+    private void createApplicationAManifest() throws IOException {
+        Map<String, String> attributes = new HashMap<String, String>();
+        attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_A);
+        attributes.put(SubsystemConstants.SUBSYSTEM_CONTENT, BUNDLE_A + ";type=osgi.bundle");
+        createManifest(APPLICATION_A + ".mf", attributes);
+    }
+
+
+    @Test
+    public void testInstallWithAccessProtectedRepository() throws Exception {
+        Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
+        try {
+            startSubsystem(applicationA);
+        }
+        finally {
+            stopAndUninstallSubsystemSilently(applicationA);
+        }
+    }
+
+
+    private Repository createTestRepository() throws IOException {
+        return new TestRepository.Builder()
+        .resource(createTestBundleResource())
+        .build();
+    }
+
+    private byte[] createTestBundleContent() throws IOException {
+        Manifest manifest = new Manifest();
+        manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+        manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, BUNDLE_B);
+        manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE,  PACKAGE_REQUIREMENT);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        JarOutputStream jos = new JarOutputStream(baos, manifest);
+        jos.close();
+        return baos.toByteArray();
+    }
+
+
+    //This resource must have private visibility for the test 
+    private Resource createTestBundleResource() throws IOException {
+
+        List<TestCapability.Builder> capabilities = new ArrayList<TestCapability.Builder>() {
+            private static final long serialVersionUID = 1L;
+
+            {
+                add(new TestCapability.Builder()
+                .namespace(IdentityNamespace.IDENTITY_NAMESPACE)
+                .attribute(IdentityNamespace.IDENTITY_NAMESPACE, BUNDLE_B)
+                .attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE));
+                add(new TestCapability.Builder()
+                .namespace(PackageNamespace.PACKAGE_NAMESPACE)
+                .attribute(PackageNamespace.PACKAGE_NAMESPACE, PACKAGE_REQUIREMENT)
+                .attribute(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE, "0.0.0"));
+            }
+        };
+
+        return new PrivateRepositoryContent(capabilities, Collections.<TestRequirement.Builder>emptyList(), 
+                createTestBundleContent());
+    }
+
+    private class PrivateRepositoryContent extends TestResource implements RepositoryContent {
+
+        private final byte[] content;
+
+        public PrivateRepositoryContent(List<TestCapability.Builder> capabilities, 
+                List<TestRequirement.Builder> requirements, byte[] content) {
+            super(capabilities, requirements);
+            this.content = content;
+        }
+
+        @Override
+        public InputStream getContent() {
+            try {
+                return new ByteArrayInputStream(content);
+            }
+            catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}