Exemple #1
0
  @Inject
  public JmxAgent(JmxConfig config) throws IOException {
    if (config.getRmiRegistryPort() == null) {
      registryPort = NetUtils.findUnusedPort();
    } else {
      registryPort = config.getRmiRegistryPort();
    }

    if (config.getRmiServerPort() == null) {
      serverPort = NetUtils.findUnusedPort();
    } else {
      serverPort = config.getRmiServerPort();
    }

    try {
      // This is how the jdk jmx agent constructs its url
      url = new JMXServiceURL("rmi", null, registryPort);
    } catch (MalformedURLException e) {
      // should not happen...
      throw new AssertionError(e);
    }
  }
Exemple #2
0
  /**
   * @param launchConfig
   * @param url
   * @param monitor
   * @param enableDebugging
   * @param browserLocation
   * @param browserName
   * @throws CoreException
   */
  private ListeningStream startNewBrowserProcess(
      DartLaunchConfigWrapper launchConfig,
      String url,
      IProgressMonitor monitor,
      boolean enableDebugging,
      IPath browserLocation,
      String browserName,
      StringBuilder argDescription)
      throws CoreException {

    Process process = null;
    monitor.worked(1);

    ProcessBuilder builder = new ProcessBuilder();
    Map<String, String> env = builder.environment();
    // Due to differences in 32bit and 64 bit environments, dartium 32bit launch does not work on
    // linux with this property.
    env.remove("LD_LIBRARY_PATH");

    // Add the environment variable DART_FLAGS="--enable-checked-mode"
    // to enable asserts and type checks
    if (launchConfig.getCheckedMode()) {
      env.put("DART_FLAGS", "--enable-checked-mode");
    }

    // Pass in --package-root if the preference is set
    String packageRoot = DartCore.getPlugin().getPackageRootPref();
    // TODO(keertip): if using default "packages" directory, do not set env variable
    // TODO(devoncarew): why are we only passing package root in when launching a file (not a url)?
    if (packageRoot != null && launchConfig.getShouldLaunchFile()) {
      try {
        String packageRootUri = getResourceServer().getUrlForFile(new Path(packageRoot).toFile());

        // Strip a trailing slash off the uri if the user setting didn't have one.
        if (!packageRoot.endsWith("/") && packageRootUri.endsWith("/")) {
          packageRootUri = packageRootUri.substring(0, packageRootUri.length() - 1);
        }

        env.put("DART_PACKAGE_ROOT", packageRootUri);
      } catch (IOException e) {
        DartDebugCorePlugin.logError(e);
      }
    }

    // This flag allows us to retrieve the dart: core sources from Dartium.
    env.put("DART_DEBUG_LIBS", "true");

    devToolsPortNumber = DEVTOOLS_PORT_NUMBER;

    if (enableDebugging) {
      devToolsPortNumber = NetUtils.findUnusedPort(DEVTOOLS_PORT_NUMBER);

      if (devToolsPortNumber == -1) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                DartDebugCorePlugin.PLUGIN_ID,
                "Unable to locate an available port for the Dartium debugger"));
      }
    }

    List<String> arguments =
        buildArgumentsList(launchConfig, browserLocation, url, enableDebugging, devToolsPortNumber);
    builder.command(arguments);
    builder.directory(DartSdkManager.getManager().getSdk().getDartiumWorkingDirectory());
    builder.redirectErrorStream(true);

    describe(arguments, argDescription);

    try {
      process = builder.start();
    } catch (IOException e) {
      DartDebugCorePlugin.logError("Exception while starting Dartium", e);

      throw new CoreException(
          new Status(
              IStatus.ERROR,
              DartDebugCorePlugin.PLUGIN_ID,
              "Could not launch browser: " + e.toString()));
    }

    browserProcess = process;

    return readFromProcessPipes(browserName, browserProcess.getInputStream());
  }