author | dadubrow |
Wed, 21 Jul 2010 14:53:42 -0500 | |
changeset 1661 | cd8159f371c7 |
parent 1637 | 06fc2fdd1ac4 |
child 1721 | 18638adda547 |
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 { |
|
65 |
super.start(context); |
|
1661 | 66 |
IProxyData proxyData = ProxyUtils.getProxyData(new URI("http://www.yahoo.com")); //$NON-NLS-1$ |
1637 | 67 |
System.setProperty(PROPERTY_PROXYHOST, proxyData.getHost()); |
68 |
System.setProperty(PROPERTY_PROXYPORT, String.valueOf(proxyData.getPort())); |
|
1360 | 69 |
} |
70 |
||
71 |
/* |
|
72 |
* (non-Javadoc) |
|
73 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
74 |
*/ |
|
75 |
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
|
76 |
super.stop(context); |
1360 | 77 |
plugin = null; |
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Returns the shared instance |
|
82 |
* |
|
83 |
* @return the shared instance |
|
84 |
*/ |
|
85 |
public static Activator getDefault() { |
|
86 |
return plugin; |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Returns an image descriptor for the image file at the given |
|
91 |
* plug-in relative path |
|
92 |
* |
|
93 |
* @param path the path |
|
94 |
* @return the image descriptor |
|
95 |
*/ |
|
96 |
public static ImageDescriptor getImageDescriptor(String path) { |
|
97 |
return imageDescriptorFromPlugin(PLUGIN_ID, path); |
|
98 |
} |
|
1363 | 99 |
|
100 |
/** |
|
101 |
* Log to error log |
|
102 |
* @param message |
|
103 |
* @param t |
|
104 |
*/ |
|
105 |
public static void logError(String message, Throwable t) { |
|
106 |
getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, t)); |
|
107 |
} |
|
1634 | 108 |
|
109 |
/** |
|
110 |
* Get a value from the server.properties file |
|
111 |
* @param key |
|
112 |
* @return |
|
113 |
*/ |
|
114 |
public static String getFromServerProperties(String key) { |
|
115 |
Location installLocation = Platform.getInstallLocation(); |
|
116 |
URL url = installLocation.getURL(); |
|
117 |
IPath path = new Path(url.getPath()); |
|
118 |
path = path.append("configuration/server.properties"); //$NON-NLS-1$ |
|
119 |
File file = path.toFile(); |
|
120 |
Properties properties = new Properties(); |
|
121 |
try { |
|
122 |
InputStream is = new FileInputStream(file); |
|
123 |
properties.load(is); |
|
124 |
is.close(); |
|
125 |
} catch (IOException e) { |
|
126 |
String message = |
|
1661 | 127 |
MessageFormat.format(Messages.Activator_MissingConfigURLError, key); |
1634 | 128 |
Activator.logError(message, e); |
129 |
} |
|
130 |
return (String) properties.get(key); |
|
131 |
} |
|
132 |
||
1360 | 133 |
} |