Copy, clean and build automatically a C++ project

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Copy, clean and build automatically a C++ project

sim0s
Hi,

I am trying to duplicate a project, do some processing on the duplicated project and (clean &) build it automatically. I managed to write the code for duplicating a project (given below) but there are still some issues.

(i) .cproject file still has some remnant of the source project (Example instead of Example2)
    e.g., <builder buildPath="${workspace_loc:/Example}/Debug" id="cdt.managedbuild.target.gnu.builder.macosx.exe.debug.1434305598" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.exe.debug"/>

Do I need to change anything in project description? Am I missing any command?


(ii) clean and build the project automatically

I looked into the CCorePlugin and CoreModel classes but couldn't find any suitable.
Any idea how can I achieve this programmatically?

 

        public static IProject copyProject(IProject project, String newProject) throws CoreException {
                try{
                    IProgressMonitor monitor = new NullProgressMonitor();
                    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                    IProjectDescription projectDescription = project.getDescription();
       
                    // create clone project in workspace
                    IProjectDescription cloneDescription = workspaceRoot.getWorkspace().newProjectDescription(newProject);
                    // copy project files
                    project.copy(cloneDescription, true, monitor);
                    IProject clone = workspaceRoot.getProject(newProject);
                   
                    //make it a CPP project
                    CCorePlugin.getDefault().convertProjectToCC(clone, monitor, clone.getFullPath().toOSString());
                   
                    // copy the project properties
                    cloneDescription.setNatureIds(projectDescription.getNatureIds());
                    cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects());
                    cloneDescription.setDynamicReferences(projectDescription.getDynamicReferences());
                    cloneDescription.setBuildSpec(projectDescription.getBuildSpec());
                    cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects());
                    clone.setDescription(cloneDescription, null);
                    return clone;
                }
                catch (CoreException e){
                        e.printStackTrace();
                        MessageUtility.writeToConsole("console", e.getMessage());
                        return null;
                }
        }



Thanks,
Simos
Loading...