Ejemplo n.º 1
0
 public static boolean jarIsNewer(String newname, File[] libfiles) {
   if (libfiles == null) return true;
   String[] newnames = FileUtils.getJarBaseNameAndSuffix(newname);
   for (File lf : libfiles) {
     String[] names = FileUtils.getJarBaseNameAndSuffix(lf.getName());
     if (newnames[0].equals(names[0]) && newnames[1].compareTo(names[1]) <= 0) return false;
   }
   return true;
 }
Ejemplo n.º 2
0
  public static List<File> filterFiles(Collection<File> jars) {
    List<File> filtered = new ArrayList<File>();
    Map<String, List<File>> filemap = new HashMap<String, List<File>>();

    for (File lf : jars) {
      String[] names = FileUtils.getJarBaseNameAndSuffix(lf.getName());
      String name = names[0];
      List<File> grp = filemap.get(name);
      if (grp == null) {
        grp = new ArrayList<File>();
        filemap.put(name, grp);
      }
      grp.add(lf);
    }

    for (List<File> fl : filemap.values()) {
      if (!fl.isEmpty()) {
        Collections.sort(
            fl,
            new Comparator<File>() {
              @Override
              public int compare(File o1, File o2) {
                return o2.getName().compareTo(o1.getName());
              }
            });
        filtered.add(fl.get(0));
      }
    }
    return filtered;
  }
  public void updateServiceConfig() throws IOException {
    try {
      //      File file = search(new File("."), "wrapper.conf");
      //      String osPathID = System.getProperty("os.path.id");
      File file = loadServerConfigProperties();
      //      String patt =
      // "^wrapper\\.java\\.classpath\\.[0-9]{1,3}\\s*=%ROOT_DIR%/lib/([a-zA-Z0-9\\.\\-_])*(\\*)?.jar$";
      String keypatt = "^wrapper\\.java\\.classpath\\.([0-9]{1,3})\\s*$";
      String pathpatt = "%ROOT_DIR%/lib/([a-zA-Z0-9\\.\\-_])*(\\*)?.jar";
      Pattern keypattern = Pattern.compile(keypatt);
      Pattern pathpattern = Pattern.compile(pathpatt);
      List<Map.Entry<Object, Object>> cpEntries = new LinkedList<Map.Entry<Object, Object>>();
      TreeMap<Integer, Map.Entry<Object, Object>> sortedMap =
          new TreeMap<Integer, Map.Entry<Object, Object>>();
      //      final Set<String> currentLibJars = new HashSet<String>();
      for (Map.Entry<Object, Object> entry : serviceConfigProperties.entrySet()) {
        String key = (String) entry.getKey();
        Matcher matcher = keypattern.matcher(key);
        if (matcher.matches()) {
          Matcher pathmatcher = pathpattern.matcher((String) entry.getValue());
          if (pathmatcher.matches()) {
            String number = matcher.group(1);
            sortedMap.put(
                Integer.parseInt(number), new DefaultMapEntry(entry.getKey(), entry.getValue()));
          } else {
            cpEntries.add(new DefaultMapEntry(entry.getKey(), entry.getValue()));
          }
        }
      }
      //      String fnamepatt = "%ROOT_DIR%/lib/((([a-zA-Z0-9\\.\\-_])*)_v[0-9]*)\\.jar";
      for (Map.Entry<Object, Object> entry : sortedMap.values()) {
        serviceConfigProperties.remove(entry.getKey());
      }

      for (Map.Entry<Object, Object> entry : cpEntries) {
        serviceConfigProperties.remove(entry.getKey());
      }

      //      String currentDirectory = System.getProperty("user.dir");
      File[] libfiles = getServerJars();

      Map<String, List<File>> filemap = new HashMap<String, List<File>>();

      for (File lf : libfiles) {
        String[] names = FileUtils.getJarBaseNameAndSuffix(lf.getName());
        String name = names[0];
        List<File> grp = filemap.get(name);
        if (grp == null) {
          grp = new ArrayList<File>();
          filemap.put(name, grp);
        }
        grp.add(lf);
      }
      int i = 0;
      for (; i < cpEntries.size(); i++) {
        serviceConfigProperties.put(
            "wrapper.java.classpath." + (i + 1), cpEntries.get(i).getValue());
      }

      for (List<File> fl : filemap.values()) {
        Collections.sort(
            fl,
            new Comparator<File>() {
              @Override
              public int compare(File o1, File o2) {
                return o2.getName().compareTo(o1.getName());
              }
            });

        serviceConfigProperties.put(
            "wrapper.java.classpath." + (i + 1), "%ROOT_DIR%/lib/" + fl.get(0).getName());
        i++;
      }
      //      props.store(new FileOutputStream(new File("wrapper_test.conf")), null);
      serviceConfigProperties.store(new FileOutputStream(file), null);
      //      WrapperManager.restartAndReturn();
    } catch (Exception exe) {
      exe.printStackTrace();
      log.error("Couldn't udpate service classpath", exe);
      throw new IOException("Couldn't udpate service classpath", exe);
    }
  }
 public boolean jarIsNewer(String newname) {
   return FileUtils.jarIsNewer(newname, getServerJars());
 }