@@ -0,0 +1,2500 @@
+package hudson.remoting;%0A%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.FilenameFilter;%0A%0A/**%0A * Takes a directory of jars and populates them into the given jar cache%0A * directory with the correct hash names.%0A *%0A * %3Cp%3EIdeally this class should exist outside hudson.remoting but unfortunately%0A * it needs access to package-private methods in hudson.remoting.%0A *%0A * @author Akshay Dayal%0A */%0Apublic class InitializeJarCacheMain %7B%0A%0A    private static final FilenameFilter JAR_FILE_FILTER = new FilenameFilter() %7B%0A        @Override%0A        public boolean accept(File dir, String name) %7B%0A            return name.endsWith(%22.jar%22);%0A        %7D%0A    %7D;%0A%0A    /**%0A     * Requires 2 parameters:%0A     * %3Col%3E%0A     * %3Cli%3EThe source jar directory.%0A     * %3Cli%3EThe jar cache directory.%0A     * %3C/ol%3E%0A     */%0A    public static void main(String%5B%5D argv) throws Exception %7B%0A        if (argv.length != 2) %7B%0A            throw new IllegalArgumentException(%0A                    %22Usage: java -cp slave.jar hudson.remoting.InitializeJarCacheMain %22 +%0A                    %22%3Csource jar dir%3E %3Cjar cache dir%3E%22);%0A        %7D%0A%0A        File sourceJarDir = new File(argv%5B0%5D);%0A        File jarCacheDir = new File(argv%5B1%5D);%0A        FileSystemJarCache jarCache = new FileSystemJarCache(jarCacheDir, false);%0A%0A        File%5B%5D jars = sourceJarDir.listFiles(JAR_FILE_FILTER);%0A        for (File jar : jars) %7B%0A            Checksum checksum = Checksum.forFile(jar);%0A            File newJarLocation = jarCache.map(checksum.sum1, checksum.sum2);%0A%0A            newJarLocation.getParentFile().mkdirs();%0A            copyFile(jar, newJarLocation);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Util method to copy file from one location to another.%0A     *%0A     * %3Cp%3EWe don't have access to Guava, apache or Java7, so we have to write%0A     * our own from scratch.%0A     */%0A    private static void copyFile(File src, File dest) throws Exception %7B%0A        FileInputStream input = null;%0A        FileOutputStream output = null;%0A        try %7B%0A            input = new FileInputStream(src);%0A            output = new FileOutputStream(dest);%0A            byte%5B%5D buf = new byte%5B1024 * 1024%5D;%0A            int bytesRead;%0A            while ((bytesRead = input.read(buf)) %3E 0) %7B%0A                output.write(buf, 0, bytesRead);%0A            %7D%0A        %7D finally %7B%0A            if (input != null) %7B%0A                input.close();%0A            %7D%0A            if (output != null) %7B%0A                output.close();%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add a utility main that can populate a jar cache dir given another directory of jars.