summaryrefslogtreecommitdiffstats
path: root/sandbox/slaws/runtimecompat/combinedlauncher/src/main/java/launcher/CombinedLauncher.java
blob: 40adc833e2cb17ce58e388ab577cbcd07f2adf63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * 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 launcher;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;

import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;


public class CombinedLauncher {
	
	
	private static final String TWO_X_LAUNCHER = "launcher.TwoXLauncher";
	private static final String ONE_X_LAUNCHER = "launcher.OneXLauncher";

    public static void main(String[] args) throws Exception {
    	// fire up the equinox host for the core set of Tuscany bundles
    	// enough to run the calculator sample
    	
    	// set TUSCANY_HOME environment variable to get 
    	// equinox host to load all the 2.x Tuscany 
    	// bundles + dependencies
    	// Hack so that I don't have to remember to 
    	// set the environment variable. Don't do this at home
        System.setProperty("TUSCANY_HOME", 
        		           "../../../java-2.x/distribution/all/target/apache-tuscany-sca-all-2.0-SNAPSHOT-dir/tuscany-sca-2.0-SNAPSHOT");
        
        // To get to the console run with -Dosgi.console=<port>
        // If running in Eclipse specifying just -Dosgi.console will bring up osgi> in the eclipse console
    	EquinoxHost equinoxHost = new EquinoxHost();
        BundleContext bundleContext = equinoxHost.start();
        
        // the 2.x equinoz host will have added all the Tuscany 2x bundles to the OSGi 
        // environment. Now add the 2.x launcher bundle
        Bundle twoXLauncherbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/2xlauncher/target/2x-launcher-1.0-SNAPSHOT.jar"), "2xlauncherbundle");
        
        // add in the 1.x bundles also
        Bundle oneXbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xbundle/target/1.x-osgi-bundle-1.6-SNAPSHOT.jar"), "1xbundle");
        Bundle oneXLauncherbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xlauncher/target/1x-launcher-1.0-SNAPSHOT.jar"), "1xlauncherbundle");
       
        System.out.println("Bundles loaded");
        
        // find the the 2.x node launcher and get it to run the calculator app
        Class<?> twoXLauncherClass = twoXLauncherbundle.loadClass(TWO_X_LAUNCHER);
        Method twoXLaunchNodeMethod = twoXLauncherClass.getMethod("launchNode");
        twoXLaunchNodeMethod.invoke(null);

        System.out.println("2.x run complete");
        
        // find the the 1.x node launcher and get it to run the calculator app
        Class<?> oneXLauncherClass = oneXLauncherbundle.loadClass(ONE_X_LAUNCHER);
        Method oneXLaunchNodeMethod = oneXLauncherClass.getMethod("launchNode");
        oneXLaunchNodeMethod.invoke(null);
        
        System.out.println("1.x run complete");
        
        equinoxHost.stop();
    }
    
}