@Test
 public void shouldStopRunningServerWhenStoppingBundler() throws Exception {
   // pre-condition: create a first server (no need for script injection)
   createAndLaunchLiveReloadServer("Server 1", false);
   assertThat(liveReloadServer.getServerState()).isEqualTo(IServer.STATE_STARTED);
   // operation: stop the core bundle
   JBossLiveReloadCoreActivator.getDefault()
       .stop(JBossLiveReloadCoreActivator.getDefault().getBundle().getBundleContext());
   // verification
   assertThat(liveReloadServer.getServerState()).isEqualTo(IServer.STATE_STOPPED);
 }
 public static IServer getRunningServer() {
   IServer server = null;
   for (IServer s : getServers()) {
     if (s.getServerState() == IServer.STATE_STARTED) {
       server = s;
       break;
     }
   }
   return server;
 }
  @Override
  public void doSave(IProgressMonitor monitor) {
    if (standardOptions != null) standardOptions.updateListeners();
    if (perModuleOptions != null) perModuleOptions.updateListeners();

    IServer s = getServer();
    if (s.getServerState() == IServer.STATE_STARTED) {
      JBossExtendedProperties properties =
          (JBossExtendedProperties) s.loadAdapter(JBossExtendedProperties.class, null);
      if (properties != null) {
        IDeploymentScannerModifier modifier = properties.getDeploymentScannerModifier();
        if (modifier != null) {
          Job scannerJob = modifier.getUpdateDeploymentScannerJob(s);
          if (scannerJob != null) scannerJob.schedule();
        }
      }
    }
  }
 public boolean startServer(String serverId, Object shell) {
   IServer server = getServer(serverId);
   if (server == null) return false;
   else {
     try {
       if (server.getServerState() != IServer.STATE_STARTING) {
         server.start("run", (IProgressMonitor) null);
       }
       if (shell == null) return true;
       else {
         if (shell instanceof Shell) return waitUntilTheServerStarts(server, (Shell) shell);
         else return true;
       }
     } catch (CoreException e) {
       return false;
     }
   }
 }
  public void selectionChanged(IAction action, ISelection selection) {
    selectedServer = null;

    if (!selection.isEmpty()) {
      if (selection instanceof IStructuredSelection) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();

        if (obj instanceof IServer) {
          selectedServer = (IServer) obj;

          action.setEnabled((selectedServer.getServerState() & getRequiredServerState()) > 0);
        } else if (obj instanceof IServerModule) {
          selectedModule = (IServerModule) obj;

          action.setEnabled(
              (selectedModule.getServer().getServerState() & getRequiredServerState()) > 0);
        }
      }
    }
  }
  private String getUrl() throws CoreException {
    String urlString = null;
    IServer server = getServer();
    if (server != null && server.getServerState() == IServer.STATE_STARTED) {
      // When a module is selected, behave as you would during run-on-server for project-level
      // selection
      ModuleServer ms = getModuleServer();
      if (ms != null) {
        // Go through the wtp framework to find the proper launchable adapter for the project
        JBTCustomHttpLaunchable launchable = getCustomLaunchable(server, ms.getModule());
        // IF its one we provide, return its url directly
        if (launchable != null) {
          return (launchable).getURL().toString();
        }

        // Otherwise, do the magic we did in the past to try our best to come up with a url
        IModule[] mss = ms.getModule();
        IModule m = getWebModule(mss);
        if (m != null) {
          IServer s = getServer();
          Object o = s.loadAdapter(IURLProvider.class, null);
          if (o instanceof IURLProvider) {
            URL url = ((IURLProvider) o).getModuleRootURL(m);
            if (url != null) {
              urlString = url.toString();
            }
          }
        }
      } else {
        // When no module is selected,use welcome page url
        ServerExtendedProperties props =
            (ServerExtendedProperties)
                server.loadAdapter(ServerExtendedProperties.class, new NullProgressMonitor());
        if (props != null) urlString = props.getWelcomePageUrl();
      }
    }
    return urlString;
  }
  private IStatus updateServerRefs(
      IModule[] modulesToRemove, IServer affectedServer, IProgressMonitor monitor)
      throws CoreException {
    if (modulesToRemove == null || modulesToRemove.length == 0) {
      return Status.OK_STATUS;
    }
    monitor.beginTask(MODS_FROM_SERVERS, modulesToRemove.length * 100);
    for (int j = 0; j < modulesToRemove.length; j++) {
      IServerWorkingCopy wc = null;
      try {
        wc = affectedServer.createWorkingCopy();
        List list = Arrays.asList(affectedServer.getModules());
        if (list.contains(modulesToRemove[j])) {
          ServerUtil.modifyModules(wc, null, new IModule[] {modulesToRemove[j]}, null);
        }
      } catch (CoreException ce) {
        // Add it to a multistatus list?
        throw ce;
        // J2EEPlugin.logError(ce);
      } finally {
        try {
          if (wc != null) {
            IServer newServer = wc.saveAll(true, null);
            int state = newServer.getServerState();
            if (state == IServer.STATE_STARTED) {
              newServer.publish(
                  IServer.PUBLISH_INCREMENTAL,
                  new NullProgressMonitor()); // TODO use child progress?
            }
          }

        } catch (CoreException ce) {
          throw ce;
        }
      }
    }
    return Status.OK_STATUS;
  }
 public int getServerStatus(String serverId) {
   IServer server = getServer(serverId);
   if (server == null) return 0;
   else return server.getServerState();
 }
Esempio n. 9
0
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    IStatus retval = Status.OK_STATUS;

    if (monitor != null) {
      monitor.beginTask(Msgs.runningCleanAppServerTask, IProgressMonitor.UNKNOWN);
    }

    try {
      IRuntime runtime = ServerUtil.getRuntime(project);
      IServer[] servers = ServerUtil.getServersForRuntime(runtime);

      for (IServer server : servers) {
        String mode = server.getServerState() == IServer.STATE_STARTED ? server.getMode() : null;

        if (mode != null) {
          LiferayTomcatUtil.syncStopServer(server);
        }
      }

      ILiferayTomcatRuntime portalTomcatRuntime =
          LiferayTomcatUtil.getLiferayTomcatRuntime(runtime);
      IPath bundleZipLocation = portalTomcatRuntime.getBundleZipLocation();

      Map<String, String> appServerProperties = ServerUtil.configureAppServerProperties(project);

      String appServerDir =
          ServerUtil.getAppServerPropertyKey(
              ISDKConstants.PROPERTY_APP_SERVER_DIR, portalTomcatRuntime);

      IStatus status =
          getSDK()
              .cleanAppServer(
                  project, bundleZipLocation, appServerDir, appServerProperties, monitor);

      assertStatus(status);

      for (IServer server : servers) {
        // need to mark all other server modules at needing republishing since ext will wipe out
        // webapps folder
        IModule[] modules = server.getModules();

        for (IModule mod : modules) {
          IModule[] m = new IModule[] {mod};

          ((LiferayTomcatServerBehavior)
                  server.loadAdapter(LiferayTomcatServerBehavior.class, monitor))
              .setModulePublishState2(m, IServer.PUBLISH_STATE_FULL);
        }
      }

    } catch (Exception ex) {
      retval = LiferayTomcatPlugin.createErrorStatus(ex);
    }

    if (monitor != null) {
      monitor.done();
    }

    return retval;
  }