apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

group = 'org.giiwa'
version = '3.3'
description = 'giiwa distributed web framework'

sourceCompatibility = 11
targetCompatibility = 11

def buildno = new Date().format("yyMMddHHmm")

tasks.withType(JavaCompile) {
	options.encoding = 'UTF-8' 
	options.warnings = false 
}
 
println description
println 'buildno: ' + buildno

repositories {
     maven { url "https://repo1.maven.org/maven2" }
     maven { url "https://repo.osgeo.org/repository/release/"}
     maven { url "https://download.dcache.org/nexus/repository/public/"}
     maven { url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/" }
     maven { url "https://artifacts.alfresco.com/nexus/content/repositories/releases/" }
     
     mavenCentral()
}

configurations.all() {
    Configuration configuration ->
        configuration.resolutionStrategy.failOnVersionConflict()
}

dependencies {

	// https://mvnrepository.com/artifact/org.openjdk.nashorn/nashorn-core
	implementation group: 'org.openjdk.nashorn', name: 'nashorn-core', version: '15.4'
	
	// https://mvnrepository.com/artifact/com.github.mwiede/jsch
	implementation group: 'com.github.mwiede', name: 'jsch', version: '0.2.23'
    
    implementation group: 'commons-net', name: 'commons-net', version:'3.6'
	
	// https://mvnrepository.com/artifact/com.emc.ecs/nfs-client
    implementation ('com.emc.ecs:nfs-client:1.1.0') {
        exclude group: 'org.apache.commons',module: 'commons-lang3'
    }
        
	// https://mvnrepository.com/artifact/jcifs/jcifs
	// implementation group: 'jcifs', name: 'jcifs', version: '1.3.17'
	// https://mvnrepository.com/artifact/org.codelibs/jcifs
	implementation ('org.codelibs:jcifs:2.1.36'){
	}

	// https://mvnrepository.com/artifact/org.littleshoot/littleproxy
//	implementation ('org.littleshoot:littleproxy:1.1.2'){
//		 exclude group: 'org.apache.commons',module: 'commons-lang3'
//		 exclude group: 'org.slf4j',module: 'slf4j-api'
//	////	 exclude group: 'com.google.guava',module: 'guava'
//		 exclude group: 'io.netty',module: 'netty-all'
//	}

	implementation ('io.netty:netty-all:4.0.56.Final') {
	}
	implementation ('com.google.guava:guava:20.0'){
	}
	
	// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core
	// implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '11.0.4'
		
	// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server
	implementation ('org.eclipse.jetty:jetty-server:12.0.16') {
        exclude group: 'org.slf4j',module: 'slf4j-api'
	}
		
	// https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api
	//implementation group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: '6.1.0'
	// https://mvnrepository.com/artifact/org.eclipse.jetty.ee10/jetty-ee10-servlet
	implementation ('org.eclipse.jetty.ee10:jetty-ee10-servlet:12.0.16'){
        exclude group: 'org.slf4j',module: 'slf4j-api'
	}
	
	// https://mvnrepository.com/artifact/com.typesafe/config
	implementation group: 'com.typesafe', name: 'config', version: '1.4.3'
		
	// https://mvnrepository.com/artifact/javax.media/jai_codec
	//implementation group: 'javax.media', name: 'jai_codec', version: '1.1.3'

	// https://mvnrepository.com/artifact/javax.media/jai-core
	//implementation group: 'javax.media', name: 'jai-core', version: '1.1.3'

	// https://mvnrepository.com/artifact/javax.media.jai/mlibwrapper-jai
	//implementation group: 'javax.media.jai', name: 'mlibwrapper-jai', version: '1.1.3'
		
	// https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3
	implementation group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.2.5'
	
	// https://mvnrepository.com/artifact/org.dcache/nfs4j-core
	implementation ('org.dcache:nfs4j-core:0.25.0') {
    	exclude group: 'org.slf4j',module: 'slf4j-api'
    	exclude group: 'com.google.guava',module: 'guava'
	}
	
	implementation ('org.codehaus.woodstox:stax2-api:4.2.1'){
		//cos 腾讯云用到了
	}
	
    implementation ('org.fusesource:sigar:1.6.4') {
    	exclude group: 'log4j',module: 'log4j'
    }
        
	// https://mvnrepository.com/artifact/redis.clients/jedis
    implementation ('redis.clients:jedis:6.0.0-beta2') {
    	//exclude group: 'org.slf4j',module: 'slf4j-api'
    	exclude group: 'org.apache.commons',module: 'commons-pool2'
    	exclude group: 'com.google.code.gson',module: 'gson'
    }

	// https://mvnrepository.com/artifact/io.milvus/milvus-sdk-java
	//implementation ('io.milvus:milvus-sdk-java:2.5.5'){
	//	exclude group: 'com.google.protobuf', module: 'protobuf-java'
	//	exclude group: 'org.apache.commons', module: 'commons-text'
	//	exclude group: 'com.google.guava', module: 'guava'
	//	exclude group: 'org.apache.commons', module: 'commons-lang3'
	//	exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
	//	exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
	//	exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-common'
	//	exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
	//}

	// https://mvnrepository.com/artifact/org.neo4j.driver/neo4j-java-driver
	//implementation("org.neo4j.driver:neo4j-java-driver:5.28.4")

//	implementation ('org.apache.httpcomponents.core5:httpcore5-h2:5.2.4') {
//	}

//	implementation ('org.apache.httpcomponents.core5:httpcore5:5.2.4') {
//	}
    
    // https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc
//	implementation ('com.clickhouse:clickhouse-jdbc:0.8.2') {
//		exclude group: 'org.apache.commons',module: 'commons-compress'
//		exclude group: 'commons-codec',module: 'commons-codec'
//		exclude group: 'commons-io',module: 'commons-io'
//		exclude group: 'org.apache.httpcomponents.core5',module: 'httpcore5-h2'
//		exclude group: 'org.apache.httpcomponents.core5',module: 'httpcore5'
//		exclude group: 'org.slf4j',module: 'slf4j-api'
//		exclude group: 'org.ow2.asm',module: 'asm'
//		exclude group: 'org.slf4j',module: 'slf4j-api'
//		exclude group: 'org.apache.commons',module: 'commons-lang3'
//	} 
    
    // https://mvnrepository.com/artifact/org.javassist/javassist
	implementation group: 'org.javassist', name: 'javassist', version: '3.29.2-GA'
    
    // https://mvnrepository.com/artifact/org.snmp4j/snmp4j-agent
	implementation group: 'org.snmp4j', name: 'snmp4j-agent', version: '3.5.4'

	implementation group: 'commons-io', name: 'commons-io', version: '2.14.0'
 	// https://mvnrepository.com/artifact/commons-codec/commons-codec
	implementation group: 'commons-codec', name: 'commons-codec', version: '1.15'
 
 	// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
	implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
 
 	// https://mvnrepository.com/artifact/org.apache.commons/commons-compress
	implementation group: 'org.apache.commons', name: 'commons-compress', version: '1.23.0'
 
	// https://mvnrepository.com/artifact/org.yaml/snakeyaml
	implementation group: 'org.yaml', name: 'snakeyaml', version: '2.2'
 
	 // https://mvnrepository.com/artifact/org.sejda.webp-imageio/webp-imageio-sejda
	implementation group: 'org.sejda.webp-imageio', name: 'webp-imageio-sejda', version: '0.1.0'
 
    implementation ('org.apache.commons:commons-lang3:3.8.1')
    implementation ('org.apache.commons:commons-configuration2:2.5'){
    	exclude group: 'org.apache.commons',module: 'commons-lang3'
    }
    
    implementation ("org.apache.commons:commons-dbcp2:2.11.0") {
    	//exclude group: 'org.apache.commons',module: 'commons-pool2'
    }
    implementation group: 'org.apache.commons', name: 'commons-pool2', version:'2.12.0'

	// https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on
	implementation group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: '1.74'
	// https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk18on
	implementation group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: '1.74'
	// https://mvnrepository.com/artifact/org.antlr/antlr4
	implementation group: 'org.antlr', name: 'antlr4', version: '4.11.1'

	// https://mvnrepository.com/artifact/com.twelvemonkeys.imageio/imageio-jpeg
	implementation group: 'com.twelvemonkeys.imageio', name: 'imageio-jpeg', version: '3.9.4'

	implementation ('net.java.dev.jna:jna:5.13.0')

    implementation ('org.apache.activemq:activemq-client:5.17.1') {
    	exclude group: 'org.slf4j',module: 'slf4j-api'
    }

	// https://mvnrepository.com/artifact/org.apache.rocketmq/rocketmq-client
    implementation ('org.apache.rocketmq:rocketmq-client:5.0.0') {
    	exclude group: 'commons-codec',module: 'commons-codec'
    	exclude group: 'org.apache.commons',module: 'commons-lang3'
    	exclude group: 'com.google.guava',module: 'guava'
    	//exclude group: 'com.alibaba',module: 'fastjson'
    	exclude group: 'org.slf4j',module: 'slf4j-api'
		exclude group: 'io.netty',module: 'netty-all'
    }

	// https://mvnrepository.com/artifact/org.graylog2/syslog4j
	implementation ('org.graylog2:syslog4j:0.9.60') {
    	exclude group: 'org.apache.commons',module: 'commons-lang3'
	}

    // https://mvnrepository.com/artifact/org.apache.curator/curator-framework
	// implementation ('org.apache.curator:curator-framework:5.2.0') {
    implementation ('org.apache.curator:curator-recipes:5.2.0') {
    	exclude group: 'org.slf4j',module: 'slf4j-api'
    	exclude group: 'com.google.guava',module: 'guava'
    	exclude group: 'io.netty',module: '*'
    }

    // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api
	implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.20.0'
    
    implementation ("org.apache.velocity:velocity-engine-core:2.3"){
    	exclude group: 'org.apache.commons',module: 'commons-lang3'
    	exclude group: 'org.slf4j',module: 'slf4j-api'
    }
    
    //implementation group: 'org.rosuda.REngine', name: 'Rserve', version:'1.8.1'
    implementation group: 'javax.mail', name: 'mail', version:'1.4'
//    implementation ('commons-fileupload:commons-fileupload2:1.5'){
//    	exclude group: 'commons-io',module: 'commons-io'
//    }
    // https://mvnrepository.com/artifact/org.apache.commons/commons-fileupload2-jakarta
	implementation ('org.apache.commons:commons-fileupload2-jakarta:2.0.0-M1'){
    	exclude group: 'commons-io',module: 'commons-io'
	}
        
    implementation group: 'dom4j', name: 'dom4j', version:'1.6.1'
    implementation group: 'org.jsoup', name: 'jsoup', version:'1.10.2'
    implementation group: 'com.google.zxing', name: 'core', version:'3.4.1'
    implementation group: 'com.google.code.gson', name: 'gson', version:'2.10.1'

	// https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync
	// compile group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.2.3'
    // implementation group: 'org.mongodb', name: 'mongo-java-driver', version:'3.12.13'
	// https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync
	implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '5.1.0'
    
	// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
	implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.6.20'
        
    // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
	//implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0'
    implementation ('com.squareup.okhttp3:okhttp:4.12.0'){
    	exclude group: 'org.jetbrains.kotlin',module: 'kotlin-stdlib'
    	exclude group: 'org.jetbrains.kotlin',module: 'kotlin-stdlib-jdk7'
    	exclude group: 'org.jetbrains.kotlin',module: 'kotlin-stdlib-jdk8'
    	exclude group: 'org.jetbrains.kotlin',module: 'kotlin-stdlib-common'
    }

	// https://mvnrepository.com/artifact/com.google.iot.coap/coap
	//implementation ('com.google.iot.coap:coap:0.02.01'){
    //	exclude group: 'org.json',module: 'json'
    //	exclude group: 'com.google.guava',module: 'guava'
    //	exclude group: 'org.checkerframework',module: 'checker-qual'
    //	exclude group: 'com.google.code.findbugs',module: 'jsr305'
    //	exclude group: 'com.google.errorprone',module: 'error_prone_annotations'
	//}

	// https://mvnrepository.com/artifact/com.github.junrar/junrar
	implementation group: 'com.github.junrar', name: 'junrar', version: '7.5.1'

    implementation ('org.slf4j:slf4j-log4j12:1.7.36')
    // https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
	implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.19.6'
    
	// https://mvnrepository.com/artifact/com.mysql/mysql-connector-j
	implementation ('com.mysql:mysql-connector-j:8.4.0'){
    	exclude group: 'com.google.protobuf',module: 'protobuf-java'
	}
	// https://mvnrepository.com/artifact/org.postgresql/postgresql
	implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.4'
	
	// https://mvnrepository.com/artifact/com.dameng/DmJdbcDriver18
//	implementation group: 'com.dameng', name: 'DmJdbcDriver18', version: '8.1.3.140'
	
	// https://mvnrepository.com/artifact/org.apache.tomcat/catalina
	//implementation group: 'org.apache.tomcat', name: 'catalina', version: '6.0.53'
		
    //implementation files('lib/catalina.jar')
//    implementation files('tomcat/lib/servlet-api.jar')
    implementation files('lib/DmJdbcDriver11.jar')
    //implementation files('lib/Dm8JdbcDriver18-8.1.1.49.jar')
        
    //testCompile 'junit:junit:4.8.2'
}

task prepare(dependsOn: [build]) {
	doLast {
/*		exec { 
			commandLine 'git', 'add', '.'
		}
		exec {
			commandLine 'git', 'commit', '-m', 'auto commit'
		}
		exec {
			commandLine 'git', 'tag', version + '.' + buildno
		}
		exec { 
			commandLine 'git', 'push', '--tags'
		}
*/		
		copy{
		    from('deploy')
		    into('build/giiwa/giiwa/')
		}

		copy{
			println 'copy modules'
		    from('src/main/modules')
		    into('build/giiwa/giiwa/modules')
		}
		
		def xml1 = new BufferedReader(new FileReader(new File('src/main/modules/default/module.xml')))
		def xml2 = new PrintStream(new File('build/giiwa/giiwa/modules/default/module.xml'))
		def line = xml1.readLine()
		while( line != null ){
			if( line.indexOf('>0<')>-1 ){
				line = line.replace('<build>0</build>', '<build>' + buildno + '</build>')
			}
			xml2.println(line)
			line = xml1.readLine();
		}
		xml1.close();
		xml2.close();

		copy{
			println 'copy depends to lib'
		    from configurations.runtimeClasspath
		    into('build/giiwa/giiwa/lib')
		}
		copy {
			println 'copy build/libs to lib'
		    from('build/libs')
		    into('build/giiwa/giiwa/lib')
		}
		copy {
			println 'copy build/libs to WEB-INF/lib'
		    from('build/giiwa/giiwa/lib')
		    into('build/giiwa/giiwa/modules/default/WEB-INF/lib')
		    exclude('sigar')
		}
		copy {
			println 'copy build/giiwa/giiwa/modules/default to upgrade'
		    from('build/giiwa/giiwa/modules/default')
		    into('build/upgrade/default')
		}
		copy {
			println 'copy build/giiwa/giiwa/lib/ to upgrade'
		    from('build/giiwa/giiwa/lib/')
		    into('build/upgrade/default/WEB-INF/lib/')
		    include('*.jar') 
		}
	}
}

task zip(type: Zip,dependsOn:prepare) {
	from 'build/giiwa'
	destinationDir file('build')
	archiveName 'giiwa-' + version + '.zip'
	
	doLast {
		println 'zip success, archived build/' + archiveName
	}
}

task tgz(type: Tar, dependsOn:prepare) {
	from 'build/giiwa'
	compression 'gzip'
	destinationDir file('build')
	archiveName 'giiwa-' + version + '.tgz'

	doLast {
		println 'tgz success, archived build/' + archiveName
	}
}

task upgrade(type: Zip,dependsOn:prepare) {
	from 'build/upgrade'
	destinationDir file('build')
	archiveName 'giiwa-' + version + '.' + buildno + '.zip'

	doLast {
		println 'zip success, archived build/' + archiveName
	}
}

task release(dependsOn: [upgrade, zip, tgz]);

task archive(type: Copy,dependsOn:release) {
	from 'build'
	into '/home/nfs/giiwa/' + version + '/'
	include "*.zip"
	include "*.tgz"
}

