Changing path variable in project properties only works when &quot;linked resources&quot; has not behttps://www.eclipse.org/forums/index.php/mv/msg/454325/1010545/#msg_1010545
I am developing a plugin and I use the IPathVariableManager to set a project specific path variable "ArduinoHardwareLibPath".
I want to change the "ArduinoHardwareLibPath" based on a setting in the project properties.
This works fine if the path variable "ArduinoHardwareLibPath" does not exists or when I do the changes without visiting the "linked resources" page in the project properties.
I have enabled a PathVariableChangeListener and learned this way that the value is set back to the old value.
I assue this is done because of the closing of the "linked resource" window which still contains the old value. (I mostly opened this to see the old value bfore changing it) This is confirmed because not visiting "Linked resources" make the code to work (no extra call to PathVariableChangeListener and the value is changed)

My question is: how can I make this work all the time?
Below is the code of the method caled as a result of the PropertyPage.performOk()

Best regards
Jantje

public static void setWorkSpacePathVariables(IProject project, URI newPath) {
IPathVariableManager pathMan = project.getPathVariableManager();
//this code has been added for debuggin and needs to be removed as it will create a change listener for each call which is a really bad idea
pathMan.addChangeListener(new IPathVariableChangeListener() {
@Override
public void pathVariableChanged(IPathVariableChangeEvent event) {
// This method is called after the setURIValue value below and then later again with the old value
System.out.println(event.getVariableName());
}
});
try {
//I read the original value for debuggin reasons. Needs to be removed
URI orgPath = pathMan.getURIValue(ArduinoConst.WORKSPACE_PATH_VARIABLE_NAME_HARDWARE_LIB);
pathMan.setURIValue(ArduinoConst.WORKSPACE_PATH_VARIABLE_NAME_HARDWARE_LIB,newPath);
//I read the value back for debugging to see wether it works
URI readPath = pathMan.getURIValue(ArduinoConst.WORKSPACE_PATH_VARIABLE_NAME_HARDWARE_LIB);
//For debugging I thow an error when the read value does not match the written value.
if (!readPath.toString().equals(newPath.toString()))
{
//this has never happened
Common.log(new Status(Status.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Failed to clean the workspace path variables.",null));
}
} catch (CoreException e) {
Common.log(new Status(Status.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Failed to create the workspace path variables. The setup will not work properly", e));
e.printStackTrace();
}
}