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();
  }
Пример #2
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   try {
     final Socket socket = serverSocket.accept();
     writer = new RemoteControlWriter(socket.getOutputStream());
     final RemoteControlReader reader = new RemoteControlReader(socket.getInputStream());
     while (true) {
       final MemoryExecutionDataSource memory = new MemoryExecutionDataSource();
       memory.readFrom(reader);
       if (memory.isEmpty()) {
         return Status.OK_STATUS;
       }
       dataReceived = true;
       final CoverageSession session =
           new CoverageSession(
               createDescription(),
               launch.getScope(),
               files.newFile(memory),
               launch.getLaunchConfiguration());
       sessionManager.addSession(session, preferences.getActivateNewSessions(), launch);
     }
   } catch (IOException e) {
     return EclEmmaStatus.EXECDATA_DUMP_ERROR.getStatus(e);
   } catch (CoreException e) {
     return e.getStatus();
   }
 }