Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************
- * Usage:
- * apply from:'LatexPlugin.gradle'
- *
- * // name of main LaTeX file
- * docuTexMainFile 'release_notes_and_restrictions'
- *
- * // set the generated variants of the documentation
- * variant '73' : 'RELEASE_NOTES_AND_RESTRICTIONS_NW73',
- * '70' : 'RELEASE_NOTES_AND_RESTRICTIONS_NW70'
- ****************************************************/
- // Provide repository for 'splitindex'
- repositories{
- ivy{ name = 'company_ivy'; url = "$companyFileShare/ivy-repo" }
- //mavenCentral()
- }
- // splitindex.jar was added as jar in company ivy repo
- configurations { splitindex }
- dependencies {
- splitindex group: 'splitindex', name: 'splitindex', version: '0.1'
- }
- guessLanguage()
- task preprocess {
- description = 'Generates temporary LaTeX files to be used by makeIndex'
- }
- task makeIndex {
- description = 'Creates temporary index lists'
- }
- task compile {
- description = 'Creates actual PDF'
- }
- task rename {
- description = 'Move PDF with technical name to output directory and applies nice name'
- }
- task deleteTemporaryLatexFiles(type:Delete) {
- description = 'Deletes temporary files generated by LaTeX build process'
- def inclds = {
- include '*.log'
- include '*.lof'
- include '*.gz'
- include '*.orig'
- include '*.bak'
- include '*.loa'
- include '*.lol'
- include '*.log'
- include '*.lot'
- include '*.bbl'
- include '*.blg'
- include '*.dvi'
- include '*.out'
- include '*.brf'
- include '*.thm'
- include '*.toc'
- include '*.idx'
- include '*.ilg'
- include '*.ind'
- // In some projects the .aux files are committed for cross references between documents
- exclude '*.aux'
- }
- delete fileTree('.', inclds)
- delete fileTree('tmp', inclds)
- }
- task (convert2utf8) {
- description = 'Converts *.tex files from ASCII to UTF-8 with BOM'
- inputs.file fileTree(dir: '.', includes: ['**/*.tex'])
- doLast {
- inputs.files.each{
- logger.quiet "Converting to UTF-8 with BOM: $it"
- def content = it.text
- it.setText '\ufeff' + content, 'UTF-8'
- }
- }
- }
- try {
- tasks.build.dependsOn compile, rename
- } catch(Exception e) {
- task build(dependsOn:[compile, rename])
- }
- defaultTasks 'rename'
- ext.language = this.&setLanguage
- ext.variant = this.&setVariants
- ext.destDir = file("$buildDir/docs")
- /*
- * in future releases the name of the main tex file may not be set in the build-gradle
- * but dynamically be calculated. Therefore the main tex file should be located in the
- * language specific folder of the documentation and should have a more dynamic name like "documentation.tex"
- */
- ext.docuTexMainFile = this.&setDocuTexMainFile
- /*
- * First shot: Try some default names. If one is found, use that one as entry (main) latex file
- */
- ['documentation', 'document', 'main'].find {
- def fileName = it + '.tex'
- if(file(fileName).exists()) {
- setDocuTexMainFile it // Don't pass the .tex suffix
- return true // break the 'find' loop
- }
- }
- def setLanguage(String lang) {
- ext.language = new Locale(lang)
- //logger.quiet "Setting language to $language.displayLanguage"
- }
- def guessLanguage() {
- def matches = projectDir.name =~ /_(\w\w)_?$/
- if (matches) {
- logger.quiet "$project.name's language seems to be ${matches[0][1]}"
- setLanguage(matches[0][1])
- }
- }
- def setDocuTexMainFile(String baseTexName){
- ext.docuTexMainFile = baseTexName
- logger.info "Setting docuTexMainFile to $baseTexName"
- }
- def setVariants(Map m) {
- def score1 = projectDir.name.endsWith('_') ? '' : '_'
- m.each{ key, value ->
- def jobname1 = "$projectDir.name$score1$key" + (key.endsWith('_') ? '' : '_')
- def taskSuffix = key.capitalize()
- if (!value) value = jobname1
- task ("preprocess$taskSuffix") {
- description = "Generates temporary LaTeX files of $jobname1"
- ext.jobname = jobname1
- preprocess.dependsOn "preprocess$taskSuffix"
- doLast {
- def result = exec {
- /*environment 'TEXINPUTS', "..;D:/DEV/SRC/COMPANY/HG;%TEXINPUTS%"*/
- commandLine 'pdflatex'
- args "--jobname=$jobname"
- args "--output-directory=$temporaryDir"
- args '-interaction=batchmode' // Don't output to console
- args "${docuTexMainFile}.tex"
- ignoreExitValue = true // Dedicated exception handling below
- }
- outputLatexLogOnError(temporaryDir, jobname, result)
- }
- }
- task ("makeIndex$taskSuffix") {
- ext.jobname = jobname1
- dependsOn "preprocess$taskSuffix"
- makeIndex.dependsOn "makeIndex$taskSuffix"
- doLast {
- /* exec {
- //makeindex <dateiname>.idx
- workingDir tasks["preprocess$taskSuffix"].temporaryDir
- commandLine 'makeindex'
- args jobname //.idx is set automatically
- args '-q' // quiet
- setIgnoreExitValue true
- } */
- // Use splitindex instead of makeindex
- // Use splitindex.jar to avoid message 'Perl interpreter could not be found'
- // (HG\company_tools\splitindex)
- javaexec {
- classpath configurations.splitindex
- main = 'splitindex' // fully qualified name of main class
- workingDir tasks["preprocess$taskSuffix"].temporaryDir
- args jobname
- args '--' // indicate to splitindex that what now follows are options to pass to makeindex
- args '-q' // makindex: quiet
- ignoreExitValue = true // In case there is not custom index ignore exit value
- }
- }
- }
- task ("compile$taskSuffix") {
- ext.jobname = jobname1
- description = "Creates PDF of $jobname1"
- dependsOn "makeIndex$taskSuffix"
- compile.dependsOn "compile$taskSuffix"
- outputs.file "${tasks["preprocess$taskSuffix"].temporaryDir}/${jobname}.pdf"
- doLast {
- def result = exec {
- commandLine 'pdflatex'
- args "--jobname=$jobname"
- args "--output-directory=${tasks["preprocess$taskSuffix"].temporaryDir}"
- args '-interaction=batchmode' // Don't output to console
- args "${docuTexMainFile}.tex"
- }
- outputLatexLogOnError(temporaryDir, jobname, result)
- }
- }
- task ("rename$taskSuffix", type:Copy) {
- //println "rename ${jobname1}.pdf into $destDir/${value}.pdf"
- rename.dependsOn "rename$taskSuffix"
- from tasks["compile$taskSuffix"]
- into destDir
- rename { "${value}.pdf" }
- }
- }
- }
- def outputLatexLogOnError(dir, jobname, executionResult) {
- if (executionResult.exitValue == 1) {
- def logFile = file("$dir/${jobname}.log")
- if (!logFile.exists())
- logFile = file("$dir/texput.log")
- throw new RuntimeException("""Failed to compile Latex script ${project.docuTexMainFile}.tex
- --------------------
- Begin latex log file
- --------------------
- $logFile.text
- ------------------
- End latex log file
- ------------------""")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement