コード例 #1
0
  public ILaunchConfiguration getSelectedLaunchConfiguration() {
    if (!fLaunchConfigButton.getSelection()) return null;

    String configName = fLaunchConfigCombo.getText();
    try {
      ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
      ILaunchConfigurationType type =
          manager.getLaunchConfigurationType(EclipseLaunchShortcut.CONFIGURATION_TYPE);
      ILaunchConfigurationType type2 =
          manager.getLaunchConfigurationType(IPDELauncherConstants.OSGI_CONFIGURATION_TYPE);
      ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
      ILaunchConfiguration[] configs2 = manager.getLaunchConfigurations(type2);
      ILaunchConfiguration[] configurations =
          new ILaunchConfiguration[configs.length + configs2.length];
      System.arraycopy(configs, 0, configurations, 0, configs.length);
      System.arraycopy(configs2, 0, configurations, configs.length, configs2.length);
      for (int i = 0; i < configurations.length; i++) {
        if (configurations[i].getName().equals(configName)
            && !DebugUITools.isPrivate(configurations[i])) return configurations[i];
      }
    } catch (CoreException e) {
      PDEPlugin.logException(e);
    }
    return null;
  }
コード例 #2
0
  public void initializeRegistry(IProcess process) {
    fProcess = process;
    processListener =
        new IDebugEventSetListener() {
          /** @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(DebugEvent[]) */
          public void handleDebugEvents(DebugEvent[] events) {
            for (int i = 0; i < events.length; i++) {
              DebugEvent e = events[i];
              if (e.getSource() == fProcess && e.getKind() == DebugEvent.TERMINATE) {
                // We terminating too soon. Pop up a msg.
                IStreamsProxy stProxy = fProcess.getStreamsProxy();
                java.io.StringWriter s = new java.io.StringWriter();
                java.io.PrintWriter w = new java.io.PrintWriter(s);

                String msg =
                    MessageFormat.format(
                        ProxyRemoteMessages.Proxy_Terminated_too_soon_ERROR_, new Object[] {fName});
                w.println(msg);
                w.println(ProxyRemoteMessages.VM_TERMINATED_INFO_);
                w.println(ProxyRemoteMessages.VM_COMMAND_LINE);
                w.println(fProcess.getAttribute(IProcess.ATTR_CMDLINE));
                w.println(ProxyRemoteMessages.VM_TERMINATED_LINE1);
                w.println(stProxy.getErrorStreamMonitor().getContents());
                w.println(ProxyRemoteMessages.VM_TERMINATED_LINE2);
                w.println(stProxy.getOutputStreamMonitor().getContents());
                w.println(ProxyRemoteMessages.VM_TERMINATED_LINE3);
                w.close();

                DebugModeHelper dh = new DebugModeHelper();
                dh.displayErrorMessage(ProxyRemoteMessages.Proxy_Error_Title, msg);
                ProxyPlugin.getPlugin()
                    .getLogger()
                    .log(
                        new Status(
                            IStatus.WARNING,
                            ProxyPlugin.getPlugin().getBundle().getSymbolicName(),
                            0,
                            s.toString(),
                            null));
                processListener = null;
                DebugPlugin.getDefault().removeDebugEventListener(this);
                terminateRegistry();
                break;
              }
            }
          }
        };

    DebugPlugin.getDefault().addDebugEventListener(processListener);
  }
コード例 #3
0
 private String[] getLaunchConfigurations() {
   ArrayList list = new ArrayList();
   try {
     ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
     ILaunchConfigurationType type =
         manager.getLaunchConfigurationType(EclipseLaunchShortcut.CONFIGURATION_TYPE);
     ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
     for (int i = 0; i < configs.length; i++) {
       if (!DebugUITools.isPrivate(configs[i])) list.add(configs[i].getName());
     }
     // add osgi launch configs to the list
     type = manager.getLaunchConfigurationType(IPDELauncherConstants.OSGI_CONFIGURATION_TYPE);
     configs = manager.getLaunchConfigurations(type);
     for (int i = 0; i < configs.length; i++) {
       if (!DebugUITools.isPrivate(configs[i])) list.add(configs[i].getName());
     }
   } catch (CoreException e) {
     PDEPlugin.logException(e);
   }
   return (String[]) list.toArray(new String[list.size()]);
 }
コード例 #4
0
ファイル: DeployUtil.java プロジェクト: robsman/stardust.ide
  public static boolean deployModel(
      List<IResource> resources, String carnotHome, String carnotWork) {
    boolean deployed = false;

    if (null != resources && !resources.isEmpty()) {
      try {
        IProject project = getCommonProject(resources);
        ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        ILaunchConfigurationType type =
            manager.getLaunchConfigurationType(
                IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
        ILaunchConfigurationWorkingCopy wc =
            type.newInstance(null, "Infinity Process Model Deployment"); // $NON-NLS-1$
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
        wc.setAttribute(
            IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
            ModelingCoreActivator.ID_DEPLOY_MODEL_CP_PROVIDER);
        wc.setAttribute(
            IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
            ModelDeploymentTool.class.getName());
        // Activate if debugging deployment is needed.
        // String debug =
        // " -Xdebug -Xnoagent -Djava.compiler=NONE
        // -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000";
        // String debug =
        // " -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000";
        wc.setAttribute(
            IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
            "-Xms50m -Xmx256m" + getLocaleArgs()); // $NON-NLS-1$
        // "-Xms50m -Xmx256m" + debug);

        boolean version =
            PlatformUI.getPreferenceStore().getBoolean(BpmProjectNature.PREFERENCE_DEPLOY_version);

        String realm =
            PlatformUI.getPreferenceStore().getString(BpmProjectNature.PREFERENCE_DEPLOY_realm);
        String partition =
            PlatformUI.getPreferenceStore().getString(BpmProjectNature.PREFERENCE_DEPLOY_partition);
        String user =
            PlatformUI.getPreferenceStore().getString(BpmProjectNature.PREFERENCE_DEPLOY_id);
        String password =
            PlatformUI.getPreferenceStore().getString(BpmProjectNature.PREFERENCE_DEPLOY_password);
        String domain =
            PlatformUI.getPreferenceStore().getString(BpmProjectNature.PREFERENCE_DEPLOY_domain);

        StringBuilder programAttributes = new StringBuilder();
        boolean separator = false;
        for (IResource resource : resources) {
          // addArgument(programAttributes, "filename64", resource.getLocation().toOSString(), true,
          // separator);
          // separator = true;
          try {
            String fileName = resource.getLocation().toOSString();
            String encodedFileName =
                new String(Base64.encode(fileName.getBytes(XpdlUtils.UTF8_ENCODING)));
            addArgument(
                programAttributes, "filename64", encodedFileName, false, separator); // $NON-NLS-1$
            separator = true;
          } catch (UnsupportedEncodingException e) {
            // should never happen since UTF-8 is standard supported on all java versions.
            e.printStackTrace();
          }
        }
        if (version) {
          addArgument(
              programAttributes,
              "version",
              Boolean.TRUE.toString(),
              false,
              true); //$NON-NLS-1$ //$NON-NLS-2$
        }

        if (!StringUtils.isEmpty(user) && !StringUtils.isEmpty(password)) {
          addArgument(programAttributes, "user", user, true, true); // $NON-NLS-1$
          addArgument(
              programAttributes, "password", password, true, true); // $NON-NLS-1$

          if (!StringUtils.isEmpty(realm)) {
            addArgument(programAttributes, "realm", realm, true, true); // $NON-NLS-1$
          }

          if (!StringUtils.isEmpty(partition)) {
            addArgument(
                programAttributes, "partition", partition, true, true); // $NON-NLS-1$
          }

          if (!StringUtils.isEmpty(domain)) {
            addArgument(programAttributes, "domain", domain, true, true); // $NON-NLS-1$
          }
        }

        wc.setAttribute(
            IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programAttributes.toString());

        wc.setAttribute(CarnotToolClasspathProvider.ATTR_HOME_LOCATION, carnotHome);
        wc.setAttribute(CarnotToolClasspathProvider.ATTR_WORK_LOCATION, carnotWork);

        wc.setAttribute(
            CarnotToolClasspathProvider.ATTR_EXTRA_LOCATION,
            BpmCoreLibrariesClasspathContainer.getLibraryLocation(
                    DeployPlugin.PLUGIN_ID, new String[] {"bin", ""})
                .toString()); //$NON-NLS-1$ //$NON-NLS-2$

        ILaunchConfiguration config = wc.doSave();
        ILaunch toolLaunch = config.launch(ILaunchManager.RUN_MODE, null);

        deployed = (0 < toolLaunch.getProcesses().length);

        config.delete();
        wc.delete();
      } catch (CoreException e) {
        // TODO
        e.printStackTrace();
      }
    }
    return deployed;
  }
コード例 #5
0
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }
    PHPexeItem phpExeItem = PHPLaunchUtilities.getPHPExe(configuration);
    if (phpExeItem == null) {
      Logger.log(Logger.ERROR, "Launch configuration could not find PHP exe item"); // $NON-NLS-1$
      monitor.setCanceled(true);
      monitor.done();
      return;
    }
    // get the launch info: php exe, php ini
    final String phpExeString =
        configuration.getAttribute(IPHPDebugConstants.ATTR_EXECUTABLE_LOCATION, (String) null);
    final String phpIniString =
        configuration.getAttribute(IPHPDebugConstants.ATTR_INI_LOCATION, (String) null);
    final String phpScriptString =
        configuration.getAttribute(IPHPDebugConstants.ATTR_FILE, (String) null);
    if (phpScriptString == null || phpScriptString.trim().length() == 0) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      displayErrorMessage(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_0);
      return;
    }
    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    // locate the project from the php script
    final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    final IPath filePath = new Path(phpScriptString);
    final IResource scriptRes = workspaceRoot.findMember(filePath);
    if (scriptRes == null) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      displayErrorMessage(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_1);
      return;
    }

    // resolve php exe location
    final IPath phpExe = new Path(phpExeString);

    // resolve project directory
    IProject project = scriptRes.getProject();

    // Set Project Name as this is required by the source lookup computer
    // delegate
    final String projectString = project.getFullPath().toString();
    ILaunchConfigurationWorkingCopy wc = null;
    if (configuration.isWorkingCopy()) {
      wc = (ILaunchConfigurationWorkingCopy) configuration;
    } else {
      wc = configuration.getWorkingCopy();
    }
    wc.setAttribute(IPHPDebugConstants.PHP_Project, projectString);
    wc.setAttribute(
        IDebugParametersKeys.TRANSFER_ENCODING, PHPProjectPreferences.getTransferEncoding(project));
    wc.setAttribute(
        IDebugParametersKeys.OUTPUT_ENCODING, PHPProjectPreferences.getOutputEncoding(project));
    wc.doSave();

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    IPath projectLocation = project.getRawLocation();
    if (projectLocation == null) {
      projectLocation = project.getLocation();
    }

    // resolve the script location, but not relative to anything
    IPath phpFile = scriptRes.getLocation();

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    // Resolve the PHP ini location
    // Locate the php ini by using the attribute. If the attribute was null,
    // try to locate an ini that exists next to the executable.
    File phpIni =
        (phpIniString != null && new File(phpIniString).exists())
            ? new File(phpIniString)
            : PHPINIUtil.findPHPIni(phpExeString);
    File tempIni = PHPINIUtil.prepareBeforeLaunch(phpIni, phpExeString, project);
    launch.setAttribute(IDebugParametersKeys.PHP_INI_LOCATION, tempIni.getAbsolutePath());

    // add process type to process attributes, basically the name of the exe
    // that was launched
    final Map<String, String> processAttributes = new HashMap<String, String>();
    String programName = phpExe.lastSegment();
    final String extension = phpExe.getFileExtension();
    if (extension != null) {
      programName = programName.substring(0, programName.length() - (extension.length() + 1));
    }
    programName = programName.toLowerCase();

    // used by the console colorer extension to determine what class to use
    // should allow the console color providers and line trackers to work
    // process.setAttribute(IProcess.ATTR_PROCESS_TYPE,
    // IPHPConstants.PHPProcessType);

    processAttributes.put(IProcess.ATTR_PROCESS_TYPE, programName);
    // used by the Console to give that console a name
    processAttributes.put(IProcess.ATTR_CMDLINE, phpScriptString);

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    // determine the environment variables
    String[] envVarString = null;
    DBGpTarget target = null;
    if (mode.equals(ILaunchManager.DEBUG_MODE)) {
      // check the launch for stop at first line, if not there go to
      // project specifics
      boolean stopAtFirstLine = PHPProjectPreferences.getStopAtFirstLine(project);
      stopAtFirstLine =
          configuration.getAttribute(IDebugParametersKeys.FIRST_LINE_BREAKPOINT, stopAtFirstLine);
      String sessionID = DBGpSessionHandler.getInstance().generateSessionId();
      String ideKey = null;
      if (phpExeItem != null) {
        DBGpProxyHandler proxyHandler =
            DBGpProxyHandlersManager.INSTANCE.getHandler(phpExeItem.getUniqueId());
        if (proxyHandler != null && proxyHandler.useProxy()) {
          ideKey = proxyHandler.getCurrentIdeKey();
          if (proxyHandler.registerWithProxy() == false) {
            displayErrorMessage(
                PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_2
                    + proxyHandler.getErrorMsg());
            DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
            return;
          }
        } else {
          ideKey = DBGpSessionHandler.getInstance().getIDEKey();
        }
      }
      target = new DBGpTarget(launch, phpFile.lastSegment(), ideKey, sessionID, stopAtFirstLine);
      target.setPathMapper(PathMapperRegistry.getByLaunchConfiguration(configuration));
      DBGpSessionHandler.getInstance().addSessionListener(target);
      envVarString = createDebugLaunchEnvironment(configuration, sessionID, ideKey, phpExe);

      int requestPort = getDebugPort(phpExeItem);
      // Check that the debug daemon is functional
      // DEBUGGER - Make sure that the active debugger id is indeed Zend's
      // debugger
      if (!PHPLaunchUtilities.isDebugDaemonActive(
          requestPort, XDebugCommunicationDaemon.XDEBUG_DEBUGGER_ID)) {
        PHPLaunchUtilities.showLaunchErrorMessage(
            NLS.bind(
                PHPDebugCoreMessages.ExeLaunchConfigurationDelegate_PortInUse,
                requestPort,
                phpExeItem.getName()));
        monitor.setCanceled(true);
        monitor.done();
        return;
      }

    } else {
      envVarString =
          PHPLaunchUtilities.getEnvironment(configuration, new String[] {getLibraryPath(phpExe)});
    }

    IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 30);
    subMonitor.beginTask(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_3, 10);

    // determine the working directory. default is the location of the
    // script
    IPath workingPath = phpFile.removeLastSegments(1);
    File workingDir = workingPath.makeAbsolute().toFile();

    boolean found = false;
    for (int i = 0; i < envVarString.length && !found; i++) {
      String envEntity = envVarString[i];
      String[] elements = envEntity.split("="); // $NON-NLS-1$
      if (elements.length > 0 && elements[0].equals("XDEBUG_WORKING_DIR")) { // $NON-NLS-1$
        found = true;
        workingPath = new Path(elements[1]);
        File temp = workingPath.makeAbsolute().toFile();
        if (temp.exists()) {
          workingDir = temp;
        }
      }
    }

    // Detect PHP SAPI type and thus where we need arguments
    File phpExeFile = new File(phpExeString);
    String sapiType = null;
    String phpV = null;
    PHPexeItem[] items = PHPexes.getInstance().getAllItems();
    for (PHPexeItem item : items) {
      if (item.getExecutable().equals(phpExeFile)) {
        sapiType = item.getSapiType();
        phpV = item.getVersion();
        break;
      }
    }
    String[] args = null;
    if (PHPexeItem.SAPI_CLI.equals(sapiType)) {
      args = PHPLaunchUtilities.getProgramArguments(launch.getLaunchConfiguration());
    }

    // define the command line for launching
    String[] cmdLine = null;
    cmdLine =
        PHPLaunchUtilities.getCommandLine(
            configuration,
            phpExe.toOSString(),
            tempIni.toString(),
            phpFile.toOSString(),
            args,
            phpV);

    // Launch the process
    final Process phpExeProcess = DebugPlugin.exec(cmdLine, workingDir, envVarString);
    // Attach a crash detector
    new Thread(new ProcessCrashDetector(launch, phpExeProcess)).start();

    IProcess eclipseProcessWrapper = null;
    if (phpExeProcess != null) {
      subMonitor.worked(10);
      eclipseProcessWrapper =
          DebugPlugin.newProcess(launch, phpExeProcess, phpExe.toOSString(), processAttributes);
      if (eclipseProcessWrapper == null) {

        // another error so we stop everything somehow
        phpExeProcess.destroy();
        subMonitor.done();
        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
        throw new CoreException(new Status(IStatus.ERROR, PHPDebugPlugin.ID, 0, null, null));
      }

      // if launching in debug mode, create the debug infrastructure and
      // link it with the launched process
      if (mode.equals(ILaunchManager.DEBUG_MODE) && target != null) {
        target.setProcess(eclipseProcessWrapper);
        launch.addDebugTarget(target);
        subMonitor.subTask(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_4);
        target.waitForInitialSession(
            (DBGpBreakpointFacade) IDELayerFactory.getIDELayer(),
            XDebugPreferenceMgr.createSessionPreferences(),
            monitor);
      }

    } else {
      // we did not launch
      if (mode.equals(ILaunchManager.DEBUG_MODE)) {
        DBGpSessionHandler.getInstance().removeSessionListener(target);
      }
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
    }
    subMonitor.done();
  }
コード例 #6
0
  protected void registryTerminated(boolean wait) {
    if (processListener != null) {
      // Remove listener cause we are now going to terminate process and don't want premature
      // terminate notice.
      // Sometimes in shutdown we are called and the debug plugin may of already been shutdown. In
      // that case the db
      // will be null and there is nothing remove listener from.
      DebugPlugin db = DebugPlugin.getDefault();
      if (db != null) db.removeDebugEventListener(processListener);
      processListener = null;
    }

    Job tjob = null;
    if (waitRegistrationThread != null) {
      synchronized (waitRegistrationThread) {
        // Still waiting. close it out.
        WaitForRegistrationThread wThread = waitRegistrationThread;
        waitRegistrationThread = null;
        wThread.notifyAll();
      }
    }
    if (fServerPort != 0) {
      IREMConnection closeCon = null; // The connection we will use to close the remote vm.
      synchronized (fConnectionPool) {
        // Now we walk through all of the free connections and close them properly.
        Iterator itr = fConnectionPool.iterator();
        if (itr.hasNext()) closeCon = (IREMConnection) itr.next();
        while (itr.hasNext()) {
          IREMConnection con = (IREMConnection) itr.next();
          con.close();
        }
      }

      // Now we terminate the server.
      if (closeCon == null)
        try {
          closeCon =
              getFreeConnection(); // There weren't any free connections, so get a new one so that
                                   // we can close it.
        } catch (IllegalStateException e) {
          // Do nothing, don't want to stop termination just because we can't get a connection.
        }
      if (closeCon != null) {
        closeCon
            .terminateServer(); // We got a connection to terminate (process may of terminated
                                // early, so we would not have a conn then).
      }
      fConnectionPool.clear();
      fServerPort = 0;

      if (fProcess != null && !fRegistryController.inShutDown()) {
        tjob = new TerminateProcess(fProcess);
        tjob.setSystem(true);
        tjob.schedule();
        fProcess = null;
      }
    }

    if (fCallbackServer != null) {
      fCallbackServer.requestShutdown();
      fCallbackServer = null;
    }

    fConnectionPool.clear();
    fRegistryController.deregisterRegistry(fRegistryKey); // De-register this registry.

    if (wait && tjob != null) {
      try {
        tjob.join();
      } catch (InterruptedException e) {
        // It timed out, so we'll just go on.
      }
    }
  }