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

plugins {
    id "com.github.hierynomus.license" version "0.14.0"
}

apply plugin: 'java'
apply plugin: 'maven-publish'

repositories {
	jcenter()
	mavenCentral()

	maven {
		url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
	}

	maven {
		url 'http://maven.sk89q.com/repo'
	}

	maven {
		url 'https://repo.destroystokyo.com/repository/maven-public//'
	}

	maven {
		url 'http://ci.emc.gs/nexus/content/groups/aikar/'
	}

	maven {
		url 'http://nexus.hc.to/content/repositories/pub_releases'
	}

	maven {
		url 'https://jitpack.io'
	}
	
	maven {
		url = "https://oss.sonatype.org/content/repositories/snapshots/"
	}
}

dependencies {
	implementation 'com.destroystokyo.paper:paper-api:1.13.1-R0.1-SNAPSHOT'
	implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0'
	implementation 'com.google.code.findbugs:findbugs:2.0.3'
	implementation 'com.sk89q:worldguard:6.1.1-SNAPSHOT'
	implementation 'net.milkbowl.vault:Vault:1.6.6'
	implementation 'com.github.marcelo-mason:PreciousStones:24e3d4bf67b7240ae36b32be10e99d4091938c5c'

	testImplementation 'junit:junit:4.12'
	testImplementation 'org.easymock:easymock:3.4'

	implementation fileTree(dir: 'lib', include: '*.jar')
}

configurations.all {
	resolutionStrategy.dependencySubstitution {
		substitute module('org.bukkit:bukkit') with module('com.destroystokyo.paper:paper-api:1.11.2-R0.1-SNAPSHOT')
	}
}

processResources {
	filter ReplaceTokens, tokens: [
		"version" :System.getenv('SKRIPT_VERSION') == null ? project.property("version") : System.getenv('SKRIPT_VERSION')
	]
}

jar {
	archiveName System.getenv('SKRIPT_JAR_NAME') == null ? 'Skript.jar' : System.getenv("SKRIPT_JAR_NAME")

	manifest {
		attributes("Name": "ch/njol/skript",
				"Sealed": "true")
	}
	
	from('skript-aliases') {
	    into('aliases-english') // Change this if we get aliases in other languages
	}
}

license {
    header file('licenseheader.txt')
    exclude('**/Metrics.java') // Not under GPLv3
    exclude('**/BurgerHelper.java') // Not exclusively GPLv3
    exclude('**/*.sk') // Sample scripts and maybe aliases
    exclude('**/*.lang') // Language files
}

configurations {
	ecj
}

dependencies {
	ecj 'org.eclipse.jdt:ecj:3.13.100'
}

sourceCompatibility = 1.8
compileJava {
	options.fork = true
	options.encoding = 'UTF-8'
	options.compilerArgs = ['-properties', '.settings/org.eclipse.jdt.core.prefs', '-encoding', 'UTF-8']
	options.forkOptions.with {
		executable = 'java'
		jvmArgs = ['-classpath', project.configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main']
	}
}

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

publishing {
	publications {
		mavenJava(MavenPublication) {
			groupId "ch.njol"
			artifactId "skript"
			version project.property("version")

			from components.java

			artifact sourceJar {
    			classifier "sources"
			}
		}
	}

	repositories {
		maven {
			url "file:///itemapi_repo/"
		}
	}
}

/*
  Set compile encoding to UTF-8
  Fixes issue #850
 */
compileJava.options.encoding = 'UTF-8'

compileTestJava.options.encoding = 'UTF-8'
