Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Eisenberg2012-07-19 17:42:25 +0000
committerIgor Fedorenko2012-08-13 11:22:43 +0000
commit2e7413e5f2b6b0bb98df5fb0699c148320deeeea (patch)
tree153b6c03a3628710ccfec79541b4066346bc9a67 /org.eclipse.m2e.core.ui
parentee868734f9715035106123b37d86af0e3d847115 (diff)
downloadm2e-core-2e7413e5f2b6b0bb98df5fb0699c148320deeeea.tar.gz
m2e-core-2e7413e5f2b6b0bb98df5fb0699c148320deeeea.tar.xz
m2e-core-2e7413e5f2b6b0bb98df5fb0699c148320deeeea.zip
This commit contains most of the work for bug 350414.
This includes adding workspace settings to the chain of lookups for determining lifecycle mappings for m2e projects. There are changes to existing quickfixes, and a new workspace preferences page that allows users to view their workspace mappings and edit the raw text file. There is partial work done for displaying a table of workspace lifecycle mappings in the preferences page. The refactoring of the project lifecycle mappings table is complete, but I just don't know how to populate the viewer with workspace mappings only For compliance with Eclipse.org's contribution rules: (1) I (Andrew Eisenberg) wrote 100% of the code; (2) I have the right to contribute the code to Eclipse; (3) the file header contains the appropriate License header. Also, this patch is built on top of the SHA 170c7936da947d28e7824bc1d2375903dbda9b17
Diffstat (limited to 'org.eclipse.m2e.core.ui')
-rw-r--r--org.eclipse.m2e.core.ui/plugin.properties3
-rw-r--r--org.eclipse.m2e.core.ui/plugin.xml6
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java14
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/LifecycleMappingOperation.java61
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java4
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties8
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPreferencePage.java167
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingPropertyPage.java414
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java445
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenPreferencePage.java29
10 files changed, 712 insertions, 439 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);
- }
-
}

Back to the top