33 import java.io.ByteArrayInputStream; |
33 import java.io.ByteArrayInputStream; |
34 import java.io.File; |
34 import java.io.File; |
35 import java.nio.file.Files; |
35 import java.nio.file.Files; |
36 import java.util.HashMap; |
36 import java.util.HashMap; |
37 import java.util.Map; |
37 import java.util.Map; |
38 import jdk.tools.jlink.internal.PoolImpl; |
38 import jdk.tools.jlink.internal.ModulePoolImpl; |
39 |
39 |
40 import jdk.tools.jlink.internal.plugins.ExcludeFilesPlugin; |
40 import jdk.tools.jlink.internal.plugins.ExcludeFilesPlugin; |
41 import jdk.tools.jlink.plugin.Pool; |
41 import jdk.tools.jlink.plugin.ModuleEntry; |
42 import jdk.tools.jlink.plugin.Pool.ModuleData; |
42 import jdk.tools.jlink.plugin.ModulePool; |
43 import jdk.tools.jlink.plugin.Pool.ModuleDataType; |
|
44 import jdk.tools.jlink.plugin.TransformerPlugin; |
43 import jdk.tools.jlink.plugin.TransformerPlugin; |
45 |
44 |
46 public class ExcludeFilesPluginTest { |
45 public class ExcludeFilesPluginTest { |
47 public static void main(String[] args) throws Exception { |
46 public static void main(String[] args) throws Exception { |
48 new ExcludeFilesPluginTest().test(); |
47 new ExcludeFilesPluginTest().test(); |
71 public void checkFiles(String s, String sample, String module, boolean exclude) throws Exception { |
70 public void checkFiles(String s, String sample, String module, boolean exclude) throws Exception { |
72 Map<String, String> prop = new HashMap<>(); |
71 Map<String, String> prop = new HashMap<>(); |
73 prop.put(ExcludeFilesPlugin.NAME, s); |
72 prop.put(ExcludeFilesPlugin.NAME, s); |
74 ExcludeFilesPlugin fplug = new ExcludeFilesPlugin(); |
73 ExcludeFilesPlugin fplug = new ExcludeFilesPlugin(); |
75 fplug.configure(prop); |
74 fplug.configure(prop); |
76 PoolImpl files = new PoolImpl(); |
75 ModulePoolImpl files = new ModulePoolImpl(); |
77 PoolImpl fresult = new PoolImpl(); |
76 ModulePoolImpl fresult = new ModulePoolImpl(); |
78 ModuleData f = Pool.newImageFile(module, "/" + module + "/" + sample, |
77 ModuleEntry f = ModuleEntry.create(module, "/" + module + "/" + sample, |
79 ModuleDataType.CONFIG, new ByteArrayInputStream(new byte[0]), 0); |
78 ModuleEntry.Type.CONFIG, new ByteArrayInputStream(new byte[0]), 0); |
80 files.add(f); |
79 files.add(f); |
81 |
80 |
82 fplug.visit(files, fresult); |
81 fplug.visit(files, fresult); |
83 |
82 |
84 if (exclude) { |
83 if (exclude) { |
85 if (fresult.getContent().contains(f)) { |
84 if (fresult.contains(f)) { |
86 throw new Exception(sample + " should be excluded by " + s); |
85 throw new Exception(sample + " should be excluded by " + s); |
87 } |
86 } |
88 } else { |
87 } else { |
89 if (!fresult.getContent().contains(f)) { |
88 if (!fresult.contains(f)) { |
90 throw new Exception(sample + " shouldn't be excluded by " + s); |
89 throw new Exception(sample + " shouldn't be excluded by " + s); |
91 } |
90 } |
92 } |
91 } |
93 } |
92 } |
94 } |
93 } |