Skip to content
Permalink
Browse files

The fix of JENKINS-27531 in #97 seems to be made simpler by the fix o…

…f JENKINS-29571 via JENKINS-27704 in #157.

We only needed getId(WorkflowRun) because CpsFlowExecution.unmarshal was trying to use an Owner.
Originally-Committed-As: fc3851f4df8881e24c079cf51f42b48ec9596ab9
  • Loading branch information
jglick committed Jul 28, 2015
1 parent 884e62d commit c034f77059966d1097e16a2bcc1dad2ddbe41994
Showing with 2 additions and 38 deletions.
  1. +2 −38 job/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java
@@ -41,7 +41,6 @@
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.RunMap;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
@@ -55,7 +54,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
@@ -363,42 +361,8 @@ protected void eol(byte[] b, int len) throws IOException {

private static final Map<String,WorkflowRun> LOADING_RUNS = new HashMap<String,WorkflowRun>();

/**
* Same as {@link Run#getId} except it works before the run has been loaded from disk.
* TODO JENKINS-27531 this logic should be handled directly in Run.getId() instead.
*/
private static String getId(WorkflowRun r) {
String id = r.getId();
Class<?> runIdMigratorC;
try {
runIdMigratorC = Class.forName("jenkins.model.RunIdMigrator");
} catch (ClassNotFoundException x) {
// 1.596 or earlier, so the ID is fine.
return id;
}
try {
RunMap<WorkflowRun> runMap = r.getParent()._getRuns();
Field runIdMigratorF = RunMap.class.getField("runIdMigrator");
Object runIdMigratorO = runIdMigratorF.get(runMap);
Field idToNumberF = runIdMigratorC.getDeclaredField("idToNumber");
idToNumberF.setAccessible(true);
Map<String,Integer> idToNumberO = (Map<String,Integer>) idToNumberF.get(runIdMigratorO);
int n = r.getNumber();
for (Map.Entry<String,Integer> entry : idToNumberO.entrySet()) {
if (entry.getValue().equals(n)) {
id = entry.getKey();
LOGGER.log(Level.FINE, "recovered legacy ID {0} for {1}", new Object[] {id, r});
return id;
}
}
} catch (Exception x) {
LOGGER.log(Level.WARNING, null, x);
}
return id;
}

private String key() {
return getParent().getFullName() + '/' + getId(this);
return getParent().getFullName() + '/' + getId();
}

/** Hack to allow {@link #execution} to use an {@link Owner} referring to this run, even when it has not yet been loaded. */
@@ -603,7 +567,7 @@ private String key() {
synchronized (LOADING_RUNS) {
candidate = LOADING_RUNS.get(key());
}
if (candidate != null && candidate.getParent().getFullName().equals(job) && getId(candidate).equals(id)) {
if (candidate != null && candidate.getParent().getFullName().equals(job) && candidate.getId().equals(id)) {
run = candidate;
} else {
Jenkins jenkins = Jenkins.getInstance();

0 comments on commit c034f77

Please sign in to comment.
You can’t perform that action at this time.