diff --git a/build.gradle b/build.gradle index cb181510578..ee8b5135ac3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ import groovy.json.JsonSlurper import org.gradle.internal.os.OperatingSystem +import org.jabref.build.xjc.XjcTask import static org.jabref.build.Dependencies.libraries @@ -41,10 +42,10 @@ apply plugin: 'install4j' apply plugin: 'me.champeau.gradle.jmh' apply plugin: 'checkstyle' apply plugin: org.jabref.build.antlr.AntlrPlugin +apply plugin: org.jabref.build.xjc.XjcPlugin apply from: 'eclipse.gradle' apply from: 'localization.gradle' -apply from: 'xjc.gradle' group = "org.jabref" version = "5.0-dev" @@ -144,6 +145,7 @@ dependencies { testCompile libraries.testFx checkstyle libraries.checkstyle + xjc libraries.xjc } jacoco { @@ -221,7 +223,12 @@ processResources { } -task generateSource(dependsOn: ["generateBstGrammarSource", "generateSearchGrammarSource"]) { +task generateSource(dependsOn: ["generateBstGrammarSource", + "generateSearchGrammarSource", + "generateMedlineSource", + "generateBibtexmlSource", + "generateEndnoteSource", + "generateModsSource"]) { group = 'JabRef' description 'Generates all Java source files.' } @@ -245,14 +252,52 @@ task generateSearchGrammarSource(type: org.jabref.build.antlr.AntlrTask) { javaPackage = "org.jabref.search" } -compileJava { - options.encoding = 'UTF-8' - options.compilerArgs << "-Xlint:none" +task generateMedlineSource(type: XjcTask) { + group = 'JabRef' + description = "Generates java files for the medline importer." + + schemaFile = "src/main/resources/xjc/medline/medline.xsd" + outputDirectory = "src/main/gen/" + javaPackage = "org.jabref.logic.importer.fileformat.medline" +} + +task generateBibtexmlSource(type: XjcTask) { + group = 'JabRef' + description = "Generates java files for the bibtexml importer." + + schemaFile = "src/main/resources/xjc/bibtexml/bibtexml.xsd" + outputDirectory = "src/main/gen" + javaPackage = "org.jabref.logic.importer.fileformat.bibtexml" +} + +task generateEndnoteSource(type: XjcTask) { + group = 'JabRef' + description = "Generates java files for the endnote importer." + + schemaFile = "src/main/resources/xjc/endnote/RSXML.dtd" + outputDirectory = "src/main/gen/" + javaPackage = "org.jabref.logic.importer.fileformat.endnote" + arguments = '-dtd' +} + +task generateModsSource(type: XjcTask) { + group = 'JabRef' + description = "Generates java files for the mods importer." + + schemaFile = "src/main/resources/xjc/mods/mods-3-7.xsd" + bindingFile = "src/main/resources/xjc/mods/mods-binding.xjb" + outputDirectory = "src/main/gen/" + javaPackage = "org.jabref.logic.importer.fileformat.mods" + arguments = '-npa' +} + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' // use UTF-8 for regular and test compilation } -compileJava.dependsOn "generateSource" -compileTestJava { - options.encoding = 'UTF-8' +compileJava { + options.compilerArgs << "-Xlint:none" + dependsOn "generateSource" } javadoc { diff --git a/buildSrc/src/main/groovy/org/jabref/build/Dependencies.groovy b/buildSrc/src/main/groovy/org/jabref/build/Dependencies.groovy index bf7f416d2f4..e77dba70d28 100644 --- a/buildSrc/src/main/groovy/org/jabref/build/Dependencies.groovy +++ b/buildSrc/src/main/groovy/org/jabref/build/Dependencies.groovy @@ -61,7 +61,8 @@ class Dependencies { archUnit: "0.8.2", testFx: "4.0.+", - checkstyle: "8.10.1" + checkstyle: "8.10.1", + xjc: "2.2.4-1", ] static def libraries = [ @@ -171,6 +172,7 @@ class Dependencies { ], checkstyle: "com.puppycrawl.tools:checkstyle:${versions.checkstyle}", + xjc: "com.sun.xml.bind:jaxb-xjc:${versions.xjc}", ] } diff --git a/buildSrc/src/main/groovy/org/jabref/build/xjc/XjcPlugin.groovy b/buildSrc/src/main/groovy/org/jabref/build/xjc/XjcPlugin.groovy new file mode 100644 index 00000000000..72e2c3644a7 --- /dev/null +++ b/buildSrc/src/main/groovy/org/jabref/build/xjc/XjcPlugin.groovy @@ -0,0 +1,20 @@ +package org.jabref.build.xjc + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class XjcPlugin implements Plugin { + + static final def CONFIGURATION_NAME = "xjc" + + @Override + void apply(Project target) { + def configuration = target.configurations.create(CONFIGURATION_NAME) + configuration.description = "Dependencies needed to run the XJC tool." + + target.afterEvaluate { evaluated -> + evaluated.logger.info(evaluated.configurations.xjc.asPath) + evaluated.ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: evaluated.configurations.getByName(CONFIGURATION_NAME).asPath) + } + } +} diff --git a/buildSrc/src/main/groovy/org/jabref/build/xjc/XjcTask.groovy b/buildSrc/src/main/groovy/org/jabref/build/xjc/XjcTask.groovy new file mode 100644 index 00000000000..bb859ea10c1 --- /dev/null +++ b/buildSrc/src/main/groovy/org/jabref/build/xjc/XjcTask.groovy @@ -0,0 +1,93 @@ +package org.jabref.build.xjc + +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.TaskAction + +class XjcTask extends DefaultTask { + + private def schemaFile + @Optional + private def bindingFile + private def outputDirectory + private String javaPackage + @Optional + private String arguments + + @TaskAction + def generateClasses() { + project.mkdir(outputDirectory) + project.ant.xjc(destdir: outputDirectory, package: javaPackage) { + schema(dir: schemaFile.getParent(), includes: schemaFile.getName()) + if (bindingFile != null) { + binding(dir: bindingFile.getParent(), includes: bindingFile.getName()) + } + if (arguments != null) { + arg(value: arguments) + } + } + } + + @Input + File getSchemaFile() { + if (schemaFile == null) { + return null + } + return project.file(schemaFile) + } + + void setSchemaFile(Object schemaFile) { + this.schemaFile = schemaFile + } + + File getOutputDirectory() { + if (outputDirectory == null) { + return null + } + return project.file(outputDirectory) + } + + void setOutputDirectory(Object outputDirectory) { + this.outputDirectory = outputDirectory + updateOutput() + } + + String getJavaPackage() { + return javaPackage + } + + void setJavaPackage(String javaPackage) { + this.javaPackage = javaPackage + updateOutput() + } + + String getArguments() { + return arguments + } + + void setArguments(String args) { + this.arguments = args + } + + @Input + File getBindingFile() { + if (bindingFile == null) { + return null + } + return project.file(bindingFile) + } + + void setBindingFile(Object binding) { + this.bindingFile = binding + } + + private void updateOutput() { + if (outputDirectory != null && javaPackage != null) + outputs.dir(new File(getOutputDirectory(), packageAsPath(javaPackage))) + } + + private static String packageAsPath(String pkg) { + return pkg.replace((char) '.', File.separatorChar) + } +} diff --git a/xjc.gradle b/xjc.gradle deleted file mode 100644 index ea33b543a03..00000000000 --- a/xjc.gradle +++ /dev/null @@ -1,41 +0,0 @@ -configurations { - xjc -} - -dependencies { - // Cannot be updated. - xjc 'com.sun.xml.bind:jaxb-xjc:2.2.4-1' -} - -task xjc { - inputs.dir "src/main/resources/xjc/medline/" - inputs.dir "src/main/resources/xjc/bibtexml/" - inputs.dir "src/main/resources/xjc/endnote/" - inputs.dir "src/main/resources/xjc/mods/" - outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/medline" - outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/bibtexml" - outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/endnote" - outputs.dir "src/main/gen/org/jabref/logic/importer/fileformat/mods" - - ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.xjc.asPath) - - doLast { - ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.medline') { - schema(dir: 'src/main/resources/xjc/medline', includes: 'medline.xsd') - } - ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.bibtexml') { - schema(dir: 'src/main/resources/xjc/bibtexml', includes: 'bibtexml.xsd') - } - ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.endnote') { - arg(value: '-dtd') - schema(dir: 'src/main/resources/xjc/endnote', includes: 'RSXML.dtd') - } - ant.xjc(destdir: 'src/main/gen/', package: 'org.jabref.logic.importer.fileformat.mods') { - arg(value: '-npa') //don't create package-info.java because it was manually added in src/main/java to ensure the namespace prefix mapping - schema(dir: 'src/main/resources/xjc/mods', includes: 'mods-3-7.xsd') - binding(dir: 'src/main/resources/xjc/mods', includes: 'mods-binding.xjb') - } - } -} - -tasks.compileJava.dependsOn xjc