< prev index next >

test/tools/jlink/plugins/FileCopierPluginTest.java

Print this page




  24 /*
  25  * @test
  26  * @summary Test files copy plugin
  27  * @author Jean-Francois Denise
  28  * @modules jdk.jlink/jdk.tools.jlink.internal
  29  *          jdk.jlink/jdk.tools.jlink.builder
  30  *          jdk.jlink/jdk.tools.jlink.internal.plugins
  31  * @run main FileCopierPluginTest
  32  */
  33 
  34 import java.io.File;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.util.Collections;
  38 import java.util.HashMap;
  39 import java.util.Map;
  40 import jdk.tools.jlink.internal.ResourcePoolManager;
  41 import jdk.tools.jlink.builder.DefaultImageBuilder;
  42 
  43 import jdk.tools.jlink.internal.plugins.FileCopierPlugin;

  44 import jdk.tools.jlink.plugin.ResourcePoolEntry;
  45 import jdk.tools.jlink.plugin.ResourcePool;
  46 
  47 public class FileCopierPluginTest {
  48 
  49     public static void main(String[] args) throws Exception {
  50         new FileCopierPluginTest().test();
  51     }
  52 
  53     /**
  54      * 3 cases - Absolute, no target ==> copy in image root dir - Absolute and
  55      * target ==> copy in image root dir/target - Relative ==> copy from JDK
  56      * home dir.
  57      *
  58      * @throws Exception
  59      */
  60     public void test() throws Exception {
  61         FileCopierPlugin plug = new FileCopierPlugin();
  62         String content = "You \n should \n be \bthere.\n";
  63         String name = "sample.txt";


  86         conf.put(FileCopierPlugin.NAME, builder.toString());
  87         plug.configure(conf);
  88         ResourcePoolManager poolMgr = new ResourcePoolManager();
  89         ResourcePool pool = plug.transform(
  90                 new ResourcePoolManager().resourcePool(),
  91                 poolMgr.resourcePoolBuilder());
  92         if (pool.entryCount() != expected) {
  93             throw new AssertionError("Wrong number of added files");
  94         }
  95         pool.entries().forEach(f -> {
  96             if (!f.type().equals(ResourcePoolEntry.Type.OTHER)) {
  97                 throw new AssertionError("Invalid type " + f.type()
  98                         + " for file " + f.path());
  99             }
 100             if (f.content() == null) {
 101                 throw new AssertionError("Null stream for file " + f.path());
 102             }
 103         });
 104         Path root = new File(".").toPath();
 105         DefaultImageBuilder imgbuilder = new DefaultImageBuilder(root);

 106         imgbuilder.storeFiles(pool);










 107 
 108         if (lic.exists()) {
 109             File license = new File(root.toFile(), "LICENSE");
 110             if (!license.exists() || license.length() == 0) {
 111                 throw new AssertionError("Invalide license file "
 112                         + license.getAbsoluteFile());
 113             }
 114         }
 115 
 116         File sample1 = new File(root.toFile(), txt.getName());
 117         if (!sample1.exists() || sample1.length() == 0) {
 118             throw new AssertionError("Invalide sample1 file "
 119                     + sample1.getAbsoluteFile());
 120         }
 121         if (!new String(Files.readAllBytes(sample1.toPath())).equals(content)) {
 122             throw new AssertionError("Invalid Content in sample1");
 123         }
 124 
 125         File sample2 = new File(root.toFile(), target);
 126         if (!sample2.exists() || sample2.length() == 0) {




  24 /*
  25  * @test
  26  * @summary Test files copy plugin
  27  * @author Jean-Francois Denise
  28  * @modules jdk.jlink/jdk.tools.jlink.internal
  29  *          jdk.jlink/jdk.tools.jlink.builder
  30  *          jdk.jlink/jdk.tools.jlink.internal.plugins
  31  * @run main FileCopierPluginTest
  32  */
  33 
  34 import java.io.File;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.util.Collections;
  38 import java.util.HashMap;
  39 import java.util.Map;
  40 import jdk.tools.jlink.internal.ResourcePoolManager;
  41 import jdk.tools.jlink.builder.DefaultImageBuilder;
  42 
  43 import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
  44 import jdk.tools.jlink.plugin.PluginException;
  45 import jdk.tools.jlink.plugin.ResourcePoolEntry;
  46 import jdk.tools.jlink.plugin.ResourcePool;
  47 
  48 public class FileCopierPluginTest {
  49 
  50     public static void main(String[] args) throws Exception {
  51         new FileCopierPluginTest().test();
  52     }
  53 
  54     /**
  55      * 3 cases - Absolute, no target ==> copy in image root dir - Absolute and
  56      * target ==> copy in image root dir/target - Relative ==> copy from JDK
  57      * home dir.
  58      *
  59      * @throws Exception
  60      */
  61     public void test() throws Exception {
  62         FileCopierPlugin plug = new FileCopierPlugin();
  63         String content = "You \n should \n be \bthere.\n";
  64         String name = "sample.txt";


  87         conf.put(FileCopierPlugin.NAME, builder.toString());
  88         plug.configure(conf);
  89         ResourcePoolManager poolMgr = new ResourcePoolManager();
  90         ResourcePool pool = plug.transform(
  91                 new ResourcePoolManager().resourcePool(),
  92                 poolMgr.resourcePoolBuilder());
  93         if (pool.entryCount() != expected) {
  94             throw new AssertionError("Wrong number of added files");
  95         }
  96         pool.entries().forEach(f -> {
  97             if (!f.type().equals(ResourcePoolEntry.Type.OTHER)) {
  98                 throw new AssertionError("Invalid type " + f.type()
  99                         + " for file " + f.path());
 100             }
 101             if (f.content() == null) {
 102                 throw new AssertionError("Null stream for file " + f.path());
 103             }
 104         });
 105         Path root = new File(".").toPath();
 106         DefaultImageBuilder imgbuilder = new DefaultImageBuilder(root);
 107         try {
 108             imgbuilder.storeFiles(pool);
 109         } catch (PluginException e) {
 110             // We didn't add any .class resource of the java.base module!
 111             // This cannot happen in non-testing scenario as java.base module
 112             // is minimum mandatory module in a .jimage. jlink depends on java.base
 113             // to generate 'release' file. If the current exception came from that
 114             // part of the code, then it is okay.
 115             if (!e.getMessage().contains("No module-info for java.base module")) {
 116                 throw e;
 117             }
 118         }
 119 
 120         if (lic.exists()) {
 121             File license = new File(root.toFile(), "LICENSE");
 122             if (!license.exists() || license.length() == 0) {
 123                 throw new AssertionError("Invalide license file "
 124                         + license.getAbsoluteFile());
 125             }
 126         }
 127 
 128         File sample1 = new File(root.toFile(), txt.getName());
 129         if (!sample1.exists() || sample1.length() == 0) {
 130             throw new AssertionError("Invalide sample1 file "
 131                     + sample1.getAbsoluteFile());
 132         }
 133         if (!new String(Files.readAllBytes(sample1.toPath())).equals(content)) {
 134             throw new AssertionError("Invalid Content in sample1");
 135         }
 136 
 137         File sample2 = new File(root.toFile(), target);
 138         if (!sample2.exists() || sample2.length() == 0) {


< prev index next >