Ejemplo n.º 1
0
 public static void doCompilation(
     CompilerConfiguration configuration,
     CompilationUnit unit,
     String[] filenames,
     boolean lookupUnnamedFiles)
     throws Exception {
   File tmpDir = null;
   // if there are any joint compilation options set stubDir if not set
   try {
     if ((configuration.getJointCompilationOptions() != null)
         && !configuration.getJointCompilationOptions().containsKey("stubDir")) {
       tmpDir =
           DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
       configuration.getJointCompilationOptions().put("stubDir", tmpDir);
     }
     FileSystemCompiler compiler = new FileSystemCompiler(configuration, unit);
     if (lookupUnnamedFiles) {
       for (String filename : filenames) {
         File file = new File(filename);
         if (file.isFile()) {
           URL url = file.getAbsoluteFile().getParentFile().toURI().toURL();
           compiler.unit.getClassLoader().addURL(url);
         }
       }
     } else {
       compiler
           .unit
           .getClassLoader()
           .setResourceLoader(
               new GroovyResourceLoader() {
                 public URL loadGroovySource(String filename) throws MalformedURLException {
                   return null;
                 }
               });
     }
     compiler.compile(filenames);
   } finally {
     try {
       if (tmpDir != null) deleteRecursive(tmpDir);
     } catch (Throwable t) {
       System.err.println("error: could not delete temp files - " + tmpDir.getPath());
     }
   }
 }
Ejemplo n.º 2
0
 protected CompilationUnit makeCompileUnit() {
   Map<String, Object> options = configuration.getJointCompilationOptions();
   if (options != null) {
     if (keepStubs) {
       options.put("keepStubs", Boolean.TRUE);
     }
     if (stubDir != null) {
       options.put("stubDir", stubDir);
     } else {
       try {
         File tempStubDir =
             DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
         temporaryFiles.add(tempStubDir);
         options.put("stubDir", tempStubDir);
       } catch (IOException ioe) {
         throw new BuildException(ioe);
       }
     }
     return new JavaAwareCompilationUnit(configuration, buildClassLoaderFor());
   } else {
     return new CompilationUnit(configuration, null, buildClassLoaderFor());
   }
 }
Ejemplo n.º 3
0
 /**
  * Creates a temporary directory in the default temporary directory (as specified by the system
  * propery <i>java.io.tmpdir</i>.
  *
  * @deprecated Use {@link DefaultGroovyStaticMethods#createTempDir(java.io.File, String, String)}
  *     instead.
  */
 @Deprecated
 public static File createTempDir() throws IOException {
   return DefaultGroovyStaticMethods.createTempDir(null);
 }