mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: make ProjectManagerImpl internal to app module
This commit is contained in:
+18
-10
@@ -89,14 +89,10 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
get() = rootProject?.projectSyncIssues
|
||||
|
||||
companion object {
|
||||
|
||||
private val log = LoggerFactory.getLogger(ProjectManagerImpl::class.java)
|
||||
|
||||
@JvmStatic
|
||||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
|
||||
fun getInstance(): ProjectManagerImpl {
|
||||
return IProjectManager.getInstance() as ProjectManagerImpl
|
||||
}
|
||||
fun getInstance(): ProjectManagerImpl = IProjectManager.getInstance() as ProjectManagerImpl
|
||||
}
|
||||
|
||||
override suspend fun setupProject(project: IProject) {
|
||||
@@ -327,7 +323,7 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
return@apply
|
||||
}
|
||||
|
||||
val module = IProjectManager.getInstance().findModuleForFile(this, false) ?: return@apply
|
||||
val module = findModuleForFile(this, false) ?: return@apply
|
||||
if (module !is AndroidModule) {
|
||||
return@apply
|
||||
}
|
||||
@@ -344,13 +340,25 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
override fun notifyFileCreated(file: File) {
|
||||
onFileCreated(FileCreationEvent(file))
|
||||
}
|
||||
|
||||
override fun notifyFileDeleted(file: File) {
|
||||
onFileDeleted(FileDeletionEvent(file))
|
||||
}
|
||||
|
||||
override fun notifyFileRenamed(from: File, to: File) {
|
||||
onFileRenamed(FileRenameEvent(from, to))
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
fun onFileCreated(event: FileCreationEvent) {
|
||||
generateSourcesIfNecessary(event)
|
||||
|
||||
if (DocumentUtils.isJavaFile(event.file.toPath())) {
|
||||
IProjectManager.getInstance().findModuleForFile(event.file, false)?.let {
|
||||
findModuleForFile(event.file, false)?.let {
|
||||
val sourceRoot = it.findSourceRoot(event.file) ?: return@let
|
||||
|
||||
// add the source node entry
|
||||
@@ -368,7 +376,7 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
// Do not check for Java file DocumentUtils.isJavaFile(...) as it checks for file existence as
|
||||
// well. As the file is already deleted, it will always return false
|
||||
if (event.file.extension == "java") {
|
||||
IProjectManager.getInstance().findModuleForFile(event.file, false)
|
||||
findModuleForFile(event.file, false)
|
||||
?.compileJavaSourceClasses
|
||||
?.findSource(event.file.toPath())
|
||||
?.let { it.parent?.removeChild(it) }
|
||||
@@ -384,14 +392,14 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
// well. As the file is already renamed to another filename, it will always return false
|
||||
if (event.file.extension == "java") {
|
||||
// remove the source node entry
|
||||
IProjectManager.getInstance().findModuleForFile(event.file, false)
|
||||
findModuleForFile(event.file, false)
|
||||
?.compileJavaSourceClasses
|
||||
?.findSource(event.file.toPath())
|
||||
?.let { it.parent?.removeChild(it) }
|
||||
}
|
||||
|
||||
if (DocumentUtils.isJavaFile(event.newFile.toPath())) {
|
||||
IProjectManager.getInstance().findModuleForFile(event.newFile, false)?.let {
|
||||
findModuleForFile(event.newFile, false)?.let {
|
||||
val sourceRoot = it.findSourceRoot(event.newFile) ?: return@let
|
||||
// add the new source node entry
|
||||
it.compileJavaSourceClasses.append(event.newFile.toPath(), sourceRoot)
|
||||
+10
-12
@@ -18,12 +18,8 @@
|
||||
package com.itsaky.androidide.projects.api
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.itsaky.androidide.eventbus.events.file.FileCreationEvent
|
||||
import com.itsaky.androidide.eventbus.events.file.FileDeletionEvent
|
||||
import com.itsaky.androidide.eventbus.events.file.FileRenameEvent
|
||||
import com.itsaky.androidide.lookup.Lookup
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.ProjectManagerImpl
|
||||
import com.itsaky.androidide.projects.builder.BuildService
|
||||
import com.itsaky.androidide.testing.tooling.ToolingApiTestLauncher
|
||||
import com.itsaky.androidide.tooling.api.IAndroidProject
|
||||
@@ -149,8 +145,8 @@ class ModuleProjectTest {
|
||||
assertThat(
|
||||
filter {
|
||||
it.absolutePath.endsWith("appcompat-1.5.1/jars/classes.jar") ||
|
||||
it.absolutePath.endsWith("material-1.8.0-alpha01/jars/classes.jar") ||
|
||||
it.absolutePath.endsWith("coordinatorlayout-1.2.0/jars/classes.jar")
|
||||
it.absolutePath.endsWith("material-1.8.0-alpha01/jars/classes.jar") ||
|
||||
it.absolutePath.endsWith("coordinatorlayout-1.2.0/jars/classes.jar")
|
||||
}
|
||||
)
|
||||
.hasSize(3)
|
||||
@@ -172,7 +168,8 @@ class ModuleProjectTest {
|
||||
|
||||
for (klass in arrayOf(
|
||||
"com.itsaky.androidide.tooling.test.Main",
|
||||
"com.itsaky.test.app.MainActivity")
|
||||
"com.itsaky.test.app.MainActivity"
|
||||
)
|
||||
) {
|
||||
|
||||
classes.find { it.qualifiedName == klass }.let {
|
||||
@@ -208,7 +205,7 @@ class ModuleProjectTest {
|
||||
Files.delete(testCls_renamed)
|
||||
}
|
||||
|
||||
val projectManager = ProjectManagerImpl.getInstance()
|
||||
val projectManager = IProjectManager.getInstance()
|
||||
runBlocking { projectManager.setupProject() }
|
||||
|
||||
val rootProject = IProjectManager.getInstance().rootProject
|
||||
@@ -239,22 +236,23 @@ class ModuleProjectTest {
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls_renamed)).isFalse()
|
||||
|
||||
testCls.writeText("public class Test { }")
|
||||
projectManager.onFileCreated(FileCreationEvent(testCls.toFile()))
|
||||
projectManager.notifyFileCreated(testCls.toFile())
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls)).isTrue()
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls_renamed)).isFalse()
|
||||
assertThat(IProjectManager.getInstance().findModuleForFile(testCls, true)).isEqualTo(module)
|
||||
assertThat(IProjectManager.getInstance().findModuleForFile(testCls_renamed, true)).isNull()
|
||||
|
||||
Files.move(testCls, testCls_renamed)
|
||||
projectManager.onFileRenamed(FileRenameEvent(testCls.toFile(), testCls_renamed.toFile()))
|
||||
projectManager.notifyFileRenamed(testCls.toFile(), testCls_renamed.toFile())
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls)).isFalse()
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls_renamed)).isTrue()
|
||||
assertThat(IProjectManager.getInstance().findModuleForFile(testCls, true)).isNull()
|
||||
assertThat(IProjectManager.getInstance().findModuleForFile(testCls_renamed, true)).isEqualTo(
|
||||
module)
|
||||
module
|
||||
)
|
||||
|
||||
Files.delete(testCls_renamed)
|
||||
projectManager.onFileDeleted(FileDeletionEvent(testCls_renamed.toFile()))
|
||||
projectManager.notifyFileDeleted(testCls_renamed.toFile())
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls)).isFalse()
|
||||
assertThat(IProjectManager.getInstance().containsSourceFile(testCls_renamed)).isFalse()
|
||||
assertThat(IProjectManager.getInstance().findModuleForFile(testCls, true)).isNull()
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.itsaky.androidide.lsp.testing
|
||||
import android.content.Context
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import com.itsaky.androidide.actions.ActionData
|
||||
import com.itsaky.androidide.eventbus.events.EventReceiver
|
||||
import com.itsaky.androidide.eventbus.events.editor.ChangeType.DELETE
|
||||
import com.itsaky.androidide.eventbus.events.editor.DocumentChangeEvent
|
||||
import com.itsaky.androidide.eventbus.events.editor.DocumentCloseEvent
|
||||
@@ -34,7 +35,7 @@ import com.itsaky.androidide.models.Range
|
||||
import com.itsaky.androidide.preferences.internal.EditorPreferences
|
||||
import com.itsaky.androidide.preferences.internal.prefManager
|
||||
import com.itsaky.androidide.projects.FileManager
|
||||
import com.itsaky.androidide.projects.ProjectManagerImpl
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.builder.BuildService
|
||||
import com.itsaky.androidide.testing.tooling.ToolingApiTestLauncher
|
||||
import com.itsaky.androidide.tooling.api.IProject
|
||||
@@ -108,8 +109,13 @@ abstract class LSPTest(
|
||||
Environment.JAVA_HOME = File(System.getProperty("java.home")!!)
|
||||
registerServer()
|
||||
|
||||
val projectManager = ProjectManagerImpl.getInstance()
|
||||
projectManager.register()
|
||||
val projectManager = IProjectManager.getInstance()
|
||||
if (projectManager is EventReceiver) {
|
||||
projectManager.register()
|
||||
} else {
|
||||
throw IllegalStateException("Expected IProjectManager instance to be an EventReceiver")
|
||||
}
|
||||
|
||||
runBlocking { projectManager.setupProject(project) }
|
||||
|
||||
// We need to manually setup the language server with the project here
|
||||
|
||||
Reference in New Issue
Block a user