1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

1. isCdtProjectCreating state functionality and tests

This commit is contained in:
Mikhail Sennikovsky 2007-05-17 15:50:24 +00:00
parent 264ab07b52
commit a4beb8b6d0
21 changed files with 663 additions and 1009 deletions

View file

@ -317,7 +317,7 @@ public class CDTConfigWizardPage extends WizardPage {
private void advancedDialog() {
if (getWizard() instanceof CDTCommonProjectWizard) {
CDTCommonProjectWizard nmWizard = (CDTCommonProjectWizard)getWizard();
IProject newProject = nmWizard.getProject(true);
IProject newProject = nmWizard.getProject(true, false);
if (newProject != null) {
boolean oldManage = CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOMNG);
// disable manage configurations button

View file

@ -23,6 +23,7 @@ import java.util.TreeMap;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
@ -381,9 +382,9 @@ public class MBSWizardHandler extends CWizardHandler {
full_tcs.put(tc.getUniqueRealName(), tc);
}
public void createProject(IProject project, boolean defaults) throws CoreException {
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescription des = coreModel.createProjectDescription(project, false);
public void createProject(IProject project, boolean defaults, boolean onFinish) throws CoreException {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
CfgHolder[] cfgs = null;
if (defaults) {
@ -430,7 +431,7 @@ public class MBSWizardHandler extends CWizardHandler {
active = cfgDes;
}
if (active != null) active.setActive();
coreModel.setProjectDescription(project, des);
mngr.setProjectDescription(project, des);
doPostProcess(project);

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.managedbuilder.ui.wizards;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -47,9 +48,9 @@ public class STDWizardHandler extends MBSWizardHandler {
/**
* Note that configurations parameter is ignored
*/
public void createProject(IProject project, boolean defaults) throws CoreException {
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescription des = coreModel.createProjectDescription(project, false);
public void createProject(IProject project, boolean defaults, boolean onFinish) throws CoreException {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
ManagedProject mProj = new ManagedProject(des);
info.setManagedProject(mProj);
@ -76,7 +77,7 @@ public class STDWizardHandler extends MBSWizardHandler {
CConfigurationData data = cfg.getConfigurationData();
des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
}
coreModel.setProjectDescription(project, des);
mngr.setProjectDescription(project, des);
doPostProcess(project);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -14,7 +14,7 @@ import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.failedTests.FailedDeclaratorsTest;
import org.eclipse.cdt.core.settings.model.CProjectDescriptionTests;
import org.eclipse.cdt.core.settings.model.AllCProjectDescriptionTests;
/**
@ -49,7 +49,7 @@ public class AllCoreTests {
// suite.addTest(CConfigurationDescriptionReferenceTests.suite());
//the CProjectDescriptionTests now groups all New Project Model related tests
//which includes the CConfigurationDescriptionReferenceTests
suite.addTest(CProjectDescriptionTests.suite());
suite.addTest(AllCProjectDescriptionTests.suite());
suite.addTest(ASTCacheTests.suite());
return suite;

View file

@ -13,19 +13,20 @@ package org.eclipse.cdt.core.settings.model;
import junit.framework.Test;
import junit.framework.TestSuite;
public class CProjectDescriptionTests {
public class AllCProjectDescriptionTests {
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(CProjectDescriptionTests.class.getName());
TestSuite suite = new TestSuite(AllCProjectDescriptionTests.class.getName());
// Just add more test cases here as you create them for
// each class being tested
suite.addTest(CConfigurationDescriptionReferenceTests.suite());
suite.addTest(ExternalSettingsProviderTests.suite());
suite.addTest(CfgSettingsTests.suite());
suite.addTest(ProjectCreationStateTests.suite());
return suite;
}

View file

@ -0,0 +1,401 @@
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.settings.model;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
public class ProjectCreationStateTests extends BaseTestCase{
private static final String PROJ_NAME_PREFIX = "ProjectCreationStateTests_";
private IProject p1, p2, p3, p4;
private Listener listener;
private class Listener implements ICProjectDescriptionListener {
private boolean fIsCreationCompletedNotified;
private boolean fIsCreating;
private boolean fIsNotified;
private String fProjName;
Listener(String projName){
init();
fProjName = projName;
}
public void handleEvent(CProjectDescriptionEvent event) {
if(!event.getProject().getName().equals(fProjName))
return;
fIsNotified = true;
boolean creating = event.getNewCProjectDescription().isCdtProjectCreating();
ICDescriptionDelta delta = event.getProjectDelta();
boolean notified = delta != null ? (delta.getChangeFlags() & ICDescriptionDelta.PROJECT_CREAION_COMPLETED) != 0 : false;
if(creating)
assertTrue(fIsCreating);
if(notified)
assertFalse(fIsCreationCompletedNotified);
fIsCreating = creating;
fIsCreationCompletedNotified = notified;
}
void init(){
fIsCreating = true;
fIsCreationCompletedNotified = false;
resetNotified();
}
boolean isCreating(){
return fIsCreating;
}
boolean isCreationCompletedNotified(){
return fIsCreationCompletedNotified;
}
boolean isNotified(){
boolean notified = fIsNotified;
resetNotified();
return notified;
}
void resetNotified(){
fIsNotified = false;
}
}
public static TestSuite suite() {
return suite(ProjectCreationStateTests.class, "_");
}
protected void setUp() throws Exception {
// p1 = CProjectHelper.createNewStileCProject(PROJ_NAME_PREFIX + "a", IPDOMManager.ID_NO_INDEXER);
}
private void initListener(String projName){
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
if(listener != null)
mngr.removeCProjectDescriptionListener(listener);
listener = new Listener(projName);
mngr.addCProjectDescriptionListener(listener, CProjectDescriptionEvent.APPLIED);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
}
public void testProjectCreatingState() throws Exception {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
String projName = PROJ_NAME_PREFIX + "a";
initListener(projName);
ICProject cp1 = CProjectHelper.createNewStileCProject(projName, IPDOMManager.ID_NO_INDEXER, true);
IProject project = cp1.getProject();
p1 = project;
assertTrue(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
listener.resetNotified();
ICProjectDescription des = mngr.getProjectDescription(project, false);
assertTrue(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, true);
assertTrue(des.isCdtProjectCreating());
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
ICProjectDescription des2 = mngr.getProjectDescription(project, true);
des2.createConfiguration(CDataUtil.genId(null), CDataUtil.genId(null), des2.getConfigurations()[0]);
mngr.setProjectDescription(project, des2);
des2 = mngr.getProjectDescription(project, false);
assertTrue(des2.isCdtProjectCreating());
des2 = mngr.getProjectDescription(project, true);
assertTrue(des2.isCdtProjectCreating());
assertTrue(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
listener.resetNotified();
des.createConfiguration(CDataUtil.genId(null), CDataUtil.genId(null), des.getConfigurations()[0]);
des.setCdtProjectCreated();
des2.createConfiguration(CDataUtil.genId(null), CDataUtil.genId(null), des2.getConfigurations()[0]);
mngr.setProjectDescription(project, des);
assertTrue(listener.isNotified());
assertTrue(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
listener.resetNotified();
assertTrue(des2.isCdtProjectCreating());
mngr.setProjectDescription(project, des2);
assertTrue(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
listener.resetNotified();
des2 = mngr.getProjectDescription(project, false);
assertFalse(des2.isCdtProjectCreating());
des2 = mngr.getProjectDescription(project, true);
assertFalse(des2.isCdtProjectCreating());
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
des2.createConfiguration(CDataUtil.genId(null), CDataUtil.genId(null), des2.getConfigurations()[0]);
mngr.setProjectDescription(project, des2);
assertTrue(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
listener.resetNotified();
}
public void testCreateProjectDescriptionForInexistingDes() throws Exception {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
String projName = PROJ_NAME_PREFIX + "b";
initListener(projName);
IWorkspace wsp = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = wsp.getRoot();
IProject project = root.getProject(projName);
p2 = project;
project.create(null);
project.open(null);
CProjectHelper.addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
ICProjectDescription des = mngr.getProjectDescription(project, false);
assertNull(des);
des = mngr.getProjectDescription(project, true);
assertNull(des);
des = mngr.createProjectDescription(project, true);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNull(des);
des = mngr.getProjectDescription(project, true);
assertNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
des = mngr.createProjectDescription(project, false);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNull(des);
des = mngr.getProjectDescription(project, true);
assertNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
des = mngr.createProjectDescription(project, true, true);
assertTrue(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNull(des);
des = mngr.getProjectDescription(project, true);
assertNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
des = mngr.createProjectDescription(project, false, true);
assertTrue(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNull(des);
des = mngr.getProjectDescription(project, true);
assertNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
}
public void testCreateProjectDescriptionForCreatingDes() throws Exception {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
String projName = PROJ_NAME_PREFIX + "c";
initListener(projName);
ICProject cp3 = CProjectHelper.createNewStileCProject(projName, IPDOMManager.ID_NO_INDEXER, true);
IProject project = cp3.getProject();
p3 = project;
assertTrue(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
ICProjectDescription des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
des = mngr.createProjectDescription(project, true);
assertTrue(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
des = mngr.createProjectDescription(project, false);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
des = mngr.createProjectDescription(project, true, true);
assertTrue(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
des = mngr.createProjectDescription(project, false, true);
assertTrue(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertTrue(listener.isCreating());
}
public void testCreateProjectDescriptionForCreatedDes() throws Exception {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
String projName = PROJ_NAME_PREFIX + "d";
initListener(projName);
ICProject cp4 = CProjectHelper.createNewStileCProject(projName, IPDOMManager.ID_NO_INDEXER, false);
IProject project = cp4.getProject();
p4 = project;
assertTrue(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
ICProjectDescription des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
des = mngr.createProjectDescription(project, true);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
des = mngr.createProjectDescription(project, false);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
des = mngr.createProjectDescription(project, true, true);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
des = mngr.createProjectDescription(project, false, true);
assertFalse(des.isCdtProjectCreating());
des = mngr.getProjectDescription(project, false);
assertNotNull(des);
des = mngr.getProjectDescription(project, true);
assertNotNull(des);
assertFalse(listener.isNotified());
assertFalse(listener.isCreationCompletedNotified());
assertFalse(listener.isCreating());
}
protected void tearDown() throws Exception {
if(listener != null){
CoreModel.getDefault().getProjectDescriptionManager().removeCProjectDescriptionListener(listener);
listener = null;
}
try {
if(p1 != null){
p1.getProject().delete(true, null);
p1 = null;
}
} catch (CoreException e){
}
try {
if(p2 != null){
p2.getProject().delete(true, null);
p2 = null;
}
} catch (CoreException e){
}
try {
if(p3 != null){
p3.getProject().delete(true, null);
p3 = null;
}
} catch (CoreException e){
}
try {
if(p4 != null){
p4.getProject().delete(true, null);
p4 = null;
}
} catch (CoreException e){
}
}
}

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.resources.IFolder;
@ -106,18 +107,25 @@ public class CProjectHelper {
return newProject[0];
}
/**
* Creates a ICProject.
*/
public static ICProject createNewStileCProject(final String projectName, final String indexerID) throws CoreException {
return createNewStileCProject(projectName, null, indexerID);
return createNewStileCProject(projectName, indexerID, false);
}
/**
* Creates a ICProject.
*/
public static ICProject createNewStileCProject(final String projectName, String cfgProviderId, final String indexerID) throws CoreException {
public static ICProject createNewStileCProject(final String projectName, final String indexerID, boolean markCreating) throws CoreException {
return createNewStileCProject(projectName, null, indexerID, markCreating);
}
/**
* Creates a ICProject.
*/
public static ICProject createNewStileCProject(final String projectName, String cfgProviderId, final String indexerID, final boolean markCreating) throws CoreException {
final IWorkspace ws = ResourcesPlugin.getWorkspace();
final ICProject newProject[] = new ICProject[1];
if(cfgProviderId == null)
@ -144,9 +152,10 @@ public class CProjectHelper {
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
ICConfigurationDescription prefCfg = CCorePlugin.getDefault().getPreferenceConfiguration(finalCfgProviderId);
ICProjectDescription projDes = CCorePlugin.getDefault().createProjectDescription(project, false);
ICProjectDescriptionManager mngr = CCorePlugin.getDefault().getProjectDescriptionManager();
ICProjectDescription projDes = mngr.createProjectDescription(project, false, markCreating);
projDes.createConfiguration(CDataUtil.genId(null), CDataUtil.genId("test"), prefCfg);
CCorePlugin.getDefault().setProjectDescription(project, projDes);
mngr.setProjectDescription(project, projDes);
// CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
}
newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
@ -350,7 +359,7 @@ public class CProjectHelper {
return null;
}
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
public static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = proj.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];

View file

@ -1312,6 +1312,15 @@ public class CoreModel {
return rc;
}
/**
* this method is a full equivalent to {@link #createProjectDescription(IProject, boolean, false)}
*
* @see #createProjectDescription(IProject, boolean, boolean)
*/
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{
return descriptionManager.createProjectDescription(project, loadIfExists);
}
/**
* the method creates and returns a writable project description
*
@ -1319,12 +1328,16 @@ public class CoreModel {
* @param loadIfExists if true the method first tries to load and return the project description
* from the settings file (.cproject)
* if false, the stored settings are ignored and the new (empty) project description is created
* NOTE: changes made to the returned project description will not be applied untill the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @param creating if true the created project description will be contain the true "isCdtProjectCreating" state.
* NOTE: in case the project already contains the project description AND its "isCdtProjectCreating" is false
* the resulting description will be created with the false "isCdtProjectCreating" state
*
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @return {@link ICProjectDescription}
* @throws CoreException
*/
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{
return descriptionManager.createProjectDescription(project, loadIfExists);
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException{
return descriptionManager.createProjectDescription(project, loadIfExists, creating);
}
/**

View file

@ -12,10 +12,37 @@ package org.eclipse.cdt.core.settings.model;
public interface ICDescriptionDelta {
/*
* delta kinds
*/
/**
* kind specifying that the setting object returned by
* the {@link #getSetting()} was removed
* the {@link #getNewSetting()} returns null
* the {@link #getOldSetting()} returns the same object as {@link #getSetting()}
*/
int REMOVED = 1;
/**
* kind specifying that the setting object returned by
* the {@link #getSetting()} was added
* the {@link #getNewSetting()} returns the same object as {@link #getSetting()}
* the {@link #getOldSetting()} returns null
*/
int ADDED = 2;
/**
* kind specifying that the setting object was changed
* the {@link #getNewSetting()} returns new object
* the {@link #getOldSetting()} returns old object
* the {@link #getSetting()} returns the same object as {@link #getNewSetting()}
*/
int CHANGED = 3;
/*
* delta change flags
*/
int ACTIVE_CFG = 1;
int NAME = 1 << 1;
int DESCRIPTION = 1 << 2;
@ -38,10 +65,39 @@ public interface ICDescriptionDelta {
int EXT_REF = 1 << 19;
int OWNER = 1 << 20;
int INDEX_CFG = 1 << 21;
int SETTING_CFG = INDEX_CFG;
/**
* specifies that the project "isCdtProjectCreating" state was set to false
* the PROJECT_CREAION_COMPLETED delta gets notified ONLY in case
* the project previously contained the project description with
* the true "isCdtProjectCreating" state
*
* in case the initial project description does NOT contain the true "isCdtProjectCreating"
* the project is considered as initialized from the very beginning
* and the PROJECT_CREAION_COMPLETED delta is NOT notified
*
* @see ICProjectDescription#isCdtProjectCreating()
* @see ICProjectDescription#setCdtProjectCreated()
* @see ICProjectDescriptionManager#createProjectDescription(org.eclipse.core.resources.IProject, boolean, boolean)
*/
int PROJECT_CREAION_COMPLETED = 1 << 22;
/**
* returns the kind
* @see #ADDED
* @see #REMOVED
* @see #CHANGED
*
* @return int
*/
int getDeltaKind();
/**
* returns ored delta flags
*
* @return
*/
int getChangeFlags();
int getSettingType();

View file

@ -161,4 +161,39 @@ public interface ICProjectDescription extends ICSettingContainer,
* @param cfg
*/
void setDefaultSettingConfiguration(ICConfigurationDescription cfg);
/**
* when true specifies that the project creation is in progress.
* Sometimes project creation might be performed via multiple steps, e.g.
* the New Project Wizard may create a temporary project with temporary settings
* and delete it on cancel, etc.
*
* Thus the project may exist as well as the project may contain the associated ICProjectDescription,
* but its initialization may not be completed.
*
* once the flag is set to false it can never be reset back to true.
* if {@link ICProjectDescriptionManager#setProjectDescription(IProject, ICProjectDescription)} is called
* for the description containing the true "isCdtProjectCreating" state,
* but the project already contains the project description with the false "isCdtProjectCreating" state
* the true state will be ignored, i.e. the resulting setting will contain false "isCdtProjectCreating" state
*
* so only the newly created descriptions (created via a {@link ICProjectDescriptionManager#createProjectDescription(IProject, boolean, boolean)}) may contain
* true "isCdtProjectCreating" state
*
*
* @return boolean
*
* @see ICProjectDescriptionManager#createProjectDescription(IProject, boolean, boolean)
* @see #setCdtProjectCreated()
*/
boolean isCdtProjectCreating();
/**
* sets the project creation state to false
*
* @see #isCdtProjectCreating()
* @see ICProjectDescriptionManager#createProjectDescription(IProject, boolean, boolean)
*/
void setCdtProjectCreated();
}

View file

@ -15,6 +15,14 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
public interface ICProjectDescriptionManager {
/**
* this method is a full equivalent to {@link #createProjectDescription(IProject, boolean, false)}
*
* @see #createProjectDescription(IProject, boolean, boolean)
*/
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException;
/**
* the method creates and returns a writable project description
*
@ -22,11 +30,16 @@ public interface ICProjectDescriptionManager {
* @param loadIfExists if true the method first tries to load and return the project description
* from the settings file (.cproject)
* if false, the stored settings are ignored and the new (empty) project description is created
* NOTE: changes made to the returned project description will not be applied untill the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @param creating if true the created project description will be contain the true "isCdtProjectCreating" state.
* NOTE: in case the project already contains the project description AND its "isCdtProjectCreating" is false
* the resulting description will be created with the false "isCdtProjectCreating" state
*
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @return {@link ICProjectDescription}
* @throws CoreException
*/
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException;
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException;
/**
* returns the project description associated with this project

View file

@ -53,6 +53,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
// private boolean fNeedsActiveCfgIdPersistence;
private boolean fIsLoadding;
private boolean fIsApplying;
private boolean fIsCreating;
private class CfgIdPair {
private String fId;
@ -149,13 +150,15 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
}
}
CProjectDescription(IProject project, ICStorageElement element, boolean loadding) throws CoreException {
CProjectDescription(IProject project, ICStorageElement element, boolean loadding, boolean isCreating) throws CoreException {
fProject = project;
fRootStorageElement = element;
fIsReadOnly = loadding;
fIsLoadding = loadding;
fActiveCfgInfo = new CfgIdPair(ACTIVE_CFG_PROPERTY);
fSettingCfgInfo = new CfgIdPair(SETTING_CFG_PROPERTY);
fIsCreating = isCreating;
ICStorageElement el = null;
CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance();
if(loadding){
@ -258,7 +261,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
return fIsApplying;
}
public CProjectDescription(CProjectDescription base, boolean saving, ICStorageElement el) {
public CProjectDescription(CProjectDescription base, boolean saving, ICStorageElement el, boolean isCreating) {
fActiveCfgInfo = new CfgIdPair(base.fActiveCfgInfo);
fSettingCfgInfo = new CfgIdPair(base.fSettingCfgInfo);
fProject = base.fProject;
@ -266,6 +269,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
fIsReadOnly = saving;
fIsLoadding = base.fIsLoadding;
fIsApplying = saving || base.fIsApplying;
fIsCreating = isCreating;
fPrefs = new CProjectDescriptionPreferences(base.fPrefs, (CProjectDescriptionPreferences)CProjectDescriptionManager.getInstance().getProjectDescriptionWorkspacePreferences(false), false);
@ -587,6 +591,21 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
public void useDefaultConfigurationRelations() {
fPrefs.useDefaultConfigurationRelations();
}
public boolean isCdtProjectCreating() {
return fIsCreating;
}
public void setCdtProjectCreated() {
if(!fIsCreating)
return;
if(fIsReadOnly)
throw ExceptionFactory.createIsReadOnlyException();
fIsCreating = false;
fIsModified = true;
}
}

View file

@ -475,7 +475,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
CCorePlugin.log(e);
}
des = new CProjectDescription((CProjectDescription)des, false, el);
des = new CProjectDescription((CProjectDescription)des, false, el, des.isCdtProjectCreating());
CProjectDescriptionEvent event = createCopyCreatedEvent(des, cache);
notifyListeners(event);
}
@ -586,7 +586,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
} catch (CoreException e2) {
}
des = new CProjectDescription(des, true, el);
des = new CProjectDescription(des, true, el, des.isCdtProjectCreating());
try {
setDescriptionApplying(project, des);
des.applyDatas();
@ -801,11 +801,16 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{
ICProjectDescription des = loadIfExists ? getProjectDescription(project) : null;
if(des == null){
return createProjectDescription(project, loadIfExists, false);
}
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException{
ICProjectDescription des = getProjectDescription(project, loadIfExists, true);
if(des == null || !loadIfExists){
if(creating && des != null)
creating = des.isCdtProjectCreating();
ICStorageElement element = createStorage(project, false, true, false);
des = new CProjectDescription(project, element, false);
des = new CProjectDescription(project, element, false, creating);
}
return des;
}
@ -913,7 +918,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
private ICProjectDescription loadProjectDescription(IProject project) throws CoreException{
ICStorageElement storage = CProjectDescriptionManager.getInstance().createStorage(project, true, false, false);
CProjectDescription des = new CProjectDescription(project, storage, true);
CProjectDescription des = new CProjectDescription(project, storage, true, false);
if(des != null){
try {
setDescriptionLoadding(project, des);
@ -1913,7 +1918,9 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
if(checkCfgChange(newDescription, oldDescription, false))
delta.addChangeFlags(ICDescriptionDelta.INDEX_CFG);
if(oldDescription.isCdtProjectCreating() && !newDescription.isCdtProjectCreating())
delta.addChangeFlags(ICDescriptionDelta.PROJECT_CREAION_COMPLETED);
}
return delta.isEmpty() ? null : delta;
}

View file

@ -54,7 +54,11 @@ public class SetCProjectDescriptionOperation extends CModelOperation {
} catch (CoreException e2) {
}
CProjectDescription fNewDescriptionCache = new CProjectDescription(fSetDescription, true, el);
boolean creating = fOldDescriptionCache != null ? fOldDescriptionCache.isCdtProjectCreating() : true;
if(creating)
creating = fSetDescription.isCdtProjectCreating();
CProjectDescription fNewDescriptionCache = new CProjectDescription(fSetDescription, true, el, creating);
try {
mngr.setDescriptionApplying(project, fNewDescriptionCache);
fNewDescriptionCache.applyDatas();

View file

@ -1132,6 +1132,15 @@ public class CCorePlugin extends Plugin {
fNewCProjectDescriptionManager.setPreferenceConfiguration(buildSystemId, des);
}
/**
* this method is a full equivalent to {@link #createProjectDescription(IProject, boolean, false)}
*
* @see #createProjectDescription(IProject, boolean, boolean)
*/
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{
return fNewCProjectDescriptionManager.createProjectDescription(project, loadIfExists);
}
/**
* the method creates and returns a writable project description
*
@ -1139,12 +1148,16 @@ public class CCorePlugin extends Plugin {
* @param loadIfExists if true the method first tries to load and return the project description
* from the settings file (.cproject)
* if false, the stored settings are ignored and the new (empty) project description is created
* NOTE: changes made to the returned project description will not be applied untill the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @param creating if true the created project description will be contain the true "isCdtProjectCreating" state.
* NOTE: in case the project already contains the project description AND its "isCdtProjectCreating" is false
* the resulting description will be created with the false "isCdtProjectCreating" state
*
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @return {@link ICProjectDescription}
* @throws CoreException
*/
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException{
return fNewCProjectDescriptionManager.createProjectDescription(project, loadIfExists);
public ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException{
return fNewCProjectDescriptionManager.createProjectDescription(project, loadIfExists, creating);
}
/**

View file

@ -110,7 +110,10 @@ public class CConfigBasedDescriptor implements ICDescriptor {
public void apply(boolean force) throws CoreException{
if(force || fIsDirty){
CProjectDescriptionManager.getInstance().setProjectDescription(fProject, fCfgDes.getProjectDescription());
ICProjectDescription des = fCfgDes.getProjectDescription();
if(des.isCdtProjectCreating())
des.setCdtProjectCreated();
CProjectDescriptionManager.getInstance().setProjectDescription(fProject, des);
fIsDirty = false;
}
}

View file

@ -299,7 +299,7 @@ public class CConfigBasedDescriptorManager implements ICDescriptorManager {
private CProjectDescription createProjDescriptionForDescriptor(IProject project) throws CoreException{
CProjectDescriptionManager mngr = CProjectDescriptionManager.getInstance();
CProjectDescription des = (CProjectDescription)mngr.createProjectDescription(project, false);
CProjectDescription des = (CProjectDescription)mngr.createProjectDescription(project, false, true);
CConfigurationData data = mngr.createDefaultConfigData(project, PathEntryConfigurationDataProvider.getDataFactory());
des.createConfiguration(CCorePlugin.DEFAULT_PROVIDER_ID, data);

View file

@ -1,599 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2005 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core;
public class CDescriptor /*implements ICDescriptor */{
private CDescriptor(){
}
// final CDescriptorManager fManager;
// final IProject fProject;
// private COwner fOwner;
//
// private HashMap extMap = new HashMap(4);
// private HashMap extInfoMap = new HashMap(4);
// private Document dataDoc;
//
// protected static final String DESCRIPTION_FILE_NAME = ".cdtproject"; //$NON-NLS-1$
//
// private static final String CEXTENSION_NAME = "cextension"; //$NON-NLS-1$
//
// private static final String PROJECT_DESCRIPTION = "cdtproject"; //$NON-NLS-1$
// private static final String PROJECT_OWNER_ID = "id"; //$NON-NLS-1$
// private static final String PROJECT_EXTENSION = "extension"; //$NON-NLS-1$
// private static final String PROJECT_EXTENSION_ATTR_POINT = "point"; //$NON-NLS-1$
// private static final String PROJECT_EXTENSION_ATTR_ID = "id"; //$NON-NLS-1$
// private static final String PROJECT_EXTENSION_ATTRIBUTE = "attribute"; //$NON-NLS-1$
// private static final String PROJECT_EXTENSION_ATTRIBUTE_KEY = "key"; //$NON-NLS-1$
// private static final String PROJECT_EXTENSION_ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
//
// private static final String PROJECT_DATA = "data"; //$NON-NLS-1$
// private static final String PROJECT_DATA_ITEM = "item"; //$NON-NLS-1$
// private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$
//
// boolean fUpdating;
// boolean isInitializing = true;
// boolean bDirty = false;
//
// protected CDescriptor(CDescriptorManager manager, IProject project, String id) throws CoreException {
// fProject = project;
// fManager = manager;
// IPath projectLocation = project.getDescription().getLocation();
//
// if (projectLocation == null) {
// projectLocation = getProjectDefaultLocation(project);
// }
// IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
//
// if (descriptionPath.toFile().exists()) {
// IStatus status;
// String ownerID = readCDTProjectFile(descriptionPath);
// if (!ownerID.equals("")) { //$NON-NLS-1$
// if (ownerID.equals(id)) {
// status = new Status(IStatus.WARNING, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
// CCorePlugin.getResourceString("CDescriptor.exception.projectAlreadyExists"), (Throwable)null); //$NON-NLS-1$
// } else {
// status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_MISMATCH,
// CCorePlugin.getResourceString("CDescriptor.exception.unmatchedOwnerId") + "<requested:" +id +"/ In file:" +ownerID+">", (Throwable)null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
// }
// throw new CoreException(status);
// }
// }
// fOwner = new COwner(manager.getOwnerConfiguration(id));
// fOwner.configure(project, this);
// isInitializing = false;
// save();
// }
//
// protected CDescriptor(CDescriptorManager manager, IProject project) throws CoreException {
// fProject = project;
// fManager = manager;
// IPath projectLocation = project.getDescription().getLocation();
//
// if (projectLocation == null) {
// projectLocation = getProjectDefaultLocation(project);
// }
// IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
//
// if (!descriptionPath.toFile().exists()) {
// fOwner = new COwner(manager.getOwnerConfiguration(project));
// fOwner.configure(project, this);
// fManager.updateDescriptor(this);
// } else {
// String ownerId = readCDTProjectFile(descriptionPath);
// fOwner = new COwner(manager.getOwnerConfiguration(ownerId));
// }
// isInitializing = false;
// }
//
// protected CDescriptor(CDescriptorManager manager, IProject project, COwner owner) throws CoreException {
// fProject = project;
// fManager = manager;
// IPath projectLocation = project.getDescription().getLocation();
//
// if (projectLocation == null) {
// projectLocation = getProjectDefaultLocation(project);
// }
// IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
//
// if (descriptionPath.toFile().exists()) {
// readCDTProjectFile(descriptionPath);
// }
// fOwner = owner;
// fOwner.configure(project, this);
// isInitializing = false;
// save();
// }
//
// private String readCDTProjectFile(IPath descriptionPath) throws CoreException {
// String ownerID = ""; //$NON-NLS-1$
// try {
// DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
// Document document = parser.parse(descriptionPath.toFile());
// NodeList nodeList = document.getElementsByTagName(PROJECT_DESCRIPTION);
// if (nodeList != null && nodeList.getLength() > 0) {
// Node node = nodeList.item(0);
// if (node.hasAttributes()) {
// ownerID = node.getAttributes().getNamedItem(PROJECT_OWNER_ID).getNodeValue();
// }
// readProjectDescription(node);
// return ownerID;
// }
// IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
// CCorePlugin.getResourceString("CDescriptor.exception.missingElement"), null); //$NON-NLS-1$
// throw new CoreException(status);
// } catch (Exception e) {
// IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.toString(), e);
// throw new CoreException(status);
// }
// }
//
// private static IPath getProjectDefaultLocation(IProject project) {
// return Platform.getLocation().append(project.getFullPath());
// }
//
// public ICOwnerInfo getProjectOwner() {
// return fOwner;
// }
//
// public String getPlatform() {
// return fOwner.getPlatform();
// }
//
// public IProject getProject() {
// return fProject;
// }
//
// synchronized public ICExtensionReference[] get(String extensionID) {
// CExtensionReference[] refs = (CExtensionReference[])extMap.get(extensionID);
// if (refs == null)
// return new ICExtensionReference[0];
// return refs;
// }
//
// synchronized public ICExtensionReference[] get(String extensionID, boolean update) throws CoreException {
// ICExtensionReference[] refs = get(extensionID);
// if (refs.length == 0 && update) {
// boolean oldIsInitializing = isInitializing;
// isInitializing = true;
// fOwner.update(fProject, this, extensionID);
// isInitializing = oldIsInitializing;
// updateIfDirty();
// refs = get(extensionID);
// }
// return refs;
// }
//
// private CExtensionReference createRef(String extensionPoint, String extension) {
// CExtensionReference extensions[] = (CExtensionReference[])extMap.get(extensionPoint);
// if (extensions == null) {
// extensions = new CExtensionReference[1];
// extMap.put(extensionPoint, extensions);
// } else {
// CExtensionReference[] newExtensions = new CExtensionReference[extensions.length + 1];
// System.arraycopy(extensions, 0, newExtensions, 0, extensions.length);
// extensions = newExtensions;
// extMap.put(extensionPoint, extensions);
// }
// extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extension);
// return extensions[extensions.length - 1];
// }
//
// synchronized public ICExtensionReference create(String extensionPoint, String extension) throws CoreException {
// boolean fireEvent = false;
// CExtensionReference extRef;
// synchronized (this) {
// extRef = createRef(extensionPoint, extension);
// updateOnDisk();
// if (!isInitializing) {
// fireEvent = true;
// }
// }
// if (fireEvent) {
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
// }
// return extRef;
// }
//
// synchronized public void remove(ICExtensionReference ext) throws CoreException {
// boolean fireEvent = false;
// synchronized (this) {
// CExtensionReference extensions[] = (CExtensionReference[])extMap.get(ext.getExtension());
// for (int i = 0; i < extensions.length; i++) {
// if (extensions[i] == ext) {
// System.arraycopy(extensions, i, extensions, i + 1, extensions.length - 1 - i);
// if (extensions.length > 1) {
// CExtensionReference[] newExtensions = new CExtensionReference[extensions.length - 1];
// System.arraycopy(extensions, 0, newExtensions, 0, newExtensions.length);
// extMap.put(ext.getExtension(), newExtensions);
// } else {
// extMap.remove(ext.getExtension());
// }
// updateOnDisk();
// if (!isInitializing) {
// fireEvent = true;
// }
// }
// }
// }
// if (fireEvent) {
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
// }
// }
//
// public void remove(String extensionPoint) throws CoreException {
// boolean fireEvent = false;
// synchronized (this) {
// CExtensionReference extensions[] = (CExtensionReference[])extMap.get(extensionPoint);
// if (extensions != null) {
// extMap.remove(extensionPoint);
// updateOnDisk();
// if (!isInitializing) {
// fireEvent = true;
// }
// }
// }
// if (fireEvent) {
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.EXTENSION_CHANGED));
// }
// }
//
// synchronized CExtensionInfo getInfo(CExtensionReference cProjectExtension) {
// CExtensionInfo info = (CExtensionInfo)extInfoMap.get(cProjectExtension);
// if (info == null) {
// info = new CExtensionInfo();
// extInfoMap.put(cProjectExtension, info);
// }
// return info;
// }
//
// protected IFile getFile() {
// return getProject().getFile(DESCRIPTION_FILE_NAME);
// }
//
// void save() throws CoreException {
// IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory();
// ISchedulingRule rule;
// IFile rscFile = getFile();
// if (rscFile.exists()) {
// rule = ruleFactory.modifyRule(rscFile);
// } else {
// rule = ruleFactory.createRule(rscFile);
// }
// fManager.getWorkspace().run(new IWorkspaceRunnable() {
//
// public void run(IProgressMonitor mon) throws CoreException {
// String xml;
// bDirty = false;
// if (!fProject.isAccessible()) {
// return;
// }
// fUpdating = true;
//
// try {
// xml = getAsXML();
// } catch (IOException e) {
// IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
// throw new CoreException(s);
// } catch (TransformerException e) {
// IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
// throw new CoreException(s);
// } catch (ParserConfigurationException e) {
// IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
// throw new CoreException(s);
// }
//
// IFile rscFile = getFile();
// InputStream inputStream;
// try {
// inputStream = new ByteArrayInputStream(xml.getBytes("UTF8")); //$NON-NLS-1$
// if (rscFile.exists()) {
// if (rscFile.isReadOnly()) {
// // provide opportunity to checkout read-only .cdtproject file
// fManager.getWorkspace().validateEdit(new IFile[]{rscFile}, null);
// }
// rscFile.setContents(inputStream, IResource.FORCE, null);
// } else {
// rscFile.create(inputStream, IResource.FORCE, null);
// }
// } catch (UnsupportedEncodingException e) {
// IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, e.getMessage(), e);
// throw new CoreException(s);
// }
// fUpdating = false;
// }
// }, rule, IWorkspace.AVOID_UPDATE, null);
// }
//
// boolean isUpdating() {
// return fUpdating;
// }
//
// void updateIfDirty() {
// if ( bDirty ) {
// updateOnDisk();
// }
// }
//
// synchronized void updateOnDisk() {
// if (isUpdating()) {
// return;
// }
// if (isInitializing) {
// bDirty = true;
// return;
// }
// fUpdating = true;
// fManager.updateDescriptor(this);
// }
//
// void updateFromDisk() throws CoreException {
// COwner origOwner;
// HashMap origExtMap;
// HashMap origExtInfoMap;
// Document origDataDoc;
// synchronized (this) {
// IPath projectLocation = fProject.getDescription().getLocation();
//
// if (projectLocation == null) {
// projectLocation = getProjectDefaultLocation(fProject);
// }
// IPath descriptionPath = projectLocation.append(DESCRIPTION_FILE_NAME);
// if (!descriptionPath.toFile().exists()) {
// updateOnDisk();
// return;
// }
//
// origOwner = fOwner;
// origExtMap = extMap;
// origExtInfoMap = extInfoMap;
// origDataDoc = dataDoc;
//
// extMap = new HashMap(4);
// extInfoMap = new HashMap(4);
// dataDoc = null;
//
// try {
// String ownerId = readCDTProjectFile(descriptionPath);
// fOwner = new COwner(fManager.getOwnerConfiguration(ownerId));
// } catch (CoreException e) {
// CCorePlugin.log(e);
// fOwner = origOwner;
// extMap = origExtMap;
// extInfoMap = origExtInfoMap;
// dataDoc = origDataDoc;
// }
// }
// if (!fOwner.equals(origOwner)) {
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.OWNER_CHANGED));
// } else {
// boolean extChanges = true;
// if (extMap.size() == origExtMap.size() && extInfoMap.size() == origExtInfoMap.size()) {
// extChanges = false;
// Iterator entries = extMap.entrySet().iterator();
// while (entries.hasNext()) {
// Entry entry = (Entry)entries.next();
// if (!origExtMap.containsKey(entry.getKey())) {
// extChanges = true;
// break;
// }
// CExtensionReference origExt[] = (CExtensionReference[])origExtMap.get(entry.getKey());
// CExtensionReference newExt[] = (CExtensionReference[])entry.getValue();
// if (!Arrays.equals(origExt, newExt)) {
// extChanges = true;
// break;
// }
// }
// }
// if (extChanges) {
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED,
// CDescriptorEvent.EXTENSION_CHANGED));
// } else {
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
// }
// }
// }
//
// private void readProjectDescription(Node node) {
// Node childNode;
// NodeList list = node.getChildNodes();
// for (int i = 0; i < list.getLength(); i++) {
// childNode = list.item(i);
// if (childNode.getNodeType() == Node.ELEMENT_NODE) {
// if (childNode.getNodeName().equals(PROJECT_EXTENSION)) {
// try {
// decodeProjectExtension((Element)childNode);
// } catch (CoreException e) {
// CCorePlugin.log(e);
// }
// } else if (childNode.getNodeName().equals(PROJECT_DATA)) {
// try {
// decodeProjectData((Element)childNode);
// } catch (CoreException e) {
// CCorePlugin.log(e);
// }
// }
// }
// }
// }
//
// private void decodeProjectExtension(Element element) throws CoreException {
// String point = element.getAttribute(PROJECT_EXTENSION_ATTR_POINT);
// String id = element.getAttribute(PROJECT_EXTENSION_ATTR_ID);
// CExtensionReference ext = createRef(point, id);
// NodeList extAttrib = element.getChildNodes();
// for (int j = 0; j < extAttrib.getLength(); j++) {
// if (extAttrib.item(j).getNodeName().equals(PROJECT_EXTENSION_ATTRIBUTE)) {
// NamedNodeMap attrib = extAttrib.item(j).getAttributes();
// getInfo(ext).setAttribute(attrib.getNamedItem(PROJECT_EXTENSION_ATTRIBUTE_KEY).getNodeValue(),
// attrib.getNamedItem(PROJECT_EXTENSION_ATTRIBUTE_VALUE).getNodeValue());
// }
// }
// }
//
// private void encodeProjectExtensions(Document doc, Element configRootElement) {
// Element element;
// Iterator extIterator = extMap.values().iterator();
// while (extIterator.hasNext()) {
// CExtensionReference extension[] = (CExtensionReference[])extIterator.next();
// for (int i = 0; i < extension.length; i++) {
// configRootElement.appendChild(element = doc.createElement(PROJECT_EXTENSION));
// element.setAttribute(PROJECT_EXTENSION_ATTR_POINT, extension[i].getExtension());
// element.setAttribute(PROJECT_EXTENSION_ATTR_ID, extension[i].getID());
// CExtensionInfo info = (CExtensionInfo)extInfoMap.get(extension[i]);
// if (info != null) {
// Iterator attribIterator = info.getAttributes().entrySet().iterator();
// while (attribIterator.hasNext()) {
// Entry entry = (Entry)attribIterator.next();
// Element extAttributes = doc.createElement(PROJECT_EXTENSION_ATTRIBUTE);
// extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_KEY, (String)entry.getKey());
// extAttributes.setAttribute(PROJECT_EXTENSION_ATTRIBUTE_VALUE, (String)entry.getValue());
// element.appendChild(extAttributes);
// }
// }
// }
// }
// }
//
// String getAsXML() throws IOException, TransformerException, ParserConfigurationException {
// DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
// DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
// Document doc = docBuilder.newDocument();
// ProcessingInstruction version = doc.createProcessingInstruction("eclipse-cdt", "version=\"2.0\""); //$NON-NLS-1$ //$NON-NLS-2$
// doc.appendChild(version);
// Element configRootElement = doc.createElement(PROJECT_DESCRIPTION);
// doc.appendChild(configRootElement);
// if (fOwner.getID().length() > 0) {
// configRootElement.setAttribute(PROJECT_OWNER_ID, fOwner.getID());
// }
// encodeProjectExtensions(doc, configRootElement);
// encodeProjectData(doc, configRootElement);
// return serializeDocument(doc);
// }
//
// protected ICExtension createExtensions(ICExtensionReference ext) throws CoreException {
// InternalCExtension cExtension = null;
// IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
// IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(ext.getExtension());
// IExtension extension = extensionPoint.getExtension(ext.getID());
// if (extension == null) {
// throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
// CCorePlugin.getResourceString("CDescriptor.exception.providerNotFound") + ":" + ext.getID(), null)); //$NON-NLS-1$ //$NON-NLS-2$
// }
// IConfigurationElement element[] = extension.getConfigurationElements();
// for (int i = 0; i < element.length; i++) {
// if (element[i].getName().equalsIgnoreCase(CEXTENSION_NAME)) {
// cExtension = (InternalCExtension)element[i].createExecutableExtension("run"); //$NON-NLS-1$
// cExtension.setExtensionReference(ext);
// cExtension.setProject(fProject);
// break;
// }
// }
// return (ICExtension)cExtension;
// }
//
// protected IConfigurationElement[] getConfigurationElement(ICExtensionReference ext) throws CoreException {
// IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
// IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(ext.getExtension());
// IExtension extension = extensionPoint.getExtension(ext.getID());
// if (extension == null) {
// throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
// CCorePlugin.getResourceString("CDescriptor.exception.providerNotFound"), null)); //$NON-NLS-1$
// }
// IConfigurationElement element[] = extension.getConfigurationElements();
// for (int i = 0; i < element.length; i++) {
// if (element[i].getName().equalsIgnoreCase(CEXTENSION_NAME)) {
// return element[i].getChildren();
// }
// }
// return new IConfigurationElement[0];
// }
//
// public synchronized Element getProjectData(String id) throws CoreException {
// Document doc = getProjectDataDoc();
// NodeList nodes = doc.getDocumentElement().getElementsByTagName(PROJECT_DATA_ITEM);
// for (int i = 0; i < nodes.getLength(); ++i) {
// Element element = (Element)nodes.item(i);
// if (element != null && element.getAttribute(PROJECT_DATA_ID).equals(id))
// return element;
// }
//
// // Not found, make a new one
// Element element = doc.createElement(PROJECT_DATA_ITEM);
// element.setAttribute(PROJECT_DATA_ID, id);
// doc.getDocumentElement().appendChild(element);
// return element;
// }
//
// public void saveProjectData() throws CoreException {
// save();
// fManager.fireEvent(new CDescriptorEvent(this, CDescriptorEvent.CDTPROJECT_CHANGED, 0));
// }
//
// // The project data allows for the storage of any structured information
// // into the cdtproject file.
// synchronized private Document getProjectDataDoc() throws CoreException {
// if (dataDoc == null) {
// try {
// dataDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
// } catch (ParserConfigurationException e) {
// throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR,
// CCorePlugin.getResourceString("CDescriptor.extension.internalError"), e)); //$NON-NLS-1$
// }
// Element rootElem = dataDoc.createElement(PROJECT_DATA);
// dataDoc.appendChild(rootElem);
// }
// return dataDoc;
// }
//
// private void decodeProjectData(Element data) throws CoreException {
// Document doc = getProjectDataDoc();
// doc.replaceChild(doc.importNode(data, true), doc.getDocumentElement());
// }
//
// private void encodeProjectData(Document doc, Element root) {
// // Don't create or encode the doc if it isn't there already
// if (dataDoc != null) {
// Element dataElements = dataDoc.getDocumentElement();
// NodeList nodes = dataElements.getElementsByTagName(PROJECT_DATA_ITEM);
// for (int i = 0; i < nodes.getLength(); ++i) {
// Element item = (Element)nodes.item(i);
// if (!item.hasChildNodes()) { // remove any empty item tags
// dataElements.removeChild(item);
// i--; //nodeList is live.... removeal changes nodelist
// }
// }
// root.appendChild(doc.importNode(dataDoc.getDocumentElement(), true));
// }
// }
//
// private String serializeDocument(Document doc) throws IOException, TransformerException {
// ByteArrayOutputStream s = new ByteArrayOutputStream();
//
// TransformerFactory factory = TransformerFactory.newInstance();
// Transformer transformer = factory.newTransformer();
// transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
// transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
// transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
//
// DOMSource source = new DOMSource(doc);
// StreamResult outputTarget = new StreamResult(s);
// transformer.transform(source, outputTarget);
//
// return s.toString("UTF8"); //$NON-NLS-1$
// }
//
// public ICConfigurationDescription getConfigurationDescription() {
// // TODO Auto-generated method stub
// return null;
// }
}

View file

@ -1,363 +0,0 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core;
public class CDescriptorManager /*implements ICDescriptorManager, IResourceChangeListener */{
private CDescriptorManager(){
}
//
// Map fOperationMap = new HashMap(1);
// Map fDescriptorMap = new HashMap();
// Map fOwnerConfigMap = null;
// List listeners = Collections.synchronizedList(new Vector());
//
// private static final COwnerConfiguration NULLCOwner = new COwnerConfiguration("", //$NON-NLS-1$
// CCorePlugin.getResourceString("CDescriptorManager.internal_owner")); //$NON-NLS-1$
//
// class CDescriptorUpdater extends Job {
//
// CDescriptor fDescriptor;
//
// public CDescriptorUpdater(CDescriptor descriptor) {
// super(CCorePlugin.getResourceString("CDescriptorManager.async_updater")); //$NON-NLS-1$
// fDescriptor = descriptor;
// setPriority(Job.INTERACTIVE);
// setSystem(true);
// setRule(descriptor.getProject());
// }
//
// protected IStatus run(IProgressMonitor monitor) {
// try {
// fDescriptor.save();
// } catch (CoreException e) {
// return e.getStatus();
// }
// return Status.OK_STATUS;
// }
//
// }
//
//
// IWorkspace getWorkspace() {
// return ResourcesPlugin.getWorkspace();
// }
//
// public void shutdown() {
// getWorkspace().removeResourceChangeListener(this);
// }
//
// public void startup() throws CoreException {
// getWorkspace().getRoot().accept(new IResourceVisitor() {
//
// public boolean visit(IResource resource) {
// if (resource.getType() == IResource.PROJECT) {
// IProject project = (IProject)resource;
// try { // seed in memory descriptor map
// if (project.isAccessible() && project.findMember(CDescriptor.DESCRIPTION_FILE_NAME) != null) {
// getDescriptor(project);
// }
// } catch (CoreException e) {
// CCorePlugin.log(e);
// }
// return false;
// }
// return resource.getType() == IResource.ROOT;
// }
// });
// getWorkspace().addResourceChangeListener(this,
// IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
// }
//
// /**
// * Watch for changes/deletions of the .cdtproject file.
// *
// * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
// */
// public void resourceChanged(IResourceChangeEvent event) {
// if (event.getSource() instanceof IWorkspace) {
// IResource resource = event.getResource();
//
// switch (event.getType()) {
// case IResourceChangeEvent.PRE_DELETE :
// case IResourceChangeEvent.PRE_CLOSE :
// if (resource.getType() == IResource.PROJECT) {
// CDescriptor descriptor = (CDescriptor)fDescriptorMap.remove(resource);
// if (descriptor != null) {
// fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_REMOVED, 0));
// }
// }
// break;
// case IResourceChangeEvent.PRE_BUILD :
// IResourceDelta resDelta = event.getDelta();
// if (resDelta == null) {
// break;
// }
// try {
// resDelta.accept(new IResourceDeltaVisitor() {
//
// public boolean visit(IResourceDelta delta) throws CoreException {
// IResource dResource = delta.getResource();
// if (dResource.getType() == IResource.PROJECT) {
// if (0 != (delta.getFlags() & IResourceDelta.OPEN)) {
// IProject project = (IProject)dResource;
// if (project.isAccessible() && project.findMember(CDescriptor.DESCRIPTION_FILE_NAME) != null
// && fDescriptorMap.get(project) == null) {
// getDescriptor(project); // file on disk but not in memory...read
// } else {
// CDescriptor descriptor = (CDescriptor)fDescriptorMap.remove(project);
// if (descriptor != null) {
// fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_REMOVED, 0));
// }
// }
// return false;
// }
// return true;
// } else if (dResource.getType() == IResource.FILE) {
// if (dResource.getName().equals(CDescriptor.DESCRIPTION_FILE_NAME)) {
// CDescriptor descriptor = (CDescriptor)fDescriptorMap.get(dResource.getProject());
// if (descriptor != null) {
// if ( (delta.getKind() & IResourceDelta.REMOVED) != 0) {
// // the file got deleted lets try
// // and restore for memory.
// descriptor.updateOnDisk();
// } else if ( (delta.getFlags() & IResourceDelta.CONTENT) != 0) {
// // content change lets try to
// // read and update
// descriptor.updateFromDisk();
// }
// }
// return false;
// }
// return true;
// }
// return dResource.getType() == IResource.ROOT;
// }
// });
// } catch (CoreException e) {
// CCorePlugin.log(e);
// }
// break;
// }
// }
// }
//
// private void initializeOwnerConfiguration() {
// IExtensionPoint extpoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, "CProject"); //$NON-NLS-1$
// IExtension extension[] = extpoint.getExtensions();
// fOwnerConfigMap = new HashMap(extension.length);
// for (int i = 0; i < extension.length; i++) {
// IConfigurationElement element[] = extension[i].getConfigurationElements();
// for (int j = 0; j < element.length; j++) {
// if (element[j].getName().equalsIgnoreCase("cproject")) { //$NON-NLS-1$
// fOwnerConfigMap.put(extension[i].getUniqueIdentifier(), new COwnerConfiguration(element[j]));
// break;
// }
// }
// }
// }
//
// COwnerConfiguration getOwnerConfiguration(String id) {
// if (id.equals(NULLCOwner.getOwnerID())) { //$NON-NLS-1$
// return NULLCOwner;
// }
// if (fOwnerConfigMap == null) {
// initializeOwnerConfiguration();
// }
// COwnerConfiguration config = (COwnerConfiguration)fOwnerConfigMap.get(id);
// if (config == null) { // no install owner, lets create place holder config for it.
// config = new COwnerConfiguration(id, CCorePlugin.getResourceString("CDescriptorManager.owner_not_Installed")); //$NON-NLS-1$
// fOwnerConfigMap.put(id, config);
// }
// return config;
// }
//
// COwnerConfiguration getOwnerConfiguration(IProject project) throws CoreException {
// if (fOwnerConfigMap == null) {
// initializeOwnerConfiguration();
// }
// IProjectDescription description = project.getDescription();
// String natureIDs[] = description.getNatureIds();
// Iterator configs = fOwnerConfigMap.entrySet().iterator();
// while (configs.hasNext()) {
// Entry entry = (Entry)configs.next();
// COwnerConfiguration config = (COwnerConfiguration)entry.getValue();
// if (config.getNature() != null) {
// if (Arrays.asList(natureIDs).lastIndexOf(config.getNature()) != -1) {
// return config;
// }
// }
// }
// return NULLCOwner;
// }
//
// synchronized public ICDescriptor getDescriptor(IProject project) throws CoreException {
// return getDescriptor(project, true);
// }
//
// synchronized public ICDescriptor getDescriptor(IProject project, boolean create) throws CoreException {
// CDescriptor descriptor = (CDescriptor)fDescriptorMap.get(project);
// if (descriptor == null) {
// if (create) {
// descriptor = new CDescriptor(this, project);
// fDescriptorMap.put(project, descriptor);
// } else {
// IPath projectLocation = project.getDescription().getLocation();
//
// if (projectLocation == null) {
// projectLocation = Platform.getLocation().append(project.getFullPath());
// }
// IPath descriptionPath = projectLocation.append(CDescriptor.DESCRIPTION_FILE_NAME);
//
// if (descriptionPath.toFile().exists()) {
// descriptor = new CDescriptor(this, project);
// fDescriptorMap.put(project, descriptor);
// }
// }
// }
// return descriptor;
// }
//
// public void configure(IProject project, String id) throws CoreException {
// CDescriptor descriptor;
// if (id.equals(NULLCOwner.getOwnerID())) { //$NON-NLS-1$
// IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
// CCorePlugin.getResourceString("CDescriptorManager.exception.invalid_ownerID"), //$NON-NLS-1$
// (Throwable)null);
// throw new CoreException(status);
// }
// synchronized (this) {
// descriptor = (CDescriptor)fDescriptorMap.get(project);
// if (descriptor != null) {
// if (descriptor.getProjectOwner().getID().equals(NULLCOwner.getOwnerID())) { //$NON-NLS-1$
// // non owned descriptors are simply configure to the new owner no questions ask!
// descriptor = new CDescriptor(this, project, new COwner(getOwnerConfiguration(id)));
// } else if (!descriptor.getProjectOwner().getID().equals(id)) {
// IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_CDTPROJECT_EXISTS,
// CCorePlugin.getResourceString("CDescriptorManager.exception.alreadyConfigured"), //$NON-NLS-1$
// (Throwable)null);
// throw new CoreException(status);
// } else {
// return; // already configured with same owner.
// }
// } else {
// try {
// descriptor = new CDescriptor(this, project, id);
// } catch (CoreException e) { // if .cdtproject already exists we'll use that
// IStatus status = e.getStatus();
// if (status.getCode() == CCorePlugin.STATUS_CDTPROJECT_EXISTS) {
// descriptor = new CDescriptor(this, project);
// } else
// throw e;
// }
// }
// fDescriptorMap.put(project, descriptor);
// }
// fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_ADDED, 0));
// }
//
// public void convert(IProject project, String id) throws CoreException {
// CDescriptor descriptor;
// synchronized (this) {
// descriptor = new CDescriptor(this, project, new COwner(getOwnerConfiguration(id)));
// fDescriptorMap.put(project, descriptor);
// }
// fireEvent(new CDescriptorEvent(descriptor, CDescriptorEvent.CDTPROJECT_CHANGED, CDescriptorEvent.OWNER_CHANGED));
// }
//
// public void addDescriptorListener(ICDescriptorListener listener) {
// listeners.add(listener);
// }
//
// public void removeDescriptorListener(ICDescriptorListener listener) {
// listeners.remove(listener);
// }
//
// protected void fireEvent(final CDescriptorEvent event) {
// if (fOperationMap.containsKey(event.getDescriptor())) {
// // lets just hold on to the important event in order of;
// // ADD/REMOVE should not receive the remove but....
// // OWNER_CHANGED
// // EXT_CHANGED
// // other
// if (event.getType() == CDescriptorEvent.CDTPROJECT_ADDED) {
// fOperationMap.put(event.getDescriptor(), event);
// } else if (event.getType() == CDescriptorEvent.CDTPROJECT_REMOVED) {
// fOperationMap.put(event.getDescriptor(), event);
// } else {
// CDescriptorEvent ev = (CDescriptorEvent)fOperationMap.get(event.getDescriptor());
// if (ev == null) {
// fOperationMap.put(event.getDescriptor(), event);
// } else if ( (ev.getFlags() & event.getFlags()) != event.getFlags()) {
// fOperationMap.put(event.getDescriptor(), new CDescriptorEvent(event.getDescriptor(), event.getType(),
// ev.getFlags() | event.getFlags()));
// }
// }
// return;
// }
// final ICDescriptorListener[] listener;
// synchronized (listeners) {
// listener = (ICDescriptorListener[])listeners.toArray(new ICDescriptorListener[listeners.size()]);
// }
// for (int i = 0; i < listener.length; i++) {
// final int index = i;
// Platform.run(new ISafeRunnable() {
//
// public void handleException(Throwable exception) {
// IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
// CCorePlugin.getResourceString("CDescriptorManager.exception.listenerError"), exception); //$NON-NLS-1$
// CCorePlugin.log(status);
// }
//
// public void run() throws Exception {
// listener[index].descriptorChanged(event);
// }
// });
// }
// }
//
// public void runDescriptorOperation(IProject project, ICDescriptorOperation op, IProgressMonitor monitor) throws CoreException {
// ICDescriptor descriptor = getDescriptor(project, true);
// if (descriptor == null) {
// throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, "Failed to create descriptor", null)); //$NON-NLS-1$
// }
// CDescriptorEvent event = null;
// synchronized (descriptor) {
// beginOperation(descriptor);
// try {
// op.execute(descriptor, monitor);
// } finally {
// event = endOperation(descriptor);
// }
// }
// if (event != null) {
// fireEvent(event);
// }
// }
//
// private void beginOperation(ICDescriptor descriptor) {
// fOperationMap.put(descriptor, null);
// }
//
// private CDescriptorEvent endOperation(ICDescriptor descriptor) {
// return (CDescriptorEvent)fOperationMap.remove(descriptor);
// }
//
// /*
// * Perform a update of the ondisk .cdtproject file. This is nessecary to avoid deadlocking when the descriptor has change from a
// * call to ICDescriptor.get(project, true) which may update the descriptor via the owner update method, while the workspace is
// * locked (ie during a resourceChange event).
// */
// protected void updateDescriptor(CDescriptor descriptor) {
// new CDescriptorUpdater(descriptor).schedule();
// }
}

View file

@ -36,6 +36,9 @@ import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.newui.UIMessages;
@ -101,8 +104,12 @@ implements IExecutableExtension, IWizardWithMemory
return savedHandler.isChanged();
}
public IProject getProject(boolean defaults) {
return getProject(defaults, true);
}
public IProject getProject(boolean defaults, boolean onFinish) {
if (newProject != null && isChanged())
clearProject();
if (newProject == null) {
@ -111,7 +118,7 @@ implements IExecutableExtension, IWizardWithMemory
lastProjectName = fMainPage.getProjectName();
lastProjectLocation = fMainPage.getProjectLocation();
// start creation process
invokeRunnable(getRunnable(defaults));
invokeRunnable(getRunnable(defaults, onFinish));
}
return newProject;
}
@ -147,13 +154,32 @@ implements IExecutableExtension, IWizardWithMemory
public boolean performFinish() {
// create project if it is not created yet
if (getProject(fMainPage.isCurrent()) == null) return false;
if (getProject(fMainPage.isCurrent(), true) == null) return false;
fMainPage.h_selected.postProcess(newProject);
setCreated();
BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
selectAndReveal(newProject);
return true;
}
protected boolean setCreated(){
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.getProjectDescription(newProject, false);
if(des.isCdtProjectCreating()){
des = mngr.getProjectDescription(newProject, true);
des.setCdtProjectCreated();
try {
mngr.setProjectDescription(newProject, des, false, null);
return true;
} catch (CoreException e) {
//TODO: log/display err
e.printStackTrace();
}
}
return false;
}
public boolean performCancel() {
clearProject();
return true;
@ -163,7 +189,7 @@ implements IExecutableExtension, IWizardWithMemory
fConfigElement= config;
}
private IRunnableWithProgress getRunnable(boolean _defaults) {
private IRunnableWithProgress getRunnable(boolean _defaults, final boolean onFinish) {
final boolean defaults = _defaults;
return new IRunnableWithProgress() {
public void run(IProgressMonitor imonitor) throws InvocationTargetException, InterruptedException {
@ -172,7 +198,7 @@ implements IExecutableExtension, IWizardWithMemory
try {
newProject = createIProject(lastProjectName, lastProjectLocation);
if (newProject != null)
fMainPage.h_selected.createProject(newProject, defaults);
fMainPage.h_selected.createProject(newProject, defaults, onFinish);
} catch (CoreException e) { CUIPlugin.getDefault().log(e); }
}
});

View file

@ -142,6 +142,20 @@ public class CWizardHandler implements Cloneable {
public void createProject(IProject proj, boolean defaults)
throws CoreException {}
/**
* Creates project
*
* @param proj - simple project to be used as base
* @param defaults - true if called from 1st Wizard page
* @param onFinish - true when the project creation is performed on finish. false -otherwise
* false means that the project created is actually a temporary one that can be removed in case cancell is pressed
*
* @throws CoreException
*/
public void createProject(IProject proj, boolean defaults, boolean onFinish)
throws CoreException {
createProject(proj, defaults);
}
/**
*
* @return true if settings were changed