diff options
author | Igor Fedorenko | 2012-08-16 11:45:38 +0000 |
---|---|---|
committer | Igor Fedorenko | 2012-08-16 11:45:47 +0000 |
commit | 3d01ea374eac20c82a420bff9d790a278bb6f395 (patch) | |
tree | 093c9a5f26361219d2837aa327c1d97863094576 /org.eclipse.m2e.core.ui | |
parent | 45af0ea6f9db6ca9f2211ece05e0172f0946df01 (diff) | |
download | m2e-core-3d01ea374eac20c82a420bff9d790a278bb6f395.tar.gz m2e-core-3d01ea374eac20c82a420bff9d790a278bb6f395.tar.xz m2e-core-3d01ea374eac20c82a420bff9d790a278bb6f395.zip |
350414 show mapping source in project properties
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.core.ui')
3 files changed, 122 insertions, 16 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java index 1431ffe7..0b349c87 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java @@ -121,12 +121,8 @@ public class Messages extends NLS { public static String LifecycleMappingPage_title; - public static String LifecycleMappingPreferencePage_Browse; - public static String LifecycleMappingPreferencePage_ChangeLocation; - public static String LifecycleMappingPreferencePage_ChooseNewLocation; - public static String LifecycleMappingPreferencePage_FileDoesNotExist; public static String LifecycleMappingPreferencePage_LifecycleMapping; @@ -850,6 +846,7 @@ public class Messages extends NLS { public static String LifecycleMappingPropertyPage_mntmExpandAll_text; public static String LifecycleMappingPropertyPage_mntmCollapseAll_text; + public static String LifecycleMappingsViewer_trclmnSource_text; static { // initialize resource bundle diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties index 2f234ca5..db03e9e2 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties @@ -60,11 +60,11 @@ LifecycleMappingPage_noMarketplaceEntryDescription=No marketplace entries found LifecycleMappingPage_numErrors={0} errors LifecycleMappingPage_resolveLaterDescription=Resolve Later LifecycleMappingPage_title=Setup Maven plugin connectors -LifecycleMappingPreferencePage_ChooseNewLocation=Choose a new location for the workspace Lifecycle Mappings file -LifecycleMappingPreferencePage_Browse=Browse... -LifecycleMappingPreferencePage_ChangeLocation=Change mapping file location: -LifecycleMappingPreferencePage_FileDoesNotExist=File does not exists: {0} +LifecycleMappingPreferencePage_ChangeLocation=Change mapping file location\: +LifecycleMappingPreferencePage_FileDoesNotExist=File does not exists\: {0} LifecycleMappingPreferencePage_LifecycleMapping=Lifecycle Mappings +LifecycleMappingPreferencePage_WorkspaceMappingsDescription=Edit the lifecycle mappings for the entire workspace.\nWarning\: improperly editing this file may cause problems with the m2e builder. +LifecycleMappingPreferencePage_WorkspaceMappingsOpen=Open workspace lifecycle mappings metadata LifecycleMappingPropertyPage_copyToClipboard=Copy to clipboard LifecycleMappingPropertyPage_mapping=Mapping LifecycleMappingPropertyPage_mntmCollapseAll_text=Collapse All @@ -73,6 +73,7 @@ LifecycleMappingPropertyPage_mntmShowIgnoredExecutions_text=Show ignored executi LifecycleMappingPropertyPage_pageMessage=Lifecycle Mapping (experimental) LifecycleMappingPropertyPage_pluginExecution=Plugin execution LifecycleMappingPropertyPage_showLIfecyclePhases=Show lifecycle phases +LifecycleMappingsViewer_trclmnSource_text=Source LocalArchetypeCatalogDialog_btnBrowse=&Browse... LocalArchetypeCatalogDialog_dialog_title=Select Archetype catalog LocalArchetypeCatalogDialog_error_empty=Archetype catalog is empty @@ -201,8 +202,6 @@ MavenPreferencePage_download=Download repository index updates on startup MavenPreferencePage_hide=Hide folders of physically nested modules (experimental) MavenPreferencePage_update=Update Maven projects on startup MavenPreferencePage_warnIncompleteMapping=Hide warning for incomplete mapping -LifecycleMappingPreferencePage_WorkspaceMappingsDescription=Edit the lifecycle mappings for the entire workspace.\nWarning: improperly editing this file may cause problems with the m2e builder. -LifecycleMappingPreferencePage_WorkspaceMappingsOpen=Open workspace lifecycle mappings metadata MavenProjectPreferencePage_btnResolve=Resolve dependencies from &Workspace projects MavenProjectPreferencePage_dialog_message=Maven settings has changed. Do you want to update project configuration? MavenProjectPreferencePage_dialog_title=Maven Settings diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java index c75b6c6b..682d2023 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java @@ -14,6 +14,7 @@ package org.eclipse.m2e.core.ui.internal.preferences; import java.io.IOException; import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; @@ -22,7 +23,14 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.osgi.framework.Bundle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -46,16 +54,23 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.PlatformUI; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.project.MavenProject; + import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; +import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingResult; 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.PluginExecutionFilter; import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata; import org.eclipse.m2e.core.internal.lifecyclemapping.model.io.xpp3.LifecycleMappingMetadataSourceXpp3Writer; +import org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade; import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata; import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction; import org.eclipse.m2e.core.project.IMavenProjectFacade; @@ -66,6 +81,8 @@ import org.eclipse.m2e.core.ui.internal.Messages; @SuppressWarnings("restriction") class LifecycleMappingsViewer { + private static final Logger log = LoggerFactory.getLogger(LifecycleMappingsViewer.class); + private TreeViewer mappingsTreeViewer; private boolean showPhases = false; @@ -127,6 +144,11 @@ class LifecycleMappingsViewer { trclmnNewColumn.setWidth(100); trclmnNewColumn.setText(Messages.LifecycleMappingPropertyPage_mapping); + TreeViewerColumn treeViewerColumn_2 = new TreeViewerColumn(mappingsTreeViewer, SWT.NONE); + TreeColumn trclmnSource = treeViewerColumn_2.getColumn(); + trclmnSource.setWidth(100); + trclmnSource.setText(Messages.LifecycleMappingsViewer_trclmnSource_text); + mappingsTreeViewer.setContentProvider(new ITreeContentProvider() { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @@ -213,6 +235,8 @@ class LifecycleMappingsViewer { return LifecycleMappingsViewer.this.toString(execution); case 1: return LifecycleMappingsViewer.this.toString(execution, mappings.get(execution)); + case 2: + return getSourcelabel(execution, mappings.get(execution), false); } } return columnIndex == 0 ? element.toString() : null; @@ -296,14 +320,15 @@ class LifecycleMappingsViewer { LifecycleMappingMetadata meta = new LifecycleMappingMetadata(); for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : this.mappings.entrySet()) { + MojoExecutionKey execution = entry.getKey(); List<IPluginExecutionMetadata> mappings = entry.getValue(); if(mappings != null && !mappings.isEmpty()) { for(IPluginExecutionMetadata mapping : mappings) { - // TODO mapping source - meta.addPluginExecution((PluginExecutionMetadata) mapping); + PluginExecutionMetadata clone = ((PluginExecutionMetadata) mapping).clone(); + setMappingSource(execution, mappings, clone); + meta.addPluginExecution(clone); } } else { - MojoExecutionKey execution = entry.getKey(); PluginExecutionFilter filter = new PluginExecutionFilter(execution.getGroupId(), execution.getArtifactId(), execution.getVersion(), execution.getGoal()); @@ -318,6 +343,8 @@ class LifecycleMappingsViewer { } mapping.setActionDom(actionDom); + setMappingSource(execution, mappings, mapping); + meta.addPluginExecution(mapping); } } @@ -342,6 +369,11 @@ class LifecycleMappingsViewer { } } + private void setMappingSource(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings, + PluginExecutionMetadata clone) { + clone.setComment("source: " + getSourcelabel(execution, mappings, true)); //$NON-NLS-1$ + } + boolean isErrorMapping(MojoExecutionKey execution) { List<IPluginExecutionMetadata> mappings = this.mappings.get(execution); if(mappings == null || mappings.isEmpty()) { @@ -386,6 +418,65 @@ class LifecycleMappingsViewer { return sb.toString(); } + String getSourcelabel(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings, boolean detailed) { + LinkedHashSet<String> sources = new LinkedHashSet<String>(); + if(mappings != null && !mappings.isEmpty()) { + for(IPluginExecutionMetadata mapping : mappings) { + LifecycleMappingMetadataSource metadata = ((PluginExecutionMetadata) mapping).getSource(); + if(metadata != null) { + Object source = metadata.getSource(); + if(source instanceof String) { + sources.add((String) source); + } else if(source instanceof Artifact) { + sources.add(getSourceLabel((Artifact) source, detailed)); + } else if(source instanceof MavenProject) { + sources.add(getSourceLabel((MavenProject) source, detailed)); + } else if(source instanceof Bundle) { + sources.add(getSourceLabel((Bundle) source, detailed)); + } else { + sources.add("unknown"); //$NON-NLS-1$ + } + } + } + } else { + if(!LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase())) { + sources.add("uninteresting"); //$NON-NLS-1$ + } + } + StringBuilder sb = new StringBuilder(); + for(String source : sources) { + if(sb.length() > 0) { + sb.append(','); + } + sb.append(source); + } + return sb.toString(); + } + + private String getSourceLabel(Bundle bundle, boolean detailed) { + StringBuilder sb = new StringBuilder("extension"); //$NON-NLS-1$ + if(detailed) { + sb.append('(').append(bundle.getSymbolicName()).append('_').append(bundle.getVersion()).append(')'); + } + return sb.toString(); + } + + private String getSourceLabel(MavenProject project, boolean detailed) { + StringBuilder sb = new StringBuilder("pom"); //$NON-NLS-1$ + if(detailed) { + sb.append('(').append(project.toString()).append(')'); + } + return sb.toString(); + } + + private String getSourceLabel(Artifact plugin, boolean detailed) { + StringBuilder sb = new StringBuilder("maven-plugin"); //$NON-NLS-1$ + if(detailed) { + sb.append('(').append(plugin.toString()).append(')'); + } + return sb.toString(); + } + String toString(MojoExecutionKey execution) { // http://maven.apache.org/guides/plugin/guide-java-plugin-development.html#Shortening_the_Command_Line @@ -421,12 +512,31 @@ class LifecycleMappingsViewer { return a != null ? a.equals(b) : b == null; } - public void setTarget(IProject project) { + public void setTarget(final IProject project) { if(project == null) { // TODO FIXADE find the mojo execution mapping for the workspace...How do I do this? } else { - IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project); - mappings = facade.getMojoExecutionMapping(); + try { + PlatformUI.getWorkbench().getProgressService().run(false, false, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project); + MavenExecutionRequest executionRequest; + try { + facade.getMavenProject(monitor); // make sure MavenProject is loaded + executionRequest = MavenPlugin.getMaven().createExecutionRequest(monitor); + } catch(CoreException ex) { + throw new InvocationTargetException(ex); + } + LifecycleMappingResult mappingResult = LifecycleMappingFactory.calculateLifecycleMapping(executionRequest, + (MavenProjectFacade) facade, monitor); + mappings = mappingResult.getMojoExecutionMapping(); + } + }); + } catch(InvocationTargetException ex) { + log.error(ex.getMessage(), ex); + } catch(InterruptedException ex) { + log.error(ex.getMessage(), ex); + } } phases = new LinkedHashMap<String, List<MojoExecutionKey>>(); |