Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: ab63eeda0d99fd4bd2919bbaeda014b4864682b9 (plain) (blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jem.internal.proxy.ide;
/*
 *  $RCSfile: IDERegistration.java,v $
 *  $Revision: 1.12 $  $Date: 2006/02/21 17:16:44 $ 
 */

import java.net.URL;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.JavaRuntime;

import org.eclipse.jem.internal.proxy.core.*;
import org.eclipse.jem.internal.proxy.ide.awt.IDERegisterAWT;
import org.eclipse.jem.internal.proxy.remote.LocalFileConfigurationContributorController;
/**
 * This is the registration class for starting an IDERemote VM.
 */

public class IDERegistration {
	
	public static ProxyFactoryRegistry startAnImplementation(
		IConfigurationContributor[] contributors,
		boolean attachAWT,
		IProject project,
		String vmName,
		String pluginName,
		IProgressMonitor pm) throws CoreException {
			IDERegistration idereg = new IDERegistration(pluginName);
			return idereg.startImplementation(contributors, attachAWT, project, vmName, pm); 
		}
	
	public IDERegistration() {
	}
	
	private IDERegistration(String pluginName) {
		this.pluginName = pluginName;
	}
	private String pluginName;	

	/**
	 * This will create a remote VM and return an initialized REMProxyFactoryRegistry.
	 * Passed in are:
	 *      project: The project this is being started on. Must not be null and must be a JavaProject. (Currently ignored for IDE).
	 *      attachAWT: Should AWT be attached to this implementation.
	 *      contributors: Contributors to the configuration. Can be null.
	 *      pm: ProgressMonitor to use. Must not be null.
	 *      vmName: Name for the vm. Can be null.
	 */
	public ProxyFactoryRegistry startImplementation(
		IConfigurationContributor[] contributors,
		boolean attachAWT,
		IProject project,
		String vmName,
		IProgressMonitor pm)
		throws CoreException {

		URL[] classPaths = null;
		IJavaProject javaProject = null;
		if (project != null) {
			javaProject = JavaCore.create(project);
			// Add in the paths for the project	 	
			classPaths = ProxyLaunchSupport.convertStringPathsToURL(JavaRuntime.computeDefaultRuntimeClassPath(javaProject));
		} else
			classPaths = new URL[0];

		final IJavaProject jp = javaProject;

		final ProxyLaunchSupport.LaunchInfo launchInfo = new ProxyLaunchSupport.LaunchInfo();
		contributors = ProxyLaunchSupport.fillInLaunchInfo(contributors == null ? ProxyLaunchSupport.EMPTY_CONFIG_CONTRIBUTORS : contributors, launchInfo, jp != null ? jp.getElementName() : null);
		final LocalFileConfigurationContributorController controller = new LocalFileConfigurationContributorController(classPaths, new URL[3][], launchInfo);
		final IConfigurationContributor[] contribs = contributors;
		for (int i = 0; i < contributors.length; i++) {
			final int ii = i;
			// Run in safe mode so that anything happens we don't go away.
			SafeRunner.run(new ISafeRunnable() {
				public void handleException(Throwable exception) {
					// Don't need to do anything. Platform.run logs it for me.
				}

				public void run() throws Exception {
					contribs[ii].initialize(launchInfo.getConfigInfo());
				}
			});				
		}			
		for (int i = 0; i < contributors.length; i++) {
			final int ii = i;
			// Run in safe mode so that anything happens we don't go away.
			SafeRunner.run(new ISafeRunnable() {
				public void handleException(Throwable exception) {
					// Don't need to do anything. Platform.run logs it for me.
				}

				public void run() throws Exception {
					contribs[ii].contributeClasspaths(controller);
				}
			});				
		}
		classPaths = controller.getFinalClasspath();

		final BaseProxyFactoryRegistry registry = (BaseProxyFactoryRegistry) createIDEProxyFactoryRegistry(vmName, pluginName, classPaths);
		ProxyLaunchSupport.performExtensionRegistrations(registry, launchInfo);
		for (int i = 0; i < contribs.length; i++) {
			final int ii = i;
			// Run in safe mode so that anything happens we don't go away.
			SafeRunner.run(new ISafeRunnable() {
				public void handleException(Throwable exception) {
					// Don't need to do anything. Platform.run logs it for me.
				}

				public void run() throws Exception {
					contribs[ii].contributeToRegistry(registry);
				}
			});	
		}

		return registry;
	}

	public static ProxyFactoryRegistry createIDEProxyFactoryRegistry(String aName, String aPluginName, URL[] otherURLs) {
		// Create the registry.
		IDEProxyFactoryRegistry registry =
			new IDEProxyFactoryRegistry(aName, IDEProxyFactoryRegistry.createSpecialLoader(aPluginName, otherURLs));
		initRegistry(registry);
		return registry;
	}

	public static ProxyFactoryRegistry createIDEProxyFactoryRegistry(String aName, ClassLoader loader) {
		// Create the registry.
		IDEProxyFactoryRegistry registry = new IDEProxyFactoryRegistry(aName, loader);
		initRegistry(registry);
		return registry;
	}

	private static void initRegistry(IDEProxyFactoryRegistry registry) {
		new IDEStandardBeanTypeProxyFactory(registry);
		new IDEStandardBeanProxyFactory(registry);
		new IDEMethodProxyFactory(registry);
		// Always support AWT for now
		IDERegisterAWT.registerAWT(registry);
	}
}

Back to the top