Skip to content
Permalink
Browse files

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 23629ee0e162925a63520fbc8d5b2e964fca6051
@@ -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;
@@ -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.
@@ -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 {
@@ -155,7 +164,7 @@ public Unmarshaller apply(PickleResolver input) {
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));
@@ -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() {

0 comments on commit 23629ee

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