Extracted interface and moved implementation of IncrementalCache to jps-plugin, accessing cache via Java service loader.
This commit is contained in:
Generated
+7
@@ -44,7 +44,14 @@
|
|||||||
<element id="file-copy" path="$PROJECT_DIR$/resources/manifest.properties" />
|
<element id="file-copy" path="$PROJECT_DIR$/resources/manifest.properties" />
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/dependencies/cli-parser-1.1.1.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/dependencies/cli-parser-1.1.1.jar" path-in-jar="/" />
|
||||||
<element id="module-output" name="util.runtime" />
|
<element id="module-output" name="util.runtime" />
|
||||||
|
<element id="module-output" name="cli" />
|
||||||
|
<element id="module-output" name="descriptor.loader.java" />
|
||||||
|
<element id="module-output" name="frontend.java" />
|
||||||
|
<element id="module-output" name="serialization.java" />
|
||||||
|
<element id="module-output" name="descriptors" />
|
||||||
|
<element id="library" level="project" name="kotlin-runtime" />
|
||||||
</element>
|
</element>
|
||||||
|
<element id="file-copy" path="$PROJECT_DIR$/dist/kotlinc/lib/kotlin-runtime.jar" />
|
||||||
</element>
|
</element>
|
||||||
<element id="file-copy" path="$PROJECT_DIR$/dist/kotlinc/lib/kotlin-runtime.jar" />
|
<element id="file-copy" path="$PROJECT_DIR$/dist/kotlinc/lib/kotlin-runtime.jar" />
|
||||||
</element>
|
</element>
|
||||||
|
|||||||
+5
-3
@@ -51,7 +51,7 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
|||||||
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCache;
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCacheProvider;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.plugin.MainFunctionDetector;
|
import org.jetbrains.jet.plugin.MainFunctionDetector;
|
||||||
import org.jetbrains.jet.utils.KotlinPaths;
|
import org.jetbrains.jet.utils.KotlinPaths;
|
||||||
@@ -327,10 +327,12 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
) {
|
) {
|
||||||
CompilerConfiguration configuration = environment.getConfiguration();
|
CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
File incrementalCacheDir = configuration.get(JVMConfigurationKeys.INCREMENTAL_CACHE_BASE_DIR);
|
File incrementalCacheDir = configuration.get(JVMConfigurationKeys.INCREMENTAL_CACHE_BASE_DIR);
|
||||||
|
IncrementalCacheProvider incrementalCacheProvider = IncrementalCacheProvider.object$.getInstance();
|
||||||
|
|
||||||
Collection<FqName> packagesWithRemovedFiles =
|
Collection<FqName> packagesWithRemovedFiles =
|
||||||
incrementalCacheDir == null || moduleId == null
|
incrementalCacheDir == null || moduleId == null || incrementalCacheProvider == null
|
||||||
? null
|
? null
|
||||||
: new IncrementalCache(incrementalCacheDir).getPackagesWithRemovedFiles(moduleId, environment.getSourceFiles());
|
: incrementalCacheProvider.getIncrementalCache(incrementalCacheDir).getPackagesWithRemovedFiles(moduleId, environment.getSourceFiles());
|
||||||
GenerationState generationState = new GenerationState(
|
GenerationState generationState = new GenerationState(
|
||||||
environment.getProject(), ClassBuilderFactories.BINARIES, Progress.DEAF,
|
environment.getProject(), ClassBuilderFactories.BINARIES, Progress.DEAF,
|
||||||
exhaust.getModuleDescriptor(), exhaust.getBindingContext(), sourceFiles,
|
exhaust.getModuleDescriptor(), exhaust.getBindingContext(), sourceFiles,
|
||||||
|
|||||||
+5
-2
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.ImportPath;
|
|||||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCache;
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCache;
|
||||||
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCacheProvider;
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalPackageFragmentProvider;
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalPackageFragmentProvider;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||||
@@ -145,13 +146,15 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
try {
|
try {
|
||||||
module.addFragmentProvider(DependencyKind.BINARIES, injector.getJavaDescriptorResolver().getPackageFragmentProvider());
|
module.addFragmentProvider(DependencyKind.BINARIES, injector.getJavaDescriptorResolver().getPackageFragmentProvider());
|
||||||
|
|
||||||
if (incrementalCacheDir != null && moduleIds != null) {
|
IncrementalCacheProvider incrementalCacheProvider = IncrementalCacheProvider.object$.getInstance();
|
||||||
|
if (incrementalCacheDir != null && moduleIds != null && incrementalCacheProvider != null) {
|
||||||
|
IncrementalCache incrementalCache = incrementalCacheProvider.getIncrementalCache(incrementalCacheDir);
|
||||||
for (String moduleId : moduleIds) {
|
for (String moduleId : moduleIds) {
|
||||||
module.addFragmentProvider(
|
module.addFragmentProvider(
|
||||||
DependencyKind.SOURCES,
|
DependencyKind.SOURCES,
|
||||||
new IncrementalPackageFragmentProvider(
|
new IncrementalPackageFragmentProvider(
|
||||||
files, module, globalContext.getStorageManager(), injector.getDescriptorDeserializers(),
|
files, module, globalContext.getStorageManager(), injector.getDescriptorDeserializers(),
|
||||||
new IncrementalCache(incrementalCacheDir), moduleId, injector.getJavaDescriptorResolver()
|
incrementalCache, moduleId, injector.getJavaDescriptorResolver()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-195
@@ -16,205 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.kotlin.incremental
|
package org.jetbrains.jet.lang.resolve.kotlin.incremental
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import com.intellij.util.io.PersistentMap
|
|
||||||
import com.intellij.util.io.PersistentHashMap
|
|
||||||
import com.intellij.util.io.KeyDescriptor
|
|
||||||
import java.io.DataOutput
|
|
||||||
import com.intellij.util.io.IOUtil
|
|
||||||
import java.io.DataInput
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
import com.intellij.util.io.DataExternalizer
|
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass
|
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
|
||||||
import org.jetbrains.jet.descriptors.serialization.BitEncoding
|
|
||||||
import org.jetbrains.jet.utils.intellij.*
|
|
||||||
import java.util.Arrays
|
|
||||||
import com.intellij.util.io.IntInlineKeyDescriptor
|
|
||||||
import org.jetbrains.org.objectweb.asm.*
|
|
||||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName
|
||||||
import java.util.TreeMap
|
|
||||||
import java.util.HashSet
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
import java.util.HashMap
|
|
||||||
|
|
||||||
public class IncrementalCache(baseDir: File) {
|
public trait IncrementalCache {
|
||||||
class object {
|
public fun getPackagesWithRemovedFiles(moduleId: String, compiledSourceFiles: Collection<JetFile>): Collection<FqName>
|
||||||
val PROTO_MAP = "proto.tab"
|
|
||||||
val CONSTANTS_MAP = "constants.tab"
|
|
||||||
val PACKAGE_SOURCES = "package-sources.tab"
|
|
||||||
|
|
||||||
private fun getConstantsHash(bytes: ByteArray): Int {
|
public fun getRemovedPackageParts(moduleId: String, compiledSourceFiles: Collection<JetFile>): Collection<JvmClassName>
|
||||||
val result = TreeMap<String, Any>() // keys order should defined to check hash of a map
|
|
||||||
|
|
||||||
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.ASM5) {
|
public fun getPackageData(moduleId: String, fqName: FqName): ByteArray?
|
||||||
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
|
|
||||||
if (value != null) {
|
|
||||||
result[name] = value
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}, ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES)
|
|
||||||
|
|
||||||
return result.hashCode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val protoData: PersistentMap<ClassOrPackageId, ByteArray>
|
|
||||||
private val constantsData: PersistentHashMap<String, Int>
|
|
||||||
= PersistentHashMap(File(baseDir, CONSTANTS_MAP), EnumeratorStringDescriptor(), IntInlineKeyDescriptor())
|
|
||||||
|
|
||||||
// Format of serialization to string: <module id> <path separator> <source file path> --> <package part JVM internal name>
|
|
||||||
private val packageSourcesData: PersistentHashMap<String, String>
|
|
||||||
= PersistentHashMap(File(baseDir, PACKAGE_SOURCES), EnumeratorStringDescriptor(), EnumeratorStringDescriptor())
|
|
||||||
|
|
||||||
;{
|
|
||||||
protoData = PersistentHashMap(File(baseDir, PROTO_MAP), object : KeyDescriptor<ClassOrPackageId> {
|
|
||||||
override fun save(out: DataOutput, value: ClassOrPackageId?) {
|
|
||||||
IOUtil.writeString(value!!.moduleId, out)
|
|
||||||
IOUtil.writeString(value.fqName.asString(), out)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun read(`in`: DataInput): ClassOrPackageId {
|
|
||||||
val module = IOUtil.readString(`in`)!!
|
|
||||||
val fqName = FqName(IOUtil.readString(`in`)!!)
|
|
||||||
return ClassOrPackageId(module, fqName)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getHashCode(value: ClassOrPackageId?): Int {
|
|
||||||
return value?.hashCode() ?: -1
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isEqual(val1: ClassOrPackageId?, val2: ClassOrPackageId?): Boolean {
|
|
||||||
return val1 == val2
|
|
||||||
}
|
|
||||||
}, object : DataExternalizer<ByteArray> {
|
|
||||||
override fun save(out: DataOutput, value: ByteArray?) {
|
|
||||||
out.writeInt(value!!.size)
|
|
||||||
out.write(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun read(`in`: DataInput): ByteArray {
|
|
||||||
val length = `in`.readInt()
|
|
||||||
val buf = ByteArray(length)
|
|
||||||
`in`.readFully(buf)
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun saveFileToCache(moduleId: String, sourceFiles: Collection<File>, file: File): Boolean {
|
|
||||||
val fileBytes = file.readBytes()
|
|
||||||
val classNameAndHeader = VirtualFileKotlinClass.readClassNameAndHeader(fileBytes)
|
|
||||||
if (classNameAndHeader == null) return false
|
|
||||||
|
|
||||||
val (className, header) = classNameAndHeader
|
|
||||||
val classFqName = className.getFqNameForClassNameWithoutDollars()
|
|
||||||
val annotationDataEncoded = header.annotationData
|
|
||||||
if (annotationDataEncoded != null) {
|
|
||||||
val data = BitEncoding.decodeBytes(annotationDataEncoded)
|
|
||||||
when (header.kind) {
|
|
||||||
KotlinClassHeader.Kind.PACKAGE_FACADE -> {
|
|
||||||
return putData(moduleId, classFqName.parent(), data)
|
|
||||||
}
|
|
||||||
KotlinClassHeader.Kind.CLASS -> {
|
|
||||||
return putData(moduleId, classFqName, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (header.syntheticClassKind == JvmAnnotationNames.KotlinSyntheticClass.Kind.PACKAGE_PART) {
|
|
||||||
assert(sourceFiles.size == 1) { "Package part from several source files: $sourceFiles" }
|
|
||||||
putPackagePartSourceData(moduleId, sourceFiles.first(), className)
|
|
||||||
return putConstantsData(className, getConstantsHash(fileBytes))
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun putData(moduleId: String, fqName: FqName, data: ByteArray): Boolean {
|
|
||||||
val id = ClassOrPackageId(moduleId, fqName)
|
|
||||||
val oldData = protoData[id]
|
|
||||||
if (Arrays.equals(data, oldData)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
protoData.put(id, data)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun putConstantsData(packagePartClass: JvmClassName, constantsHash: Int): Boolean {
|
|
||||||
val key = packagePartClass.getInternalName()
|
|
||||||
|
|
||||||
val oldHash = constantsData[key]
|
|
||||||
if (oldHash == constantsHash) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
constantsData.put(key, constantsHash)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun putPackagePartSourceData(moduleId: String, sourceFile: File, className: JvmClassName?) {
|
|
||||||
val key = moduleId + File.pathSeparator + sourceFile.getAbsolutePath()
|
|
||||||
|
|
||||||
if (className != null) {
|
|
||||||
packageSourcesData.put(key, className.getInternalName())
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
packageSourcesData.remove(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun clearPackagePartSourceData(moduleId: String, sourceFile: File) {
|
|
||||||
putPackagePartSourceData(moduleId, sourceFile, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getPackagesWithRemovedFiles(moduleId: String, compiledSourceFiles: Collection<JetFile>): Collection<FqName> {
|
|
||||||
return getRemovedPackageParts(moduleId, compiledSourceFiles).map { it.getFqNameForClassNameWithoutDollars().parent() }
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getRemovedPackageParts(moduleId: String, compiledSourceFiles: Collection<JetFile>): Collection<JvmClassName> {
|
|
||||||
val sourceFileToCurrentFqNameMap = HashMap<File, FqName>()
|
|
||||||
for (sourceFile in compiledSourceFiles) {
|
|
||||||
sourceFileToCurrentFqNameMap[File(sourceFile.getVirtualFile()!!.getPath())] = sourceFile.getPackageFqName()
|
|
||||||
}
|
|
||||||
|
|
||||||
val result = HashSet<JvmClassName>()
|
|
||||||
|
|
||||||
packageSourcesData.processKeysWithExistingMapping { key ->
|
|
||||||
if (key!!.startsWith(moduleId + File.pathSeparator)) {
|
|
||||||
val indexOf = key.indexOf(File.pathSeparator)
|
|
||||||
val sourceFile = File(key.substring(indexOf + 1))
|
|
||||||
|
|
||||||
val packagePartClassName = JvmClassName.byInternalName(packageSourcesData[key]!!)
|
|
||||||
if (!sourceFile.exists()) {
|
|
||||||
result.add(packagePartClassName)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
val previousPackageFqName = packagePartClassName.getFqNameForClassNameWithoutDollars().parent()
|
|
||||||
val currentPackageFqName = sourceFileToCurrentFqNameMap[sourceFile]
|
|
||||||
if (currentPackageFqName != null && currentPackageFqName != previousPackageFqName) {
|
|
||||||
result.add(packagePartClassName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getPackageData(moduleId: String, fqName: FqName): ByteArray? {
|
|
||||||
return protoData[ClassOrPackageId(moduleId, fqName)]
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun close() {
|
|
||||||
protoData.close()
|
|
||||||
constantsData.close()
|
|
||||||
packageSourcesData.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
private data class ClassOrPackageId(val moduleId: String, val fqName: FqName) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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 org.jetbrains.jet.lang.resolve.kotlin.incremental
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.util.ServiceLoader
|
||||||
|
|
||||||
|
public trait IncrementalCacheProvider {
|
||||||
|
public fun getIncrementalCache(baseDir: File): IncrementalCache
|
||||||
|
|
||||||
|
public class object {
|
||||||
|
public fun getInstance(): IncrementalCacheProvider? {
|
||||||
|
val serviceLoader = ServiceLoader.load(javaClass<IncrementalCacheProvider>(), javaClass<IncrementalCacheProvider>().getClassLoader())
|
||||||
|
val implementations = serviceLoader.toList()
|
||||||
|
if (implementations.size > 1) {
|
||||||
|
throw IllegalStateException("More than one IncrementalCacheProvider: " + implementations)
|
||||||
|
}
|
||||||
|
return implementations.firstOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
|
|
||||||
<fileTypeFactory implementation="org.jetbrains.jet.plugin.JetFileFactory"/>
|
<fileTypeFactory implementation="org.jetbrains.jet.plugin.JetFileFactory"/>
|
||||||
|
|
||||||
<compileServer.plugin classpath="jps/kotlin-jps-plugin.jar"/>
|
<compileServer.plugin classpath="jps/kotlin-jps-plugin.jar;jps/kotlin-runtime.jar"/>
|
||||||
|
|
||||||
<lang.syntaxHighlighterFactory key="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetSyntaxHighlighterFactory"/>
|
<lang.syntaxHighlighterFactory key="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetSyntaxHighlighterFactory"/>
|
||||||
<lang.braceMatcher language="jet" implementationClass="org.jetbrains.jet.plugin.JetPairMatcher"/>
|
<lang.braceMatcher language="jet" implementationClass="org.jetbrains.jet.plugin.JetPairMatcher"/>
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
<orderEntry type="module" module-name="backend" scope="TEST" />
|
<orderEntry type="module" module-name="backend" scope="TEST" />
|
||||||
<orderEntry type="module" module-name="descriptors" />
|
<orderEntry type="module" module-name="descriptors" />
|
||||||
<orderEntry type="module" module-name="frontend.java" />
|
<orderEntry type="module" module-name="frontend.java" />
|
||||||
<orderEntry type="module" module-name="descriptor.loader.java" scope="TEST" />
|
<orderEntry type="module" module-name="descriptor.loader.java" />
|
||||||
<orderEntry type="module" module-name="serialization.java" scope="TEST" />
|
<orderEntry type="module" module-name="serialization.java" />
|
||||||
<orderEntry type="module" module-name="serialization" scope="TEST" />
|
<orderEntry type="module" module-name="serialization" scope="TEST" />
|
||||||
<orderEntry type="module" module-name="compiler-tests" scope="TEST" />
|
<orderEntry type="module" module-name="compiler-tests" scope="TEST" />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.jet.jps.incremental.IncrementalCacheProviderImpl
|
||||||
@@ -37,7 +37,7 @@ import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl;
|
|||||||
import org.jetbrains.jet.compiler.runner.SimpleOutputItem;
|
import org.jetbrains.jet.compiler.runner.SimpleOutputItem;
|
||||||
import org.jetbrains.jet.config.IncrementalCompilation;
|
import org.jetbrains.jet.config.IncrementalCompilation;
|
||||||
import org.jetbrains.jet.jps.JpsKotlinCompilerSettings;
|
import org.jetbrains.jet.jps.JpsKotlinCompilerSettings;
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCache;
|
import org.jetbrains.jet.jps.incremental.IncrementalCacheImpl;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
import org.jetbrains.jps.ModuleChunk;
|
import org.jetbrains.jps.ModuleChunk;
|
||||||
import org.jetbrains.jps.builders.BuildTarget;
|
import org.jetbrains.jps.builders.BuildTarget;
|
||||||
@@ -209,7 +209,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IncrementalCache cache = new IncrementalCache(KotlinBuilderModuleScriptGenerator.getIncrementalCacheDir(context));
|
IncrementalCacheImpl cache = new IncrementalCacheImpl(KotlinBuilderModuleScriptGenerator.getIncrementalCacheDir(context));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (ModuleBuildTarget target : chunk.getTargets()) {
|
for (ModuleBuildTarget target : chunk.getTargets()) {
|
||||||
|
|||||||
@@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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 org.jetbrains.jet.jps.incremental
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import com.intellij.util.io.PersistentMap
|
||||||
|
import com.intellij.util.io.PersistentHashMap
|
||||||
|
import com.intellij.util.io.KeyDescriptor
|
||||||
|
import java.io.DataOutput
|
||||||
|
import com.intellij.util.io.IOUtil
|
||||||
|
import java.io.DataInput
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import com.intellij.util.io.DataExternalizer
|
||||||
|
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass
|
||||||
|
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
||||||
|
import org.jetbrains.jet.descriptors.serialization.BitEncoding
|
||||||
|
import org.jetbrains.jet.utils.intellij.*
|
||||||
|
import java.util.Arrays
|
||||||
|
import com.intellij.util.io.IntInlineKeyDescriptor
|
||||||
|
import org.jetbrains.org.objectweb.asm.*
|
||||||
|
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName
|
||||||
|
import java.util.TreeMap
|
||||||
|
import java.util.HashSet
|
||||||
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCache
|
||||||
|
|
||||||
|
public class IncrementalCacheImpl(baseDir: File): IncrementalCache {
|
||||||
|
class object {
|
||||||
|
val PROTO_MAP = "proto.tab"
|
||||||
|
val CONSTANTS_MAP = "constants.tab"
|
||||||
|
val PACKAGE_SOURCES = "package-sources.tab"
|
||||||
|
|
||||||
|
private fun getConstantsHash(bytes: ByteArray): Int {
|
||||||
|
val result = TreeMap<String, Any>() // keys order should defined to check hash of a map
|
||||||
|
|
||||||
|
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.ASM5) {
|
||||||
|
override fun visitField(access: Int, name: String, desc: String, signature: String?, value: Any?): FieldVisitor? {
|
||||||
|
if (value != null) {
|
||||||
|
result[name] = value
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}, ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES)
|
||||||
|
|
||||||
|
return result.hashCode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val protoData: PersistentMap<ClassOrPackageId, ByteArray>
|
||||||
|
private val constantsData: PersistentHashMap<String, Int>
|
||||||
|
= PersistentHashMap(File(baseDir, CONSTANTS_MAP), EnumeratorStringDescriptor(), IntInlineKeyDescriptor())
|
||||||
|
|
||||||
|
// Format of serialization to string: <module id> <path separator> <source file path> --> <package part JVM internal name>
|
||||||
|
private val packageSourcesData: PersistentHashMap<String, String>
|
||||||
|
= PersistentHashMap(File(baseDir, PACKAGE_SOURCES), EnumeratorStringDescriptor(), EnumeratorStringDescriptor())
|
||||||
|
|
||||||
|
;{
|
||||||
|
protoData = PersistentHashMap(File(baseDir, PROTO_MAP), object : KeyDescriptor<ClassOrPackageId> {
|
||||||
|
override fun save(out: DataOutput, value: ClassOrPackageId?) {
|
||||||
|
IOUtil.writeString(value!!.moduleId, out)
|
||||||
|
IOUtil.writeString(value.fqName.asString(), out)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(`in`: DataInput): ClassOrPackageId {
|
||||||
|
val module = IOUtil.readString(`in`)!!
|
||||||
|
val fqName = FqName(IOUtil.readString(`in`)!!)
|
||||||
|
return ClassOrPackageId(module, fqName)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getHashCode(value: ClassOrPackageId?): Int {
|
||||||
|
return value?.hashCode() ?: -1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEqual(val1: ClassOrPackageId?, val2: ClassOrPackageId?): Boolean {
|
||||||
|
return val1 == val2
|
||||||
|
}
|
||||||
|
}, object : DataExternalizer<ByteArray> {
|
||||||
|
override fun save(out: DataOutput, value: ByteArray?) {
|
||||||
|
out.writeInt(value!!.size)
|
||||||
|
out.write(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun read(`in`: DataInput): ByteArray {
|
||||||
|
val length = `in`.readInt()
|
||||||
|
val buf = ByteArray(length)
|
||||||
|
`in`.readFully(buf)
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun saveFileToCache(moduleId: String, sourceFiles: Collection<File>, file: File): Boolean {
|
||||||
|
val fileBytes = file.readBytes()
|
||||||
|
val classNameAndHeader = VirtualFileKotlinClass.readClassNameAndHeader(fileBytes)
|
||||||
|
if (classNameAndHeader == null) return false
|
||||||
|
|
||||||
|
val (className, header) = classNameAndHeader
|
||||||
|
val classFqName = className.getFqNameForClassNameWithoutDollars()
|
||||||
|
val annotationDataEncoded = header.annotationData
|
||||||
|
if (annotationDataEncoded != null) {
|
||||||
|
val data = BitEncoding.decodeBytes(annotationDataEncoded)
|
||||||
|
when (header.kind) {
|
||||||
|
KotlinClassHeader.Kind.PACKAGE_FACADE -> {
|
||||||
|
return putData(moduleId, classFqName.parent(), data)
|
||||||
|
}
|
||||||
|
KotlinClassHeader.Kind.CLASS -> {
|
||||||
|
return putData(moduleId, classFqName, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (header.syntheticClassKind == JvmAnnotationNames.KotlinSyntheticClass.Kind.PACKAGE_PART) {
|
||||||
|
assert(sourceFiles.size == 1) { "Package part from several source files: $sourceFiles" }
|
||||||
|
putPackagePartSourceData(moduleId, sourceFiles.first(), className)
|
||||||
|
return putConstantsData(className, getConstantsHash(fileBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun putData(moduleId: String, fqName: FqName, data: ByteArray): Boolean {
|
||||||
|
val id = ClassOrPackageId(moduleId, fqName)
|
||||||
|
val oldData = protoData[id]
|
||||||
|
if (Arrays.equals(data, oldData)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
protoData.put(id, data)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun putConstantsData(packagePartClass: JvmClassName, constantsHash: Int): Boolean {
|
||||||
|
val key = packagePartClass.getInternalName()
|
||||||
|
|
||||||
|
val oldHash = constantsData[key]
|
||||||
|
if (oldHash == constantsHash) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
constantsData.put(key, constantsHash)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun putPackagePartSourceData(moduleId: String, sourceFile: File, className: JvmClassName?) {
|
||||||
|
val key = moduleId + File.pathSeparator + sourceFile.getAbsolutePath()
|
||||||
|
|
||||||
|
if (className != null) {
|
||||||
|
packageSourcesData.put(key, className.getInternalName())
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
packageSourcesData.remove(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun clearPackagePartSourceData(moduleId: String, sourceFile: File) {
|
||||||
|
putPackagePartSourceData(moduleId, sourceFile, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun getPackagesWithRemovedFiles(moduleId: String, compiledSourceFiles: Collection<JetFile>): Collection<FqName> {
|
||||||
|
return getRemovedPackageParts(moduleId, compiledSourceFiles).map { it.getFqNameForClassNameWithoutDollars().parent() }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun getRemovedPackageParts(moduleId: String, compiledSourceFiles: Collection<JetFile>): Collection<JvmClassName> {
|
||||||
|
val sourceFileToCurrentFqNameMap = HashMap<File, FqName>()
|
||||||
|
for (sourceFile in compiledSourceFiles) {
|
||||||
|
sourceFileToCurrentFqNameMap[File(sourceFile.getVirtualFile()!!.getPath())] = sourceFile.getPackageFqName()
|
||||||
|
}
|
||||||
|
|
||||||
|
val result = HashSet<JvmClassName>()
|
||||||
|
|
||||||
|
packageSourcesData.processKeysWithExistingMapping { key ->
|
||||||
|
if (key!!.startsWith(moduleId + File.pathSeparator)) {
|
||||||
|
val indexOf = key.indexOf(File.pathSeparator)
|
||||||
|
val sourceFile = File(key.substring(indexOf + 1))
|
||||||
|
|
||||||
|
val packagePartClassName = JvmClassName.byInternalName(packageSourcesData[key]!!)
|
||||||
|
if (!sourceFile.exists()) {
|
||||||
|
result.add(packagePartClassName)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val previousPackageFqName = packagePartClassName.getFqNameForClassNameWithoutDollars().parent()
|
||||||
|
val currentPackageFqName = sourceFileToCurrentFqNameMap[sourceFile]
|
||||||
|
if (currentPackageFqName != null && currentPackageFqName != previousPackageFqName) {
|
||||||
|
result.add(packagePartClassName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
public override fun getPackageData(moduleId: String, fqName: FqName): ByteArray? {
|
||||||
|
return protoData[ClassOrPackageId(moduleId, fqName)]
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun close() {
|
||||||
|
protoData.close()
|
||||||
|
constantsData.close()
|
||||||
|
packageSourcesData.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class ClassOrPackageId(val moduleId: String, val fqName: FqName) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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 org.jetbrains.jet.jps.incremental
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCacheProvider
|
||||||
|
import java.io.File
|
||||||
|
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalCache
|
||||||
|
|
||||||
|
public class IncrementalCacheProviderImpl: IncrementalCacheProvider {
|
||||||
|
override fun getIncrementalCache(baseDir: File): IncrementalCache {
|
||||||
|
return IncrementalCacheImpl(baseDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user