Project

General

Profile

« Previous | Next » 

Revision 21ce1d0d

Added by Cherian Mathew almost 8 years ago

Revert update handler to earlier version

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/UpdateHandler.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
9 11
package eu.etaxonomy.taxeditor.update;
10 12

  
11
import java.lang.reflect.InvocationTargetException;
12
import java.net.URI;
13

  
14
import org.eclipse.core.commands.AbstractHandler;
15
import org.eclipse.core.commands.ExecutionEvent;
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
21
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
22
import org.eclipse.equinox.internal.p2.ui.ProvUI;
23
import org.eclipse.equinox.p2.core.IProvisioningAgent;
24
import org.eclipse.equinox.p2.core.ProvisionException;
25
import org.eclipse.equinox.p2.operations.ProvisioningJob;
26
import org.eclipse.equinox.p2.operations.ProvisioningSession;
13
import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
14
import org.eclipse.equinox.p2.operations.RepositoryTracker;
27 15
import org.eclipse.equinox.p2.operations.UpdateOperation;
28
import org.eclipse.equinox.p2.repository.IRepositoryManager;
29
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
30
import org.eclipse.equinox.p2.ui.ProvisioningUI;
31
import org.eclipse.jface.dialogs.MessageDialog;
32
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
34
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.widgets.Display;
36
import org.eclipse.ui.IWorkbench;
37
import org.eclipse.ui.PlatformUI;
38
import org.osgi.framework.BundleContext;
39
import org.osgi.framework.ServiceReference;
40

  
41
import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
42
import eu.etaxonomy.taxeditor.model.MessagingUtils;
16
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
17
import org.eclipse.jface.wizard.WizardDialog;
43 18

  
44 19
/**
45 20
 * UpdateHandler invokes the check for updates UI
46 21
 *
22
 * @since 3.4
47 23
 */
48
public class UpdateHandler extends AbstractHandler {
49

  
50
    private static final String ERROR_PERFORMING_UPDATES = "Error performing updates";
51
    /**
52
     * {@inheritDoc}
53
     */
54
    @Override
55
    public Object execute(ExecutionEvent event) throws ExecutionException {
56
        // update using a progress monitor
57
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
58
            @Override
59
            public void run(IProgressMonitor monitor) throws InvocationTargetException,
60
                    InterruptedException {
61
                doExecute(monitor);
62
            }
63
        };
64

  
65
        try {
66
            new ProgressMonitorDialog(null).run(true, true, runnable);
67
        } catch (InvocationTargetException | InterruptedException e) {
68
            showError(e);
69
        }
70
        return null;
71
    }
72

  
73
    private void doExecute(IProgressMonitor monitor) {
74

  
75
        //UpdateOperation operation = new UpdateOperation(ProvisioningUI.getDefaultUI().getSession());
76

  
77
        BundleContext bundleContext = TaxonomicEditorPlugin.getContext();
78
        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
79
        if (reference == null) {
80
            showMessage(MessageDialog.ERROR, ERROR_PERFORMING_UPDATES, "No provisioning agent found.  This application is not set up for updates.");
81
            return;
82
        }
83

  
84
        final IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
85
        final IWorkbench workbench = PlatformUI.getWorkbench();
86

  
87
        ProvisioningSession session = new ProvisioningSession(agent);
88
        // update all user-visible installable units
89
        UpdateOperation operation = new UpdateOperation(session);
24
public class UpdateHandler extends PreloadingRepositoryHandler {
90 25

  
91
        // force refresh all the repository caches before update
92
        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
93
        URI[] repos = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
26
    boolean hasNoRepos = false;
94 27

  
95
        for(URI repo : repos) {
96
            try {
97
                metaManager.refreshRepository(repo, null);
98
            } catch (ProvisionException | OperationCanceledException e) {
99
                showError(e);
100
            }
101
        }
102

  
103
        // set location of artifact and metadata repo
104
        operation.getProvisioningContext().setArtifactRepositories(repos);
105
        operation.getProvisioningContext().setMetadataRepositories(repos);
106

  
107
        IStatus status = operation.resolveModal(monitor);
108

  
109
//        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
110
//            if (UpdateSingleIUWizard.validFor(operation)) {
111
//                // Special case for only updating a single root
112
//                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
113
//                WizardDialog dialog = new WizardDialog(getShell(), wizard);
114
//                dialog.create();
115
//                dialog.open();
116
//            } else {
117
//                // Open the normal version of the update wizard
118
//                getProvisioningUI().openUpdateWizard(false, operation, job);
119
//            }
120
//        }
121

  
122
        if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
123
            showMessage(MessageDialog.INFORMATION, "Checking for updates", "No updates were found");
28
    @Override
29
    protected void doExecute(LoadMetadataRepositoryJob job) {
30
        if (hasNoRepos) {
124 31
            return;
125 32
        }
126

  
127
        final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
128
        if (provisioningJob != null) {
129
            Display.getDefault().syncExec(new Runnable() {
130
                @Override
131
                public void run() {
132
                    boolean performUpdate = MessageDialog.openQuestion(
133
                            null,
134
                            "Updates available",
135
                            "There are updates available. Do you want to install them now?");
136
                    if (performUpdate) {
137
                        provisioningJob.addJobChangeListener(new JobChangeAdapter() {
138
                            @Override
139
                            public void done(IJobChangeEvent event) {
140
                                if (event.getResult().isOK()) {
141
                                    Display.getDefault().syncExec(new Runnable() {
142
                                        @Override
143
                                        public void run() {
144
                                            boolean restart = MessageDialog.openQuestion(null,
145
                                                    "Updates installed, restart?",
146
                                                    "Updates have been installed successfully, do you want to restart?");
147
                                            if (restart) {
148
                                                workbench.restart();
149
                                            }
150
                                        }
151
                                    });
152
                                } else {
153
                                    MessageDialog.openInformation(
154
                                            null,
155
                                            ERROR_PERFORMING_UPDATES,
156
                                            event.getResult().getMessage());
157
                                }
158
                            }
159
                        });
160
                        provisioningJob.schedule();
161
                    }
162
                }
163
            });
164
        } else {
165
            if (operation.hasResolved()) {
166
                showMessage(MessageDialog.ERROR, ERROR_PERFORMING_UPDATES, "Couldn't get provisioning job: " + operation.getResolutionResult());
33
        UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
34

  
35

  
36
        // check for updates
37
        operation.resolveModal(null);
38
        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
39
            if (UpdateSingleIUWizard.validFor(operation)) {
40
                // Special case for only updating a single root
41
                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
42
                WizardDialog dialog = new WizardDialog(getShell(), wizard);
43
                dialog.create();
44
                dialog.open();
167 45
            } else {
168
                showMessage(MessageDialog.ERROR, ERROR_PERFORMING_UPDATES, "Couldn't resolve provisioning job");
46
                // Open the normal version of the update wizard
47
                getProvisioningUI().openUpdateWizard(false, operation, job);
169 48
            }
170 49
        }
171 50
    }
172 51

  
173
    private void showMessage(final int kind, final String title, final String info) {
174
        Display.getDefault().syncExec(new Runnable() {
175
            @Override
176
            public void run() {
177
                MessageDialog.open(kind, null, title, info, SWT.NONE);
178
            }
179
        });
180
    }
181

  
182
    private void showError(final Throwable t) {
183
        Display.getDefault().syncExec(new Runnable() {
184
            @Override
185
            public void run() {
186
                MessagingUtils.errorDialog(ERROR_PERFORMING_UPDATES,
187
                        this,
188
                        t.getMessage(),
189
                        TaxonomicEditorPlugin.PLUGIN_ID,
190
                        t,
191
                        true);
192
            }
193
        });
52
    @Override
53
    protected boolean preloadRepositories() {
54
        hasNoRepos = false;
55
        RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
56
        if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
57
            hasNoRepos = true;
58
            return false;
59
        }
60
        return super.preloadRepositories();
194 61
    }
195

  
196

  
197 62
}
eu.etaxonomy.taxeditor/eu.etaxonomy.taxeditor.product
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<?pde version="3.5"?><product application="eu.etaxonomy.taxeditor.application.application" id="eu.etaxonomy.taxeditor.application.eu_etaxonomy_taxeditor_product" includeLaunchers="true" name="EDIT Taxonomic Editor" uid="eu.etaxonomy.taxeditor.product" useFeatures="true" version="3.12.0.SNAPSHOT">
3
  <aboutInfo>
4
    <image path="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
5
    <text>
2
<?pde version="3.5"?>
3

  
4
<product name="EDIT Taxonomic Editor" uid="eu.etaxonomy.taxeditor.product" id="eu.etaxonomy.taxeditor.application.eu_etaxonomy_taxeditor_product" application="eu.etaxonomy.taxeditor.application.application" version="3.12.0.qualifier" useFeatures="true" includeLaunchers="true">
5

  
6
   <aboutInfo>
7
      <image path="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
8
      <text>
6 9
         %productBlurb
7 10
      </text>
8
  </aboutInfo>
9
  <configIni use="default"></configIni>
10
  <launcherArgs>
11
    <programArgs>-data @user.home/.cdmLibrary -Dserver_port=58080</programArgs>
12
    <vmArgs>-Xmx512M -XX:MaxPermSize=256M -Dorg.eclipse.update.reconcile=false -Declipse.p2.unsignedPolicy=allow</vmArgs>
13
    <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts</vmArgsMac>
14
  </launcherArgs>
15
  <windowImages i16="/eu.etaxonomy.taxeditor.application/icons/256color_16x16.gif" i32="/eu.etaxonomy.taxeditor.application/icons/256color_32x32.gif" i48="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
16
  <splash location="eu.etaxonomy.taxeditor.application" startupForegroundColor="000000" startupMessageRect="7,432,360,20" startupProgressRect="5,447,366,15"/>
17
  <launcher name="TaxonomicEditor">
18
    <solaris/>
19
    <win useIco="false">
20
      <bmp/>
21
    </win>
22
  </launcher>
23
  <vm></vm>
24
  <plugins></plugins>
25
  <features>
26
    <feature id="eu.etaxonomy.taxeditor.feature"/>
27
  </features>
28
  <configurations>
29
    <plugin autoStart="true" id="eu.etaxonomy.taxeditor.application" startLevel="5"/>
30
    <plugin autoStart="true" id="org.eclipse.core.runtime" startLevel="4"/>
31
    <plugin autoStart="true" id="org.eclipse.equinox.common" startLevel="2"/>
32
    <plugin autoStart="true" id="org.eclipse.equinox.ds" startLevel="2"/>
33
    <plugin autoStart="true" id="org.eclipse.equinox.p2.transport.ecf" startLevel="4"/>
34
    <plugin autoStart="true" id="org.eclipse.equinox.simpleconfigurator" startLevel="1"/>
35
  </configurations>
11
   </aboutInfo>
12

  
13
   <configIni use="default">
14
   </configIni>
15

  
16
   <launcherArgs>
17
      <programArgs>-data @user.home/.cdmLibrary -Dserver_port=58080
18
      </programArgs>
19
      <vmArgs>-Xmx512M -XX:MaxPermSize=256M -Dorg.eclipse.update.reconcile=false -Declipse.p2.unsignedPolicy=allow
20
      </vmArgs>
21
      <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
22
      </vmArgsMac>
23
   </launcherArgs>
24

  
25
   <windowImages i16="/eu.etaxonomy.taxeditor.application/icons/256color_16x16.gif" i32="/eu.etaxonomy.taxeditor.application/icons/256color_32x32.gif" i48="/eu.etaxonomy.taxeditor.application/icons/256color_48x48.gif"/>
26

  
27
   <splash
28
      location="eu.etaxonomy.taxeditor.application"
29
      startupProgressRect="5,447,366,15"
30
      startupMessageRect="7,432,360,20"
31
      startupForegroundColor="000000" />
32
   <launcher name="TaxonomicEditor">
33
      <solaris/>
34
      <win useIco="false">
35
         <bmp/>
36
      </win>
37
   </launcher>
38

  
39
   <vm>
40
   </vm>
41

  
42
   <plugins>
43
   </plugins>
44

  
45
   <features>
46
      <feature id="eu.etaxonomy.taxeditor.feature"/>
47
   </features>
48

  
49
   <configurations>
50
      <plugin id="eu.etaxonomy.taxeditor.application" autoStart="true" startLevel="5" />
51
      <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="4" />
52
      <plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
53
      <plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="2" />
54
      <plugin id="org.eclipse.equinox.p2.transport.ecf" autoStart="true" startLevel="4" />
55
      <plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
56
   </configurations>
57

  
36 58
</product>

Also available in: Unified diff