mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix(tooling-api): remove usage of hardcoded root project path
This commit is contained in:
+2
-2
@@ -45,9 +45,9 @@ class ProjectTransformer {
|
||||
fun transform(project: IProject): Project? {
|
||||
try {
|
||||
val allProjects = project.getProjects().get()
|
||||
val selectionResult = project.selectProject(StringParameter(IProject.ROOT_PROJECT_PATH)).get()
|
||||
val selectionResult = project.selectProject(StringParameter("")).get()
|
||||
check(selectionResult.isSuccessful) {
|
||||
"Cannot find root project with path '${IProject.ROOT_PROJECT_PATH}'"
|
||||
"Cannot find root project"
|
||||
}
|
||||
|
||||
val rootProject = when (project.getType().get()) {
|
||||
|
||||
+5
-1
@@ -148,7 +148,11 @@ internal class ToolingApiServerImpl(private val project: ProjectImpl) :
|
||||
|
||||
var projectPath = message.projectPath
|
||||
if (projectPath == null) {
|
||||
projectPath = IProject.ROOT_PROJECT_PATH
|
||||
projectPath = project.rootProjectPath
|
||||
}
|
||||
|
||||
checkNotNull(projectPath) {
|
||||
"Unable to determine root project path"
|
||||
}
|
||||
|
||||
val project = this.project.run {
|
||||
|
||||
+9
-3
@@ -34,8 +34,11 @@ import java.util.concurrent.CompletableFuture
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@Suppress("JoinDeclarationAndAssignment")
|
||||
internal class ProjectImpl(var rootProject: IGradleProject? = null,
|
||||
var projects: List<IGradleProject> = emptyList()) : IProject, Serializable {
|
||||
internal class ProjectImpl(
|
||||
var rootProject: IGradleProject? = null,
|
||||
var rootProjectPath: String? = null,
|
||||
var projects: List<IGradleProject> = emptyList()
|
||||
) : IProject, Serializable {
|
||||
|
||||
private val serialVersionUID = 1L
|
||||
|
||||
@@ -48,11 +51,14 @@ internal class ProjectImpl(var rootProject: IGradleProject? = null,
|
||||
private val selectedProject: ForwardingProject
|
||||
|
||||
init {
|
||||
require((rootProject == null) == (rootProjectPath == null)) {
|
||||
"rootProject, rootProjectPath: both must be specified or null"
|
||||
}
|
||||
this.selectedProject = ForwardingProject()
|
||||
}
|
||||
|
||||
private fun getProject(path: String): IGradleProject? {
|
||||
return if (IProject.ROOT_PROJECT_PATH == path) rootProject else projects.find {
|
||||
return if (path.isBlank()) rootProject else projects.find {
|
||||
it.getMetadata().get().projectPath == path
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -49,9 +49,9 @@ class RootModelBuilder(initializationParams: InitializeProjectParams) :
|
||||
|
||||
val ideaModules = ideaProject.modules
|
||||
val modulePaths = mapOf(*ideaModules.map { it.name to it.gradleProject.path }.toTypedArray())
|
||||
val rootModule = ideaModules.find { it.gradleProject.path == IProject.ROOT_PROJECT_PATH }
|
||||
val rootModule = ideaModules.find { it.gradleProject.parent == null }
|
||||
?: throw ModelBuilderException(
|
||||
"No GradleProject model is associated with project path: '${IProject.ROOT_PROJECT_PATH}'")
|
||||
"Unable to find root project")
|
||||
|
||||
val rootProjectVersions = getAndroidVersions(rootModule, controller)
|
||||
|
||||
@@ -68,7 +68,7 @@ class RootModelBuilder(initializationParams: InitializeProjectParams) :
|
||||
ModuleProjectModelBuilderParams(controller, ideaProject, ideaModule, modulePaths))
|
||||
}
|
||||
|
||||
return@action ProjectImpl(rootProject, projects)
|
||||
return@action ProjectImpl(rootProject, rootModule.gradleProject.path, projects)
|
||||
}
|
||||
|
||||
finalizeLauncher(executor)
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ class MultiModuleAndroidProjectTest {
|
||||
val isInitialized = server.isServerInitialized().get()
|
||||
assertThat(isInitialized).isTrue()
|
||||
|
||||
var selectionResult = project.selectProject(StringParameter(IProject.ROOT_PROJECT_PATH)).get()
|
||||
var selectionResult = project.selectProject(StringParameter("")).get()
|
||||
assertThat(selectionResult.isSuccessful).isTrue()
|
||||
assertThat(project.getType().get()).isEqualTo(ProjectType.Gradle)
|
||||
|
||||
|
||||
-5
@@ -47,11 +47,6 @@ interface IProject : IProjectQueries {
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* Gradle project path for the root project.
|
||||
*/
|
||||
const val ROOT_PROJECT_PATH = ":"
|
||||
|
||||
/**
|
||||
* Name that can be used for project whose [BasicProjectMetadata.name] property is null.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ interface IProjectQueries {
|
||||
/**
|
||||
* Select the project to work with. This overwrites the existing selection.
|
||||
*
|
||||
* @param param A [StringParameter] with the project's path as the value.
|
||||
* @param param A [StringParameter] with the project's path as the value. If the value is an empty string, the root project will be selected.
|
||||
*/
|
||||
@JsonRequest
|
||||
fun selectProject(param: StringParameter): CompletableFuture<SelectProjectResult>
|
||||
|
||||
Reference in New Issue
Block a user