apply plugin: 'java'

configurations {
    bundlor
}

dependencies {
    bundlor 'com.springsource.bundlor:com.springsource.bundlor.ant:1.0.0.RELEASE',
            'com.springsource.bundlor:com.springsource.bundlor:1.0.0.RELEASE',
            'com.springsource.bundlor:com.springsource.bundlor.blint:1.0.0.RELEASE'
}

task bundlor(dependsOn: compileJava) {
    def template = new File(projectDir, 'template.mf')
    def bundlorDir = new File("${project.buildDir}/bundlor")
    def manifest = file("${bundlorDir}/META-INF/MANIFEST.MF")

    outputs.dir bundlorDir
    outputs.files manifest
    inputs.files template, project.sourceSets.main.runtimeClasspath

    jar.manifest.from manifest
    jar.inputs.files manifest

    doFirst {
        ant.taskdef(resource: 'com/springsource/bundlor/ant/antlib.xml', classpath: configurations.bundlor.asPath)
        logging.captureStandardOutput(LogLevel.INFO)

        mkdir(bundlorDir)

        ant.bundlor(inputPath: sourceSets.main.classesDir, outputPath: "$buildDir/bundlor", manifestTemplatePath: template) {
            property(name: 'version', value: project.version)
            property(name: 'spring.version', value: project.springVersion)
        }
    }
}

jar.dependsOn bundlor
