Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java')
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java114
1 files changed, 51 insertions, 63 deletions
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 84239ba3..07c3267c 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
@@ -13,17 +13,13 @@ package org.eclipse.m2e.internal.discovery.wizards;
import java.net.URL;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
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.operation.IRunnableContext;
@@ -42,12 +38,14 @@ import org.eclipse.osgi.util.NLS;
@SuppressWarnings("restriction")
public class MavenCatalogViewer extends CatalogViewer {
+ private static final String CONFIGURATOR_PREFIX = "configurator:"; //$NON-NLS-1$
+
+ private static final String LIFECYCLE_PREFIX = "lifecycle:"; //$NON-NLS-1$
+
private static final String PATH = "lifecycle/"; //$NON-NLS-1$
private static final String EXT = ".xml"; //$NON-NLS-1$
- private Map<CatalogItem, LifecycleMappingMetadataSource> lifecycleCache = new HashMap<CatalogItem, LifecycleMappingMetadataSource>();
-
public MavenCatalogViewer(Catalog catalog, IShellProvider shellProvider, IRunnableContext context,
CatalogConfiguration configuration) {
super(catalog, shellProvider, context, configuration);
@@ -60,90 +58,80 @@ public class MavenCatalogViewer extends CatalogViewer {
final MavenCatalogConfiguration config = (MavenCatalogConfiguration) getConfiguration();
final Collection<String> selectedPackagingTypes = config.getSelectedPackagingTypes();
final Collection<MojoExecution> 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() {
- Map<String, Set<CatalogItem>> map = new HashMap<String, Set<CatalogItem>>(selectedPackagingTypes.size());
-
- for(String packagingType : selectedPackagingTypes) {
- map.put(packagingType, new HashSet<CatalogItem>());
- for(CatalogItem ci : getCatalog().getItems()) {
- LifecycleMappingMetadataSource src = getLifecycleMappingMetadataSource(ci);
- if(src != null && hasPackaging(src, packagingType)) {
- Set<CatalogItem> items = map.get(packagingType);
- items.add(ci);
+ for (CatalogItem ci : getCatalog().getItems()) {
+ boolean selected = false;
+
+ LifecycleMappingMetadataSource src = getLifecycleMappingMetadataSource(ci);
+ if (src != null) {
+ for (String packagingType : selectedPackagingTypes) {
+ if(hasPackaging(src, packagingType)) {
+ selected = true;
+ select(ci);
+ break;
+ }
}
- }
- }
-
- Map<MojoExecution, Set<CatalogItem>> mojoMap = new HashMap<MojoExecution, Set<CatalogItem>>(selectedMojos
- .size());
- // Mojo
- for(MojoExecution mojoExecution : selectedMojos) {
- mojoMap.put(mojoExecution, new HashSet<CatalogItem>());
- for(CatalogItem ci : getCatalog().getItems()) {
- LifecycleMappingMetadataSource src = getLifecycleMappingMetadataSource(ci);
- if(src != null && matchesFilter(src, mojoExecution)) {
- mojoMap.get(mojoExecution).add(ci);
+ if (selected) {
+ continue;
+ }
+ for(MojoExecution mojoExecution : selectedMojos) {
+ if (matchesFilter(src, mojoExecution)) {
+ selected = true;
+ select(ci);
+ break;
+ }
+ }
+ if (selected) {
+ continue;
}
}
- }
- // Select relevant CatalogItems
- // TODO Make selection smarter
- for(Entry<String, Set<CatalogItem>> type : map.entrySet()) {
- if(type.getValue().isEmpty()) {
- MavenLogger.log(NLS.bind(Messages.MavenCatalogViewer_Missing_packaging_type, type.getKey()));
+ for(String configuratorId : selectedConfiguratorIds) {
+ Tag configuratorIdTag = new Tag(CONFIGURATOR_PREFIX + configuratorId, CONFIGURATOR_PREFIX + configuratorId);
+ if (ci.hasTag(configuratorIdTag)) {
+ selected = true;
+ select(ci);
+ break;
+ }
}
- for(CatalogItem ci : type.getValue()) {
- modifySelection(ci, true);
- ci.addTag(MavenDiscovery.APPLICABLE_TAG);
+ if (selected) {
+ continue;
}
- }
- for(Entry<MojoExecution, Set<CatalogItem>> type : mojoMap.entrySet()) {
- if(type.getValue().isEmpty()) {
- MavenLogger.log(NLS.bind(Messages.MavenCatalogViewer_Missing_mojo_execution, new String[] {
- type.getKey().getGroupId(), type.getKey().getArtifactId(), type.getKey().getExecutionId(),
- type.getKey().getGoal()}));
- }
- for(CatalogItem ci : type.getValue()) {
- modifySelection(ci, true);
- ci.addTag(MavenDiscovery.APPLICABLE_TAG);
+ for(String lifecycleId : selectedLifecycleIds) {
+ Tag lifecycleIdTag = new Tag(LIFECYCLE_PREFIX + lifecycleId, LIFECYCLE_PREFIX + lifecycleId);
+ if (ci.hasTag(lifecycleIdTag)) {
+ select(ci);
+ break;
+ }
}
}
}
});
}
+ private void select(CatalogItem ci) {
+ modifySelection(ci, true);
+ ci.addTag(MavenDiscovery.APPLICABLE_TAG);
+ }
+
private static boolean matchesFilter(LifecycleMappingMetadataSource src, MojoExecution mojoExecution) {
for(PluginExecutionMetadata p : src.getPluginExecutions()) {
if(p.getFilter().match(mojoExecution)) {
return true;
}
}
- for(LifecycleMappingMetadata m : src.getLifecycleMappings()) {
- for(PluginExecutionMetadata p : m.getPluginExecutions()) {
- if(p.getFilter().match(mojoExecution)) {
- return true;
- }
- }
- }
return false;
}
private LifecycleMappingMetadataSource getLifecycleMappingMetadataSource(CatalogItem ci) {
try {
- if(lifecycleCache.get(ci) != null) {
- return lifecycleCache.get(ci);
- }
- LifecycleMappingMetadataSource source = LifecycleMappingFactory
- .createLifecycleMappingMetadataSource(getLifecycleMappingMetadataSourceURL(ci));
- if(source != null) {
- lifecycleCache.put(ci, source);
- }
- return source;
+ return LifecycleMappingFactory.createLifecycleMappingMetadataSource(getLifecycleMappingMetadataSourceURL(ci));
} catch(Exception e) {
MavenLogger.log(new Status(IStatus.WARNING, MavenDiscoveryIcons.PLUGIN_ID, NLS.bind(
Messages.MavenCatalogViewer_Error_loading_lifecycle,

Back to the top