Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-08-03 11:25:22 +0000
committerIgor Fedorenko2011-08-03 11:25:22 +0000
commit9b0f9f606581c7e5385cdcf01cdaa90b1ce63fad (patch)
tree4363c6ff6992f31d7f3cd728120106cd13056cf2
parent9f1a4bad630f4c22430279c6a77e3a4bbc9df4e6 (diff)
downloadm2e-core-9b0f9f606581c7e5385cdcf01cdaa90b1ce63fad.tar.gz
m2e-core-9b0f9f606581c7e5385cdcf01cdaa90b1ce63fad.tar.xz
m2e-core-9b0f9f606581c7e5385cdcf01cdaa90b1ce63fad.zip
350443 - Quickfix for lifecycle mapping ignore does not always work
Fixed a problem when quick fix dialog did not appear right after workbench restart, when MavenProject cache was not primed yet. The code now calls getMavenProject(IProgressMonitor), which loads MavenProject instance as necessary. Fixed a problem when quick-fix failed if plugin was using ${prop} version. Unfortunately, the code will still fail if plugin groupId or artifactId are defined using properties, but I to fix that association between elements of effective and original project model is necessary, but Maven does not currently provide it. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java3
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java36
2 files changed, 29 insertions, 10 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java
index aa65e6f8..efb57f08 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java
@@ -96,7 +96,8 @@ public class PomHierarchyComposite extends Composite implements IInputSelectionP
private void computeHeirarchy(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
LinkedList<MavenProject> hierarchy = new LinkedList<MavenProject>();
- hierarchy.addAll(new ParentGatherer(projectFacade.getMavenProject(), projectFacade).getParentHierarchy(monitor));
+ hierarchy.addAll(new ParentGatherer(projectFacade.getMavenProject(monitor), projectFacade)
+ .getParentHierarchy(monitor));
setHierarchy(hierarchy);
}
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 2ed6ef84..a2b86977 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
@@ -8,10 +8,13 @@
* Contributors:
* Sonatype, Inc. - initial API and implementation
*******************************************************************************/
+
package org.eclipse.m2e.editor.xml.internal.lifecycle;
+import java.io.File;
import java.lang.reflect.InvocationTargetException;
+import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
@@ -40,6 +43,7 @@ import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.components.PomHierarchyComposite;
+@SuppressWarnings("restriction")
public class LifecycleMappingDialog extends Dialog implements ISelectionChangedListener {
private PomHierarchyComposite pomComposite;
@@ -105,7 +109,9 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
//350439
//set selection here, because we listen on changes and update the ok button.
//but the button is not created until super is called here..
- pomComposite.setSelection(new StructuredSelection(pluginProject));
+ if(pluginProject != null) {
+ pomComposite.setSelection(new StructuredSelection(pluginProject));
+ }
}
public void selectionChanged(SelectionChangedEvent event) {
@@ -143,16 +149,28 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
}
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;
- }
- }
+ MavenProject project = facade.getMavenProject(); // if we got here, facade.getMavenProject can be null
+
+ Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId);
+
+ if(plugin == null) {
+ return null; // can't really happy
+ }
+
+ InputLocation location = plugin.getLocation("");
+
+ if(location == null || location.getSource() == null || location.getSource().getLocation() == null) {
+ // that's odd. where does this come from???
+ return null;
+ }
+
+ File basedir = new File(location.getSource().getLocation()).getParentFile(); // should be canonical file already
+ for(MavenProject other : pomComposite.getHierarchy()) {
+ if(basedir.equals(other.getBasedir())) {
+ return other;
}
}
+
return null;
}
}

Back to the top