apply plugin: 'osgi'

configurations {
    embedOsgi
}

dependencies {
    compile project(path: ':svnkit')
    compile project(path: ':svnkit-javahl16')
    compile 'org.eclipse.core:runtime:3.2.0-v20060603'

    embedOsgi project(path: ':svnkit', transitive: false, configuration: 'jar_archive')
    embedOsgi project(path: ':svnkit-javahl16', transitive: false, configuration: 'jar_archive')
    embedOsgi 'de.regnis.q.sequence:sequence-library:1.0.3'
    embedOsgi 'com.jcraft:jsch.agentproxy.connector-factory:0.0.7'
    embedOsgi 'org.lz4:lz4-java:1.4.1'
    embedOsgi('com.jcraft:jsch.agentproxy.svnkit-trilead-ssh2:0.0.7'){
       transitive = false
    }
}

classes << {
    configurations.embedOsgi.files.each {
        f ->
        if (f.name.endsWith('.jar') || f.name.endsWith('.zip')) {
        copy {
            into 'build/classes/main'
            from zipTree(f)
            exclude 'META-INF/**'
        }
        }
    }
}

jar {
    ext {
        bundleName = rootProject.group
        bundleSymbolicName = 'SVNKit pure Java Subversion Library'
        if (rootProject.release && rootProject.buildNumber.startsWith("snapshot")) {
            bundleVersion = rootProject.version.replace('-snapshot', '.snapshot').replace('-', '.')
        } else {
            bundleVersion = rootProject.version.replace('-SNAPSHOT', '.SNAPSHOT').replace('-', '.') + (rootProject.release ? '.' : '_') + buildNumber
        }
        bundleVendor = 'TMate Software'

        println "OSGi version: ${bundleVersion}"
    }

    baseName = bundleName
    manifest {
        attributes (
        'Bundle-SymbolicName': bundleName,
        'Bundle-Version': bundleVersion,
        'Bundle-Vendor': bundleVendor,
        'Bundle-Name': bundleSymbolicName,
        'Bundle-RequiredExecutionEnvironment' : 'JavaSE-' + targetCompatibility,
        'Bundle-Activator' : 'org.tmatesoft.svn.core.SVNKitActivator',
        'Bundle-ActivationPolicy' : 'lazy',
        'Build-Version' : rootProject.version,
        'Build-Number' : rootProject.buildNumber,
        'Eclipse-BundleShape' : 'jar',
        'Require-Bundle': 'net.java.dev.jna;bundle-version="[3.2.7,4.1.0]";resolution:=optional,' +
            'com.trilead.ssh2;bundle-version="[1.0.0,2.0.0)",' +        
			'org.tmatesoft.sqljet;bundle-version="[1.0.5,2.0.0)",' +
			'org.eclipse.core.runtime;bundle-version="[3.0.0,4.0.0)"')

        instruction ('Export-Package','*;version=' + bundleVersion)
        instruction ('Import-Package', '!*')
    }
}
