Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-40909] Mechanism to allow tests to intercept program.dat deserialization #28

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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