mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 573512: Added parameter for removing projects from workspace.
This is command line option to -remove and -removeAll projects from the workspace. Change-Id: Ice4e7db3485d2a0c698f48dc2aa0662170289f36
This commit is contained in:
parent
78b9b1e16c
commit
8b385ffc1f
3 changed files with 122 additions and 7 deletions
|
@ -18,6 +18,7 @@
|
||||||
* R. Zulliger, C. Walther (Indel AG) - Bug 355609 Disable indexer
|
* R. Zulliger, C. Walther (Indel AG) - Bug 355609 Disable indexer
|
||||||
* John Dallaway - Bug 513763 Save workspace on conclusion
|
* John Dallaway - Bug 513763 Save workspace on conclusion
|
||||||
* Torbjörn Svensson (STMicroelectronics) - bug #330204
|
* Torbjörn Svensson (STMicroelectronics) - bug #330204
|
||||||
|
* Marc Siebenhaar (top-logic.com) - Bug #573512
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.managedbuilder.internal.core;
|
package org.eclipse.cdt.managedbuilder.internal.core;
|
||||||
|
@ -84,6 +85,8 @@ import org.eclipse.osgi.service.datalocation.Location;
|
||||||
*
|
*
|
||||||
* IApplication ID: org.eclipse.cdt.managedbuilder.core.headlessbuild
|
* IApplication ID: org.eclipse.cdt.managedbuilder.core.headlessbuild
|
||||||
* Provides:
|
* Provides:
|
||||||
|
* - Remove projects from workspace : -remove {[uri:/]/path/to/project}
|
||||||
|
* - Remove all projects in the tree : -removeAll {[uri:/]/path/to/projectTreeURI}
|
||||||
* - Import projects : -import {[uri:/]/path/to/project}
|
* - Import projects : -import {[uri:/]/path/to/project}
|
||||||
* - Import all projects in the tree : -importAll {[uri:/]/path/to/projectTreeURI}
|
* - Import all projects in the tree : -importAll {[uri:/]/path/to/projectTreeURI}
|
||||||
* - Build projects / the workspace : -build {project_name_reg_ex/config_name_reg_ex | all}
|
* - Build projects / the workspace : -build {project_name_reg_ex/config_name_reg_ex | all}
|
||||||
|
@ -177,6 +180,10 @@ public class HeadlessBuilder implements IApplication {
|
||||||
/** Show usage return status */
|
/** Show usage return status */
|
||||||
public static final Integer SHOW_USAGE = 2;
|
public static final Integer SHOW_USAGE = 2;
|
||||||
|
|
||||||
|
/** Set of project URIs / paths to remove */
|
||||||
|
protected final Set<String> projectsToRemove = new HashSet<>();
|
||||||
|
/** Tree of projects to recursively remove */
|
||||||
|
protected final Set<String> projectTreeToRemove = new HashSet<>();
|
||||||
/** Set of project URIs / paths to import */
|
/** Set of project URIs / paths to import */
|
||||||
protected final Set<String> projectsToImport = new HashSet<>();
|
protected final Set<String> projectsToImport = new HashSet<>();
|
||||||
/** Tree of projects to recursively import */
|
/** Tree of projects to recursively import */
|
||||||
|
@ -401,6 +408,91 @@ public class HeadlessBuilder implements IApplication {
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close and remove a project from the workspace
|
||||||
|
* @param projURIStr base URI string
|
||||||
|
* @param recurse should we recurse down the URI removing all projects?
|
||||||
|
* @return int OK / ERROR
|
||||||
|
*/
|
||||||
|
protected int removeProject(String projURIStr, boolean recurse) throws CoreException {
|
||||||
|
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
IProgressMonitor monitor = new PrintingProgressMonitor();
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
URI project_uri = null;
|
||||||
|
try {
|
||||||
|
project_uri = URI.create(projURIStr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Will be treated as straightforward path in the case below
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle local paths as well
|
||||||
|
if (project_uri == null || project_uri.getScheme() == null) {
|
||||||
|
IPath p = new Path(projURIStr).addTrailingSeparator();
|
||||||
|
project_uri = URIUtil.toURI(p);
|
||||||
|
|
||||||
|
// Handle relative paths as relative to cwd
|
||||||
|
if (project_uri.getScheme() == null) {
|
||||||
|
String cwd = System.getProperty("user.dir"); //$NON-NLS-1$
|
||||||
|
p = new Path(cwd).addTrailingSeparator();
|
||||||
|
p = p.append(projURIStr);
|
||||||
|
project_uri = URIUtil.toURI(p);
|
||||||
|
}
|
||||||
|
if (project_uri.getScheme() == null) {
|
||||||
|
System.err.println(HeadlessBuildMessages.HeadlessBuilder_invalid_uri + project_uri);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recurse) {
|
||||||
|
if (!EFS.getStore(project_uri).fetchInfo().exists()) {
|
||||||
|
System.err.println(HeadlessBuildMessages.HeadlessBuilder_Directory + project_uri
|
||||||
|
+ HeadlessBuildMessages.HeadlessBuilder_cant_be_found);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
for (IFileStore info : EFS.getStore(project_uri).childStores(EFS.NONE, monitor)) {
|
||||||
|
if (!info.fetchInfo().isDirectory())
|
||||||
|
continue;
|
||||||
|
int status = removeProject(info.toURI().toString(), recurse);
|
||||||
|
if (status != OK)
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the project description
|
||||||
|
IFileStore fstore = EFS.getStore(project_uri).getChild(".project"); //$NON-NLS-1$
|
||||||
|
if (!fstore.fetchInfo().exists()) {
|
||||||
|
if (!recurse) {
|
||||||
|
System.err.println(HeadlessBuildMessages.HeadlessBuilder_project + project_uri
|
||||||
|
+ HeadlessBuildMessages.HeadlessBuilder_cant_be_found);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
// .project not found; OK if we're not recursing
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
in = fstore.openInputStream(EFS.NONE, monitor);
|
||||||
|
IProjectDescription desc = root.getWorkspace().loadProjectDescription(in);
|
||||||
|
|
||||||
|
// Check that a project with the name exist in the workspace, then close and remove the project gently from workspace
|
||||||
|
IProject project = root.getProject(desc.getName());
|
||||||
|
if (project.exists()) {
|
||||||
|
if (project.isOpen()) {
|
||||||
|
project.close(monitor);
|
||||||
|
}
|
||||||
|
project.delete(false, true, monitor);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (in != null)
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e2) {
|
||||||
|
/* don't care */ }
|
||||||
|
}
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean isProjectSuccesfullyBuild(IProject project) {
|
protected boolean isProjectSuccesfullyBuild(IProject project) {
|
||||||
try {
|
try {
|
||||||
for (String markerType : markerTypes) {
|
for (String markerType : markerTypes) {
|
||||||
|
@ -491,17 +583,32 @@ public class HeadlessBuilder implements IApplication {
|
||||||
if (System.getProperty("org.eclipse.cdt.core.console") == null) //$NON-NLS-1$
|
if (System.getProperty("org.eclipse.cdt.core.console") == null) //$NON-NLS-1$
|
||||||
System.setProperty("org.eclipse.cdt.core.console", "org.eclipse.cdt.core.systemConsole"); //$NON-NLS-1$ //$NON-NLS-2$
|
System.setProperty("org.eclipse.cdt.core.console", "org.eclipse.cdt.core.systemConsole"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
/*
|
// Perform the import of list of project trees
|
||||||
* Perform the project import
|
projectTreeToImport.removeAll(projectTreeToRemove);
|
||||||
*/
|
for (String projURIStr : projectTreeToImport) {
|
||||||
// Import any projects that need importing
|
int status = importProject(projURIStr, true);
|
||||||
|
if (status != OK)
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the removal of list of project trees
|
||||||
|
for (String projURIStr : projectTreeToRemove) {
|
||||||
|
int status = removeProject(projURIStr, true);
|
||||||
|
if (status != OK)
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the import of list of single projects
|
||||||
|
projectsToImport.removeAll(projectsToRemove);
|
||||||
for (String projURIStr : projectsToImport) {
|
for (String projURIStr : projectsToImport) {
|
||||||
int status = importProject(projURIStr, false);
|
int status = importProject(projURIStr, false);
|
||||||
if (status != OK)
|
if (status != OK)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
for (String projURIStr : projectTreeToImport) {
|
|
||||||
int status = importProject(projURIStr, true);
|
// Perform the removal of list of single projects
|
||||||
|
for (String projURIStr : projectsToRemove) {
|
||||||
|
int status = removeProject(projURIStr, false);
|
||||||
if (status != OK)
|
if (status != OK)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -648,6 +755,8 @@ public class HeadlessBuilder implements IApplication {
|
||||||
* Helper method to process expected arguments
|
* Helper method to process expected arguments
|
||||||
*
|
*
|
||||||
* Arguments
|
* Arguments
|
||||||
|
* -remove {[uri:/]/path/to/project}
|
||||||
|
* -removeAll {[uri:/]/path/to/projectTreeURI} Remove all projects in the tree
|
||||||
* -import {[uri:/]/path/to/project}
|
* -import {[uri:/]/path/to/project}
|
||||||
* -importAll {[uri:/]/path/to/projectTreeURI} Import all projects in the tree
|
* -importAll {[uri:/]/path/to/projectTreeURI} Import all projects in the tree
|
||||||
* -build {project_name_reg_ex/config_name_reg_ex | all}
|
* -build {project_name_reg_ex/config_name_reg_ex | all}
|
||||||
|
@ -678,6 +787,10 @@ public class HeadlessBuilder implements IApplication {
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if ("-help".equals(args[i])) { //$NON-NLS-1$
|
if ("-help".equals(args[i])) { //$NON-NLS-1$
|
||||||
throw new Exception(HeadlessBuildMessages.HeadlessBuilder_help_requested);
|
throw new Exception(HeadlessBuildMessages.HeadlessBuilder_help_requested);
|
||||||
|
} else if ("-remove".equals(args[i])) { //$NON-NLS-1$
|
||||||
|
projectsToRemove.add(args[++i]);
|
||||||
|
} else if ("-removeAll".equals(args[i])) { //$NON-NLS-1$
|
||||||
|
projectTreeToRemove.add(args[++i]);
|
||||||
} else if ("-import".equals(args[i])) { //$NON-NLS-1$
|
} else if ("-import".equals(args[i])) { //$NON-NLS-1$
|
||||||
projectsToImport.add(args[++i]);
|
projectsToImport.add(args[++i]);
|
||||||
} else if ("-importAll".equals(args[i])) { //$NON-NLS-1$
|
} else if ("-importAll".equals(args[i])) { //$NON-NLS-1$
|
||||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.headlessbuilderapp;singleton:=true
|
Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.headlessbuilderapp;singleton:=true
|
||||||
Bundle-Version: 1.0.0.qualifier
|
Bundle-Version: 1.0.100.qualifier
|
||||||
Bundle-Vendor: %providerName
|
Bundle-Vendor: %providerName
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
CommandLineUsage=Usage: {0} -data <workspace> -application org.eclipse.cdt.managedbuilder.core.headlessbuild [ OPTIONS ]\n\
|
CommandLineUsage=Usage: {0} -data <workspace> -application org.eclipse.cdt.managedbuilder.core.headlessbuild [ OPTIONS ]\n\
|
||||||
'\n\
|
'\n\
|
||||||
\ -data {/path/to/workspace}\n\
|
\ -data {/path/to/workspace}\n\
|
||||||
|
\ -remove {[uri:/]/path/to/project}\n\
|
||||||
|
\ -removeAll {[uri:/]/path/to/projectTreeURI} Remove all projects under URI\n\
|
||||||
\ -import {[uri:/]/path/to/project}\n\
|
\ -import {[uri:/]/path/to/project}\n\
|
||||||
\ -importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI\n\
|
\ -importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI\n\
|
||||||
\ -build {project_name_reg_ex{/config_reg_ex} | all}\n\
|
\ -build {project_name_reg_ex{/config_reg_ex} | all}\n\
|
||||||
|
|
Loading…
Add table
Reference in a new issue