Skip to content

Commit

Permalink
Headless importAll fails with error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
umairsair authored and jonahgraham committed May 3, 2023
1 parent 7cd76ee commit 0869304
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public boolean equals(Object obj) {
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<String> 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<String> projectsToRemove = new HashSet<>();
Expand Down Expand Up @@ -343,6 +345,8 @@ protected int importProject(String projURIStr, boolean recurse) throws CoreExcep
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 {
Expand All @@ -369,6 +373,10 @@ protected int importProject(String projURIStr, boolean recurse) throws CoreExcep
}
}

// 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
Expand All @@ -380,7 +388,7 @@ protected int importProject(String projURIStr, boolean recurse) throws CoreExcep
continue;
int status = importProject(info.toURI().toString(), recurse);
if (status != OK)
return status;
recurseStatus = status;
}
}

Expand All @@ -392,8 +400,8 @@ protected int importProject(String projURIStr, boolean recurse) throws CoreExcep
+ 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);
Expand All @@ -405,7 +413,7 @@ protected int importProject(String projURIStr, boolean recurse) throws CoreExcep
// 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);
Expand Down Expand Up @@ -436,7 +444,7 @@ protected int importProject(String projURIStr, boolean recurse) throws CoreExcep
} catch (IOException e2) {
/* don't care */ }
}
return OK;
return recurseStatus;
}

/**
Expand All @@ -449,6 +457,8 @@ protected int removeProject(String projURIStr, boolean recurse) throws CoreExcep
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 {
Expand All @@ -475,6 +485,10 @@ protected int removeProject(String projURIStr, boolean recurse) throws CoreExcep
}
}

// 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
Expand All @@ -486,7 +500,7 @@ protected int removeProject(String projURIStr, boolean recurse) throws CoreExcep
continue;
int status = removeProject(info.toURI().toString(), recurse);
if (status != OK)
return status;
recurseStatus = status;
}
}

Expand All @@ -498,8 +512,8 @@ protected int removeProject(String projURIStr, boolean recurse) throws CoreExcep
+ 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);
Expand All @@ -512,7 +526,7 @@ protected int removeProject(String projURIStr, boolean recurse) throws CoreExcep
project.close(monitor);
}
project.delete(false, true, monitor);
return OK;
return recurseStatus;
}
} finally {
try {
Expand All @@ -521,7 +535,7 @@ protected int removeProject(String projURIStr, boolean recurse) throws CoreExcep
} catch (IOException e2) {
/* don't care */ }
}
return OK;
return recurseStatus;
}

protected boolean isProjectSuccesfullyBuild(IProject project) {
Expand Down

0 comments on commit 0869304

Please sign in to comment.