From e93834dc06338e2018ef23bcad407067f773f50c Mon Sep 17 00:00:00 2001 From: rfeng Date: Mon, 16 Mar 2009 17:51:28 +0000 Subject: Update the MF and pom git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@754968 13f79535-47bb-0310-9956-ffa450edef68 --- .../META-INF/MANIFEST.MF | 34 ++++++++ .../modules/implementation-osgi-runtime/pom.xml | 16 +++- .../osgi/runtime/OSGiTargetInvoker.java | 74 +++++++++++++++- .../dosgi/test/CalculatorOSGiNodeTestCase.java | 98 ++++++++++++++-------- 4 files changed, 181 insertions(+), 41 deletions(-) create mode 100644 java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF (limited to 'java/sca/modules') diff --git a/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF b/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5acde3c935 --- /dev/null +++ b/java/sca/modules/implementation-osgi-runtime/META-INF/MANIFEST.MF @@ -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/ + diff --git a/java/sca/modules/implementation-osgi-runtime/pom.xml b/java/sca/modules/implementation-osgi-runtime/pom.xml index 13ef5c983f..b7ac27f7e0 100644 --- a/java/sca/modules/implementation-osgi-runtime/pom.xml +++ b/java/sca/modules/implementation-osgi-runtime/pom.xml @@ -46,6 +46,14 @@ 2.0-SNAPSHOT runtime + + + org.apache.tuscany.sca + tuscany-contribution-java + 2.0-SNAPSHOT + runtime + + org.eclipse osgi @@ -64,6 +72,7 @@ org.apache.tuscany.sca tuscany-node-api 2.0-SNAPSHOT + test @@ -94,32 +103,35 @@ org.apache.tuscany.sca tuscany-interface-java-xml 2.0-SNAPSHOT - runtime + test org.apache.tuscany.sca tuscany-implementation-java 2.0-SNAPSHOT + test org.apache.tuscany.sca tuscany-implementation-java-runtime 2.0-SNAPSHOT + test org.apache.tuscany.sca tuscany-implementation-java-xml 2.0-SNAPSHOT + test org.apache.tuscany.sca tuscany-assembly-xml 2.0-SNAPSHOT - runtime + test diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java index f6e2eb09ed..8e7de6dd8c 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java +++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java @@ -21,11 +21,16 @@ package org.apache.tuscany.sca.implementation.osgi.runtime; 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 @@ public class OSGiTargetInvoker implements Invoker { 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 @@ public class OSGiTargetInvoker implements Invoker { return msg; } + /** + * @Deprecated + */ + private static Class[] getPhysicalTypes(Operation operation) { + DataType> inputType = operation.getInputType(); + if (inputType == null) { + return new Class[] {}; + } + List 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 matchingMethods = new ArrayList(); + 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); + } + } diff --git a/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java index 8b4d16f783..abd2985005 100644 --- a/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java +++ b/java/sca/modules/implementation-osgi-runtime/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java @@ -24,9 +24,13 @@ import java.lang.reflect.InvocationHandler; 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 @@ import calculator.dosgi.operations.SubtractServiceImpl; public class CalculatorOSGiNodeTestCase { private static EquinoxHost host; + public static URL getCodeLocation(final Class anchorClass) { + return AccessController.doPrivileged(new PrivilegedAction() { + public URL run() { + return anchorClass.getProtectionDomain().getCodeSource().getLocation(); + } + }); + } + /** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { - Set bundles = new HashSet(); + try { + Set bundles = new HashSet(); - 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 @@ public class CalculatorOSGiNodeTestCase { if ((s & Bundle.ACTIVE) != 0) { sb.append(" ACTIVE"); } - + if (verbose) { sb.append(" ").append(bundle.getLocation()); sb.append(" ").append(bundle.getHeaders()); -- cgit v1.2.3