From 08693047c5235f3c17ec080dfa46efef226bc16d Mon Sep 17 00:00:00 2001 From: Umair Sair Date: Tue, 2 May 2023 21:15:35 +0500 Subject: [PATCH] Headless importAll fails with error importAll fails with error 'Project: .org.eclipse.egit.core.cmp already exists in the workspace!' and no further projects are imported. The fix is to not go into special directories .metadata and .org.eclipse.egit.core.cmp. Moreover, importAll and removeAll do not fail immediately if operation on a project fails, instead it keeps on performing operation on all projects and at the end, headless builder returns with error code if operation of any project failed --- .../internal/core/HeadlessBuilder.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java index b630186246a..b4c5e7e7246 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/HeadlessBuilder.java @@ -209,6 +209,8 @@ public class HeadlessBuilder implements IApplication { public static final Integer OK = IApplication.EXIT_OK; /** Show usage return status */ public static final Integer SHOW_USAGE = 2; + /** Directory names which should not be considered as projects */ + private static final Set SPECIAL_DIRS = Set.of(".metadata", ".org.eclipse.egit.core.cmp"); //$NON-NLS-1$ //$NON-NLS-2$ /** Set of project URIs / paths to remove */ protected final Set projectsToRemove = new HashSet<>(); @@ -343,6 +345,8 @@ public class HeadlessBuilder implements IApplication { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProgressMonitor monitor = new PrintingProgressMonitor(verboseProgressMonitor); InputStream in = null; + // Recursive import failure will be recorded in recurseStatus and recurse will not stop + int recurseStatus = OK; try { URI project_uri = null; try { @@ -369,6 +373,10 @@ public class HeadlessBuilder implements IApplication { } } + // do not go into special directories + if (SPECIAL_DIRS.contains(EFS.getStore(project_uri).fetchInfo().getName())) + return OK; + if (recurse) { if (!EFS.getStore(project_uri).fetchInfo().exists()) { System.err.println(HeadlessBuildMessages.HeadlessBuilder_Directory + project_uri @@ -380,7 +388,7 @@ public class HeadlessBuilder implements IApplication { continue; int status = importProject(info.toURI().toString(), recurse); if (status != OK) - return status; + recurseStatus = status; } } @@ -392,8 +400,8 @@ public class HeadlessBuilder implements IApplication { + HeadlessBuildMessages.HeadlessBuilder_cant_be_found); return ERROR; } - // .project not found; OK if we're not recursing - return OK; + // .project not found; return resurseStatus + return recurseStatus; } in = fstore.openInputStream(EFS.NONE, monitor); @@ -405,7 +413,7 @@ public class HeadlessBuilder implements IApplication { // It's ok if the project we're importing is the same as one already in the workspace if (URIUtil.equals(project.getLocationURI(), project_uri)) { project.open(monitor); - return OK; + return recurseStatus; } System.err.println(HeadlessBuildMessages.HeadlessBuilder_project + desc.getName() + HeadlessBuildMessages.HeadlessBuilder_already_exists_in_workspace); @@ -436,7 +444,7 @@ public class HeadlessBuilder implements IApplication { } catch (IOException e2) { /* don't care */ } } - return OK; + return recurseStatus; } /** @@ -449,6 +457,8 @@ public class HeadlessBuilder implements IApplication { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProgressMonitor monitor = new PrintingProgressMonitor(true); InputStream in = null; + // Recursive remove failure will be recorded in recurseStatus and recurse will not stop + int recurseStatus = OK; try { URI project_uri = null; try { @@ -475,6 +485,10 @@ public class HeadlessBuilder implements IApplication { } } + // do not go into special directories + if (SPECIAL_DIRS.contains(EFS.getStore(project_uri).fetchInfo().getName())) + return OK; + if (recurse) { if (!EFS.getStore(project_uri).fetchInfo().exists()) { System.err.println(HeadlessBuildMessages.HeadlessBuilder_Directory + project_uri @@ -486,7 +500,7 @@ public class HeadlessBuilder implements IApplication { continue; int status = removeProject(info.toURI().toString(), recurse); if (status != OK) - return status; + recurseStatus = status; } } @@ -498,8 +512,8 @@ public class HeadlessBuilder implements IApplication { + HeadlessBuildMessages.HeadlessBuilder_cant_be_found); return ERROR; } - // .project not found; OK if we're not recursing - return OK; + // .project not found; return recurseStatus + return recurseStatus; } in = fstore.openInputStream(EFS.NONE, monitor); @@ -512,7 +526,7 @@ public class HeadlessBuilder implements IApplication { project.close(monitor); } project.delete(false, true, monitor); - return OK; + return recurseStatus; } } finally { try { @@ -521,7 +535,7 @@ public class HeadlessBuilder implements IApplication { } catch (IOException e2) { /* don't care */ } } - return OK; + return recurseStatus; } protected boolean isProjectSuccesfullyBuild(IProject project) {