コード例 #1
0
 /**
  * (Re)Compiles the given source. This method starts the compilation of a given source, if the
  * source has changed since the class was created. For this isSourceNewer is called.
  *
  * @param source the source pointer for the compilation
  * @param className the name of the class to be generated
  * @param oldClass a possible former class
  * @return the old class if the source wasn't new enough, the new class else
  * @throws CompilationFailedException if the compilation failed
  * @throws IOException if the source is not readable
  * @see #isSourceNewer(URL, Class)
  */
 protected Class recompile(URL source, String className, Class oldClass)
     throws CompilationFailedException, IOException {
   if (source != null) {
     // found a source, compile it if newer
     if ((oldClass != null && isSourceNewer(source, oldClass)) || (oldClass == null)) {
       synchronized (sourceCache) {
         String name = source.toExternalForm();
         sourceCache.remove(name);
         if (isFile(source)) {
           try {
             return parseClass(
                 new GroovyCodeSource(new File(source.toURI()), config.getSourceEncoding()));
           } catch (URISyntaxException e) {
             // do nothing and fall back to the other version
           }
         }
         return parseClass(source.openStream(), name);
       }
     }
   }
   return oldClass;
 }
コード例 #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;
 }