buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'gradle.plugin.net.minecrell:gitpatcher:0.9.0'
    }
}
subprojects {
    apply plugin: 'net.minecrell.gitpatcher'

    patches {
        def name = project.name
        root = rootProject.file('../..')
        submodule = "gradle/reprod/upstream/$name"
        target = rootProject.file("deps/$name")
        patches = rootProject.file("patches/$name")
    }

    task build(type: Exec) {
        dependsOn applyPatches
        if (project.name == 'forgegradle-1.2') {
            dependsOn ':srg2source-3.2:build'
        }
        if (project.name == 'forgegradle-2.3') {
            dependsOn ':forgeflower:build'
        }
        onlyIf {
            !rootProject.file('deps/repo/' + [
                    'mixin': 'org/spongepowered/mixin/0.7.5-SNAPSHOT',
                    'forgeflower': 'net/minecraftforge/forgeflower/1.0.342-SNAPSHOT',
                    'srg2source-3.2': 'net/minecraftforge/srg2source/Srg2Source/3.2-SNAPSHOT',
                    'forgegradle-1.2': 'net/minecraftforge/gradle/ForgeGradle/1.2-SNAPSHOT',
                    'forgegradle-2.1': 'net/minecraftforge/gradle/ForgeGradle/2.1-SNAPSHOT',
                    'forgegradle-2.2': 'net/minecraftforge/gradle/ForgeGradle/2.2-SNAPSHOT',
                    'forgegradle-2.3': 'net/minecraftforge/gradle/ForgeGradle/2.3-SNAPSHOT',
            ][project.name]).exists()
        }
        workingDir patches.target
        executable rootProject.file('../../gradlew').absolutePath
        args System.getenv('PROXY_SETTINGS').tokenize(' ')
        args '-I', rootProject.file('init.gradle').absolutePath
        args 'uploadArchives'
        args '-x', 'test', '-x', 'javadoc'
    }
}
