/*
 *
 * Copyright 2014 Applied Visions
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 *
 */

package org.jenkinsci.plugins.codedx;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import hudson.FilePath;

/**
 * Archiving utility class
 *
 * @author anthonyd
 *
 */
public class Archiver {

	private static final Logger log = Logger.getLogger(Archiver.class.getName());

	/**
	 *
	 * Creates zips of the workspace using an array of path filters (in Ant GLOB format)
	 * to determine which files to include in the zip.  The zip file will have a random
	 * name with a specified prefix.
	 *
	 * @param workspace Workspace for the job.
	 * @param paths Paths in the ANT Glob format to include.
	 * @param excludePaths Paths in the ANT Glob format to exclude.
	 * @param prefix Prefix of the zip file to create.
	 * @return The zip archive FilePath.
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static FilePath Archive(FilePath workspace, String[] paths, String[] excludePaths, String prefix, final PrintStream logger) throws IOException, InterruptedException{

		final Set<String> includeFiles = new HashSet<String>();
		final Set<String> excludeFiles = new HashSet<String>();

		//Build up a set of all files to include
		for(String path : paths){

			if(path != null && path.length() > 0){

				for(FilePath match : workspace.list(path)){

					includeFiles.add(match.getRemote());
				};
			}
		}

		//Build up a set of all files to excluded
		for(String path : excludePaths){

			if(path != null && path.length() > 0){

				for(FilePath match : workspace.list(path)){

					excludeFiles.add(match.getRemote());
				};
			}
		}

		if(includeFiles.size() == 0){

			return null;
		}

		//Create our zip file
		final FilePath result = workspace.createTempFile(prefix, ".zip");

		//Zip up the workspace filtering on files to include.
		workspace.zip(result.write(), new FileFilter(){
			public boolean accept(File file) {

				boolean include = includeFiles.contains(file.getAbsolutePath()) && !excludeFiles.contains(file.getAbsolutePath());

				if(include){
					log.log(Level.FINE, "Adding" + file + " to zip");
				}

				return include;
			}

		});

		return result;
	}
}

@@ -649,95 +649,9 @@
 .io.
-File;%0Aimport java.io.FileFilter;%0Aimport java.io.IOException;%0Aimport java.io.PrintStream
+*
 ;%0Aim
@@ -2479,23 +2479,424 @@
 new 
-FileFilter()%7B%0A%09
+SourceAndBinaryFileFilter(includeFiles, excludeFiles));%0A%0A%09%09return result;%0A%09%7D%0A%0A%09private static class SourceAndBinaryFileFilter implements FileFilter, Serializable %7B%0A%09%09private Set%3CString%3E includeFiles;%0A%09%09private Set%3CString%3E excludeFiles;%0A%09%09public SourceAndBinaryFileFilter(final Set%3CString%3E includeFiles, final Set%3CString%3E excludeFiles) %7B%0A%09%09%09this.includeFiles = includeFiles;%0A%09%09%09this.excludeFiles = excludeFiles;%0A%09%09%7D%0A%0A
 %09%09pu
@@ -2928,18 +2928,16 @@
 file) %7B%0A
-%0A%09
 %09%09%09boole
@@ -3050,17 +3050,16 @@
 ));%0A%0A%09%09%09
-%09
 if(inclu
@@ -3061,19 +3061,19 @@
 include)
+ 
 %7B%0A
-%09
 %09%09%09%09log.
@@ -3118,17 +3118,16 @@
  zip%22);%0A
-%09
 %09%09%09%7D%0A%0A%09%09
@@ -3127,17 +3127,16 @@
 %09%09%7D%0A%0A%09%09%09
-%09
 return i
@@ -3149,35 +3149,9 @@
 ;%0A%09%09
-%09%7D%0A%0A%09%09%7D);%0A%0A%09%09return result;
+%7D
 %0A%09%7D%0A

Make Archiver’s FileFilter implementation be serializable