ext.globalDist = rootDir.path + '/DIST'

task gitinfoDist(type: Copy) {
    from(globalBin) {
        include('gitinfo.txt')
    }
    from(globalBin + '/resources') {
        include('gitinfo.properties')
    }
    into(globalDist)

    for (p in subprojects) {
        dependsOn p.tasks.getByPath("build")
    }
}

task historyDist(type:Copy) {
	from(rootDir.path + '/freeplane/doc/'){
		include 'history_en.txt'
	}
	into(globalDist)
}

apply from: './bin.dist.gradle'
apply from: './win.dist.gradle'
apply from: './mac.dist.gradle'
apply from: './src.dist.gradle'
apply from: './linux-packages.gradle'

// meta task
task dist {
    dependsOn binZip
    dependsOn srcTarGz
    dependsOn srcpureTarGz
    dependsOn windowsInstaller
    dependsOn windowsPortableInstaller
    dependsOn gitinfoDist
    dependsOn historyDist
    dependsOn freeplaneDeb
}

// clean
task cleanDist(type: Delete) {
    delete globalDist
}
clean.dependsOn cleanDist

task createGitTag(type: Exec) {
	def tag = "${versionStatus.empty ? 'release':versionStatus}-$majorVersion${minorVersion.empty ? '':'-pre'+minorVersion}"
    ignoreExitValue = true
	doFirst {
		println "> Press enter to create tag $tag"
		System.in.newReader().readLine()
	}
    commandLine 'git', 'tag', tag
}

task release {
	dependsOn (clean, dist, createGitTag)
}
dist.mustRunAfter clean
createGitTag.mustRunAfter dist
