blob: 3088399f328df14b4975ff824e755aeb0ad12f6d (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*******************************************************************************
* Copyright (c) 2009, 2014 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:
* Evgeny Mandrikov - initial API and implementation
* Kyle Lieber - implementation of CheckMojo
*
*******************************************************************************/
package org.jacoco.maven;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.jacoco.core.analysis.Analyzer;
import org.jacoco.core.analysis.CoverageBuilder;
import org.jacoco.core.analysis.IBundleCoverage;
import org.jacoco.core.data.ExecutionDataStore;
/**
* Creates an IBundleCoverage.
*/
public final class BundleCreator {
private final MavenProject project;
private final FileFilter fileFilter;
/**
* Construct a new BundleCreator given the MavenProject and FileFilter.
*
* @param project
* the MavenProject
* @param fileFilter
* the FileFilter
*/
public BundleCreator(final MavenProject project, final FileFilter fileFilter) {
this.project = project;
this.fileFilter = fileFilter;
}
/**
* Create an IBundleCoverage for the given ExecutionDataStore.
*
* @param executionDataStore
* the execution data.
* @return the coverage data.
* @throws IOException
* if class files can't be read
*/
public IBundleCoverage createBundle(
final ExecutionDataStore executionDataStore) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionDataStore, builder);
final File classesDir = new File(this.project.getBuild()
.getOutputDirectory());
@SuppressWarnings("unchecked")
final List<File> filesToAnalyze = FileUtils.getFiles(classesDir,
fileFilter.getIncludes(), fileFilter.getExcludes());
for (final File file : filesToAnalyze) {
analyzer.analyzeAll(file);
}
return builder.getBundle(this.project.getName());
}
}
|