com.heroku.sdk.deploy.ConfigVars Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of heroku-deploy Show documentation
Show all versions of heroku-deploy Show documentation
Library for deploying Java applications to Heroku
package com.heroku.sdk.deploy;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.heroku.api.HerokuAPI;
public class ConfigVars {
private Deployer deployer;
private HerokuAPI api;
public ConfigVars(Deployer deployer, String apiKey) {
this.deployer = deployer;
this.api = new HerokuAPI(apiKey);
}
public void merge(Map configVars) throws Exception {
Map existingConfigVars = getConfigVars();
deployer.logDebug("Heroku existing config variables: " + existingConfigVars.keySet());
Map newConfigVars = new HashMap();
for (String key : configVars.keySet()) {
newConfigVars.putAll(addConfigVar(key, configVars.get(key), existingConfigVars));
}
setConfigVars(newConfigVars);
}
protected Map getConfigVars() throws Exception {
return this.api.listConfig(deployer.getName());
}
protected void setConfigVars(Map configVars) throws IOException {
if (!configVars.isEmpty()) {
api.updateConfig(deployer.getName(), configVars);
}
}
private Map addConfigVar(String key, String value, Map existingConfigVars) {
return addConfigVar(key, value, existingConfigVars, true);
}
private Map addConfigVar(String key, String value, Map existingConfigVars, Boolean force) {
Map m = new HashMap();
if (!existingConfigVars.containsKey(key) || (!value.equals(existingConfigVars.get(key)) && force)) {
m.put(key, value);
}
return m;
}
}