From 22cfa08f2696dd218296e949bc418907669ca60a Mon Sep 17 00:00:00 2001 From: Romain Bioteau Date: Fri, 8 Dec 2023 09:05:33 +0100 Subject: [PATCH] fix(utils): Improve robustness in createFolder The `createFolder` util method should not throw an Exception when the folder already exists. A first step toward this behavior has been added with https://github.com/eclipse-m2e/m2e-core/commit/00ca0dfed8127cbbaae96e061f2e195f056e258d It looks however incomplete as I have a case in my integration of me where an ResourceException is thrown like below: ``` org.eclipse.core.internal.resources.ResourceException(/procurement-app/target)[374]: java.lang.Exception: Resource '/procurement-app/target' already exists. at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42) at org.eclipse.core.internal.resources.ResourceException.(ResourceException.java:38) at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:346) at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:333) at org.eclipse.core.internal.resources.Folder.assertCreateRequirements(Folder.java:40) at org.eclipse.core.internal.resources.Folder.create(Folder.java:101) at org.eclipse.core.internal.resources.Folder.create(Folder.java:129) at org.eclipse.m2e.core.internal.M2EUtils.createFolder(M2EUtils.java:61) at org.eclipse.m2e.core.project.configurator.AbstractLifecycleMapping.configure(AbstractLifecycleMapping.java:87) at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.lambda$6(ProjectConfigurationManager.java:504) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275) at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration(ProjectConfigurationManager.java:498) at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.configureNewMavenProjects(ProjectConfigurationManager.java:279) at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.lambda$1(ProjectConfigurationManager.java:166) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275) at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:214) at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:139) at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:130) ``` `374` is the code status for `PATH_OCCUPIED` which is used [here](https://github.com/eclipse-platform/eclipse.platform/blob/master/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Resource.java#L345) Also ignoring this status should improve robustness. Signed-off-by: Romain Bioteau --- .../src/org/eclipse/m2e/core/internal/M2EUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 3fb33d41cb..a7cb66a7f5 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 @@ -61,7 +61,8 @@ public static void createFolder(IFolder folder, boolean derived, IProgressMonito } } catch(CoreException ex) { //Don't fail if the resource already exists, in case of a race condition - if(ex.getStatus().getCode() != IResourceStatus.RESOURCE_EXISTS) { + int code = ex.getStatus().getCode(); + if(code != IResourceStatus.RESOURCE_EXISTS && code != IResourceStatus.PATH_OCCUPIED) { throw ex; } }