package org.jetbrains.plugins.groovy.grape;

import groovy.lang.GroovyShell;
import org.codehaus.groovy.control.CompilationFailedException;

import java.io.File;
import java.net.URL;

/**
 * @author peter
 */
public class GrapeRunner {
  public static final String URL_PREFIX = "URL:";

  private GrapeRunner() {
  }

  public static void main(String[] args) {
    final File file = new File(args[0]);
    if (!file.exists()) {
      return;
    }

    final GroovyShell shell = new GroovyShell();
    try {
      shell.parse(file);
    }
    catch (CompilationFailedException ignored) {
      //should fail, we're not compiling, we're just resolving Grab dependencies
    }
    catch (Throwable e) {
      e.printStackTrace();
    }

    for (URL url : shell.getClassLoader().getURLs()) {
      System.out.println(URL_PREFIX + url);
    }
  }

}

@@ -736,22 +736,20 @@
     
-for (URL url :
+URL%5B%5D URLs =
  she
@@ -777,16 +777,83 @@
 etURLs()
+;%0A    for (int i = 0, URLsLength = URLs.length; i %3C URLsLength; i++
 ) %7B%0A    
@@ -890,11 +890,15 @@
 X + 
-url
+URLs%5Bi%5D
 );%0A 

make grape-rt compile under 1.4