src/share/classes/org/openjdk/jigsaw/ModuleFile.java

Print this page




 492         }
 493 
 494         // Track files installed outside the module library. For later removal.
 495         // files are relative to the modules directory.
 496         private PrintWriter filesWriter;
 497 
 498         private void trackFiles(SectionType type, File file)
 499             throws IOException
 500         {
 501             if (file == null || file.toPath().startsWith(destination.toPath()))
 502                 return;
 503 
 504             // Lazy construction, not all modules will need this.
 505             if (filesWriter == null)
 506                 filesWriter = new PrintWriter(computeRealPath("files"), "UTF-8");
 507 
 508             filesWriter.println(Files.convertSeparator(relativize(destination, file)));
 509             filesWriter.flush();
 510         }
 511 
 512         void remove() throws IOException {
 513             ModuleFile.Reader.remove(destination);
 514         }
 515 
 516         // Removes a module, given its module install directory
 517         static void remove(File moduleDir) throws IOException {

 518             // Firstly remove any files installed outside of the module dir
 519             File files = new File(moduleDir, "files");
 520             if (files.exists()) {
 521                 try (FileInputStream fis = new FileInputStream(files);
 522                      InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
 523                      BufferedReader in = new BufferedReader(isr)) {
 524                     String filename;
 525                     while ((filename = in.readLine()) != null)
 526                         Files.delete(new File(moduleDir,
 527                                               Files.platformSeparator(filename)));


 528                 }


 529             }

 530 
 531             Files.deleteTree(moduleDir);

 532         }
 533 
 534         // Returns the absolute path of the given section type.
 535         private File getDirOfSection(SectionType type) {
 536             if (type == SectionType.NATIVE_LIBS)
 537                 return natlibs; 
 538             else if (type == SectionType.NATIVE_CMDS)
 539                 return natcmds;
 540             else if (type == SectionType.CONFIG)
 541                 return configs;
 542 
 543             // resolve sub dir section paths against the modules directory
 544             return new File(destination, ModuleFile.getSubdirOfSection(type));
 545         }
 546 
 547         private File computeRealPath(String path) throws IOException {
 548             return resolveAndNormalize(destination, path);
 549         }
 550 
 551         private File computeRealPath(SectionType type, String storedpath)




 492         }
 493 
 494         // Track files installed outside the module library. For later removal.
 495         // files are relative to the modules directory.
 496         private PrintWriter filesWriter;
 497 
 498         private void trackFiles(SectionType type, File file)
 499             throws IOException
 500         {
 501             if (file == null || file.toPath().startsWith(destination.toPath()))
 502                 return;
 503 
 504             // Lazy construction, not all modules will need this.
 505             if (filesWriter == null)
 506                 filesWriter = new PrintWriter(computeRealPath("files"), "UTF-8");
 507 
 508             filesWriter.println(Files.convertSeparator(relativize(destination, file)));
 509             filesWriter.flush();
 510         }
 511 
 512         List<IOException> remove() {
 513             return ModuleFile.Reader.remove(destination);
 514         }
 515 
 516         // Removes a module, given its module install directory
 517         static List<IOException> remove(File moduleDir) {
 518             List<IOException> excs = new ArrayList<>();
 519             // Firstly remove any files installed outside of the module dir
 520             File files = new File(moduleDir, "files");
 521             if (files.exists()) {
 522                 try (FileInputStream fis = new FileInputStream(files);
 523                      InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
 524                      BufferedReader in = new BufferedReader(isr)) {
 525                     String filename;
 526                     while ((filename = in.readLine()) != null) {
 527                          IOException x = Files.deleteUnchecked(new File(moduleDir,
 528                                     Files.platformSeparator(filename)).toPath());
 529                          if (x != null)
 530                              excs.add(x);
 531                     }
 532                 } catch (IOException x) {
 533                     excs.add(x);
 534                 }
 535             }
 536 
 537             excs.addAll(Files.deleteAllUnchecked(moduleDir.toPath()));
 538             return excs;
 539         }
 540 
 541         // Returns the absolute path of the given section type.
 542         private File getDirOfSection(SectionType type) {
 543             if (type == SectionType.NATIVE_LIBS)
 544                 return natlibs;
 545             else if (type == SectionType.NATIVE_CMDS)
 546                 return natcmds;
 547             else if (type == SectionType.CONFIG)
 548                 return configs;
 549 
 550             // resolve sub dir section paths against the modules directory
 551             return new File(destination, ModuleFile.getSubdirOfSection(type));
 552         }
 553 
 554         private File computeRealPath(String path) throws IOException {
 555             return resolveAndNormalize(destination, path);
 556         }
 557 
 558         private File computeRealPath(SectionType type, String storedpath)