示例#1
0
  /*
   * @see IActionDelegate#run(IAction)
   */
  public void run(IAction action) {
    final String tomcatDir = TomcatLauncherPlugin.getDefault().getTomcatDir();

    if (TomcatLauncherPlugin.checkTomcatSettingsAndWarn()) {
      // TomcatLauncherPlugin.log(TomcatLauncherPlugin.getResourceString("msg.start"));
      command(tomcatDir + File.separatorChar + "conf" + File.separatorChar + "server.xml");
    }
  }
  public static void dumpJacoco() throws IOException {

    ExecutionDataFiles executionDataFiles = new ExecutionDataFiles();

    // final FileOutputStream localFile = new FileOutputStream(DESTFILE);
    // final ExecutionDataWriter localWriter = new ExecutionDataWriter(
    // localFile);
    int port =
        TomcatLauncherPlugin.getDefault()
            .getPreferenceStore()
            .getInt(TomcatLauncherPlugin.JacocoAgentPort);
    // Open a socket to the coverage agent:
    final Socket socket = new Socket(InetAddress.getByName(ADDRESS), port);
    final RemoteControlWriter writer = new RemoteControlWriter(socket.getOutputStream());
    final RemoteControlReader reader = new RemoteControlReader(socket.getInputStream());

    MemoryExecutionDataSource memoryExecutionDataSource = new MemoryExecutionDataSource();

    reader.setSessionInfoVisitor(memoryExecutionDataSource);
    reader.setExecutionDataVisitor(memoryExecutionDataSource);

    // reader.setSessionInfoVisitor(localWriter);
    // reader.setExecutionDataVisitor(localWriter);

    // Send a dump command and read the response:
    writer.visitDumpCommand(true, false);
    reader.read();

    socket.close();

    try {
      IExecutionDataSource source = executionDataFiles.newFile(memoryExecutionDataSource);
      ISessionManager sessionManager = CoverageTools.getSessionManager();
      ILaunchConfiguration launchconfig = null;
      CoverageSession Coveragesession =
          new CoverageSession(
              "tomcat coverage" + getNow(), TomcatBootstrap.getSrcRoots(), source, launchconfig);
      // SessionImporter importer=new
      // SessionImporter(sessionManager,executionDataFiles);
      // importer.importSession(s);
      // ICoverageSession session=
      ILaunch launch = null;
      // setIjavaProject

      sessionManager.addSession(Coveragesession, true, launch);

    } catch (CoreException e) {
      TomcatLauncherPlugin.log(e);
    }

    // localFile.close();
  }
  /*
   * @see IActionDelegate#run(IAction)
   */
  public void run(IAction action) {
    if (TomcatLauncherPlugin.checkTomcatSettingsAndWarn()) {
      // TomcatLauncherPlugin.log(TomcatLauncherPlugin.getResourceString("msg.stop"));
      try {

        dumpJacoco();

        TomcatLauncherPlugin.getDefault().getTomcatBootstrap().stop();
        TomcatLauncherPlugin.log("tomcat stop");

      } catch (Exception ex) {
        String msg = TomcatLauncherPlugin.getResourceString("msg.stop.failed");
        TomcatLauncherPlugin.log(msg + "/n");
        TomcatLauncherPlugin.log(ex);
      }
    }
  }