< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/FileCopierPlugin.java

Print this page




  41 import jdk.tools.jlink.plugin.PluginException;
  42 import jdk.tools.jlink.plugin.ResourcePool;
  43 import jdk.tools.jlink.plugin.ResourcePoolBuilder;
  44 import jdk.tools.jlink.plugin.ResourcePoolEntry;
  45 import jdk.tools.jlink.plugin.Plugin;
  46 import jdk.tools.jlink.internal.Utils;
  47 
  48 /**
  49  *
  50  * Copy files to image from various locations.
  51  */
  52 public class FileCopierPlugin implements Plugin {
  53 
  54     public static final String NAME = "copy-files";
  55 
  56     private static final class CopiedFile {
  57 
  58         Path source;
  59         Path target;
  60     }
  61     public static final String FAKE_MODULE = "$jlink-file-copier";
  62 
  63     private final List<CopiedFile> files = new ArrayList<>();
  64 
  65     /**
  66      * Symbolic link to another path.
  67      */
  68     public static abstract class SymImageFile extends PathResourcePoolEntry {
  69 
  70         private final String targetPath;
  71 
  72         public SymImageFile(String targetPath, String module, String path,
  73                 ResourcePoolEntry.Type type, Path file) {
  74             super(module, path, type, file);
  75             this.targetPath = targetPath;
  76         }
  77 
  78         public String getTargetPath() {
  79             return targetPath;
  80         }
  81     }
  82 


 142                 throws IOException {
 143             if (exc != null) {
 144                 throw exc;
 145             }
 146             return FileVisitResult.CONTINUE;
 147         }
 148 
 149         @Override
 150         public FileVisitResult visitFileFailed(Path file, IOException exc)
 151                 throws IOException {
 152             throw exc;
 153         }
 154     }
 155 
 156     private static void addFile(ResourcePoolBuilder pool, Path file, String path)
 157             throws IOException {
 158         Objects.requireNonNull(pool);
 159         Objects.requireNonNull(file);
 160         Objects.requireNonNull(path);
 161         ResourcePoolEntry impl = ResourcePoolEntry.create(
 162                 "/" + FAKE_MODULE + "/other/" + path,
 163                 ResourcePoolEntry.Type.OTHER, file);
 164         try {
 165             pool.add(impl);
 166         } catch (Exception ex) {
 167             throw new IOException(ex);
 168         }
 169     }
 170 
 171     @Override
 172     public void configure(Map<String, String> config) {
 173         List<String> arguments = Utils.parseList(config.get(NAME));
 174         if (arguments.isEmpty()) {
 175             throw new RuntimeException("Invalid argument for " + NAME);
 176         }
 177 
 178         String javahome = System.getProperty("java.home");
 179         for (String a : arguments) {
 180             int i = a.indexOf("=");
 181             CopiedFile cf = new CopiedFile();
 182             if (i == -1) {




  41 import jdk.tools.jlink.plugin.PluginException;
  42 import jdk.tools.jlink.plugin.ResourcePool;
  43 import jdk.tools.jlink.plugin.ResourcePoolBuilder;
  44 import jdk.tools.jlink.plugin.ResourcePoolEntry;
  45 import jdk.tools.jlink.plugin.Plugin;
  46 import jdk.tools.jlink.internal.Utils;
  47 
  48 /**
  49  *
  50  * Copy files to image from various locations.
  51  */
  52 public class FileCopierPlugin implements Plugin {
  53 
  54     public static final String NAME = "copy-files";
  55 
  56     private static final class CopiedFile {
  57 
  58         Path source;
  59         Path target;
  60     }


  61     private final List<CopiedFile> files = new ArrayList<>();
  62 
  63     /**
  64      * Symbolic link to another path.
  65      */
  66     public static abstract class SymImageFile extends PathResourcePoolEntry {
  67 
  68         private final String targetPath;
  69 
  70         public SymImageFile(String targetPath, String module, String path,
  71                 ResourcePoolEntry.Type type, Path file) {
  72             super(module, path, type, file);
  73             this.targetPath = targetPath;
  74         }
  75 
  76         public String getTargetPath() {
  77             return targetPath;
  78         }
  79     }
  80 


 140                 throws IOException {
 141             if (exc != null) {
 142                 throw exc;
 143             }
 144             return FileVisitResult.CONTINUE;
 145         }
 146 
 147         @Override
 148         public FileVisitResult visitFileFailed(Path file, IOException exc)
 149                 throws IOException {
 150             throw exc;
 151         }
 152     }
 153 
 154     private static void addFile(ResourcePoolBuilder pool, Path file, String path)
 155             throws IOException {
 156         Objects.requireNonNull(pool);
 157         Objects.requireNonNull(file);
 158         Objects.requireNonNull(path);
 159         ResourcePoolEntry impl = ResourcePoolEntry.create(
 160                 "/java.base/other/" + path,
 161                 ResourcePoolEntry.Type.OTHER, file);
 162         try {
 163             pool.add(impl);
 164         } catch (Exception ex) {
 165             throw new IOException(ex);
 166         }
 167     }
 168 
 169     @Override
 170     public void configure(Map<String, String> config) {
 171         List<String> arguments = Utils.parseList(config.get(NAME));
 172         if (arguments.isEmpty()) {
 173             throw new RuntimeException("Invalid argument for " + NAME);
 174         }
 175 
 176         String javahome = System.getProperty("java.home");
 177         for (String a : arguments) {
 178             int i = a.indexOf("=");
 179             CopiedFile cf = new CopiedFile();
 180             if (i == -1) {


< prev index next >