Revision 4884e7f6
Added by Katja Luther over 2 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/update/UpdateHandler.java | ||
---|---|---|
10 | 10 |
*******************************************************************************/ |
11 | 11 |
package eu.etaxonomy.taxeditor.handler.update; |
12 | 12 |
|
13 |
import java.net.InetSocketAddress; |
|
14 |
import java.net.MalformedURLException; |
|
15 |
import java.net.Proxy; |
|
16 |
import java.net.SocketAddress; |
|
17 | 13 |
import java.net.URI; |
18 |
import java.net.URL; |
|
19 |
import java.net.URLConnection; |
|
20 |
|
|
21 | 14 |
import org.apache.log4j.Logger; |
22 |
import org.eclipse.core.runtime.CoreException; |
|
15 |
|
|
23 | 16 |
import org.eclipse.core.runtime.IProgressMonitor; |
24 | 17 |
import org.eclipse.core.runtime.IStatus; |
25 | 18 |
import org.eclipse.core.runtime.Status; |
... | ... | |
35 | 28 |
import org.eclipse.equinox.p2.operations.UpdateOperation; |
36 | 29 |
import org.eclipse.jface.dialogs.MessageDialog; |
37 | 30 |
import org.eclipse.swt.widgets.Shell; |
38 |
import org.osgi.framework.BundleContext; |
|
39 |
import org.osgi.framework.FrameworkUtil; |
|
40 |
import org.osgi.framework.ServiceReference; |
|
41 |
import org.osgi.util.tracker.ServiceTracker; |
|
42 |
import org.eclipse.core.internal.net.ProxyData; |
|
43 |
import org.eclipse.core.internal.net.ProxyManager; |
|
44 |
import org.eclipse.core.net.proxy.IProxyData; |
|
45 |
import org.eclipse.core.net.proxy.IProxyService; |
|
31 |
|
|
46 | 32 |
|
47 | 33 |
import eu.etaxonomy.taxeditor.l10n.Messages; |
48 | 34 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
49 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
50 |
import eu.etaxonomy.taxeditor.workbench.Activator; |
|
35 |
|
|
51 | 36 |
|
52 | 37 |
/** |
53 | 38 |
* UpdateHandler invokes the check for updates UI |
... | ... | |
60 | 45 |
|
61 | 46 |
private UpdateOperation operation; |
62 | 47 |
|
63 |
private ServiceTracker proxyTracker; |
|
64 |
Proxy proxy; |
|
48 |
|
|
65 | 49 |
|
66 | 50 |
@Execute |
67 | 51 |
public void execute(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync, |
... | ... | |
118 | 102 |
|
119 | 103 |
// configure update operation |
120 | 104 |
final ProvisioningSession session = new ProvisioningSession(agent); |
121 |
MessagingUtils.info("Try to get updates" + System.currentTimeMillis()); |
|
122 |
operation = new UpdateOperation(session); |
|
105 |
MessagingUtils.info("Try to get updates" + System.currentTimeMillis()); |
|
106 |
try{ |
|
107 |
operation = new UpdateOperation(session); |
|
108 |
configureUpdate(operation); |
|
109 |
// check for updates, this causes I/O |
|
110 |
final IStatus status = operation.resolveModal(monitor); |
|
111 |
// failed to find updates (inform user and exit) |
|
112 |
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { |
|
113 |
showMessage(shell, sync); |
|
114 |
return Status.CANCEL_STATUS; |
|
115 |
} |
|
116 |
MessagingUtils.info("update resolved " + System.currentTimeMillis() + "Status: " + status.toString()); |
|
117 |
}catch(Exception e){ |
|
118 |
MessagingUtils.warn(this.getClass(), e.getStackTrace().toString()); |
|
119 |
return Status.CANCEL_STATUS; |
|
120 |
} |
|
121 |
|
|
123 | 122 |
|
124 | 123 |
|
125 |
configureUpdate(operation); |
|
126 |
|
|
127 |
// check for updates, this causes I/O |
|
128 |
final IStatus status = operation.resolveModal(monitor); |
|
129 |
ungetProxyService(); |
|
130 |
MessagingUtils.info("update resolved " + System.currentTimeMillis() + "Status: " + status.toString()); |
|
131 |
// failed to find updates (inform user and exit) |
|
132 |
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) { |
|
133 |
showMessage(shell, sync); |
|
134 |
return Status.CANCEL_STATUS; |
|
135 |
} |
|
136 | 124 |
return Status.OK_STATUS; |
137 | 125 |
} |
138 | 126 |
|
139 |
public static ProxyManager getProxyService() { |
|
140 |
BundleContext bc = Activator.getDefault().getBundle().getBundleContext(); |
|
141 |
ServiceReference serviceReference = bc.getServiceReference(IProxyService.class.getName()); |
|
142 |
ProxyManager service = (ProxyManager) bc.getService(serviceReference); |
|
143 |
return service; |
|
144 |
} |
|
145 |
|
|
146 |
public static boolean ungetProxyService() { |
|
147 |
BundleContext bc = Activator.getDefault().getBundle().getBundleContext(); |
|
148 |
ServiceReference serviceReference = bc.getServiceReference(IProxyService.class.getName()); |
|
149 |
return bc.ungetService(serviceReference); |
|
150 |
|
|
151 |
} |
|
152 |
|
|
127 |
|
|
128 |
|
|
153 | 129 |
private void configureProvisioningJob(ProvisioningJob provisioningJob, final Shell shell, final UISynchronize sync, |
154 | 130 |
final IWorkbench workbench) { |
155 | 131 |
|
Also available in: Unified diff
minor for update problems