1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Project remove handling fixes

Property manager fixes
This commit is contained in:
Mikhail Sennikovsky 2006-04-24 22:05:17 +00:00
parent 45152faccd
commit 93c96e0452
3 changed files with 104 additions and 26 deletions

View file

@ -35,6 +35,7 @@ import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.internal.envvar.UserDefinedEnvironmentSupplier;
@ -45,9 +46,12 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PluginVersionIdentifier;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@ -109,10 +113,11 @@ public class Configuration extends BuildObject implements IConfiguration {
//as a special Builder object of the tool-chain and implement the internal
//builder enabling/disabling as the Builder substitution functionality
//
//property that holds the Internal Builder enable state
private static final String INTERNAL_BUILDER_ENABLED = "internalBuilderOn"; //$NON-NLS-1$
//property that holds the internal builder mode
private static final String INTERNAL_BUILDER_IGNORE_ERR = "internalBuilderIgnoreErr"; //$NON-NLS-1$
private static final String INTERNAL_BUILDER = "internalBuilder";
//preference key that holds the Internal Builder enable state
private static final String INTERNAL_BUILDER_ENABLED = "enabled"; //$NON-NLS-1$
//preference key that holds the internal builder mode
private static final String INTERNAL_BUILDER_IGNORE_ERR = "ignoreErr"; //$NON-NLS-1$
//Internal Builder enable state
private boolean internalBuilderEnabled;
//Internal Builder mode
@ -270,11 +275,12 @@ public class Configuration extends BuildObject implements IConfiguration {
}
}
internalBuilderEnabled = Boolean.valueOf(
mngr.getProperty(this, INTERNAL_BUILDER_ENABLED)).booleanValue();
String tmp = mngr.getProperty(this, INTERNAL_BUILDER_IGNORE_ERR);
if(tmp == null || Boolean.valueOf(tmp).booleanValue())
internalBuilderIgnoreErr = true;
Preferences prefs = getPreferences(INTERNAL_BUILDER);
internalBuilderEnabled = prefs != null ?
prefs.getBoolean(INTERNAL_BUILDER_ENABLED, false) : false;
internalBuilderIgnoreErr = prefs != null ?
prefs.getBoolean(INTERNAL_BUILDER_IGNORE_ERR, true) : true;
}
/**
@ -1722,7 +1728,14 @@ public class Configuration extends BuildObject implements IConfiguration {
public void enableInternalBuilder(boolean enable){
if(internalBuilderEnabled != enable){
internalBuilderEnabled = enable;
PropertyManager.getInstance().setProperty(this, INTERNAL_BUILDER_ENABLED, Boolean.toString(internalBuilderEnabled));
Preferences prefs = getPreferences(INTERNAL_BUILDER);
if(prefs != null){
prefs.putBoolean(INTERNAL_BUILDER_ENABLED, internalBuilderEnabled);
try {
prefs.flush();
} catch (BackingStoreException e) {
}
}
}
}
@ -1746,7 +1759,14 @@ public class Configuration extends BuildObject implements IConfiguration {
public void setInternalBuilderIgnoreErr(boolean ignore){
if(internalBuilderIgnoreErr != ignore){
internalBuilderIgnoreErr = ignore;
PropertyManager.getInstance().setProperty(this, INTERNAL_BUILDER_IGNORE_ERR, Boolean.toString(internalBuilderIgnoreErr));
Preferences prefs = getPreferences(INTERNAL_BUILDER);
if(prefs != null){
prefs.putBoolean(INTERNAL_BUILDER_IGNORE_ERR, internalBuilderIgnoreErr);
try {
prefs.flush();
} catch (BackingStoreException e) {
}
}
}
}
@ -1760,4 +1780,22 @@ public class Configuration extends BuildObject implements IConfiguration {
public boolean getInternalBuilderIgnoreErr(){
return internalBuilderIgnoreErr;
}
private Preferences getPreferences(String name){
if(isTemporary)
return null;
IProject project = (IProject)getOwner();
if(project == null || !project.exists() || !project.isOpen())
return null;
Preferences prefs = new ProjectScope(project).getNode(ManagedBuilderCorePlugin.getUniqueIdentifier());
if(prefs != null){
prefs = prefs.node(getId());
if(prefs != null && name != null)
prefs = prefs.node(name);
}
return prefs;
}
}

View file

@ -40,7 +40,6 @@ import org.osgi.service.prefs.Preferences;
/**
* This class allows specifying BuildObject-specific persisted properties
* The properties are stored as project preferences for now
*
*/
public class PropertyManager {
@ -64,7 +63,6 @@ public class PropertyManager {
Properties props = getProperties(cfg, bo);
if(props != null){
props.setProperty(prop, value);
serialize(cfg);
}
}
@ -231,9 +229,8 @@ public class PropertyManager {
}
protected Preferences getNode(IManagedProject mProject){
//TODO: should we store the data as the workspaces preferences?
return getProjNode(mProject);
// return getInstNode(mProject);
// return getProjNode(mProject);
return getInstNode(mProject);
}
protected Preferences getProjNode(IManagedProject mProject){
@ -342,7 +339,24 @@ public class PropertyManager {
public String getProperty(IBuilder builder, String key){
return getProperty(getConfiguration(builder), builder, key);
}
public void clearProperties(IManagedProject mProject){
IConfiguration cfgs[] = mProject.getConfigurations();
for(int i = 0; i < cfgs.length; i++)
clearLoaddedData(cfgs[i]);
Preferences prefs = getNode(mProject);
if(prefs != null){
try {
Preferences parent = prefs.parent();
prefs.removeNode();
if(parent != null)
parent.flush();
} catch (BackingStoreException e) {
}
}
}
public void clearProperties(IConfiguration cfg){
clearLoaddedData(cfg);
storeData(cfg, null);

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.managedbuilder.internal.core;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -48,6 +49,8 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.MultiRule;
public class ResourceChangeHandler implements IResourceChangeListener, ISaveParticipant {
private Map fRmProjectToBuildInfoMap = new HashMap();
private class ResourceConfigurationChecker implements IResourceDeltaVisitor{
private IResourceDelta fRootDelta;
@ -73,9 +76,16 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
IResource rcToCheck = null;
switch (delta.getKind()) {
case IResourceDelta.REMOVED :
if ((delta.getFlags() & IResourceDelta.MOVED_TO) == 0 && rcType == IResource.PROJECT) {
sendClose((IProject)dResource);
break;
if (rcType == IResource.PROJECT){
IManagedBuildInfo info = (IManagedBuildInfo)fRmProjectToBuildInfoMap.remove(dResource);
if((delta.getFlags() & IResourceDelta.MOVED_TO) == 0) {
if(info != null){
sendClose(info);
PropertyManager.getInstance().clearProperties(info.getManagedProject());
}
break;
}
}
case IResourceDelta.CHANGED :
if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
@ -279,9 +289,12 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
return makeGen;
}
}
public void sendClose(IProject project){
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project,false);
sendClose(ManagedBuildManager.getBuildInfo(project,false));
}
private void sendClose(IManagedBuildInfo info){
if(info != null){
IManagedProject managedProj = info.getManagedProject();
if (managedProj != null) {
@ -292,7 +305,7 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
}
}
}
/*
* I R e s o u r c e C h a n g e L i s t e n e r
*/
@ -313,9 +326,21 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
if(proj instanceof IProject)
sendClose((IProject)proj);
break;
case IResourceChangeEvent.PRE_DELETE :
IResource rc = event.getResource();
if(rc instanceof IProject){
IProject project = (IProject)rc;
try {
if (project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)) {
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
if(info != null)
fRmProjectToBuildInfoMap.put(project, info);
}
} catch (CoreException e) {
}
}
case IResourceChangeEvent.POST_CHANGE :
case IResourceChangeEvent.POST_BUILD :
case IResourceChangeEvent.PRE_DELETE :
IResourceDelta resDelta = event.getDelta();
if (resDelta == null) {
break;
@ -433,8 +458,9 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
* @see org.eclipse.core.resources.ISaveParticipant#saving(org.eclipse.core.resources.ISaveContext)
*/
public void saving(ISaveContext context) throws CoreException {
// No state to be saved by the plug-in, but request a
// resource delta to be used on next activation.
PropertyManager.getInstance().serialize();
//Request a resource delta to be used on next activation.
context.needDelta();
}