src/share/classes/org/openjdk/jigsaw/SimpleLibrary.java
Print this page
*** 1470,1479 ****
--- 1470,1578 ----
throws ConfigurationException, IOException, SignatureException
{
install(res, verifySignature, false);
}
+ @Override
+ public List<IOException> removeForcibly(List<ModuleId> mids)
+ throws IOException
+ {
+ try {
+ return remove(mids, true, false);
+ } catch (ConfigurationException x) {
+ throw new Error("should not be thrown when forcibly removing", x);
+ }
+ }
+
+ @Override
+ public List<IOException> remove(List<ModuleId> mids, boolean dry)
+ throws ConfigurationException, IOException
+ {
+ return remove(mids, false, dry);
+ }
+
+ private List<IOException> remove(List<ModuleId> mids, boolean force, boolean dry)
+ throws ConfigurationException, IOException
+ {
+ boolean needRefresh = false;
+ List<IOException> excs = new ArrayList<>();
+ IOException ioe = null;
+ FileChannel fc = FileChannel.open(lockf.toPath(), WRITE);
+ try {
+ fc.lock();
+ for (ModuleId mid : mids) {
+ if (moduleDictionary.findDeclaringModuleDir(mid) == null)
+ throw new IllegalArgumentException(mid + ": No such module");
+ }
+ if (!force)
+ checkRootsRequire(mids);
+ if (dry)
+ return Collections.emptyList();
+
+ // The library may be altered after this point, so the modules
+ // dictionary needs to be refreshed
+ needRefresh = true;
+ excs.addAll(removeWhileLocked(mids));
+ } catch (IOException x) {
+ ioe = x;
+ } finally {
+ if (needRefresh) {
+ try {
+ moduleDictionary.refresh();
+ moduleDictionary.store();
+ } catch (IOException x) {
+ if (ioe == null)
+ ioe = x;
+ else
+ ioe.addSuppressed(x);
+ }
+ }
+ fc.close();
+ if (ioe != null)
+ throw ioe;
+ }
+ return excs;
+ }
+
+ private void checkRootsRequire(List<ModuleId> mids)
+ throws ConfigurationException, IOException
+ {
+ // ## We do not know if a root module in a child library depends on one
+ // ## of the 'to be removed' modules. We would break it's configuration.
+
+ // check each root configuration for reference to a module in mids
+ for (ModuleId rootid : libraryRoots()) {
+ // skip any root modules being removed
+ if (mids.contains(rootid))
+ continue;
+
+ Configuration<Context> cf = readConfiguration(rootid);
+ for (Context cx : cf.contexts()) {
+ for (ModuleId mid : cx.modules()) {
+ if (mids.contains(mid))
+ throw new ConfigurationException(mid +
+ ": being used by " + rootid);
+ }
+ }
+ }
+ }
+
+ private List<IOException> removeWhileLocked(List<ModuleId> mids) {
+ List<IOException> excs = new ArrayList<>();
+ for (ModuleId mid : mids) {
+ File md = moduleDir(root, mid);
+ excs.addAll(ModuleFile.Reader.remove(md));
+ File p = md.getParentFile();
+ if (p.list().length == 0) {
+ IOException x = Files.deleteUnchecked(p.toPath());
+ if (x != null)
+ excs.add(x);
+ }
+ }
+ return excs;
+ }
+
/**
* <p> Pre-install one or more modules to an arbitrary destination
* directory. </p>
*
* <p> A pre-installed module has the same format as within the library
*** 1540,1570 ****
private void configureWhileModuleDirectoryLocked(Collection<ModuleId> mids)
throws ConfigurationException, IOException
{
// ## mids not used yet
List<ModuleId> roots = new ArrayList<>();
for (ModuleId mid : listLocalDeclaringModuleIds()) {
! // each module can have multiple entry points
! // only configure once for each module.
ModuleInfo mi = readModuleInfo(mid);
for (ModuleView mv : mi.views()) {
if (mv.mainClass() != null) {
roots.add(mid);
break;
}
}
}
!
! for (ModuleId mid : roots) {
! // ## We could be a lot more clever about this!
! Configuration<Context> cf
! = Configurator.configure(this, mid.toQuery());
! File md = moduleDictionary.findDeclaringModuleDir(mid);
! new StoredConfiguration(md, cf).store();
}
- }
public URI findLocalResource(ModuleId mid, String name)
throws IOException
{
return locateContent(mid, name);
--- 1639,1674 ----
private void configureWhileModuleDirectoryLocked(Collection<ModuleId> mids)
throws ConfigurationException, IOException
{
// ## mids not used yet
+ for (ModuleId mid : libraryRoots()) {
+ // ## We could be a lot more clever about this!
+ Configuration<Context> cf
+ = Configurator.configure(this, mid.toQuery());
+ File md = moduleDictionary.findDeclaringModuleDir(mid);
+ new StoredConfiguration(md, cf).store();
+ }
+ }
+
+ private List<ModuleId> libraryRoots()
+ throws IOException
+ {
List<ModuleId> roots = new ArrayList<>();
for (ModuleId mid : listLocalDeclaringModuleIds()) {
! // each module can have multiple entry points, but
! // only one configuration for each module.
ModuleInfo mi = readModuleInfo(mid);
for (ModuleView mv : mi.views()) {
if (mv.mainClass() != null) {
roots.add(mid);
break;
}
}
}
! return roots;
}
public URI findLocalResource(ModuleId mid, String name)
throws IOException
{
return locateContent(mid, name);
*** 1796,1805 ****
--- 1900,1910 ----
private void delete(File md) throws IOException {
if (!md.exists())
return;
checkModuleDir(md);
+ // ## TODO:
ModuleFile.Reader.remove(md);
File parent = md.getParentFile();
if (parent.list().length == 0)
parent.delete();
}