Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-04-20 17:34:16 -0400
committerMatthew Piggott2011-04-20 17:35:22 -0400
commit6bac8880fd4f0dfb83de5f641929d9ff7f918665 (patch)
tree637a704c7d9cb89fdf55b84d1380db7dd90b6fe2
parentcd221a5336069559b6d764282b4a34393a8b2871 (diff)
downloadm2e-core-6bac8880fd4f0dfb83de5f641929d9ff7f918665.tar.gz
m2e-core-6bac8880fd4f0dfb83de5f641929d9ff7f918665.tar.xz
m2e-core-6bac8880fd4f0dfb83de5f641929d9ff7f918665.zip
Bug 336411 - Automatically mark target folder as derived
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java19
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java47
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java105
3 files changed, 112 insertions, 59 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java
index 39ce9339..e64a244c 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/M2EUtils.java
@@ -24,6 +24,8 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.apache.maven.model.Plugin;
@@ -40,20 +42,33 @@ public class M2EUtils {
* @param folder The folder to create.
* @param derived true if folder should be marked as derived
* @throws CoreException if creating the given <code>folder</code> or any of its parents fails.
+ * @deprecated use {@link #createFolder(IFolder, boolean, IProgressMonitor)}
*/
public static void createFolder(IFolder folder, boolean derived) throws CoreException {
+ createFolder(folder, derived, new NullProgressMonitor());
+ }
+
+ /**
+ * Helper method which creates a folder and, recursively, all its parent folders.
+ *
+ * @param folder The folder to create.
+ * @param derived true if folder should be marked as derived
+ * @param monitor the progress monitor
+ * @throws CoreException if creating the given <code>folder</code> or any of its parents fails.
+ */
+ public static void createFolder(IFolder folder, boolean derived, IProgressMonitor monitor) throws CoreException {
// Recurse until we find a parent folder which already exists.
if(!folder.exists()) {
IContainer parent = folder.getParent();
// First, make sure that all parent folders exist.
if(parent != null && !parent.exists()) {
- createFolder((IFolder) parent, false);
+ createFolder((IFolder) parent, false, monitor);
}
folder.create(true, true, null);
}
if(folder.isAccessible() && derived) {
- folder.setDerived(true);
+ folder.setDerived(true, monitor);
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java
index 2c7d15df..f457ee32 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/configurator/AbstractLifecycleMapping.java
@@ -11,11 +11,17 @@
package org.eclipse.m2e.core.project.configurator;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
+
+import org.apache.maven.model.Build;
import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.internal.M2EUtils;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
@@ -33,17 +39,40 @@ public abstract class AbstractLifecycleMapping implements ILifecycleMapping {
/**
* Calls #configure method of all registered project configurators
*/
- public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
- MavenPlugin.getProjectConfigurationManager()
- .addMavenBuilder(request.getProject(), null /*description*/, monitor);
-
- IMavenProjectFacade projectFacade = request.getMavenProjectFacade();
+ public void configure(ProjectConfigurationRequest request, IProgressMonitor mon) throws CoreException {
+ final SubMonitor monitor = SubMonitor.convert(mon, 5);
+ try {
+ MavenPlugin.getProjectConfigurationManager().addMavenBuilder(request.getProject(), null /*description*/,
+ monitor.newChild(1));
+
+ IMavenProjectFacade projectFacade = request.getMavenProjectFacade();
+ Build build = projectFacade.getMavenProject(monitor.newChild(1)).getBuild();
+ if(build != null) {
+ String directory = build.getDirectory();
+ if(directory != null) {
+ IContainer container = projectFacade.getProject().getFolder(projectFacade.getProjectRelativePath(directory));
+ if(container != null) {
+ if(!container.exists() && container instanceof IFolder) {
+ M2EUtils.createFolder((IFolder) container, true, monitor.newChild(1));
+ } else {
+ container.setDerived(true, monitor.newChild(1));
+ }
+ }
+ }
+ }
- for(AbstractProjectConfigurator configurator : getProjectConfigurators(projectFacade, monitor)) {
- if(monitor.isCanceled()) {
- throw new OperationCanceledException();
+ SubMonitor confMon = null;
+ for(AbstractProjectConfigurator configurator : getProjectConfigurators(projectFacade, monitor.newChild(1))) {
+ if(monitor.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+ if(confMon == null) {
+ confMon = monitor.newChild(1);
+ }
+ configurator.configure(request, confMon.newChild(1));
}
- configurator.configure(request, monitor);
+ } finally {
+ monitor.done();
}
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
index 4778a681..534e953d 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
@@ -30,6 +30,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -218,65 +219,73 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
protected void addProjectSourceFolders(IClasspathDescriptor classpath, ProjectConfigurationRequest request,
IProgressMonitor monitor) throws CoreException {
- IProject project = request.getProject();
- MavenProject mavenProject = request.getMavenProject();
- IMavenProjectFacade projectFacade = request.getMavenProjectFacade();
+ SubMonitor mon = SubMonitor.convert(monitor, 6);
+ try {
+ IProject project = request.getProject();
+ MavenProject mavenProject = request.getMavenProject();
+ IMavenProjectFacade projectFacade = request.getMavenProjectFacade();
- IFolder classes = getFolder(project, mavenProject.getBuild().getOutputDirectory());
- IFolder testClasses = getFolder(project, mavenProject.getBuild().getTestOutputDirectory());
+ IFolder classes = getFolder(project, mavenProject.getBuild().getOutputDirectory());
+ IFolder testClasses = getFolder(project, mavenProject.getBuild().getTestOutputDirectory());
- M2EUtils.createFolder(classes, true);
- M2EUtils.createFolder(testClasses, true);
+ M2EUtils.createFolder(classes, true, mon.newChild(1));
+ M2EUtils.createFolder(testClasses, true, mon.newChild(1));
- IPath[] inclusion = new IPath[0];
- IPath[] exclusion = new IPath[0];
+ IPath[] inclusion = new IPath[0];
+ IPath[] exclusion = new IPath[0];
- IPath[] inclusionTest = new IPath[0];
- IPath[] exclusionTest = new IPath[0];
-
- String mainSourceEncoding = null;
- String testSourceEncoding = null;
+ IPath[] inclusionTest = new IPath[0];
+ IPath[] exclusionTest = new IPath[0];
- MavenSession mavenSession = request.getMavenSession();
+ String mainSourceEncoding = null;
+ String testSourceEncoding = null;
- for(MojoExecution compile : projectFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID, COMPILER_PLUGIN_ARTIFACT_ID,
- monitor, GOAL_COMPILE)) {
- mainSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$
- try {
- inclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, "includes", String[].class)); //$NON-NLS-1$
- } catch(CoreException ex) {
- log.error("Failed to determine compiler inclusions, assuming defaults", ex);
- }
- try {
- exclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, "excludes", String[].class)); //$NON-NLS-1$
- } catch(CoreException ex) {
- log.error("Failed to determine compiler exclusions, assuming defaults", ex);
- }
- }
+ MavenSession mavenSession = request.getMavenSession();
- for(MojoExecution compile : projectFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID, COMPILER_PLUGIN_ARTIFACT_ID,
- monitor, GOAL_TESTCOMPILE)) {
- testSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$
- try {
- inclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile,
- "testIncludes", String[].class)); //$NON-NLS-1$
- } catch(CoreException ex) {
- log.error("Failed to determine compiler test inclusions, assuming defaults", ex);
+ for(MojoExecution compile : projectFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID,
+ COMPILER_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_COMPILE)) {
+ mainSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$
+ try {
+ inclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile,
+ "includes", String[].class)); //$NON-NLS-1$
+ } catch(CoreException ex) {
+ log.error("Failed to determine compiler inclusions, assuming defaults", ex);
+ }
+ try {
+ exclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile,
+ "excludes", String[].class)); //$NON-NLS-1$
+ } catch(CoreException ex) {
+ log.error("Failed to determine compiler exclusions, assuming defaults", ex);
+ }
}
- try {
- exclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile,
- "testExcludes", String[].class)); //$NON-NLS-1$
- } catch(CoreException ex) {
- log.error("Failed to determine compiler test exclusions, assuming defaults", ex);
+
+ for(MojoExecution compile : projectFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID,
+ COMPILER_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_TESTCOMPILE)) {
+ testSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$
+ try {
+ inclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile,
+ "testIncludes", String[].class)); //$NON-NLS-1$
+ } catch(CoreException ex) {
+ log.error("Failed to determine compiler test inclusions, assuming defaults", ex);
+ }
+ try {
+ exclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile,
+ "testExcludes", String[].class)); //$NON-NLS-1$
+ } catch(CoreException ex) {
+ log.error("Failed to determine compiler test exclusions, assuming defaults", ex);
+ }
}
- }
- addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion, exclusion, mainSourceEncoding, monitor);
- addResourceDirs(classpath, project, mavenProject.getBuild().getResources(), classes.getFullPath());
+ addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion,
+ exclusion, mainSourceEncoding, mon.newChild(1));
+ addResourceDirs(classpath, project, mavenProject.getBuild().getResources(), classes.getFullPath());
- addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(),
- inclusionTest, exclusionTest, testSourceEncoding, monitor);
- addResourceDirs(classpath, project, mavenProject.getBuild().getTestResources(), testClasses.getFullPath());
+ addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(),
+ inclusionTest, exclusionTest, testSourceEncoding, mon.newChild(1));
+ addResourceDirs(classpath, project, mavenProject.getBuild().getTestResources(), testClasses.getFullPath());
+ } finally {
+ mon.done();
+ }
}
private IPath[] toPaths(String[] values) {

Back to the top