apply plugin: "com.axelor.app-module"

apply from: "../version.gradle"

apply {
	version = openSuiteVersion
}

axelor {
	title "Axelor Studio"
	description "Axelor Studio Module"
}

dependencies {
    compile project(":modules:axelor-admin")
	compile project(":modules:axelor-message")
	compile 'commons-lang:commons-lang:2.3'
//	compile 'org.xhtmlrenderer:flying-saucer-pdf:9.1.4'
	compile 'org.eclipse.birt.runtime.3_7_1:Tidy:1'
	compile 'org.apache.commons:commons-exec:1.2'
//	compile "org.bouncycastle:bcprov-jdk15on:1.62"
}

def updateJsp(jspFile, check, lines) {
	def jsp = file("${rootProject.buildDir}/webapp/${jspFile}")
	def text = lines.join("\n");
	if (jsp.exists()) {
		def jspText = jsp.getText('UTF-8')
		if (jspText.indexOf(check) == -1) {
			text = jspText + text
		}
	}
	file(jsp).write(text, 'UTF-8')
}

//XXX: this task should be removed when we introduce per module webapp support in Axelor Open Platform
task copyWebapp(type: Copy) {
	destinationDir = file(rootProject.buildDir)
	into("webapp/studio") {
		from "src/main/webapp"
	}
	doLast {
		// update index-head.jsp
		updateJsp("index-head.jsp", "diagram-js.css", [
			'<link href="studio/lib/bpmn-js/assets/bpmn-font/css/bpmn-embedded.css" rel="stylesheet">',
			'<link href="studio/lib/bpmn-js/assets/diagram-js.css" rel="stylesheet">',
			'<link href="studio/css/bpmn.css" rel="stylesheet">'])
		// update index-foot.jsp
		updateJsp("index-foot.jsp", "bpmn-modeler.js", [
			'<script src="studio/lib/bpmn-js/bpmn-modeler.js"></script>',
			'<script src="studio/js/form/form.bpmn.js"></script>'])
	}
}

rootProject.tasks.war.dependsOn copyWebapp
