Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-04-12 21:10:21 +0000
committerMatthew Piggott2011-04-12 21:10:47 +0000
commit416af3a5f8c49e6e8f89a62bd094eb9a29563927 (patch)
tree11367686d3d96dd2be5fcfd6495f0d3fbe35c47b /org.eclipse.m2e.editor.xml
parent82f98e04fecbff44ddda2d95c76a8cb14569a254 (diff)
downloadm2e-core-416af3a5f8c49e6e8f89a62bd094eb9a29563927.tar.gz
m2e-core-416af3a5f8c49e6e8f89a62bd094eb9a29563927.tar.xz
m2e-core-416af3a5f8c49e6e8f89a62bd094eb9a29563927.zip
Added support for choosing pom in hierarchy to ignore goal
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java143
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java34
2 files changed, 171 insertions, 6 deletions
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
new file mode 100644
index 00000000..729924a7
--- /dev/null
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+package org.eclipse.m2e.editor.xml.internal.lifecycle;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+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;
+
+
+public class LifecycleMappingDialog extends Dialog implements ISelectionChangedListener {
+
+ private PomHierarchyComposite pomComposite;
+
+ private CLabel status;
+
+ private IFile pomFile;
+
+ private IMavenProjectFacade facade;
+
+ private String pluginGroupId;
+
+ private String pluginArtifactId;
+
+ private String pluginVersion;
+
+ private MavenProject pluginProject;
+
+ public LifecycleMappingDialog(Shell parentShell, IFile pom, String pluginGroupId, String pluginArtifactId,
+ String pluginVersion) {
+ super(parentShell);
+ facade = MavenPlugin.getMavenProjectRegistry().create(pom, true, new NullProgressMonitor());
+ this.pluginGroupId = pluginGroupId;
+ this.pluginArtifactId = pluginArtifactId;
+ this.pluginVersion = pluginVersion;
+ }
+
+ @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");
+ pomComposite = new PomHierarchyComposite(container, SWT.BORDER);
+ pomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ pomComposite.addSelectionChangedListener(this);
+ pomComposite.computeHeirarchy(facade, new IRunnableContext() {
+
+ public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
+ throws InvocationTargetException, InterruptedException {
+ runnable.run(new NullProgressMonitor());
+ }
+ });
+ status = new CLabel(container, SWT.WRAP);
+ status.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
+
+ pluginProject = locatePlugin();
+ return container;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ getButton(OK).setEnabled(false);
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ MavenProject project = pomComposite.fromSelection();
+ if(getButton(OK) != null) {
+ getButton(OK).setEnabled(project != null && project.getFile() != null);
+ }
+ updateStatus(project);
+ }
+
+ private void updateStatus(MavenProject project) {
+ if(project.getFile() == null) {
+ status.setText("Non-workspace pom");
+ status.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
+ } else if(project.equals(pluginProject)) {
+ status.setText("Plugin definition in selected pom.");
+ status.setImage(null);
+ } else {
+ status.setText("");
+ status.setImage(null);
+ }
+ }
+
+ @Override
+ protected void okPressed() {
+ pomFile = M2EUtils.getPomFile(pomComposite.fromSelection());
+ super.okPressed();
+ }
+
+ /*
+ * Should only be called after dialog has closed with OK return code
+ */
+ public IFile getPomFile() {
+ return pomFile;
+ }
+
+ private MavenProject locatePlugin() {
+ for (MavenProject project : pomComposite.getHierarchy()) {
+ if (project.getOriginalModel().getBuild() != null) {
+ for (Plugin plugin : project.getOriginalModel().getBuild().getPlugins()) {
+ if(plugin.getGroupId().equals(pluginGroupId) && plugin.getArtifactId().equals(pluginArtifactId)
+ && (plugin.getVersion() == null || pluginVersion.equals(plugin.getVersion()))) {
+ return project;
+ }
+ }
+ }
+ }
+ return null;
+ }
+}
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 7ab80136..a07c130c 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
@@ -12,6 +12,8 @@
package org.eclipse.m2e.editor.xml.internal.lifecycle;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument;
+
import java.io.IOException;
import org.slf4j.Logger;
@@ -26,17 +28,19 @@ 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.jface.window.Window;
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.internal.Workbench;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
-
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
+import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
import org.eclipse.m2e.editor.xml.internal.Messages;
public class LifecycleMappingProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution {
@@ -61,8 +65,7 @@ public class LifecycleMappingProposal implements ICompletionProposal, ICompletio
public void apply(final IDocument doc) {
try {
- performOnDOMDocument(new OperationTuple(doc, createOperation()));
- marker.delete();
+ perform();
} catch(IOException e) {
log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
} catch(CoreException e) {
@@ -70,6 +73,26 @@ public class LifecycleMappingProposal implements ICompletionProposal, ICompletio
}
}
+ private void perform() throws IOException, CoreException {
+ final IFile[] pomFile = new IFile[1];
+ Workbench.getInstance().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, ""));
+ dialog.setBlockOnOpen(true);
+ if(dialog.open() == Window.OK) {
+ pomFile[0] = dialog.getPomFile();
+ }
+ }
+ });
+ if(pomFile[0] != null) {
+ performOnDOMDocument(new OperationTuple(pomFile[0], createOperation()));
+ }
+ }
+
private LifecycleMappingOperation createOperation() {
String pluginGroupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$
String pluginArtifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$
@@ -129,8 +152,7 @@ public class LifecycleMappingProposal implements ICompletionProposal, ICompletio
public void run(final IMarker marker) {
try {
- performOnDOMDocument(new OperationTuple((IFile) marker.getResource(), createOperation()));
- marker.delete();
+ perform();
} catch(IOException e) {
log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
} catch(CoreException e) {

Back to the top