Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-02-09 09:22:12 +0000
committerMilos Kleint2011-02-09 09:24:51 +0000
commit669341e14247b627a0d39628723f3b6a1123ee71 (patch)
tree91a2432012e4c9c6891e86752ac34b216b8df282
parent681d24add5d563c8e8bdf99748177af91e2f4ba2 (diff)
downloadm2e-core-669341e14247b627a0d39628723f3b6a1123ee71.tar.gz
m2e-core-669341e14247b627a0d39628723f3b6a1123ee71.tar.xz
m2e-core-669341e14247b627a0d39628723f3b6a1123ee71.zip
335299, 335490 have a more prominent place for the discover quick fix proposal, show only once on one line in editor and when invoked, take all markers in the same file into consideration
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java22
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/MavenDiscoveryMarkerResolutionGenerator.java17
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java47
3 files changed, 77 insertions, 9 deletions
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
index 5c3b5c7b..6415115b 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
@@ -18,25 +18,37 @@ import java.util.List;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecution;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.core.IMavenConstants;
+import org.eclipse.m2e.core.core.MavenLogger;
import org.eclipse.m2e.internal.discovery.MavenDiscovery;
import org.eclipse.m2e.internal.discovery.MavenDiscoveryIcons;
import org.eclipse.m2e.internal.discovery.Messages;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
+//IMPORANT: if you decide to rename the class please correct code in PomQuickAssistProcessor as well..
class DiscoveryWizardProposal extends WorkbenchMarkerResolution {
- private IMarker marker;
-
- public DiscoveryWizardProposal(IMarker marker) {
- this.marker = marker;
+ public DiscoveryWizardProposal() {
}
@SuppressWarnings("unchecked")
public void run(IMarker marker) {
+ //by default we want save people some time by resolving discovery issues in one project/file in one shot..
+ try {
+ IMarker[] fileMarkers = marker.getResource().findMarkers(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID,
+ true, IResource.DEPTH_INFINITE);
+ run(fileMarkers, new NullProgressMonitor());
+ return;
+ } catch(CoreException e) {
+ //doesn't matter, as a fallback run the one marker variant only
+ }
+
String type = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null);
if(IMavenConstants.EDITOR_HINT_UNKNOWN_PACKAGING.equals(type)) {
MavenDiscovery.launchWizard(Collections.singleton(getPackageType(marker)), Collections.EMPTY_LIST,
@@ -117,7 +129,7 @@ class DiscoveryWizardProposal extends WorkbenchMarkerResolution {
public IMarker[] findOtherMarkers(IMarker[] markers) {
List<IMarker> handled = new ArrayList<IMarker>();
for(IMarker marker : markers) {
- if(marker != this.marker && MavenDiscoveryMarkerResolutionGenerator.canResolve(marker)) {
+ if(MavenDiscoveryMarkerResolutionGenerator.canResolve(marker)) {
handled.add(marker);
}
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/MavenDiscoveryMarkerResolutionGenerator.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/MavenDiscoveryMarkerResolutionGenerator.java
index 76633e0c..61420a76 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/MavenDiscoveryMarkerResolutionGenerator.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/MavenDiscoveryMarkerResolutionGenerator.java
@@ -12,6 +12,8 @@
package org.eclipse.m2e.internal.discovery.markers;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;
@@ -20,13 +22,26 @@ import org.eclipse.ui.IMarkerResolutionGenerator2;
public class MavenDiscoveryMarkerResolutionGenerator implements IMarkerResolutionGenerator, IMarkerResolutionGenerator2 {
+ private static QualifiedName QUALIFIED = new QualifiedName("org.eclipse.m2e.discovery", "discoveryResolution");
+
public boolean hasResolutions(IMarker marker) {
return canResolve(marker);
}
public IMarkerResolution[] getResolutions(IMarker marker) {
if(canResolve(marker)) {
- return new IMarkerResolution[] {new DiscoveryWizardProposal(marker)};
+ try {
+ //for each file have just one instance of the discover proposal array.
+ //important for 335299
+ IMarkerResolution[] cached = (IMarkerResolution[]) marker.getResource().getSessionProperty(QUALIFIED);
+ if (cached == null) {
+ cached = new IMarkerResolution[] {new DiscoveryWizardProposal()};
+ marker.getResource().setSessionProperty(QUALIFIED, cached);
+ }
+ return cached;
+ } catch(CoreException e) {
+ return new IMarkerResolution[] {new DiscoveryWizardProposal()};
+ }
}
return new IMarkerResolution[0];
}
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 52490df2..07bf0ac3 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
@@ -115,9 +115,9 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor {
proposals.add(new SchemaCompletionProposal(context, mark));
}
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 LifecycleMappingProposal(context, mark, PluginExecutionAction.execute));
- extractedFromMarkers(proposals, mark);
} else if (hint.equals(IMavenConstants.EDITOR_HINT_UNKNOWN_PACKAGING)){
extractedFromMarkers(proposals, mark);
}
@@ -146,7 +146,15 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor {
for (IMarkerResolution res : resolutions) {
//sort of weak condition, but can't think of anything else that would filter our explicitly declared ones..
if (!res.getClass().getName().contains("org.eclipse.m2e.editor.xml")) {
- proposals.add(new MarkerResolutionProposal(res, mark.getMarker()));
+ MarkerResolutionProposal prop = new MarkerResolutionProposal(res, mark.getMarker());
+ //335299 for discoveryWizardProposal have only one item returned per invokation.
+ if (res.getClass().getName().contains("DiscoveryWizardProposal")) {
+ if (!proposals.contains(prop)) {
+ proposals.add(prop);
+ }
+ } else {
+ proposals.add(prop);
+ }
}
}
}
@@ -699,11 +707,44 @@ static class IgnoreWarningProposal implements ICompletionProposal, ICompletionPr
/**
* a wrapper around IMarkerResolution that acts as ICompletionProposal
- *
+ * for 335299 introduced equals() and hashcode() methods that are based on the MarkerResolution passed in.
* @author mkleint
*/
public class MarkerResolutionProposal implements ICompletionProposal {
+ /**
+ *
+ * for 335299 introduced equals() and hashcode() methods that are based on the MarkerResolution passed in.
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((resolution == null) ? 0 : resolution.hashCode());
+ return result;
+ }
+
+ /*
+ * for 335299 introduced equals() and hashcode() methods that are based on the MarkerResolution passed in.
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj)
+ return true;
+ if(obj == null)
+ return false;
+ if(!(obj instanceof MarkerResolutionProposal))
+ return false;
+ MarkerResolutionProposal other = (MarkerResolutionProposal) obj;
+ if(resolution == null) {
+ if(other.resolution != null)
+ return false;
+ } else if(!resolution.equals(other.resolution))
+ return false;
+ return true;
+ }
+
private final IMarkerResolution resolution;
private final IMarker marker;

Back to the top