PluginContentScanner: Use java.util.Optional
Change-Id: I5df1e0b21b727f19ee034e3df54d14d4b54516e1
This commit is contained in:
		| @@ -17,12 +17,9 @@ package com.google.gerrit.server.plugins; | ||||
| import static com.google.common.base.MoreObjects.firstNonNull; | ||||
| import static com.google.common.collect.Iterables.transform; | ||||
|  | ||||
| import com.google.common.base.Optional; | ||||
| import com.google.common.base.Predicates; | ||||
| import com.google.common.base.Strings; | ||||
| import com.google.common.collect.ArrayListMultimap; | ||||
| import com.google.common.collect.ImmutableMap; | ||||
| import com.google.common.collect.Iterables; | ||||
| import com.google.common.collect.Lists; | ||||
| import com.google.common.collect.Maps; | ||||
| import com.google.common.collect.Multimap; | ||||
| @@ -49,6 +46,7 @@ import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Optional; | ||||
| import java.util.Set; | ||||
| import java.util.jar.Attributes; | ||||
| import java.util.jar.JarEntry; | ||||
| @@ -192,9 +190,9 @@ public class JarScanner implements PluginContentScanner { | ||||
|     String annotationName; | ||||
|     String annotationValue; | ||||
|     String[] interfaces; | ||||
|     Iterable<String> exports; | ||||
|     Collection<String> exports; | ||||
|  | ||||
|     private ClassData(Iterable<String> exports) { | ||||
|     private ClassData(Collection<String> exports) { | ||||
|       super(Opcodes.ASM5); | ||||
|       this.exports = exports; | ||||
|     } | ||||
| @@ -214,9 +212,12 @@ public class JarScanner implements PluginContentScanner { | ||||
|  | ||||
|     @Override | ||||
|     public AnnotationVisitor visitAnnotation(String desc, boolean visible) { | ||||
|       if (!visible) { | ||||
|         return null; | ||||
|       } | ||||
|       Optional<String> found = | ||||
|           Iterables.tryFind(exports, Predicates.equalTo(desc)); | ||||
|       if (visible && found.isPresent()) { | ||||
|           exports.stream().filter(x -> x.equals(desc)).findAny(); | ||||
|       if (found.isPresent()) { | ||||
|         annotationName = desc; | ||||
|         return new AbstractAnnotationVisitor() { | ||||
|           @Override | ||||
| @@ -287,10 +288,11 @@ public class JarScanner implements PluginContentScanner { | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public Optional<PluginEntry> getEntry(String resourcePath) throws IOException { | ||||
|   public Optional<PluginEntry> getEntry(String resourcePath) | ||||
|       throws IOException { | ||||
|     JarEntry jarEntry = jarFile.getJarEntry(resourcePath); | ||||
|     if (jarEntry == null || jarEntry.getSize() == 0) { | ||||
|       return Optional.absent(); | ||||
|       return Optional.empty(); | ||||
|     } | ||||
|  | ||||
|     return Optional.of(resourceOf(jarEntry)); | ||||
|   | ||||
| @@ -14,8 +14,6 @@ | ||||
|  | ||||
| package com.google.gerrit.server.plugins; | ||||
|  | ||||
| import com.google.common.base.Optional; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.lang.annotation.Annotation; | ||||
| @@ -23,6 +21,7 @@ import java.nio.file.NoSuchFileException; | ||||
| import java.util.Collections; | ||||
| import java.util.Enumeration; | ||||
| import java.util.Map; | ||||
| import java.util.Optional; | ||||
| import java.util.jar.Manifest; | ||||
|  | ||||
| /** | ||||
| @@ -51,9 +50,8 @@ public interface PluginContentScanner { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Optional<PluginEntry> getEntry(String resourcePath) | ||||
|         throws IOException { | ||||
|       return Optional.absent(); | ||||
|     public Optional<PluginEntry> getEntry(String resourcePath) { | ||||
|       return Optional.empty(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -11,13 +11,13 @@ | ||||
| // 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 com.google.gerrit.server.plugins; | ||||
|  | ||||
| import com.google.common.base.Optional; | ||||
| package com.google.gerrit.server.plugins; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import java.util.Comparator; | ||||
| import java.util.Map; | ||||
| import java.util.Optional; | ||||
|  | ||||
| /** | ||||
|  * Plugin static resource entry | ||||
| @@ -38,7 +38,7 @@ public class PluginEntry { | ||||
|       }; | ||||
|  | ||||
|   private static final Map<Object, String> EMPTY_ATTRS = Collections.emptyMap(); | ||||
|   private static final Optional<Long> NO_SIZE = Optional.absent(); | ||||
|   private static final Optional<Long> NO_SIZE = Optional.empty(); | ||||
|  | ||||
|   private final String name; | ||||
|   private final long time; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Dave Borowitz
					Dave Borowitz