Thanks Neil,
For some reason, though, when I use those methods, the variables aren't shown in the project.variables file.
I did a little more digging through the API's and found VariableProviderLazyProxy. After some playing, I got the following code to work... but I'm not sure if this is another right way to do this.
VariableProviderLazyProxy proxy = new VariableProviderLazyProxy(getProject(), "");
try {
Collection<String> varNames = proxy.getSortedResourceNames(getProject());
boolean vpmsExists = false;
boolean appnameExists = false;
for (String var : varNames) {
if (var.equals("__VPvpms")) {
vpmsExists = true;
if (appnameExists)
break;
else
continue;
}
if (var.equals("__VPappname")) {
appnameExists = true;
if (vpmsExists)
break;
else
continue;
}
}
if (!vpmsExists) {
proxy.createSimpleVariable(getProject(), "__VPvpms", "", "", "", VariableEditPolicy.LOCKED_VARIABLE, "", new NullProgressMonitor());
}
if (!appnameExists) {
proxy.createSimpleVariable(getProject(), "__VPappname", "", "", "", VariableEditPolicy.LOCKED_VARIABLE, "", new NullProgressMonitor());
}
if (!vpmsExists || !appnameExists) {
proxy.updateProjectVariables(new NullProgressMonitor());
}
} catch (VariablesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Essentially, the variables are only created if they don't already exists.