You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/03/16 18:51:29 UTC

svn commit: r754968 - in /tuscany/java/sca/modules/implementation-osgi-runtime: ./ META-INF/ src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/ src/test/java/calculator/dosgi/test/

Author: rfeng
Date: Mon Mar 16 17:51:28 2009
New Revision: 754968

URL: http://svn.apache.org/viewvc?rev=754968&view=rev
Log:
Update the MF and pom

Added:
    tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
Modified:
    tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/   (props changed)
    tuscany/java/sca/modules/implementation-osgi-runtime/pom.xml
    tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
    tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java

Propchange: tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/
            ('svn:ignore' removed)

Added: tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF?rev=754968&view=auto
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF (added)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF Mon Mar 16 17:51:28 2009
@@ -0,0 +1,34 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.apache.tuscany.sca.implementation.osgi.runtime
+Bundle-Version: 2.0.0
+Bundle-ActivationPolicy: lazy
+Bundle-Name: Apache Tuscany SCA OSGi Implementation Runtime
+Bundle-Vendor: The Apache Software Foundation
+Eclipse-LazyStart: true
+Bundle-Activator: org.apache.tuscany.sca.implementation.osgi.runtime.OSGiImplementationRuntimeActivator
+Bundle-Description: Apache Tuscany SCA OSGi Implementation
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.core.factory;version="2.0.0",
+ org.apache.tuscany.sca.core.invocation;version="2.0.0",
+ org.apache.tuscany.sca.core.scope;version="2.0.0",
+ org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.definitions;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.implementation.osgi;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
+ org.apache.tuscany.sca.invocation;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.provider;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0",
+ org.oasisopen.sca.annotation;version="2.0.0";resolution:=optional,
+ org.osgi.framework;version="1.4.0",
+ org.osgi.service.packageadmin;version="1.2.0",
+ org.osgi.util.tracker;version="1.3.3"
+Bundle-DocURL: http://www.apache.org/
+

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/pom.xml?rev=754968&r1=754967&r2=754968&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/pom.xml (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/pom.xml Mon Mar 16 17:51:28 2009
@@ -46,6 +46,14 @@
             <version>2.0-SNAPSHOT</version>
             <scope>runtime</scope>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-contribution-java</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+        
         <dependency>
             <groupId>org.eclipse</groupId>
             <artifactId>osgi</artifactId>
@@ -64,6 +72,7 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-node-api</artifactId>
             <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
@@ -94,32 +103,35 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-interface-java-xml</artifactId>
             <version>2.0-SNAPSHOT</version>
-            <scope>runtime</scope>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-java</artifactId>
             <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-java-runtime</artifactId>
             <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-java-xml</artifactId>
             <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-assembly-xml</artifactId>
             <version>2.0-SNAPSHOT</version>
-            <scope>runtime</scope>
+            <scope>test</scope>
         </dependency>
 
         <dependency>

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java?rev=754968&r1=754967&r2=754968&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java Mon Mar 16 17:51:28 2009
@@ -21,11 +21,16 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.tuscany.sca.core.factory.InstanceWrapper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -77,7 +82,7 @@
             String filter = "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))";
             ServiceReference[] refs = bundleContext.getServiceReferences(javaInterface.getName(), filter);
             Object instance = bundleContext.getService(refs[0]);
-            Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
+            Method m = findMethod(instance.getClass(), operation);
 
             Object ret = invokeMethod(instance, m, msg);
 
@@ -118,4 +123,69 @@
         return msg;
     }
 
+    /**
+     * @Deprecated
+     */
+    private static Class<?>[] getPhysicalTypes(Operation operation) {
+        DataType<List<DataType>> inputType = operation.getInputType();
+        if (inputType == null) {
+            return new Class<?>[] {};
+        }
+        List<DataType> types = inputType.getLogical();
+        Class<?>[] javaTypes = new Class<?>[types.size()];
+        for (int i = 0; i < javaTypes.length; i++) {
+            Type physical = types.get(i).getPhysical();
+            if (physical instanceof Class<?>) {
+                javaTypes[i] = (Class<?>)physical;
+            } else {
+                throw new UnsupportedOperationException();
+            }
+        }
+        return javaTypes;
+    }
+
+    /**
+     * Return the method on the implementation class that matches the operation.
+     * 
+     * @param implClass the implementation class or interface
+     * @param operation the operation to match
+     * @return the method described by the operation
+     * @throws NoSuchMethodException if no such method exists
+     * @Deprecated
+     */
+    public static Method findMethod(Class<?> implClass, Operation operation) throws NoSuchMethodException {
+        String name = operation.getName();
+        if (operation instanceof JavaOperation) {
+            name = ((JavaOperation)operation).getJavaMethod().getName();
+        }
+        Interface interface1 = operation.getInterface();
+        int numParams = operation.getInputType().getLogical().size();
+        if (interface1 != null && interface1.isRemotable()) {
+            List<Method> matchingMethods = new ArrayList<Method>();
+            for (Method m : implClass.getMethods()) {
+                if (m.getName().equals(name) && m.getParameterTypes().length == numParams) {
+                    matchingMethods.add(m);
+                }
+            }
+            
+            // TUSCANY-2180 If there is only one method then we just match on the name 
+            // (this is the same as the existing behaviour)
+            if (matchingMethods.size() == 1) {
+                return matchingMethods.get(0);
+            }
+            if (matchingMethods.size() > 1) {
+                // TUSCANY-2180 We need to check the parameter types too
+                Class<?>[] paramTypes = getPhysicalTypes(operation);
+                return implClass.getMethod(name, paramTypes);
+            }
+            
+            // No matching method found
+            throw new NoSuchMethodException("No matching method for operation " + operation.getName()
+                + " is found on "
+                + implClass);
+        }
+        Class<?>[] paramTypes = getPhysicalTypes(operation);
+        return implClass.getMethod(name, paramTypes);
+    }
+
 }

Modified: tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java?rev=754968&r1=754967&r2=754968&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java (original)
+++ tuscany/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java Mon Mar 16 17:51:28 2009
@@ -24,9 +24,13 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.tuscany.sca.contribution.osgi.impl.OSGiBundleContributionScanner;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
 import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
 import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost;
 import org.apache.tuscany.sca.node.osgi.impl.NodeImpl;
@@ -56,51 +60,71 @@
 public class CalculatorOSGiNodeTestCase {
     private static EquinoxHost host;
 
+    public static URL getCodeLocation(final Class<?> anchorClass) {
+        return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+            public URL run() {
+                return anchorClass.getProtectionDomain().getCodeSource().getLocation();
+            }
+        });
+    }
+
     /**
      * @throws java.lang.Exception
      */
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
-        Set<URL> bundles = new HashSet<URL>();
+        try {
+            Set<URL> bundles = new HashSet<URL>();
 
-        File plugins = new File("target/test-classes/plugins");
-        for (File f : plugins.listFiles()) {
-            if (f.isFile()) {
-                bundles.add(f.toURI().toURL());
+            File plugins = new File("target/test-classes/plugins");
+            for (File f : plugins.listFiles()) {
+                if (f.isFile()) {
+                    bundles.add(f.toURI().toURL());
+                }
             }
-        }
-        
-        bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar",
-                                                 "calculator/dosgi/META-INF/MANIFEST.MF",
-                                                 new String[] {"OSGI-INF/calculator-component.xml",
-                                                               "OSGI-INF/sca/bundle.componentType",
-                                                               "calculator/calculator.composite"},
-                                                 CalculatorService.class,
-                                                 CalculatorServiceImpl.class,
-                                                 CalculatorServiceDSImpl.class,
-                                                 CalculatorActivator.class));
-
-        bundles.add(OSGiTestBundles.createBundle("target/test-classes/operations-bundle.jar",
-                                                 "calculator/dosgi/operations/META-INF/MANIFEST.MF",
-                                                 new String[] {"OSGI-INF/add-component.xml",
-                                                               "OSGI-INF/subtract-component.xml",
-                                                               "OSGI-INF/multiply-component.xml",
-                                                               "OSGI-INF/divide-component.xml"},
-                                                 OperationsActivator.class,
-                                                 AddService.class,
-                                                 AddServiceImpl.class,
-                                                 SubtractService.class,
-                                                 SubtractServiceImpl.class,
-                                                 MultiplyService.class,
-                                                 MultiplyServiceImpl.class,
-                                                 DivideService.class,
-                                                 DivideServiceImpl.class));
-        try {
-            host = new EquinoxHost(bundles);
+
+            bundles.add(getCodeLocation(OSGiImplementation.class));
+            bundles.add(getCodeLocation(OSGiBundleContributionScanner.class));
+
+            bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar",
+                                                     "calculator/dosgi/META-INF/MANIFEST.MF",
+                                                     new String[] {"OSGI-INF/calculator-component.xml",
+                                                                   "OSGI-INF/sca/bundle.componentType",
+                                                                   "calculator/dosgi/calculator.composite"},
+                                                     CalculatorService.class,
+                                                     CalculatorServiceImpl.class,
+                                                     CalculatorServiceDSImpl.class,
+                                                     CalculatorActivator.class));
+
+            bundles.add(OSGiTestBundles.createBundle("target/test-classes/operations-bundle.jar",
+                                                     "calculator/dosgi/operations/META-INF/MANIFEST.MF",
+                                                     new String[] {"OSGI-INF/add-component.xml",
+                                                                   "OSGI-INF/subtract-component.xml",
+                                                                   "OSGI-INF/multiply-component.xml",
+                                                                   "OSGI-INF/divide-component.xml"},
+                                                     OperationsActivator.class,
+                                                     AddService.class,
+                                                     AddServiceImpl.class,
+                                                     SubtractService.class,
+                                                     SubtractServiceImpl.class,
+                                                     MultiplyService.class,
+                                                     MultiplyServiceImpl.class,
+                                                     DivideService.class,
+                                                     DivideServiceImpl.class));
+            host = new EquinoxHost();
             BundleContext context = host.start();
+            for(URL loc: bundles) {
+                host.installBundle(loc, null);
+            }
             for (Bundle b : context.getBundles()) {
-                if (b.getSymbolicName().equals("org.eclipse.equinox.ds")) {
-                    b.start();
+                if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName()
+                    .startsWith("org.apache.tuscany.sca.")) {
+                    try {
+                        b.start();
+                    } catch (Exception e) {
+                        System.out.println(string(b, false));
+                        e.printStackTrace();
+                    }
                     System.out.println(string(b, false));
                 }
             }
@@ -177,7 +201,7 @@
         if ((s & Bundle.ACTIVE) != 0) {
             sb.append(" ACTIVE");
         }
-    
+
         if (verbose) {
             sb.append(" ").append(bundle.getLocation());
             sb.append(" ").append(bundle.getHeaders());