subprojects {
	apply plugin: 'java'
	apply plugin: 'eclipse'

	repositories { mavenCentral() }

	dependencies { testCompile 'junit:junit:4.8.2' }

	sourceCompatibility = 1.5

	version = '4.0.0-SNAPSHOT'
	pdfasversion = version
	revision = getCheckedOutGitCommitHash()
	
	jar { manifest.attributes provider: 'EGIZ', 'Specification-Version': getCheckedOutGitCommitHash(), 'Implementation-Version': version  }
}

def getCheckedOutGitCommitHash() {
	def gitFolder = "$projectDir/.git/"
	def takeFromHash = 40
	/*
	 * '.git/HEAD' contains either
	 *      in case of detached head: the currently checked out commit hash
	 *      otherwise: a reference to a file containing the current commit hash
	 */
	def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
	def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
	// def isRef = head.length > 1     // ref: refs/heads/master
 
	if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb
 
	def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
	refHead.text.trim().take takeFromHash
}

task docs(type: Javadoc) {
	source subprojects.collect {project -> project.sourceSets.main.allJava }
	classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
	destinationDir = new File(projectDir, 'docs')
}