Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #28 from jglick/AbstractStepExecutionImpl-JENKINS-…
…39134

[JENKINS-40909] Mechanism to allow tests to intercept program.dat deserialization
  • Loading branch information
jglick committed Jan 10, 2017
2 parents 6b29343 + 0fc5bea commit 23629ee
Showing 1 changed file with 15 additions and 2 deletions.
Expand Up @@ -25,7 +25,9 @@
package org.jenkinsci.plugins.workflow.support.pickles.serialization;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListenableFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.io.IOUtils;
import org.jboss.marshalling.ChainingObjectResolver;
import org.jboss.marshalling.Marshalling;
Expand All @@ -50,8 +52,11 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;

import static org.apache.commons.io.IOUtils.*;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Reads program data file that stores the object graph of the CPS-transformed program.
Expand Down Expand Up @@ -89,6 +94,10 @@ public Object writeReplace(Object original) {
}
};

@SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="intentionally not")
@Restricted(NoExternalUse.class) // tests only
public static @CheckForNull ObjectResolver customResolver = null;

private InputStream in;

public RiverReader(File f, ClassLoader classLoader, FlowExecutionOwner owner) throws IOException {
Expand Down Expand Up @@ -155,7 +164,7 @@ private List<Pickle> readPickles(int offset) throws IOException {
try {
MarshallingConfiguration config = new MarshallingConfiguration();
config.setClassResolver(new SimpleClassResolver(classLoader));
config.setObjectResolver(ownerResolver);
config.setObjectResolver(combine(ownerResolver));
Unmarshaller eu = new RiverMarshallerFactory().createUnmarshaller(config);
try {
eu.start(Marshalling.createByteInput(es));
Expand All @@ -177,7 +186,11 @@ private BufferedInputStream openStreamAt(int offset) throws IOException {
}

private ObjectResolver combine(ObjectResolver... resolvers) {
return new ChainingObjectResolver(resolvers);
List<ObjectResolver> _resolvers = Lists.newArrayList(resolvers);
if (customResolver != null) {
_resolvers.add(0, customResolver);
}
return _resolvers.size() == 1 ? _resolvers.get(0) : new ChainingObjectResolver(_resolvers);
}

@Override public void close() {
Expand Down

0 comments on commit 23629ee

Please sign in to comment.