diff options
24 files changed, 993 insertions, 767 deletions
diff --git a/org.eclipse.m2e.core.ui/plugin.properties b/org.eclipse.m2e.core.ui/plugin.properties index 9a938846..da48ae02 100644 --- a/org.eclipse.m2e.core.ui/plugin.properties +++ b/org.eclipse.m2e.core.ui/plugin.properties @@ -77,6 +77,7 @@ page.usersettings.name = User Settings page.archetypes.name = Archetypes page.userinterface.name = User Interface page.warnings.name = Warnings +page.lifecyclemapping.name = Lifecycle Mappings category.general.name = General wizard.install.name = Install or deploy an artifact to a Maven repository wizard.install.description = Install or Deploy an artifact (archive) into a Maven repository @@ -112,4 +113,4 @@ extension-point.lifecycleMappingMetadataSource.name = Lifecycle Mapping Metadata convert.to.maven.name=Convert to Maven Project m2.build.directory.filter.name=Maven build folder -m2.build.directory.filter.description=Hides the Maven build folder
\ No newline at end of file +m2.build.directory.filter.description=Hides the Maven build folder diff --git a/org.eclipse.m2e.core.ui/plugin.xml b/org.eclipse.m2e.core.ui/plugin.xml index 1600e8f4..117f86be 100644 --- a/org.eclipse.m2e.core.ui/plugin.xml +++ b/org.eclipse.m2e.core.ui/plugin.xml @@ -409,6 +409,12 @@ class="org.eclipse.m2e.core.ui.internal.preferences.WarningsPreferencePage" name="%page.warnings.name"> <keywordReference id="org.eclipse.m2e.maven"/> + </page> + <page id="org.eclipse.m2e.core.preferences.LifecycleMappingPreferencePag" + class="org.eclipse.m2e.core.ui.internal.preferences.LifecycleMappingPreferencePage" + category="org.eclipse.m2e.core.preferences.Maven2PreferencePage" + name="%page.lifecyclemapping.name"> + <keywordReference id="org.eclipse.m2e.core.maven"/> </page> </extension> 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 3e8955a6..1431ffe7 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,6 +121,20 @@ 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; + + public static String LifecycleMappingPreferencePage_WorkspaceMappingsDescription; + + public static String LifecycleMappingPreferencePage_WorkspaceMappingsOpen; + public static String LifecycleMappingPropertyPage_copyToClipboard; public static String LifecycleMappingPropertyPage_mapping; diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/LifecycleMappingOperation.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/LifecycleMappingOperation.java index f5b730ea..d3f3fbe7 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/LifecycleMappingOperation.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/LifecycleMappingOperation.java @@ -7,6 +7,7 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ package org.eclipse.m2e.core.ui.internal.editing; @@ -46,35 +47,63 @@ public class LifecycleMappingOperation implements Operation { private PluginExecutionAction action; private String[] goals; + + /** + * If set to true, then the lifecycle mapping metadata is created + * at the top level of the file, rather than within a plugin. + * For use when not inside a pom + */ + private boolean createAtTopLevel = false; public LifecycleMappingOperation(String pluginGroupId, String pluginArtifactId, String pluginVersion, PluginExecutionAction action, String[] goals) { + this(pluginGroupId, pluginArtifactId, pluginVersion, action, goals, false); + } + + public LifecycleMappingOperation(String pluginGroupId, String pluginArtifactId, String pluginVersion, + PluginExecutionAction action, String[] goals, boolean createAtTopLevel) { this.artifactId = pluginArtifactId; this.groupId = pluginGroupId; this.version = pluginVersion; assert !PluginExecutionAction.configurator.equals(action); this.action = action; this.goals = goals; + this.createAtTopLevel = createAtTopLevel; } public void process(Document document) { Element root = document.getDocumentElement(); - Element managedPlugins = getChild(root, BUILD, PLUGIN_MANAGEMENT, PLUGINS); - //now find the lifecycle stuff if it's there. - Element lifecyclePlugin = findChild(managedPlugins, PLUGIN, - childEquals(GROUP_ID, LIFECYCLE_PLUGIN_GROUPID), - childEquals(ARTIFACT_ID, LIFECYCLE_PLUGIN_ARTIFACTID)); - if (lifecyclePlugin == null) { - //not found, create - lifecyclePlugin = PomHelper.createPlugin(managedPlugins, LIFECYCLE_PLUGIN_GROUPID, LIFECYCLE_PLUGIN_ARTIFACTID, LIFECYCLE_PLUGIN_VERSION); + Element pluginExecutions; // add the new plugins here - //mkleint: a bit scared to have this text localized, with chinese/japanese locales, it could write garbage into the pom file.. - Comment comment = document.createComment("This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself."); - managedPlugins.insertBefore(comment, lifecyclePlugin); - format(comment); + + //now find the lifecycle stuff if it's there. + if (createAtTopLevel) { + if (root == null) { + // probably an empty document + root = document.createElement("lifecycleMappingMetadata"); //$NON-NLS-1$ + document.appendChild(root); + } + pluginExecutions = getChild(root, "pluginExecutions"); //$NON-NLS-1$ + } else { + Element managedPlugins = getChild(root, BUILD, PLUGIN_MANAGEMENT, PLUGINS); + Element lifecyclePlugin = findChild(managedPlugins, PLUGIN, + childEquals(GROUP_ID, LIFECYCLE_PLUGIN_GROUPID), + childEquals(ARTIFACT_ID, LIFECYCLE_PLUGIN_ARTIFACTID)); + + + if (lifecyclePlugin == null) { + //not found, create + lifecyclePlugin = PomHelper.createPlugin(managedPlugins, LIFECYCLE_PLUGIN_GROUPID, LIFECYCLE_PLUGIN_ARTIFACTID, LIFECYCLE_PLUGIN_VERSION); + + //mkleint: a bit scared to have this text localized, with chinese/japanese locales, it could write garbage into the pom file.. + Comment comment = document.createComment("This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself."); //$NON-NLS-1$ + managedPlugins.insertBefore(comment, lifecyclePlugin); + format(comment); + } + + pluginExecutions = getChild(lifecyclePlugin, CONFIGURATION, "lifecycleMappingMetadata", "pluginExecutions"); //$NON-NLS-1$ //$NON-NLS-2$ } - Element pluginExecutions = getChild(lifecyclePlugin, CONFIGURATION, "lifecycleMappingMetadata", "pluginExecutions"); //$NON-NLS-1$ //$NON-NLS-2$ //now find the plugin execution for the plugin we have.. Element execution = null; for (Element exec : findChilds(pluginExecutions, "pluginExecution")) { //$NON-NLS-1$ @@ -92,7 +121,7 @@ public class LifecycleMappingOperation implements Operation { VersionRange range = VersionRange.createFromVersionSpec(versionRange); if (!range.containsVersion(new DefaultArtifactVersion(version))) { Element rangeEl = findChild(filter, "versionRange"); //$NON-NLS-1$ - setText(rangeEl, "[" + version + ",)"); + setText(rangeEl, "[" + version + ",)"); //$NON-NLS-1$ //$NON-NLS-2$ } } catch(InvalidVersionSpecificationException e) { log.error("Failed to parse version range:" + versionRange, e); //$NON-NLS-1$ @@ -129,7 +158,7 @@ public class LifecycleMappingOperation implements Operation { exec.appendChild(filter); createElementWithText(filter, GROUP_ID, groupId); createElementWithText(filter, ARTIFACT_ID, artifactId); - createElementWithText(filter, "versionRange", "[" + version + ",)"); //$NON-NLS-1$ + createElementWithText(filter, "versionRange", "[" + version + ",)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Element actionEl = document.createElement("action"); //$NON-NLS-1$ exec.appendChild(actionEl); @@ -137,7 +166,7 @@ public class LifecycleMappingOperation implements Operation { actionEl.appendChild(actionEl2); if(PluginExecutionAction.execute.equals(action)) { //mkleint: a bit scared to have this text localized, with chinese/japanese locales, it could write garbage into the pom file.. - actionEl2.appendChild(document.createComment("use <runOnIncremental>false</runOnIncremental>to only execute the mojo during full/clean build")); + actionEl2.appendChild(document.createComment("use <runOnIncremental>false</runOnIncremental>to only execute the mojo during full/clean build")); //$NON-NLS-1$ } format(exec); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java index eef55019..11529a5e 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java @@ -7,6 +7,7 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ @@ -390,6 +391,7 @@ public class PomEdits { (tuple.getFile() != null ? (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tuple.getFile()) : (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(tuple.getDocument())); //existing shall be ok here.. + //let the model know we make changes domModel.aboutToChangeModel(); undo = domModel.getStructuredDocument().getUndoManager(); @@ -417,7 +419,7 @@ public class PomEdits { if(domModel != null) { if (tuple.isReadOnly()) { domModel.releaseFromRead(); - } else { + } else if (domModel.getId() != null) { // id will be null for files outside of workspace //for ducuments saving shall generally only happen when the model is not held elsewhere (eg. in opened view) //for files, save always if(tuple.isForceSave() || domModel.getReferenceCountForEdit() == 1) { 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 759f1486..2f234ca5 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,6 +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_LifecycleMapping=Lifecycle Mappings LifecycleMappingPropertyPage_copyToClipboard=Copy to clipboard LifecycleMappingPropertyPage_mapping=Mapping LifecycleMappingPropertyPage_mntmCollapseAll_text=Collapse All @@ -68,7 +73,6 @@ LifecycleMappingPropertyPage_mntmShowIgnoredExecutions_text=Show ignored executi LifecycleMappingPropertyPage_pageMessage=Lifecycle Mapping (experimental) LifecycleMappingPropertyPage_pluginExecution=Plugin execution LifecycleMappingPropertyPage_showLIfecyclePhases=Show lifecycle phases -LifecycleMappingPropertyPage_this_message=dfdfdf LocalArchetypeCatalogDialog_btnBrowse=&Browse... LocalArchetypeCatalogDialog_dialog_title=Select Archetype catalog LocalArchetypeCatalogDialog_error_empty=Archetype catalog is empty @@ -197,6 +201,8 @@ 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/LifecycleMappingPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPreferencePage.java new file mode 100644 index 00000000..dec414d0 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPreferencePage.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2012 VMware, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Eisenberg - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences; + +import java.io.File; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.internal.filesystem.local.LocalFile; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.m2e.core.ui.internal.Messages; + + +/** + * This preferences page provides preferences for managing workspace-scoped lifecycle mappings + */ +@SuppressWarnings("restriction") +public class LifecycleMappingPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + private static final Logger log = LoggerFactory.getLogger(LifecycleMappingPreferencePage.class); + + private LifecycleMappingsViewer mappingsViewer; + + private String mappingFilePath; + + private Text mappingFileTextBox; + + public LifecycleMappingPreferencePage() { + setTitle(Messages.LifecycleMappingPreferencePage_LifecycleMapping); + mappingsViewer = new LifecycleMappingsViewer(); + } + + // reset to default lifecycle mappings file + protected void performDefaults() { + // set to default + mappingFilePath = getDefaultLocation(); + mappingFileTextBox.setText(mappingFilePath); + super.performDefaults(); + } + + public boolean performOk() { + if (isValid()) { + setCurrentLocation(mappingFilePath); + return super.performOk(); + } + return false; + } + + public void init(IWorkbench workbench) { + mappingFilePath = getCurrentLocation(); + } + + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + composite.setLayout(gridLayout); + + new Label(composite, SWT.WRAP).setText( + Messages.LifecycleMappingPreferencePage_WorkspaceMappingsDescription); + Button editLifecyclesButton = new Button(composite, SWT.PUSH); + editLifecyclesButton.setText(Messages.LifecycleMappingPreferencePage_WorkspaceMappingsOpen); + editLifecyclesButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + try { + IDE.openEditorOnFileStore(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), + new LocalFile(new File(mappingFilePath))); + } catch(PartInitException ex) { + log.error(ex.getMessage(), ex); + } + } + }); + + + new Label(composite, SWT.NONE).setText(Messages.LifecycleMappingPreferencePage_ChangeLocation); + + mappingFileTextBox = new Text(composite, SWT.BORDER); + mappingFileTextBox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + mappingFileTextBox.setText(getCurrentLocation()); + mappingFileTextBox.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + // validate current file name + mappingFilePath = mappingFileTextBox.getText(); + if (isValid()) { + LifecycleMappingPreferencePage.this.setErrorMessage(null); + } else { + LifecycleMappingPreferencePage.this.setErrorMessage(NLS.bind(Messages.LifecycleMappingPreferencePage_FileDoesNotExist, mappingFilePath)); + } + } + }); + + Button newFileButton = new Button(composite, SWT.PUSH); + newFileButton.setText(Messages.LifecycleMappingPreferencePage_Browse); + newFileButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + FileDialog dialog = new FileDialog(LifecycleMappingPreferencePage.this.getShell(), SWT.NONE); + + dialog.setText(Messages.LifecycleMappingPreferencePage_ChooseNewLocation); + dialog.setFilterExtensions(new String[] {"*.xml","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ + String res = dialog.open(); + if (res == null) { + return; + } + mappingFileTextBox.setText(dialog.getFilterPath() + "/" + dialog.getFileName()); //$NON-NLS-1$ + } + }); + + // TODO FIXADE Commwented out until we learn how to display workspace lifecylce mappings. +// mappingsViewer.createContents(composite); + + + return composite; + } + + private String getCurrentLocation() { + return MavenPluginActivator.getDefault().getMavenConfiguration().getWorkspaceMappingsFile(); + } + + private String getDefaultLocation() { + return MavenPluginActivator.getDefault().getMavenConfiguration().getDefaultWorkspaceMappingsFile(); + } + + private void setCurrentLocation(String newLocation) { + MavenPluginActivator.getDefault().getMavenConfiguration().setWorkspaceMappingsFile(newLocation); + } + + /** + * @param mappingFileTextBox + */ + public boolean isValid() { + File maybeFile = new File(mappingFilePath); + return maybeFile.exists(); + } + +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPropertyPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPropertyPage.java index d31c0938..30644535 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPropertyPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPropertyPage.java @@ -7,440 +7,42 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - adapted for workspace preferences *******************************************************************************/ package org.eclipse.m2e.core.ui.internal.preferences; -import java.io.IOException; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.TreeViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.ui.dialogs.PropertyPage; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import org.eclipse.m2e.core.MavenPlugin; -import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; -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.lifecyclemapping.model.IPluginExecutionMetadata; -import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction; -import org.eclipse.m2e.core.project.IMavenProjectFacade; -import org.eclipse.m2e.core.project.configurator.MojoExecutionKey; -import org.eclipse.m2e.core.ui.internal.MavenImages; import org.eclipse.m2e.core.ui.internal.Messages; -@SuppressWarnings("restriction") public class LifecycleMappingPropertyPage extends PropertyPage { - boolean showPhases = false; - - boolean showIgnoredExecutions = true; - - TreeViewer mappingsTreeViewer; - - IMavenProjectFacade facade; - - Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mappings; - - Map<String, List<MojoExecutionKey>> phases; + private LifecycleMappingsViewer mappingsViewer; public LifecycleMappingPropertyPage() { setMessage(Messages.LifecycleMappingPropertyPage_pageMessage); noDefaultAndApplyButton(); + mappingsViewer = new LifecycleMappingsViewer(); } @Override public Control createContents(Composite parent) { - Composite container = new Composite(parent, SWT.NULL); - GridLayout gl_container = new GridLayout(1, false); - gl_container.marginWidth = 0; - gl_container.marginHeight = 0; - container.setLayout(gl_container); - - mappingsTreeViewer = new TreeViewer(container, SWT.BORDER); - Tree tree = mappingsTreeViewer.getTree(); - tree.setHeaderVisible(true); - tree.setLinesVisible(true); - tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); - - TreeViewerColumn treeViewerColumn = new TreeViewerColumn(mappingsTreeViewer, SWT.NONE); - TreeColumn trclmnGoal = treeViewerColumn.getColumn(); - trclmnGoal.setWidth(100); - trclmnGoal.setText(Messages.LifecycleMappingPropertyPage_pluginExecution); - - TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(mappingsTreeViewer, SWT.NONE); - TreeColumn trclmnNewColumn = treeViewerColumn_1.getColumn(); - trclmnNewColumn.setWidth(100); - trclmnNewColumn.setText(Messages.LifecycleMappingPropertyPage_mapping); - - mappingsTreeViewer.setContentProvider(new ITreeContentProvider() { - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public void dispose() { - } - - public boolean hasChildren(Object element) { - return getChildren(element) != null; - } - - public Object getParent(Object element) { - return null; - } - - public Object[] getElements(Object inputElement) { - if(showPhases) { - return phases.keySet().toArray(); - } else { - Set<MojoExecutionKey> executions; - if(showIgnoredExecutions) { - executions = mappings.keySet(); - } else { - executions = new LinkedHashSet<MojoExecutionKey>(); - for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : mappings.entrySet()) { - if(!isIgnoreMapping(entry.getKey(), entry.getValue())) { - executions.add(entry.getKey()); - } - } - } - return executions.toArray(); - } - } - - public Object[] getChildren(Object parentElement) { - List<MojoExecutionKey> executions = phases.get(parentElement); - if(executions == null || executions.isEmpty()) { - return null; - } - if(showIgnoredExecutions) { - return executions.toArray(); - } - // filter out ignored executions - executions = new ArrayList<MojoExecutionKey>(executions); // clone - Iterator<MojoExecutionKey> iter = executions.iterator(); - while(iter.hasNext()) { - MojoExecutionKey execution = iter.next(); - if(isIgnoreMapping(execution, mappings.get(execution))) { - iter.remove(); - } - } - return !executions.isEmpty() ? executions.toArray() : null; - } - }); - - mappingsTreeViewer.setLabelProvider(new ITableLabelProvider() { - - public void addListener(ILabelProviderListener listener) { - } - - public void dispose() { - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - } - - public Image getColumnImage(Object element, int columnIndex) { - if(columnIndex == 0 && element instanceof MojoExecutionKey) { - return isErrorMapping((MojoExecutionKey) element) ? MavenImages.IMG_ERROR : MavenImages.IMG_PASSED; - } - return null; - } - - public String getColumnText(Object element, int columnIndex) { - if(element instanceof MojoExecutionKey) { - MojoExecutionKey execution = (MojoExecutionKey) element; - switch(columnIndex) { - case 0: - return LifecycleMappingPropertyPage.this.toString(execution); - case 1: - return LifecycleMappingPropertyPage.this.toString(execution, mappings.get(execution)); - } - } - return columnIndex == 0 ? element.toString() : null; - } - }); - - Menu menu = new Menu(tree); - tree.setMenu(menu); - - final MenuItem mntmShowPhases = new MenuItem(menu, SWT.CHECK); - mntmShowPhases.setSelection(showPhases); - mntmShowPhases.setText(Messages.LifecycleMappingPropertyPage_showLIfecyclePhases); - - final MenuItem mntmShowIgnoredExecutions = new MenuItem(menu, SWT.CHECK); - mntmShowIgnoredExecutions.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - showIgnoredExecutions = mntmShowIgnoredExecutions.getSelection(); - updateMappingsTreeViewer(); - } - }); - mntmShowIgnoredExecutions.setSelection(showIgnoredExecutions); - mntmShowIgnoredExecutions.setText(Messages.LifecycleMappingPropertyPage_mntmShowIgnoredExecutions_text); - - new MenuItem(menu, SWT.SEPARATOR); - - final MenuItem mntmExpandAll = new MenuItem(menu, SWT.NONE); - mntmExpandAll.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - mappingsTreeViewer.expandAll(); - } - }); - mntmExpandAll.setEnabled(showPhases); - mntmExpandAll.setText(Messages.LifecycleMappingPropertyPage_mntmExpandAll_text); - - final MenuItem mntmCollapseAll = new MenuItem(menu, SWT.NONE); - mntmCollapseAll.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - mappingsTreeViewer.collapseAll(); - } - }); - mntmCollapseAll.setEnabled(showPhases); - mntmCollapseAll.setText(Messages.LifecycleMappingPropertyPage_mntmCollapseAll_text); - - mntmShowPhases.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - showPhases = mntmShowPhases.getSelection(); - mntmExpandAll.setEnabled(showPhases); - mntmCollapseAll.setEnabled(showPhases); - updateMappingsTreeViewer(); - } - }); - - Composite actionsComposite = new Composite(container, SWT.NONE); - actionsComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); - actionsComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); - - Button btnCopyToClipboard = new Button(actionsComposite, SWT.NONE); - btnCopyToClipboard.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - copyToClipboard(); - } - }); - btnCopyToClipboard.setText(Messages.LifecycleMappingPropertyPage_copyToClipboard); - - mappingsTreeViewer.setInput(facade); - updateMappingsTreeViewer(); - - return container; - } - - void copyToClipboard() { - if(facade == null || mappings == null) { - return; - } - - LifecycleMappingMetadata meta = new LifecycleMappingMetadata(); - - for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : this.mappings.entrySet()) { - List<IPluginExecutionMetadata> mappings = entry.getValue(); - if(mappings != null && !mappings.isEmpty()) { - for(IPluginExecutionMetadata mapping : mappings) { - // TODO mapping source - meta.addPluginExecution((PluginExecutionMetadata) mapping); - } - } else { - MojoExecutionKey execution = entry.getKey(); - PluginExecutionFilter filter = new PluginExecutionFilter(execution.getGroupId(), execution.getArtifactId(), - execution.getVersion(), execution.getGoal()); - - PluginExecutionMetadata mapping = new PluginExecutionMetadata(); - mapping.setFilter(filter); - - Xpp3Dom actionDom; - if(LifecycleMappingFactory.isInterestingPhase(entry.getKey().getLifecyclePhase())) { - actionDom = new Xpp3Dom(PluginExecutionAction.error.toString()); - } else { - actionDom = new Xpp3Dom(PluginExecutionAction.ignore.toString()); - } - mapping.setActionDom(actionDom); - - meta.addPluginExecution(mapping); - } - } - - LifecycleMappingMetadataSource xml = new LifecycleMappingMetadataSource(); - xml.addLifecycleMapping(meta); - - StringWriter buf = new StringWriter(); - try { - new LifecycleMappingMetadataSourceXpp3Writer().write(buf, xml); - - Clipboard clipboard = new Clipboard(getShell().getDisplay()); - - Object[] data = new Object[] {buf.toString()}; - Transfer[] dataTypes = new Transfer[] {TextTransfer.getInstance()}; - - clipboard.setContents(data, dataTypes); - - clipboard.dispose(); - } catch(IOException ex) { - // TODO log - } - } - - boolean isErrorMapping(MojoExecutionKey execution) { - List<IPluginExecutionMetadata> mappings = this.mappings.get(execution); - if(mappings == null || mappings.isEmpty()) { - return LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase()); - } - for(IPluginExecutionMetadata mapping : mappings) { - if(PluginExecutionAction.error == mapping.getAction()) { - return true; - } - } - return false; - } - - void updateMappingsTreeViewer() { - mappingsTreeViewer.refresh(); - if(showPhases) { - // reveal non-empty mappings - mappingsTreeViewer.collapseAll(); - for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : mappings.entrySet()) { - boolean expand = false; - if(isErrorMapping(entry.getKey())) { - expand = true; - } else { - expand = !isIgnoreMapping(entry.getKey(), entry.getValue()); - } - if(expand) { - mappingsTreeViewer.expandToLevel(entry.getKey().getLifecyclePhase(), TreeViewer.ALL_LEVELS); - } - } - } - // auto-size all columns - for(TreeColumn column : mappingsTreeViewer.getTree().getColumns()) { - column.pack(); - } - } - - boolean isIgnoreMapping(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings) { - if(mappings == null || mappings.isEmpty()) { - return !LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase()); - } - for(IPluginExecutionMetadata mapping : mappings) { - if(PluginExecutionAction.ignore != mapping.getAction()) { - return false; - } - } - return true; - } - - String toString(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings) { - StringBuilder sb = new StringBuilder(); - if(mappings != null && !mappings.isEmpty()) { - for(IPluginExecutionMetadata mapping : mappings) { - if(sb.length() > 0) { - sb.append(','); - } - sb.append(mapping.getAction().toString()); - } - } else { - if(LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase())) { - sb.append(PluginExecutionAction.error.toString()); - } else { - sb.append(PluginExecutionAction.ignore.toString()); - } - } - return sb.toString(); - } - - String toString(MojoExecutionKey execution) { - // http://maven.apache.org/guides/plugin/guide-java-plugin-development.html#Shortening_the_Command_Line - - StringBuilder sb = new StringBuilder(); - - // TODO show groupId, but only if not a known plugin groupId - - // shorten artifactId - String artifactId = execution.getArtifactId(); - if(artifactId.endsWith("-maven-plugin")) { //$NON-NLS-1$ - artifactId = artifactId.substring(0, artifactId.length() - "-maven-plugin".length()); //$NON-NLS-1$ - } else if(artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { //$NON-NLS-1$ //$NON-NLS-2$ - artifactId = artifactId.substring("maven-".length(), artifactId.length() - "-plugin".length()); //$NON-NLS-1$ //$NON-NLS-2$ - } - - sb.append(artifactId).append(':').append(execution.getGoal()); - - // only show execution id if necessary - int count = 0; - for(MojoExecutionKey other : mappings.keySet()) { - if(eq(execution.getGroupId(), other.getGroupId()) && eq(execution.getArtifactId(), other.getArtifactId()) - && eq(execution.getGoal(), other.getGoal())) { - count++ ; - } - } - if(count > 1) { - sb.append(" (").append(execution.getExecutionId()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ - } - return sb.toString(); - } - - static <T> boolean eq(T a, T b) { - return a != null ? a.equals(b) : b == null; + mappingsViewer.setShell(parent.getShell()); + return mappingsViewer.createContents(parent); } public void setElement(IAdaptable element) { super.setElement(element); - + IProject project = (IProject) getElement().getAdapter(IProject.class); - facade = MavenPlugin.getMavenProjectRegistry().getProject(project); - mappings = facade.getMojoExecutionMapping(); - - phases = new LinkedHashMap<String, List<MojoExecutionKey>>(); - for(MojoExecutionKey execution : mappings.keySet()) { - List<MojoExecutionKey> executions = phases.get(execution.getLifecyclePhase()); - if(executions == null) { - executions = new ArrayList<MojoExecutionKey>(); - phases.put(execution.getLifecyclePhase(), executions); - } - executions.add(execution); + if (project != null) { + mappingsViewer.setTarget(project); } } } 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 new file mode 100644 index 00000000..52d15441 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java @@ -0,0 +1,445 @@ +/******************************************************************************* + * Copyright (c) 2011 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - adapted for workspace preferences + *******************************************************************************/ +package org.eclipse.m2e.core.ui.internal.preferences; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +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.codehaus.plexus.util.xml.Xpp3Dom; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; +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.lifecyclemapping.model.IPluginExecutionMetadata; +import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.configurator.MojoExecutionKey; +import org.eclipse.m2e.core.ui.internal.MavenImages; +import org.eclipse.m2e.core.ui.internal.Messages; + +@SuppressWarnings("restriction") +class LifecycleMappingsViewer { + private TreeViewer mappingsTreeViewer; + private boolean showPhases = false; + private boolean showIgnoredExecutions = true; + private Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mappings; + private Map<String, List<MojoExecutionKey>> phases; + private Shell shell; + + void updateMappingsTreeViewer() { + mappingsTreeViewer.refresh(); + if(showPhases) { + // reveal non-empty mappings + mappingsTreeViewer.collapseAll(); + for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : mappings.entrySet()) { + boolean expand = false; + if(isErrorMapping(entry.getKey())) { + expand = true; + } else { + expand = !isIgnoreMapping(entry.getKey(), entry.getValue()); + } + if(expand) { + mappingsTreeViewer.expandToLevel(entry.getKey().getLifecyclePhase(), TreeViewer.ALL_LEVELS); + } + } + } + // auto-size all columns + for(TreeColumn column : mappingsTreeViewer.getTree().getColumns()) { + column.pack(); + } + } + + + public Composite createContents(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout gl_container = new GridLayout(1, false); + gl_container.marginWidth = 0; + gl_container.marginHeight = 0; + container.setLayout(gl_container); + + mappingsTreeViewer = new TreeViewer(container, SWT.BORDER); + Tree tree = mappingsTreeViewer.getTree(); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + + TreeViewerColumn treeViewerColumn = new TreeViewerColumn(mappingsTreeViewer, SWT.NONE); + TreeColumn trclmnGoal = treeViewerColumn.getColumn(); + trclmnGoal.setWidth(100); + trclmnGoal.setText(Messages.LifecycleMappingPropertyPage_pluginExecution); + + TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(mappingsTreeViewer, SWT.NONE); + TreeColumn trclmnNewColumn = treeViewerColumn_1.getColumn(); + trclmnNewColumn.setWidth(100); + trclmnNewColumn.setText(Messages.LifecycleMappingPropertyPage_mapping); + + mappingsTreeViewer.setContentProvider(new ITreeContentProvider() { + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public boolean hasChildren(Object element) { + return getChildren(element) != null; + } + + public Object getParent(Object element) { + return null; + } + + public Object[] getElements(Object inputElement) { + if(showPhases) { + return phases.keySet().toArray(); + } else { + Set<MojoExecutionKey> executions; + if(showIgnoredExecutions) { + executions = mappings.keySet(); + } else { + executions = new LinkedHashSet<MojoExecutionKey>(); + for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : mappings.entrySet()) { + if(!isIgnoreMapping(entry.getKey(), entry.getValue())) { + executions.add(entry.getKey()); + } + } + } + return executions.toArray(); + } + } + + public Object[] getChildren(Object parentElement) { + List<MojoExecutionKey> executions = phases.get(parentElement); + if(executions == null || executions.isEmpty()) { + return null; + } + if(showIgnoredExecutions) { + return executions.toArray(); + } + // filter out ignored executions + executions = new ArrayList<MojoExecutionKey>(executions); // clone + Iterator<MojoExecutionKey> iter = executions.iterator(); + while(iter.hasNext()) { + MojoExecutionKey execution = iter.next(); + if(isIgnoreMapping(execution, mappings.get(execution))) { + iter.remove(); + } + } + return !executions.isEmpty() ? executions.toArray() : null; + } + }); + + mappingsTreeViewer.setLabelProvider(new ITableLabelProvider() { + + public void addListener(ILabelProviderListener listener) { + } + + public void dispose() { + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + } + + public Image getColumnImage(Object element, int columnIndex) { + if(columnIndex == 0 && element instanceof MojoExecutionKey) { + return isErrorMapping((MojoExecutionKey) element) ? MavenImages.IMG_ERROR : MavenImages.IMG_PASSED; + } + return null; + } + + public String getColumnText(Object element, int columnIndex) { + if(element instanceof MojoExecutionKey) { + MojoExecutionKey execution = (MojoExecutionKey) element; + switch(columnIndex) { + case 0: + return LifecycleMappingsViewer.this.toString(execution); + case 1: + return LifecycleMappingsViewer.this.toString(execution, mappings.get(execution)); + } + } + return columnIndex == 0 ? element.toString() : null; + } + }); + + Menu menu = new Menu(tree); + tree.setMenu(menu); + + final MenuItem mntmShowPhases = new MenuItem(menu, SWT.CHECK); + mntmShowPhases.setSelection(showPhases); + mntmShowPhases.setText(Messages.LifecycleMappingPropertyPage_showLIfecyclePhases); + + final MenuItem mntmShowIgnoredExecutions = new MenuItem(menu, SWT.CHECK); + mntmShowIgnoredExecutions.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + showIgnoredExecutions = mntmShowIgnoredExecutions.getSelection(); + updateMappingsTreeViewer(); + } + }); + mntmShowIgnoredExecutions.setSelection(showIgnoredExecutions); + mntmShowIgnoredExecutions.setText(Messages.LifecycleMappingPropertyPage_mntmShowIgnoredExecutions_text); + + new MenuItem(menu, SWT.SEPARATOR); + + final MenuItem mntmExpandAll = new MenuItem(menu, SWT.NONE); + mntmExpandAll.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + mappingsTreeViewer.expandAll(); + } + }); + mntmExpandAll.setEnabled(showPhases); + mntmExpandAll.setText(Messages.LifecycleMappingPropertyPage_mntmExpandAll_text); + + final MenuItem mntmCollapseAll = new MenuItem(menu, SWT.NONE); + mntmCollapseAll.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + mappingsTreeViewer.collapseAll(); + } + }); + mntmCollapseAll.setEnabled(showPhases); + mntmCollapseAll.setText(Messages.LifecycleMappingPropertyPage_mntmCollapseAll_text); + + mntmShowPhases.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + showPhases = mntmShowPhases.getSelection(); + mntmExpandAll.setEnabled(showPhases); + mntmCollapseAll.setEnabled(showPhases); + updateMappingsTreeViewer(); + } + }); + + Composite actionsComposite = new Composite(container, SWT.NONE); + actionsComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); + actionsComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); + + Button btnCopyToClipboard = new Button(actionsComposite, SWT.NONE); + btnCopyToClipboard.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + copyToClipboard(); + } + }); + btnCopyToClipboard.setText(Messages.LifecycleMappingPropertyPage_copyToClipboard); + + updateMappingsTreeViewer(); + return container; + } + + + void copyToClipboard() { + if(mappings == null) { + return; + } + + LifecycleMappingMetadata meta = new LifecycleMappingMetadata(); + + for(Map.Entry<MojoExecutionKey, List<IPluginExecutionMetadata>> entry : this.mappings.entrySet()) { + List<IPluginExecutionMetadata> mappings = entry.getValue(); + if(mappings != null && !mappings.isEmpty()) { + for(IPluginExecutionMetadata mapping : mappings) { + // TODO mapping source + meta.addPluginExecution((PluginExecutionMetadata) mapping); + } + } else { + MojoExecutionKey execution = entry.getKey(); + PluginExecutionFilter filter = new PluginExecutionFilter(execution.getGroupId(), execution.getArtifactId(), + execution.getVersion(), execution.getGoal()); + + PluginExecutionMetadata mapping = new PluginExecutionMetadata(); + mapping.setFilter(filter); + + Xpp3Dom actionDom; + if(LifecycleMappingFactory.isInterestingPhase(entry.getKey().getLifecyclePhase())) { + actionDom = new Xpp3Dom(PluginExecutionAction.error.toString()); + } else { + actionDom = new Xpp3Dom(PluginExecutionAction.ignore.toString()); + } + mapping.setActionDom(actionDom); + + meta.addPluginExecution(mapping); + } + } + + LifecycleMappingMetadataSource xml = new LifecycleMappingMetadataSource(); + xml.addLifecycleMapping(meta); + + StringWriter buf = new StringWriter(); + try { + new LifecycleMappingMetadataSourceXpp3Writer().write(buf, xml); + + Clipboard clipboard = new Clipboard(shell.getDisplay()); + + Object[] data = new Object[] {buf.toString()}; + Transfer[] dataTypes = new Transfer[] {TextTransfer.getInstance()}; + + clipboard.setContents(data, dataTypes); + + clipboard.dispose(); + } catch(IOException ex) { + // TODO log + } + } + + + boolean isErrorMapping(MojoExecutionKey execution) { + List<IPluginExecutionMetadata> mappings = this.mappings.get(execution); + if(mappings == null || mappings.isEmpty()) { + return LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase()); + } + for(IPluginExecutionMetadata mapping : mappings) { + if(PluginExecutionAction.error == mapping.getAction()) { + return true; + } + } + return false; + } + + + boolean isIgnoreMapping(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings) { + if(mappings == null || mappings.isEmpty()) { + return !LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase()); + } + for(IPluginExecutionMetadata mapping : mappings) { + if(PluginExecutionAction.ignore != mapping.getAction()) { + return false; + } + } + return true; + } + + + String toString(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings) { + StringBuilder sb = new StringBuilder(); + if(mappings != null && !mappings.isEmpty()) { + for(IPluginExecutionMetadata mapping : mappings) { + if(sb.length() > 0) { + sb.append(','); + } + sb.append(mapping.getAction().toString()); + } + } else { + if(LifecycleMappingFactory.isInterestingPhase(execution.getLifecyclePhase())) { + sb.append(PluginExecutionAction.error.toString()); + } else { + sb.append(PluginExecutionAction.ignore.toString()); + } + } + return sb.toString(); + } + + + String toString(MojoExecutionKey execution) { + // http://maven.apache.org/guides/plugin/guide-java-plugin-development.html#Shortening_the_Command_Line + + StringBuilder sb = new StringBuilder(); + + // TODO show groupId, but only if not a known plugin groupId + + // shorten artifactId + String artifactId = execution.getArtifactId(); + if(artifactId.endsWith("-maven-plugin")) { //$NON-NLS-1$ + artifactId = artifactId.substring(0, artifactId.length() - "-maven-plugin".length()); //$NON-NLS-1$ + } else if(artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { //$NON-NLS-1$ //$NON-NLS-2$ + artifactId = artifactId.substring("maven-".length(), artifactId.length() - "-plugin".length()); //$NON-NLS-1$ //$NON-NLS-2$ + } + + sb.append(artifactId).append(':').append(execution.getGoal()); + + // only show execution id if necessary + int count = 0; + for(MojoExecutionKey other : mappings.keySet()) { + if(eq(execution.getGroupId(), other.getGroupId()) && eq(execution.getArtifactId(), other.getArtifactId()) + && eq(execution.getGoal(), other.getGoal())) { + count++ ; + } + } + if(count > 1) { + sb.append(" (").append(execution.getExecutionId()).append(")"); //$NON-NLS-1$ //$NON-NLS-2$ + } + return sb.toString(); + } + + + static <T> boolean eq(T a, T b) { + return a != null ? a.equals(b) : b == null; + } + + public void setTarget(IProject project) { + if (project == null) { + // TODO FIXADE find the modo execution mapping for the workspace...How do I do this? + } else { + IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project); + mappings = facade.getMojoExecutionMapping(); + } + + phases = new LinkedHashMap<String, List<MojoExecutionKey>>(); + for(MojoExecutionKey execution : mappings.keySet()) { + List<MojoExecutionKey> executions = phases.get(execution.getLifecyclePhase()); + if(executions == null) { + executions = new ArrayList<MojoExecutionKey>(); + phases.put(execution.getLifecyclePhase(), executions); + } + executions.add(execution); + } + } + + + /** + * @param shell + */ + public void setShell(Shell shell) { + this.shell = shell; + } +}
\ No newline at end of file diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java index 239f759c..89c2d53d 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java @@ -7,20 +7,32 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ package org.eclipse.m2e.core.ui.internal.preferences; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.internal.filesystem.local.LocalFile; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants; import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; import org.eclipse.m2e.core.ui.internal.Messages; @@ -28,6 +40,8 @@ import org.eclipse.m2e.core.ui.internal.Messages; public class MavenPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + private static final Logger log = LoggerFactory.getLogger(MavenPreferencePage.class); + public MavenPreferencePage() { super(GRID); setPreferenceStore(M2EUIPluginActivator.getDefault().getPreferenceStore()); @@ -75,7 +89,7 @@ public class MavenPreferencePage extends FieldEditorPreferencePage implements IW addField(new BooleanFieldEditor(MavenPreferenceConstants.P_HIDE_FOLDERS_OF_NESTED_PROJECTS, // Messages.MavenPreferencePage_hide, getFieldEditorParent())); - + GridData comboCompositeGridData = new GridData(); comboCompositeGridData.verticalIndent = 25; comboCompositeGridData.horizontalSpan = 3; @@ -86,18 +100,5 @@ public class MavenPreferencePage extends FieldEditorPreferencePage implements IW comboComposite.setLayoutData(comboCompositeGridData); comboComposite.setLayout(new GridLayout(2, false)); - // addSeparator(); } - - private void addSeparator() { - Label separator = new Label(getFieldEditorParent(), SWT.HORIZONTAL | SWT.SEPARATOR); - // separator.setVisible(false); - GridData separatorGridData = new GridData(); - separatorGridData.horizontalSpan = 4; - separatorGridData.grabExcessHorizontalSpace = true; - separatorGridData.horizontalAlignment = GridData.FILL; - separatorGridData.verticalIndent = 10; - separator.setLayoutData(separatorGridData); - } - } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java index bb7466ca..5df81787 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java @@ -7,10 +7,13 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ package org.eclipse.m2e.core.embedder; +import java.io.File; + import org.eclipse.core.runtime.CoreException; @@ -66,5 +69,26 @@ public interface IMavenConfiguration { public boolean isHideFoldersOfNestedProjects(); + // lifecycle mappings + + /** + * Sets the text of the workspace lifecycle mapping file + * and saves it + */ + public void setWorkspaceMappings(String newMapping); + + /** + * Gets the text of the workspace lifecycle mapping file + */ + public String getWorkspaceMappings(); + + /** + * Gets the workspace lifecycle mappings metadata file located in the .metadata directory + * @return the lifecycle mappings metadata file + */ + public String getWorkspaceMappingsFile(); + + public void setWorkspaceMappingsFile(String newFile); + public String getDefaultWorkspaceMappingsFile(); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java index 64cefb89..58d24da5 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java @@ -21,11 +21,14 @@ import org.osgi.framework.Version; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.DefaultContainerConfiguration; diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java index 2ad2969d..98d28c46 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java @@ -7,6 +7,7 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ package org.eclipse.m2e.core.internal.lifecyclemapping; @@ -19,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.net.URL; -import java.rmi.activation.Activator; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -37,7 +37,6 @@ import org.osgi.framework.Bundle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -46,12 +45,10 @@ import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.spi.RegistryContributor; import org.eclipse.osgi.util.NLS; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringInputStream; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -232,10 +229,12 @@ public class LifecycleMappingFactory { // List order // 1. this pom embedded, this pom referenced, parent embedded, parent referenced, grand parent embedded... - // 2. preferences in workspace - // 3. sources contributed by eclipse extensions - // 4. maven-plugin embedded metadata - // 5. default source, if present + // 2. preferences in project (*** not implemented yet) + // 3. preferebces in ancestor project (*** not implemented yet) + // 4. preferences in workspace + // 5. sources contributed by eclipse extensions + // 6. maven-plugin embedded metadata + // 7. default source, if present // TODO validate metadata and replace invalid entries with error mapping for(LifecycleMappingMetadataSource source : getPomMappingMetadataSources(mavenProject, templateRequest, monitor)) { metadataSources.add(new SimpleMappingMetadataSource(source)); @@ -372,24 +371,24 @@ public class LifecycleMappingFactory { private static LifecycleMappingMetadataSource readMavenPluginEmbeddedMetadata(Artifact artifact, InputStream is) throws IOException, XmlPullParserException { return new LifecycleMappingMetadataSourceXpp3Reader().read(is); - /** - * @return - */ - private static LifecycleMappingMetadataSource getWorkspacePreferencesMetadataSources() { - LifecycleMappingMetadataSource source = new LifecycleMappingMetadataSource(); - String mapp = MavenPluginActivator.getDefault().getPluginPreferences().getString("XXX_mappings"); - if (mapp != null) { + } + + public static LifecycleMappingMetadataSource getWorkspacePreferencesMetadataSources() { + LifecycleMappingMetadataSource source = null; + String mappings = MavenPluginActivator.getDefault().getMavenConfiguration().getWorkspaceMappings(); + if (mappings != null) { LifecycleMappingMetadataSourceXpp3Reader reader = new LifecycleMappingMetadataSourceXpp3Reader(); try { - source = reader.read(new StringReader(mapp)); + source = reader.read(new StringReader(mappings)); } catch(IOException ex) { - // TODO Auto-generated catch block log.error(ex.getMessage(), ex); } catch(XmlPullParserException ex) { - // TODO Auto-generated catch block log.error(ex.getMessage(), ex); } } + if (source == null) { + source = new LifecycleMappingMetadataSource(); + } return source; } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java index bb7620f3..c3f3ccfa 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java @@ -7,10 +7,16 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ package org.eclipse.m2e.core.internal.preferences; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.Map; import org.osgi.service.prefs.BackingStoreException; @@ -36,9 +42,13 @@ import org.eclipse.m2e.core.embedder.IMavenConfiguration; import org.eclipse.m2e.core.embedder.IMavenConfigurationChangeListener; import org.eclipse.m2e.core.embedder.MavenConfigurationChangeEvent; import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceChangeListener, INodeChangeListener { + private String defaultWorkspaceMappingsFile; + private static final Logger log = LoggerFactory.getLogger(MavenConfigurationImpl.class); private final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; @@ -70,7 +80,7 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC ((IEclipsePreferences) preferencesLookup[0].parent()).removeNodeChangeListener(this); preferencesLookup[0].removePreferenceChangeListener(this); } - preferencesLookup[0] = new InstanceScope().getNode(IMavenConstants.PLUGIN_ID); + preferencesLookup[0] = InstanceScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); ((IEclipsePreferences) preferencesLookup[0].parent()).addNodeChangeListener(this); preferencesLookup[0].addPreferenceChangeListener(this); @@ -78,8 +88,10 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC ((IEclipsePreferences) preferencesLookup[1].parent()).removeNodeChangeListener(this); preferencesLookup[1].removePreferenceChangeListener(this); } - preferencesLookup[1] = new DefaultScope().getNode(IMavenConstants.PLUGIN_ID); + preferencesLookup[1] = DefaultScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); ((IEclipsePreferences) preferencesLookup[1].parent()).addNodeChangeListener(this); + + ensureLifecycleMappingMetadataFile(); } public String getGlobalSettingsFile() { @@ -197,4 +209,83 @@ public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceC throw new IllegalArgumentException(); } } + + public void setWorkspaceMappings(String newMappings) { + if (newMappings == null) { + newMappings = ""; + } + File mappingsFile = new File(getWorkspaceMappingsFile()); + writeFile(newMappings, mappingsFile); + } + + public String getWorkspaceMappings() { + File mappingsFile = new File(getWorkspaceMappingsFile()); + StringBuilder sb = new StringBuilder(); + try { + BufferedReader in = new BufferedReader(new FileReader(mappingsFile)); + String str; + while((str = in.readLine()) != null) { + sb.append(str + "\n"); + } + in.close(); + return sb.toString(); + } catch(IOException e) { + log.error("Could not read workspace lifecycle mapping metadata file from: " + mappingsFile.getAbsolutePath(), e); + } + return ""; + } + + /** + * Gets the workspace lifecycle mappings metadata file located in the .metadata directory + * @return the lifecycle mappings metadata file + */ + public String getWorkspaceMappingsFile() { + return preferenceStore.get(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION, getDefaultWorkspaceMappingsFile(), + preferencesLookup); + } + + /** + * Sets the location of the workspace mapping file. Setting to null returns the value to the default + */ + public void setWorkspaceMappingsFile(String newFile) { + if (newFile == null) { + preferencesLookup[0].remove(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION); + } else { + preferencesLookup[0].put(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION, newFile); + } + } + + public String getDefaultWorkspaceMappingsFile() { + if (defaultWorkspaceMappingsFile == null) { + defaultWorkspaceMappingsFile = MavenPluginActivator.getDefault().getStateLocation() + .append(LifecycleMappingFactory.LIFECYCLE_MAPPING_METADATA_SOURCE_NAME).toFile().getAbsolutePath(); + } + return defaultWorkspaceMappingsFile; + } + + private static void writeFile(String newMappings, File mappingsFile) { + try { + FileWriter writer = new FileWriter(mappingsFile); + writer.write(newMappings); + writer.close(); + } catch (IOException e) { + log.error("Could not write workspace lifecycle mapping metadata file to: " + mappingsFile.getAbsolutePath(), e); + } + } + + /** + * ensures that the worksoace lifecycle mapping metadata file exists + * and has the correct root + */ + private void ensureLifecycleMappingMetadataFile() { + File workspaceLifecycleMappingsFile = new File(getDefaultWorkspaceMappingsFile()); + if (!workspaceLifecycleMappingsFile.exists()) { + setWorkspaceMappings( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<lifecycleMappingMetadata>\n" + + "</lifecycleMappingMetadata>"); + } + } + + } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java index fdf76d81..51fd1c0e 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java @@ -95,4 +95,11 @@ public interface MavenPreferenceConstants { /** boolean **/ public static final String P_DISABLE_VERSION_DUP_OF_PARENT_WARNING = PREFIX + ".disableVersionDuplicateOfParentWarning"; //$NON-NLS-1$ + + /** string **/ + public static final String P_LIFECYCLE_MAPPINGS = PREFIX + "lifecycleMappings"; //$NON-NLS-1$ + + /** string **/ + public static final String P_WORKSPACE_MAPPINGS_LOCATION = PREFIX + "WorkspacelifecycleMappingsLocation"; //$NON-NLS-1$ + } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java index c646c435..c15451b7 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceInitializer.java @@ -14,7 +14,6 @@ package org.eclipse.m2e.core.internal.preferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IScopeContext; import org.apache.maven.cli.MavenCli; @@ -34,7 +33,7 @@ public class MavenPreferenceInitializer extends AbstractPreferenceInitializer { * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() */ public void initializeDefaultPreferences() { - IEclipsePreferences store = ((IScopeContext) new DefaultScope()).getNode(IMavenConstants.PLUGIN_ID); + IEclipsePreferences store = DefaultScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); store.put(MavenPreferenceConstants.P_USER_SETTINGS_FILE, // MavenCli.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath()); @@ -65,6 +64,8 @@ public class MavenPreferenceInitializer extends AbstractPreferenceInitializer { store.putBoolean(MavenPreferenceConstants.P_SHOW_CONSOLE_ON_ERR, true); store.putBoolean(MavenPreferenceConstants.P_SHOW_CONSOLE_ON_OUTPUT, false); + + // set to null since the plugin state location is not available by the time execution reaches here + store.put(MavenPreferenceConstants.P_WORKSPACE_MAPPINGS_LOCATION, null); } - } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java index 8438b1b2..07b630e0 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java @@ -19,7 +19,6 @@ import org.eclipse.ui.IMarkerResolutionGenerator2; import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction; import org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingProposal; -import org.eclipse.m2e.editor.xml.internal.lifecycle.WorkspaceLifecycleMappingProposal; /** @@ -56,7 +55,6 @@ public class MavenMarkerResolutionGenerator implements IMarkerResolutionGenerato if(hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { return new IMarkerResolution[] { new LifecycleMappingProposal(marker, PluginExecutionAction.ignore), - new WorkspaceLifecycleMappingProposal(marker, PluginExecutionAction.ignore) // new LifecycleMappingProposal(marker, PluginExecutionAction.execute) }; } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java index 964ef47f..4ea8e323 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java @@ -62,7 +62,6 @@ import org.eclipse.m2e.editor.xml.internal.Messages; import org.eclipse.m2e.editor.xml.internal.NodeOperation; import org.eclipse.m2e.editor.xml.internal.XmlUtils; import org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingProposal; -import org.eclipse.m2e.editor.xml.internal.lifecycle.WorkspaceLifecycleMappingProposal; public class PomQuickAssistProcessor implements IQuickAssistProcessor { private static final Logger log = LoggerFactory.getLogger(PomQuickAssistProcessor.class); @@ -121,7 +120,6 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { } else if (hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { extractedFromMarkers(proposals, mark); //having this first sort of helps for 335490 proposals.add(new LifecycleMappingProposal(context, mark, PluginExecutionAction.ignore)); - proposals.add(new WorkspaceLifecycleMappingProposal(context, mark, PluginExecutionAction.ignore)); // proposals.add(new LifecycleMappingProposal(context, mark, PluginExecutionAction.execute)); } else if(mark.getMarker().getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR && hint.equals(IMavenConstants.EDITOR_HINT_IMPLICIT_LIFECYCLEMAPPING)) { diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java index f0aa3c69..3924eb8c 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java @@ -41,6 +41,18 @@ public class Messages extends NLS { public static String InsertSPDXLicenseProposal_0; + public static String LifecycleMappingDialog_Ignore; + + public static String LifecycleMappingDialog_LocationToIgnore; + + public static String LifecycleMappingDialog_NonWorkspacePom; + + public static String LifecycleMappingDialog_PluginDefinitionInSelectedPom; + + public static String LifecycleMappingDialog_UseWorkspaceSettings; + + public static String LifecycleMappingDialog_UseWorkspaceSettingsDesc; + public static String LifecycleMappingProposal_all_desc; public static String LifecycleMappingProposal_execute_desc; diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java index 59a55028..406e83fe 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java @@ -7,6 +7,7 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ package org.eclipse.m2e.editor.xml.internal.lifecycle; @@ -29,7 +30,10 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -41,6 +45,7 @@ import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.internal.M2EUtils; import org.eclipse.m2e.core.project.IMavenProjectFacade; import org.eclipse.m2e.core.ui.internal.components.PomHierarchyComposite; +import org.eclipse.m2e.editor.xml.internal.Messages; @SuppressWarnings("restriction") @@ -58,33 +63,36 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL private String pluginArtifactId; - private String pluginVersion; + // TODO Unused...consider deleting +// private String pluginVersion; private String goal; private MavenProject pluginProject; + private boolean workspaceSettings = false; + public LifecycleMappingDialog(Shell parentShell, IFile pom, String pluginGroupId, String pluginArtifactId, String pluginVersion, String goal) { super(parentShell); facade = MavenPlugin.getMavenProjectRegistry().create(pom, true, new NullProgressMonitor()); this.pluginGroupId = pluginGroupId; this.pluginArtifactId = pluginArtifactId; - this.pluginVersion = pluginVersion; +// this.pluginVersion = pluginVersion; this.goal = goal; } @Override protected void configureShell(Shell shell) { super.configureShell(shell); - shell.setText(NLS.bind("Ignore {0}", goal)); + shell.setText(NLS.bind(Messages.LifecycleMappingDialog_Ignore, goal)); } @Override protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); Label label = new Label(container, SWT.NONE); - label.setText("Select location to place ignore"); + label.setText(Messages.LifecycleMappingDialog_LocationToIgnore); pomComposite = new PomHierarchyComposite(container, SWT.BORDER); pomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); pomComposite.addSelectionChangedListener(this); @@ -98,9 +106,28 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL status = new CLabel(container, SWT.WRAP); status.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false)); + // separator + new Label(container, SWT.NONE); + + final Button workspaceSettingsButton = new Button(container, SWT.CHECK); + workspaceSettingsButton.setText(Messages.LifecycleMappingDialog_UseWorkspaceSettings); + workspaceSettingsButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + pomComposite.setEnabled(!workspaceSettingsButton.getSelection()); + workspaceSettings = workspaceSettingsButton.getSelection(); + } + }); + new Label(container, SWT.NONE). + setText(Messages.LifecycleMappingDialog_UseWorkspaceSettingsDesc); + pluginProject = locatePlugin(); return container; } + + public boolean useWorkspaceSettings() { + return workspaceSettings; + } @Override protected void createButtonsForButtonBar(Composite parent) { @@ -124,13 +151,13 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL private void updateStatus(MavenProject project) { if(project.getFile() == null) { - status.setText("Non-workspace pom"); + status.setText(Messages.LifecycleMappingDialog_NonWorkspacePom); status.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK)); } else if(project.equals(pluginProject)) { - status.setText("Plugin definition in selected pom."); + status.setText(Messages.LifecycleMappingDialog_PluginDefinitionInSelectedPom); status.setImage(null); } else { - status.setText(""); + status.setText(""); //$NON-NLS-1$ status.setImage(null); } } @@ -151,13 +178,13 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL private MavenProject locatePlugin() { MavenProject project = facade.getMavenProject(); // if we got here, facade.getMavenProject cannot be null - Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId); + Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId); //$NON-NLS-1$ if(plugin == null) { return null; // can't really happy } - InputLocation location = plugin.getLocation(""); + InputLocation location = plugin.getLocation(""); //$NON-NLS-1$ if(location == null || location.getSource() == null || location.getSource().getLocation() == null) { // that's odd. where does this come from??? diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java index 6c14f625..6947e1ea 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java @@ -7,6 +7,7 @@ * * Contributors: * Sonatype, Inc. - initial API and implementation + * Andrew Eisenberg - Work on Bug 350414 *******************************************************************************/ @@ -14,7 +15,9 @@ package org.eclipse.m2e.editor.xml.internal.lifecycle; import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -23,6 +26,7 @@ import org.slf4j.LoggerFactory; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -36,17 +40,21 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IMarkerResolution; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.views.markers.WorkbenchMarkerResolution; +import org.eclipse.wst.sse.core.internal.encoding.EncodingRule; +import org.eclipse.wst.xml.core.internal.modelhandler.XMLModelLoader; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction; +import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob; import org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation; import org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation; -import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple; import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation; +import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple; import org.eclipse.m2e.editor.xml.internal.Messages; public class LifecycleMappingProposal extends WorkbenchMarkerResolution implements ICompletionProposal, ICompletionProposalExtension5 { @@ -74,7 +82,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen if(PluginExecutionAction.ignore.equals(action)) { performIgnore(new IMarker[] {marker}); } else { - performOnDOMDocument(new OperationTuple(doc, createOperation(marker))); + performOnDOMDocument(new OperationTuple(doc, createOperation(marker, false))); } } catch(IOException e) { log.error("Error generating code in pom.xml", e); //$NON-NLS-1$ @@ -85,34 +93,72 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen private void performIgnore(IMarker[] marks) throws IOException, CoreException { final IFile[] pomFile = new IFile[1]; + final boolean[] useWorkspace = new boolean[1]; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { - public void run() { LifecycleMappingDialog dialog = new LifecycleMappingDialog(Display.getCurrent().getActiveShell(), - (IFile) marker.getResource(), marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""), marker - .getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""), marker.getAttribute( - IMavenConstants.MARKER_ATTR_VERSION, ""), marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")); + (IFile) marker.getResource(), marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""), marker //$NON-NLS-1$ + .getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""), marker.getAttribute( //$NON-NLS-1$ + IMavenConstants.MARKER_ATTR_VERSION, ""), marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")); //$NON-NLS-1$ //$NON-NLS-2$ dialog.setBlockOnOpen(true); if(dialog.open() == Window.OK) { - pomFile[0] = dialog.getPomFile(); + if (dialog.useWorkspaceSettings()) { + // store in workspace, not in pom file + useWorkspace[0] = true; + } else { + pomFile[0] = dialog.getPomFile(); + } } } }); - if(pomFile[0] != null) { + + if (pomFile[0] != null || useWorkspace[0]) { List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>(); for (IMarker m : marks) { - lst.add(createOperation(m)); + lst.add(createOperation(m, useWorkspace[0])); + } + + OperationTuple operationTuple; + IDOMModel model = null; + if (useWorkspace[0]) { + // write to workspace preferences + model = loadWorkspaceMappingsModel(); + operationTuple = new OperationTuple(model, new CompoundOperation(lst.toArray(new Operation[0]))); + } else { + operationTuple = new OperationTuple(pomFile[0], new CompoundOperation(lst.toArray(new Operation[0]))); + } + performOnDOMDocument(operationTuple); + + if (useWorkspace[0]) { + // now save the workspace file if necessary + MavenPluginActivator.getDefault().getMavenConfiguration().setWorkspaceMappings(model.getDocument().getSource()); + + // must kick off an update project job since the pom isn't modified. + // Only update the project from where this quick fix was executed. + // Other projects can be updated manually + new UpdateMavenProjectJob(new IProject[] { marker.getResource().getProject() }).schedule(); } - performOnDOMDocument(new OperationTuple(pomFile[0], new CompoundOperation(lst.toArray(new Operation[0])))); } } - private LifecycleMappingOperation createOperation(IMarker mark) { + /** + * Loads the workspace lifecycle mappings file as a dom model + */ + private IDOMModel loadWorkspaceMappingsModel() throws UnsupportedEncodingException, IOException { + IDOMModel model; + XMLModelLoader loader = new XMLModelLoader(); + model = (IDOMModel) loader.createModel(); + loader.load(new ByteArrayInputStream(MavenPluginActivator.getDefault().getMavenConfiguration() + .getWorkspaceMappings().getBytes()), model, EncodingRule.CONTENT_BASED); + return model; + } + + private LifecycleMappingOperation createOperation(IMarker mark, boolean createAtTopLevel) { String pluginGroupId = mark.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$ String pluginArtifactId = mark.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$ String pluginVersion = mark.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$ String[] goals = new String[] { mark.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")}; //$NON-NLS-1$ - return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals); + return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals, createAtTopLevel); } @@ -201,7 +247,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen } else { List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>(); for (IMarker m : markers) { - lst.add(createOperation(m)); + lst.add(createOperation(m, false)); } performOnDOMDocument(new OperationTuple((IFile) marker.getResource(), new CompoundOperation(lst.toArray(new Operation[0])))); } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java deleted file mode 100644 index 4e807c42..00000000 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java +++ /dev/null @@ -1,275 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - - -package org.eclipse.m2e.editor.xml.internal.lifecycle; - - -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.repository.internal.DefaultVersionRangeResolver; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.ICompletionProposalExtension5; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.IMarkerResolution; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.MarkerAnnotation; -import org.eclipse.ui.views.markers.WorkbenchMarkerResolution; - -import org.eclipse.m2e.core.internal.IMavenConstants; -import org.eclipse.m2e.core.internal.MavenPluginActivator; -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.LifecycleMappingMetadataSourceXpp3Reader; -import org.eclipse.m2e.core.internal.lifecyclemapping.model.io.xpp3.LifecycleMappingMetadataSourceXpp3Writer; -import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction; -import org.eclipse.m2e.core.project.configurator.MojoExecutionKey; -import org.eclipse.m2e.core.ui.internal.UpdateConfigurationJob; -import org.eclipse.m2e.editor.xml.internal.Messages; - -public class WorkspaceLifecycleMappingProposal extends WorkbenchMarkerResolution implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution { - private static final Logger log = LoggerFactory.getLogger(WorkspaceLifecycleMappingProposal.class); - - - private IQuickAssistInvocationContext context; - private final IMarker marker; - - private final PluginExecutionAction action; - - public WorkspaceLifecycleMappingProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark, - PluginExecutionAction action) { - this.context = context; - marker = mark.getMarker(); - this.action = action; - } - - public WorkspaceLifecycleMappingProposal(IMarker marker, PluginExecutionAction action) { - this.marker = marker; - this.action = action; - } - - public void apply(final IDocument doc) { - run(marker); - } - - /** - * @return - */ - private static LifecycleMappingMetadataSource getWorkspacePreferencesMetadataSources() { - LifecycleMappingMetadataSource source = new LifecycleMappingMetadataSource(); - String mapp = MavenPluginActivator.getDefault().getPluginPreferences().getString("XXX_mappings"); - if (mapp != null) { - LifecycleMappingMetadataSourceXpp3Reader reader = new LifecycleMappingMetadataSourceXpp3Reader(); - try { - source = reader.read(new StringReader(mapp)); - } catch(IOException ex) { - // TODO Auto-generated catch block - log.error(ex.getMessage(), ex); - } catch(XmlPullParserException ex) { - // TODO Auto-generated catch block - log.error(ex.getMessage(), ex); - } - } - return source; - } - - - private static void performIgnore(IMarker mark, LifecycleMappingMetadataSource source) throws IOException, CoreException { - String pluginGroupId = mark.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$ - String pluginArtifactId = mark.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$ - String pluginVersion = mark.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$ - String goal = mark.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$ - String id = pluginGroupId + ":" + pluginArtifactId; - MojoExecutionKey key = new MojoExecutionKey(pluginGroupId, pluginArtifactId, pluginVersion, goal, null, null); - boolean found = false; - for (PluginExecutionMetadata pem : source.getPluginExecutions()) { - PluginExecutionFilter filter = pem.getFilter(); - if (PluginExecutionAction.ignore.equals(pem.getAction())) { - if (filter.getGroupId().equals(pluginGroupId) && filter.getArtifactId().equals(pluginArtifactId)) { - found = true; - try { - VersionRange range = VersionRange.createFromVersionSpec(filter.getVersionRange()); - DefaultArtifactVersion version = new DefaultArtifactVersion(pluginVersion); - if (!range.containsVersion(version)) { - filter.setVersionRange("[" + pluginVersion + ",)"); - } - } catch(InvalidVersionSpecificationException e) { - log.error(e.getMessage(), e); - } - if (!filter.getGoals().contains(goal)) { - filter.addGoal(goal); - } - break; - } - } - } - if (!found) { - PluginExecutionMetadata pe = new PluginExecutionMetadata(); - PluginExecutionFilter fil = new PluginExecutionFilter(pluginGroupId, pluginArtifactId, "[" + pluginVersion + ",)", goal); - pe.setFilter(fil); - source.addPluginExecution(pe); - Xpp3Dom actionDom = new Xpp3Dom("action"); - actionDom.addChild(new Xpp3Dom(PluginExecutionAction.ignore.name())); - pe.setActionDom(actionDom); - } - - - - } - - - - public String getAdditionalProposalInfo() { - return null; - } - - public IContextInformation getContextInformation() { - return null; - } - - public String getDisplayString() { - String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$ - return PluginExecutionAction.ignore.equals(action) ? NLS.bind("Mark goal {0} in workspace as ignored in Eclipse build", goal) - : NLS.bind(Messages.LifecycleMappingProposal_execute_label, goal); - } - - public Image getImage() { - return PluginExecutionAction.ignore.equals(action) ? PlatformUI.getWorkbench().getSharedImages() - .getImage(org.eclipse.ui.ISharedImages.IMG_TOOL_DELETE) : PlatformUI.getWorkbench().getSharedImages() - .getImage(org.eclipse.ui.ISharedImages.IMG_TOOL_FORWARD); - } - - public Point getSelection(IDocument arg0) { - return null; - } - - public Object getAdditionalProposalInfo(IProgressMonitor monitor) { - if (context == null) { - //no context in markerresolution, just to be sure.. - return null; - } - String pluginGroupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$ - String pluginArtifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$ - String pluginVersion = marker.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$ - String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$ - String execution = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, "-"); //$NON-NLS-1$ - String phase = marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, "-"); //$NON-NLS-1$ - String info = NLS.bind(Messages.LifecycleMappingProposal_all_desc, - new Object[] {goal, execution, phase, pluginGroupId + ":" + pluginArtifactId + ":" + pluginVersion, //$NON-NLS-1$ //$NON-NLS-2$ - (PluginExecutionAction.ignore.equals(action) - ? "This quickfix generates a plugin configuration snippet recognized by the m2e integration during project configuration. It marks the given goal as ignored for the purposes of the Eclipse build." - : Messages.LifecycleMappingProposal_execute_desc)}); - - return info; - } - - public String getLabel() { - return getDisplayString(); - } - - public void run(final IMarker marker) { - try { - if(PluginExecutionAction.ignore.equals(action)) { - LifecycleMappingMetadataSource source = getWorkspacePreferencesMetadataSources(); - performIgnore(marker, source); - LifecycleMappingMetadataSourceXpp3Writer writer = new LifecycleMappingMetadataSourceXpp3Writer(); - StringWriter sw = new StringWriter(); - writer.write(sw, source); - MavenPluginActivator.getDefault().getPluginPreferences().setValue("XXX_mappings", sw.toString()); - - //now update the project - new UpdateConfigurationJob(new IProject[] {marker.getResource().getProject()}).schedule(); - MavenPluginActivator.getDefault().savePluginPreferences(); - - } - } catch(IOException e) { - log.error("Error generating code in pom.xml", e); //$NON-NLS-1$ - } catch(CoreException e) { - log.error(e.getMessage(), e); - } - } - - public String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - public IMarker[] findOtherMarkers(IMarker[] markers) { - List<IMarker> handled = new ArrayList<IMarker>(); - - for (IMarker marker : markers) { - if (marker == this.marker) { - continue; - } - String hint = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null); - if ( hint != null && hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { - handled.add(marker); - } - } - return handled.toArray(new IMarker[handled.size()]); - } - - @Override - public void run(IMarker[] markers, IProgressMonitor monitor) { - try { - if(PluginExecutionAction.ignore.equals(action)) { - Set<IProject> prjs = new HashSet<IProject>(); - LifecycleMappingMetadataSource source = getWorkspacePreferencesMetadataSources(); - for (IMarker mark : markers) { - performIgnore(mark, source); - prjs.add(mark.getResource().getProject()); - } - LifecycleMappingMetadataSourceXpp3Writer writer = new LifecycleMappingMetadataSourceXpp3Writer(); - StringWriter sw = new StringWriter(); - writer.write(sw, source); - MavenPluginActivator.getDefault().getPluginPreferences().setValue("XXX_mappings", sw.toString()); - - MavenPluginActivator.getDefault().savePluginPreferences(); - for (IMarker mark : markers) { - mark.delete(); - } - //now update the projects - new UpdateConfigurationJob(prjs.toArray(new IProject[0])).schedule(); - - } - } catch(IOException e) { - log.error("Error generating code in pom.xml", e); //$NON-NLS-1$ - } catch(CoreException e) { - log.error(e.getMessage(), e); - } - } - -}
\ No newline at end of file diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties index 3cf16b38..640e7c0c 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties @@ -10,11 +10,17 @@ InsertArtifactProposal_searchDialog_title=Select Parent InsertExpressionProposal_hint1=The expression evaluates to <b>{0}</b> in the current effective pom. InsertExpressionProposal_hint2=<br>It is based on property defined in <b>{0}</b> InsertSPDXLicenseProposal_0=Insert SPDX License +LifecycleMappingDialog_Ignore=Ignore {0} +LifecycleMappingDialog_LocationToIgnore=Select location to place ignore +LifecycleMappingDialog_NonWorkspacePom=Non-workspace pom +LifecycleMappingDialog_PluginDefinitionInSelectedPom=Plugin definition in selected pom. +LifecycleMappingDialog_UseWorkspaceSettings=Place in workspace settings +LifecycleMappingDialog_UseWorkspaceSettingsDesc=Checking this box will place the lifecycle mapping metadata in workspace settings.\nTo edit this, go to Preferences -> Maven and click on Open workspace lifecycle mappings metadata LifecycleMappingProposal_all_desc=<html>Goal: <b>{0}</b><br/>ExecutionId: <b>{1}</b><br/>Phase: <b>{2}</b><br/>Plugin: {3}<br/><br/>{4}</html> LifecycleMappingProposal_execute_desc=This quickfix generates a plugin configuration snippet recognized by the m2e integration during project configuration. It marks the given goal to be executed during the Eclipse build. LifecycleMappingProposal_execute_label=Execute goal {0} as part of Eclipse build LifecycleMappingProposal_ignore_desc=This quickfix generates a plugin configuration snippet recognized by the m2e integration during project configuration. It marks the given goal as ignored for the purposes of the Eclipse build. -LifecycleMappingProposal_ignore_label=Permanently mark goal {0} in pom.xml as ignored in Eclipse build +LifecycleMappingProposal_ignore_label=Permanently mark goal {0} in pom.xml or workspace preferences as ignored in Eclipse build MavenMarkerResolution_error=Unable to apply the quick fix. The file may have unsaved changes that invalidate the current quick fix. MavenMarkerResolution_error_title=Error MavenMarkerResolution_schema_label=Add Schema information to the specified pom.xml diff --git a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java index 29f7742d..9ff3a467 100644 --- a/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java +++ b/org.eclipse.m2e.tests.common/src/org/eclipse/m2e/tests/common/AbstractLifecycleMappingTest.java @@ -77,9 +77,9 @@ public abstract class AbstractLifecycleMappingTest extends AbstractMavenProjectT return mavenProjectManager.create(project[0], monitor); } - protected LifecycleMappingMetadataSource loadLifecycleMappingMetadataSource(String metadataFilename) + + private LifecycleMappingMetadataSource loadLifecycleMappingMetadataSourceInternal(File metadataFile) throws IOException, XmlPullParserException { - File metadataFile = new File(metadataFilename); assertTrue("File does not exist:" + metadataFile.getAbsolutePath(), metadataFile.exists()); InputStream in = new FileInputStream(metadataFile); try { @@ -90,6 +90,22 @@ public abstract class AbstractLifecycleMappingTest extends AbstractMavenProjectT IOUtil.close(in); } } + protected LifecycleMappingMetadataSource loadLifecycleMappingMetadataSource(String metadataFilename) + throws IOException, XmlPullParserException { + return loadLifecycleMappingMetadataSourceInternal(new File(metadataFilename)); + } + + protected LifecycleMappingMetadataSource loadWorkspaceLifecycleMappingMetadataSource() + throws IOException, XmlPullParserException { + return loadLifecycleMappingMetadataSourceInternal(new File(MavenPluginActivator.getDefault() + .getMavenConfiguration().getWorkspaceMappingsFile())); + } + + protected void setWorkspaceLifecycleMappingMetadataSource(String newMapping) + throws IOException, XmlPullParserException { + MavenPluginActivator.getDefault() + .getMavenConfiguration().setWorkspaceMappings(newMapping); + } /** * Creates new partially initialised MavenProjectFacade instance |