author | dadubrow |
Thu, 29 Jul 2010 13:28:20 -0500 | |
changeset 1721 | 18638adda547 |
parent 1661 | cd8159f371c7 |
child 1734 | bf670d38123a |
permissions | -rw-r--r-- |
1377
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
1 |
/* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
3 |
* All rights reserved. |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
8 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
9 |
* Initial Contributors: |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
11 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
12 |
* Contributors: |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
13 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
14 |
* Description: |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
15 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
16 |
*/ |
1360 | 17 |
package com.nokia.carbide.discovery.ui; |
18 |
||
1634 | 19 |
import java.io.File; |
20 |
import java.io.FileInputStream; |
|
21 |
import java.io.IOException; |
|
22 |
import java.io.InputStream; |
|
1637 | 23 |
import java.net.URI; |
1634 | 24 |
import java.net.URL; |
25 |
import java.text.MessageFormat; |
|
26 |
import java.util.Properties; |
|
27 |
||
1637 | 28 |
import org.eclipse.core.net.proxy.IProxyData; |
1634 | 29 |
import org.eclipse.core.runtime.IPath; |
1363 | 30 |
import org.eclipse.core.runtime.IStatus; |
1634 | 31 |
import org.eclipse.core.runtime.Path; |
32 |
import org.eclipse.core.runtime.Platform; |
|
1363 | 33 |
import org.eclipse.core.runtime.Status; |
1360 | 34 |
import org.eclipse.jface.resource.ImageDescriptor; |
1634 | 35 |
import org.eclipse.osgi.service.datalocation.Location; |
1360 | 36 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
37 |
import org.osgi.framework.BundleContext; |
|
38 |
||
1637 | 39 |
import com.nokia.cpp.internal.api.utils.core.ProxyUtils; |
40 |
||
1360 | 41 |
/** |
42 |
* The activator class controls the plug-in life cycle |
|
43 |
*/ |
|
44 |
public class Activator extends AbstractUIPlugin { |
|
45 |
// The plug-in ID |
|
46 |
public static final String PLUGIN_ID = "com.nokia.carbide.discovery.ui"; //$NON-NLS-1$ |
|
47 |
||
48 |
// The shared instance |
|
49 |
private static Activator plugin; |
|
50 |
||
1637 | 51 |
private static final String PROPERTY_PROXYPORT = "network.proxy_port"; //$NON-NLS-1$ |
52 |
private static final String PROPERTY_PROXYHOST = "network.proxy_host"; //$NON-NLS-1$ |
|
53 |
||
1360 | 54 |
/** |
55 |
* The constructor |
|
56 |
*/ |
|
57 |
public Activator() { |
|
58 |
} |
|
59 |
||
60 |
/* |
|
61 |
* (non-Javadoc) |
|
62 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
63 |
*/ |
|
64 |
public void start(BundleContext context) throws Exception { |
|
1721 | 65 |
plugin = this; |
1360 | 66 |
super.start(context); |
1661 | 67 |
IProxyData proxyData = ProxyUtils.getProxyData(new URI("http://www.yahoo.com")); //$NON-NLS-1$ |
1721 | 68 |
if (proxyData != null) { |
69 |
System.setProperty(PROPERTY_PROXYHOST, proxyData.getHost()); |
|
70 |
System.setProperty(PROPERTY_PROXYPORT, String.valueOf(proxyData.getPort())); |
|
71 |
} |
|
1360 | 72 |
} |
73 |
||
74 |
/* |
|
75 |
* (non-Javadoc) |
|
76 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
77 |
*/ |
|
78 |
public void stop(BundleContext context) throws Exception { |
|
1377
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
79 |
super.stop(context); |
1360 | 80 |
plugin = null; |
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Returns the shared instance |
|
85 |
* |
|
86 |
* @return the shared instance |
|
87 |
*/ |
|
88 |
public static Activator getDefault() { |
|
89 |
return plugin; |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Returns an image descriptor for the image file at the given |
|
94 |
* plug-in relative path |
|
95 |
* |
|
96 |
* @param path the path |
|
97 |
* @return the image descriptor |
|
98 |
*/ |
|
99 |
public static ImageDescriptor getImageDescriptor(String path) { |
|
100 |
return imageDescriptorFromPlugin(PLUGIN_ID, path); |
|
101 |
} |
|
1363 | 102 |
|
103 |
/** |
|
104 |
* Log to error log |
|
105 |
* @param message |
|
106 |
* @param t |
|
107 |
*/ |
|
108 |
public static void logError(String message, Throwable t) { |
|
109 |
getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, t)); |
|
110 |
} |
|
1634 | 111 |
|
112 |
/** |
|
113 |
* Get a value from the server.properties file |
|
114 |
* @param key |
|
115 |
* @return |
|
116 |
*/ |
|
117 |
public static String getFromServerProperties(String key) { |
|
118 |
Location installLocation = Platform.getInstallLocation(); |
|
119 |
URL url = installLocation.getURL(); |
|
120 |
IPath path = new Path(url.getPath()); |
|
121 |
path = path.append("configuration/server.properties"); //$NON-NLS-1$ |
|
122 |
File file = path.toFile(); |
|
123 |
Properties properties = new Properties(); |
|
124 |
try { |
|
125 |
InputStream is = new FileInputStream(file); |
|
126 |
properties.load(is); |
|
127 |
is.close(); |
|
128 |
} catch (IOException e) { |
|
129 |
String message = |
|
1661 | 130 |
MessageFormat.format(Messages.Activator_MissingConfigURLError, key); |
1634 | 131 |
Activator.logError(message, e); |
132 |
} |
|
133 |
return (String) properties.get(key); |
|
134 |
} |
|
135 |
||
1360 | 136 |
} |