You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. apply plugin: 'java'
  2. // Setting up project wide variables
  3. project.ext {
  4. name = 'Apache FOP'
  5. year = '1999-2009'
  6. // Not sure exactly what to put here, but since 1.1rc1 is out...
  7. version = '1.2-SNAPSHOT'
  8. sourceDir = 'src/java'
  9. sourceSandboxClassesDir = "src/sandbox/"
  10. sourceCodegenDir = "src/codegen"
  11. gensrcDir = "$buildDir/gensrc/"
  12. buildClassesDir = "$buildDir/classes/main/"
  13. buildSandboxClassesDir = "$buildDir/sandbox-classes/main/"
  14. buildCodegenClassesDir = "$buildDir/codegen-classes"
  15. }
  16. loadPropertiesFrom 'build.config'
  17. loadPropertiesFrom 'build.local.config'
  18. jar {
  19. baseName = 'fop'
  20. destinationDir = buildDir
  21. }
  22. sourceSets {
  23. main {
  24. java {
  25. srcDirs sourceDir, gensrcDir
  26. }
  27. }
  28. codegen {
  29. java {
  30. srcDir 'src/codegen/java'
  31. }
  32. }
  33. }
  34. // Setting up dependencies
  35. repositories {
  36. mavenCentral()
  37. maven {
  38. url 'http://repository.springsource.com/maven/bundles/external'
  39. }
  40. }
  41. configurations {
  42. tools
  43. }
  44. dependencies {
  45. compile 'avalon-framework:avalon-framework-api:4.2.0',
  46. 'avalon-framework:avalon-framework-impl:4.2.0',
  47. 'javax.media.jai:com.springsource.javax.media.jai.core:1.1.3',
  48. 'org.apache.ant:ant:1.8.4',
  49. 'commons-io:commons-io:1.3.1',
  50. 'commons-logging:commons-logging:1.0.4',
  51. 'net.sf.offo:fop-hyph:1.2',
  52. 'xalan:serializer:2.7.1',
  53. 'xalan:xalan:2.7.1',
  54. 'xerces:xercesImpl:2.7.1',
  55. 'xml-apis:xml-apis:1.3.04',
  56. 'xml-apis:xml-apis-ext:1.3.04',
  57. fileTree(dir: 'lib', includes: ['batik*.jar', 'servlet*.jar', 'xmlgraphics-commons*.jar'])
  58. tools 'com.thoughtworks.qdox:qdox:1.12',
  59. 'xmlunit:xmlunit:1.3',
  60. 'pmd:pmd:4.3',
  61. 'asm:asm:3.1'
  62. }
  63. // This is an artefact from the legacy Ant builder, but until we have alternate mechanisms some of this
  64. // needs to be done.
  65. task init() << {
  66. println """ |------------------- ${name} ${version} [${year}] ----------------
  67. |See build.properties and build-local.properties for additional build settings
  68. |${gradle.gradleVersion}
  69. |VM: ${System.properties['java.vm.version']}, ${System.properties['java.vm.vendor']}
  70. |JAVA_HOME: ${System.env.JAVA_HOME?: 'NOT SET'}
  71. """.stripMargin().trim()
  72. def failUnless = { msg, predicate ->
  73. if (!predicate()) {
  74. throw new GradleException(msg)
  75. }
  76. }
  77. def isAvailable = { map, yield = {->} ->
  78. def ant = new groovy.util.AntBuilder()
  79. def atts = [property: 'isAvailable'] + map
  80. ant.available(atts, yield)
  81. Boolean.valueOf(ant.project.properties.isAvailable)
  82. }
  83. def isClassAvailable = { String className, configuration ->
  84. isAvailable([classname: className]) {
  85. classpath {
  86. configuration.each {
  87. pathelement(location: it.toString())
  88. }
  89. }
  90. }
  91. }
  92. failUnless("${name} requires at least Java 1.5!") {
  93. return Float.valueOf(System.getProperty('java.version')[0..2]) >= 1.5
  94. }
  95. project.ext {
  96. jcePresent = isClassAvailable('javax.crypto.Cipher', configurations.compile)
  97. println 'JCE Support ' + (jcePresent ? 'PRESENT' : 'NOT present')
  98. /* TODO junitPresent = isClassAvailable('org.junit.Test', configurations.testCompile)
  99. println 'JUnit Support ' + (junitPresent ? 'PRESENT' : 'NOT present - Committers are required to have JUnit working')
  100. */
  101. }
  102. }
  103. private void loadPropertiesFrom(fileName) {
  104. def propFile = new File(fileName)
  105. if (propFile.file) {
  106. def conf = new ConfigSlurper().parse(propFile.toURL())
  107. conf.each {k,v->
  108. setProperty(k,v)
  109. }
  110. }
  111. }
  112. // Perform the creation of the auto-generated classes
  113. task codegen() << {
  114. String outputDir = "${buildDir}/gensrc/org/apache/fop/fonts/"
  115. String base14Dir = outputDir + 'base14/'
  116. String srcFontsDir = "$sourceCodegenDir/fonts/"
  117. def createFont = { String fontName, String encodingName = 'WinAnsiEncoding' ->
  118. ant.xslt(in: srcFontsDir + "${fontName}",
  119. style: srcFontsDir + "font-file.xsl",
  120. out: base14Dir + "${fontName.replaceFirst('xml', 'java')}") {
  121. if (encodingName) {
  122. param(name: 'encoding', expression: encodingName)
  123. }
  124. }
  125. }
  126. new File(base14Dir).mkdirs()
  127. fileTree(dir: srcFontsDir, includes: ['Helvetica*.xml', 'Times*.xml', 'Courier*.xml']).each {
  128. createFont(it.getName())
  129. }
  130. createFont('Symbol.xml', null)
  131. createFont('ZapfDingbats.xml', null)
  132. ant.xslt(in: srcFontsDir + 'encodings.xml', style: srcFontsDir + 'code-point-mapping.xsl', out: outputDir + 'CodePointMapping.java');
  133. }
  134. task compileSandboxJava(dependsOn: compileJava) << {
  135. new File(buildSandboxClassesDir).mkdirs()
  136. ant.javac(destDir: buildSandboxClassesDir) {
  137. src(path: sourceSandboxClassesDir)
  138. patternset(includes: '**/*.java')
  139. classpath {
  140. pathElement(path: configurations.compile.asPath)
  141. pathElement(location: buildClassesDir)
  142. }
  143. }
  144. }
  145. compileJava {
  146. dependsOn init, codegen
  147. doLast { tasks.compileSandboxJava.execute() }
  148. }
  149. task resourcegen(dependsOn: compileJava) << {
  150. String codegenClassesSrc = "$sourceCodegenDir/java"
  151. new File(buildCodegenClassesDir).mkdirs()
  152. ant.javac(destdir: buildCodegenClassesDir) {
  153. src(path: codegenClassesSrc)
  154. patternset(includes: '**/*.java')
  155. classpath { pathElement(location: buildClassesDir)
  156. pathElement(path: configurations.compile.asPath)
  157. pathElement(path: configurations.tools.asPath)
  158. }
  159. }
  160. copy {
  161. from(codegenClassesSrc) {
  162. include '**/*.xsl'
  163. }
  164. into buildCodegenClassesDir
  165. }
  166. ant.taskdef(name: 'eventResourceGenerator', classname: 'org.apache.fop.tools.EventProducerCollectorTask') {
  167. classpath { pathElement(location: buildClassesDir)
  168. pathElement(location: buildCodegenClassesDir)
  169. pathElement(path: configurations.compile.asPath)
  170. pathElement(path: configurations.tools.asPath)
  171. }
  172. }
  173. ant.eventResourceGenerator(destdir: gensrcDir) {
  174. fileset(dir: sourceDir, includes: '**/*.java')
  175. }
  176. }
  177. task compileCopyResources(dependsOn: resourcegen) << {
  178. String viewerResourceSourceDir = "$sourceDir/org/apache/fop/render/awt/viewer/"
  179. String viewerResourceTargetDir = "$buildClassesDir/org/apache/fop/render/awt/viewer/"
  180. copy {
  181. from(sourceDir) {
  182. include 'META-INF/**'
  183. include '**/*.icm'
  184. include '**/*.xml'
  185. include '**/*.LICENSE.txt'
  186. include '**/*.xsl'
  187. }
  188. from(gensrcDir) {
  189. include '**/*.xml'
  190. }
  191. into buildClassesDir
  192. }
  193. def copyViewerClasses = { dir ->
  194. new File(viewerResourceTargetDir + dir).mkdirs()
  195. copy {
  196. from(viewerResourceSourceDir + dir) {
  197. include '**/*'
  198. }
  199. into viewerResourceTargetDir + dir
  200. }
  201. }
  202. copyViewerClasses('images/')
  203. copyViewerClasses('resources/')
  204. copy {
  205. from(sourceSandboxClassesDir) {
  206. include 'META-INF/**'
  207. }
  208. into buildSandboxClassesDir
  209. }
  210. }
  211. task compile {
  212. dependsOn compileCopyResources, compileJava
  213. }
  214. // Handle hyphenation compilation
  215. task codegenHyphenationClasses(dependsOn: compile) << {
  216. ant.javac(destDir: buildCodegenClassesDir) {
  217. src(path: "$sourceCodegenDir/unicode/java")
  218. }
  219. ant.java(classname: 'org.apache.fop.hyphenation.UnicodeClasses', classpath: buildCodegenClassesDir, outputproperty: 'classesresult', fork: true) {
  220. arg(value: "$sourceDir/org/apache/fop/hyphenation/classes.xml")
  221. }
  222. // Ant did some messaging here, couldn't figure out how to replicate it, I'm sure it wasn't important... Hubris...
  223. }
  224. task compileHyphenation(dependsOn: compile) << {
  225. new File("$buildDir/classes/hyph").mkdirs()
  226. ant.java(classname: 'org.apache.fop.hyphenation.SerializeHyphPattern', classpath: buildClassesDir, fork: true) {
  227. arg(value: 'hyph/')
  228. arg(value: "$buildDir/classes/hyph/")
  229. jvmarg(value: '-Xss512k')
  230. }
  231. }
  232. task uptodateJarHyphenation(dependsOn: compileHyphenation) << {
  233. ant.uptodate(property: 'jar.hyphenation.uptodate', targetfile: '$buildDir/fop-hyph.jar') {
  234. srcfiles(dir: '$buildDir/classes/hyph/')
  235. }
  236. }
  237. task jarHyphenation(dependsOn: uptodateJarHyphenation) << {
  238. ant.jar(jarfile: "$buildDir/fop-hyph.jar", basedir: buildClassesDir, includes: "hyph/*.hyph") {
  239. delegate.manifest {
  240. attribute(name: 'Implementation-Title', value: project.ext.name)
  241. attribute(name: 'Implementation-Version', value: project.ext.version)
  242. attribute(name: 'Implementation-Vendor', value: "The Apache Software Foundation (http://xmlgraphics.apache.org/fop/)")
  243. // TODO: the Java version is a global property in the Ant version
  244. attribute(name: 'Build-Id', value: "${new Date()} (${getProperty('user.name')} [${getProperty('os.name')} ${getProperty('os.version')} ${getProperty('os.arch')}, Java ${getProperty('java.runtime.version')}, Target Java 1.5])")
  245. }
  246. }
  247. }