Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Feb 3, 2013
1 parent ba4c580 commit e0585e4
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/main/java/org/jenkinsci/lib/envinject/EnvInjectAction.java
Expand Up @@ -34,11 +34,31 @@ public EnvInjectAction(AbstractBuild build, Map<String, String> envMap) {
}

public void overrideAll(Map<String, String> all) {
if (envMap == null) {
return;
}

if (all == null) {
return;
}

envMap.putAll(all);
}

@SuppressWarnings({"unused", "unchecked"})
public Map<String, String> getEnvMap() {
if (envMap == null) {

//Try to fill the envMap from the build injected environment
//file (injectedEnvVars.txt by default).
try {
envMap = getEnvironment(build);
} catch (EnvInjectException e) {
return null;
}
return envMap;
}

return UnmodifiableMap.decorate(envMap);
}

Expand Down Expand Up @@ -72,6 +92,24 @@ private Object writeReplace() throws ObjectStreamException {
return this;
}


private Map<String, String> getEnvironment(AbstractBuild build) throws EnvInjectException {

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

AbstractProject project = build.getProject();
if (project == null) {
return null;
}

EnvInjectSavable dao = new EnvInjectSavable();
File rootDir = new File(project.getRootDir(), build.getId());
return dao.getEnvironment(rootDir);
}


@SuppressWarnings("unused")
private Object readResolve() throws ObjectStreamException {

Expand All @@ -80,21 +118,20 @@ private Object readResolve() throws ObjectStreamException {
return this;
}

EnvInjectSavable dao = new EnvInjectSavable();
Map<String, String> resultMap = null;
try {
if (build != null) {
AbstractProject project = build.getProject();
if (project != null) {
File rootDir = new File(project.getRootDir(), build.getId());
resultMap = dao.getEnvironment(rootDir);
}
return getEnvironment(build);
} else if (rootDir != null) {
EnvInjectSavable dao = new EnvInjectSavable();
resultMap = dao.getEnvironment(rootDir);
}


if (resultMap != null) {
envMap = resultMap;
}

} catch (Throwable e) {
e.printStackTrace();
}
Expand Down

0 comments on commit e0585e4

Please sign in to comment.