import org.apache.tools.ant.filters.ReplaceTokens

// --------------- Plugins ---------------

plugins {
	id 'application'
}

// --------------- Info ---------------

version = getTagVersion('compiler/')
description = 'The Dyvil Compiler'

mainClassName = 'dyvilx.tools.compiler.Main'

// --------------- Dependencies ---------------

dependencies {
	implementation libraryDependency

	// https://mvnrepository.com/artifact/commons-cli/commons-cli
	compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
}

// --------------- Source Copying ---------------

tasks.register('copyJava', Copy) {
	it.from sourceSets.main.java
	it.into "$buildDir/src/main/java/"

	it.include '**/DyvilCompiler.java'
	it.includeEmptyDirs = false

	it.filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: [
			version        : rootProject.version,
			libraryVersion : project(':library').version,
			compilerVersion: project.version
	])
}

tasks.named('compileJava', JavaCompile) {
	it.dependsOn 'copyJava'
	it.source fileTree("$buildDir/src/main/java").builtBy('copyJava')
	it.exclude {
		final String path = it.file.path
		return path.endsWith('DyvilCompiler.java') && (path.contains('compiler/src/main/java') || path.contains('compiler\\src\\main\\java'))
	}
}
