Fix precise Java IC for multi-module projects
The problem may happen in case of multi-module projects: If a Java class was effectively unused in one module (A), but it's used in kt-files from the dependent module (B) then we wouldn't track the changes of the class while compiling A and don't recompile its usages in B. It happens because now we track only Java classes that were resolved by out frontend instead of all classes in the module that would be more correct but it might be rather slow. The idea is that whenever we see change in an untracked Java file we start tracking the classes in it and for the first time we mark all its content as changed.
This commit is contained in:
+21
-1
@@ -100,7 +100,27 @@ open class A {
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
val affectedSources = project.projectDir.getFilesByNames("JavaClassChild.kt", "useJavaClass.kt")
|
||||
val affectedSources = project.projectDir.getFilesByNames("JavaClassChild.kt", "useJavaClass.kt", "useJavaClassFooMethodUsage.kt")
|
||||
val relativePaths = project.relativize(affectedSources)
|
||||
assertCompiledKotlinSources(relativePaths, weakTesting = false)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testModifyTrackedJavaClassInLib() {
|
||||
val project = Project("incrementalMultiproject", GRADLE_VERSION)
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
val javaClassJava = project.projectDir.getFileByName("TrackedJavaClass.java")
|
||||
javaClassJava.modify { it.replace("String getString", "Object getString") }
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
val affectedSources = project.projectDir.getFilesByNames(
|
||||
"TrackedJavaClassChild.kt", "useTrackedJavaClass.kt", "useTrackedJavaClassSameModule.kt"
|
||||
)
|
||||
val relativePaths = project.relativize(affectedSources)
|
||||
assertCompiledKotlinSources(relativePaths, weakTesting = false)
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
class TrackedJavaClassChild : TrackedJavaClass() {}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
fun useJavaClassFooMethodUsage(jc: JavaClass) {
|
||||
jc.foo()
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
fun useTrackedJavaClass(jc: TrackedJavaClass) {
|
||||
jc.getString()
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package foo
|
||||
|
||||
import bar.*
|
||||
|
||||
fun useTrackedJavaClassFooMethodUsage(jc: TrackedJavaClass) {
|
||||
jc.foo()
|
||||
}
|
||||
+2
-1
@@ -2,4 +2,5 @@ package bar;
|
||||
|
||||
public class JavaClass {
|
||||
public String getString() { return "Hello, World!"; }
|
||||
}
|
||||
public String foo() { return ""; }
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package bar;
|
||||
|
||||
public class TrackedJavaClass {
|
||||
public String getString() { return "Hello, World!"; }
|
||||
public String foo() { return ""; }
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package bar
|
||||
|
||||
private fun useTrackedJavaClass() {
|
||||
TrackedJavaClass().getString()
|
||||
}
|
||||
Reference in New Issue
Block a user