aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-08-30 22:13:04 +0600
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-08-30 22:13:04 +0600
commite69ba4dbb015949c5d84ba7bbb0b53efac28bb23 (patch)
tree44cbe6d78216fcb3c37c0aca1dc7ed3fc09906fa /org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
parenta888d873ac20357a4a11029bc84c5c4b48e394a3 (diff)
downloadjacoco-e69ba4dbb015949c5d84ba7bbb0b53efac28bb23.tar.gz
Fix EOLs
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java428
1 files changed, 214 insertions, 214 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
index 1b351d6d..b6400bcf 100644
--- a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
+++ b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
@@ -1,214 +1,214 @@
-/*******************************************************************************
- * 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:
- * Marc R. Hoffmann - initial API and implementation
- *
- *******************************************************************************/
-package org.jacoco.core.analysis;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.StringTokenizer;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.jacoco.core.data.ExecutionData;
-import org.jacoco.core.data.ExecutionDataStore;
-import org.jacoco.core.internal.analysis.ClassAnalyzer;
-import org.jacoco.core.internal.analysis.ContentTypeDetector;
-import org.jacoco.core.internal.analysis.StringPool;
-import org.jacoco.core.internal.data.CRC64;
-import org.jacoco.core.internal.flow.ClassProbesAdapter;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-
-/**
- * An {@link Analyzer} instance processes a set of Java class files and
- * calculates coverage data for them. For each class file the result is reported
- * to a given {@link ICoverageVisitor} instance. In addition the
- * {@link Analyzer} requires a {@link ExecutionDataStore} instance that holds
- * the execution data for the classes to analyze. The {@link Analyzer} offers
- * several methods to analyze classes from a variety of sources.
- */
-public class Analyzer {
-
- private final ExecutionDataStore executionData;
-
- private final ICoverageVisitor coverageVisitor;
-
- private final StringPool stringPool;
-
- /**
- * Creates a new analyzer reporting to the given output.
- *
- * @param executionData
- * execution data
- * @param coverageVisitor
- * the output instance that will coverage data for every analyzed
- * class
- */
- public Analyzer(final ExecutionDataStore executionData,
- final ICoverageVisitor coverageVisitor) {
- this.executionData = executionData;
- this.coverageVisitor = coverageVisitor;
- this.stringPool = new StringPool();
- }
-
- /**
- * Creates an ASM class visitor for analysis.
- *
- * @param classid
- * id of the class calculated with {@link CRC64}
- * @return ASM visitor to write class definition to
- */
- private ClassVisitor createAnalyzingVisitor(final long classid) {
- final ExecutionData data = executionData.get(classid);
- final boolean[] classExec = data == null ? null : data.getData();
- final ClassAnalyzer analyzer = new ClassAnalyzer(classid, classExec,
- stringPool) {
- @Override
- public void visitEnd() {
- super.visitEnd();
- coverageVisitor.visitCoverage(getCoverage());
- }
- };
- return new ClassProbesAdapter(analyzer);
- }
-
- /**
- * Analyzes the class given as a ASM reader.
- *
- * @param reader
- * reader with class definitions
- */
- public void analyzeClass(final ClassReader reader) {
- final ClassVisitor visitor = createAnalyzingVisitor(CRC64
- .checksum(reader.b));
- reader.accept(visitor, 0);
- }
-
- /**
- * Analyzes the class definition from a given in-memory buffer.
- *
- * @param buffer
- * class definitions
- */
- public void analyzeClass(final byte[] buffer) {
- analyzeClass(new ClassReader(buffer));
- }
-
- /**
- * Analyzes the class definition from a given input stream.
- *
- * @param input
- * stream to read class definition from
- * @throws IOException
- */
- public void analyzeClass(final InputStream input) throws IOException {
- analyzeClass(new ClassReader(input));
- }
-
- /**
- * Analyzes all classes contained in the ZIP archive (jar, war, ear, etc.)
- * given as an input stream. Contained archives are read recursively.
- *
- * @param input
- * ZIP archive data
- * @return number of class files found
- * @throws IOException
- */
- public int analyzeArchive(final InputStream input) throws IOException {
- final ZipInputStream zip = new ZipInputStream(input);
- int count = 0;
- while (true) {
- final ZipEntry entry = zip.getNextEntry();
- if (entry == null) {
- break;
- }
- count += analyzeAll(zip);
- }
- return count;
- }
-
- /**
- * Analyzes all classes found in the given input stream. The input stream
- * may either represent a single class file or a ZIP archive that is
- * searched recursively for class files. All other content types are
- * ignored.
- *
- * @param input
- * input data
- * @return number of class files found
- * @throws IOException
- */
- public int analyzeAll(final InputStream input) throws IOException {
- final ContentTypeDetector detector = new ContentTypeDetector(input);
- switch (detector.getType()) {
- case ContentTypeDetector.CLASSFILE:
- analyzeClass(detector.getInputStream());
- return 1;
- case ContentTypeDetector.ZIPFILE:
- return analyzeArchive(detector.getInputStream());
- default:
- return 0;
- }
- }
-
- /**
- * Analyzes all class files contained in the given file or folder. Class
- * files as well as ZIP files are considered. Folders are searched
- * recursively.
- *
- * @param file
- * file or folder to look for class files
- * @return number of class files found
- * @throws IOException
- */
- public int analyzeAll(final File file) throws IOException {
- int count = 0;
- if (file.isDirectory()) {
- for (final File f : file.listFiles()) {
- count += analyzeAll(f);
- }
- } else {
- final InputStream in = new FileInputStream(file);
- try {
- count += analyzeAll(in);
- } finally {
- in.close();
- }
- }
- return count;
- }
-
- /**
- * Analyzes all classes from the given class path. Directories containing
- * class files as well as archive files are considered.
- *
- * @param path
- * path definition
- * @param basedir
- * optional base directory, if <code>null</code> the current
- * working directory is used as the base for relative path
- * entries
- * @return number of class files found
- * @throws IOException
- */
- public int analyzeAll(final String path, final File basedir)
- throws IOException {
- int count = 0;
- final StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
- while (st.hasMoreTokens()) {
- count += analyzeAll(new File(basedir, st.nextToken()));
- }
- return count;
- }
-
-}
+/*******************************************************************************
+ * 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:
+ * Marc R. Hoffmann - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.analysis;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.StringTokenizer;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.jacoco.core.data.ExecutionData;
+import org.jacoco.core.data.ExecutionDataStore;
+import org.jacoco.core.internal.analysis.ClassAnalyzer;
+import org.jacoco.core.internal.analysis.ContentTypeDetector;
+import org.jacoco.core.internal.analysis.StringPool;
+import org.jacoco.core.internal.data.CRC64;
+import org.jacoco.core.internal.flow.ClassProbesAdapter;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+
+/**
+ * An {@link Analyzer} instance processes a set of Java class files and
+ * calculates coverage data for them. For each class file the result is reported
+ * to a given {@link ICoverageVisitor} instance. In addition the
+ * {@link Analyzer} requires a {@link ExecutionDataStore} instance that holds
+ * the execution data for the classes to analyze. The {@link Analyzer} offers
+ * several methods to analyze classes from a variety of sources.
+ */
+public class Analyzer {
+
+ private final ExecutionDataStore executionData;
+
+ private final ICoverageVisitor coverageVisitor;
+
+ private final StringPool stringPool;
+
+ /**
+ * Creates a new analyzer reporting to the given output.
+ *
+ * @param executionData
+ * execution data
+ * @param coverageVisitor
+ * the output instance that will coverage data for every analyzed
+ * class
+ */
+ public Analyzer(final ExecutionDataStore executionData,
+ final ICoverageVisitor coverageVisitor) {
+ this.executionData = executionData;
+ this.coverageVisitor = coverageVisitor;
+ this.stringPool = new StringPool();
+ }
+
+ /**
+ * Creates an ASM class visitor for analysis.
+ *
+ * @param classid
+ * id of the class calculated with {@link CRC64}
+ * @return ASM visitor to write class definition to
+ */
+ private ClassVisitor createAnalyzingVisitor(final long classid) {
+ final ExecutionData data = executionData.get(classid);
+ final boolean[] classExec = data == null ? null : data.getData();
+ final ClassAnalyzer analyzer = new ClassAnalyzer(classid, classExec,
+ stringPool) {
+ @Override
+ public void visitEnd() {
+ super.visitEnd();
+ coverageVisitor.visitCoverage(getCoverage());
+ }
+ };
+ return new ClassProbesAdapter(analyzer);
+ }
+
+ /**
+ * Analyzes the class given as a ASM reader.
+ *
+ * @param reader
+ * reader with class definitions
+ */
+ public void analyzeClass(final ClassReader reader) {
+ final ClassVisitor visitor = createAnalyzingVisitor(CRC64
+ .checksum(reader.b));
+ reader.accept(visitor, 0);
+ }
+
+ /**
+ * Analyzes the class definition from a given in-memory buffer.
+ *
+ * @param buffer
+ * class definitions
+ */
+ public void analyzeClass(final byte[] buffer) {
+ analyzeClass(new ClassReader(buffer));
+ }
+
+ /**
+ * Analyzes the class definition from a given input stream.
+ *
+ * @param input
+ * stream to read class definition from
+ * @throws IOException
+ */
+ public void analyzeClass(final InputStream input) throws IOException {
+ analyzeClass(new ClassReader(input));
+ }
+
+ /**
+ * Analyzes all classes contained in the ZIP archive (jar, war, ear, etc.)
+ * given as an input stream. Contained archives are read recursively.
+ *
+ * @param input
+ * ZIP archive data
+ * @return number of class files found
+ * @throws IOException
+ */
+ public int analyzeArchive(final InputStream input) throws IOException {
+ final ZipInputStream zip = new ZipInputStream(input);
+ int count = 0;
+ while (true) {
+ final ZipEntry entry = zip.getNextEntry();
+ if (entry == null) {
+ break;
+ }
+ count += analyzeAll(zip);
+ }
+ return count;
+ }
+
+ /**
+ * Analyzes all classes found in the given input stream. The input stream
+ * may either represent a single class file or a ZIP archive that is
+ * searched recursively for class files. All other content types are
+ * ignored.
+ *
+ * @param input
+ * input data
+ * @return number of class files found
+ * @throws IOException
+ */
+ public int analyzeAll(final InputStream input) throws IOException {
+ final ContentTypeDetector detector = new ContentTypeDetector(input);
+ switch (detector.getType()) {
+ case ContentTypeDetector.CLASSFILE:
+ analyzeClass(detector.getInputStream());
+ return 1;
+ case ContentTypeDetector.ZIPFILE:
+ return analyzeArchive(detector.getInputStream());
+ default:
+ return 0;
+ }
+ }
+
+ /**
+ * Analyzes all class files contained in the given file or folder. Class
+ * files as well as ZIP files are considered. Folders are searched
+ * recursively.
+ *
+ * @param file
+ * file or folder to look for class files
+ * @return number of class files found
+ * @throws IOException
+ */
+ public int analyzeAll(final File file) throws IOException {
+ int count = 0;
+ if (file.isDirectory()) {
+ for (final File f : file.listFiles()) {
+ count += analyzeAll(f);
+ }
+ } else {
+ final InputStream in = new FileInputStream(file);
+ try {
+ count += analyzeAll(in);
+ } finally {
+ in.close();
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Analyzes all classes from the given class path. Directories containing
+ * class files as well as archive files are considered.
+ *
+ * @param path
+ * path definition
+ * @param basedir
+ * optional base directory, if <code>null</code> the current
+ * working directory is used as the base for relative path
+ * entries
+ * @return number of class files found
+ * @throws IOException
+ */
+ public int analyzeAll(final String path, final File basedir)
+ throws IOException {
+ int count = 0;
+ final StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
+ while (st.hasMoreTokens()) {
+ count += analyzeAll(new File(basedir, st.nextToken()));
+ }
+ return count;
+ }
+
+}