Author: fbricon
Date: 2011-11-26 08:08:52 -0500 (Sat, 26 Nov 2011)
New Revision: 36676
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/OpenPageInBrowserMarkerResolution.java
Removed:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/JBossRepositoriesMarkerResolution.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/problems/
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/MavenDependencyMarkerResolutionGenerator.java
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties
Log:
JBIDE-9921: Add quickfixes for missing dependencies based on M2E error markers. Quickfixes
will open documentation pages on
jboss.org
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-11-25 19:55:09 UTC (rev
36675)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-11-26 13:08:52 UTC (rev
36676)
@@ -222,13 +222,18 @@
</perspectiveExtension>
</extension>
- <!-- TODO implement marker resolution as part of JBIDE-9921
- <extension
+ <extension
point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
-
class="org.jboss.tools.maven.ui.internal.problems.MavenDependencyMarkerResolutionGenerator"
+
class="org.jboss.tools.maven.ui.internal.markers.MavenDependencyMarkerResolutionGenerator"
markerType="org.eclipse.m2e.core.maven2Problem.dependency">
</markerResolutionGenerator>
</extension>
- -->
+ <extension
+ point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+
class="org.jboss.tools.maven.ui.internal.markers.MavenDependencyMarkerResolutionGenerator"
+ markerType="org.eclipse.m2e.core.maven2Problem.pomloading">
+ </markerResolutionGenerator>
+ </extension>
</plugin>
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java 2011-11-25
19:55:09 UTC (rev 36675)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/Messages.java 2011-11-26
13:08:52 UTC (rev 36676)
@@ -84,6 +84,8 @@
public static String SelectProfilesDialog_Select_Maven_profiles;
public static String SelectProfilesDialog_Select_the_active_Maven_profiles;
public static String SelectProfilesDialog_SelectAll;
+ public static String Quickfix_setupCommunityRepo;
+ public static String Quickfix_setupEnterpriseRepo;
static {
// initialize resource bundle
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/JBossRepositoriesMarkerResolution.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/problems/JBossRepositoriesMarkerResolution.java 2011-11-25
13:21:37 UTC (rev 36660)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/JBossRepositoriesMarkerResolution.java 2011-11-26
13:08:52 UTC (rev 36676)
@@ -1,72 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2009-2011 Red Hat, Inc. and others.
- * 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:
- * JBoss by Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.maven.ui.internal.problems;
-
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.internal.compiler.util.Util;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
-import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IMarkerResolution;
-import org.eclipse.ui.IMarkerResolution2;
-import org.w3c.dom.Document;
-
-public class JBossRepositoriesMarkerResolution implements IMarkerResolution,
- IMarkerResolution2 {
-
- public String getDescription() {
- return getLabel();
- }
-
- public Image getImage() {
- return null;
- }
-
- public String getLabel() {
- // TODO Auto-generated method stub
- return "Add missing JBoss repositories to settings.xml";
- }
-
- public void run(IMarker arg0) {
- Operation addRepos = new AddRepositoriesOperation();
- File settings = new File(MavenPlugin.getMavenConfiguration().getUserSettingsFile());
- try {
- String content = new String(Util.getFileCharContent(settings, null));
- IDocument settingsDoc = new org.eclipse.jface.text.Document(content);
- performOnDOMDocument(new OperationTuple(settingsDoc, addRepos));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
- class AddRepositoriesOperation implements Operation {
-
- public void process(Document document) {
- document.createComment("Changing settings at "+new Date());
- System.err.println("Resolving repository stuff");
- }
-
- }
-}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/MavenDependencyMarkerResolutionGenerator.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/problems/MavenDependencyMarkerResolutionGenerator.java 2011-11-25
13:21:37 UTC (rev 36660)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/MavenDependencyMarkerResolutionGenerator.java 2011-11-26
13:08:52 UTC (rev 36676)
@@ -8,20 +8,32 @@
* Contributors:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
-package org.jboss.tools.maven.ui.internal.problems;
+package org.jboss.tools.maven.ui.internal.markers;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.jboss.tools.maven.ui.Messages;
@SuppressWarnings("nls")
public class MavenDependencyMarkerResolutionGenerator implements
IMarkerResolutionGenerator2 {
- private static final String MSG_PREFIX = "Missing artifact "; //$NON-NLS-1$
+ private static final String ORG_JBOSS_PREFIX = "org.jboss";
+ private static final String REDHAT_SUFFIX = "-redhat";
+
+ private static final String JBOSS_ENTERPRISE_REPO_SETUP_GUIDE_URL =
"http://community.jboss.org/wiki/SettingUpTheJBossEnterpriseRepositories";
+
+ private static final String JBOSS_COMMUNITY_REPO_SETUP_GUIDE_URL =
"http://community.jboss.org/wiki/MavenGettingStarted-Users";
+
+ private static final String MISSING_ARTIFACT_PREFIX = "Missing artifact ";
//$NON-NLS-1$
+
+ private static final String FAILURE_TO_FIND_STRING = "Failure to find ";
//$NON-NLS-1$
+
enum ResolutionType {
JBOSS_REPO, EAP_REPO, UNSUPPORTED
}
@@ -35,21 +47,14 @@
switch (type) {
case JBOSS_REPO:
return new IMarkerResolution[] {
- new JBossRepositoriesMarkerResolution(),
- new JBossRepositoriesMarkerResolution() {
- @Override
- public String getLabel() {
- return "Add JBoss repositories to pom.xml";
- }
- } };
+ new OpenPageInBrowserMarkerResolution(Messages.Quickfix_setupCommunityRepo,
+ JBOSS_COMMUNITY_REPO_SETUP_GUIDE_URL)
+ };
case EAP_REPO:
return new IMarkerResolution[] {
- new JBossRepositoriesMarkerResolution() {
- @Override
- public String getLabel() {
- return "Set up EAP repository";
- }
- } };
+ new OpenPageInBrowserMarkerResolution(Messages.Quickfix_setupEnterpriseRepo,
+ JBOSS_ENTERPRISE_REPO_SETUP_GUIDE_URL)
+ };
}
return new IMarkerResolution[0];
}
@@ -60,9 +65,9 @@
private ResolutionType getResolutionType(IMarker marker) {
ArtifactKey key = getArtifactKey(marker);
- if (key.getVersion().contains("-redhat")) {
+ if (key.getVersion().contains(REDHAT_SUFFIX)) {
return ResolutionType.EAP_REPO;
- } else if (key.getGroupId().startsWith("org.jboss")) {
+ } else if (key.getGroupId().startsWith(ORG_JBOSS_PREFIX)) {
return ResolutionType.JBOSS_REPO;
}
return ResolutionType.UNSUPPORTED;
@@ -74,7 +79,14 @@
key = (ArtifactKey) marker.getAttribute("artifactKey");
if (key == null) {
String message = (String) marker.getAttribute("message", null);
- key = parseMessage(message);
+ if (message != null) {
+ String markerType = marker.getType();
+ if (IMavenConstants.MARKER_DEPENDENCY_ID.equals(markerType)) {
+ key = parseDependencyErrorMessage(message);
+ } else if (IMavenConstants.MARKER_POM_LOADING_ID.equals(markerType)) {
+ key = parsePomLoadingErrorMessage(message);
+ }
+ }
}
} catch (CoreException e) {
e.printStackTrace();
@@ -82,24 +94,40 @@
return key;
}
- private ArtifactKey parseMessage(String message) {
+ private ArtifactKey parseDependencyErrorMessage(String message) {
ArtifactKey key = null;
- if (message != null && message.startsWith(MSG_PREFIX)) {
- String keyString = message.substring(MSG_PREFIX.length());
- String[] keyAsArray = keyString.trim().split(":"); //$NON-NLS-1$
- if (keyAsArray.length > 3) {
- String artifactId = keyAsArray[0];
- String groupId = keyAsArray[1];
- String classifier = null;
- String version;
- if (keyAsArray.length > 4) {
- classifier = keyAsArray[3];
- version = keyAsArray[4];
- } else {
- version = keyAsArray[3];
- }
- key = new ArtifactKey(groupId, artifactId, version, classifier);
+ if (message.startsWith(MISSING_ARTIFACT_PREFIX)) {
+ String keyString = message.substring(MISSING_ARTIFACT_PREFIX.length());
+ key = extractKey(key, keyString);
+ }
+ return key;
+ }
+
+ private ArtifactKey parsePomLoadingErrorMessage(String message) {
+ ArtifactKey key = null;
+ int start = message.indexOf(FAILURE_TO_FIND_STRING);
+ if (start > -1) {
+ int from = FAILURE_TO_FIND_STRING.length()+start;
+ String keyString = message.substring(from, message.indexOf(" ", from));
+ key = extractKey(key, keyString);
+ }
+ return key;
+ }
+
+ private ArtifactKey extractKey(ArtifactKey key, String keyString) {
+ String[] keyAsArray = keyString.trim().split(":"); //$NON-NLS-1$
+ if (keyAsArray.length > 3) {
+ String groupId = keyAsArray[0];
+ String artifactId = keyAsArray[1];
+ String classifier = null;
+ String version;
+ if (keyAsArray.length > 4) {
+ classifier = keyAsArray[3];
+ version = keyAsArray[4];
+ } else {
+ version = keyAsArray[3];
}
+ key = new ArtifactKey(groupId, artifactId, version, classifier);
}
return key;
}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/OpenPageInBrowserMarkerResolution.java
(from rev 36660,
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/problems/JBossRepositoriesMarkerResolution.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/OpenPageInBrowserMarkerResolution.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/internal/markers/OpenPageInBrowserMarkerResolution.java 2011-11-26
13:08:52 UTC (rev 36676)
@@ -0,0 +1,69 @@
+/*************************************************************************************
+ * Copyright (c) 2009-2011 Red Hat, Inc. and others.
+ * 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:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.ui.internal.markers;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
+
+public class OpenPageInBrowserMarkerResolution implements IMarkerResolution,
+ IMarkerResolution2 {
+
+
+ private final String label;
+ private final String url;
+
+ public OpenPageInBrowserMarkerResolution(String label, String url) {
+ this.label = label;
+ this.url = url;
+ }
+
+ public String getDescription() {
+ return getLabel();
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker arg0) {
+
+ IWorkbenchBrowserSupport browserSupport =
PlatformUI.getWorkbench().getBrowserSupport();
+ try {
+ IWebBrowser browser;
+ if (browserSupport.isInternalWebBrowserAvailable()) {
+ browser = browserSupport.createBrowser(null);
+ } else {
+ browser = browserSupport.getExternalBrowser();
+ }
+ browser.openURL(new URL(url));
+ } catch (PartInitException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties 2011-11-25
19:55:09 UTC (rev 36675)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/messages.properties 2011-11-26
13:08:52 UTC (rev 36676)
@@ -64,3 +64,6 @@
SelectProfilesDialog_Select_Maven_profiles=Select Maven profiles
SelectProfilesDialog_Select_the_active_Maven_profiles=Select the active Maven profiles
for project {0}. Right-click to (de)activate a profile.
SelectProfilesDialog_SelectAll=Select All
+
+Quickfix_setupCommunityRepo=See how to setup JBoss repositories in your settings.xml
+Quickfix_setupEnterpriseRepo=See how to setup JBoss Enterprise repositories in your
settings.xml
\ No newline at end of file