Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature]
workspace/directories
implementation
symlinks are excluded by default review empty lines rebase fix Merge remote-tracking branch 'origin/master' into abrams/directories_endpoint # Conflicts: # executioncontext/workspacecontext/src/main/kotlin/org/jetbrains/bsp/bazel/workspacecontext/DirectoriesSpec.kt # executioncontext/workspacecontext/src/test/kotlin/org/jetbrains/bsp/bazel/workspacecontext/DirectoriesSpecExtractorTest.kt # server/src/main/kotlin/org/jetbrains/bsp/bazel/server/sync/ProjectSyncService.java # server/src/main/kotlin/org/jetbrains/bsp/bazel/server/sync/ProjectSyncService.kt endpoint impl directories spec! ProjectSyncService is now kotlin! Rename .java to .kt Merge-request: BAZEL-MR-497 Merged-by: Marcin Abramowicz <marcin.abramowicz@jetbrains.com>
- Loading branch information
Showing
10 changed files
with
354 additions
and
165 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...kspacecontext/src/main/kotlin/org/jetbrains/bsp/bazel/workspacecontext/DirectoriesSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jetbrains.bsp.bazel.workspacecontext | ||
|
||
import org.jetbrains.bsp.bazel.executioncontext.api.ExecutionContextEntityExtractor | ||
import org.jetbrains.bsp.bazel.executioncontext.api.ExecutionContextExcludableListEntity | ||
import org.jetbrains.bsp.bazel.projectview.model.ProjectView | ||
import org.jetbrains.bsp.bazel.projectview.model.sections.ProjectViewDirectoriesSection | ||
import java.nio.file.Path | ||
|
||
data class DirectoriesSpec( | ||
override val values: List<Path>, | ||
override val excludedValues: List<Path>, | ||
) : ExecutionContextExcludableListEntity<Path>() | ||
|
||
internal class DirectoriesSpecExtractor(private val workspaceRoot: Path) | ||
: ExecutionContextEntityExtractor<DirectoriesSpec> { | ||
|
||
override fun fromProjectView(projectView: ProjectView): DirectoriesSpec = | ||
projectView.directories?.toDirectoriesSpec() | ||
?: DirectoriesSpec( | ||
values = listOf(workspaceRoot), | ||
excludedValues = emptyList(), | ||
) | ||
|
||
private fun ProjectViewDirectoriesSection.toDirectoriesSpec(): DirectoriesSpec = | ||
DirectoriesSpec( | ||
values = values.map { it.resolveAndNormalize() }, | ||
excludedValues = excludedValues.map { it.resolveAndNormalize() }, | ||
) | ||
|
||
private fun Path.resolveAndNormalize() = | ||
workspaceRoot.resolve(this).normalize() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../src/test/kotlin/org/jetbrains/bsp/bazel/workspacecontext/DirectoriesSpecExtractorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.jetbrains.bsp.bazel.workspacecontext | ||
|
||
import io.kotest.matchers.shouldBe | ||
import org.jetbrains.bsp.bazel.projectview.model.ProjectView | ||
import org.jetbrains.bsp.bazel.projectview.model.sections.ProjectViewDirectoriesSection | ||
import org.junit.jupiter.api.Test | ||
import kotlin.io.path.Path | ||
|
||
class DirectoriesSpecExtractorTest { | ||
|
||
@Test | ||
fun `should return workspace root if directories section is null`() { | ||
// given | ||
val workspaceRoot = Path("path/to/workspace") | ||
val projectView = ProjectView.Builder(directories = null).build() | ||
|
||
// when | ||
val directoriesSpec = DirectoriesSpecExtractor(workspaceRoot).fromProjectView(projectView) | ||
|
||
// then | ||
val expectedDirectoriesSpec = DirectoriesSpec( | ||
values = listOf(workspaceRoot), | ||
excludedValues = emptyList() | ||
) | ||
directoriesSpec shouldBe expectedDirectoriesSpec | ||
} | ||
|
||
@Test | ||
fun `should return workspace root if directories section contains only dot wildcard`() { | ||
// given | ||
val workspaceRoot = Path("path/to/workspace") | ||
val projectView = ProjectView.Builder( | ||
directories = ProjectViewDirectoriesSection( | ||
values = listOf(Path(".")), | ||
excludedValues = emptyList() | ||
) | ||
).build() | ||
|
||
// when | ||
val directoriesSpec = DirectoriesSpecExtractor(workspaceRoot).fromProjectView(projectView) | ||
|
||
// then | ||
val expectedDirectoriesSpec = DirectoriesSpec( | ||
values = listOf(workspaceRoot), | ||
excludedValues = emptyList() | ||
) | ||
directoriesSpec shouldBe expectedDirectoriesSpec | ||
} | ||
|
||
@Test | ||
fun `should return resolved paths if directories section is not null`() { | ||
// given | ||
val workspaceRoot = Path("path/to/workspace") | ||
val projectView = ProjectView.Builder( | ||
directories = ProjectViewDirectoriesSection( | ||
values = listOf(Path("path/to/included1"), Path("path/to/included2")), | ||
excludedValues = listOf(Path("path/to/excluded")), | ||
) | ||
).build() | ||
|
||
// when | ||
val directoriesSpec = DirectoriesSpecExtractor(workspaceRoot).fromProjectView(projectView) | ||
|
||
// then | ||
val expectedDirectoriesSpec = DirectoriesSpec( | ||
values = listOf( | ||
workspaceRoot.resolve("path/to/included1"), | ||
workspaceRoot.resolve("path/to/included2") | ||
), | ||
excludedValues = listOf(workspaceRoot.resolve("path/to/excluded")) | ||
) | ||
directoriesSpec shouldBe expectedDirectoriesSpec | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.