apply plugin: "java"
tasks.withType(JavaCompile){
	options.encoding = "UTF-8"
}

def basicDir="../"
def libDir="${basicDir}/lib"

task appletJar<<{
	ant{
		mkdir(dir:"./tmp")
		mkdir(dir:"build/classes/main")
		copy(todir:"build/classes/"){
			fileset(dir:"${basicDir}/core/build/classes/main")
			fileset(dir:"${basicDir}/chart/build/classes/main")			
			fileset(dir:"${basicDir}/report/build/classes/main")		
			fileset(dir:"${basicDir}/platform/build/classes/main")		
		}
		unjar(src:"${libDir}/3rd.jar",dest:"./tmp")
		unjar(src:"${libDir}/servlet-api.jar",dest:"./tmp")
		jar(jarfile:"build/libs/fr-applet-8.0.jar"){
			fileset(dir:"build/classes"){
				exclude(name:"*.*")
				exclude(name:"bin/*.*")
				exclude(name:"classes/**")
				exclude(name:"com/fr/schedule/**")
				exclude(name:"com/fr/cell/**")
				exclude(name:"com/fr/dialog/**")
				exclude(name:"com/fr/view/**")
				exclude(name:"com/fr/web/**")
				exclude(name:"com/fr/fs/**")
				exclude(name:"com/fr/design/**")
				exclude(name:"com/fr/start/**")
				exclude(name:"com/fr/process/**")
			}
			fileset(dir:"./tmp"){
				include(name:"javax/mail/**")
				include(name:"javax/servlet/**")
				include(name:"org/freehep/**")
				include(name:"com/fr/third/JAI/**")
				include(name:"com/fr/third/antlr/**")
				include(name:"com/fr/third/javax/**")
				include(name:"com/sun/xml/**")
				include(name:"javax/xml/**")

			}
			fileset(dir:"build/classes"){
				include(name:"com/fr/web/*.class")
				include(name:"com/fr/web/attr/*.class")
			}
		}
		delete(dir:"./tmp")
		def jdk6home=	"D:/FineReport/develop/java/jdk1.6u35"
		def keystore="frapplet.store"
		def keycert="fr.cert"
		def keypassword="123456"
		def keyalias="fr"
		
		exec(executable:"${jdk6home}/bin/keytool"){
			arg(line:"-genkey -dname &quot;CN=FineReport L=NanJing C=China&quot; -keystore ${keystore} -alias ${keyalias} -validity 3650 -storepass ${keypassword}")
		}
		exec(executable:"${jdk6home}/bin/keytool"){
			arg(line:"-export -keystore ${keystore} -alias ${keyalias} -file ${keycert} -storepass ${keypassword}")
		}

		exec(executable:"${jdk6home}/bin/jarsigner"){
			arg(line:"-keystore ${keystore} -storepass ${keypassword} 'build/libs/fr-applet-8.0.jar' ${keyalias}")
		}
		delete(file:"${keystore}")
		delete(file:"${keycert}")
		delete(dir:"build/classes")
	
	}

}