mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 17:55:39 +02:00
Bug 309909 Headless build import should treat relative paths as relative to the cwd
Verify that the Workspace isn't already locked, as done by IDEApplication, to prevent unsafe shared access to one workspace by multiple Eclipse instances.
This commit is contained in:
parent
f210a17908
commit
3660472c4c
3 changed files with 61 additions and 1 deletions
|
@ -20,12 +20,14 @@ public class HeadlessBuildMessages extends NLS {
|
||||||
public static String HeadlessBuilder_cant_be_found;
|
public static String HeadlessBuilder_cant_be_found;
|
||||||
public static String HeadlessBuilder_clean_failed;
|
public static String HeadlessBuilder_clean_failed;
|
||||||
public static String HeadlessBuilder_cleaning_all_projects;
|
public static String HeadlessBuilder_cleaning_all_projects;
|
||||||
|
public static String HeadlessBuilder_CouldntLockWorkspace;
|
||||||
public static String HeadlessBuilder_Directory;
|
public static String HeadlessBuilder_Directory;
|
||||||
public static String HeadlessBuilder_Error;
|
public static String HeadlessBuilder_Error;
|
||||||
public static String HeadlessBuilder_importAll;
|
public static String HeadlessBuilder_importAll;
|
||||||
public static String HeadlessBuilder_invalid_argument;
|
public static String HeadlessBuilder_invalid_argument;
|
||||||
public static String HeadlessBuilder_is_not_accessible;
|
public static String HeadlessBuilder_is_not_accessible;
|
||||||
public static String HeadlessBuilder_is_not_valid_in_workspace;
|
public static String HeadlessBuilder_is_not_valid_in_workspace;
|
||||||
|
public static String HeadlessBuilder_MustSpecifyWorkspace;
|
||||||
public static String HeadlessBuilder_no_arguments;
|
public static String HeadlessBuilder_no_arguments;
|
||||||
public static String HeadlessBuilder_NoConfigMatched;
|
public static String HeadlessBuilder_NoConfigMatched;
|
||||||
public static String HeadlessBuilder_NoProjectMatched;
|
public static String HeadlessBuilder_NoProjectMatched;
|
||||||
|
@ -40,8 +42,10 @@ public class HeadlessBuildMessages extends NLS {
|
||||||
public static String HeadlessBuilder_usage;
|
public static String HeadlessBuilder_usage;
|
||||||
public static String HeadlessBuilder_usage_build;
|
public static String HeadlessBuilder_usage_build;
|
||||||
public static String HeadlessBuilder_usage_clean_build;
|
public static String HeadlessBuilder_usage_clean_build;
|
||||||
|
public static String HeadlessBuilder_invalid_uri;
|
||||||
public static String HeadlessBuilder_usage_import;
|
public static String HeadlessBuilder_usage_import;
|
||||||
public static String HeadlessBuilder_Workspace;
|
public static String HeadlessBuilder_Workspace;
|
||||||
|
public static String HeadlessBuilder_WorkspaceInUse;
|
||||||
static {
|
static {
|
||||||
// initialize resource bundle
|
// initialize resource bundle
|
||||||
NLS.initializeMessages(BUNDLE_NAME, HeadlessBuildMessages.class);
|
NLS.initializeMessages(BUNDLE_NAME, HeadlessBuildMessages.class);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Broadcom Corporation - initial API and implementation
|
* Broadcom Corporation - initial API and implementation
|
||||||
* Clare Richardson (Motorola) - Bug 281397 building specific configs
|
* Clare Richardson (Motorola) - Bug 281397 building specific configs
|
||||||
|
* Dmitry Kozlov (CodeSourcery) - Bug 309909 Headless build import fails
|
||||||
|
* silently with relative pathname
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.managedbuilder.internal.core;
|
package org.eclipse.cdt.managedbuilder.internal.core;
|
||||||
|
@ -46,11 +48,13 @@ import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.equinox.app.IApplication;
|
import org.eclipse.equinox.app.IApplication;
|
||||||
import org.eclipse.equinox.app.IApplicationContext;
|
import org.eclipse.equinox.app.IApplicationContext;
|
||||||
|
import org.eclipse.osgi.service.datalocation.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A headless builder for CDT with additional features.
|
* A headless builder for CDT with additional features.
|
||||||
|
@ -58,7 +62,7 @@ import org.eclipse.equinox.app.IApplicationContext;
|
||||||
* IApplication ID: org.eclipse.cdt.managedbuilder.core.headlessbuild
|
* IApplication ID: org.eclipse.cdt.managedbuilder.core.headlessbuild
|
||||||
* Provides:
|
* Provides:
|
||||||
* - 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}
|
||||||
* - Clean build projects / the workspace : -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
|
* - Clean build projects / the workspace : -cleanBuild {project_name_reg_ex/config_name_reg_ex | all}
|
||||||
*
|
*
|
||||||
|
@ -218,6 +222,18 @@ public class HeadlessBuilder implements IApplication {
|
||||||
if (project_uri == null || project_uri.getScheme() == null) {
|
if (project_uri == null || project_uri.getScheme() == null) {
|
||||||
IPath p = new Path(projURIStr).addTrailingSeparator();
|
IPath p = new Path(projURIStr).addTrailingSeparator();
|
||||||
project_uri = URIUtil.toURI(p);
|
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 (recurse) {
|
||||||
|
@ -285,6 +301,10 @@ public class HeadlessBuilder implements IApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object start(IApplicationContext context) throws Exception {
|
public Object start(IApplicationContext context) throws Exception {
|
||||||
|
// Check its OK to use this workspace as IDEApplication does
|
||||||
|
if (!checkInstanceLocation())
|
||||||
|
return ERROR;
|
||||||
|
|
||||||
IProgressMonitor monitor = new PrintingProgressMonitor();
|
IProgressMonitor monitor = new PrintingProgressMonitor();
|
||||||
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
|
||||||
|
@ -384,6 +404,38 @@ public class HeadlessBuilder implements IApplication {
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify that it's safe to use the specified workspace. i.e. that
|
||||||
|
* we can write to it and that it's not already locked / in-use.
|
||||||
|
*
|
||||||
|
* Return true if a valid workspace path has been set and false otherwise.
|
||||||
|
*
|
||||||
|
* @return true if a valid instance location has been set and false
|
||||||
|
* otherwise
|
||||||
|
*/
|
||||||
|
private boolean checkInstanceLocation() {
|
||||||
|
// -data @none was specified but an ide requires workspace
|
||||||
|
Location instanceLoc = Platform.getInstanceLocation();
|
||||||
|
if (instanceLoc == null || !instanceLoc.isSet()) {
|
||||||
|
System.err.println(HeadlessBuildMessages.HeadlessBuilder_MustSpecifyWorkspace);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -data "/valid/path", workspace already set
|
||||||
|
try {
|
||||||
|
// at this point its valid, so try to lock it to prevent concurrent use
|
||||||
|
if (!instanceLoc.lock()) {
|
||||||
|
System.err.println(HeadlessBuildMessages.HeadlessBuilder_WorkspaceInUse);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(HeadlessBuildMessages.HeadlessBuilder_CouldntLockWorkspace);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to process expected arguments
|
* Helper method to process expected arguments
|
||||||
*
|
*
|
||||||
|
|
|
@ -166,6 +166,7 @@ HeadlessBuilder_building_all=Building All Projects...
|
||||||
HeadlessBuilder_cant_be_found=\ can't be found\!
|
HeadlessBuilder_cant_be_found=\ can't be found\!
|
||||||
HeadlessBuilder_clean_failed=Couldn't CLEAN project
|
HeadlessBuilder_clean_failed=Couldn't CLEAN project
|
||||||
HeadlessBuilder_cleaning_all_projects=Cleaning All Projects...
|
HeadlessBuilder_cleaning_all_projects=Cleaning All Projects...
|
||||||
|
HeadlessBuilder_CouldntLockWorkspace=Could not obtain lock for workspace location
|
||||||
HeadlessBuilder_Directory=Directory:
|
HeadlessBuilder_Directory=Directory:
|
||||||
HeadlessBuilder_Error=Error:
|
HeadlessBuilder_Error=Error:
|
||||||
HeadlessBuilder_invalid_argument=Invalid Arguments:
|
HeadlessBuilder_invalid_argument=Invalid Arguments:
|
||||||
|
@ -187,7 +188,10 @@ HeadlessBuilder_usage_build=\ \ \ -build {project_name_reg_ex{/config_reg_e
|
||||||
HeadlessBuilder_usage_clean_build=\ \ \ -cleanBuild {project_name_reg_ex{/config_reg_ex} | all}
|
HeadlessBuilder_usage_clean_build=\ \ \ -cleanBuild {project_name_reg_ex{/config_reg_ex} | all}
|
||||||
HeadlessBuilder_usage_import=\ \ \ -import {[uri:/]/path/to/project}
|
HeadlessBuilder_usage_import=\ \ \ -import {[uri:/]/path/to/project}
|
||||||
HeadlessBuilder_importAll=\ \ \ -importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI
|
HeadlessBuilder_importAll=\ \ \ -importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI
|
||||||
|
HeadlessBuilder_invalid_uri=Invalid project URI:
|
||||||
|
HeadlessBuilder_MustSpecifyWorkspace=Must specify a location for the workspace. Restart with the '-data' switch.
|
||||||
HeadlessBuilder_Workspace=Workspace
|
HeadlessBuilder_Workspace=Workspace
|
||||||
|
HeadlessBuilder_WorkspaceInUse=Workspace already in use\!
|
||||||
|
|
||||||
MakeBuilder.buildError=
|
MakeBuilder.buildError=
|
||||||
MultiResourceInfo.MultiResourceInfo.UnhandledIHoldsOptionsType=Unhandled parent type: not ITool nor IToolChain
|
MultiResourceInfo.MultiResourceInfo.UnhandledIHoldsOptionsType=Unhandled parent type: not ITool nor IToolChain
|
||||||
|
|
Loading…
Add table
Reference in a new issue