示例#1
0
 private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) {
   if (!dir.exists()) return;
   Resource res = null;
   int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter));
   long size = ResourceUtil.getRealSize(dir, filter);
   PrintWriter out = config.getOutWriter();
   SystemOut.printDate(out, "check size of directory [" + dir + "]");
   SystemOut.printDate(out, "- current size	[" + size + "]");
   SystemOut.printDate(out, "- max size 	[" + maxSize + "]");
   int len = -1;
   while (count > 100000 || size > maxSize) {
     Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter);
     if (len == files.length) break; // protect from inifinti loop
     len = files.length;
     for (int i = 0; i < files.length; i++) {
       if (res == null || res.lastModified() > files[i].lastModified()) {
         res = files[i];
       }
     }
     if (res != null) {
       size -= res.length();
       try {
         res.remove(true);
         count--;
       } catch (IOException e) {
         SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath());
         break;
       }
     }
     res = null;
   }
 }
示例#2
0
  /**
   * This private worker method attempts to find [java_home]/lib/tools.jar. Note: The tools.jar is a
   * part of the SDK, it is not present in the JRE.
   *
   * @return If tools.jar can be found, a File representing tools.jar. <br>
   *     If tools.jar cannot be found, null.
   */
  private static Resource findToolsJar(Config config, Log log, RefBoolean useOurOwn) {
    log.info("Instrumentation", "looking for tools.jar");
    String javaHome = System.getProperty("java.home");
    Resource javaHomeFile = ResourcesImpl.getFileResourceProvider().getResource(javaHome);

    Resource toolsJarFile = javaHomeFile.getRealResource("lib" + File.separator + "tools.jar");
    if (toolsJarFile.exists()) {
      useOurOwn.setValue(false);
      return toolsJarFile;
    }
    log.info("Instrumentation", "couldn't find tools.jar at: " + toolsJarFile.getAbsolutePath());

    // If we're on an IBM SDK, then remove /jre off of java.home and try again.
    if (javaHomeFile.getAbsolutePath().endsWith(SEP + "jre")) {
      javaHomeFile = javaHomeFile.getParentResource();
      toolsJarFile = javaHomeFile.getRealResource("lib" + SEP + "tools.jar");
      if (!toolsJarFile.exists()) {
        log.info("Instrumentation", "for IBM SDK couldn't find " + toolsJarFile.getAbsolutePath());
      } else {
        useOurOwn.setValue(false);
        return toolsJarFile;
      }
    } else if (System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0) {
      // If we're on a Mac, then change the search path to use ../Classes/classes.jar.
      if (javaHomeFile.getAbsolutePath().endsWith(SEP + "Home")) {
        javaHomeFile = javaHomeFile.getParentResource();
        toolsJarFile = javaHomeFile.getRealResource("Classes" + SEP + "classes.jar");
        if (!toolsJarFile.exists()) {
          log.info("Instrumentation", "for Mac OS couldn't find " + toolsJarFile.getAbsolutePath());
        } else {
          useOurOwn.setValue(false);
          return toolsJarFile;
        }
      }
    }

    // if the engine could not find the tools.jar it is using it's own version
    try {
      toolsJarFile = createToolsJar(config);
    } catch (IOException e) {
      log.error("Instrumentation", e);
    }

    if (!toolsJarFile.exists()) {
      log.info("Instrumentation", "could not be created " + toolsJarFile.getAbsolutePath());
      return null;
    }
    log.info("Instrumentation", "found " + toolsJarFile.getAbsolutePath());
    return toolsJarFile;
  }