apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'java-library-distribution'

jar {
	manifest {
		attributes 'Implementation-Title': 'PDF-AS-4 Library', 'JARMANIFEST': 'PDF-AS-LIB'
	}
}

buildscript {
	repositories {
		mavenLocal()
		mavenCentral()
	}
	dependencies { classpath("commons-io:commons-io:2.8.0") }

}

sourceSets {
	main {
		java {
			srcDirs = [ 'src/main/java', 'src/generated/java' ]
		}
	}
	test {
		java {
			srcDirs = ["src/test/java"]
		}
	}
}

configurations { 
	ws 
	
	pdfDoclet { extendsFrom compile }
}

project.ext {
	wsdlDir = file("src/main/resources/wsdl")
	generatedWsdlDir = file("src/generated/java")
	wsdlsToGenerate = [
			   ['-xjc', 
				    "$wsdlDir/MOA-SPSS-2.0.0.wsdl"],
	 ]
}

task createConf(type: Zip, dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME) {
	from 'src/configuration'
	//archiveBaseName 'config'
	archiveName 'config.zip'
	destinationDir new File(projectDir, 'src/main/resources/config')
}

compileJava.dependsOn(createConf)


repositories {
	mavenLocal()
	mavenCentral()
}

dependencies {
	api project (':pdf-as-common')
	api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
	api group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.13'
	api group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
    api group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.68'
	api group: 'javax.activation', name: 'activation', version: '1.1.1'
	api group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
	api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
	api group: 'org.bitbucket.b_c', name: 'jose4j', version: '0.7.6'
	api group: 'commons-io', name: 'commons-io', version: '2.8'
	api group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3'
	api 'org.apache.commons:commons-collections4:4.4'
	api group: 'ognl', name: 'ognl', version: '3.2.19'
	api files('libs/iaik_eccelerate_cms.jar')
	api files('libs/iaik_eccelerate.jar')
	api files('libs/iaik_jce_full.jar')
	api files('libs/iaik_cms.jar')
	api group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
	api group: 'org.slf4j', name: 'jcl-over-slf4j', version: slf4jVersion
	
	api group: 'com.google.zxing', name: 'core', version: '3.4.1'
	api group: 'com.google.zxing', name: 'javase', version: '3.4.1'
	testImplementation group: 'junit', name: 'junit', version: '4.+'
	testCompile "junit:junit:4.11"
	ws group: 'org.apache.cxf', name: 'cxf-tools', version: cxfVersion
	ws group: 'org.apache.cxf', name: 'cxf-tools-wsdlto-databinding-jaxb', version: cxfVersion
	ws group: 'org.apache.cxf', name: 'cxf-tools-wsdlto-frontend-jaxws', version: cxfVersion
}

task wsdl2Java() {
	if (!wsdlDir.listFiles()) {
		// do nothing
	} else {
		inputs.files wsdlDir.listFiles()
		outputs.files generatedWsdlDir
		doLast {
			wsdlsToGenerate.each { argsin ->
				argsin.add(argsin.size - 1, '-d')
				argsin.add(argsin.size - 1, generatedWsdlDir)
				javaexec {
					classpath configurations.ws
					main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
					args = argsin
					systemProperties = ['exitOnFinish':'TRUE']
				}
			}
		}
	}
}

task releaseConfig(type: Copy) {
	from 'src/main/resources/config/config.zip'
	into rootDir.toString() + "/releases/" + version + "/cfg"
	rename 'config.zip', 'defaultConfig.zip'
}

task releases(type: Copy) {
	from jar.outputs
	from distZip.outputs
	from distTar.outputs
	into rootDir.toString() + "/releases/" + version
}

releases.dependsOn jar
releases.dependsOn sourcesJar
releases.dependsOn distZip
releases.dependsOn distTar

releases.dependsOn releaseConfig

task apidocs(type: Javadoc) {
	classpath = configurations.compile
	source = sourceSets.main.allJava
	destinationDir = new File(rootDir.toString() + "/releases/" + version + "/docs/api")
	title = "PDF-AS " + project.pdfasversion + " Documentation"
	options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC
	options.charSet = "ISO-8859-1"
	options.author = "Andreas Fitzek"
	options.docTitle = "PDF-AS " + project.pdfasversion + " Documentation"
	options.version = project.pdfasversion
	options.windowTitle = "PDF-AS " + project.pdfasversion + " Library"
	options.header = "<b>PDF-AS " + project.pdfasversion + " Library  " + project.pdfasversion + " [" + project.revision + "]</b>"
	options.use = "true"
	options.links("http://docs.oracle.com/javase/1.7.0/docs/api/")
	include('at/gv/egiz/pdfas/lib/api/**')
}

task fulldocs(type: Javadoc) {
	classpath = configurations.compile
	source = sourceSets.main.allJava
	destinationDir = new File(rootDir.toString() + "/releases/" + version + "/docs/full")
	title = "PDF-AS " + project.pdfasversion + " Documentation"
	options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
	options.charSet = "ISO-8859-1"
	options.author = "Andreas Fitzek"
	options.docTitle = "PDF-AS " + project.pdfasversion + " Documentation"
	options.version = project.pdfasversion
	options.windowTitle = "PDF-AS " + project.pdfasversion + " Library"
	options.header = "<b>PDF-AS " + project.pdfasversion + " Library  " + project.pdfasversion + " [" + project.revision + "]</b>"
	options.use = "true"
	options.links("http://docs.oracle.com/javase/1.7.0/docs/api/")
	include('at/knowcenter/wag/egiz/**')
	include('at/gv/egiz/**')
}

//releases.dependsOn apidocs
//releases.dependsOn fulldocs

test {
	systemProperties 'property': 'value'
}