Package com.onpositive.gae.tools.core

Source Code of com.onpositive.gae.tools.core.CheckLaunchJob

package com.onpositive.gae.tools.core;

import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;

public class CheckLaunchJob extends Job {

  public CheckLaunchJob(String name, IJavaProject iJavaProject,
      boolean openBrowser) {
    super(name);
    this.nm = name;
    this.project = iJavaProject;
  }

  String nm;
  boolean openBrowser;

  IJavaProject project;

  int result = -1;

  protected ILaunchConfiguration config;

  public ILaunchConfiguration getConfiguration() {
    return config;
  }

  protected IStatus run(IProgressMonitor monitor) {
    int p = DebugServerLaunchManager.getPort(project);
    if (p == -1) {
      ILaunchConfiguration launchConfiguration;
      try {
        launchConfiguration = DebugServerLaunchManager
            .getLaunchConfiguration(project);
        config = launchConfiguration;

        if (launchConfiguration != null) {
          ILaunchConfigurationWorkingCopy copy = launchConfiguration
              .copy("A");
          if (!openBrowser) {
            copy.setAttribute("com.google.gwt.eclipse.core.URL", "");
          }
          ILaunch launch = copy.launch("debug", monitor);
               
          for (int a = 0; a < 300; a++) {
            p = DebugServerLaunchManager.getPort(project);
            if (p != -1) {
              result = p;
              break;
            }
            if (launch.isTerminated()) {
              break;
            }
            try {
              Thread.sleep(300);
            } catch (InterruptedException e) {

            }
          }
          if (p == -1) {
            Display.getDefault().asyncExec(new Runnable() {
              public void run() {
                String string = "Unable to detect local development server for "
                    + project.getElementName();
                MessageDialog.openError(Display.getCurrent()
                    .getActiveShell(), "Error", string);
              }
            });
          }
        } else {
          Display.getDefault().asyncExec(new Runnable() {

            public void run() {
              String string = "There is no suitable launch configuration for project: "
                  + project.getElementName();
              // +
              // " before using OnPositive Tools with debug server";
              MessageDialog.openError(Display.getCurrent()
                  .getActiveShell(), "Error", string);
            }
          });
        }
      } catch (CoreException e) {
        return e.getStatus();
      }

    } else {
      result = p;
    }
    return Status.OK_STATUS;
  }

  public int getPort() {
    return result;
  }
}
TOP

Related Classes of com.onpositive.gae.tools.core.CheckLaunchJob

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.