8159593: Plugin Set<Category> getType() should return a Category

Reviewed-by: jlaskey
This commit is contained in:
Athijegannathan Sundararajan 2016-06-21 19:05:34 +05:30
parent 47ade5bbb9
commit e011bbd371
28 changed files with 51 additions and 210 deletions

View File

@ -101,7 +101,7 @@ public final class ImagePluginConfiguration {
List<Plugin> orderedPlugins = PluginOrderingGraph.sort(entry.getValue()); List<Plugin> orderedPlugins = PluginOrderingGraph.sort(entry.getValue());
Category category = entry.getKey(); Category category = entry.getKey();
for (Plugin p : orderedPlugins) { for (Plugin p : orderedPlugins) {
if (Utils.isPostProcessor(category)) { if (category.isPostProcessor()) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
PostProcessorPlugin pp = (PostProcessorPlugin) p; PostProcessorPlugin pp = (PostProcessorPlugin) p;
postProcessingPlugins.add(pp); postProcessingPlugins.add(pp);

View File

@ -35,7 +35,6 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.Plugin.Category; import jdk.tools.jlink.plugin.Plugin.Category;
@ -57,46 +56,16 @@ public class Utils {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public static boolean isPostProcessor(Category category) {
return category.equals(Category.VERIFIER)
|| category.equals(Category.PROCESSOR)
|| category.equals(Category.PACKAGER);
}
public static boolean isPreProcessor(Category category) {
return category.equals(Category.COMPRESSOR)
|| category.equals(Category.FILTER)
|| category.equals(Category.MODULEINFO_TRANSFORMER)
|| category.equals(Category.SORTER)
|| category.equals(Category.TRANSFORMER)
|| category.equals(Category.METAINFO_ADDER);
}
public static boolean isPostProcessor(Plugin provider) { public static boolean isPostProcessor(Plugin provider) {
Set<Category> types = provider.getType(); return provider.getType().isPostProcessor();
Objects.requireNonNull(types);
for (Category pt : types) {
return isPostProcessor(pt);
}
return false;
} }
public static boolean isPreProcessor(Plugin provider) { public static boolean isPreProcessor(Plugin provider) {
Set<Category> types = provider.getType(); return !isPostProcessor(provider);
Objects.requireNonNull(types);
for (Category pt : types) {
return isPreProcessor(pt);
}
return false;
} }
public static Category getCategory(Plugin provider) { public static Category getCategory(Plugin provider) {
Set<Category> types = provider.getType(); return provider.getType();
Objects.requireNonNull(types);
for (Category t : types) {
return t;
}
return null;
} }
public static List<Plugin> getPreProcessors(List<Plugin> plugins) { public static List<Plugin> getPreProcessors(List<Plugin> plugins) {

View File

@ -25,9 +25,7 @@
package jdk.tools.jlink.internal.plugins; package jdk.tools.jlink.internal.plugins;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.internal.ModulePoolImpl; import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.plugin.ModulePool; import jdk.tools.jlink.plugin.ModulePool;
@ -77,10 +75,8 @@ public final class DefaultCompressPlugin implements TransformerPlugin, ResourceP
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.COMPRESSOR;
set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -26,9 +26,7 @@ package jdk.tools.jlink.internal.plugins;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import jdk.tools.jlink.plugin.TransformerPlugin; import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.ModulePool; import jdk.tools.jlink.plugin.ModulePool;
@ -60,10 +58,8 @@ public final class ExcludeFilesPlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.FILTER;
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -25,9 +25,7 @@
package jdk.tools.jlink.internal.plugins; package jdk.tools.jlink.internal.plugins;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import jdk.tools.jlink.plugin.TransformerPlugin; import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.ModuleEntry; import jdk.tools.jlink.plugin.ModuleEntry;
@ -73,10 +71,8 @@ public final class ExcludePlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.FILTER;
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -32,10 +32,8 @@ import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -159,10 +157,8 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.FILTER;
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -36,11 +36,9 @@ import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import jdk.tools.jlink.internal.ModuleEntryImpl; import jdk.tools.jlink.internal.ModuleEntryImpl;
import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ModuleEntry; import jdk.tools.jlink.plugin.ModuleEntry;
@ -187,13 +185,6 @@ public class FileCopierPlugin implements TransformerPlugin {
} }
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public void configure(Map<String, String> config) { public void configure(Map<String, String> config) {
List<String> arguments = Utils.parseList(config.get(NAME)); List<String> arguments = Utils.parseList(config.get(NAME));

View File

@ -60,11 +60,6 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
public GenerateJLIClassesPlugin() { public GenerateJLIClassesPlugin() {
} }
@Override
public Set<Category> getType() {
return Collections.singleton(Category.TRANSFORMER);
}
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;

View File

@ -27,7 +27,6 @@ package jdk.tools.jlink.internal.plugins;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.IllformedLocaleException; import java.util.IllformedLocaleException;
import java.util.Locale; import java.util.Locale;
import java.util.List; import java.util.List;
@ -134,10 +133,8 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.FILTER;
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -31,7 +31,6 @@ import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -284,11 +283,4 @@ public final class OptimizationPlugin extends AsmPlugin {
} }
} }
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
} }

View File

@ -32,7 +32,6 @@ import java.nio.file.PathMatcher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -143,11 +142,8 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.SORTER;
set.add(Category.SORTER);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -49,8 +49,8 @@ public final class ReleaseInfoPlugin implements TransformerPlugin {
private final Map<String, String> release = new HashMap<>(); private final Map<String, String> release = new HashMap<>();
@Override @Override
public Set<Category> getType() { public Category getType() {
return Collections.singleton(Category.METAINFO_ADDER); return Category.METAINFO_ADDER;
} }
@Override @Override

View File

@ -343,10 +343,8 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.COMPRESSOR;
set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -27,8 +27,6 @@ package jdk.tools.jlink.internal.plugins;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import jdk.internal.org.objectweb.asm.ClassReader; import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.ClassWriter;
@ -57,13 +55,6 @@ public final class StripDebugPlugin implements TransformerPlugin {
return NAME; return NAME;
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public String getDescription() { public String getDescription() {
return PluginsResourceBundle.getDescription(NAME); return PluginsResourceBundle.getDescription(NAME);

View File

@ -25,8 +25,6 @@
package jdk.tools.jlink.internal.plugins; package jdk.tools.jlink.internal.plugins;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import jdk.tools.jlink.plugin.ModuleEntry; import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool; import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin; import jdk.tools.jlink.plugin.TransformerPlugin;
@ -45,10 +43,8 @@ public final class StripNativeCommandsPlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.FILTER;
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -82,11 +82,6 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
this.enabled = true; this.enabled = true;
} }
@Override
public Set<Category> getType() {
return Collections.singleton(Category.TRANSFORMER);
}
@Override @Override
public String getName() { public String getName() {
return NAME; return NAME;

View File

@ -29,9 +29,7 @@ import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.zip.Deflater; import java.util.zip.Deflater;
import jdk.tools.jlink.internal.ModulePoolImpl; import jdk.tools.jlink.internal.ModulePoolImpl;
@ -66,10 +64,8 @@ public final class ZipPlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.COMPRESSOR;
set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -57,19 +57,29 @@ public interface Plugin {
SORTER("SORTER"), SORTER("SORTER"),
COMPRESSOR("COMPRESSOR"), COMPRESSOR("COMPRESSOR"),
METAINFO_ADDER("METAINFO_ADDER"), METAINFO_ADDER("METAINFO_ADDER"),
VERIFIER("VERIFIER"), VERIFIER("VERIFIER", true),
PROCESSOR("PROCESSOR"), PROCESSOR("PROCESSOR", true),
PACKAGER("PACKAGER"); PACKAGER("PACKAGER", true);
private final String name; private final String name;
private final boolean postProcessor;
Category(String name, boolean postProcessor) {
this.name = name;
this.postProcessor = postProcessor;
}
Category(String name) { Category(String name) {
this.name = name; this(name, false);
} }
public String getName() { public String getName() {
return name; return name;
} }
public boolean isPostProcessor() {
return postProcessor;
}
} }
/** /**
@ -90,11 +100,12 @@ public interface Plugin {
} }
/** /**
* The Plugin set of types. * The type of this plugin.
* @return The set of types. *
* @return The type of this plugin
*/ */
public default Set<Category> getType() { public default Category getType() {
return Collections.emptySet(); return Category.TRANSFORMER;
} }
/** /**

View File

@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -64,13 +63,6 @@ public class DefaultProviderTest {
private static class Custom implements TransformerPlugin { private static class Custom implements TransformerPlugin {
private boolean enabled = true; private boolean enabled = true;
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public Set<State> getState() { public Set<State> getState() {
return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL) return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL)

View File

@ -90,10 +90,8 @@ public class IntegrationTest {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.PROCESSOR;
set.add(Category.PROCESSOR);
return Collections.unmodifiableSet(set);
} }
@Override @Override
@ -138,13 +136,6 @@ public class IntegrationTest {
}, out); }, out);
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public String getDescription() { public String getDescription() {
return null; return null;

View File

@ -9,11 +9,9 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.internal.org.objectweb.asm.ClassReader; import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.Opcodes; import jdk.internal.org.objectweb.asm.Opcodes;
@ -132,13 +130,6 @@ public class JLinkOptimTest {
public String getName() { public String getName() {
return NAME; return NAME;
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
} }
private static void testForName() throws Exception { private static void testForName() throws Exception {

View File

@ -26,10 +26,8 @@ import java.io.UncheckedIOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.internal.PluginRepository; import jdk.tools.jlink.internal.PluginRepository;
import jdk.tools.jlink.plugin.ExecutableImage; import jdk.tools.jlink.plugin.ExecutableImage;
@ -75,10 +73,8 @@ public class JLinkPostProcessingTest {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.PROCESSOR;
set.add(Category.PROCESSOR);
return Collections.unmodifiableSet(set);
} }
@Override @Override

View File

@ -23,9 +23,7 @@
package plugin; package plugin;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import jdk.tools.jlink.plugin.ModuleEntry; import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool; import jdk.tools.jlink.plugin.ModulePool;
@ -58,9 +56,7 @@ public class CustomPlugin implements TransformerPlugin {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
Set<Category> set = new HashSet<>(); return Category.PROCESSOR;
set.add(Category.PROCESSOR);
return Collections.unmodifiableSet(set);
} }
} }

View File

@ -26,9 +26,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.plugin.ModuleEntry; import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool; import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin; import jdk.tools.jlink.plugin.TransformerPlugin;
@ -62,13 +60,6 @@ public final class HelloPlugin implements TransformerPlugin {
} }
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public String getDescription() { public String getDescription() {
return NAME + "-description"; return NAME + "-description";

View File

@ -33,10 +33,8 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.internal.ImagePluginConfiguration; import jdk.tools.jlink.internal.ImagePluginConfiguration;
import jdk.tools.jlink.internal.PluginRepository; import jdk.tools.jlink.internal.PluginRepository;
@ -199,13 +197,6 @@ public class LastSorterTest {
return name; return name;
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public void configure(Map<String, String> config) { public void configure(Map<String, String> config) {
String arguments = config.get(name); String arguments = config.get(name);

View File

@ -260,8 +260,8 @@ public class PluginOrderTest {
} }
@Override @Override
public Set<Category> getType() { public Category getType() {
return Collections.singleton(category); return category;
} }
@Override @Override

View File

@ -32,10 +32,8 @@
import java.lang.reflect.Layer; import java.lang.reflect.Layer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.internal.ImagePluginConfiguration; import jdk.tools.jlink.internal.ImagePluginConfiguration;
import jdk.tools.jlink.internal.PluginRepository; import jdk.tools.jlink.internal.PluginRepository;
@ -137,13 +135,6 @@ public class PluginsNegativeTest {
return name; return name;
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@Override @Override
public String getDescription() { public String getDescription() {
return null; return null;

View File

@ -34,11 +34,9 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import jdk.tools.jlink.internal.ImagePluginConfiguration; import jdk.tools.jlink.internal.ImagePluginConfiguration;
@ -160,12 +158,5 @@ public class PrevisitorTest {
} }
}); });
} }
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
} }
} }