Skip to content

Commit 0cf1c8d

Browse files
committed
Workaround for building against jars from both JDK 6 and JDK 8 on TeamCity
1 parent 598f48a commit 0cf1c8d

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2010-2016 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jetbrains.kotlin.jps
18+
19+
import org.jetbrains.jps.cmdline.ClasspathBootstrap
20+
import java.lang.reflect.Field
21+
import java.lang.reflect.Modifier
22+
23+
fun disableJava6FileManager() {
24+
val fileManagerClass = ClasspathBootstrap.getOptimizedFileManagerClass()
25+
if (fileManagerClass?.simpleName == "OptimizedFileManager") {
26+
// JPS tests depends on idea.jar and can't be executed under Java 1.6 anymore. But currently TeamCity merges classpath from all
27+
// dependencies in a one big mess with no differences between JDK and non-JDK jars. Such behaviour causes both
28+
// JDK 8 and JDK 6 classes present in classpath. Next there's ClasspathBootstrap.OptimizedFileManagerClassHolder in idea
29+
// that works through reflection and tries to choose correct FileManager that are not the same in JDK 6 and JDK 8. Choosing
30+
// FileManager for JDK 6 leads to exceptions on Runtime as classes from JDK 8 goes first on teamcity.
31+
//
32+
// Here we disable JDK 6 FileManager with brute force.
33+
val clazz = Class.forName("org.jetbrains.jps.cmdline.ClasspathBootstrap\$OptimizedFileManagerClassHolder")
34+
setFinalStaticToNull(clazz.getDeclaredField("managerClass"))
35+
setFinalStaticToNull(clazz.getDeclaredField("directoryCacheClearMethod"))
36+
}
37+
}
38+
39+
private fun setFinalStaticToNull(field: Field) {
40+
field.isAccessible = true;
41+
42+
val modifiersField = (Field::class.java).getDeclaredField("modifiers")
43+
modifiersField.isAccessible = true
44+
modifiersField.setInt(field, field.modifiers and Modifier.FINAL.inv())
45+
46+
field.set(null, null)
47+
}

jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.incremental.CacheVersion
4646
import org.jetbrains.kotlin.incremental.LookupSymbol
4747
import org.jetbrains.kotlin.incremental.components.LookupTracker
4848
import org.jetbrains.kotlin.incremental.testingUtils.*
49+
import org.jetbrains.kotlin.jps.disableJava6FileManager
4950
import org.jetbrains.kotlin.jps.incremental.JpsLookupStorageProvider
5051
import org.jetbrains.kotlin.jps.incremental.KotlinDataContainerTarget
5152
import org.jetbrains.kotlin.jps.incremental.getKotlinCache
@@ -65,6 +66,10 @@ abstract class AbstractIncrementalJpsTest(
6566
private val allowNoBuildLogFileInTestData: Boolean = false
6667
) : JpsBuildTestCase() {
6768
companion object {
69+
init {
70+
disableJava6FileManager()
71+
}
72+
6873
private val COMPILATION_FAILED = "COMPILATION FAILED"
6974

7075
// change to "/tmp" or anything when default is too long (for easier debugging)

jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractKotlinJpsBuildTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.jetbrains.jps.model.library.sdk.JpsSdk;
3232
import org.jetbrains.jps.model.module.JpsModule;
3333
import org.jetbrains.jps.util.JpsPathUtil;
34+
import org.jetbrains.kotlin.jps.BothJdkClasspathPatcherKt;
3435
import org.jetbrains.kotlin.utils.PathUtil;
3536

3637
import java.io.File;
@@ -40,6 +41,10 @@
4041
public abstract class AbstractKotlinJpsBuildTestCase extends JpsBuildTestCase {
4142
public static final String TEST_DATA_PATH = "jps-plugin/testData/";
4243

44+
static {
45+
BothJdkClasspathPatcherKt.disableJava6FileManager();
46+
}
47+
4348
protected File workDir;
4449

4550
@Override

0 commit comments

Comments
 (0)