buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "https://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath ('com.anatawa12.forge:ForgeGradle:1.2-1.0.+') {
            changing = true
        }
    }
}

repositories {
    maven {
        url = "https://maven.tilera.xyz/"
    }
    maven {
        name = "ChickenBones"
        url = "http://chickenbones.net/maven"
    }
    maven {
		name = "ic2"
		url = "http://maven.ic2.player.to/"
        metadataSources {
            artifact()
        }
	}
    maven {
        url = "https://maven.thorfusion.com/artifactory/central/"
        metadataSources {
            artifact()
        }
    }
    maven {
        url = "https://s3.tilera.xyz/cdn/minecraft/libs/"
        metadataSources {
            artifact()
        }
    }
    ivy {
        url "https://ci.rs485.network/job/LogisticsPipes-0.9-mc17-bc7"
        layout "pattern", {
            artifact "[revision]/artifact/build/libs/[artifact]-0.9.3.[revision](-[classifier]).[ext]"
        }
        metadataSources {
            artifact()
        }
    }
}

apply plugin: 'forge'
apply plugin: 'curseforge'

sourceCompatibility = 1.8
targetCompatibility = 1.8

// define the properties file
ext.configFile = file "project.properties"

configFile.withReader {
    // read config.  it shall from now on be referenced as simply config or as project.config
    def prop = new Properties()
    prop.load(it)
    project.ext.config = new ConfigSlurper().parse prop
}

def buildnumber = System.getenv("BUILD_NUMBER")
def travisbuildnumber = (System.getenv("TRAVIS_BUILD_NUMBER") ?: -111).toInteger() + 111
version = "${config.minecraft_version}-${config.mod_version}." + (buildnumber ?: travisbuildnumber)
group= "${config.group_id}" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "${config.mod_id}"
def numina_version = (System.getenv("NUMINA_VERSION") ?:"0.4.1.105")

minecraft {
    version = "${config.minecraft_version}-${config.forge_version}"
    replace "@numina_version@", numina_version
    replace "@VERSION@", project.version
    runDir = "run"
}

dependencies {
    implementation 'codechicken:CodeChickenCore:1.7.10-1.0.7.47:dev'
    implementation 'codechicken:NotEnoughItems:1.7.10-1.0.5.120:dev'
    implementation 'codechicken:CodeChickenLib:1.7.10-1.1.3.140:dev'
    implementation "codechicken:ForgeMultipart:1.7.10-1.2.0.347:dev"
    implementation "universalelectricity:universalelectricity:5.1.0:deobf"
    implementation 'net.industrial-craft:industrialcraft-2:2.2.826-experimental:api'
    implementation 'thaumcraft:Thaumcraft:1.7.10-4.2.3.5:deobf'
    implementation 'logisticspipes:logisticspipes:128:dev'
    implementation 'appeng:appliedenergistics2:rv3-beta-23:dev'
    implementation 'mekanism:Mekanism:1.7.10-9.13.1:deobf'
    implementation 'buildcraft:buildcraft:7.1.25:dev'
    implementation 'cofh:CoFHCore:[1.7.10]3.1.4-329:dev'
    implementation 'cofh:ThermalFoundation:[1.7.10]1.2.6-118:dev'
    implementation 'cofh:ThermalExpansion:[1.7.10]4.1.5-248:dev'
    implementation 'ender:EnderCore:1.7.10-0.2.0.39_beta:dev'
    implementation 'ender:EnderIO:1.7.10-2.3.0.429_beta:dev'
    implementation 'chisel:Chisel:2.9.5.11:deobf'
    implementation 'mods:ExtraCells:1.7.10-2.3.14b197:deobf'
    implementation 'mods:MineFactoryReloaded:[1.7.10]2.8.0-104:dev'
    implementation 'mods:Numina:0.4.1.106'
    implementation 'mods:PlayerAPI:1.7.10-1.4'
    implementation 'mods:RenderPlayerAPI:1.7.10-1.4'
    implementation 'mods:SmartRender:1.7.10-2.1'
    implementation 'mods:forestry_1.7.10:4.2.16.64'
    implementation 'mods:Railcraft_1.7.10:9.12.2.0'
    implementation 'mods:BluePower:1.7.10-0.2.962:universal'
    implementation 'mods:QmunityLib:1.7.10-0.1.114:universal'
    implementation 'mods:MrTJPCore:1.1.0.31:universal'
    implementation 'mods:ProjectRed:1.7.10-4.7.0pre8.92:Base'
}

processResources {
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    filesMatching('mcmod.info') {
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
}

jar {
    manifest {
        attributes 'FMLAT': 'numina_at.cfg'
    }
}

task devJar(type: Jar) {
    from sourceSets.main.output
    classifier = 'dev'
}

task copyToLib(type: Copy) {
    into "$buildDir/libs"
    from(sourceSets.main.resources.srcDirs){
        include 'mps-vanilla.recipes'
        include 'mps-thermalexpansion.recipes'
        include 'mps-ic2.recipes'
        include 'mps-enderio.recipes'
    }
}

def getGitChangelog = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        def gitHash = System.getenv("GIT_COMMIT")
        def gitPrevHash = System.getenv("GIT_PREVIOUS_COMMIT")
        if(gitHash && gitPrevHash) {
            exec {
                commandLine 'git', 'log', '--pretty=tformat:%s - %aN', '' + gitPrevHash + '...' + gitHash
                standardOutput = stdout
            }
            return stdout.toString().trim()
        } else {
            return "";
        }
    } catch(ignored) {
        return "";
    }
}


build.dependsOn(copyToLib)

artifacts {
    archives devJar
}

curse {
    projectId = '235442'
    apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
    def branch = System.getenv("GIT_BRANCH")
    if(branch == null) {
        releaseType = 'alpha'
    } else if(branch.equals("origin/experimental")) {
        releaseType = 'beta'
    } else if(branch.equals("origin/master")) {
        releaseType = 'release'
    } else {
        releaseType = 'alpha'
    }

    changelog = getGitChangelog()

    addGameVersion '1.7.10'

    relatedProject 'numina': 'requiredLibrary'
}

apply plugin: 'idea'
idea {
    module {
        inheritOutputDirs = true
    }
}
