Skip to content
Permalink
Browse files

[JENKINS-39134] Mechanism to allow tests to intercept program.dat des…

…erialization.
  • Loading branch information...
jglick committed Jan 9, 2017
1 parent 6b29343 commit ddadc4b61b4b438946550e530f18c1b3b47cc46a
@@ -25,6 +25,7 @@
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 org.apache.commons.io.IOUtils;
import org.jboss.marshalling.ChainingObjectResolver;
@@ -50,8 +51,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 +93,9 @@ public Object writeReplace(Object original) {
}
};

@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 +162,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 +184,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 ddadc4b

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