Switched from annotation based scheme to a function based scheme.

This commit is contained in:
Kohsuke Kawaguchi committed 2014-09-23 19:12:43 -07:00
1 parent 59456c734a
commit ffb5b65093
44 files changed
+247 -251

No files matched your search

+2 -3
View File
@@ -26,7 +26,7 @@ package hudson;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.CaseInsensitiveComparator;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import java.io.File;
import java.io.IOException;
@@ -213,8 +213,7 @@ public class EnvVars extends TreeMap<String,String> {
return channel.call(new GetEnvVars());
}
@MasterToSlave
private static final class GetEnvVars implements Callable<EnvVars,RuntimeException> {
private static final class GetEnvVars extends MasterToSlaveCallable<EnvVars,RuntimeException> {
public EnvVars call() {
return new EnvVars(EnvVars.masterEnvVars);
}
+97 -47
View File
@@ -55,9 +55,8 @@ import hudson.util.io.Archiver;
import hudson.util.io.ArchiverFactory;
import jenkins.FilePathFilter;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import jenkins.security.SlaveToMaster;
import jenkins.security.Roles;
import jenkins.util.VirtualFile;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.input.CountingInputStream;
@@ -68,6 +67,8 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.jenkinsci.remoting.Role;
import org.jenkinsci.remoting.RoleSensitive;
import org.kohsuke.stapler.Stapler;
import javax.annotation.Nonnull;
@@ -94,6 +95,8 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
@@ -432,7 +435,7 @@ public final class FilePath implements Serializable {
*/
public int archive(final ArchiverFactory factory, OutputStream os, final DirScanner scanner) throws IOException, InterruptedException {
final OutputStream out = (channel!=null)?new RemoteOutputStream(os):os;
return act(new FileCallable<Integer>() {
return act(new SecureFileCallable<Integer>() {
public Integer invoke(File f, VirtualChannel channel) throws IOException {
Archiver a = factory.create(out);
try {
@@ -464,7 +467,7 @@ public final class FilePath implements Serializable {
* @see #unzipFrom(InputStream)
*/
public void unzip(final FilePath target) throws IOException, InterruptedException {
target.act(new FileCallable<Void>() {
target.act(new SecureFileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
if (FilePath.this.isRemote())
@@ -488,7 +491,7 @@ public final class FilePath implements Serializable {
* @see #untarFrom(InputStream, TarCompression)
*/
public void untar(final FilePath target, final TarCompression compression) throws IOException, InterruptedException {
target.act(new FileCallable<Void>() {
target.act(new SecureFileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
readFromTar(FilePath.this.getName(),dir,compression.extract(FilePath.this.read()));
return null;
@@ -507,7 +510,7 @@ public final class FilePath implements Serializable {
*/
public void unzipFrom(InputStream _in) throws IOException, InterruptedException {
final InputStream in = new RemoteInputStream(_in);
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException {
unzip(dir, in);
return null;
@@ -566,7 +569,7 @@ public final class FilePath implements Serializable {
* Absolutizes this {@link FilePath} and returns the new one.
*/
public FilePath absolutize() throws IOException, InterruptedException {
return new FilePath(channel,act(new FileCallable<String>() {
return new FilePath(channel,act(new SecureFileCallable<String>() {
private static final long serialVersionUID = 1L;
public String invoke(File f, VirtualChannel channel) throws IOException {
return f.getAbsolutePath();
@@ -584,7 +587,7 @@ public final class FilePath implements Serializable {
* @since 1.456
*/
public void symlinkTo(final String target, final TaskListener listener) throws IOException, InterruptedException {
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
writing(f);
@@ -602,7 +605,7 @@ public final class FilePath implements Serializable {
* @since 1.456
*/
public String readLink() throws IOException, InterruptedException {
return act(new FileCallable<String>() {
return act(new SecureFileCallable<String>() {
private static final long serialVersionUID = 1L;
public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return Util.resolveSymlink(reading(f));
@@ -676,7 +679,7 @@ public final class FilePath implements Serializable {
public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException {
try {
final InputStream in = new RemoteInputStream(_in);
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
public Void invoke(File dir, VirtualChannel channel) throws IOException {
readFromTar("input stream",dir, compression.extract(in));
return null;
@@ -786,8 +789,8 @@ public final class FilePath implements Serializable {
}
}
@MasterToSlave // this reads from arbitrary URL
private final class Unpack implements FileCallable<Void> {
// this reads from arbitrary URL
private final class Unpack extends MasterToSlaveFileCallable<Void> {
private final URL archive;
Unpack(URL archive) {
this.archive = archive;
@@ -881,9 +884,14 @@ public final class FilePath implements Serializable {
* Code that gets executed on the machine where the {@link FilePath} is local.
* Used to act on {@link FilePath}.
* <strong>Warning:</code> implementations must be serializable, so prefer a static nested class to an inner class.
*
* <p>
* Subtypes would likely want to extend from either {@link MasterToSlaveCallable}
* or {@link SlaveToMasterFileCallable}.
*
* @see FilePath#act(FileCallable)
*/
public interface FileCallable<T> extends Serializable {
public interface FileCallable<T> extends Serializable, RoleSensitive {
/**
* Performs the computational task on the node where the data is located.
*
@@ -899,6 +907,37 @@ public final class FilePath implements Serializable {
T invoke(File f, VirtualChannel channel) throws IOException, InterruptedException;
}
/**
* {@link FileCallable}s that are meant to be only used on the master.
*/
public static abstract class MasterToSlaveFileCallable<T> implements FileCallable<T> {
@Override
public Collection<Role> getRecipients() {
return Roles.FOR_SLAVE;
}
private static final long serialVersionUID = 1L;
}
/**
* {@link FileCallable}s that can be executed on the master, sent by the slave.
*/
public static abstract class SlaveToMasterFileCallable<T> implements FileCallable<T> {
@Override
public Collection<Role> getRecipients() {
return Roles.FOR_MASTER;
}
private static final long serialVersionUID = 1L;
}
/**
* {@link FileCallable}s that can be executed anywhere, including the master.
*
* The code is the same as {@link SlaveToMasterFileCallable}, but used as a marker to
* designate those impls that use {@link FilePathFilter}.
*/
/*package*/ static abstract class SecureFileCallable<T> extends SlaveToMasterFileCallable<T> {
}
/**
* Executes some program on the machine that this {@link FilePath} exists,
* so that one can perform local file operations.
@@ -1044,6 +1083,12 @@ public final class FilePath implements Serializable {
throw (IOException)new InterruptedIOException().initCause(e);
}
}
@Override
public Collection<Role> getRecipients() {
return task.getRecipients();
}
private static final long serialVersionUID = 1L;
};
}
@@ -1053,7 +1098,7 @@ public final class FilePath implements Serializable {
* on which this file is available.
*/
public URI toURI() throws IOException, InterruptedException {
return act(new FileCallable<URI>() {
return act(new SecureFileCallable<URI>() {
private static final long serialVersionUID = 1L;
public URI invoke(File f, VirtualChannel channel) {
return f.toURI();
@@ -1074,7 +1119,7 @@ public final class FilePath implements Serializable {
* Creates this directory.
*/
public void mkdirs() throws IOException, InterruptedException {
if(!act(new FileCallable<Boolean>() {
if(!act(new SecureFileCallable<Boolean>() {
private static final long serialVersionUID = 1L;
public Boolean invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
if(mkdirs(f) || f.exists())
@@ -1093,7 +1138,7 @@ public final class FilePath implements Serializable {
* Deletes this directory, including all its contents recursively.
*/
public void deleteRecursive() throws IOException, InterruptedException {
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
deleteRecursive(deleting(f));
@@ -1106,7 +1151,7 @@ public final class FilePath implements Serializable {
* Deletes all the contents of this directory, but not the directory itself
*/
public void deleteContents() throws IOException, InterruptedException {
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
deleteContentsRecursive(f);
@@ -1223,7 +1268,7 @@ public final class FilePath implements Serializable {
*/
public FilePath createTempFile(final String prefix, final String suffix) throws IOException, InterruptedException {
try {
return new FilePath(this,act(new FileCallable<String>() {
return new FilePath(this,act(new SecureFileCallable<String>() {
private static final long serialVersionUID = 1L;
public String invoke(File dir, VirtualChannel channel) throws IOException {
File f = writing(File.createTempFile(prefix, suffix, dir));
@@ -1279,7 +1324,7 @@ public final class FilePath implements Serializable {
*/
public FilePath createTextTempFile(final String prefix, final String suffix, final String contents, final boolean inThisDirectory) throws IOException, InterruptedException {
try {
return new FilePath(channel,act(new FileCallable<String>() {
return new FilePath(channel,act(new SecureFileCallable<String>() {
private static final long serialVersionUID = 1L;
public String invoke(File dir, VirtualChannel channel) throws IOException {
if(!inThisDirectory)
@@ -1325,7 +1370,7 @@ public final class FilePath implements Serializable {
*/
public FilePath createTempDir(final String prefix, final String suffix) throws IOException, InterruptedException {
try {
return new FilePath(this,act(new FileCallable<String>() {
return new FilePath(this,act(new SecureFileCallable<String>() {
private static final long serialVersionUID = 1L;
public String invoke(File dir, VirtualChannel channel) throws IOException {
File f = File.createTempFile(prefix, suffix, dir);
@@ -1345,7 +1390,7 @@ public final class FilePath implements Serializable {
* @return true, for a modicum of compatibility
*/
public boolean delete() throws IOException, InterruptedException {
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
Util.deleteFile(deleting(f));
@@ -1359,7 +1404,7 @@ public final class FilePath implements Serializable {
* Checks if the file exists.
*/
public boolean exists() throws IOException, InterruptedException {
return act(new FileCallable<Boolean>() {
return act(new SecureFileCallable<Boolean>() {
private static final long serialVersionUID = 1L;
public Boolean invoke(File f, VirtualChannel channel) throws IOException {
return stating(f).exists();
@@ -1375,7 +1420,7 @@ public final class FilePath implements Serializable {
* @see #touch(long)
*/
public long lastModified() throws IOException, InterruptedException {
return act(new FileCallable<Long>() {
return act(new SecureFileCallable<Long>() {
private static final long serialVersionUID = 1L;
public Long invoke(File f, VirtualChannel channel) throws IOException {
return stating(f).lastModified();
@@ -1389,7 +1434,7 @@ public final class FilePath implements Serializable {
* @since 1.299
*/
public void touch(final long timestamp) throws IOException, InterruptedException {
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = -5094638816500738429L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
if(!f.exists())
@@ -1402,7 +1447,7 @@ public final class FilePath implements Serializable {
}
private void setLastModifiedIfPossible(final long timestamp) throws IOException, InterruptedException {
String message = act(new FileCallable<String>() {
String message = act(new SecureFileCallable<String>() {
private static final long serialVersionUID = -828220335793641630L;
public String invoke(File f, VirtualChannel channel) throws IOException {
if(!writing(f).setLastModified(timestamp)) {
@@ -1427,7 +1472,7 @@ public final class FilePath implements Serializable {
* Checks if the file is a directory.
*/
public boolean isDirectory() throws IOException, InterruptedException {
return act(new FileCallable<Boolean>() {
return act(new SecureFileCallable<Boolean>() {
private static final long serialVersionUID = 1L;
public Boolean invoke(File f, VirtualChannel channel) throws IOException {
return stating(f).isDirectory();
@@ -1441,7 +1486,7 @@ public final class FilePath implements Serializable {
* @since 1.129
*/
public long length() throws IOException, InterruptedException {
return act(new FileCallable<Long>() {
return act(new SecureFileCallable<Long>() {
private static final long serialVersionUID = 1L;
public Long invoke(File f, VirtualChannel channel) throws IOException {
return stating(f).length();
@@ -1466,7 +1511,7 @@ public final class FilePath implements Serializable {
*/
public void chmod(final int mask) throws IOException, InterruptedException {
if(!isUnix() || mask==-1) return;
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
_chmod(writing(f), mask);
@@ -1517,7 +1562,7 @@ public final class FilePath implements Serializable {
*/
public int mode() throws IOException, InterruptedException, PosixException {
if(!isUnix()) return -1;
return act(new FileCallable<Integer>() {
return act(new SecureFileCallable<Integer>() {
private static final long serialVersionUID = 1L;
public Integer invoke(File f, VirtualChannel channel) throws IOException {
return IOUtils.mode(stating(f));
@@ -1564,7 +1609,7 @@ public final class FilePath implements Serializable {
if (filter != null && !(filter instanceof Serializable)) {
throw new IllegalArgumentException("Non-serializable filter of " + filter.getClass());
}
return act(new FileCallable<List<FilePath>>() {
return act(new SecureFileCallable<List<FilePath>>() {
private static final long serialVersionUID = 1L;
public List<FilePath> invoke(File f, VirtualChannel channel) throws IOException {
File[] children = reading(f).listFiles(filter);
@@ -1617,7 +1662,7 @@ public final class FilePath implements Serializable {
* @since 1.465
*/
public FilePath[] list(final String includes, final String excludes, final boolean defaultExcludes) throws IOException, InterruptedException {
return act(new FileCallable<FilePath[]>() {
return act(new SecureFileCallable<FilePath[]>() {
private static final long serialVersionUID = 1L;
public FilePath[] invoke(File f, VirtualChannel channel) throws IOException {
String[] files = glob(reading(f), includes, excludes, defaultExcludes);
@@ -1655,7 +1700,7 @@ public final class FilePath implements Serializable {
return new FileInputStream(reading(new File(remote)));
final Pipe p = Pipe.createRemoteToLocal();
actAsync(new FileCallable<Void>() {
actAsync(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
@Override
@@ -1709,7 +1754,7 @@ public final class FilePath implements Serializable {
return new FileOutputStream(writing(f));
}
return act(new FileCallable<OutputStream>() {
return act(new SecureFileCallable<OutputStream>() {
private static final long serialVersionUID = 1L;
public OutputStream invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
f = f.getAbsoluteFile();
@@ -1728,7 +1773,7 @@ public final class FilePath implements Serializable {
* @since 1.105
*/
public void write(final String content, final String encoding) throws IOException, InterruptedException {
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
mkdirs(f.getParentFile());
@@ -1749,7 +1794,7 @@ public final class FilePath implements Serializable {
* @see Util#getDigestOf(File)
*/
public String digest() throws IOException, InterruptedException {
return act(new FileCallable<String>() {
return act(new SecureFileCallable<String>() {
private static final long serialVersionUID = 1L;
public String invoke(File f, VirtualChannel channel) throws IOException {
return Util.getDigestOf(reading(f));
@@ -1765,7 +1810,7 @@ public final class FilePath implements Serializable {
if(this.channel != target.channel) {
throw new IOException("renameTo target must be on the same host");
}
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
reading(f).renameTo(creating(new File(target.remote)));
@@ -1783,7 +1828,7 @@ public final class FilePath implements Serializable {
if(this.channel != target.channel) {
throw new IOException("pullUpTo target must be on the same host");
}
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
File t = new File(target.getRemote());
@@ -1832,7 +1877,7 @@ public final class FilePath implements Serializable {
public void copyTo(OutputStream os) throws IOException, InterruptedException {
final OutputStream out = new RemoteOutputStream(os);
act(new FileCallable<Void>() {
act(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 4088559042349254141L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
FileInputStream fis = null;
@@ -1933,7 +1978,7 @@ public final class FilePath implements Serializable {
public int copyRecursiveTo(final DirScanner scanner, final FilePath target, final String description) throws IOException, InterruptedException {
if(this.channel==target.channel) {
// local to local copy.
return act(new FileCallable<Integer>() {
return act(new SecureFileCallable<Integer>() {
private static final long serialVersionUID = 1L;
public Integer invoke(File base, VirtualChannel channel) throws IOException {
if(!base.exists()) return 0;
@@ -1975,7 +2020,7 @@ public final class FilePath implements Serializable {
// local -> remote copy
final Pipe pipe = Pipe.createLocalToRemote();
Future<Void> future = target.actAsync(new FileCallable<Void>() {
Future<Void> future = target.actAsync(new SecureFileCallable<Void>() {
private static final long serialVersionUID = 1L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
try {
@@ -1986,7 +2031,7 @@ public final class FilePath implements Serializable {
}
}
});
Future<Integer> future2 = actAsync(new FileCallable<Integer>() {
Future<Integer> future2 = actAsync(new SecureFileCallable<Integer>() {
private static final long serialVersionUID = 1L;
@Override public Integer invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return writeToTar(new File(remote), scanner, TarCompression.GZIP.compress(pipe.getOut()));
@@ -2003,7 +2048,7 @@ public final class FilePath implements Serializable {
// remote -> local copy
final Pipe pipe = Pipe.createRemoteToLocal();
Future<Integer> future = actAsync(new FileCallable<Integer>() {
Future<Integer> future = actAsync(new SecureFileCallable<Integer>() {
private static final long serialVersionUID = 1L;
public Integer invoke(File f, VirtualChannel channel) throws IOException {
try {
@@ -2126,8 +2171,7 @@ public final class FilePath implements Serializable {
return new RemoteLauncher(listener,channel,channel.call(new IsUnix()));
}
@MasterToSlave @SlaveToMaster
private static final class IsUnix implements Callable<Boolean,IOException> {
private static final class IsUnix extends MasterToSlaveCallable<Boolean,IOException> {
public Boolean call() throws IOException {
return File.pathSeparatorChar==':';
}
@@ -2164,7 +2208,7 @@ public final class FilePath implements Serializable {
* @since 1.484
*/
public String validateAntFileMask(final String fileMasks, final int bound) throws IOException, InterruptedException {
return act(new FileCallable<String>() {
return act(new MasterToSlaveFileCallable<String>() {
private static final long serialVersionUID = 1;
public String invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
if(fileMasks.startsWith("~"))
@@ -2467,8 +2511,6 @@ public final class FilePath implements Serializable {
/**
* Adapts {@link FileCallable} to {@link Callable}.
*/
@MasterToSlave // the normal case
@SlaveToMaster // possible, but triggers FilePathFilter
private class FileCallableWrapper<T> implements DelegatingCallable<T,IOException> {
private final FileCallable<T> callable;
private transient ClassLoader classLoader;
@@ -2491,6 +2533,14 @@ public final class FilePath implements Serializable {
}
}
/**
* Role check comes from {@link FileCallable}s.
*/
@Override
public Collection<Role> getRecipients() {
return callable.getRecipients();
}
public ClassLoader getClassLoader() {
return classLoader;
}
+4 -7
View File
@@ -38,7 +38,7 @@ import hudson.remoting.VirtualChannel;
import hudson.util.StreamCopyThread;
import hudson.util.ArgumentListBuilder;
import hudson.util.ProcessTree;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.io.input.NullInputStream;
import java.io.BufferedOutputStream;
@@ -888,8 +888,7 @@ public abstract class Launcher {
getChannel().call(new KillTask(modelEnvVars));
}
@MasterToSlave
private static final class KillTask implements Callable<Void,RuntimeException> {
private static final class KillTask extends MasterToSlaveCallable<Void,RuntimeException> {
private final Map<String, String> modelEnvVars;
public KillTask(Map<String, String> modelEnvVars) {
@@ -964,8 +963,7 @@ public abstract class Launcher {
IOTriplet getIOtriplet();
}
@MasterToSlave
private static class RemoteLaunchCallable implements Callable<RemoteProcess,IOException> {
private static class RemoteLaunchCallable extends MasterToSlaveCallable<RemoteProcess,IOException> {
private final List<String> cmd;
private final boolean[] masks;
private final String[] env;
@@ -1035,8 +1033,7 @@ public abstract class Launcher {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static class RemoteChannelLaunchCallable implements Callable<OutputStream,IOException> {
private static class RemoteChannelLaunchCallable extends MasterToSlaveCallable<OutputStream,IOException> {
private final String[] cmd;
private final Pipe out;
private final String workDir;
@@ -36,8 +36,7 @@ import hudson.remoting.Channel;
import hudson.remoting.ChannelProperty;
import hudson.security.CliAuthenticator;
import hudson.security.SecurityRealm;
import jenkins.security.MasterToSlave;
import jenkins.security.SlaveToMaster;
import jenkins.security.MasterToSlaveCallable;
import org.acegisecurity.Authentication;
import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.context.SecurityContext;
@@ -361,8 +360,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
return checkChannel().call(new GetSystemProperty(name));
}
@MasterToSlave
private static final class GetSystemProperty implements Callable<String, IOException> {
private static final class GetSystemProperty extends MasterToSlaveCallable<String, IOException> {
private final String name;
private GetSystemProperty(String name) {
@@ -391,8 +389,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
}
}
@MasterToSlave @SlaveToMaster
private static final class GetCharset implements Callable<String, IOException> {
private static final class GetCharset extends MasterToSlaveCallable<String, IOException> {
public String call() throws IOException {
return Charset.defaultCharset().name();
}
@@ -407,8 +404,7 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
return checkChannel().call(new GetEnvironmentVariable(name));
}
@MasterToSlave
private static final class GetEnvironmentVariable implements Callable<String, IOException> {
private static final class GetEnvironmentVariable extends MasterToSlaveCallable<String, IOException> {
private final String name;
private GetEnvironmentVariable(String name) {
@@ -28,7 +28,7 @@ import jenkins.model.Jenkins;
import hudson.model.Job;
import hudson.model.Run;
import hudson.remoting.Callable;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.args4j.CmdLineException;
import java.io.IOException;
@@ -82,8 +82,7 @@ public abstract class CommandDuringBuild extends CLICommand {
/**
* Gets the environment variables that points to the build being executed.
*/
@MasterToSlave
private static final class GetCharacteristicEnvironmentVariables implements Callable<String[],IOException> {
private static final class GetCharacteristicEnvironmentVariables extends MasterToSlaveCallable<String[],IOException> {
public String[] call() throws IOException {
return new String[] {
System.getenv("JOB_NAME"),
@@ -31,10 +31,7 @@ import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.Executor;
import hudson.model.Node;
import hudson.model.EnvironmentSpecific;
import hudson.model.Item;
import hudson.remoting.Callable;
import hudson.slaves.NodeSpecific;
import hudson.util.EditDistance;
import hudson.util.StreamTaskListener;
import hudson.tools.ToolDescriptor;
@@ -44,7 +41,7 @@ import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.args4j.Argument;
/**
@@ -129,8 +126,7 @@ public class InstallToolCommand extends CLICommand {
return 0;
}
@MasterToSlave
private static final class BuildIDs implements Callable<BuildIDs, IOException> {
private static final class BuildIDs extends MasterToSlaveCallable<BuildIDs, IOException> {
String job,number,id;
public BuildIDs call() throws IOException {
@@ -1,8 +1,7 @@
package hudson.cli.util;
import hudson.AbortException;
import hudson.remoting.Callable;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
@@ -17,8 +16,7 @@ import java.net.URL;
*
* @author vjuranek
*/
@MasterToSlave
public class ScriptLoader implements Callable<String,IOException> {
public class ScriptLoader extends MasterToSlaveCallable<String,IOException> {
private final String script;
@@ -42,7 +42,7 @@ import hudson.slaves.ComputerListener;
import hudson.util.CopyOnWriteList;
import hudson.util.RingBufferLogHandler;
import hudson.util.XStream2;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
@@ -161,8 +161,7 @@ public class LogRecorder extends AbstractModelObject implements Saveable {
}
@MasterToSlave
private static final class SetLevel implements Callable<Void,Error> {
private static final class SetLevel extends MasterToSlaveCallable<Void,Error> {
/** known loggers (kept per slave), to avoid GC */
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private static final Set<Logger> loggers = new HashSet<Logger>();
private final String name;
@@ -34,7 +34,6 @@ import hudson.cli.declarative.CLIMethod;
import hudson.cli.declarative.CLIResolver;
import hudson.model.listeners.ItemListener;
import hudson.model.listeners.SaveableListener;
import hudson.remoting.Callable;
import hudson.security.AccessControlled;
import hudson.security.Permission;
import hudson.security.ACL;
@@ -44,6 +43,7 @@ import hudson.util.AtomicFileWriter;
import hudson.util.IOException2;
import hudson.util.IOUtils;
import jenkins.model.Jenkins;
import jenkins.security.NotReallyRoleSensitiveCallable;
import org.acegisecurity.Authentication;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.types.FileSet;
@@ -216,7 +216,7 @@ public abstract class AbstractItem extends Actionable implements Item, HttpDelet
// the test to see if the project already exists or not needs to be done in escalated privilege
// to avoid overwriting
ACL.impersonate(ACL.SYSTEM,new Callable<Void,IOException>() {
ACL.impersonate(ACL.SYSTEM,new NotReallyRoleSensitiveCallable<Void,IOException>() {
final Authentication user = Jenkins.getAuthentication();
@Override
public Void call() throws IOException {
@@ -58,7 +58,7 @@ import hudson.util.RemotingDiagnostics.HeapDump;
import hudson.util.RunList;
import hudson.util.Futures;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.stapler.StaplerRequest;
@@ -1025,8 +1025,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
oneOffExecutors.remove(e);
}
@MasterToSlave
private static class ListPossibleNames implements Callable<List<String>,IOException> {
private static class ListPossibleNames extends MasterToSlaveCallable<List<String>,IOException> {
public List<String> call() throws IOException {
List<String> names = new ArrayList<String>();
@@ -1056,8 +1055,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static class GetFallbackName implements Callable<String,IOException> {
private static class GetFallbackName extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
return System.getProperty("host.name");
}
@@ -1146,8 +1144,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
w.close();
}
@MasterToSlave
private static final class DumpExportTableTask implements Callable<String,IOException> {
private static final class DumpExportTableTask extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
+3 -6
View File
@@ -58,7 +58,7 @@ import javax.servlet.ServletException;
import hudson.util.TimeUnit2;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import jenkins.slaves.WorkspaceLocator;
import org.apache.commons.io.IOUtils;
@@ -439,8 +439,7 @@ public abstract class Slave extends Node implements Serializable {
* <li>When it's read on this side as a return value, it morphs itself into {@link ClockDifference}.
* </ol>
*/
@MasterToSlave
private static final class GetClockDifference1 implements Callable<ClockDifference,IOException> {
private static final class GetClockDifference1 extends MasterToSlaveCallable<ClockDifference,IOException> {
public ClockDifference call() {
// this method must be being invoked locally, which means the clock is in sync
return new ClockDifference(0);
@@ -453,8 +452,7 @@ public abstract class Slave extends Node implements Serializable {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static final class GetClockDifference2 implements Callable<GetClockDifference3,IOException> {
private static final class GetClockDifference2 extends MasterToSlaveCallable<GetClockDifference3,IOException> {
/**
* Capture the time on the master when this object is sent to remote, which is when
* {@link GetClockDifference1#writeReplace()} is run.
@@ -468,7 +466,6 @@ public abstract class Slave extends Node implements Serializable {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static final class GetClockDifference3 implements Serializable {
private final long remoteTime = System.currentTimeMillis();
private final long startTime;
@@ -26,7 +26,7 @@ package hudson.node_monitors;
import hudson.model.Computer;
import hudson.remoting.Callable;
import hudson.Extension;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
@@ -57,8 +57,7 @@ public class ArchitectureMonitor extends NodeMonitor {
/**
* Obtains the string that represents the architecture.
*/
@MasterToSlave
private static class GetArchTask implements Callable<String,IOException> {
private static class GetArchTask extends MasterToSlaveCallable<String,IOException> {
public String call() {
String os = System.getProperty("os.name");
String arch = System.getProperty("os.arch");
@@ -23,8 +23,7 @@
*/
package hudson.node_monitors;
import hudson.FilePath.FileCallable;
import hudson.model.Computer;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.remoting.VirtualChannel;
import hudson.Util;
import hudson.slaves.OfflineCause;
@@ -159,7 +158,7 @@ public abstract class DiskSpaceMonitorDescriptor extends AbstractAsyncNodeMonito
private static final long serialVersionUID = 2L;
}
protected static final class GetUsableSpace implements FileCallable<DiskSpace> {
protected static final class GetUsableSpace extends MasterToSlaveFileCallable<DiskSpace> {
public GetUsableSpace() {}
@IgnoreJRERequirement
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException {
@@ -32,8 +32,7 @@ import hudson.remoting.Future;
import hudson.util.ClockDifference;
import hudson.util.TimeUnit2;
import hudson.util.IOException2;
import jenkins.security.MasterToSlave;
import jenkins.security.SlaveToMaster;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
@@ -94,8 +93,7 @@ public class ResponseTimeMonitor extends NodeMonitor {
}
};
@MasterToSlave
private static final class Step1 implements Callable<Data,IOException> {
private static final class Step1 extends MasterToSlaveCallable<Data,IOException> {
private Data cur;
private Step1(Data cur) {
@@ -114,8 +112,7 @@ public class ResponseTimeMonitor extends NodeMonitor {
private static final long serialVersionUID = 1L;
}
@MasterToSlave
private static final class Step2 implements Callable<Step3,IOException> {
private static final class Step2 extends MasterToSlaveCallable<Step3,IOException> {
private final Data cur;
private final long start = System.currentTimeMillis();
@@ -131,7 +128,6 @@ public class ResponseTimeMonitor extends NodeMonitor {
private static final long serialVersionUID = 1L;
}
@SlaveToMaster
private static final class Step3 implements Serializable {
private final Data cur;
private final long start;
@@ -27,8 +27,7 @@ import hudson.Util;
import hudson.Extension;
import hudson.model.Computer;
import jenkins.model.Jenkins;
import hudson.remoting.Callable;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.jvnet.hudson.MemoryMonitor;
import org.jvnet.hudson.MemoryUsage;
@@ -98,8 +97,7 @@ public class SwapSpaceMonitor extends NodeMonitor {
/**
* Obtains the string that represents the architecture.
*/
@MasterToSlave
private static class MonitorTask implements Callable<MemoryUsage,IOException> {
private static class MonitorTask extends MasterToSlaveCallable<MemoryUsage,IOException> {
public MemoryUsage call() throws IOException {
MemoryMonitor mm;
try {
@@ -25,7 +25,7 @@ package hudson.node_monitors;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Functions;
import hudson.model.Computer;
import hudson.remoting.Callable;
@@ -82,7 +82,7 @@ public class TemporarySpaceMonitor extends AbstractDiskSpaceMonitor {
return null;
}
protected static final class GetTempSpace implements FileCallable<DiskSpace> {
protected static final class GetTempSpace extends MasterToSlaveFileCallable<DiskSpace> {
@IgnoreJRERequirement
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException {
try {
@@ -23,13 +23,13 @@
*/
package hudson.os.solaris;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.FileSystemProvisioner;
import hudson.FilePath;
import hudson.WorkspaceSnapshot;
import hudson.FileSystemProvisionerDescriptor;
import hudson.Extension;
import hudson.remoting.VirtualChannel;
import hudson.FilePath.FileCallable;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.model.AbstractProject;
@@ -52,7 +52,7 @@ public class ZFSProvisioner extends FileSystemProvisioner implements Serializabl
private final String rootDataset;
public ZFSProvisioner(Node node) throws IOException, InterruptedException {
rootDataset = node.getRootPath().act(new FileCallable<String>() {
rootDataset = node.getRootPath().act(new MasterToSlaveFileCallable<String>() {
private static final long serialVersionUID = -2142349338699797436L;
public String invoke(File f, VirtualChannel channel) throws IOException {
@@ -68,7 +68,7 @@ public class ZFSProvisioner extends FileSystemProvisioner implements Serializabl
public void prepareWorkspace(AbstractBuild<?,?> build, FilePath ws, final TaskListener listener) throws IOException, InterruptedException {
final String name = build.getProject().getFullName();
ws.act(new FileCallable<Void>() {
ws.act(new MasterToSlaveFileCallable<Void>() {
private static final long serialVersionUID = 2129531727963121198L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
@@ -87,7 +87,7 @@ public class ZFSProvisioner extends FileSystemProvisioner implements Serializabl
}
public void discardWorkspace(AbstractProject<?, ?> project, FilePath ws) throws IOException, InterruptedException {
ws.act(new FileCallable<Void>() {
ws.act(new MasterToSlaveFileCallable<Void>() {
private static final long serialVersionUID = 1916618107019257530L;
public Void invoke(File f, VirtualChannel channel) throws IOException {
@@ -4,9 +4,8 @@ import groovy.lang.Binding;
import hudson.FilePath;
import hudson.cli.CLICommand;
import jenkins.model.Jenkins;
import hudson.remoting.Callable;
import hudson.util.spring.BeanBuilder;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
@@ -141,8 +140,7 @@ public abstract class AbstractPasswordBasedSecurityRealm extends SecurityRealm i
/**
* Asks for the password.
*/
@MasterToSlave
private static class InteractivelyAskForPassword implements Callable<String,IOException> {
private static class InteractivelyAskForPassword extends MasterToSlaveCallable<String,IOException> {
@IgnoreJRERequirement
public String call() throws IOException {
Console console = System.console();
@@ -28,10 +28,9 @@ import hudson.FilePath;
import hudson.model.Computer;
import hudson.model.Slave;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.PingThread;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -86,8 +85,7 @@ public class ChannelPinger extends ComputerListener {
setUpPingForChannel(channel, pingInterval);
}
@MasterToSlave
private static class SetUpRemotePing implements Callable<Void, IOException> {
private static class SetUpRemotePing extends MasterToSlaveCallable<Void, IOException> {
private static final long serialVersionUID = -2702219700841759872L;
private int pingInterval;
public SetUpRemotePing(int pingInterval) {
@@ -30,10 +30,8 @@ import hudson.model.Computer;
import hudson.util.TimeUnit2;
import hudson.remoting.VirtualChannel;
import hudson.remoting.Channel;
import hudson.remoting.Callable;
import hudson.Extension;
import jenkins.security.MasterToSlave;
import jenkins.security.SlaveToMaster;
import jenkins.security.SlaveToMasterCallable;
import java.io.IOException;
import java.util.logging.Logger;
@@ -104,8 +102,7 @@ public class ConnectionActivityMonitor extends AsyncPeriodicWork {
public boolean enabled = Boolean.getBoolean(ConnectionActivityMonitor.class.getName()+".enabled");
private static final PingCommand PING_COMMAND = new PingCommand();
@MasterToSlave @SlaveToMaster
private static final class PingCommand implements Callable<Void,RuntimeException> {
private static final class PingCommand extends SlaveToMasterCallable<Void,RuntimeException> {
public Void call() throws RuntimeException {
return null;
}
@@ -72,8 +72,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.RequestDispatcher;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.SlaveToMaster;
import jenkins.security.MasterToSlaveCallable;
import jenkins.slaves.JnlpSlaveAgentProtocol;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -401,8 +400,7 @@ public class SlaveComputer extends Computer {
return channel.call(new LoadingTime(true));
}
@MasterToSlave @SlaveToMaster
static class LoadingCount implements Callable<Integer,RuntimeException> {
static class LoadingCount extends MasterToSlaveCallable<Integer,RuntimeException> {
private final boolean resource;
LoadingCount(boolean resource) {
this.resource = resource;
@@ -413,15 +411,13 @@ public class SlaveComputer extends Computer {
}
}
@MasterToSlave
static class LoadingPrefetchCacheCount implements Callable<Integer,RuntimeException> {
static class LoadingPrefetchCacheCount extends MasterToSlaveCallable<Integer,RuntimeException> {
@Override public Integer call() {
return Channel.current().classLoadingPrefetchCacheCount.get();
}
}
@MasterToSlave
static class LoadingTime implements Callable<Long,RuntimeException> {
static class LoadingTime extends MasterToSlaveCallable<Long,RuntimeException> {
private final boolean resource;
LoadingTime(boolean resource) {
this.resource = resource;
@@ -716,22 +712,19 @@ public class SlaveComputer extends Computer {
private static final Logger logger = Logger.getLogger(SlaveComputer.class.getName());
@MasterToSlave
private static final class SlaveVersion implements Callable<String,IOException> {
private static final class SlaveVersion extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
try { return Launcher.VERSION; }
catch (Throwable ex) { return "< 1.335"; } // Older slave.jar won't have VERSION
}
}
@MasterToSlave @SlaveToMaster
private static final class DetectOS implements Callable<Boolean,IOException> {
private static final class DetectOS extends MasterToSlaveCallable<Boolean,IOException> {
public Boolean call() throws IOException {
return File.pathSeparatorChar==':';
}
}
@MasterToSlave @SlaveToMaster
private static final class DetectDefaultCharset implements Callable<String,IOException> {
private static final class DetectDefaultCharset extends MasterToSlaveCallable<String,IOException> {
public String call() throws IOException {
return Charset.defaultCharset().name();
}
@@ -748,8 +741,7 @@ public class SlaveComputer extends Computer {
static final RingBufferLogHandler SLAVE_LOG_HANDLER = new RingBufferLogHandler();
}
@MasterToSlave
private static class SlaveInitializer implements Callable<Void,RuntimeException> {
private static class SlaveInitializer extends MasterToSlaveCallable<Void,RuntimeException> {
public Void call() {
// avoid double installation of the handler. JNLP slaves can reconnect to the master multiple times
// and each connection gets a different RemoteClassLoader, so we need to evict them by class name,
@@ -796,8 +788,7 @@ public class SlaveComputer extends Computer {
return null;
}
@MasterToSlave
private static class SlaveLogFetcher implements Callable<List<LogRecord>,RuntimeException> {
private static class SlaveLogFetcher extends MasterToSlaveCallable<List<LogRecord>,RuntimeException> {
public List<LogRecord> call() {
return new ArrayList<LogRecord>(SLAVE_LOG_HANDLER.getView());
}
@@ -24,6 +24,7 @@
package hudson.tasks;
import hudson.FilePath;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.Extension;
@@ -169,7 +170,7 @@ public class ArtifactArchiver extends Recorder {
return true;
}
private static final class ListFiles implements FilePath.FileCallable<Map<String,String>> {
private static final class ListFiles extends MasterToSlaveFileCallable<Map<String,String>> {
private static final long serialVersionUID = 1;
private final String includes, excludes;
ListFiles(String includes, String excludes) {
@@ -28,6 +28,7 @@ import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.matrix.MatrixConfiguration;
@@ -220,7 +221,7 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
return;
}
List<Record> records = ws.act(new FileCallable<List<Record>>() {
List<Record> records = ws.act(new MasterToSlaveFileCallable<List<Record>>() {
public List<Record> invoke(File baseDir, VirtualChannel channel) throws IOException {
List<Record> results = new ArrayList<Record>();
+2 -1
View File
@@ -24,6 +24,7 @@
package hudson.tasks;
import hudson.Extension;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Functions;
import hudson.EnvVars;
@@ -219,7 +220,7 @@ public class Maven extends Builder {
* Looks for <tt>pom.xlm</tt> or <tt>project.xml</tt> to determine the maven executable
* name.
*/
private static final class DecideDefaultMavenCommand implements FileCallable<String> {
private static final class DecideDefaultMavenCommand extends MasterToSlaveFileCallable<String> {
private static final long serialVersionUID = -2327576423452215146L;
// command line arguments.
private final String arguments;
+2 -4
View File
@@ -28,12 +28,11 @@ import hudson.Functions;
import hudson.Util;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.util.FormValidation;
import java.io.IOException;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
@@ -195,8 +194,7 @@ public class Shell extends CommandInterpreter {
return FormValidation.validateExecutable(value);
}
@MasterToSlave
private static final class Shellinterpreter implements Callable<String, IOException> {
private static final class Shellinterpreter extends MasterToSlaveCallable<String, IOException> {
private static final long serialVersionUID = 1L;
@@ -23,6 +23,7 @@
*/
package hudson.tasks.junit;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.model.TaskListener;
import hudson.tasks.test.TestResultParser;
import hudson.model.AbstractBuild;
@@ -87,8 +88,8 @@ public class JUnitParser extends TestResultParser {
return workspace.act(new ParseResultCallable(testResultLocations, buildTime, timeOnMaster, keepLongStdio));
}
private static final class ParseResultCallable implements
FilePath.FileCallable<TestResult> {
private static final class ParseResultCallable extends
MasterToSlaveFileCallable<TestResult> {
private final long buildTime;
private final String testResults;
private final long nowMaster;
@@ -25,7 +25,7 @@ package hudson.tasks.test;
import hudson.AbortException;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractBuild;
@@ -74,7 +74,7 @@ public abstract class DefaultTestResultParserImpl extends TestResultParser imple
@Override
public TestResult parse(final String testResultLocations, final AbstractBuild build, final Launcher launcher, final TaskListener listener) throws InterruptedException, IOException {
return build.getWorkspace().act(new FileCallable<TestResult>() {
return build.getWorkspace().act(new MasterToSlaveFileCallable<TestResult>() {
final boolean ignoreTimestampCheck = IGNORE_TIMESTAMP_CHECK; // so that the property can be set on the master
final long buildTime = build.getTimestamp().getTimeInMillis();
final long nowMaster = System.currentTimeMillis();
@@ -40,7 +40,7 @@ import hudson.util.FormValidation;
import hudson.util.HttpResponses;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
@@ -502,8 +502,7 @@ public class JDKInstaller extends ToolInstaller {
throw new DetectionFailedException("Unknown CPU name: "+arch);
}
@MasterToSlave
static class GetCurrentPlatform implements Callable<Platform,DetectionFailedException> {
static class GetCurrentPlatform extends MasterToSlaveCallable<Platform,DetectionFailedException> {
private static final long serialVersionUID = 1L;
public Platform call() throws DetectionFailedException {
return current();
@@ -565,8 +564,7 @@ public class JDKInstaller extends ToolInstaller {
throw new DetectionFailedException("Unknown CPU architecture: "+arch);
}
@MasterToSlave
static class GetCurrentCPU implements Callable<CPU,DetectionFailedException> {
static class GetCurrentCPU extends MasterToSlaveCallable<CPU,DetectionFailedException> {
private static final long serialVersionUID = 1L;
public CPU call() throws DetectionFailedException {
return current();
@@ -26,7 +26,7 @@ package hudson.tools;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.FilePath.MasterToSlaveFileCallable;
import hudson.ProxyConfiguration;
import hudson.Util;
import hudson.Functions;
@@ -119,7 +119,7 @@ public class ZipExtractionInstaller extends ToolInstaller {
* Sets execute permission on all files, since unzip etc. might not do this.
* Hackish, is there a better way?
*/
static class ChmodRecAPlusX implements FileCallable<Void> {
static class ChmodRecAPlusX extends MasterToSlaveFileCallable<Void> {
private static final long serialVersionUID = 1L;
public Void invoke(File d, VirtualChannel channel) throws IOException {
if(!Functions.isWindows())
@@ -34,7 +34,7 @@ import hudson.remoting.DelegatingCallable;
import hudson.remoting.Future;
import hudson.remoting.VirtualChannel;
import hudson.security.AccessControlled;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.kohsuke.stapler.StaplerRequest;
@@ -71,8 +71,7 @@ public final class RemotingDiagnostics {
return channel.call(new GetSystemProperties());
}
@MasterToSlave
private static final class GetSystemProperties implements Callable<Map<Object,Object>,RuntimeException> {
private static final class GetSystemProperties extends MasterToSlaveCallable<Map<Object,Object>,RuntimeException> {
public Map<Object,Object> call() {
return new TreeMap<Object,Object>(System.getProperties());
}
@@ -91,8 +90,7 @@ public final class RemotingDiagnostics {
return channel.callAsync(new GetThreadDump());
}
@MasterToSlave
private static final class GetThreadDump implements Callable<Map<String,String>,RuntimeException> {
private static final class GetThreadDump extends MasterToSlaveCallable<Map<String,String>,RuntimeException> {
public Map<String,String> call() {
Map<String,String> r = new LinkedHashMap<String,String>();
try {
@@ -122,8 +120,7 @@ public final class RemotingDiagnostics {
return channel.call(new Script(script));
}
@MasterToSlave
private static final class Script implements DelegatingCallable<String,RuntimeException> {
private static final class Script extends MasterToSlaveCallable<String,RuntimeException> implements DelegatingCallable<String,RuntimeException> {
private final String script;
private transient ClassLoader cl;
@@ -205,8 +202,7 @@ public final class RemotingDiagnostics {
}
}
@MasterToSlave
private static class GetHeapDump implements Callable<FilePath, IOException> {
private static class GetHeapDump extends MasterToSlaveCallable<FilePath, IOException> {
public FilePath call() throws IOException {
final File hprof = File.createTempFile("hudson-heapdump", "hprof");
hprof.delete();
@@ -1,25 +0,0 @@
package jenkins.security;
import hudson.remoting.Callable;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Annotates {@link Callable} that this callable is meant to be run on the slave.
*
* @author Kohsuke Kawaguchi
* @see SlaveToMaster
* @since 1.THU
*/
@Retention(RUNTIME)
@Target(TYPE)
@Inherited
@Documented
public @interface MasterToSlave {
}
@@ -1,14 +1,21 @@
package jenkins.security;
import hudson.remoting.Callable;
import org.jenkinsci.remoting.Role;
import java.util.Collection;
/**
* Convenient {@link Callable} with {@link MasterToSlave} to create anonymous Callable class.
* Convenient {@link Callable} meant to be run on slave.
*
* @author Kohsuke Kawaguchi
* @since 1.THU
*/
@MasterToSlave
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements Callable<V,T> {
@Override
public Collection<Role> getRecipients() {
return Roles.FOR_SLAVE;
}
private static final long serialVersionUID = 1L;
}
@@ -0,0 +1,21 @@
package jenkins.security;
import hudson.remoting.Callable;
import org.jenkinsci.remoting.Role;
import java.util.Collection;
/**
* {@link Callable} adapter for situations where Callable is not used for remoting but
* just as a convenient function that has parameterized return value and exception type.
*
* @author Kohsuke Kawaguchi
* @since 1.THU
*/
public abstract class NotReallyRoleSensitiveCallable<V,T extends Throwable> implements Callable<V,T> {
@Override
public final Collection<Role> getRecipients() {
// not meant to be used where this matters
throw new UnsupportedOperationException();
}
}
@@ -1,26 +0,0 @@
package jenkins.security;
import hudson.remoting.Callable;
import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* Annotates {@link Callable} that are meant for the slave to execute on the master.
*
* @author Kohsuke Kawaguchi
* @see MasterToSlave
* @see CallableDirectionChecker
* @since 1.THU
*/
@Retention(RUNTIME)
@Target(TYPE)
@Inherited
@Documented
public @interface SlaveToMaster {
}
@@ -1,14 +1,21 @@
package jenkins.security;
import hudson.remoting.Callable;
import org.jenkinsci.remoting.Role;
import java.util.Collection;
/**
* Convenient {@link Callable} with {@link SlaveToMaster} to create anonymous Callable class.
* Convenient {@link Callable} that are meant to run on the master (sent by slave/CLI/etc).
*
* @author Kohsuke Kawaguchi
* @since 1.THU
*/
@SlaveToMaster
public abstract class SlaveToMasterCallable<V, T extends Throwable> implements Callable<V,T> {
@Override
public Collection<Role> getRecipients() {
return Roles.FOR_MASTER;
}
private static final long serialVersionUID = 1L;
}
@@ -4,12 +4,11 @@ import hudson.Extension;
import hudson.FilePath;
import hudson.model.Computer;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.StandardOutputStream;
import hudson.slaves.ComputerListener;
import hudson.util.jna.GNUCLibrary;
import jenkins.security.MasterToSlave;
import jenkins.security.MasterToSlaveCallable;
import java.io.File;
import java.io.FileDescriptor;
@@ -36,8 +35,7 @@ public class StandardOutputSwapper extends ComputerListener {
}
}
@MasterToSlave
private static final class ChannelSwapper implements Callable<Boolean,Exception> {
private static final class ChannelSwapper extends MasterToSlaveCallable<Boolean,Exception> {
public Boolean call() throws Exception {
if (File.pathSeparatorChar==';') return false; // Windows
@@ -39,6 +39,8 @@ import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import static hudson.FilePath.MasterToSlaveFileCallable;
/**
* Abstraction over {@link File}, {@link FilePath}, or other items such as network resources or ZIP entries.
* Assumed to be read-only and makes very limited assumptions, just enough to display content and traverse directories.
@@ -334,7 +336,7 @@ public abstract class VirtualFile implements Comparable<VirtualFile> {
}
};
}
private static final class Scanner implements FilePath.FileCallable<String[]> {
private static final class Scanner extends MasterToSlaveFileCallable<String[]> {
private final String glob;
Scanner(String glob) {
this.glob = glob;
@@ -351,7 +353,7 @@ public abstract class VirtualFile implements Comparable<VirtualFile> {
}
}
private static final class Readable implements FilePath.FileCallable<Boolean> {
private static final class Readable extends MasterToSlaveFileCallable<Boolean> {
@Override public Boolean invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
return f.canRead();
}