public static String getDeployDirectory(IServer server) {
    IDeployableServer deployableServer = ServerConverter.getDeployableServer(server);
    if (server != null && deployableServer != null) {
      return deployableServer.getDeployFolder();
    }
    String ret =
        server.getAttribute(IDeployableServer.DEPLOY_DIRECTORY, (String) null); // $NON-NLS-1$
    if (ret != null) return ret.trim();

    // Other runtimes like tomcat / default behavior (?)
    IRuntime rt = server.getRuntime();
    if (rt != null) {
      return rt.getLocation().toString();
    }

    return null; // No idea
  }
  @Override
  public boolean preLaunchCheck(
      ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
      throws CoreException {
    IServer server = ServerUtil.getServer(configuration);
    IStatus s = server.canStart(mode);
    Trace.trace(Trace.STRING_FINEST, "Ensuring Server can start: " + s.getMessage()); // $NON-NLS-1$
    if (!s.isOK()) throw new CoreException(s);

    IControllableServerBehavior jbsBehavior =
        JBossServerBehaviorUtils.getControllableBehavior(server);
    if (LaunchCommandPreferences.isIgnoreLaunchCommand(server)) {
      Trace.trace(
          Trace.STRING_FINEST,
          "Server is marked as ignore Launch. Marking as started."); //$NON-NLS-1$
      ((ControllableServerBehavior) jbsBehavior).setRunMode(mode);
      ((ControllableServerBehavior) jbsBehavior).setServerStarting();
      boolean attachDebugger = server.getAttribute(RemoteDebugUtils.ATTACH_DEBUGGER, true);
      if ("debug".equals(mode) && attachDebugger) {
        // add a listener which will run the debugger once server is started
        IServerListener listener = createAttachDebuggerListener();
        server.addServerListener(listener);
      }

      initiatePolling(server);
      return false;
    }

    validateServerStructure(server);

    Trace.trace(
        Trace.STRING_FINEST,
        "Checking if similar server is already up on the same ports."); //$NON-NLS-1$
    IStatus startedStatus = isServerStarted(server);
    boolean started = startedStatus.isOK();
    if (started) {
      Trace.trace(
          Trace.STRING_FINEST,
          "A server is already started. Now handling the already started scenario."); //$NON-NLS-1$
      return handleAlreadyStartedScenario(server, startedStatus);
    }

    Trace.trace(Trace.STRING_FINEST, "A full launch will now proceed."); // $NON-NLS-1$
    return true;
  }
 /**
  * Checks if this started server has already a configured proxy and returns the associated port if
  * it is still free, or associate a new port if the previous port is not avaiable anymore, or
  * create a new port if none existed before.
  *
  * @param startedServer
  * @return the proxy port
  * @throws CoreException
  */
 private int getProxyPort(final IServer startedServer) throws CoreException {
   final IServer liveReloadServer = getServer();
   @SuppressWarnings("unchecked")
   final Map<String, Integer> proxyPorts =
       liveReloadServer.getAttribute(PROXY_PORTS, new HashMap<String, Integer>());
   final String startedServerId = startedServer.getId();
   if (proxyPorts.containsKey(startedServerId)) {
     final int port = proxyPorts.get(startedServerId);
     if (!SocketUtil.isPortInUse(port)) {
       return port;
     }
   }
   final IServerWorkingCopy swc = getServer().createWorkingCopy();
   final int port = SocketUtil.findUnusedPort(50000, 60000);
   proxyPorts.put(startedServerId, port);
   swc.setAttribute(PROXY_PORTS, proxyPorts);
   swc.saveAll(true, null);
   return port;
 }
 /**
  * Starts the {@link LiveReloadServer} which is responsable for the embedded web/websocket/proxy
  * server configuration and lifecycle
  *
  * @param serverBehaviour
  * @throws CoreException
  * @throws TimeoutException
  * @throws InterruptedException
  */
 public void startServer() throws CoreException {
   try {
     // set the server status to "Starting"
     setServerStarting();
     // now, let's init and start the embedded jetty server from the
     // server attributes
     final IServer server = getServer();
     // retrieve the websocket port, use the default value if it was missing
     websocketPort =
         server.getAttribute(
             LiveReloadLaunchConfiguration.WEBSOCKET_PORT,
             LiveReloadLaunchConfiguration.DEFAULT_WEBSOCKET_PORT);
     // fix the new default behaviour: proxy is now always enabled
     if (!isProxyEnabled()) {
       setProxyEnabled(true);
     }
     final boolean allowRemoteConnections = isRemoteConnectionsAllowed();
     final boolean enableScriptInjection = isScriptInjectionEnabled();
     this.liveReloadServer =
         new LiveReloadServer(
             server.getName(),
             server.getHost(),
             websocketPort,
             true,
             allowRemoteConnections,
             enableScriptInjection);
     this.liveReloadServerRunnable = JettyServerRunner.start(liveReloadServer);
     if (!this.liveReloadServerRunnable.isSuccessfullyStarted()) {
       setServerStopped();
     } else {
       // listen to file changes in the workspace
       addWorkspaceResourceChangeListener();
       // listen to server lifecycles
       addServerLifeCycleListener();
       // set the server status to "Started"
       setServerStarted();
     }
   } catch (TimeoutException e) {
     setServerStopped();
     throw new CoreException(
         new Status(IStatus.ERROR, JBossLiveReloadCoreActivator.PLUGIN_ID, e.getMessage(), e));
   }
 }
 protected boolean addCustomHotcodeReplaceLogic(IServer server) {
   return server.getAttribute(
       ServerHotCodeReplaceListener.PROPERTY_HOTCODE_REPLACE_OVERRIDE, true);
 }