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());
Category category = entry.getKey();
for (Plugin p : orderedPlugins) {
if (Utils.isPostProcessor(category)) {
if (category.isPostProcessor()) {
@SuppressWarnings("unchecked")
PostProcessorPlugin pp = (PostProcessorPlugin) p;
postProcessingPlugins.add(pp);

View File

@ -35,7 +35,6 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.Plugin.Category;
@ -57,46 +56,16 @@ public class Utils {
.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) {
Set<Category> types = provider.getType();
Objects.requireNonNull(types);
for (Category pt : types) {
return isPostProcessor(pt);
}
return false;
return provider.getType().isPostProcessor();
}
public static boolean isPreProcessor(Plugin provider) {
Set<Category> types = provider.getType();
Objects.requireNonNull(types);
for (Category pt : types) {
return isPreProcessor(pt);
}
return false;
return !isPostProcessor(provider);
}
public static Category getCategory(Plugin provider) {
Set<Category> types = provider.getType();
Objects.requireNonNull(types);
for (Category t : types) {
return t;
}
return null;
return provider.getType();
}
public static List<Plugin> getPreProcessors(List<Plugin> plugins) {

View File

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

View File

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

View File

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

View File

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

View File

@ -36,11 +36,9 @@ import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import jdk.tools.jlink.internal.ModuleEntryImpl;
import jdk.tools.jlink.plugin.PluginException;
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
public void configure(Map<String, String> config) {
List<String> arguments = Utils.parseList(config.get(NAME));

View File

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

View File

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

View File

@ -31,7 +31,6 @@ import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
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.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -143,11 +142,8 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
}
@Override
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.SORTER);
return Collections.unmodifiableSet(set);
public Category getType() {
return Category.SORTER;
}
@Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,11 +9,9 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.Opcodes;
@ -132,13 +130,6 @@ public class JLinkOptimTest {
public String getName() {
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 {

View File

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

View File

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

View File

@ -26,9 +26,7 @@ import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
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
public String getDescription() {
return NAME + "-description";

View File

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

View File

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

View File

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

View File

@ -34,11 +34,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
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.stream.Collectors;
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);
}
}
}