!7

import org.openimaj.image.processing.edges.*;

static Class module;

p {
  module = hotwireSharingLibraries(#1010058);
  
  callMain(module);
}

svoid test {
  MBFImage image = readMBF(loadImageAsFile(#1002132));
  call(module, 'processImage, image);
}

static Class<?> hotwireSharingLibraries(S progID) ctex {
  Pair<File, S> p = CompilerBot.compileSnippet2(progID);
  File jar = p.a;
  assertTrue(f2s(jar), jar.isFile());
  
  // collect files (program + libraries)
  
  L<File> files = ll(jar);
  S dehlibs = unnull(loadTextFileFromZip(jar, "libraries"));
  
  L<File> myLibraries = myLibraryFiles();
  print("My libraries: " + myLibraries);
  
  Matcher matcher = Pattern.compile("\\d+").matcher(dehlibs);
  while (matcher.find()) {
    S libID = matcher.group();
    File lib = loadLibrary(libID);
    if (myLibraries.contains(lib))
      print("Skipping lib " + lib);
    else {
      print("Adding lib " + lib);
      files.add(lib);
    }
  }

  // make class loader
  JavaXClassLoader classLoader = new JavaXClassLoader(progID, files, myClassLoader());
  
  ret hotwire_finish(classLoader, progID, p.b);
}