/**
   * Starts pub serve for a given launch configuration. Checks if the current pub serve is for the
   * same pubspec.yaml, if not then starts up pub serve.
   *
   * @param wrapper - the launch config wrapper
   * @return - true if pub serve starts
   */
  public boolean startPubServe(DartLaunchConfigWrapper wrapper) {

    // TODO(keertip): output to process console
    console = DartCore.getConsole();

    if (currentLaunch != null) {
      IResource resource = currentLaunch.getApplicationResource();
      if (resource != null) {
        // check if previous launch and new launch share the same pubspec. If so, and pub serve is
        // running, then current pub serve can be used.
        IContainer appDir = DartCore.getApplicationDirectory(resource);
        if (appDir.equals(DartCore.getApplicationDirectory(wrapper.getApplicationResource()))) {
          // TODO(keertip): make this separate checks so that new connection can be started without
          // starting new process
          if (process != null
              && !isTerminated()
              && pubConnection != null
              && pubConnection.isConnected()) {
            console.printSeparator("Starting pub serve : " + resource.getProject().getName());
            // make sure pub is serving the directory, send serve directory command
            boolean isServed = serveDirectory(wrapper.getApplicationResource());
            if (isServed) {
              currentLaunch = wrapper;
              return true;
            }
          }
        }
      }
    }

    // terminate existing pub serve if any
    dispose();
    return runPubServe(wrapper);
  }
 @Override
 public void handleResult(PubResult<String> result) {
   if (result.isError()) {
     done[0] = false;
   } else {
     DartCore.getConsole().println("Serving from " + result.getResult());
     done[0] = true;
   }
   latch.countDown();
 }
Example #3
0
  /**
   * Runs the pub command and displays the output in the console.
   *
   * @return the result of running the pub command
   */
  @Override
  public IStatus run(IProgressMonitor monitor) {
    IStatus status = runSilent(monitor);

    if (!status.isOK()) {
      MessageConsole console = DartCore.getConsole();
      console.printSeparator(NLS.bind(PubMessages.RunPubJob_running, command));
      console.println(status.getMessage());
    }

    return status;
  }