apply from: "$rootDir/gradle/instrumentation.gradle"

muzzle {
  pass {
    coreJdk()
  }
}

task "rmic", dependsOn: testClasses {
  def clazz = 'rmi.app.ServerLegacy'

  // Try one level up too in case java.home refers to jre directory inside jdk directory
  def rmicBinaryPath = ['/bin/rmic', '/../bin/rmic'].findResult {
    def path = new File(System.getProperty("java.home"), it).getAbsoluteFile()
    path.isFile() ? path.toString() : null
  } ?: "rmic"

  String command = """$rmicBinaryPath -g -keep -classpath ${sourceSets.test.output.classesDirs.asPath} -d ${buildDir}/classes/java/test ${clazz}"""
  command.execute().text
}

test.dependsOn "rmic"

// We cannot use "--release" javac option here because that will forbid importing "sun.rmi" package.
// We also can't seem to use the toolchain without the "--release" option. So disable everything.

java {
  toolchain {
    languageVersion = null
  }
}

tasks.withType(JavaCompile) {
  options.release = null
}
tasks.withType(GroovyCompile) {
  options.release = null
}
