Skip to content

Commit

Permalink
release of version 0.1.18
Browse files Browse the repository at this point in the history
~ fixed a regression not properly using auto-implicit schemata
+ added renderExtension option to disable dependence on validateAll task if there is nothing to be validated!
  • Loading branch information
ramonwirsch committed Jul 24, 2018
1 parent eeafc5f commit 73a9a41
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ fopRenderer {
schemaGroupName { // used for task names
files = file('some.xml') // or fileTree(dir: 'xmlDir', include: '*.xml')
schemaUri = 'http://www.url.com/to/some/schema.xsd'
offlineSchema = file('offlineSchema.xsd')
offlineSchema = file('offlineSchema.xsd') // [optional]
useInherentSchemas = false // [default: false] uses xsi:schemaLocation tags or Doctype statements in the XML files for validation instead of forced schema
}
// ... as many different groups as you like
}
Expand All @@ -50,12 +51,9 @@ fopRenderer {
resources = file('resources/dir') // pictures and other resources. Links will be interpreted relative to this
resourceCollectionParams = [exclude: '**/*.xml'] // default: params for resource fileTree.
// resources + resourceCollectionParams will be combined into a FileCollection that is monitored for changes by the renderTask
requiresValidation = true // [default: true] whether to require passing of schema validation before attempting to transform/render
}
}
/*schemas.all { // uncomment to use xsi:schemaLocation tags in in XML files for validation instead of forced schema
useInherentSchemas=true
}*/
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildScan {
}

group = "com.github.ramonwirsch"
version = "0.1.17"
version = "0.1.18"

repositories {
jcenter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ open class FopRendererPlugin : Plugin<Project> {

val currentTransformTask = tasks.create("transform" + renderConfig.name.capitalize(), XSLTTransformTask::class.java) {
this.renderConfig = renderConfig
dependsOn(validateAllTask)

if (renderConfig.isRequiresValidation) {
dependsOn(validateAllTask)
}
}

val currentRenderTask = tasks.create("render" + renderConfig.name.capitalize(), FopRenderTask::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ class RenderConfigExtension(val name: String) {
* Additional params fed to gradles [org.gradle.api.Project.fileTree] method
*/
var resourceCollectionParams: Map<String, Any> = mapOf("exclude" to "**/*.xml")

/**
* whether all validations must have passed before trying to render
*/
var isRequiresValidation: Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class XMLValidatorFactory

init {
val schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
schema = schemaFactory.newSchema(schemaUri)
schema = if (schemaUri == null) schemaFactory.newSchema() else schemaFactory.newSchema(schemaUri)
saxParserFactory = SAXParserFactory.newInstance()
saxParserFactory.isNamespaceAware = true
saxParserFactory.isValidating = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ open class XMLValidatorTask
internal fun execute(inputs: IncrementalTaskInputs) {
val validationSchema = if (!FopRendererPlugin.isOffline(project) && schemaConfig.isUseInherentSchemas) {
logger.info("Using inherent schemas")
null
SchemaConfigExtension.FALLBACK_URL
} else {
val schemaUri = schemaUri
logger.info("Using schema {}", schemaUri)
Expand Down Expand Up @@ -125,13 +125,15 @@ open class XMLValidatorTask
}
}

private class ValidationWorker
open private class ValidationWorker
@Inject constructor(
validationSchema: URL?,
val input: File
) : Runnable {

private val validator = XMLValidatorFactory.forSchema(validationSchema).createValidator()
private val actualValSchema = if (validationSchema == SchemaConfigExtension.FALLBACK_URL) null else validationSchema

private val validator = XMLValidatorFactory.forSchema(actualValSchema).createValidator()

override fun run() {
validator.validateOrThrow(input)
Expand Down

0 comments on commit 73a9a41

Please sign in to comment.