transition to Java 8: some test modules configured to use JDK 8, build scripts updated
authornik <Nikolay.Chashnikov@jetbrains.com>
Tue, 26 May 2015 09:30:15 +0000 (12:30 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Tue, 26 May 2015 09:30:42 +0000 (12:30 +0300)
.idea/compiler.xml
README.md
build/build.iml
build/scripts/common_tests.gant
build/scripts/utils.gant
community-main.iml
json/tests/json-tests.iml

index 8cff9d767a6f4e5e09d71b800797e48fcf83ed42..34b6271646290bb418c3ea8c0cf2a5f19e9dee46 100644 (file)
@@ -44,6 +44,7 @@
       <module name="jps-model-impl" target="1.6" />
       <module name="jps-model-serialization" target="1.6" />
       <module name="jps-standalone-builder" target="1.6" />
+      <module name="json-tests" target="1.8"/>
       <module name="junit_rt" target="1.3" />
       <module name="maven-jps-plugin" target="1.6" />
       <module name="remote-servers-agent-rt" target="1.5" />
index 5d4abee4d3c7f214bcb073381f7d07887ba87990..04ae48984b4de85a6f1ea94480dc04556a04f467 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,9 +4,11 @@ To develop IntelliJ IDEA, you can use either IntelliJ IDEA Community Edition or
 * Run **getPlugins.sh** / **getPlugins.bat** from the project root directory to check out additional modules.
 * Make sure you have the **Groovy** plugin enabled. Parts of IntelliJ IDEA are written in Groovy, and you will get compilation errors if you don't have the plugin enabled.
 * Make sure you have the **UI Designer** plugin enabled. Most of IntelliJ IDEA's UI is built using the **UI Designer**, and the version you build will not run correctly if you don't have the plugin enabled.
-* Open the project
-* Configure a JSDK named "**IDEA jdk**" (case sensitive), pointing to an installation of JDK 1.6
+* Open the project.
+* Configure a JSDK named "**IDEA jdk**" (case sensitive), pointing to an installation of JDK 1.6.
 * Unless you're running on a Mac with an Apple JDK, add <JDK_HOME>/lib/tools.jar to the set of "**IDEA jdk**" jars.
+* Configure a JSDK named "**1.8**", pointing to an installation of JDK 1.8.
+* Add <JDK_18_HOME>/lib/tools.jar to the set of "**1.8**" jars.
 * Use Build | Make Project to build the code.
 * To run the code, use the provided shared run configuration "**IDEA**".
 
index 56fe67fc3588e376f29c02029ec136f68aa6c928..63461f0cceb6f43a5a9218f2c9789676c21054c1 100644 (file)
@@ -7,7 +7,7 @@
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
       <excludeFolder url="file://$MODULE_DIR$/restApiDocGenerator/node_modules" />
     </content>
-    <orderEntry type="inheritedJdk" />
+    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="library" exported="" name="Groovy" level="project" />
     <orderEntry type="library" exported="" name="Ant" level="project" />
index 1512bf21f679b01fb940f05101e695899bb87747..3d91ccc09aa4b63f3940e2b8dd3e08dbadb42c06 100644 (file)
@@ -45,9 +45,16 @@ target('run_tests': 'Run java tests') {
   depends([compile])
 
   def classpathFile = "$home/junit.classpath"
-  List<String> testRuntimeClasspath = projectBuilder.moduleRuntimeClasspath(findModule("community-main"), true)
+  //todo[nik] currently runtime classpath includes path to JDKs from all modules in it so we need to manually exclude paths from JDK 1.6
+  List<String> testRuntimeClasspath = removeJdkJarFiles(projectBuilder.moduleRuntimeClasspath(findModule("community-main"), true))
+  testRuntimeClasspath << "${jdk8Home}/lib/tools.jar"
+  projectBuilder.info("Test runtime classpath=" + testRuntimeClasspath)
   new File(classpathFile).text = testRuntimeClasspath.findAll({ new File((String)it).exists() }).join('\n')
 
+  List<String> bootstrapClasspath = removeJdkJarFiles(projectBuilder.moduleRuntimeClasspath(findModule("tests_bootstrap"), false))
+  bootstrapClasspath << "${jdk8Home}/lib/tools.jar"
+  projectBuilder.info("Bootstrap classpath=" + bootstrapClasspath)
+
   testcases.each { testCase ->
     List<String> jvmArgs = [
       "-Dclasspath.file=${classpathFile}",
@@ -82,10 +89,9 @@ target('run_tests': 'Run java tests') {
       }
 
       classpath {
-        projectBuilder.moduleRuntimeClasspath(findModule("tests_bootstrap"), false).each {
+        bootstrapClasspath.each {
           pathelement(location: it)
         }
-        pathelement(location: "${jdkHome}/lib/tools.jar")
       }
 
       test(name: 'com.intellij.tests.BootstrapTests')
index 07d6b835268cdae3c98289649ce6bf31ccd3181f..b0ac9466ad33ccdf4266e7247572bc588238c0c5 100644 (file)
  * limitations under the License.
  */
 
-
+import com.intellij.openapi.util.SystemInfo
 import com.intellij.openapi.util.io.FileUtil
 import org.jetbrains.jps.gant.JpsGantTool
 import org.jetbrains.jps.gant.TeamCityBuildInfoPrinter
 import org.jetbrains.jps.model.java.JavaSourceRootType
+import org.jetbrains.jps.model.java.JdkVersionDetector
 import org.jetbrains.jps.model.java.JpsJavaExtensionService
+import org.jetbrains.jps.model.java.JpsJavaSdkType
+import org.jetbrains.jps.model.library.JpsOrderRootType
 import org.jetbrains.jps.model.module.JpsModule
 
 includeTool << JpsGantTool
@@ -129,13 +132,8 @@ binding.setVariable("guessHome", {
 })
 
 binding.setVariable("loadProject", {
-  requireProperty("jdkHome", guessJdk())
-  def mac = isMac()
-  jdk("IDEA jdk", jdkHome) {
-    if (!mac) {
-      classpath "$jdkHome/lib/tools.jar"
-    }
-  }
+  defineJdk("IDEA jdk", setupJdkPath("jdkHome", "$home/build/jdk/1.6", "JDK_16_x64"))
+  defineJdk("1.8", setupJdkPath("jdk8Home", "$home/build/jdk/1.8", "JDK_18_x64"))
   projectBuilder.buildIncrementally = Boolean.parseBoolean(p("jps.build.incrementally", "false"))
   def dataDirName = projectBuilder.buildIncrementally ? ".jps-incremental-build" : ".jps-build-data"
   projectBuilder.dataStorageRoot = new File("$home/$dataDirName")
@@ -149,6 +147,68 @@ binding.setVariable("loadProject", {
   compilerOptions.ADDITIONAL_OPTIONS_STRING = compilerOptions.ADDITIONAL_OPTIONS_STRING.replace("-Xlint:unchecked", "")
 })
 
+binding.setVariable("removeJdkJarFiles", { Collection<String> classpath ->
+  def jdkHomePaths = project.model.global.libraryCollection.getLibraries(JpsJavaSdkType.INSTANCE).collect {
+    def homeDir = new File(it.properties.homePath)
+    return SystemInfo.isMac && homeDir.name == "Home" ? homeDir.parent : homeDir.absolutePath
+  }
+  return classpath.findAll { jarPath -> jdkHomePaths.every { !FileUtil.isAncestor(it, jarPath, false) } }
+})
+
+private String setupJdkPath(String propertyName, String defaultDir, String envVarName) {
+  try {
+    this[propertyName]
+  }
+  catch (MissingPropertyException ignored) {
+    def jdk = SystemInfo.isMac ? "$defaultDir/Home" : defaultDir
+    if (new File(jdk).exists()) {
+      projectBuilder.info("$propertyName set to $jdk")
+    }
+    else {
+      jdk = System.getenv(envVarName)
+      if (jdk != null) {
+        projectBuilder.info("'$defaultDir' doesn't exist, $propertyName set to '$envVarName' environment variable: $jdk")
+      }
+      else {
+        jdk = guessJdk()
+        def version = JdkVersionDetector.instance.detectJdkVersion(jdk)
+        if (propertyName.contains("8") && !version.contains("1.8.")) {
+          projectBuilder.error("JDK 1.8 is required to compile the project, but '$propertyName' property and '$envVarName' environment variable aren't defined and default JDK $jdk ($version) cannot be used as JDK 1.8")
+          return null
+        }
+        projectBuilder.info("'$envVarName' isn't defined and '$defaultDir' doesn't exist, $propertyName set to $jdk")
+      }
+    }
+    this[propertyName] = jdk
+    return jdk
+  }
+}
+
+private void defineJdk(String jdkName, jdkHomePath) {
+  jdk(jdkName, jdkHomePath) {
+    def toolsJar = "$jdkHomePath/lib/tools.jar"
+    if (new File(toolsJar).exists()) {
+      classpath toolsJar
+    }
+  }
+
+  if (SystemInfo.isMac) {
+    //temporary workaround for Mac: resolve symlinks manually. Previously ZipFileCache used FileUtil.toCanonicalPath method which doesn't resolve symlinks.
+    def jdk = global.libraryCollection.findLibrary(jdkName, JpsJavaSdkType.INSTANCE)
+    def jdkClasspath = jdk.getFiles(JpsOrderRootType.COMPILED)
+    def urls = jdk.getRootUrls(JpsOrderRootType.COMPILED)
+    urls.each { jdk.removeUrl(it, JpsOrderRootType.COMPILED) }
+    jdkClasspath.each {
+      try {
+        jdk.addRoot(it.getCanonicalFile(), JpsOrderRootType.COMPILED)
+      }
+      catch (IOException ignored) {
+      }
+    }
+    projectBuilder.info("JDK '$jdkName' classpath: ${jdk.getFiles(JpsOrderRootType.COMPILED)}")
+  }
+}
+
 binding.setVariable("prepareOutputFolder", {
   def targetFolder = projectBuilder.buildIncrementally ? "$home/out/incremental-build" : out
   projectBuilder.targetFolder = targetFolder
@@ -210,7 +270,7 @@ binding.setVariable("notifyArtifactBuilt", { String artifactPath ->
 })
 
 def debugPort = System.getProperty("debug.port")
-def debugSuspend = System.getProperty("debug.suspend") ?: "n"
+def debugSuspend = System.getProperty("") ?: "n"
 if (debugSuspend == 'y') {
   println """
 
index eff249add93bb6ad569409847dcd31f3fc48c825..314b308718841770063bf3115d833b8368e938b9 100644 (file)
@@ -3,7 +3,7 @@
   <component name="NewModuleRootManager" inherit-compiler-output="true">
     <exclude-output />
     <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
+    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="module" module-name="annotations" />
     <orderEntry type="module" module-name="ant" />
index 06d046d470ac4bb505a03acbdef6ccfd7070026a..758d0ef87cd30a1c01c60a939f78f87b33e4d629 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" inherit-compiler-output="true">
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
     <exclude-output />
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/testData" type="java-test-resource" />
     </content>
-    <orderEntry type="inheritedJdk" />
+    <orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="module" module-name="testFramework" scope="TEST" />
     <orderEntry type="module" module-name="json" scope="TEST" />