Esempio n. 1
0
 private boolean checkModDirs() {
   if (!modRoot.exists()) {
     if (!modRoot.mkdir()) {
       log.error("Failed to create mods dir " + modRoot);
       return false;
     }
   }
   if (!systemModRoot.exists()) {
     if (!systemModRoot.mkdir()) {
       log.error("Failed to create sys mods dir " + modRoot);
       return false;
     }
   }
   return true;
 }
Esempio n. 2
0
  private boolean unzipModule(
      final ModuleIdentifier modID, final ModuleZipInfo zipInfo, boolean deleteZip) {
    // We synchronize to prevent a race whereby it tries to unzip the same module at the
    // same time (e.g. deployModule for the same module name has been called in parallel)
    String modName = modID.toString();
    synchronized (modName.intern()) {
      if (!checkModDirs()) {
        return false;
      }

      File fdest = new File(modRoot, modName);
      File sdest = new File(systemModRoot, modName);
      if (fdest.exists() || sdest.exists()) {
        // This can happen if the same module is requested to be installed
        // at around the same time
        // It's ok if this happens
        log.warn("Module " + modID + " is already installed");
        return true;
      }

      // Unzip into temp dir first
      File tdest = unzipIntoTmpDir(zipInfo, deleteZip);
      if (tdest == null) {
        return false;
      }

      // Check if it's a system module
      JsonObject conf = loadModuleConfig(modID, tdest);
      ModuleFields fields = new ModuleFields(conf);

      boolean system = fields.isSystem();

      // Now copy it to the proper directory
      String moveFrom = tdest.getAbsolutePath();
      try {
        vertx
            .fileSystem()
            .moveSync(moveFrom, system ? sdest.getAbsolutePath() : fdest.getAbsolutePath());
      } catch (Exception e) {
        log.error("Failed to move module", e);
        return false;
      }

      log.info("Module " + modID + " successfully installed");
      return true;
    }
  }
Esempio n. 3
0
 private boolean doPullInDependencies(File modRoot, ModuleIdentifier modID) {
   File modDir = new File(modRoot, modID.toString());
   if (!modDir.exists()) {
     log.error("Cannot find module to uninstall");
   }
   JsonObject conf = loadModuleConfig(modID, modDir);
   if (conf == null) {
     log.error("Module " + modID + " does not contain a mod.json");
   }
   ModuleFields fields = new ModuleFields(conf);
   List<String> mods = new ArrayList<>();
   String includes = fields.getIncludes();
   if (includes != null) {
     mods.addAll(Arrays.asList(parseIncludeString(includes)));
   }
   String deploys = fields.getDeploys();
   if (deploys != null) {
     mods.addAll(Arrays.asList(parseIncludeString(deploys)));
   }
   if (!mods.isEmpty()) {
     File internalModsDir = new File(modDir, "mods");
     if (!internalModsDir.exists()) {
       internalModsDir.mkdir();
     }
     for (String modName : mods) {
       File internalModDir = new File(internalModsDir, modName);
       if (!internalModDir.exists()) {
         ModuleIdentifier theModID = new ModuleIdentifier(modName);
         ModuleZipInfo zipInfo = getModule(theModID);
         if (zipInfo.filename != null) {
           internalModDir.mkdir();
           if (!unzipModuleData(internalModDir, zipInfo, true)) {
             return false;
           } else {
             log.info("Module " + modName + " successfully installed in mods dir of " + modName);
             // Now recurse so we bring in all of the deps
             doPullInDependencies(internalModsDir, theModID);
           }
         }
       }
     }
   }
   return true;
 }
Esempio n. 4
0
 private File locateModule(File currentModDir, ModuleIdentifier modID) {
   if (currentModDir != null) {
     // Nested moduleRefs - look inside current module dir
     File modDir = new File(new File(currentModDir, LOCAL_MODS_DIR), modID.toString());
     if (modDir.exists()) {
       return modDir;
     }
   }
   File modDir = new File(modRoot, modID.toString());
   if (modDir.exists()) {
     return modDir;
   } else if (!systemModRoot.equals(modRoot)) {
     modDir = new File(systemModRoot, modID.toString());
     if (modDir.exists()) {
       return modDir;
     }
   }
   return null;
 }
Esempio n. 5
0
 public synchronized void uninstallModule(String moduleName) {
   log.info("Uninstalling module " + moduleName + " from directory " + modRoot);
   File modDir = new File(modRoot, moduleName);
   if (!modDir.exists()) {
     log.error("Cannot find module to uninstall");
   } else {
     try {
       vertx.fileSystem().deleteSync(modDir.getAbsolutePath(), true);
       log.info("Module " + moduleName + " successfully uninstalled");
     } catch (Exception e) {
       log.error("Failed to delete directory: " + e.getMessage());
     }
   }
 }
Esempio n. 6
0
 private List<URL> getModuleClasspath(File modDir) {
   List<URL> urls = new ArrayList<>();
   // Add the urls for this module
   try {
     urls.add(modDir.toURI().toURL());
     File libDir = new File(modDir, "lib");
     if (libDir.exists()) {
       File[] jars = libDir.listFiles();
       for (File jar : jars) {
         URL jarURL = jar.toURI().toURL();
         urls.add(jarURL);
       }
     }
     return urls;
   } catch (MalformedURLException e) {
     // Won't happen
     log.error("malformed url", e);
     return null;
   }
 }