group = 'org.tmatesoft.svnkit'
version = '1.8.12'

project.ext {
   release = true
   target = '1.6'
   compatibleSvnVersion = '1.8.1'
}

apply from: 'build.pom.gradle'

buildscript {
    apply from: 'build.defaults.gradle'
    configurations.all {
        resolutionStrategy {
            cacheChangingModulesFor 0, 'seconds'
            cacheDynamicVersionsFor 0, 'seconds'
        }
    }
    repositories {
        maven {
           url project.ext.buildPluginRepositoryURL
        }
    }
    dependencies { classpath 'org.tmatesoft.build:build:0.9.9' }
}

task wrapper(type: Wrapper) {}

def javaProjects() {
    return subprojects - project(':svnkit-distribution')
}

allprojects {
    apply plugin : 'base'
    apply plugin : 'build'
}

configure(javaProjects() + rootProject) {
    apply plugin: 'eclipse'
    apply plugin: 'idea'

    gradle.taskGraph.whenReady { taskGraph ->
        taskGraph.allTasks.each { task ->
            if (task.name == 'eclipseWtpComponent') {
                task.enabled = false
            }
            if (task.name == 'eclipseWtpFacet') {
                task.enabled = false
            }
        }
    }
}


configure(javaProjects()) {
    apply plugin : 'java'
    apply plugin : 'signing'

    sourceCompatibility = target
    targetCompatibility = target

    configurations {
        sources
        javadocs
    }

    task sourcesJar(type: Jar) {
        description = 'Builds Java Sources Jar'
        from sourceSets.main.java.srcDirs
        classifier = 'sources'
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        description="Builds Javadoc Jar"
        from "$docsDir/javadoc"
        classifier = 'javadoc'
    }

    jar {
        metaInf {
            from rootProject.file('LICENSE.txt')
        }
    }

    artifacts { sources sourcesJar }
}

project(':svnkit') {
    dependencies {
        compile 'de.regnis.q.sequence:sequence-library:1.0.3'
        compile 'org.tmatesoft.sqljet:sqljet:1.1.10'
        compile 'net.java.dev.jna:jna:4.1.0'
        compile 'net.java.dev.jna:jna-platform:4.1.0'
        compile 'com.trilead:trilead-ssh2:1.0.0-build220'
        compile('com.jcraft:jsch.agentproxy.connector-factory:0.0.7') {
		exclude group: 'net.java.dev.jna'
	}
        compile 'com.jcraft:jsch.agentproxy.svnkit-trilead-ssh2:0.0.7'

        testCompile 'junit:junit:4.8'
    }
    artifacts { maven jar, sourcesJar, javadocJar }
}

project(':svnkit-javahl16') {
    dependencies {
        compile project(path: ':svnkit')
        compile 'org.apache.subversion:svn-javahl-api:1.8.1'

        testCompile 'org.apache.subversion:svn-javahl-tests:1.8.1'
    }
    artifacts { maven jar, sourcesJar, javadocJar }
}

project(':svnkit-cli') {
    dependencies {
        compile project(path: ':svnkit')
    }
    artifacts { maven jar, sourcesJar, javadocJar }
}

project(':svnkit-dav') {
    apply plugin: 'war'

    dependencies {
        compile project(path: ':svnkit')
        compile 'javax.servlet:servlet-api:2.5'
    }
    artifacts { maven war }
}

project(':svnkit-test') {
    dependencies {
        compile project(path: ':svnkit-cli')
    }
    sourcesJar.enabled=false
}

project(':svnkit-osgi') {
    sourcesJar.enabled=false
    artifacts { maven jar }
}

project(':svnkit-distribution') {
    configurations {
        binaries
        sources
        scripts
        osgi
    }

    dependencies {
        binaries project(path: ':svnkit')
        binaries project(path: ':svnkit-cli')
        binaries project(path: ':svnkit-javahl16', configuration: 'archives')

        sources project(path: ':svnkit', configuration: 'sources')
        sources project(path: ':svnkit-cli', configuration: 'sources')
        sources project(path: ':svnkit-javahl16', configuration: 'sources')

        scripts project(path: ':svnkit-cli', configuration: 'scripts')

        osgi project(path: ':svnkit-osgi', configuration: 'archives')
        osgi 'com.trilead:trilead-ssh2-osgi:1.0.0-build220'
        osgi 'org.tmatesoft.sqljet:sqljet-osgi:1.1.10'
        osgi 'net.java.dev.jna:jna-osgi:4.1.0'
    }
}
task publish(dependsOn: [':svnkit-distribution:buildAll']) {
    enabled = project.hasProperty('to')
} << {
    File toDir = new File(project.properties['to'])
    delete(toDir)
    toDir.mkdirs()
    ant.unzip(src: new File(project(':svnkit-distribution').distsDir, "svnkit-${version}-all.zip"), dest: toDir.absolutePath) {
       cutdirsmapper(dirs: '1')
    }
    ant.chmod(dir: new File(toDir, 'bin').absolutePath, perm: 'ugo+rx', includes: '**/**', excludes: '**/*.bat')
}
