private boolean hasParentInServer(IProject project, IServer server, IProgressMonitor pm) {
    IModule[] modules = ServerUtil.getModules(project);
    if (modules == null || modules.length == 0) {
      return false;
    }
    IModule[] parents = null;
    boolean parentFound = false;
    for (IModule module : modules) {
      try {
        parents = server.getRootModules(module, pm);
      } catch (CoreException e) {
        org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e);
      }

      if (parents == null || parents.length == 0) {
        return false;
      }
      for (IModule parent : parents) {
        if (!parent.equals(module) && ServerUtil.containsModule(server, parent, pm)) {
          parentFound = true;
          break;
        }
      }
    }
    return parentFound;
  }
 public static DeployableServerBehavior getServerBehavior(ILaunchConfiguration configuration)
     throws CoreException {
   IServer server = ServerUtil.getServer(configuration);
   DeployableServerBehavior jbossServerBehavior =
       (DeployableServerBehavior) server.getAdapter(DeployableServerBehavior.class);
   return jbossServerBehavior;
 }
  public void configureLaunch(final ILaunch launch) throws CoreException {
    final IServer server = ServerUtil.getServer(configuration);

    server.addServerListener(
        new IServerListener() {
          IModule[] modules = server.getModules();

          private boolean modulesChanged(IModule[] modules, IModule[] modules2) {
            if (CoreUtil.isNullOrEmpty(modules) && CoreUtil.isNullOrEmpty(modules2)) {
              return true;
            }

            if (CoreUtil.isNullOrEmpty(modules) || CoreUtil.isNullOrEmpty(modules2)) {
              return true;
            }

            if (modules.length != modules2.length) {
              return true;
            }

            for (int i = 0; i < modules.length; i++) {
              if (!modules[i].equals(modules2[i])) {
                return true;
              }
            }

            return false;
          }

          public synchronized void serverChanged(ServerEvent event) {
            if ((event.getKind() & ServerEvent.MODULE_CHANGE) > 0) {
              IModule[] newModules = event.getServer().getModules();

              if (modulesChanged(modules, newModules)) {
                try {
                  final PortalSourceLookupDirector director =
                      (PortalSourceLookupDirector) launch.getSourceLocator();
                  director.initializeDefaults(configuration);
                } catch (Exception e) {
                  LiferayServerCore.logError(
                      "Unable to update source containers for server", e); // $NON-NLS-1$
                }

                modules = newModules;
              }
            }
          }
        });

    final ISourcePathComputer sourcePathComputer =
        getLaunchManager().getSourcePathComputer(this.sourceComputerId);
    this.setSourcePathComputer(sourcePathComputer);
    this.initializeDefaults(configuration);
    launch.setSourceLocator(this);
  }
 public void launch(
     ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
     throws CoreException {
   IServer server = ServerUtil.getServer(configuration);
   if (LaunchCommandPreferences.isIgnoreLaunchCommand(server)) {
     return;
   }
   beforeVMRunner(configuration, mode, launch, monitor);
   actualLaunch(configuration, mode, launch, monitor);
   afterVMRunner(configuration, mode, launch, monitor);
 }
 /*
  * (non-Javadoc)
  * @see org.jboss.ide.eclipse.as.wtp.core.server.launch.AbstractJavaServerLaunchDelegate#overrideHotcodeReplace(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.debug.core.ILaunch)
  */
 protected boolean overrideHotcodeReplace(ILaunchConfiguration configuration, ILaunch launch)
     throws CoreException {
   boolean added = super.overrideHotcodeReplace(configuration, launch);
   IServer server = ServerUtil.getServer(configuration);
   IControllableServerBehavior jbsBehavior =
       JBossServerBehaviorUtils.getControllableBehavior(server);
   if (added) {
     jbsBehavior.putSharedData(HOTCODE_REPLACE_OVERRIDDEN, added); // $NON-NLS-1$
   }
   return added;
 }
Exemplo n.º 6
0
  private IServer getServerFromLaunchConfig(ILaunch launch) {
    ILaunchConfiguration launchConfig = launch.getLaunchConfiguration();
    if (launchConfig == null) {
      return null;
    }

    IServer server = null;
    try {
      server = ServerUtil.getServer(launchConfig);
    } catch (CoreException e) {
      logError("getServerFromLaunchConfig: Getting the WTP server error.", e);
      return null;
    }
    return server;
  }
  @Test
  public void testMetadataWithCustomModule() {
    try {
      // Create the server
      IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType);
      IServerWorkingCopy wc = s.createWorkingCopy();
      wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_METADATA);
      s = wc.save(true, null);

      // Create the project
      projNum++;
      String projName = "Project" + projNum;
      IDataModel dm =
          CreateProjectOperationsUtility.getWebDataModel(
              projName, null, null, null, null, JavaEEFacetConstants.WEB_24, false);
      try {
        OperationTestCase.runAndVerify(dm);
      } catch (Exception e) {
        fail("Unable to create test web project: " + e.getMessage());
      }
      IProject p = ResourceUtils.findProject(projName);
      assertTrue(p.exists());
      IModule projMod = ServerUtil.getModule(p);

      // Set the custom setting. For now, just override output name
      wc = s.createWorkingCopy();
      AbstractPublishingTest.setCustomDeployOverride(wc, projMod, "newName.war", null, null);
      s = wc.save(true, null);

      // verify no change vs standard metadata
      String[] folders = getAdditions().getDeployLocationFolders(s);
      assertEquals(1, folders.length);
      assertTrue(folders[0].contains("metadata"));

      // Change it to now make some other output folder
      wc = s.createWorkingCopy();
      AbstractPublishingTest.setCustomDeployOverride(
          wc, projMod, "newName.war", "/home/user/deploy", null);
      s = wc.save(true, null);
      folders = getAdditions().getDeployLocationFolders(s);
      assertEquals(2, folders.length);
      assertTrue(folders[0].contains("metadata"));
      assertTrue(folders[1].equals("/home/user/deploy"));

    } catch (CoreException ce) {
      fail("Unable to save changes to server");
    }
  }
  @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;
  }
  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 void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    IServer server = ServerUtil.getServer(configuration);
    if (server == null) {
      Trace.trace(Trace.FINEST, "Launch configuration could not find server");
      // throw CoreException();
      return;
    }

    if (server.shouldPublish() && ServerCore.isAutoPublishing())
      server.publish(IServer.PUBLISH_INCREMENTAL, monitor);

    PreviewServerBehaviour previewServer =
        (PreviewServerBehaviour) server.loadAdapter(PreviewServerBehaviour.class, null);

    int size = REQUIRED_BUNDLE_IDS.length;
    String[] jars = new String[size];
    for (int i = 0; i < size; i++) {
      Bundle b = Platform.getBundle(REQUIRED_BUNDLE_IDS[i]);
      IPath path = null;
      if (b != null) path = PreviewRuntime.getJarredPluginPath(b);
      if (path == null)
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                PreviewPlugin.PLUGIN_ID,
                "Could not find required bundle " + REQUIRED_BUNDLE_IDS[i]));
      jars[i] = path.toOSString();
    }

    // Appending the bin onto the classpath is to support running from the workbench
    // when org.eclipse.wst.server.preview is checked out
    Trace.trace(Trace.FINEST, jars[CLASSPATH_BIN_INDEX_PREVIEW_SERVER] + File.separator + "bin");
    if (new File(jars[CLASSPATH_BIN_INDEX_PREVIEW_SERVER] + File.separator + "bin").exists())
      jars[CLASSPATH_BIN_INDEX_PREVIEW_SERVER] =
          jars[CLASSPATH_BIN_INDEX_PREVIEW_SERVER] + File.separator + "bin";

    IVMInstall vm = verifyVMInstall(configuration);

    IVMRunner runner = vm.getVMRunner(mode);
    if (runner == null) runner = vm.getVMRunner(ILaunchManager.RUN_MODE);

    File workingDir = verifyWorkingDirectory(configuration);
    String workingDirName = null;
    if (workingDir != null) workingDirName = workingDir.getAbsolutePath();

    // Program & VM args
    String pgmArgs =
        "\"" + previewServer.getTempDirectory().append("preview.xml").toOSString() + "\"";
    // getProgramArguments(configuration);
    String vmArgs = getVMArguments(configuration);
    String[] envp = getEnvironment(configuration);

    ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);

    // VM-specific attributes
    Map vmAttributesMap = getVMSpecificAttributesMap(configuration);

    // Classpath
    String[] classpath2 = getClasspath(configuration);
    String[] classpath = new String[classpath2.length + REQUIRED_BUNDLE_IDS.length];
    System.arraycopy(jars, 0, classpath, 0, REQUIRED_BUNDLE_IDS.length);
    System.arraycopy(classpath2, 0, classpath, REQUIRED_BUNDLE_IDS.length, classpath2.length);

    // Create VM config
    VMRunnerConfiguration runConfig = new VMRunnerConfiguration(MAIN_CLASS, classpath);
    runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
    runConfig.setVMArguments(execArgs.getVMArgumentsArray());
    runConfig.setWorkingDirectory(workingDirName);
    runConfig.setEnvironment(envp);
    runConfig.setVMSpecificAttributesMap(vmAttributesMap);

    // Bootpath
    String[] bootpath = getBootpath(configuration);
    if (bootpath != null && bootpath.length > 0) runConfig.setBootClassPath(bootpath);

    setDefaultSourceLocator(launch, configuration);

    // Launch the configuration
    previewServer.setupLaunch(launch, mode, monitor);

    if (ILaunchManager.PROFILE_MODE.equals(mode))
      ServerProfilerDelegate.configureProfiling(launch, vm, runConfig, monitor);

    try {
      runner.run(runConfig, launch, monitor);
      previewServer.addProcessListener(launch.getProcesses()[0]);
    } catch (Exception e) {
      // ignore - process failed
    }
  }
  protected void afterVMRunner(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    IProcess[] processes = launch.getProcesses();
    final IServer server = ServerUtil.getServer(configuration);
    IControllableServerBehavior beh =
        JBossServerBehaviorUtils.getControllableBehavior(configuration);
    if (processes != null && processes.length >= 1 && processes[0] != null) {
      ProcessTerminatedDebugListener debug =
          new ProcessTerminatedDebugListener(ServerUtil.getServer(configuration), processes[0]) {
            protected void handleEarlyTermination() {
              cancelPolling(server);
              IStatus status =
                  new Status(
                      IStatus.INFO,
                      ASWTPToolsPlugin.PLUGIN_ID,
                      IEventCodes.BEHAVIOR_PROCESS_TERMINATED,
                      Messages.TERMINATED,
                      null);
              logStatus(server, status);
            }
          };
      if (beh != null) {
        final IProcess launched = processes[0];
        beh.putSharedData(PROCESS, launched);
        beh.putSharedData(DEBUG_LISTENER, debug);
        final IServer ser = beh.getServer();

        // During some niche cases, a server may be set to stopped,
        // but the process may not be shutting down. For example if two
        // conflicting servers were launched using the same ports.
        // This is a cleanup thread that waits a significant amount of time
        // that should be suitable for all genuine shutdowns, and then
        // force terminates the process.
        IServerListener list =
            new IServerListener() {
              public void serverChanged(ServerEvent event) {
                final IServerListener list2 = this;
                int eventKind = event.getKind();
                if ((eventKind & ServerEvent.SERVER_CHANGE) != 0) {
                  // server change event
                  if ((eventKind & ServerEvent.STATE_CHANGE) != 0) {
                    if (ser.getServerState() == IServer.STATE_STOPPED) {
                      new Thread() {
                        public void run() {
                          // wait 7 seconds
                          try {
                            Thread.sleep(getProcessTerminationDelay());
                          } catch (InterruptedException ie) {
                            // do nothing
                          }
                          if (!launched.isTerminated()) {
                            // Alert user
                            Object result =
                                getPrompter()
                                    .promptUser(UserPrompter.EVENT_CODE_PROCESS_UNTERMINATED, ser);
                            if (result == null
                                || (result instanceof Boolean
                                    && ((Boolean) result).booleanValue())) {
                              // force terminate this process
                              try {
                                launched.terminate();
                              } catch (DebugException de) {
                                ASWTPToolsPlugin.log(de);
                              }
                            }
                          }
                          ser.removeServerListener(list2);
                        }
                      }.start();
                    }
                  }
                }
              }
            };
        ser.addServerListener(list);
      }
      DebugPlugin.getDefault().addDebugEventListener(debug);
    }
    initiatePolling(server);
  }
Exemplo n.º 12
0
  /**
   * Possibly start the GWT Super Dev Mode CodeServer. <br>
   * <br>
   * This starts as separate process, which allows for custom args modification. It adds a launcher
   * id to both processes for reference. 1. Get it from classic launch config 2. Get it from server
   * VM properties
   */
  protected void posiblyLaunchGwtSuperDevModeCodeServer(DebugEvent event) {
    RuntimeProcess runtimeProcess = (RuntimeProcess) event.getSource();
    ILaunch launch = runtimeProcess.getLaunch();
    ILaunchConfiguration launchConfig = launch.getLaunchConfiguration();
    String launchMode = launch.getLaunchMode();

    IServer server = null;
    try {
      server = ServerUtil.getServer(launchConfig);
    } catch (CoreException e) {
      logError("posiblyLaunchGwtSuperDevModeCodeServer: Could get the WTP server.", e);
      return;
    }

    if (server == null) {
      logMessage("posiblyLaunchGwtSuperDevModeCodeServer: No WTP server found.");
      return;
    }

    IProject project = getProject(server);
    if (project == null) {
      logMessage("posiblyLaunchGwtSuperDevModeCodeServer: Couldn't find project.");
      return;
    }

    if (!GwtFacetUtils.hasGwtFacet(project)) {
      logMessage("posiblyLaunchGwtSuperDevModeCodeServer: Does not have a GWT Facet.");
      return;
    }

    if (GWTProjectProperties.getFacetSyncCodeServer(project) != null
        && GWTProjectProperties.getFacetSyncCodeServer(project) == false) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer: GWT Facet project properties, the code server sync is off.");
      return;
    }

    /** Get the war output path for the `-launcherDir` in SDM launcher */
    String launcherDir = null;

    // Get the the war output path from classic launch configuration working directory
    // Also used GaeServerBehaviour.setupLaunchConfig(...)
    try {
      launcherDir =
          launchConfig.getAttribute(
              IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
    } catch (CoreException e) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer: Couldn't get working directory from launchConfig IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY.");
    }

    // Get the war output path from Server VM properties for working directory
    if (launcherDir == null || launcherDir.isEmpty()) {
      launcherDir = getLauncherDirFromServerLaunchConfigAttributes(server, launchConfig);
    }

    // Exit on error
    if (launcherDir == null || launcherDir.isEmpty()) {
      logError(
          "posiblyLaunchGwtSuperDevModeCodeServer: No -launcherDir arg is available, EXITING. launcherDir="
              + launcherDir);
      return;
    }

    // Add server urls to DevMode view for easy clicking on
    addServerUrlsToDevModeView(launch);

    // LauncherId used to reference and terminate the the process
    String launcherId = setLauncherIdToWtpRunTimeLaunchConfig(launchConfig);

    logMessage(
        "posiblyLaunchGwtSuperDevModeCodeServer: Launching GWT Super Dev Mode CodeServer. launcherId="
            + launcherId
            + " launcherDir="
            + launcherDir);

    // Just in case
    if (launchMode == null) {
      launchMode = "run";
    }

    if (launcherId == null) {
      logMessage("posiblyLaunchGwtSuperDevModeCodeServer: No launcherId.");
    }

    // Creates ore launches an existing Super Dev Mode Code Server process
    GwtSuperDevModeCodeServerLaunchUtil.launch(project, launchMode, launcherDir, launcherId);
  }
Exemplo n.º 13
0
  @Override
  public String[] getClasspathAdditions(TestServerConfiguration config) {
    List<String> entries = new ArrayList<String>(2);
    String entry =
        ClasspathUtil.getClasspathEntry("org.eclipse.edt.ide.deployment.core"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    entry =
        ClasspathUtil.getClasspathEntry("org.eclipse.edt.ide.deployment.services"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    entry = ClasspathUtil.getClasspathEntry("org.eclipse.edt.runtime.java"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    entry = ClasspathUtil.getClasspathEntry("com.ibm.icu"); // $NON-NLS-1$
    if (entry != null) {
      entries.add(entry);
    }

    DDUtil.addJDBCJars(
        config.getProject(), new HashSet<IProject>(), new HashSet<IResource>(), entries);

    // Add a Tomcat runtime if one's available, so that JNDI can use connection pooling.
    IRuntime bestTomcat = null;
    for (IRuntime rt : ServerUtil.getRuntimes(null, null)) {
      if (rt.getRuntimeType().getName().toLowerCase().contains("tomcat")) { // $NON-NLS-1$
        if (bestTomcat == null) {
          bestTomcat = rt;
        } else if (bestTomcat
                .getRuntimeType()
                .getVersion()
                .compareTo(rt.getRuntimeType().getVersion())
            < 0) {
          bestTomcat = rt;
        }
      }
    }

    if (bestTomcat != null) {
      RuntimeClasspathProviderWrapper rcpw =
          JavaServerPlugin.findRuntimeClasspathProvider(bestTomcat.getRuntimeType());
      if (rcpw != null) {
        entries.add(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeClasspathEntry containerPath=\"" //$NON-NLS-1$
                + RuntimeClasspathContainer.SERVER_CONTAINER
                + "/"
                + rcpw.getId()
                + "/"
                + bestTomcat.getId() // $NON-NLS-1$ //$NON-NLS-2$
                + "\" path=\"3\" type=\"4\"/>"); //$NON-NLS-1$
      }
    }

    return entries.toArray(new String[entries.size()]);
  }