git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4548 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2012-08-09 14:47:09 +00:00
parent c772b5d61e
commit 06057a5a81
1 changed files with 33 additions and 57 deletions

View File

@ -2,20 +2,23 @@ package org.chibios.tools.eclipse.config.wizards;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
@ -25,6 +28,7 @@ import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard; import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
@SuppressWarnings("restriction")
public class NewApplicationProjectWizard extends Wizard implements INewWizard { public class NewApplicationProjectWizard extends Wizard implements INewWizard {
private NewApplicationProjectWizardPage page; private NewApplicationProjectWizardPage page;
@ -97,67 +101,39 @@ public class NewApplicationProjectWizard extends Wizard implements INewWizard {
*/ */
private void doFinish(IProgressMonitor monitor) throws CoreException { private void doFinish(IProgressMonitor monitor) throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
monitor.beginTask("Creating " + projectName, 3); monitor.beginTask("Creating " + projectName, 3);
/* Step #1, creates the project file.*/ /* Step #1, creates the project file.*/
IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); IProject project = root.getProject(projectName);
if (newProject.exists()) { if (project.exists()) {
monitor.done(); monitor.done();
MessageDialog.openError(getShell(), "Error", "Project " + projectName + MessageDialog.openError(getShell(), "Error", "Project " + projectName +
" already exists in workspace"); " already exists in workspace");
return; return;
} }
IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName()); IProjectDescription desc = project.getWorkspace().newProjectDescription(projectName);
if (finalProjectPath != null) if (finalProjectPath != null)
desc.setLocation(new Path(finalProjectPath)); desc.setLocation(new Path(finalProjectPath));
CCorePlugin corePlugin = CCorePlugin.getDefault(); project.create(desc, null);
newProject = corePlugin.createCProject(desc, newProject, null,
ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
IManagedBuildInfo managedBuildInfo = ManagedBuildManager.createBuildInfo(newProject);
ManagedCProjectNature.addManagedNature(newProject, null);
ManagedCProjectNature.addManagedBuilder(newProject, null);
IProjectType parentProjectType; /* Step #2, makes it a CDT project.*/
try { desc = workspace.newProjectDescription(projectName);
IManagedProject newManagedProject = ManagedBuildManager project = CCorePlugin.getDefault().createCDTProject(desc, project, new NullProgressMonitor());
.createManagedProject(newProject, ManagedBuildManager.getProjectType(""));
}
catch (BuildException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return; ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription cdesc = mngr.createProjectDescription(project, false);
ManagedProject mproject = new ManagedProject(cdesc);
Configuration cfg = new Configuration(mproject, null, "Default", "Default");
IBuilder bld = cfg.getEditableBuilder();
bld.setManagedBuildOn(false);
CConfigurationData data = cfg.getConfigurationData();
cdesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
mngr.setProjectDescription(project, cdesc);
/* monitor.worked(1);
IProjectDescription desc = newProject.getWorkspace().newProjectDescription(newProject.getName());
if (finalProjectPath != null)
desc.setLocation(new Path(finalProjectPath));
try {
newProject.create(desc, null);
if (!newProject.isOpen()) {
newProject.open(null);
}
} catch (CoreException e) {
monitor.done();
MessageDialog.openError(getShell(), "Error", "Project " + projectName +
" creation failed: " + e.getMessage());
return;
}
monitor.worked(1);*/
/* Step #2, adding builders.*/
/* desc = newProject.getDescription();
String[] build_configs = new String[] {ManagedCProjectNature.BUILDER_ID,
"org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder"};
desc.setBuildConfigs(build_configs);
newProject.setDescription(desc, null);*/
// CProjectNature.addCNature(newProject, null);
// ManagedCProjectNature.addNature(newProject, ManagedCProjectNature.MNG_NATURE_ID, null);
// ManagedCProjectNature.addNature(newProject, "org.eclipse.cdt.managedbuilder.core.ScannerConfigNature", null);
// ManagedCProjectNature.addManagedBuilder(newProject, null);
// monitor.worked(1);
} }
} }