blob: 7f5b328a3cc9448cf3154d47df02b71086c27074 (
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
|
/*******************************************************************************
* Copyright (c) 2011 Red Hat Inc..
* 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:
* Red Hat Incorporated - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.profiling.launch;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy;
import org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher;
import org.eclipse.linuxtools.internal.profiling.launch.Messages;
import org.eclipse.linuxtools.internal.profiling.launch.ProfileLaunchPlugin;
public class RemoteProxyManager implements IRemoteProxyManager {
private static final String EXT_ATTR_CLASS = "class"; //$NON-NLS-1$
private static final String LOCALSCHEME = "file"; //$NON-NLS-1$
private static RemoteProxyManager manager;
private LocalFileProxy lfp;
private Map<String, IRemoteProxyManager> remoteManagers = new HashMap<String, IRemoteProxyManager>();
private RemoteProxyManager() {
// do nothing
}
public static RemoteProxyManager getInstance() {
if (manager == null)
manager = new RemoteProxyManager();
return manager;
}
LocalFileProxy getLocalFileProxy() {
if (lfp == null)
lfp = new LocalFileProxy();
return lfp;
}
private IRemoteProxyManager getRemoteManager(String schemeId) throws CoreException {
IRemoteProxyManager remoteManager = remoteManagers.get(schemeId);
if (remoteManager == null) {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(ProfileLaunchPlugin.PLUGIN_ID, IRemoteProxyManager.EXTENSION_POINT_ID);
IConfigurationElement[] infos = extensionPoint.getConfigurationElements();
for(int i = 0; i < infos.length; i++) {
IConfigurationElement configurationElement = infos[i];
if (configurationElement.getName().equals(IRemoteProxyManager.MANAGER_NAME)) {
if (configurationElement.getAttribute(IRemoteProxyManager.SCHEME_ID).equals(schemeId)) {
Object obj = configurationElement.createExecutableExtension(EXT_ATTR_CLASS);
if (obj instanceof IRemoteProxyManager) {
remoteManager = (IRemoteProxyManager)obj;
remoteManagers.put(schemeId, remoteManager);
break;
}
}
}
}
}
return remoteManager;
}
public IRemoteFileProxy getFileProxy(URI uri) throws CoreException {
String scheme = uri.getScheme();
if (scheme != null && !scheme.equals(LOCALSCHEME)){
IRemoteProxyManager manager = getRemoteManager(scheme);
if (manager != null)
return manager.getFileProxy(uri);
else
throw new CoreException(new Status(IStatus.ERROR, ProfileLaunchPlugin.PLUGIN_ID,
IStatus.OK, Messages.RemoteProxyManager_unrecognized_scheme + scheme, null));
}
return getLocalFileProxy();
}
public IRemoteFileProxy getFileProxy(IProject project) throws CoreException {
URI projectURI = project.getLocationURI();
return getFileProxy(projectURI);
}
public IRemoteCommandLauncher getLauncher(URI uri) throws CoreException {
String scheme = uri.getScheme();
if (scheme != null && !scheme.equals(LOCALSCHEME)){
IRemoteProxyManager manager = getRemoteManager(scheme);
if (manager != null)
return manager.getLauncher(uri);
}
return new LocalLauncher();
}
public IRemoteCommandLauncher getLauncher(IProject project) throws CoreException {
URI projectURI = project.getLocationURI();
return getLauncher(projectURI);
}
public String getOS(URI uri) throws CoreException {
String scheme = uri.getScheme();
if (scheme != null && !scheme.equals(LOCALSCHEME)){
IRemoteProxyManager manager = getRemoteManager(scheme);
if (manager != null)
return manager.getOS(uri);
}
return Platform.getOS();
}
public String getOS(IProject project) throws CoreException {
URI projectURI = project.getLocationURI();
return getOS(projectURI);
}
}
|