mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 15:56:48 +08:00
fix(projects): remove IProjectManager.app
This commit is contained in:
@@ -20,7 +20,7 @@ package com.itsaky.androidide.lsp.java
|
||||
import com.itsaky.androidide.lsp.api.ILanguageServerRegistry
|
||||
import com.itsaky.androidide.lsp.api.LSPTest
|
||||
import com.itsaky.androidide.lsp.java.compiler.JavaCompilerService
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.util.findAppModule
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
|
||||
@@ -30,7 +30,7 @@ object JavaLSPTest : LSPTest() {
|
||||
|
||||
val server by lazy {
|
||||
ILanguageServerRegistry.getDefault().getServer(JavaLanguageServer.SERVER_ID)
|
||||
as JavaLanguageServer
|
||||
as JavaLanguageServer
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -46,7 +46,7 @@ object JavaLSPTest : LSPTest() {
|
||||
override fun getServerId() = JavaLanguageServer.SERVER_ID
|
||||
|
||||
fun getCompiler(): JavaCompilerService {
|
||||
return JavaCompilerProvider.get(IProjectManager.getInstance().app)
|
||||
return JavaCompilerProvider.get(findAppModule()!!)
|
||||
}
|
||||
|
||||
override fun test() {}
|
||||
|
||||
@@ -19,8 +19,8 @@ package com.itsaky.androidide.lsp.xml
|
||||
import com.itsaky.androidide.lookup.Lookup
|
||||
import com.itsaky.androidide.lsp.api.ILanguageServerRegistry
|
||||
import com.itsaky.androidide.lsp.api.LSPTest
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.api.ModuleProject
|
||||
import com.itsaky.androidide.projects.util.findAppModule
|
||||
import com.itsaky.androidide.xml.resources.ResourceTableRegistry
|
||||
import com.itsaky.androidide.xml.versions.ApiVersions
|
||||
import com.itsaky.androidide.xml.widgets.WidgetTable
|
||||
@@ -38,11 +38,11 @@ object XMLLSPTest : LSPTest() {
|
||||
}
|
||||
super.initProjectIfNeeded()
|
||||
try {
|
||||
val module = IProjectManager.getInstance().app!!
|
||||
val module = findAppModule()!!
|
||||
val lookup = Lookup.getDefault()
|
||||
|
||||
|
||||
lookup.update(ModuleProject.COMPLETION_MODULE_KEY, module)
|
||||
|
||||
|
||||
val versions = module.getApiVersions()
|
||||
if (versions != null) {
|
||||
lookup.update(ApiVersions.COMPLETION_LOOKUP_KEY, versions)
|
||||
@@ -52,7 +52,7 @@ object XMLLSPTest : LSPTest() {
|
||||
if (widgets != null) {
|
||||
lookup.update(WidgetTable.COMPLETION_LOOKUP_KEY, widgets)
|
||||
}
|
||||
|
||||
|
||||
val frameworkResources = module.getFrameworkResourceTable()
|
||||
if (frameworkResources != null) {
|
||||
lookup.update(ResourceTableRegistry.COMPLETION_FRAMEWORK_RES, frameworkResources)
|
||||
@@ -62,12 +62,12 @@ object XMLLSPTest : LSPTest() {
|
||||
if (moduleResources.isNotEmpty()) {
|
||||
lookup.update(ResourceTableRegistry.COMPLETION_MODULE_RES, moduleResources)
|
||||
}
|
||||
|
||||
|
||||
val depResTables = module.getDependencyResourceTables()
|
||||
if (depResTables.isNotEmpty()) {
|
||||
lookup.update(ResourceTableRegistry.COMPLETION_DEP_RES, depResTables)
|
||||
}
|
||||
|
||||
|
||||
val manifestAttrTable = module.getManifestAttrTable()
|
||||
if (manifestAttrTable != null) {
|
||||
lookup.update(ResourceTableRegistry.COMPLETION_MANIFEST_ATTR_RES, manifestAttrTable)
|
||||
|
||||
+2
-7
@@ -57,11 +57,6 @@ interface IProjectManager {
|
||||
*/
|
||||
val rootProject: Project?
|
||||
|
||||
/**
|
||||
* The Android application module in the project.
|
||||
*/
|
||||
val app: AndroidModule?
|
||||
|
||||
/**
|
||||
* The path to the project's root directory.
|
||||
*/
|
||||
@@ -102,14 +97,14 @@ interface IProjectManager {
|
||||
*
|
||||
* @return The list of Android application modules.
|
||||
*/
|
||||
fun getAndroidAppModules() : List<AndroidModule>
|
||||
fun getAndroidAppModules(): List<AndroidModule>
|
||||
|
||||
/**
|
||||
* Get the list of modules in this project which are Android library modules.
|
||||
*
|
||||
* @return The list of Android library modules.
|
||||
*/
|
||||
fun getAndroidLibraryModules() : List<AndroidModule>
|
||||
fun getAndroidLibraryModules(): List<AndroidModule>
|
||||
|
||||
/**
|
||||
* Find the module for the given file.
|
||||
|
||||
+1
-15
@@ -34,7 +34,6 @@ import com.itsaky.androidide.projects.api.Project
|
||||
import com.itsaky.androidide.projects.builder.BuildService
|
||||
import com.itsaky.androidide.projects.util.ProjectTransformer
|
||||
import com.itsaky.androidide.tasks.executeAsync
|
||||
import com.itsaky.androidide.tasks.executeAsyncProvideError
|
||||
import com.itsaky.androidide.tooling.api.IAndroidProject
|
||||
import com.itsaky.androidide.tooling.api.IProject
|
||||
import com.itsaky.androidide.tooling.api.ProjectType
|
||||
@@ -69,8 +68,6 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
|
||||
override var rootProject: Project? = null
|
||||
private set
|
||||
override var app: AndroidModule? = null
|
||||
private set
|
||||
|
||||
override var androidBuildVariants: Map<String, BuildVariantInfo> = emptyMap()
|
||||
private set
|
||||
@@ -100,8 +97,6 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
androidBuildVariants = buildVariants
|
||||
}
|
||||
|
||||
this.app = this.rootProject!!.findFirstAndroidAppModule()
|
||||
|
||||
this.rootProject!!.subProjects.filterIsInstance(ModuleProject::class.java).forEach {
|
||||
it.indexSourcesAndClasspaths()
|
||||
if (it is AndroidModule) {
|
||||
@@ -171,7 +166,6 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
override fun destroy() {
|
||||
log.info("Destroying project manager")
|
||||
this.rootProject = null
|
||||
this.app = null
|
||||
this.cachedInitResult = null
|
||||
this.projectInitialized = false
|
||||
|
||||
@@ -192,11 +186,6 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
return
|
||||
}
|
||||
|
||||
if (app == null) {
|
||||
log.warn("Cannot run resource and source generation task. No application module found.")
|
||||
return
|
||||
}
|
||||
|
||||
val tasks = getAndroidModules().flatMap { module ->
|
||||
val variant = module.getSelectedVariant()
|
||||
if (variant == null) {
|
||||
@@ -220,10 +209,7 @@ class ProjectManagerImpl : IProjectManager, EventReceiver {
|
||||
|
||||
|
||||
builder
|
||||
.executeProjectTasks(
|
||||
app!!.path,
|
||||
*tasks.toTypedArray()
|
||||
)
|
||||
.executeTasks(*tasks.toTypedArray())
|
||||
.whenComplete { result, taskErr ->
|
||||
if (result == null || !result.isSuccessful || taskErr != null) {
|
||||
log.warn(
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.projects.util
|
||||
|
||||
import androidx.annotation.RestrictTo
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.api.AndroidModule
|
||||
|
||||
/**
|
||||
* **For testing purposes only!**
|
||||
*/
|
||||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
|
||||
fun findAppModule(): AndroidModule? {
|
||||
return IProjectManager.getInstance().getAndroidAppModules().firstOrNull { it.path == ":app" }
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import com.itsaky.androidide.inflater.internal.utils.IDTable
|
||||
import com.itsaky.androidide.inflater.utils.newAttribute
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.api.AndroidModule
|
||||
import com.itsaky.androidide.projects.util.findAppModule
|
||||
import org.junit.Before
|
||||
import java.io.File
|
||||
import org.junit.Test
|
||||
@@ -228,7 +229,7 @@ class LayoutInflaterTest {
|
||||
}
|
||||
|
||||
private fun layoutFile(name: String): File {
|
||||
val app = IProjectManager.getInstance().app ?: throw IllegalStateException("GradleProject is not initialized")
|
||||
val app = findAppModule() ?: throw IllegalStateException("GradleProject is not initialized")
|
||||
return File(app.projectDir, "src/main/res/layout/$name.xml")
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.itsaky.androidide.lookup.Lookup
|
||||
import com.itsaky.androidide.projects.IProjectManager
|
||||
import com.itsaky.androidide.projects.api.AndroidModule
|
||||
import com.itsaky.androidide.projects.builder.BuildService
|
||||
import com.itsaky.androidide.projects.util.findAppModule
|
||||
import com.itsaky.androidide.tooling.api.messages.InitializeProjectParams
|
||||
import com.itsaky.androidide.tooling.testing.ToolingApiTestLauncher
|
||||
import com.itsaky.androidide.utils.FileProvider
|
||||
@@ -55,7 +56,7 @@ object XmlInflaterTest {
|
||||
|
||||
fun inflaterTest(block: (AndroidModule) -> Unit) {
|
||||
XmlInflaterTest.initIfNeeded()
|
||||
val app = IProjectManager.getInstance().app!!
|
||||
val app = findAppModule()!!
|
||||
startParse(app)
|
||||
block(app)
|
||||
endParse()
|
||||
|
||||
Reference in New Issue
Block a user