mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Added methods to create and convert to
default standard make C and C++ projects from simple projects such as when checking out new code "as a project" from CVS
This commit is contained in:
parent
b725003bc8
commit
e8a221b7de
1 changed files with 145 additions and 1 deletions
|
@ -13,8 +13,8 @@ import org.eclipse.cdt.core.index.IndexModel;
|
|||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.internal.core.CProjectDescriptor;
|
||||
import org.eclipse.cdt.internal.core.model.CProject;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -22,9 +22,13 @@ import org.eclipse.core.runtime.IConfigurationElement;
|
|||
import org.eclipse.core.runtime.IExtension;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IPluginDescriptor;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
|
||||
|
||||
public class CCorePlugin extends Plugin {
|
||||
|
@ -151,4 +155,144 @@ public class CCorePlugin extends Plugin {
|
|||
public void mapCProjectOwner(IProject project, String id) throws CoreException {
|
||||
CProjectDescriptor.configure(project, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a C project resource given the project handle and description.
|
||||
*
|
||||
* @param description the project description to create a project resource for
|
||||
* @param projectHandle the project handle to create a project resource for
|
||||
* @param monitor the progress monitor to show visual progress with
|
||||
* @param projectID required for mapping the project to an owner
|
||||
*
|
||||
* @exception CoreException if the operation fails
|
||||
* @exception OperationCanceledException if the operation is canceled
|
||||
*/
|
||||
public IProject createCProject(IProjectDescription description, IProject projectHandle,
|
||||
IProgressMonitor monitor, String projectID) throws CoreException, OperationCanceledException {
|
||||
try {
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask("Creating C Project", 3);//$NON-NLS-1$
|
||||
if (!projectHandle.exists()){
|
||||
projectHandle.create(description, monitor);
|
||||
}
|
||||
|
||||
if (monitor.isCanceled()){
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
|
||||
// Open first.
|
||||
projectHandle.open(monitor);
|
||||
|
||||
// Add C Nature ... does not add duplicates
|
||||
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1));
|
||||
mapCProjectOwner(projectHandle, projectID);
|
||||
} finally {
|
||||
//monitor.done();
|
||||
}
|
||||
return projectHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method convertProjectFromCtoCC converts
|
||||
* a C Project to a C++ Project
|
||||
* The newProject MUST, not be null, already have a C Nature
|
||||
* && must NOT already have a C++ Nature
|
||||
*
|
||||
* @param projectHandle
|
||||
* @param monitor
|
||||
* @param projectID
|
||||
* @throws CoreException
|
||||
*/
|
||||
|
||||
public void convertProjectFromCtoCC(IProject projectHandle, IProgressMonitor monitor, String projectID)
|
||||
throws CoreException{
|
||||
if ((projectHandle != null)
|
||||
&& projectHandle.hasNature(CCProjectNature.C_NATURE_ID)
|
||||
&& !projectHandle.hasNature(CCProjectNature.CC_NATURE_ID)) {
|
||||
// Add C++ Nature ... does not add duplicates
|
||||
CCProjectNature.addCCNature(projectHandle, monitor);
|
||||
|
||||
if(projectID != null){
|
||||
mapCProjectOwner(projectHandle, projectID);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method convertProjectFromCtoCC converts
|
||||
* a C Project to a C++ Project
|
||||
* The newProject MUST, not be null, already have a C Nature
|
||||
* && must NOT already have a C++ Nature<br>
|
||||
* This method does not map the project to an owner and should only
|
||||
* be used when this mapping has already taken place.
|
||||
*
|
||||
* @param projectHandle
|
||||
* @param monitor
|
||||
* @throws CoreException
|
||||
*/
|
||||
|
||||
public void convertProjectFromCtoCC(IProject projectHandle, IProgressMonitor monitor)
|
||||
throws CoreException{
|
||||
|
||||
convertProjectFromCtoCC(projectHandle, monitor, null);
|
||||
}
|
||||
/**
|
||||
* Method addDefaultCBuilder adds the default C make builder
|
||||
* @param projectHandle
|
||||
* @param monitor
|
||||
* @exception CoreException
|
||||
*/
|
||||
public void addDefaultCBuilder( IProject projectHandle, IProgressMonitor monitor)
|
||||
throws CoreException{
|
||||
// Set the Default C Builder.
|
||||
CProjectNature.addCBuildSpec(projectHandle, monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to convert a project to a C nature
|
||||
* & default make builder
|
||||
* All checks should have been done externally
|
||||
* (as in the Conversion Wizards).
|
||||
* This method blindly does the conversion.
|
||||
*
|
||||
* @param project
|
||||
* @param String targetNature
|
||||
* @param monitor
|
||||
* @param projectID
|
||||
* @exception CoreException
|
||||
*/
|
||||
|
||||
public void convertProjectToC(IProject projectHandle, IProgressMonitor monitor, String projectID)
|
||||
throws CoreException{
|
||||
if ((projectHandle == null) || (monitor == null) || (projectID == null)){
|
||||
return;
|
||||
}
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProjectDescription description = workspace.newProjectDescription(projectHandle.getName());
|
||||
description.setLocation(projectHandle.getFullPath());
|
||||
createCProject(description, projectHandle, monitor, projectID);
|
||||
addDefaultCBuilder(projectHandle, monitor);
|
||||
}
|
||||
/**
|
||||
* Method to convert a project to a C++ nature
|
||||
* & default make builder, if it does not have one already
|
||||
*
|
||||
* @param project
|
||||
* @param String targetNature
|
||||
* @param monitor
|
||||
* @param projectID
|
||||
* @exception CoreException
|
||||
*/
|
||||
|
||||
public void convertProjectToCC(IProject projectHandle, IProgressMonitor monitor, String projectID)
|
||||
throws CoreException{
|
||||
if ((projectHandle == null) || (monitor == null) || (projectID == null)){
|
||||
return;
|
||||
}
|
||||
createCProject(projectHandle.getDescription(), projectHandle, monitor, projectID);
|
||||
// now add C++ nature
|
||||
convertProjectFromCtoCC(projectHandle, monitor);
|
||||
addDefaultCBuilder(projectHandle, monitor);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue