project.ext {
	mainSamplesClass = 'jadx.samples.RunTests'
	samplesJadxSrcDir = "${buildDir}/samples-jadx/src"
	samplesJadxOutDir = "${buildDir}/samples-jadx/output"
}

dependencies {
	implementation(project(":jadx-cli"))
}

compileJava {
	options.compilerArgs << '-g:none'
	if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
		options.compilerArgs.addAll('--release 8'.split(' '))
	}
}

task samplesRun(type: JavaExec, dependsOn: compileJava) {
	classpath = sourceSets.main.output
	main = mainSamplesClass
}

task samplesJar(type: Jar, dependsOn: samplesRun) {
	archivesBaseName = 'samples'
	from sourceSets.main.output
}

task samplesJadxCreate(type: JavaExec, dependsOn: samplesJar) {
	classpath = sourceSets.main.output + configurations.runtimeClasspath
	main = project(":jadx-cli").mainClassName
	args = ['-v', '-d', samplesJadxSrcDir, samplesJar.archiveFile.get()]
}

task samplesJadxCompile(type: JavaCompile, dependsOn: samplesJadxCreate) {
	classpath = configurations.runtimeClasspath
	destinationDir = file(samplesJadxOutDir)
	source = samplesJadxSrcDir
	options.encoding = "UTF-8"
}

task samplesJadxRun(type: JavaExec, dependsOn: samplesJadxCompile) {
	classpath = files(samplesJadxOutDir)
	main = mainSamplesClass
}

task samples(dependsOn: samplesJadxRun) {
}

task cleanGeneratedFiles(type: Delete) {
	delete samplesJadxSrcDir
	delete samplesJadxOutDir
}

clean.dependsOn cleanGeneratedFiles
