From e883860868fed5263de50bce4259e8afdfe87bca Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Tue, 19 Jul 2022 18:48:36 +0300 Subject: [PATCH] prototype for client/server #21 --- build.gradle | 174 +++++++++--------- core/build.gradle | 16 ++ .../org/utbot/jcdb/CompilationDatabase.kt | 2 + .../utbot/jcdb/CompilationDatabaseSettings.kt | 9 + .../main/kotlin/org/utbot/jcdb/api/Api.kt | 0 .../main/kotlin/org/utbot/jcdb/api/ApiExt.kt | 0 .../kotlin/org/utbot/jcdb/api/Exceptions.kt | 0 .../main/kotlin/org/utbot/jcdb/api/Hook.kt | 8 + .../main/kotlin/org/utbot/jcdb/api/Index.kt | 0 .../main/kotlin/org/utbot/jcdb/impl/Async.kt | 0 .../org/utbot/jcdb/impl/ClassIdService.kt | 0 .../utbot/jcdb/impl/ClasspathSetExtensions.kt | 0 .../org/utbot/jcdb/impl/ClasspathSetImpl.kt | 0 .../jcdb/impl/CompilationDatabaseImpl.kt | 6 + .../org/utbot/jcdb/impl/FeaturesRegistry.kt | 0 .../org/utbot/jcdb/impl/LocationsRegistry.kt | 0 .../jcdb/impl/fs/AbstractByteCodeLocation.kt | 0 .../utbot/jcdb/impl/fs/BuildFolderLocation.kt | 0 .../utbot/jcdb/impl/fs/ByteCodeConverter.kt | 64 +++++++ .../utbot/jcdb/impl/fs/ByteCodeLoaderImpl.kt | 0 .../utbot/jcdb/impl/fs/ByteCodeLocations.kt | 0 .../utbot/jcdb/impl/fs/ClassByteCodeSource.kt | 60 +----- .../org/utbot/jcdb/impl/fs/JarLocationImpl.kt | 0 .../org/utbot/jcdb/impl/fs/JavaRuntime.kt | 0 .../org/utbot/jcdb/impl/fs/JmodLocation.kt | 0 .../jcdb/impl/index/HierarchyExtension.kt | 0 .../utbot/jcdb/impl/index/HierarchyIndex.kt | 0 .../org/utbot/jcdb/impl/index/Indexes.kt | 0 .../jcdb/impl/index/ReversedUsageIndex.kt | 0 .../impl/index/ReversedUsagesExtension.kt | 0 .../jcdb/impl/signature/FieldSignature.kt | 0 .../jcdb/impl/signature/FormalTypeVariable.kt | 0 .../impl/signature/GenericTypeExtractor.kt | 0 .../impl/signature/GenericTypeRegistrant.kt | 0 .../jcdb/impl/signature/MethodSignature.kt | 0 .../jcdb/impl/signature/RecordSignature.kt | 0 .../utbot/jcdb/impl/signature/Resolutions.kt | 0 .../utbot/jcdb/impl/signature/Signature.kt | 0 .../jcdb/impl/signature/TypeSignature.kt | 0 .../org/utbot/jcdb/impl/signature/Types.kt | 0 .../jcdb/impl/storage/DataStorageException.kt | 0 .../impl/storage/PersistentEnvironment.kt | 0 .../impl/storage/scheme/DatabaseEntity.kt | 0 .../jcdb/impl/storage/scheme/GlobalIdStore.kt | 0 .../impl/storage/scheme/LocationEntity.kt | 0 .../utbot/jcdb/impl/tree/AbstractClassTree.kt | 0 .../org/utbot/jcdb/impl/tree/ClassNode.kt | 0 .../org/utbot/jcdb/impl/tree/ClassTree.kt | 0 .../utbot/jcdb/impl/tree/ClassTreeListener.kt | 0 .../utbot/jcdb/impl/tree/ClassTreeNodes.kt | 0 .../jcdb/impl/tree/ClasspathClassTree.kt | 0 .../utbot/jcdb/impl/tree/LibraryClassTree.kt | 0 .../org/utbot/jcdb/impl/tree/PackageNode.kt | 0 .../utbot/jcdb/impl/types/ArrayClassIdImpl.kt | 0 .../org/utbot/jcdb/impl/types/ClassIdImpl.kt | 0 .../org/utbot/jcdb/impl/types/FieldIdImpl.kt | 0 .../org/utbot/jcdb/impl/types/MethodIdImpl.kt | 0 .../org/utbot/jcdb/impl/types/Objects.kt | 0 .../jcdb/impl/types/PredefinedPrimitive.kt | 0 .../test/java/org/utbot/jcdb/impl/Bar.java | 0 .../utbot/jcdb/impl/hierarchies/Creature.java | 0 .../org/utbot/jcdb/impl/usages/Generics.java | 0 .../usages/HelloWorldAnonymousClasses.java | 0 .../org/utbot/jcdb/impl/usages/WithInner.java | 0 .../jcdb/impl/usages/direct/DirectA.java | 0 .../jcdb/impl/usages/fields/FakeFieldA.java | 0 .../utbot/jcdb/impl/usages/fields/FieldA.java | 0 .../utbot/jcdb/impl/usages/fields/FieldB.java | 0 .../jcdb/impl/usages/methods/MethodA.java | 0 .../jcdb/impl/usages/methods/MethodB.java | 0 .../jcdb/impl/usages/methods/MethodC.java | 0 .../kotlin/org/utbot/jcdb/impl/ApiExtTest.kt | 0 .../kotlin/org/utbot/jcdb/impl/ClassesTest.kt | 0 .../utbot/jcdb/impl/DatabaseLifecycleTest.kt | 0 .../org/utbot/jcdb/impl/DirectUsagesTest.kt | 0 .../test/kotlin/org/utbot/jcdb/impl/Foo.kt | 0 .../kotlin/org/utbot/jcdb/impl/Hierarchy.kt | 0 .../utbot/jcdb/impl/IndexSerializationTest.kt | 0 .../org/utbot/jcdb/impl/LibrariesMixin.kt | 0 .../kotlin/org/utbot/jcdb/impl/MethodUsage.kt | 0 .../jcdb/impl/SearchReversedUsagesTest.kt | 0 .../jcdb/impl/performance/DBBenchmarks.kt | 0 .../impl/performance/DBLifeCycleBenchmarks.kt | 0 .../impl/performance/RestoreDBBenchmark.kt | 0 .../jcdb/impl/performance/TakeMemoryDump.kt | 0 .../jcdb/impl/persistence/RestoredDBTest.kt | 0 .../org/utbot/jcdb/impl/tree/ClassTreeTest.kt | 0 .../utbot/jcdb/impl/tree/DummyCodeLocation.kt | 0 remote-rd/build.gradle | 11 ++ .../org/utbot/jcdb/remote/rd/InternalApi.kt | 71 +++++++ .../org/utbot/jcdb/remote/rd/RDClient.kt | 78 ++++++++ .../org/utbot/jcdb/remote/rd/RDServer.kt | 87 +++++++++ .../jcdb/remote/rd/client/RemoteClassId.kt | 64 +++++++ .../remote/rd/client/RemoteClasspathSet.kt | 57 ++++++ .../kotlin/org/utbot/jcdb/remote/rd/rd.kt | 14 ++ settings.gradle | 5 +- 96 files changed, 583 insertions(+), 143 deletions(-) create mode 100644 core/build.gradle rename {src => core/src}/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt (97%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt (90%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/api/Api.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/api/ApiExt.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/api/Exceptions.kt (100%) create mode 100644 core/src/main/kotlin/org/utbot/jcdb/api/Hook.kt rename {src => core/src}/main/kotlin/org/utbot/jcdb/api/Index.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/Async.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/ClassIdService.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/ClasspathSetExtensions.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/ClasspathSetImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt (97%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/FeaturesRegistry.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/LocationsRegistry.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/AbstractByteCodeLocation.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/BuildFolderLocation.kt (100%) create mode 100644 core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeConverter.kt rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLoaderImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLocations.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt (60%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/JarLocationImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/JavaRuntime.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/fs/JmodLocation.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/index/HierarchyExtension.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/index/HierarchyIndex.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/index/Indexes.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsageIndex.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsagesExtension.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/FieldSignature.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/FormalTypeVariable.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeExtractor.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeRegistrant.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/MethodSignature.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/RecordSignature.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/Resolutions.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/Signature.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/TypeSignature.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/signature/Types.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/storage/DataStorageException.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/storage/PersistentEnvironment.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/storage/scheme/DatabaseEntity.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/storage/scheme/GlobalIdStore.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/storage/scheme/LocationEntity.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/AbstractClassTree.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/ClassNode.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/ClassTree.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeListener.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeNodes.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/ClasspathClassTree.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/LibraryClassTree.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/tree/PackageNode.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/types/ArrayClassIdImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/types/ClassIdImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/types/FieldIdImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/types/MethodIdImpl.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/types/Objects.kt (100%) rename {src => core/src}/main/kotlin/org/utbot/jcdb/impl/types/PredefinedPrimitive.kt (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/Bar.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/hierarchies/Creature.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/Generics.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/HelloWorldAnonymousClasses.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/WithInner.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/direct/DirectA.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/fields/FakeFieldA.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/fields/FieldA.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/fields/FieldB.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/methods/MethodA.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/methods/MethodB.java (100%) rename {src => core/src}/test/java/org/utbot/jcdb/impl/usages/methods/MethodC.java (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/ApiExtTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/ClassesTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/DatabaseLifecycleTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/DirectUsagesTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/Foo.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/Hierarchy.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/IndexSerializationTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/LibrariesMixin.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/MethodUsage.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/SearchReversedUsagesTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/performance/DBBenchmarks.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/performance/DBLifeCycleBenchmarks.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/performance/TakeMemoryDump.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/persistence/RestoredDBTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/tree/ClassTreeTest.kt (100%) rename {src => core/src}/test/kotlin/org/utbot/jcdb/impl/tree/DummyCodeLocation.kt (100%) create mode 100644 remote-rd/build.gradle create mode 100644 remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/InternalApi.kt create mode 100644 remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDClient.kt create mode 100644 remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDServer.kt create mode 100644 remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClassId.kt create mode 100644 remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClasspathSet.kt create mode 100644 remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/rd.kt diff --git a/build.gradle b/build.gradle index 7b3c3808d..b74a11e56 100644 --- a/build.gradle +++ b/build.gradle @@ -23,109 +23,115 @@ buildscript { } } -apply plugin: 'base' -apply plugin: 'java' -apply plugin: 'kotlin' -apply plugin: 'maven-publish' -apply plugin: 'org.jetbrains.kotlin.plugin.allopen' -apply plugin: 'org.jetbrains.kotlin.plugin.serialization' -apply plugin: 'org.jetbrains.kotlinx.benchmark' - -dependencies { - implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "1.8.3" - implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlin_version - implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: coroutines_version - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-collections-immutable-jvm', version: collections_version - implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-cbor', version: '1.3.3' - implementation group: 'org.jetbrains.xodus', name: 'xodus-entity-store', version: xodus_version - implementation group: 'org.ow2.asm', name: 'asm', version: asm_version - implementation group: 'org.ow2.asm', name: 'asm-tree', version: asm_version - - testImplementation(platform('org.junit:junit-bom:5.8.2')) - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter' - testImplementation group: 'com.google.guava', name: 'guava', version: '31.1-jre' - testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-benchmark-runtime', version: '0.4.4' -} +subprojects { + + group = rootProject.group + version = rootProject.version + + apply plugin: 'base' + apply plugin: 'java' + apply plugin: 'kotlin' + apply plugin: 'maven-publish' + apply plugin: 'org.jetbrains.kotlin.plugin.allopen' + apply plugin: 'org.jetbrains.kotlin.plugin.serialization' + apply plugin: 'org.jetbrains.kotlinx.benchmark' + + + publishing { + publications { + jar(MavenPublication) { + from components.java + groupId 'org.utbot' + artifactId project.name + } + } + } -allOpen { - annotation("org.openjdk.jmh.annotations.State") -} + repositories { + mavenCentral() + maven { url 'https://jitpack.io' } + } -compileKotlin { - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 - languageVersion = "1.4" - apiVersion = "1.4" - freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"] - allWarningsAsErrors = false + publishing { + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/UnitTestBot/java-compilation-database") + credentials { + username = project.findProperty("gprUser") ?: System.getenv("USERNAME") + password = project.findProperty("gprKey") ?: System.getenv("TOKEN") + } + } + } + publications { + gpr(MavenPublication) { + from components.java + groupId 'org.utbot' + artifactId project.name + } + } } -} -compileTestKotlin { - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 - languageVersion = "1.4" - apiVersion = "1.4" - freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"] - allWarningsAsErrors = false + dependencies { + testImplementation(platform('org.junit:junit-bom:5.8.2')) + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter' + testImplementation group: 'com.google.guava', name: 'guava', version: '31.1-jre' + testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-benchmark-runtime', version: '0.4.4' } -} -test { - useJUnitPlatform() - jvmArgs = ['-Xmx2g', '-XX:+HeapDumpOnOutOfMemoryError', '-XX:HeapDumpPath=heapdump.hprof'] - testLogging { - events "passed", "skipped", "failed" + allOpen { + annotation("org.openjdk.jmh.annotations.State") } -} -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} + compileKotlin { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 + languageVersion = "1.4" + apiVersion = "1.4" + freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"] + allWarningsAsErrors = false + } + } -publishing { - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/UnitTestBot/java-compilation-database") - credentials { - username = project.findProperty("gprUser") ?: System.getenv("USERNAME") - password = project.findProperty("gprKey") ?: System.getenv("TOKEN") - } + compileTestKotlin { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 + languageVersion = "1.4" + apiVersion = "1.4" + freeCompilerArgs += ["-Xallow-result-return-type", "-Xinline-classes"] + allWarningsAsErrors = false } } - publications { - gpr(MavenPublication) { - from components.java - groupId 'org.utbot' - artifactId project.name + + test { + useJUnitPlatform() + jvmArgs = ['-Xmx2g', '-XX:+HeapDumpOnOutOfMemoryError', '-XX:HeapDumpPath=heapdump.hprof'] + testLogging { + events "passed", "skipped", "failed" } } -} -repositories { - repositories { - mavenCentral() + java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } -} // Configure benchmark -benchmark { - configurations { - main { // main configuration is created automatically, but you can change its defaults - warmups = 3 // number of warmup iterations - iterations = 5 // number of iterations + benchmark { + configurations { + main { // main configuration is created automatically, but you can change its defaults + warmups = 3 // number of warmup iterations + iterations = 5 // number of iterations + } } - } - // Setup configurations - targets { - // This one matches sourceSet name above - register("test") { - jmhVersion = "1.21" + // Setup configurations + targets { + // This one matches sourceSet name above + register("test") { + jmhVersion = "1.21" + } } } -} \ No newline at end of file +} diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 000000000..69c8c7765 --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,16 @@ +dependencies { + implementation group: 'io.github.microutils', name: 'kotlin-logging', version: "1.8.3" + implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jdk8', version: kotlin_version + implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: coroutines_version + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-collections-immutable-jvm', version: collections_version + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-serialization-cbor', version: '1.3.3' + implementation group: 'org.jetbrains.xodus', name: 'xodus-entity-store', version: xodus_version + implementation group: 'org.ow2.asm', name: 'asm', version: asm_version + implementation group: 'org.ow2.asm', name: 'asm-tree', version: asm_version + + testImplementation(platform('org.junit:junit-bom:5.8.2')) + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter' + testImplementation group: 'com.google.guava', name: 'guava', version: '31.1-jre' + testImplementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-benchmark-runtime', version: '0.4.4' +} \ No newline at end of file diff --git a/src/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt b/core/src/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt similarity index 97% rename from src/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt rename to core/src/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt index 0c9bbba60..c5c5ca211 100644 --- a/src/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt +++ b/core/src/main/kotlin/org/utbot/jcdb/CompilationDatabase.kt @@ -27,6 +27,7 @@ suspend fun compilationDatabase(builder: CompilationDatabaseSettings.() -> Unit) ) database.restoreDataFrom(restoredLocations.toMap()) database.loadLocations(notLoaded.toList()) + database.afterStart() return database } } @@ -38,6 +39,7 @@ suspend fun compilationDatabase(builder: CompilationDatabaseSettings.() -> Unit) if (settings.watchFileSystemChanges != null) { database.watchFileSystemChanges() } + database.afterStart() return database } diff --git a/src/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt b/core/src/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt similarity index 90% rename from src/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt rename to core/src/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt index d767d2c85..158e03b3b 100644 --- a/src/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt +++ b/core/src/main/kotlin/org/utbot/jcdb/CompilationDatabaseSettings.kt @@ -1,6 +1,8 @@ package org.utbot.jcdb import org.utbot.jcdb.api.Feature +import org.utbot.jcdb.api.Hook +import org.utbot.jcdb.impl.CompilationDatabaseImpl import org.utbot.jcdb.impl.index.Hierarchy import java.io.File @@ -17,6 +19,8 @@ class CompilationDatabaseSettings { /** jar files which should be loaded right after database is created */ var predefinedDirOrJars: List = emptyList() + var hooks: MutableList<(CompilationDatabaseImpl) -> Hook> = arrayListOf() + /** mandatory setting for java location */ lateinit var jre: File @@ -35,6 +39,11 @@ class CompilationDatabaseSettings { watchFileSystemChanges = CompilationDatabaseWatchFileSystemSettings().also(settings) } + /** builder for hooks */ + fun withHook(hook: (CompilationDatabaseImpl) -> Hook) { + hooks += hook + } + /** * use java from JAVA_HOME env variable */ diff --git a/src/main/kotlin/org/utbot/jcdb/api/Api.kt b/core/src/main/kotlin/org/utbot/jcdb/api/Api.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/api/Api.kt rename to core/src/main/kotlin/org/utbot/jcdb/api/Api.kt diff --git a/src/main/kotlin/org/utbot/jcdb/api/ApiExt.kt b/core/src/main/kotlin/org/utbot/jcdb/api/ApiExt.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/api/ApiExt.kt rename to core/src/main/kotlin/org/utbot/jcdb/api/ApiExt.kt diff --git a/src/main/kotlin/org/utbot/jcdb/api/Exceptions.kt b/core/src/main/kotlin/org/utbot/jcdb/api/Exceptions.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/api/Exceptions.kt rename to core/src/main/kotlin/org/utbot/jcdb/api/Exceptions.kt diff --git a/core/src/main/kotlin/org/utbot/jcdb/api/Hook.kt b/core/src/main/kotlin/org/utbot/jcdb/api/Hook.kt new file mode 100644 index 000000000..2f980dc0b --- /dev/null +++ b/core/src/main/kotlin/org/utbot/jcdb/api/Hook.kt @@ -0,0 +1,8 @@ +package org.utbot.jcdb.api + +interface Hook { + + fun afterStart() + + fun afterStop() {} +} \ No newline at end of file diff --git a/src/main/kotlin/org/utbot/jcdb/api/Index.kt b/core/src/main/kotlin/org/utbot/jcdb/api/Index.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/api/Index.kt rename to core/src/main/kotlin/org/utbot/jcdb/api/Index.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/Async.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/Async.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/Async.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/Async.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/ClassIdService.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/ClassIdService.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/ClassIdService.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/ClassIdService.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetExtensions.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetExtensions.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetExtensions.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetExtensions.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/ClasspathSetImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt similarity index 97% rename from src/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt index 60c0c998c..354e6f7f7 100644 --- a/src/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt +++ b/core/src/main/kotlin/org/utbot/jcdb/impl/CompilationDatabaseImpl.kt @@ -25,6 +25,7 @@ class CompilationDatabaseImpl( private val classTree = ClassTree() internal val javaRuntime = JavaRuntime(settings.jre) + private val hooks = settings.hooks.map { it(this) } internal val featureRegistry = FeaturesRegistry(persistentEnvironment, settings.fullFeatures) internal val locationsRegistry = LocationsRegistry(featureRegistry) @@ -152,6 +153,10 @@ class CompilationDatabaseImpl( backgroundJobs.values.toList().joinAll() } + fun afterStart() { + hooks.forEach { it.afterStart() } + } + override fun close() { isClosed.set(true) locationsRegistry.close() @@ -160,6 +165,7 @@ class CompilationDatabaseImpl( } backgroundJobs.clear() persistentEnvironment?.close() + hooks.forEach { it.afterStop() } } private fun assertNotClosed() { diff --git a/src/main/kotlin/org/utbot/jcdb/impl/FeaturesRegistry.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/FeaturesRegistry.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/FeaturesRegistry.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/FeaturesRegistry.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/LocationsRegistry.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/LocationsRegistry.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/LocationsRegistry.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/LocationsRegistry.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/AbstractByteCodeLocation.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/AbstractByteCodeLocation.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/AbstractByteCodeLocation.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/AbstractByteCodeLocation.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/BuildFolderLocation.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/BuildFolderLocation.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/BuildFolderLocation.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/BuildFolderLocation.kt diff --git a/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeConverter.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeConverter.kt new file mode 100644 index 000000000..23b7e5c8d --- /dev/null +++ b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeConverter.kt @@ -0,0 +1,64 @@ +package org.utbot.jcdb.impl.fs + +import kotlinx.collections.immutable.toImmutableList +import org.objectweb.asm.Type +import org.objectweb.asm.tree.AnnotationNode +import org.objectweb.asm.tree.ClassNode +import org.objectweb.asm.tree.FieldNode +import org.objectweb.asm.tree.MethodNode +import org.utbot.jcdb.impl.types.* + +interface ByteCodeConverter { + + fun ClassNode.asClassInfo() = ClassInfo( + name = Type.getObjectType(name).className, + signature = signature, + access = access, + + outerClass = outerClassName(), + innerClasses = innerClasses.map { + Type.getObjectType(it.name).className + }.toImmutableList(), + outerMethod = outerMethod, + outerMethodDesc = outerMethodDesc, + superClass = superName?.let { Type.getObjectType(it).className }, + interfaces = interfaces.map { Type.getObjectType(it).className }.toImmutableList(), + methods = methods.map { it.asMethodInfo() }.toImmutableList(), + fields = fields.map { it.asFieldInfo() }.toImmutableList(), + annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList() + ) + + private fun ClassNode.outerClassName(): OuterClassRef? { + val innerRef = innerClasses.firstOrNull { it.name == name } + + val direct = outerClass?.let { Type.getObjectType(it).className } + if (direct == null && innerRef != null) { + return OuterClassRef(Type.getObjectType(innerRef.outerName).className, innerRef.innerName) + } + return direct?.let { + OuterClassRef(it, innerRef?.innerName) + } + } + + private fun AnnotationNode.asAnnotationInfo() = AnnotationInfo( + className = Type.getType(desc).className + ) + + private fun MethodNode.asMethodInfo() = MethodInfo( + name = name, + signature = signature, + desc = desc, + access = access, + returnType = Type.getReturnType(desc).className, + parameters = Type.getArgumentTypes(desc).map { it.className }.toImmutableList(), + annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList() + ) + + private fun FieldNode.asFieldInfo() = FieldInfo( + name = name, + signature = signature, + access = access, + type = Type.getType(desc).className, + annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList() + ) +} \ No newline at end of file diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLoaderImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLoaderImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLoaderImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLoaderImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLocations.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLocations.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLocations.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/ByteCodeLocations.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt similarity index 60% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt index b40f98eaf..070209e1b 100644 --- a/src/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt +++ b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/ClassByteCodeSource.kt @@ -1,19 +1,15 @@ package org.utbot.jcdb.impl.fs -import kotlinx.collections.immutable.toImmutableList import org.objectweb.asm.ClassReader import org.objectweb.asm.Opcodes -import org.objectweb.asm.Type -import org.objectweb.asm.tree.AnnotationNode import org.objectweb.asm.tree.ClassNode -import org.objectweb.asm.tree.FieldNode import org.objectweb.asm.tree.MethodNode import org.utbot.jcdb.api.ByteCodeLocation import org.utbot.jcdb.impl.suspendableLazy -import org.utbot.jcdb.impl.types.* +import org.utbot.jcdb.impl.types.ClassInfo import java.io.InputStream -abstract class ClassByteCodeSource(val location: ByteCodeLocation, val className: String) { +abstract class ClassByteCodeSource(val location: ByteCodeLocation, val className: String) : ByteCodeConverter { abstract suspend fun info(): ClassInfo abstract suspend fun fullByteCode(): ClassNode @@ -26,58 +22,6 @@ abstract class ClassByteCodeSource(val location: ByteCodeLocation, val className return location.resolve(className) } - protected fun ClassNode.asClassInfo() = ClassInfo( - name = Type.getObjectType(name).className, - signature = signature, - access = access, - - outerClass = outerClassName(), - innerClasses = innerClasses.map { - Type.getObjectType(it.name).className - }.toImmutableList(), - outerMethod = outerMethod, - outerMethodDesc = outerMethodDesc, - superClass = superName?.let { Type.getObjectType(it).className }, - interfaces = interfaces.map { Type.getObjectType(it).className }.toImmutableList(), - methods = methods.map { it.asMethodInfo() }.toImmutableList(), - fields = fields.map { it.asFieldInfo() }.toImmutableList(), - annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList() - ) - - private fun ClassNode.outerClassName(): OuterClassRef? { - val innerRef = innerClasses.firstOrNull { it.name == name } - - val direct = outerClass?.let { Type.getObjectType(it).className } - if (direct == null && innerRef != null) { - return OuterClassRef(Type.getObjectType(innerRef.outerName).className, innerRef.innerName) - } - return direct?.let { - OuterClassRef(it, innerRef?.innerName) - } - } - - private fun AnnotationNode.asAnnotationInfo() = AnnotationInfo( - className = Type.getType(desc).className - ) - - private fun MethodNode.asMethodInfo() = MethodInfo( - name = name, - signature = signature, - desc = desc, - access = access, - returnType = Type.getReturnType(desc).className, - parameters = Type.getArgumentTypes(desc).map { it.className }.toImmutableList(), - annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList() - ) - - private fun FieldNode.asFieldInfo() = FieldInfo( - name = name, - signature = signature, - access = access, - type = Type.getType(desc).className, - annotations = visibleAnnotations.orEmpty().map { it.asAnnotationInfo() }.toImmutableList() - ) - suspend fun loadMethod(name: String, desc: String): MethodNode? { return fullByteCode().methods.first { it.name == name && it.desc == desc } } diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/JarLocationImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/JarLocationImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/JarLocationImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/JarLocationImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/JavaRuntime.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/JavaRuntime.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/JavaRuntime.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/JavaRuntime.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/fs/JmodLocation.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/fs/JmodLocation.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/fs/JmodLocation.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/fs/JmodLocation.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyExtension.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyExtension.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyExtension.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyExtension.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyIndex.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyIndex.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyIndex.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/index/HierarchyIndex.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/index/Indexes.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/index/Indexes.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/index/Indexes.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/index/Indexes.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsageIndex.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsageIndex.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsageIndex.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsageIndex.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsagesExtension.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsagesExtension.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsagesExtension.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/index/ReversedUsagesExtension.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/FieldSignature.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/FieldSignature.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/FieldSignature.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/FieldSignature.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/FormalTypeVariable.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/FormalTypeVariable.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/FormalTypeVariable.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/FormalTypeVariable.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeExtractor.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeExtractor.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeExtractor.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeExtractor.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeRegistrant.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeRegistrant.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeRegistrant.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/GenericTypeRegistrant.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/MethodSignature.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/MethodSignature.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/MethodSignature.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/MethodSignature.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/RecordSignature.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/RecordSignature.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/RecordSignature.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/RecordSignature.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/Resolutions.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/Resolutions.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/Resolutions.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/Resolutions.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/Signature.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/Signature.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/Signature.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/Signature.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/TypeSignature.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/TypeSignature.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/TypeSignature.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/TypeSignature.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/signature/Types.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/signature/Types.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/signature/Types.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/signature/Types.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/storage/DataStorageException.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/storage/DataStorageException.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/storage/DataStorageException.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/storage/DataStorageException.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/storage/PersistentEnvironment.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/storage/PersistentEnvironment.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/storage/PersistentEnvironment.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/storage/PersistentEnvironment.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/DatabaseEntity.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/DatabaseEntity.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/DatabaseEntity.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/DatabaseEntity.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/GlobalIdStore.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/GlobalIdStore.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/GlobalIdStore.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/GlobalIdStore.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/LocationEntity.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/LocationEntity.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/LocationEntity.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/storage/scheme/LocationEntity.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/AbstractClassTree.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/AbstractClassTree.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/AbstractClassTree.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/AbstractClassTree.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassNode.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassNode.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/ClassNode.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassNode.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTree.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTree.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTree.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTree.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeListener.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeListener.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeListener.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeListener.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeNodes.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeNodes.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeNodes.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClassTreeNodes.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/ClasspathClassTree.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClasspathClassTree.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/ClasspathClassTree.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/ClasspathClassTree.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/LibraryClassTree.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/LibraryClassTree.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/LibraryClassTree.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/LibraryClassTree.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/tree/PackageNode.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/tree/PackageNode.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/tree/PackageNode.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/tree/PackageNode.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/types/ArrayClassIdImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/types/ArrayClassIdImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/types/ArrayClassIdImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/types/ArrayClassIdImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/types/ClassIdImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/types/ClassIdImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/types/ClassIdImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/types/ClassIdImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/types/FieldIdImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/types/FieldIdImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/types/FieldIdImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/types/FieldIdImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/types/MethodIdImpl.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/types/MethodIdImpl.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/types/MethodIdImpl.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/types/MethodIdImpl.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/types/Objects.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/types/Objects.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/types/Objects.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/types/Objects.kt diff --git a/src/main/kotlin/org/utbot/jcdb/impl/types/PredefinedPrimitive.kt b/core/src/main/kotlin/org/utbot/jcdb/impl/types/PredefinedPrimitive.kt similarity index 100% rename from src/main/kotlin/org/utbot/jcdb/impl/types/PredefinedPrimitive.kt rename to core/src/main/kotlin/org/utbot/jcdb/impl/types/PredefinedPrimitive.kt diff --git a/src/test/java/org/utbot/jcdb/impl/Bar.java b/core/src/test/java/org/utbot/jcdb/impl/Bar.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/Bar.java rename to core/src/test/java/org/utbot/jcdb/impl/Bar.java diff --git a/src/test/java/org/utbot/jcdb/impl/hierarchies/Creature.java b/core/src/test/java/org/utbot/jcdb/impl/hierarchies/Creature.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/hierarchies/Creature.java rename to core/src/test/java/org/utbot/jcdb/impl/hierarchies/Creature.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/Generics.java b/core/src/test/java/org/utbot/jcdb/impl/usages/Generics.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/Generics.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/Generics.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/HelloWorldAnonymousClasses.java b/core/src/test/java/org/utbot/jcdb/impl/usages/HelloWorldAnonymousClasses.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/HelloWorldAnonymousClasses.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/HelloWorldAnonymousClasses.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/WithInner.java b/core/src/test/java/org/utbot/jcdb/impl/usages/WithInner.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/WithInner.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/WithInner.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/direct/DirectA.java b/core/src/test/java/org/utbot/jcdb/impl/usages/direct/DirectA.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/direct/DirectA.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/direct/DirectA.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/fields/FakeFieldA.java b/core/src/test/java/org/utbot/jcdb/impl/usages/fields/FakeFieldA.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/fields/FakeFieldA.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/fields/FakeFieldA.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/fields/FieldA.java b/core/src/test/java/org/utbot/jcdb/impl/usages/fields/FieldA.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/fields/FieldA.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/fields/FieldA.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/fields/FieldB.java b/core/src/test/java/org/utbot/jcdb/impl/usages/fields/FieldB.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/fields/FieldB.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/fields/FieldB.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodA.java b/core/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodA.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/methods/MethodA.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodA.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodB.java b/core/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodB.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/methods/MethodB.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodB.java diff --git a/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodC.java b/core/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodC.java similarity index 100% rename from src/test/java/org/utbot/jcdb/impl/usages/methods/MethodC.java rename to core/src/test/java/org/utbot/jcdb/impl/usages/methods/MethodC.java diff --git a/src/test/kotlin/org/utbot/jcdb/impl/ApiExtTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/ApiExtTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/ApiExtTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/ApiExtTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/ClassesTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/ClassesTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/ClassesTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/ClassesTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/DatabaseLifecycleTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/DatabaseLifecycleTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/DatabaseLifecycleTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/DatabaseLifecycleTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/DirectUsagesTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/DirectUsagesTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/DirectUsagesTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/DirectUsagesTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/Foo.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/Foo.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/Foo.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/Foo.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/Hierarchy.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/Hierarchy.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/Hierarchy.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/Hierarchy.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/IndexSerializationTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/IndexSerializationTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/IndexSerializationTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/IndexSerializationTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/LibrariesMixin.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/LibrariesMixin.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/LibrariesMixin.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/LibrariesMixin.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/MethodUsage.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/MethodUsage.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/MethodUsage.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/MethodUsage.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/SearchReversedUsagesTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/SearchReversedUsagesTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/SearchReversedUsagesTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/SearchReversedUsagesTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/performance/DBBenchmarks.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/performance/DBBenchmarks.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/performance/DBBenchmarks.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/performance/DBBenchmarks.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/performance/DBLifeCycleBenchmarks.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/performance/DBLifeCycleBenchmarks.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/performance/DBLifeCycleBenchmarks.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/performance/DBLifeCycleBenchmarks.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/performance/TakeMemoryDump.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/performance/TakeMemoryDump.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/performance/TakeMemoryDump.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/performance/TakeMemoryDump.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/persistence/RestoredDBTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/persistence/RestoredDBTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/persistence/RestoredDBTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/persistence/RestoredDBTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/tree/ClassTreeTest.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/tree/ClassTreeTest.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/tree/ClassTreeTest.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/tree/ClassTreeTest.kt diff --git a/src/test/kotlin/org/utbot/jcdb/impl/tree/DummyCodeLocation.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/tree/DummyCodeLocation.kt similarity index 100% rename from src/test/kotlin/org/utbot/jcdb/impl/tree/DummyCodeLocation.kt rename to core/src/test/kotlin/org/utbot/jcdb/impl/tree/DummyCodeLocation.kt diff --git a/remote-rd/build.gradle b/remote-rd/build.gradle new file mode 100644 index 000000000..36c5515e6 --- /dev/null +++ b/remote-rd/build.gradle @@ -0,0 +1,11 @@ +dependencies { + implementation project(":core") + + + implementation group: 'org.ow2.asm', name: 'asm', version: asm_version + implementation group: 'org.ow2.asm', name: 'asm-tree', version: asm_version + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: coroutines_version + implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-collections-immutable-jvm', version: collections_version + implementation group: 'com.jetbrains.rd', name: 'rd-core', version: '2022.3.1' + implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: '2022.3.1' +} \ No newline at end of file diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/InternalApi.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/InternalApi.kt new file mode 100644 index 000000000..4bf6bdab6 --- /dev/null +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/InternalApi.kt @@ -0,0 +1,71 @@ +package org.utbot.jcdb.remote.rd + +import com.jetbrains.rd.framework.* +import kotlin.reflect.KClass + +val serializers = Serializers().also { + it.register(GetClasspathReq) + it.register(GetClassReq) + it.register(GetClassRes) +} + + +class GetClasspathReq(val locations: List) { + + companion object : IMarshaller { + + override val _type: KClass = GetClasspathReq::class + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): GetClasspathReq { + return GetClasspathReq( + buffer.readArray { + buffer.readString() + }.toList() + ) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GetClasspathReq) { + buffer.writeArray(value.locations.toTypedArray()) { + buffer.writeString(it) + } + } + } +} + +class GetClassReq(val cpKey: String, val className: String) { + + companion object : IMarshaller { + + override val _type: KClass = GetClassReq::class + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): GetClassReq { + return GetClassReq( + buffer.readString(), + buffer.readString() + ) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GetClassReq) { + buffer.writeString(value.cpKey) + buffer.writeString(value.className) + } + } +} + +class GetClassRes(val bytes: ByteArray) { + + companion object : IMarshaller { + + override val _type: KClass = GetClassRes::class + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): GetClassRes { + return GetClassRes( + buffer.readByteArray() + ) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GetClassRes) { + buffer.writeByteArray(value.bytes) + } + } +} \ No newline at end of file diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDClient.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDClient.kt new file mode 100644 index 000000000..baae9ab3f --- /dev/null +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDClient.kt @@ -0,0 +1,78 @@ +package org.utbot.jcdb.remote.rd + +import com.jetbrains.rd.framework.* +import com.jetbrains.rd.framework.base.IRdBindable +import com.jetbrains.rd.framework.base.static +import com.jetbrains.rd.framework.impl.RdCall +import com.jetbrains.rd.util.lifetime.Lifetime +import com.jetbrains.rd.util.threading.SingleThreadScheduler +import org.utbot.jcdb.api.ByteCodeLocation +import org.utbot.jcdb.api.ClasspathSet +import org.utbot.jcdb.api.CompilationDatabase +import org.utbot.jcdb.remote.rd.client.RemoteClasspathSet +import java.io.File + +class RDClient(port: Int) : CompilationDatabase { + + private val lifetimeDef = Lifetime.Eternal.createNested() + private val scheduler = SingleThreadScheduler(lifetimeDef, "rd-scheduler") + + private val clientProtocol = Protocol( + "rd-client-$port", + serializers, + Identities(IdKind.Client), + scheduler, + SocketWire.Client(lifetimeDef, scheduler, port), + lifetimeDef + ) + + private val getClasspath = RdCall().static(1) + private val getClass = RdCall().static(2) + private val closeClasspath = RdCall().static(3) + + init { + clientProtocol.bindStatic(getClasspath, "client-get-classpath") + clientProtocol.bindStatic(getClass, "client-get-class") + clientProtocol.bindStatic(closeClasspath, "client-close-classpath") + } + + override suspend fun classpathSet(dirOrJars: List): ClasspathSet { + val id = getClasspath.startSuspending(GetClasspathReq(dirOrJars.map { it.absolutePath })) + return RemoteClasspathSet( + id, + close = closeClasspath, + getClass = getClass + ) + } + + override suspend fun load(dirOrJar: File): CompilationDatabase { + TODO("Not yet implemented") + } + + override suspend fun load(dirOrJars: List): CompilationDatabase { + TODO("Not yet implemented") + } + + override suspend fun loadLocations(locations: List): CompilationDatabase { + TODO("Not yet implemented") + } + + override suspend fun refresh() { + } + + override fun watchFileSystemChanges() = this + + override suspend fun awaitBackgroundJobs() { + } + + private fun IProtocol.bindStatic(x: T, name: String): T { + x.bind(lifetimeDef, this, name) + return x + } + + override fun close() { + lifetimeDef.terminate() + } +} + + diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDServer.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDServer.kt new file mode 100644 index 000000000..f79afbe0e --- /dev/null +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RDServer.kt @@ -0,0 +1,87 @@ +package org.utbot.jcdb.remote.rd + +import com.jetbrains.rd.framework.* +import com.jetbrains.rd.framework.base.IRdBindable +import com.jetbrains.rd.framework.base.static +import com.jetbrains.rd.framework.impl.RdCall +import com.jetbrains.rd.util.lifetime.Lifetime +import com.jetbrains.rd.util.threading.SingleThreadScheduler +import kotlinx.coroutines.runBlocking +import org.utbot.jcdb.api.ClasspathSet +import org.utbot.jcdb.api.Hook +import org.utbot.jcdb.compilationDatabase +import org.utbot.jcdb.impl.CompilationDatabaseImpl +import java.io.File +import java.util.concurrent.ConcurrentHashMap + + +class RDServer(port: Int, val db: CompilationDatabaseImpl) : Hook { + + private val lifetimeDef = Lifetime.Eternal.createNested() + + private val classpaths = ConcurrentHashMap() + private val scheduler = SingleThreadScheduler(lifetimeDef, "rd-scheduler") + + private val serverProtocol = Protocol( + "rd-server", + serializers, + Identities(IdKind.Server), + scheduler, + SocketWire.Server(lifetimeDef, scheduler, port, allowRemoteConnections = false), + lifetimeDef + ) + + private val getClasspath = RdCall(null, null) { req -> + val key = req.locations.joinToString() + val cp = runBlocking { + db.classpathSet(req.locations.map { File(it) }) + } + classpaths[key] = cp + key + } + + private val closeClasspath = RdCall(null, null) { req -> + classpaths[req]?.close() + } + + private val getClass = RdCall(null, null) { req -> + val key = req.cpKey + val cp = classpaths[key] ?: throw IllegalStateException("No classpath found by key $key. \n Create it first") + GetClassRes(ByteArray(1)) + } + + override fun afterStart() { + getClasspath.static(1) + closeClasspath.static(3) + getClass.static(2) + + serverProtocol.bindStatic(getClasspath, "get-classpath") + serverProtocol.bindStatic(closeClasspath, "close-classpath") + serverProtocol.bindStatic(getClass, "get-class") + } + + override fun afterStop() { + lifetimeDef.terminate() + } + + private fun IProtocol.bindStatic(x: T, name: String): T { + x.bind(lifetimeDef, this, name) + return x + } + +} + +fun main() { + val db = runBlocking { + compilationDatabase { + useProcessJavaRuntime() + } as CompilationDatabaseImpl + } + RDServer(8080, db).afterStart() + + val client = RDClient(8080) + runBlocking { + val classpathSet = client.classpathSet(emptyList()) + println(classpathSet) + } +} \ No newline at end of file diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClassId.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClassId.kt new file mode 100644 index 000000000..068373a3e --- /dev/null +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClassId.kt @@ -0,0 +1,64 @@ +package org.utbot.jcdb.remote.rd.client + +import org.objectweb.asm.tree.ClassNode +import org.utbot.jcdb.api.* +import org.utbot.jcdb.impl.fs.ByteCodeConverter +import org.utbot.jcdb.impl.signature.TypeResolution + +class RemoteClassId(private val node: ClassNode, override val classpath: ClasspathSet) : ClassId, ByteCodeConverter { + + private val classInfo = node.asClassInfo() + + override val name: String + get() = classInfo.name + + override suspend fun access() = classInfo.access + + override val location: ByteCodeLocation? + get() = null + + override val simpleName: String + get() = classInfo.name + + override suspend fun byteCode() = node + + override suspend fun innerClasses(): List { + TODO("Not yet implemented") + } + + override suspend fun outerClass(): ClassId? { + TODO("Not yet implemented") + } + + override suspend fun isAnonymous(): Boolean { + TODO("Not yet implemented") + } + + override suspend fun signature(): TypeResolution { + TODO("Not yet implemented") + } + + override suspend fun outerMethod(): MethodId? { + TODO("Not yet implemented") + } + + override suspend fun methods(): List { + TODO("Not yet implemented") + } + + override suspend fun superclass(): ClassId? { + TODO("Not yet implemented") + } + + override suspend fun interfaces(): List { + TODO("Not yet implemented") + } + + override suspend fun annotations(): List { + TODO("Not yet implemented") + } + + override suspend fun fields(): List { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClasspathSet.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClasspathSet.kt new file mode 100644 index 000000000..dcbe2943d --- /dev/null +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteClasspathSet.kt @@ -0,0 +1,57 @@ +package org.utbot.jcdb.remote.rd.client + +import com.jetbrains.rd.framework.impl.RdCall +import org.objectweb.asm.ClassReader +import org.objectweb.asm.Opcodes +import org.objectweb.asm.tree.ClassNode +import org.utbot.jcdb.api.ByteCodeLocation +import org.utbot.jcdb.api.ClassId +import org.utbot.jcdb.api.ClasspathSet +import org.utbot.jcdb.api.CompilationDatabase +import org.utbot.jcdb.remote.rd.GetClassReq +import org.utbot.jcdb.remote.rd.GetClassRes + +class RemoteClasspathSet( + private val key: String, + private val getClass: RdCall, + private val close: RdCall +) : ClasspathSet { + + override val locations: List + get() = emptyList() + + override val db: CompilationDatabase + get() = TODO("Not yet implemented") + + override suspend fun refreshed(closeOld: Boolean) = this + + override suspend fun findClassOrNull(name: String): ClassId? { + val res = getClass.startSuspending(GetClassReq(key, name)) + val node = ClassNode(Opcodes.ASM9).also { + ClassReader(res.bytes).accept(it, ClassReader.EXPAND_FRAMES) + } + val classNode = res.bytes + return null + } + + override suspend fun findSubClasses(name: String, allHierarchy: Boolean): List { + TODO("Not yet implemented") + } + + override suspend fun findSubClasses(classId: ClassId, allHierarchy: Boolean): List { + TODO("Not yet implemented") + } + + override suspend fun query(key: String, term: String): List { + TODO("Not yet implemented") + } + + override suspend fun query(key: String, location: ByteCodeLocation, term: String): List { + TODO("Not yet implemented") + } + + override fun close() { + close.start(id) + } + +} \ No newline at end of file diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/rd.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/rd.kt new file mode 100644 index 000000000..299a96a33 --- /dev/null +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/rd.kt @@ -0,0 +1,14 @@ +package org.utbot.jcdb.remote.rd + +import org.utbot.jcdb.CompilationDatabaseSettings +import org.utbot.jcdb.api.CompilationDatabase + +fun CompilationDatabaseSettings.rd(port: Int) { + withHook { + RDServer(port, it) + } +} + +fun remoteRdDatabase(port: Int): CompilationDatabase { + return RDClient(port) +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 4f2901032..a065e8516 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,4 @@ -rootProject.name = 'jcdb' \ No newline at end of file +rootProject.name = 'jcdb' + +include 'core' +include 'remote-rd'