This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NetBeans Module projects support, patch provided by Graeme Ingleby. Thx!
- Loading branch information
1 parent
fed3951
commit 88acaf9
Showing
11 changed files
with
591 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
## JaCoCoverage Documentation | ||
|
||
### What Is JaCoCoverage | ||
The JaCoCoverage Plugin is a Netbeans plugin that enhances the existing NetBeans functionality with new code coverage features. In other words, you can launch your program or test it and JaCoCoverage will provide you coverage information by highlighting your source code files and providing various types of reports (currently, textual and HTML). This way, you can easily know what piece of code has been executed or not. | ||
|
||
### How It Works | ||
The JaCoCoverage Plugin is based on JaCoCo: a library created by the [EclEmma team](http://www.eclemma.org/jacoco/). This library is able to generate coverage data when you launch a Java program. | ||
More precsisely, JaCoCoverage uses the JaCoCo Java Agent to enable coverage collections (i.e. a JaCoCo Java Agent is attached to your program). | ||
When your program terminates, JaCoCo generates coverage data and JaCoCoverage assures the coverage information integration in your NetBeans IDE. | ||
JaCoCo and JaCoCoverage support Java 7 and are also tested with Java 6. It may work with Java 5 too. The EclEmma team is currently working on Java 8 support. | ||
|
||
### Media | ||
NetBeans Java editor showing highlighted code. You can see covered, partially covered and not covered code, and annotations in the left margin: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_editor.png) | ||
|
||
A context menu is enabled for supported projects. It allows you to run and test your programs with JaCoCoverage: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_menu.png) | ||
|
||
JaCoCoverage is configurable: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_options.png) | ||
|
||
A short textual coverage report: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_consolereport.png) | ||
|
||
A complete HTML coverage report: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_htmlreport.png) | ||
|
||
### Author | ||
* Jonathan Lermitage (<jonathan.lermitage@gmail.com>) | ||
|
||
### License | ||
[WTFPL](http://www.wtfpl.net) License. In other words, you can do what you want: this project is entirely OpenSource, Free and Gratis. | ||
## JaCoCoverage Documentation | ||
|
||
### What Is JaCoCoverage | ||
The JaCoCoverage Plugin is a Netbeans plugin that enhances the existing NetBeans functionality with new code coverage features. In other words, you can launch your program or test it and JaCoCoverage will provide you coverage information by highlighting your source code files and providing various types of reports (currently, textual and HTML). This way, you can easily know what piece of code has been executed or not. | ||
|
||
### How It Works | ||
The JaCoCoverage Plugin is based on JaCoCo: a library created by the [EclEmma team](http://www.eclemma.org/jacoco/). This library is able to generate coverage data when you launch a Java program. | ||
More precsisely, JaCoCoverage uses the JaCoCo Java Agent to enable coverage collections (i.e. a JaCoCo Java Agent is attached to your program). | ||
When your program terminates, JaCoCo generates coverage data and JaCoCoverage assures the coverage information integration in your NetBeans IDE. | ||
JaCoCo and JaCoCoverage support Java 7 and 8 and are also tested with Java 6. It may work with Java 5 too. | ||
|
||
### Media | ||
NetBeans Java editor showing highlighted code. You can see covered, partially covered and not covered code, and annotations in the left margin: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_editor.png) | ||
|
||
A context menu is enabled for supported projects. It allows you to run and test your programs with JaCoCoverage: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_menu.png) | ||
|
||
JaCoCoverage is configurable: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_options.png) | ||
|
||
A short textual coverage report: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_consolereport.png) | ||
|
||
A complete HTML coverage report: | ||
|
||
![Screenshot](http://netbeanscolors.org/files/jacococoverage_htmlreport.png) | ||
|
||
### Author | ||
* Jonathan Lermitage (<jonathan.lermitage@gmail.com>) | ||
|
||
### License | ||
[WTFPL](http://www.wtfpl.net) License. In other words, you can do what you want: this project is entirely OpenSource, Free and Gratis. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Manifest-Version: 1.0 | ||
AutoUpdate-Show-In-Client: false | ||
OpenIDE-Module: fr.tikione.jacocoexec.analyzer/1 | ||
OpenIDE-Module-Localizing-Bundle: fr/tikione/jacocoexec/analyzer/Bundle.properties | ||
OpenIDE-Module-Specification-Version: 1.3.3.20130929.1404 | ||
Manifest-Version: 1.0 | ||
AutoUpdate-Show-In-Client: false | ||
OpenIDE-Module: fr.tikione.jacocoexec.analyzer/1 | ||
OpenIDE-Module-Localizing-Bundle: fr/tikione/jacocoexec/analyzer/Bundle.properties | ||
OpenIDE-Module-Specification-Version: 1.5.0.20150116.2200 | ||
|
69 changes: 69 additions & 0 deletions
69
...jacocoexec-analyzer/src/fr/tikione/jacocoexec/analyzer/JacocoNBModuleReportGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package fr.tikione.jacocoexec.analyzer; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import org.jacoco.core.analysis.Analyzer; | ||
import org.jacoco.core.analysis.CoverageBuilder; | ||
import org.jacoco.core.analysis.IBundleCoverage; | ||
import org.jacoco.core.tools.ExecFileLoader; | ||
import org.jacoco.report.DirectorySourceFileLocator; | ||
import org.jacoco.report.FileMultiReportOutput; | ||
import org.jacoco.report.IReportGroupVisitor; | ||
import org.jacoco.report.IReportVisitor; | ||
import org.jacoco.report.MultiSourceFileLocator; | ||
import org.jacoco.report.html.HTMLFormatter; | ||
import org.jacoco.report.xml.XMLFormatter; | ||
|
||
/** | ||
* @author Graeme Ingleby | ||
*/ | ||
public class JacocoNBModuleReportGenerator { | ||
|
||
private static final String DEF_ENCODING = "UTF-8"; | ||
|
||
private final IReportVisitor visitor; | ||
private final IReportGroupVisitor groupVisitor; | ||
private final File executionDataFile; | ||
private final ExecFileLoader execFileLoader; | ||
|
||
public JacocoNBModuleReportGenerator(File executationDataFile, File reportdir, boolean xmlReport) throws IOException { | ||
this.executionDataFile = executationDataFile; | ||
execFileLoader = new ExecFileLoader(); | ||
execFileLoader.load(executionDataFile); | ||
|
||
if (xmlReport) { | ||
XMLFormatter xmlformatter = new XMLFormatter(); | ||
xmlformatter.setOutputEncoding(DEF_ENCODING); | ||
visitor = xmlformatter.createVisitor(new FileOutputStream(reportdir)); | ||
} else { | ||
HTMLFormatter htmlFormater = new HTMLFormatter(); | ||
visitor = htmlFormater.createVisitor(new FileMultiReportOutput(reportdir)); | ||
} | ||
visitor.visitInfo(execFileLoader.getSessionInfoStore().getInfos(), execFileLoader.getExecutionDataStore().getContents()); | ||
groupVisitor = visitor.visitGroup("JaCoCo Coverage Report"); | ||
} | ||
|
||
public void processNBModule(String projectName, List<String> classDirectories, List<String> sourceDirectories) throws IOException { | ||
CoverageBuilder coverageBuilder = new CoverageBuilder(); | ||
Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder); | ||
|
||
for (String classDirectory : classDirectories) { | ||
analyzer.analyzeAll(new File(classDirectory)); | ||
} | ||
|
||
IBundleCoverage bundleCoverage = coverageBuilder.getBundle(projectName); | ||
|
||
MultiSourceFileLocator sourceLocator = new MultiSourceFileLocator(4); | ||
for (String sourceDirectory : sourceDirectories) { | ||
sourceLocator.add(new DirectorySourceFileLocator(new File(sourceDirectory), DEF_ENCODING, 4)); | ||
} | ||
|
||
groupVisitor.visitBundle(bundleCoverage, sourceLocator); | ||
} | ||
|
||
public void end() throws IOException { | ||
visitor.visitEnd(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tikione-jacocoverage-plugin/src/fr/tikione/jacocoverage/plugin/action/NBJaCoCoExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package fr.tikione.jacocoverage.plugin.action; | ||
|
||
import fr.tikione.jacocoexec.analyzer.JacocoNBModuleReportGenerator; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.netbeans.api.project.Project; | ||
import org.netbeans.api.project.ProjectUtils; | ||
import org.netbeans.api.project.SourceGroup; | ||
import org.netbeans.api.project.Sources; | ||
import org.netbeans.spi.project.SubprojectProvider; | ||
import org.openide.util.Exceptions; | ||
|
||
/** | ||
* @author Graeme Ingleby | ||
*/ | ||
public class NBJaCoCoExtension { | ||
|
||
private JacocoNBModuleReportGenerator reportGenerator; | ||
|
||
public static String toHTMLReport(File binreport, File reportdir, Project project) { | ||
return (new NBJaCoCoExtension()).myReportGeneration(binreport, reportdir, project); | ||
} | ||
|
||
public static void toXmlReport(File binreport, File reportfile, Project project) { | ||
(new NBJaCoCoExtension()).myXmlReportGeneration(binreport, reportfile, project); | ||
} | ||
|
||
/** | ||
* XML Generation. | ||
* | ||
* @param jacocoExecFile | ||
* @param reportdir | ||
* @param project | ||
*/ | ||
public void myXmlReportGeneration(File jacocoExecFile, File reportdir, Project project) { | ||
try { | ||
reportGenerator = new JacocoNBModuleReportGenerator(jacocoExecFile, reportdir, true); | ||
processProject(project); | ||
reportGenerator.end(); | ||
} catch (IOException ex) { | ||
Exceptions.printStackTrace(ex); | ||
} | ||
} | ||
|
||
/** | ||
* HTML Generation. | ||
* | ||
* @param jacocoExecFile | ||
* @param reportdir | ||
* @param project | ||
* @return | ||
*/ | ||
public String myReportGeneration(File jacocoExecFile, File reportdir, Project project) { | ||
try { | ||
reportGenerator = new JacocoNBModuleReportGenerator(jacocoExecFile, reportdir, false); | ||
processProject(project); | ||
reportGenerator.end(); | ||
} catch (IOException ex) { | ||
Exceptions.printStackTrace(ex); | ||
} | ||
return new File(reportdir, "index.html").getAbsolutePath(); | ||
} | ||
|
||
public void processProject(Project project) throws FileNotFoundException, IOException { | ||
List<String> moduleClassDirectories = new ArrayList<>(8); | ||
List<String> moduleSourceDirectories = new ArrayList<>(8); | ||
|
||
String prjDir = project.getProjectDirectory().getPath(); | ||
|
||
File classDir = new File(prjDir + "/build/classes"); | ||
if (classDir.exists()) { | ||
moduleClassDirectories.add(classDir.getPath()); | ||
} | ||
|
||
Sources source = ProjectUtils.getSources(project); | ||
SourceGroup[] groups = source.getSourceGroups("java"); | ||
for (SourceGroup group : groups) { | ||
moduleSourceDirectories.add(group.getRootFolder().getPath()); | ||
} | ||
File genDir = new File(prjDir + "/build/classes-generated"); | ||
if (genDir.exists()) { | ||
moduleSourceDirectories.add(genDir.getPath()); | ||
} | ||
|
||
reportGenerator.processNBModule(project.getProjectDirectory().getName(), moduleClassDirectories, moduleSourceDirectories); | ||
processSubprojects(project); | ||
} | ||
|
||
public void processSubprojects(Project project) throws IOException { | ||
SubprojectProvider subs = project.getLookup().lookup(SubprojectProvider.class); | ||
if (subs != null) { | ||
Set<? extends Project> subProjects = subs.getSubprojects(); | ||
for (Project p : subProjects) { | ||
processProject(p); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.