Revert stapler changes for guava 18.0
diff --git a/stapler-core/pom.xml b/stapler-core/pom.xml
index 067e513..ef7b160 100644
--- a/stapler-core/pom.xml
+++ b/stapler-core/pom.xml
@@ -123,7 +123,7 @@
         <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
-            <version>18.0</version>
+            <version>r09</version>
             <type>jar</type>
         </dependency>
         
diff --git a/stapler-core/src/main/java/org/eclipse/hudson/stapler/SoftValueDynamicHashMap.java b/stapler-core/src/main/java/org/eclipse/hudson/stapler/SoftValueDynamicHashMap.java
deleted file mode 100644
index 23e07b3..0000000
--- a/stapler-core/src/main/java/org/eclipse/hudson/stapler/SoftValueDynamicHashMap.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.eclipse.hudson.stapler;
-
-import java.lang.ref.SoftReference;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * A very simple implementation of a dynamic hash map that stores soft references to its values.
- * 
- * <p>To use, create a subclass that implements the <code>load</code> method.
- * This method is called by <code>get</code> whenever the underlying map has no value or the 
- * soft reference value has no value. <code>load</code> must not return null.
- * 
- * <p>Null values are not permitted.
- * 
- * @author Bob Foster
- *
- * @param <K>
- * @param <V>
- */
-public abstract class SoftValueDynamicHashMap<K,V> implements Map<K,V> {
-	private ConcurrentHashMap<K,SoftReference<V>> map = new ConcurrentHashMap<K,SoftReference<V>>();
-
-	@Override
-	public int size() {
-		return map.size();
-	}
-
-	@Override
-	public boolean isEmpty() {
-		return map.isEmpty();
-	}
-
-	@Override
-	public boolean containsKey(Object key) {
-		return map.containsKey(key);
-	}
-
-	@Override
-	public boolean containsValue(Object value) {
-		throw new UnsupportedOperationException();
-	}
-
-	@SuppressWarnings("unchecked")
-	@Override
-	public V get(Object key) {
-		SoftReference<V> softValue = map.get(key);
-		V got = softValue == null ? null : softValue.get();
-		if (got == null) {
-			got = checkNull(load((K) key));
-			map.put((K) key, new SoftReference<V>(got));
-		}
-		return got;
-	}
-	
-	private V checkNull(V value) {
-		if (value == null) {
-			throw new NullPointerException("null values not supported");
-		}
-		return value;
-	}
-	
-	public abstract V load(K key);
-
-	@Override
-	public V put(K key, V value) {
-		checkNull(value);
-		return deref(map.put(key, new SoftReference<V>(value)));
-	}
-	
-	private V deref(SoftReference<V> softValue) {
-		V value = softValue == null ? null : softValue.get();
-		return value;
-	}
-
-	@Override
-	public V remove(Object key) {
-		return deref(map.remove(key));
-	}
-
-	@Override
-	public void putAll(Map<? extends K, ? extends V> m) {
-		for (Map.Entry<? extends K, ? extends V> entry : m.entrySet()) {
-			put(entry.getKey(), entry.getValue());
-		}
-	}
-
-	@Override
-	public void clear() {
-		map.clear();
-	}
-
-	@Override
-	public Set<K> keySet() {
-		return map.keySet();
-	}
-
-	@Override
-	public Collection<V> values() {
-		throw new UnsupportedOperationException();
-	}
-
-	@Override
-	public Set<java.util.Map.Entry<K, V>> entrySet() {
-		throw new UnsupportedOperationException();
-	}
-}
diff --git a/stapler-core/src/main/java/org/kohsuke/stapler/AbstractAPT6.java b/stapler-core/src/main/java/org/kohsuke/stapler/AbstractAPT6.java
index 5ce0531..1340c5f 100644
--- a/stapler-core/src/main/java/org/kohsuke/stapler/AbstractAPT6.java
+++ b/stapler-core/src/main/java/org/kohsuke/stapler/AbstractAPT6.java
@@ -112,8 +112,7 @@
         }
         finally
         {
-            //Closeables.closeQuietly( os );
-            try { if (os != null) os.close(); } catch (Exception e) { }
+            Closeables.closeQuietly( os );
         }
     }
 }
diff --git a/stapler-core/src/main/java/org/kohsuke/stapler/AbstractTearOff.java b/stapler-core/src/main/java/org/kohsuke/stapler/AbstractTearOff.java
index c38639a..54aa9c5 100644
--- a/stapler-core/src/main/java/org/kohsuke/stapler/AbstractTearOff.java
+++ b/stapler-core/src/main/java/org/kohsuke/stapler/AbstractTearOff.java
@@ -15,15 +15,10 @@
 
 package org.kohsuke.stapler;
 
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
 import com.google.common.collect.MapMaker;
-
 import java.net.URL;
 import java.util.Map;
 
-import org.eclipse.hudson.stapler.SoftValueDynamicHashMap;
-
 /**
  * Partial default implementation of tear-off class, for convenience of derived classes.
  *
@@ -112,30 +107,17 @@
      *
      * {@link Optional} is used as Google Collection doesn't allow null values in a map.
      */
-    /*
-    private final Map<String,Optional<S>> scripts = CacheBuilder.from("softValues").build(new CacheLoader<String,Optional<S>>() {
-    	public Optional<S> load(String key) {
+    private final Map<String,Optional<S>> scripts = new MapMaker().softValues().makeComputingMap(new com.google.common.base.Function<String, Optional<S>>() {
+        public Optional<S> apply(String from) {
             try {
-                return Optional.create(loadScript(key));
+                return Optional.create(loadScript(from));
             } catch (RuntimeException e) {
                 throw e;    // pass through
             } catch (Exception e) {
                 throw new ScriptLoadException(e);
             }
-    	}
-    }).asMap();
-    */
-    private final Map<String, Optional<S>> scripts = new SoftValueDynamicHashMap<String,Optional<S>>() {
-    	public Optional<S> load(String key) {
-            try {
-                return Optional.create(loadScript(key));
-            } catch (RuntimeException e) {
-                throw e;    // pass through
-            } catch (Exception e) {
-                throw new ScriptLoadException(e);
-            }
-    	}
-    };
+        }
+    });
 
     protected final URL findResource(String name, ClassLoader cl) {
         URL res = null;
diff --git a/stapler-core/src/main/java/org/kohsuke/stapler/Function.java b/stapler-core/src/main/java/org/kohsuke/stapler/Function.java
index 9f0f983..4767d73 100644
--- a/stapler-core/src/main/java/org/kohsuke/stapler/Function.java
+++ b/stapler-core/src/main/java/org/kohsuke/stapler/Function.java
@@ -15,16 +15,11 @@
 
 package org.kohsuke.stapler;
 
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
 import com.google.common.collect.MapMaker;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.hudson.stapler.SoftValueDynamicHashMap;
-
 import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationTargetException;
@@ -160,11 +155,8 @@
             throw new AssertionError(e);    // impossible
         }
 
-        // This was formerly a weakKey map, but class objects are never gc'd unless the classes
-        // are, so the weak references are essentially strong until undeploy.
-        // The presence of a class in this map should not prevent undeploy, as Function will be gc'd.
-        PARSE_METHODS = new SoftValueDynamicHashMap<Class,Function>() {
-        	public Function load(Class from) {
+        PARSE_METHODS = new MapMaker().weakKeys().makeComputingMap(new com.google.common.base.Function<Class,Function>() {
+            public Function apply(Class from) {
                 // MethdFunction for invoking a static method as a static method
                 FunctionList methods = new ClassDescriptor(from).methods.name("fromStapler");
                 switch (methods.size()) {
@@ -196,7 +188,7 @@
                     };
                 }
             }
-        };
+        });
     }
 
     public static Object returnNull() { return null; }
diff --git a/stapler-core/src/main/java/org/kohsuke/stapler/QueryParameterAPT6.java b/stapler-core/src/main/java/org/kohsuke/stapler/QueryParameterAPT6.java
index 33fad51..c767127 100644
--- a/stapler-core/src/main/java/org/kohsuke/stapler/QueryParameterAPT6.java
+++ b/stapler-core/src/main/java/org/kohsuke/stapler/QueryParameterAPT6.java
@@ -15,7 +15,6 @@
 
 package org.kohsuke.stapler;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -102,6 +101,6 @@
         }
 
         final byte[] bytes = buf.toString().getBytes( Charsets.UTF_8 );
-        ByteStreams.copy( new ByteArrayInputStream( bytes ), os );
+        ByteStreams.copy( ByteStreams.newInputStreamSupplier( bytes ), os );
     }
 }
diff --git a/stapler-core/src/main/java/org/kohsuke/stapler/export/ExportedBeanAPT6.java b/stapler-core/src/main/java/org/kohsuke/stapler/export/ExportedBeanAPT6.java
index 33cc2fc..bf6d09c 100644
--- a/stapler-core/src/main/java/org/kohsuke/stapler/export/ExportedBeanAPT6.java
+++ b/stapler-core/src/main/java/org/kohsuke/stapler/export/ExportedBeanAPT6.java
@@ -15,7 +15,6 @@
 
 package org.kohsuke.stapler.export;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -117,7 +116,7 @@
         throws IOException
     {
         final byte[] bytes = Joiner.on( '\n' ).join( beans ).getBytes( Charsets.UTF_8 );
-        ByteStreams.copy( new ByteArrayInputStream( bytes ), os );
+        ByteStreams.copy( ByteStreams.newInputStreamSupplier( bytes ), os );
     }
 }
 
diff --git a/stapler-jelly/src/main/java/org/kohsuke/stapler/jelly/JellyClassLoaderTearOff.java b/stapler-jelly/src/main/java/org/kohsuke/stapler/jelly/JellyClassLoaderTearOff.java
index 5ff4b85..ab58f7d 100644
--- a/stapler-jelly/src/main/java/org/kohsuke/stapler/jelly/JellyClassLoaderTearOff.java
+++ b/stapler-jelly/src/main/java/org/kohsuke/stapler/jelly/JellyClassLoaderTearOff.java
@@ -31,8 +31,6 @@
 import java.net.URL;
 import java.util.Map;
 
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
 import com.google.common.collect.MapMaker;
 import com.google.common.base.Function;
 
@@ -60,8 +58,8 @@
         if(taglibs!=null)
             m = taglibs.get();
         if(m==null) {
-            m = CacheBuilder.from("weakKeys").build(new CacheLoader<String,TagLibrary>() {
-                public TagLibrary load(String nsUri) {
+            m = new MapMaker().makeComputingMap(new Function<String,TagLibrary>() {
+                public TagLibrary apply(String nsUri) {
                     if(owner.parent!=null) {
                         // parent first
                         TagLibrary tl = owner.parent.loadTearOff(JellyClassLoaderTearOff.class).getTagLibrary(nsUri);
@@ -80,7 +78,7 @@
 
                     return NO_SUCH_TAGLIBRARY;    // "not found" is also cached.
                 }
-            }).asMap();
+            });
             taglibs = new WeakReference<Map<String,TagLibrary>>(m);
         }