aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.agent.rt/src/org/jacoco/agent/rt/controller/LocalController.java
blob: 64c7c659480d7bc15e9c01622b9c43e6575e523c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
 * Copyright (c) 2009, 2012 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Brock Janiczak - initial API and implementation
 *    
 *******************************************************************************/
package org.jacoco.agent.rt.controller;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.jacoco.core.data.ExecutionDataWriter;
import org.jacoco.core.runtime.AgentOptions;
import org.jacoco.core.runtime.RuntimeData;

/**
 * Local only agent controller that will write coverage data to the filesystem.
 * This controller uses the following agent options:
 * <ul>
 * <li>destfile</li>
 * <li>append</li>
 * </ul>
 */
public class LocalController implements IAgentController {

	private RuntimeData data;

	private OutputStream output;

	public final void startup(final AgentOptions options, final RuntimeData data)
			throws IOException {
		this.data = data;
		final File destFile = new File(options.getDestfile()).getAbsoluteFile();
		final File folder = destFile.getParentFile();
		if (folder != null) {
			folder.mkdirs();
		}
		output = new BufferedOutputStream(new FileOutputStream(destFile,
				options.getAppend()));
	}

	public void writeExecutionData() throws IOException {
		final ExecutionDataWriter writer = new ExecutionDataWriter(output);
		data.collect(writer, writer, false);
	}

	public void shutdown() throws IOException {
		output.close();
	}

}