Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2010-12-27 05:11:31 -0500
committerMilos Kleint2010-12-27 05:11:31 -0500
commit1851236546adb97f4b72cf45ce7c38475d4f3e64 (patch)
tree8ee03c3ff137b84f58d18896d1781935a7a7d08c
parent9c946c3ebecfc372968ebc2e176b998916f47831 (diff)
downloadm2e-core-1851236546adb97f4b72cf45ce7c38475d4f3e64.tar.gz
m2e-core-1851236546adb97f4b72cf45ce7c38475d4f3e64.tar.xz
m2e-core-1851236546adb97f4b72cf45ce7c38475d4f3e64.zip
simplify the dependency label provider
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java9
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java10
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java81
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ManageDependencyLabelProvider.java14
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java4
5 files changed, 24 insertions, 94 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
index c8f05033..eb18169e 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
@@ -335,7 +335,6 @@ public class DependenciesComposite extends Composite {
if (facade == null) {
return;
}
- dependencyLabelProvider.setFacade(facade);
showInheritedDependencies = true;
Display.getDefault().asyncExec(new Runnable() {
@@ -712,6 +711,14 @@ public class DependenciesComposite extends Composite {
}
+ /** mkleint: apparently this methods shall find the version in resolved pom for the given dependency
+ * not sure if getBaseVersion is the way to go..
+ * Note: duplicated in DependencyDetailsComposite
+ * @param groupId
+ * @param artifactId
+ * @param monitor
+ * @return
+ */
String getVersion(String groupId, String artifactId, IProgressMonitor monitor) {
try {
MavenProject mavenProject = editorPage.getPomEditor().readMavenProject(false, monitor);
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java
index 525af9b8..28712236 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java
@@ -85,10 +85,18 @@ public class DependencyDetailComposite extends Composite {
toolkit.paintBordersFor(this);
toolkit.adapt(this);
}
-
+ /** mkleint: apparently this methods shall find the version in resolved pom for the given dependency
+ * not sure if getBaseVersion is the way to go..
+ * Note: duplicated in DependenciesComposite
+ * @param groupId
+ * @param artifactId
+ * @param monitor
+ * @return
+ */
protected String getVersion(String groupId, String artifactId, IProgressMonitor monitor) {
try {
MavenProject mavenProject = editorPage.getPomEditor().readMavenProject(false, monitor);
+
Artifact a = mavenProject.getArtifactMap().get(groupId + ":" + artifactId); //$NON-NLS-1$
if(a != null) {
return a.getBaseVersion();
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java
index 15280b70..165a1a99 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java
@@ -48,8 +48,6 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
private boolean showGroupId = false;
- private IMavenProjectFacade facade = null;
-
public void setPomEditor(MavenPomEditor pomEditor) {
this.pomEditor = pomEditor;
}
@@ -61,70 +59,13 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
// IColorProvider
public Color getForeground(Object element) {
- if(element instanceof Dependency) {
- Dependency dependency = (Dependency) element;
- String scope = dependency.getScope();
- if(scope != null && !"compile".equals(scope)) { //$NON-NLS-1$
- return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
- }
- } else if (element instanceof org.apache.maven.model.Dependency) {
- if (facade == null || facade.getMavenProject() == null
- || facade.getMavenProject().getModel() == null) {
- //If facade is null and we are getting maven Dependencies, something has gone horribly wrong
- return Display.getDefault().getSystemColor(SWT.COLOR_RED);
- }
-
- if(!isInherited((org.apache.maven.model.Dependency) element)) {
- return null;
- }
-
- /*
- * Element is inherited, therefore we cannot edit it (yet ...)
- */
-
+ if (element instanceof org.apache.maven.model.Dependency) {
+ //mkleint: let's just assume all maven Dependency instances are inherited
return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
}
return null;
}
-
- protected boolean isInherited(org.apache.maven.model.Dependency dependency) {
- if (dependency.getLocation("") == null) { //$NON-NLS-1$
- MavenEditorPlugin.getDefault().getLog().log(
- new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID,
- "getLocation(\"\") for dependency '"+dependency.toString()+"' is null. This is a bug in Maven.")); //$NON-NLS-1$ //$NON-NLS-2$
- return false;
- }
-
- if (dependency.getLocation("").getSource() == null) { //$NON-NLS-1$
- MavenEditorPlugin.getDefault().getLog().log(
- new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID,
- "getLocation(\"\").getSource() for dependency '"+dependency.toString()+"' is null. This is a bug in Maven.")); //$NON-NLS-1$ //$NON-NLS-2$
- return false;
- }
-
- String modelID = dependency.getLocation("").getSource().getModelId(); //$NON-NLS-1$
- Model model = facade.getMavenProject().getModel();
- String thisModelID = toModelID(model.getGroupId(), model.getArtifactId(), model.getVersion());
-
- return (!thisModelID.equals(modelID));
- }
- public static String toModelID(String groupId, String artifactId, String version) {
- /*
- * Copied straight from package org.apache.maven.model.building.ModelProblemUtils.toId()
- * TODO Remove this method when those methods are made public
- */
- StringBuilder buffer = new StringBuilder( 96 );
-
- buffer.append( ( groupId != null && groupId.length() > 0 ) ? groupId : "[unknown-group-id]" ); //$NON-NLS-1$
- buffer.append( ':' );
- buffer.append( ( artifactId != null && artifactId.length() > 0 ) ? artifactId : "[unknown-artifact-id]" ); //$NON-NLS-1$
- buffer.append( ':' );
- buffer.append( ( version != null && version.length() > 0 ) ? version : "[unknown-version]" ); //$NON-NLS-1$
-
- return buffer.toString();
- }
-
public Color getBackground(Object element) {
return null;
}
@@ -157,11 +98,8 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
Dependency dependency = (Dependency) element;
return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
} else if (element instanceof org.apache.maven.model.Dependency) {
- org.apache.maven.model.Dependency dependency = (org.apache.maven.model.Dependency) element;
- if (isInherited(dependency)) {
- return MavenEditorImages.IMG_INHERITED;
- }
- return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
+ //mkleint: all MavenDependency instances are inherited
+ return MavenEditorImages.IMG_INHERITED;
}else if(element instanceof Exclusion) {
Exclusion exclusion = (Exclusion) element;
return getImage(exclusion.getGroupId(), exclusion.getArtifactId(), null);
@@ -178,8 +116,7 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
// XXX need to handle version ranges
if((version == null || version.indexOf("${") > -1) && pomEditor != null) { //$NON-NLS-1$
- try {
- MavenProject mavenProject = pomEditor.readMavenProject(false, null);
+ MavenProject mavenProject = pomEditor.getMavenProject();
if(mavenProject != null) {
Artifact artifact = mavenProject.getArtifactMap().get(groupId + ":" + artifactId); //$NON-NLS-1$
if(artifact!=null) {
@@ -195,9 +132,6 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
}
}
}
- } catch(CoreException ex) {
- MavenLogger.log(ex);
- }
}
if(groupId != null && artifactId != null && version != null) {
@@ -241,9 +175,4 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
return s == null || s.trim().length() == 0;
}
- public void setFacade(IMavenProjectFacade facade) {
- this.facade = facade;
- }
-
-
}
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ManageDependencyLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ManageDependencyLabelProvider.java
deleted file mode 100644
index 15556e45..00000000
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ManageDependencyLabelProvider.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.eclipse.m2e.editor.composites;
-
-import org.eclipse.swt.graphics.Color;
-
-public class ManageDependencyLabelProvider extends DependencyLabelProvider {
- @Override
- public Color getForeground(Object element) {
- /*
- * Super class shows scope=compile dependencies as greyed out, which we
- * don't want to do here.
- */
- return null;
- }
-}
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
index f6e44cde..1213bf19 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
@@ -41,8 +41,8 @@ import org.eclipse.m2e.core.core.MavenLogger;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.dialogs.AbstractMavenDialog;
import org.eclipse.m2e.editor.MavenEditorPlugin;
+import org.eclipse.m2e.editor.composites.DependencyLabelProvider;
import org.eclipse.m2e.editor.composites.ListEditorContentProvider;
-import org.eclipse.m2e.editor.composites.ManageDependencyLabelProvider;
import org.eclipse.m2e.model.edit.pom.Dependency;
import org.eclipse.m2e.model.edit.pom.DependencyManagement;
import org.eclipse.m2e.model.edit.pom.Model;
@@ -195,7 +195,7 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
*/
dependenciesViewer = new TableViewer(dependenciesTable);
- dependenciesViewer.setLabelProvider(new ManageDependencyLabelProvider());
+ dependenciesViewer.setLabelProvider(new DependencyLabelProvider());
dependenciesViewer.setContentProvider(new ListEditorContentProvider<Dependency>());
//MNGECLIPSE-2675 only show the dependencies not already managed (decide just by absence of the version element
List<Dependency> deps = model.getDependencies();

Back to the top