Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Aug 30, 2012
1 parent 952af19 commit 9abab6b
Showing 1 changed file with 41 additions and 3 deletions.
Expand Up @@ -6,6 +6,7 @@
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.Hudson;
import hudson.util.VariableResolver;
import org.jenkinsci.lib.envinject.EnvInjectException;
import org.jenkinsci.lib.envinject.EnvInjectLogger;

Expand Down Expand Up @@ -197,17 +198,54 @@ public void resolveVars(Map<String, String> variables, Map<String, String> env)
private Map<String, String> removeUnsetVars(Map<String, String> envVars) {
Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<String, String> entry : envVars.entrySet()) {
if (!isUnresolvedVar(entry.getValue())) {
result.put(entry.getKey(), removeEscapeDollar(entry.getValue()));

String value = entry.getValue();

value = removeUnsetVars(value);

if (!isUnresolvedVar(value)) {
result.put(entry.getKey(), removeEscapeDollar(value));
} else {
logger.info(String.format("Unset unresolved '%s' variable.", entry.getKey()));
}
}
return result;
}

private String removeUnsetVars(String value) {

if (value == null) {
return null;
}

if (value.length() == 0) {
return value;
}

if (!value.contains("$") || value.contains("\\$")) {
return value;
}

return Util.replaceMacro(value, new VariableResolver<String>() {

public String resolve(String name) {
return "";
}
});

}

private boolean isUnresolvedVar(String value) {
return value != null && value.contains("$") && !value.contains("\\$");

if (value == null) {
return true;
}

if (value.trim().length() == 0) {
return true;
}

return value.contains("$") && !value.contains("\\$");
}

private String removeEscapeDollar(String value) {
Expand Down

0 comments on commit 9abab6b

Please sign in to comment.