aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-03-01 13:47:13 (EST)
committerPascal Rapicault2011-03-03 16:35:20 (EST)
commit98b50bf774feaad18250c77c2f8ab904e048ff2e (patch)
treec7c7ac80b435812554b76cdd6ab183854feb477a
parentb17a45bfe7c5b0a64edb17d9cd68964eadf93063 (diff)
downloadm2e-core-98b50bf774feaad18250c77c2f8ab904e048ff2e.zip
m2e-core-98b50bf774feaad18250c77c2f8ab904e048ff2e.tar.gz
m2e-core-98b50bf774feaad18250c77c2f8ab904e048ff2e.tar.bz2
bug 335488 - [discovery] Set message in WizardPage for errors
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/Messages.java9
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/messages.properties3
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java205
3 files changed, 164 insertions, 53 deletions
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/Messages.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/Messages.java
index 846f80e..e14bf95 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/Messages.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/Messages.java
@@ -42,8 +42,17 @@ public class Messages extends NLS {
public static String MavenCatalogPage_Title;
+ public static String MavenCatalogViewer_allInstalled;
+
+
public static String MavenCatalogViewer_Error_loading_lifecycle;
+
+ public static String MavenCatalogViewer_noEntries;
+
+
+ public static String MavenCatalogViewer_unexpectedException;
+
public static String MavenDiscoveryWizard_Title;
public static String MavenDiscovery_Wizard_Applicable_Tag;
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/messages.properties b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/messages.properties
index 4f650e4..07ce418 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/messages.properties
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/messages.properties
@@ -17,7 +17,10 @@ DiscoveryWizardProposal_description=Opens the m2e Marketplace dialog and lets yo
DiscoveryWizardProposal_Label=Discover new m2e connectors
MavenCatalogPage_Descripton=Select updates and extensions to install. Press Finish to proceed with installation.\nPress the information button to see a detailed overview and a link to more information.
MavenCatalogPage_Title=Install m2e connectors
+MavenCatalogViewer_allInstalled=All available entries are installed.
MavenCatalogViewer_Error_loading_lifecycle=An error occurred loading lifecycle data for catalog item: {0}
+MavenCatalogViewer_noEntries=No entries available.
+MavenCatalogViewer_unexpectedException=Unexpected exception
MavenDiscoveryWizard_Title=m2e Marketplace
MavenDiscovery_Wizard_Applicable_Tag=Applicable
MavenDiscovery_Wizard_ExtrasTag=Extras
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java
index 125182f..8008555 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java
@@ -11,21 +11,33 @@
package org.eclipse.m2e.internal.discovery.wizards;
+import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Collection;
+import java.util.Set;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
import org.eclipse.equinox.internal.p2.discovery.model.Tag;
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogConfiguration;
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogViewer;
+import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadata;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
+import org.eclipse.m2e.internal.discovery.DiscoveryActivator;
import org.eclipse.m2e.internal.discovery.MavenDiscovery;
+import org.eclipse.m2e.internal.discovery.Messages;
+import org.eclipse.ui.statushandlers.StatusManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,73 +54,136 @@ public class MavenCatalogViewer extends CatalogViewer {
private static final String EXT = ".xml"; //$NON-NLS-1$
+ private Set<String> installedFeatures;
+
+ /*
+ * Outside of tests the shellProvider should generally be a WizardPage which allows setting the header.
+ */
public MavenCatalogViewer(Catalog catalog, IShellProvider shellProvider, IRunnableContext context,
CatalogConfiguration configuration) {
super(catalog, shellProvider, context, configuration);
}
- @Override
- protected void postDiscovery() {
- super.postDiscovery();
-
- final MavenCatalogConfiguration config = (MavenCatalogConfiguration) getConfiguration();
- final Collection<String> selectedPackagingTypes = config.getSelectedPackagingTypes();
- final Collection<MojoExecutionKey> selectedMojos = config.getSelectedMojos();
- final Collection<String> selectedLifecycleIds = config.getSelectedLifecycleIds();
- final Collection<String> selectedConfiguratorIds = config.getSelectedConfiguratorIds();
-
- shellProvider.getShell().getDisplay().syncExec(new Runnable() {
- @SuppressWarnings("synthetic-access")
- public void run() {
- for(CatalogItem ci : getCatalog().getItems()) {
- boolean selected = false;
-
- LifecycleMappingMetadataSource src = MavenDiscovery.getLifecycleMappingMetadataSource(ci);
- if(src != null) {
- for(String packagingType : selectedPackagingTypes) {
- if(hasPackaging(src, packagingType)) {
- selected = true;
- select(ci);
- break;
+ protected void postDiscovery(IProgressMonitor monitor) {
+ final SubMonitor subMon = SubMonitor.convert(monitor, getCatalog().getItems().size() * 3);
+ try {
+ for(CatalogItem connector : getCatalog().getItems()) {
+ connector.setInstalled(installedFeatures != null
+ && installedFeatures.containsAll(connector.getInstallableUnits()));
+ subMon.worked(1);
+ }
+
+ if(getCatalog().getItems().size() == installedFeatures.size()) {
+ handleStatus(new Status(IStatus.ERROR, DiscoveryActivator.PLUGIN_ID, Messages.MavenCatalogViewer_allInstalled));
+ } else {
+ final MavenCatalogConfiguration config = (MavenCatalogConfiguration) getConfiguration();
+ final Collection<String> selectedPackagingTypes = config.getSelectedPackagingTypes();
+ final Collection<MojoExecutionKey> selectedMojos = config.getSelectedMojos();
+ final Collection<String> selectedLifecycleIds = config.getSelectedLifecycleIds();
+ final Collection<String> selectedConfiguratorIds = config.getSelectedConfiguratorIds();
+
+ shellProvider.getShell().getDisplay().syncExec(new Runnable() {
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ for(CatalogItem ci : getCatalog().getItems()) {
+ boolean selected = false;
+ subMon.worked(2);
+
+ LifecycleMappingMetadataSource src = MavenDiscovery.getLifecycleMappingMetadataSource(ci);
+ if(src != null) {
+ for(String packagingType : selectedPackagingTypes) {
+ if(hasPackaging(src, packagingType)) {
+ selected = true;
+ select(ci);
+ break;
+ }
+ }
+ if(selected) {
+ continue;
+ }
+ for(MojoExecutionKey mojoExecution : selectedMojos) {
+ if(matchesFilter(src, mojoExecution)) {
+ selected = true;
+ select(ci);
+ break;
+ }
+ }
+ if(selected) {
+ continue;
+ }
}
- }
- if(selected) {
- continue;
- }
- for(MojoExecutionKey mojoExecution : selectedMojos) {
- if(matchesFilter(src, mojoExecution)) {
- selected = true;
- select(ci);
- break;
+
+ for(String configuratorId : selectedConfiguratorIds) {
+ Tag configuratorIdTag = new Tag(CONFIGURATOR_PREFIX + configuratorId, CONFIGURATOR_PREFIX
+ + configuratorId);
+ if(ci.hasTag(configuratorIdTag)) {
+ selected = true;
+ select(ci);
+ break;
+ }
+ }
+ if(selected) {
+ continue;
}
- }
- if(selected) {
- continue;
- }
- }
- for(String configuratorId : selectedConfiguratorIds) {
- Tag configuratorIdTag = new Tag(CONFIGURATOR_PREFIX + configuratorId, CONFIGURATOR_PREFIX + configuratorId);
- if(ci.hasTag(configuratorIdTag)) {
- selected = true;
- select(ci);
- break;
+ for(String lifecycleId : selectedLifecycleIds) {
+ Tag lifecycleIdTag = new Tag(LIFECYCLE_PREFIX + lifecycleId, LIFECYCLE_PREFIX + lifecycleId);
+ if(ci.hasTag(lifecycleIdTag)) {
+ select(ci);
+ break;
+ }
+ }
}
}
- if(selected) {
- continue;
- }
+ });
+ }
+ } finally {
+ subMon.done();
+ }
+ }
- for(String lifecycleId : selectedLifecycleIds) {
- Tag lifecycleIdTag = new Tag(LIFECYCLE_PREFIX + lifecycleId, LIFECYCLE_PREFIX + lifecycleId);
- if(ci.hasTag(lifecycleIdTag)) {
- select(ci);
- break;
+ @Override
+ public void updateCatalog() {
+ boolean wasCancelled = false;
+ boolean wasError = false;
+ final IStatus[] result = new IStatus[1];
+ try {
+ context.run(true, true, new IRunnableWithProgress() {
+ @SuppressWarnings("synthetic-access")
+ public void run(IProgressMonitor monitor) throws InterruptedException {
+ SubMonitor submon = SubMonitor.convert(monitor, 100);
+ try {
+ if(installedFeatures == null) {
+ installedFeatures = getInstalledFeatures(submon.newChild(10));
+ }
+ result[0] = getCatalog().performDiscovery(submon.newChild(80));
+ if(monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
+ if(!getCatalog().getItems().isEmpty()) {
+ postDiscovery(submon.newChild(10));
}
+ } finally {
+ submon.done();
}
}
- }
- });
+ });
+ } catch(InvocationTargetException e) {
+ result[0] = computeStatus(e, Messages.MavenCatalogViewer_unexpectedException);
+ } catch(InterruptedException e) {
+ // cancelled by user so nothing to do here.
+ wasCancelled = true;
+ }
+ if(result[0] != null && !result[0].isOK()) {
+ handleStatus(result[0]);
+ wasError = true;
+ }
+ if(getCatalog() != null) {
+ catalogUpdated(wasCancelled, wasError);
+ verifyUpdateSiteAvailability();
+ }
+ // help UI tests
+ viewer.setData("discoveryComplete", Boolean.TRUE); //$NON-NLS-1$
}
private void select(CatalogItem ci) {
@@ -116,6 +191,30 @@ public class MavenCatalogViewer extends CatalogViewer {
ci.addTag(MavenDiscovery.APPLICABLE_TAG);
}
+ private void handleStatus(final IStatus status) {
+ if(status.isOK()) {
+ return;
+ }
+
+ if(shellProvider instanceof WizardPage) {
+ shellProvider.getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ // Display the error in the wizard header
+ int messageType = IMessageProvider.INFORMATION;
+ if(status.matches(IStatus.ERROR)) {
+ messageType = IMessageProvider.ERROR;
+ } else if(status.matches(IStatus.WARNING)) {
+ messageType = IMessageProvider.WARNING;
+ }
+ ((WizardPage) shellProvider).setMessage(status.getMessage(), messageType);
+ StatusManager.getManager().handle(status);
+ }
+ });
+ } else {
+ StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
+ }
+ }
+
private static boolean matchesFilter(LifecycleMappingMetadataSource src, MojoExecutionKey mojoExecution) {
for(PluginExecutionMetadata p : src.getPluginExecutions()) {
if(p.getFilter().match(mojoExecution)) {