Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2012-07-18 11:16:59 -0400
committerFred Bricon2012-07-18 17:19:32 -0400
commit6f86bed29a2b5eb5ce1a740da733cd273d5afdf7 (patch)
tree3bd84a6f6b0d840882318914ef943f2c8bf128ee
parentf3fd90a9d1a82928a39f25c7287d51c47e33dc05 (diff)
downloadm2e-core-6f86bed29a2b5eb5ce1a740da733cd273d5afdf7.tar.gz
m2e-core-6f86bed29a2b5eb5ce1a740da733cd273d5afdf7.tar.xz
m2e-core-6f86bed29a2b5eb5ce1a740da733cd273d5afdf7.zip
385422 : Hide build dir in project explorer view
Adds a new "Maven build directory" filter in the project explorer view. The property tester doesn't force load the m2e plugins on startup so the build output directories won't be hidden until m2e has been initialized first. Manually refreshing the Project explorer view might then be necessary. The filter is disabled by default and needs to be enabled in the project explorer view menu : "Customize View..." > check "Maven build folder". Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.core.ui/plugin.properties3
-rw-r--r--org.eclipse.m2e.core.ui/plugin.xml27
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java32
3 files changed, 60 insertions, 2 deletions
diff --git a/org.eclipse.m2e.core.ui/plugin.properties b/org.eclipse.m2e.core.ui/plugin.properties
index 98629170..9a938846 100644
--- a/org.eclipse.m2e.core.ui/plugin.properties
+++ b/org.eclipse.m2e.core.ui/plugin.properties
@@ -110,3 +110,6 @@ extension-point.component.name = Maven Core Component Contributor
extension-point.changed.name = mavenProjectChangedListeners
extension-point.lifecycleMappingMetadataSource.name = Lifecycle Mapping Metadata Source
convert.to.maven.name=Convert to Maven Project
+
+m2.build.directory.filter.name=Maven build folder
+m2.build.directory.filter.description=Hides the Maven build folder \ No newline at end of file
diff --git a/org.eclipse.m2e.core.ui/plugin.xml b/org.eclipse.m2e.core.ui/plugin.xml
index 7bd68a42..63b0e382 100644
--- a/org.eclipse.m2e.core.ui/plugin.xml
+++ b/org.eclipse.m2e.core.ui/plugin.xml
@@ -342,7 +342,7 @@
id="org.eclipse.m2e.core.MavenPropertyTester"
class="org.eclipse.m2e.core.ui.internal.actions.MavenPropertyTester"
namespace="org.eclipse.m2e"
- properties="workspaceResulutionEnable,hasArtifactKey,hasProjectArtifactKey"
+ properties="workspaceResulutionEnable,hasArtifactKey,hasProjectArtifactKey,isBuildDirectory"
type="org.eclipse.core.runtime.IAdaptable"/>
<propertyTester
id="org.eclipse.m2e.core.MavenPropertyTester2"
@@ -562,4 +562,29 @@
</adapter>
</factory>
</extension>
+
+ <extension point="org.eclipse.ui.navigator.navigatorContent">
+ <commonFilter
+ description="%m2.build.directory.filter.description"
+ id="org.eclipse.m2e.ui.filter.hideMavenBuildDir"
+ name="%m2.build.directory.filter.name"
+ activeByDefault="false">
+ <filterExpression>
+ <and>
+ <adapt type="org.eclipse.core.resources.IFolder">
+ <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.m2e.core.maven2Nature"/>
+ <test property="org.eclipse.m2e.isBuildDirectory" />
+ </adapt>
+ </and>
+ </filterExpression>
+ </commonFilter>
+ </extension>
+ <extension point="org.eclipse.ui.navigator.viewer">
+ <viewerContentBinding
+ viewerId="org.eclipse.ui.navigator.ProjectExplorer">
+ <includes>
+ <contentExtension pattern="org.eclipse.m2e.ui.filter.hideMavenBuildDir"/>
+ </includes>
+ </viewerContentBinding>
+ </extension>
</plugin>
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java
index 0f69603f..f059183d 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java
@@ -12,9 +12,12 @@
package org.eclipse.m2e.core.ui.internal.actions;
import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.sonatype.aether.graph.DependencyNode;
@@ -22,6 +25,7 @@ import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
+import org.eclipse.m2e.core.project.MavenProjectUtils;
import org.eclipse.m2e.core.project.ResolverConfiguration;
/**
@@ -38,6 +42,8 @@ public class MavenPropertyTester extends PropertyTester {
private static final String HAS_PROJECT_ARTIFACT_KEY = "hasProjectArtifactKey"; //$NON-NLS-1$
private static final String HAS_ARTIFACT_KEY = "hasArtifactKey"; //$NON-NLS-1$
private static final String WORKSPACE_RESULUTION_ENABLE = "workspaceResulutionEnable"; //$NON-NLS-1$
+ private static final String IS_BUILD_DIRECTORY = "isBuildDirectory"; //$NON-NLS-1$
+ private static final String DEFAULT_BUILD_DIR = "target"; //$NON-NLS-1$
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (WORKSPACE_RESULUTION_ENABLE.equals(property)) {
@@ -60,7 +66,7 @@ public class MavenPropertyTester extends PropertyTester {
ArtifactKey ak = SelectionUtil.getType(receiver, ArtifactKey.class);
return ak != null;
}
-
+
if (HAS_PROJECT_ARTIFACT_KEY.equals(property)) {
ArtifactKey key = SelectionUtil.getType(receiver, ArtifactKey.class);
if(key != null) {
@@ -85,6 +91,30 @@ public class MavenPropertyTester extends PropertyTester {
}
}
+ if (IS_BUILD_DIRECTORY.equals(property)) {
+ if (receiver instanceof IFolder) {
+ IFolder folder = (IFolder) receiver;
+ IProject project = folder.getProject();
+ if(project != null) {
+ IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
+ //Lookup project facade in the cache registry to minimize UI locking
+ IMavenProjectFacade projectFacade = projectManager.create(project, new NullProgressMonitor());
+ IPath outputLocation;
+ if (projectFacade == null || projectFacade.getMavenProject() == null) {
+ //If the project facade has not been cached yet (ex. during workspace startup),
+ //fall back on the default value
+ outputLocation = new Path(DEFAULT_BUILD_DIR);
+ } else {
+ String buildDir = projectFacade.getMavenProject().getBuild().getDirectory();
+ outputLocation = MavenProjectUtils.getProjectRelativePath(project, buildDir);
+ }
+ if (outputLocation != null) {
+ return folder.equals(project.getFolder(outputLocation));
+ }
+ }
+ }
+ }
+
return false;
}

Back to the top