allprojects {
  apply plugin: "idea"
  apply plugin: "eclipse"

  idea {
    module {
      outputFile = file(outputFile.path.replace(".iml", "-${variant}.iml"))
    }
  }
}

def gitIgnore = file(".gitignore").readLines()
def gitIgnoreDirs = gitIgnore*.trim().findAll { !it.startsWith("#") && it.endsWith("/") }
def (topLevelDirs, allLevelDirs) = gitIgnoreDirs.split { it.startsWith("/") }
topLevelDirs = topLevelDirs.collect { it.substring(1) }

idea {
  project {
    languageLevel = "1.6"
    vcs = "Git"
    outputFile = file(outputFile.path.replace(".ipr", "-${variant}.ipr"))
    configure(modules) { module ->
      def prj = module.project
      excludeDirs = prj.files(allLevelDirs) as Set
      if (prj == prj.rootProject) {
        excludeDirs += allLevelDirs.collect { prj.file("buildSrc/$it") }
        excludeDirs += (prj.files(topLevelDirs) as Set)
      }
    }
  }
}

ideaWorkspace {
  outputFile = file(outputFile.path.replace(".iws", "-${variant}.iws"))
}