Esempio n. 1
0
 private synchronized void scanComponents() {
   List<Component> list = new ArrayList<Component>();
   backupedComponents = new ArrayList<Component>();
   File dir = new File(this.directory);
   if (dir.isDirectory()) {
     File[] files =
         dir.listFiles(
             new FilenameFilter() {
               @Override
               public boolean accept(File dir, String name) {
                 return name.endsWith(".jar") || name.endsWith(".jar.bak");
               }
             });
     for (File f : files) {
       Map<String, String> manifest = FileUtils.parseManifestFile(f);
       if (manifest == null || manifest.isEmpty() || !manifest.containsKey(IRONRHINO_COMPONENT_ID))
         continue;
       Component component = new Component(manifest);
       component.setRealPath(f.getAbsolutePath());
       (f.getName().endsWith(".jar") ? list : backupedComponents).add(component);
     }
     Collections.sort(
         list,
         new Comparator<Component>() {
           @Override
           public int compare(Component o1, Component o2) {
             return o1.getId().compareTo(o2.getId());
           }
         });
     this.installedComponents = new ArrayList<Component>();
     for (Component c : list) addInstalledComponent(c);
   }
 }
Esempio n. 2
0
 public void install(File f) {
   Map<String, String> manifest = FileUtils.parseManifestFile(f);
   if (manifest == null || !manifest.containsKey(IRONRHINO_COMPONENT_ID)) {
     throw new ErrorMessage("invalid component");
   }
   Component newcomp = new Component(manifest);
   Component oldcomp = null;
   for (Component c : getInstalledComponents())
     if (c.getId().equals(newcomp.getId())) {
       oldcomp = c;
       break;
     }
   checkDependence(newcomp.getDependence());
   if (oldcomp != null) {
     if (oldcomp.getVersion().compareTo(newcomp.getVersion()) >= 0)
       throw new ErrorMessage("component has installed");
     try {
       new File(oldcomp.getRealPath() + ".bak").delete();
       org.apache.commons.io.FileUtils.moveFile(
           new File(oldcomp.getRealPath()), new File(oldcomp.getRealPath() + ".bak"));
     } catch (IOException e) {
       throw new ErrorMessage(e.getMessage());
     }
     oldcomp.setRealPath(oldcomp.getRealPath() + ".bak");
     getBackupedComponents().add(oldcomp);
   }
   String newfilename =
       new StringBuilder(directory)
           .append(File.separator)
           .append(newcomp.getId())
           .append("-")
           .append(newcomp.getVersion())
           .append(".jar")
           .toString();
   try {
     org.apache.commons.io.FileUtils.copyFile(f, new File(newfilename));
   } catch (IOException e) {
     throw new ErrorMessage(e.getMessage());
   }
   newcomp.setRealPath(newfilename);
   addInstalledComponent(newcomp);
 }