Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import groovy.text.SimpleTemplateEngine
- import java.text.DateFormat
- import java.text.SimpleDateFormat
- import java.util.jar.Attributes
- import org.apache.tools.ant.taskdefs.condition.Os
- import org.gradle.api.Task
- import org.gradle.api.tasks.StopExecutionException
- import org.gradle.api.tasks.wrapper.Wrapper
- import org.gradle.util.GradleVersion
- import org.slf4j.Logger
- import org.slf4j.LoggerFactory
- import org.apache.tools.ant.filters.ReplaceTokens
- apply plugin: 'groovy'
- type = 'jar'
- buildTime = new Date()
- versionModifier = null
- sourceSets {
- main { resources { srcDir 'src/latex' } }
- }
- // PROPERTIES
- def stagingDirName = 'build/staging/docs'
- def docsDirName = 'build/docs'
- task copyDocs << {
- def stagingDir = file(stagingDirName)
- stagingDir.mkdirs()
- copy {
- from('src/latex') { include '**/*.tex','**/*.inc' }
- filter(ReplaceTokens, tokens: [release: version, docVersion: docVersion])
- into stagingDir
- includeEmptyDirs = false
- }
- }
- task myInitConfig(type:Copy) << {
- def stagingDir = file(stagingDirName)
- stagingDir.mkdirs()
- from('src/latex') { include '**/*.tex' //
- }
- into stagingDir
- includeEmptyDirs = false
- }
- task genDocs << {
- myInitConfig.execute()
- cleanLatex(file(stagingDirName))
- copyDocs.execute()
- if (!isLatexInstallled()) {
- throw new StopExecutionException('Latex is not installed. We skip the document!')
- }
- FileTree tree = fileTree(dir: stagingDirName)
- tree.include '**/*.tex'
- tree.each {File file ->
- compileLatex(file)
- }
- }
- boolean isLatexInstallled() {
- boolean ret_val = false;
- try {
- ant.exec(output: 'build/staging/findLatexOut', executable: 'pdflatex', dir: projectDir) { arg(line: "-help") }
- ret_val = true
- } catch (Throwable e) {
- e.printStackTrace();
- ret_val = false
- }
- return ret_val
- }
- void cleanLatex(File dir) {
- file(dir.path).mkdirs()
- ant.delete() {
- fileset(dir: dir, includes: "*.aux, *.lg, *.tmp, *.html, *.pdf, *.log, *.dvi, *.css, *.fdb_latexmk, *.idv, *.toc, *.xref, *.4ct, *.4tc, *.out")
- }
- }
- void compileLatex(File fileToProcess) {
- 3.times {
- ant.exec(executable: 'pdflatex', dir: fileToProcess.parent, failonerror: true) { arg(value: fileToProcess.name) }
- }
- 3.times {
- ant.exec(executable: 'makeindex', dir: fileToProcess.parent, failonerror: true) { arg(value: fileToProcess.name) }
- }
- 3.times {
- ant.exec(executable: 'pdflatex', dir: fileToProcess.parent, failonerror: true) { arg(value: fileToProcess.name) }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement