Ejemplo n.º 1
0
  private static void exec(Class clazz, String classLocation, PrintStream stream)
      throws IOException, InterruptedException {
    String javaHome = System.getProperty("java.home");
    String javaBin = javaHome + "/bin/java";
    String classpath =
        FileUtils.getParentFolder(classLocation); // System.getProperty("java.class.path");
    String className = clazz.getCanonicalName();

    String outputLocation = FileUtils.getParentFolder(classLocation);

    Command command =
        new Command(
            Display.getDefault(),
            "\"" + javaBin + "\" -cp " + "\"" + classpath + "\" " + className,
            outputLocation);

    command.execute();
  }
Ejemplo n.º 2
0
  public static Program run(String fileLocation, final ConsoleStream stream) {
    fileLocation = FileUtils.removeExtension(fileLocation);

    // TODO: Fix the issue with the /src/ possible ambiguities.
    String projectLocation = FileUtils.getPrecedingPath(fileLocation, "/src/");

    String className = FileUtils.getPathRelativeTo(fileLocation, "/src/");

    String classLocation = projectLocation + "/bin/" + className;

    //		try
    //		{
    //			URL url = new URL("file://" + FileUtils.getParentFolder(classLocation) + "/");
    //
    //			final ClassLoader cLoader   = new URLClassLoader(new URL[] { url });
    //
    //			final String      className = FileUtils.getFileNameWithoutExtension(classLocation);
    //
    ////			Class        clazz     = cLoader.loadClass(className);//classLocation.substring(0,
    // classLocation.lastIndexOf('.')));
    //
    ////			final Method m         = clazz.getMethod("main", String[].class);
    //
    ////			classRunning = true;
    //
    //			new Thread()
    //			{
    //				public void run()
    //				{
    //					try
    //					{
    //						Class clazz = null;
    //
    //						if (classes.containsKey(classLocation))
    //						{
    //							clazz = classes.get(classLocation);
    //						}
    //						else
    //						{
    //							clazz = cLoader.loadClass(className);
    //
    //							classes.put(classLocation, clazz);
    //						}
    //
    //						exec(clazz, classLocation, stream);
    //					}
    //					catch (ClassNotFoundException e)
    //					{
    //						e.printStackTrace();
    //					}
    //					catch (InterruptedException e)
    //					{
    //						e.printStackTrace();
    //					}
    //					catch (IOException e)
    //					{
    //						e.printStackTrace();
    //					}
    //				}
    //			}.start();
    //		}
    //		catch (MalformedURLException e)
    //		{
    //			e.printStackTrace();
    //		}

    if (!FileUtils.fileExists(CONFIG_DATA.get("jdk.location"))) {
      FileBrowseDialog jdkSearch =
          new FileBrowseDialog(
              "Specify your JDK location.",
              "Location:",
              CONFIG_DATA.get("jdk.location"),
              FileBrowseDialog.DIRECTORY);

      String jdkLoc = jdkSearch.open();

      if (jdkLoc != null) {
        String location = FileUtils.removeEndingSlashes(jdkLoc.replace('\\', '/'));

        ArrowIDE.setConfigDataValue("jdk.location", location);
      } else {
        stream.println("You must specify a valid jdk to compile this program.");

        return null;
      }
    }

    String classpath = getClasspath(projectLocation);

    Command c =
        new Command(
            Display.getDefault(),
            new String[] {
              CONFIG_DATA.get("jdk.location") + "/bin/java", "-cp", classpath, className
            },
            projectLocation);

    String fileName = FileUtils.getFileNameWithoutExtension(fileLocation);

    try {
      c.execute(fileName);

      return c.getProgram();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }