Skip to content

Commit

Permalink
Make it possible to append optional source directories from plugin ex…
Browse files Browse the repository at this point in the history
…tension
  • Loading branch information
kt3k committed Jun 22, 2014
1 parent 2bb9508 commit 9253a4e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ class CoverallsPluginExtension {
/** Cobertura report path */
String coberturaReportPath = 'build/reports/cobertura/coverage.xml'

/**
* Additional source directories
*/
List<String> sourceDirs = []

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ class CoberturaSourceReportFactory implements SourceReportFactory {
// parse
Node coverage = parser.parse(file)


// default source directories
List<String> sourceDirectories = coverage.sources.source*.text()

// append optional directories
sourceDirectories += project.extensions.coveralls.sourceDirs

// mapping of [filename] => [hits per line]
Map<String, Map<Integer, Integer>> hitsPerLineMapForFilename = [:]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JacocoSourceReportFactory implements SourceReportFactory {
targetSrcDirs += project.sourceSets.main.scala.srcDirs
}

return targetSrcDirs.sort()
return project.extensions.coveralls.sourceDirs + targetSrcDirs.sort()
}

static List<SourceReport> createReportList(List<File> srcDirs, File jacocoReportFile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package org.kt3k.gradle.plugin.coveralls.domain

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Before
import org.junit.Test
import static org.junit.Assert.*
import static org.mockito.Mockito.mock
import org.kt3k.gradle.plugin.CoverallsPluginExtension

class CoberturaSourceReportFactoryTest {

Project project

@Before
public void setUp() {

// fake a project
project = ProjectBuilder.builder().build()

// create coveralls extension
project.extensions.create('coveralls', CoverallsPluginExtension)
}

@Test
void testCreateFromCoberturaXML() {

Project project = mock Project
CoberturaSourceReportFactory factory = new CoberturaSourceReportFactory()
List<SourceReport> reports = factory.createReportList project, new File('src/test/fixture/coverage.xml')

Expand All @@ -30,7 +43,6 @@ class CoberturaSourceReportFactoryTest {
@Test
void testCreateFromCoberturaWithMultipleSourcesIncludingWrongOneXML() {

Project project = mock Project
CoberturaSourceReportFactory factory = new CoberturaSourceReportFactory()
List<SourceReport> reports = factory.createReportList project, new File('src/test/fixture/coverage_with_multiple_sources_including_wrong_ones.xml')

Expand All @@ -50,9 +62,6 @@ class CoberturaSourceReportFactoryTest {
@Test
void testCreateFromCoberturaWithNonexistentFileEntry() {

// mock up project
Project project = mock Project

CoberturaSourceReportFactory factory = new CoberturaSourceReportFactory()

// create source report
Expand All @@ -68,7 +77,6 @@ class CoberturaSourceReportFactoryTest {
// test line hits addition
// see <line> tags in src/test/fixture/coverage_add_hits.xml

Project project = mock Project
CoberturaSourceReportFactory factory = new CoberturaSourceReportFactory()
List<SourceReport> reports = factory.createReportList project, new File('src/test/fixture/coverage_add_hits.xml')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.scala.ScalaPlugin
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
import org.junit.Before
import org.kt3k.gradle.plugin.CoverallsPluginExtension

import static org.junit.Assert.*

class JacocoSourceReportFactoryTest {

Project project

@Before
public void setUp() {

// fake a project
project = ProjectBuilder.builder().build()

// create coveralls extension
project.extensions.create('coveralls', CoverallsPluginExtension)
}

@Test
public void testCreateReport() throws Exception {
List<SourceReport> reports = JacocoSourceReportFactory.createReportList([new File('src/main/groovy')], new File('src/test/fixture/jacocoTestReport.xml'))
Expand All @@ -31,7 +45,6 @@ class JacocoSourceReportFactoryTest {

@Test
public void testCreateReportList() throws Exception {
Project project = ProjectBuilder.builder().build()
project.plugins.apply(GroovyPlugin)

List<SourceReport> reports = new JacocoSourceReportFactory().createReportList(project, new File('src/test/fixture/jacocoTestReport.xml'))
Expand All @@ -42,7 +55,7 @@ class JacocoSourceReportFactoryTest {

@Test
public void testCreateReportForJavaPlugin() throws Exception {
Project project = ProjectBuilder.builder().build()

project.plugins.apply(JavaPlugin)

List<File> srcDirs = JacocoSourceReportFactory.createTargetSrcDirs(project)
Expand All @@ -55,7 +68,7 @@ class JacocoSourceReportFactoryTest {

@Test
public void testCreateReportForGroovyPlugin() throws Exception {
Project project = ProjectBuilder.builder().build()

project.plugins.apply(GroovyPlugin)

List<File> srcDirs = JacocoSourceReportFactory.createTargetSrcDirs(project)
Expand All @@ -68,7 +81,7 @@ class JacocoSourceReportFactoryTest {

@Test
public void testCreateReportForScalaPlugin() throws Exception {
Project project = ProjectBuilder.builder().build()

project.plugins.apply(ScalaPlugin)

List<File> srcDirs = JacocoSourceReportFactory.createTargetSrcDirs(project)
Expand Down

0 comments on commit 9253a4e

Please sign in to comment.