buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
    }
}

apply plugin: 'forge'
apply plugin: 'scala'
apply plugin: 'maven-publish'

file "build.properties" withReader {
    def prop = new Properties()
    prop.load(it)
    ext.config = new ConfigSlurper().parse prop
}

version = "${config.oc.version}"
group = "li.cil.oc"
archivesBaseName = "OpenComputers"

if (System.getenv("BUILD_NUMBER") != null)
    version += ".${System.getenv("BUILD_NUMBER")}"

if (config.oc.subversion != null && config.oc.subversion != "")
    version += "-${config.oc.subversion}"

ext.simpleVersion = version
version = "MC${config.minecraft.version}-${project.version}"

repositories {
    ivy {
        name "minecraftforge"
        artifactPattern "http://files.minecraftforge.net/[module]/[module]-dev-[revision].[ext]"
    }
    maven {
        name = "chickenbones"
        url = "http://chickenbones.net/maven/"
    }
}

// From http://stackoverflow.com/questions/10405970/how-do-i-define-a-compile-time-only-classpath-in-gradle
configurations {
  provided
}

dependencies {
    provided "codechicken:CodeChickenLib:${config.minecraft.version}-${config.ccl.version}:dev"
    provided "codechicken:ForgeMultipart:${config.minecraft.version}-${config.fmp.version}:dev"
    provided "codechicken:NotEnoughItems:${config.minecraft.version}-${config.nei.version}:dev"
    provided "codechicken:WR-CBE:${config.minecraft.version}-${config.wrcbe.version}:dev"
}

sourceSets.main.compileClasspath += configurations.provided
idea.module.scopes.PROVIDED.plus += configurations.provided
eclipse.classpath.plusConfigurations += configurations.provided

minecraft {
    version = "${config.minecraft.version}-${config.forge.version}"

    replaceIn "li/cil/oc/OpenComputers.scala"
    replace "@VERSION@", project.simpleVersion
}

processResources {
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
        expand 'version': project.simpleVersion, 'mcversion': config.minecraft.version
    }
    from(sourceSets.main.resources.srcDirs) {
        include 'application.conf'
        filter { line ->
            line.replaceAll("@VERSION@", project.simpleVersion)
        }
    }
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
        exclude 'application.conf'
    }
}

jar {
    classifier = 'universal'
    manifest {
        attributes FMLCorePlugin: "li.cil.oc.common.launch.TransformerLoader"
        attributes FMLCorePluginContainsFMLMod: "true"
    }
}

javadoc {
    include 'li/cil/oc/api/**'
}

// because the normal default jar task has been modified to be obfuscated
task deobfJar(type: Jar) {
    from sourceSets.main.output
    classifier = 'deobf'
    manifest {
        attributes FMLCorePlugin: "li.cil.oc.common.launch.TransformerLoader"
        attributes FMLCorePluginContainsFMLMod: "true"
    }
}

task apiJar(type: Jar) {
    from sourceSets.main.output
    from sourceSets.main.java
    classifier = 'api'
    include 'li/cil/oc/api/**'
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    from 'build/docs/javadoc'
    classifier 'javadoc'
}

artifacts {
    archives deobfJar
    archives apiJar
    archives javadocJar
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact jar
            artifact apiJar
            artifact javadocJar
            artifact deobfJar { classifier 'dev' }
        }
    }
    repositories {
        maven {
            url "${config.maven.url}"
        }
    }
}
