예제 #1
0
  /**
   * Decides if the given source is newer than a class.
   *
   * @param source the source we may want to compile
   * @param cls the former class
   * @return true if the source is newer, false else
   * @throws IOException if it is not possible to open an connection for the given source
   * @see #getTimeStamp(Class)
   */
  protected boolean isSourceNewer(URL source, Class cls) throws IOException {
    long lastMod;

    // Special handling for file:// protocol, as getLastModified() often reports
    // incorrect results (-1)
    if (isFile(source)) {
      // Coerce the file URL to a File
      // See ClassNodeResolver.isSourceNewer for another method that replaces '|' with ':'.
      // WTF: Why is this done and where is it documented?
      String path = source.getPath().replace('/', File.separatorChar).replace('|', ':');
      File file = new File(path);
      lastMod = file.lastModified();
    } else {
      URLConnection conn = source.openConnection();
      lastMod = conn.getLastModified();
      conn.getInputStream().close();
    }
    long classTime = getTimeStamp(cls);
    return classTime + config.getMinimumRecompilationInterval() < lastMod;
  }
예제 #2
0
 private File fileReallyExists(URL ret, String fileWithoutPackage) {
   File path;
   try {
     /* fix for GROOVY-5809 */
     path = new File(ret.toURI());
   } catch (URISyntaxException e) {
     path = new File(decodeFileName(ret.getFile()));
   }
   path = path.getParentFile();
   if (path.exists() && path.isDirectory()) {
     File file = new File(path, fileWithoutPackage);
     if (file.exists()) {
       // file.exists() might be case insensitive. Let's do
       // case sensitive match for the filename
       File parent = file.getParentFile();
       for (String child : parent.list()) {
         if (child.equals(fileWithoutPackage)) return file;
       }
     }
   }
   // file does not exist!
   return null;
 }