mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Related to fix for Bug 265282 -- don't lose previous unchanged environment on save. Add test.
This commit is contained in:
parent
b60a11baac
commit
3308a839d6
2 changed files with 81 additions and 4 deletions
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.envvar;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
@ -91,6 +93,63 @@ public class IEnvironmentVariableManagerTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public void testNoChangeToOneVariable() throws Exception {
|
||||
final IProject project = ResourceHelper.createCDTProjectWithConfig("envProject");
|
||||
|
||||
// Add another, derived configuration
|
||||
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
|
||||
ICConfigurationDescription desc = prjDesc.getActiveConfiguration();
|
||||
final String id1 = desc.getId();
|
||||
|
||||
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
|
||||
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
|
||||
|
||||
// Try setting an environment variable
|
||||
final IEnvironmentVariable var = new EnvironmentVariable("FOO", "BAR");
|
||||
final IEnvironmentVariable var1 = new EnvironmentVariable("FOO1", "BAR1");
|
||||
final IEnvironmentVariable var2 = new EnvironmentVariable("FOO2", "BAR2");
|
||||
contribEnv.addVariable(var, prjDesc.getConfigurationById(id1));
|
||||
contribEnv.addVariable(var1, prjDesc.getConfigurationById(id1));
|
||||
contribEnv.addVariable(var2, prjDesc.getConfigurationById(id1));
|
||||
|
||||
// Check that the variable exists on config1
|
||||
IEnvironmentVariable readVar = envManager.getVariable(var.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var, readVar);
|
||||
readVar = envManager.getVariable(var1.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var1, readVar);
|
||||
readVar = envManager.getVariable(var2.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var2, readVar);
|
||||
|
||||
// Save the project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDesc);
|
||||
|
||||
// Close and open the project
|
||||
project.close(null);
|
||||
project.open(null);
|
||||
prjDesc = CoreModel.getDefault().getProjectDescription(project);
|
||||
final IEnvironmentVariable var3 = new EnvironmentVariable("FOO", "BAZ");
|
||||
contribEnv.addVariable(var3, prjDesc.getConfigurationById(id1));
|
||||
readVar = envManager.getVariable(var3.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var3, readVar);
|
||||
readVar = envManager.getVariable(var1.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var1, readVar);
|
||||
// Save the project description
|
||||
CoreModel.getDefault().setProjectDescription(project, prjDesc);
|
||||
|
||||
// Close and open the project
|
||||
project.close(null);
|
||||
project.open(null);
|
||||
prjDesc = CoreModel.getDefault().getProjectDescription(project);
|
||||
|
||||
readVar = envManager.getVariable(var3.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var3, readVar);
|
||||
readVar = envManager.getVariable(var1.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var1, readVar);
|
||||
readVar = envManager.getVariable(var2.getName(), prjDesc.getConfigurationById(id1), true);
|
||||
assertEquals(var2, readVar);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This bug checks for an environment load race during project open / import.
|
||||
*
|
||||
|
|
|
@ -178,19 +178,37 @@ public class StorableEnvironment /*implements Cloneable*/{
|
|||
fIsDirty = false;
|
||||
fIsChanged = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialize the Storable enviornment into the ICStorageElement
|
||||
*
|
||||
* NB assumes that any variables part of the ISerializeInfo will continue to be serialized
|
||||
* @param element
|
||||
*/
|
||||
public void serialize(ICStorageElement element){
|
||||
checkBackingSerializeInfo();
|
||||
Map<String, IEnvironmentVariable> map = new HashMap<String, IEnvironmentVariable>();
|
||||
if (fCachedSerialEnv != null)
|
||||
map.putAll(fCachedSerialEnv);
|
||||
if (fDeletedVariables != null) {
|
||||
for (String rem : fDeletedVariables.keySet())
|
||||
map.remove(rem);
|
||||
fDeletedVariables.clear();
|
||||
}
|
||||
if (fVariables != null)
|
||||
map.putAll(fVariables);
|
||||
|
||||
element.setAttribute(ATTRIBUTE_APPEND, Boolean.valueOf(fAppend).toString());
|
||||
element.setAttribute(ATTRIBUTE_APPEND_CONTRIBUTED, Boolean.valueOf(fAppendContributedEnv).toString());
|
||||
if(fVariables != null){
|
||||
Iterator<IEnvironmentVariable> iter = fVariables.values().iterator();
|
||||
if(!map.isEmpty()){
|
||||
Iterator<IEnvironmentVariable> iter = map.values().iterator();
|
||||
while(iter.hasNext()){
|
||||
StorableEnvVar var = (StorableEnvVar)iter.next();
|
||||
ICStorageElement varEl = element.createChild(StorableEnvVar.VARIABLE_ELEMENT_NAME);
|
||||
var.serialize(varEl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fIsDirty = false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue