Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow doctype declaration for JaCoCo #18

Merged
merged 2 commits into from
Jul 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/main/groovy/org/kt3k/gradle/plugin/CoverallsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.kt3k.gradle.plugin.coveralls.CoverallsTask
import org.kt3k.gradle.plugin.coveralls.domain.CoberturaSourceReportFactory
import org.kt3k.gradle.plugin.coveralls.domain.JacocoSourceReportFactory
import org.kt3k.gradle.plugin.coveralls.domain.SourceReportFactory

/**
* Coveralls plugin for gradle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ class CoberturaSourceReportFactory implements SourceReportFactory {
@Override
List<SourceReport> createReportList(Project project, File file) {
// create parser
XmlParser parser = new XmlParser()

// skip external DTD validation
// see http://xerces.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)

// allow DOCTYPE declaration
// see http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl
// this is the same as the default, but in some situation it seems to turn to be true ( see https://github.com/kt3k/coveralls-gradle-plugin/pull/16 )
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)
XmlParser parser = new XmlParserFactory().xmlParser

// parse
Node coverage = parser.parse(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ class JacocoSourceReportFactory implements SourceReportFactory {

static List<SourceReport> createReportList(List<File> srcDirs, File jacocoReportFile) {
// create parser
XmlParser parser = new XmlParser()

// skip external DTD validation
// see http://xerces.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
XmlParser parser = new XmlParserFactory().xmlParser

// parse
Node report = parser.parse(jacocoReportFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.kt3k.gradle.plugin.coveralls.domain

class XmlParserFactory {

def getXmlParser() {
// create parser
XmlParser parser = new XmlParser()

// skip external DTD validation
// see http://xerces.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)

// allow DOCTYPE declaration
// see http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl
// this is the same as the default, but in some situation it seems to turn to be true ( see https://github.com/kt3k/coveralls-gradle-plugin/pull/16 )
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false)

return parser
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.gradle.testfixtures.ProjectBuilder

import org.kt3k.gradle.plugin.CoverallsPluginExtension
import org.kt3k.gradle.plugin.coveralls.domain.CoberturaSourceReportFactory
import org.kt3k.gradle.plugin.coveralls.domain.SourceReportFactory

import org.mockito.Mockito

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.kt3k.gradle.plugin.coveralls.domain

import org.junit.Test

import static org.junit.Assert.assertFalse

class XmlParserFactoryTest {

@Test
void testXmlParserConfiguration() {
def parser = new XmlParserFactory().xmlParser

assertFalse parser.getFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd")
assertFalse parser.getFeature("http://apache.org/xml/features/disallow-doctype-decl")
}
}