Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local project manager work against any folder #8985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/language-server/protocol-project-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ the action.
* If not provided, defaults to `Fail`.
*/
missingComponentAction?: MissingComponentAction;

/**
* Custom directory with the user projects.
*/
projectsDirectory?: string;
}
```

Expand Down Expand Up @@ -399,6 +404,11 @@ interface ProjectCreateRequest {
* If not provided, defaults to `Fail`.
*/
missingComponentAction?: MissingComponentAction;

/**
* Custom directory with the user projects.
*/
projectsDirectory?: string;
}
```

Expand Down Expand Up @@ -445,7 +455,13 @@ This message requests the renaming of a project.
```typescript
interface ProjectRenameRequest {
projectId: UUID;

name: String;

/**
* Custom directory with the user projects.
*/
projectsDirectory?: string;
}
```

Expand Down Expand Up @@ -482,6 +498,11 @@ This message requests the deletion of a project.
```typescript
interface ProjectDeleteRequest {
projectId: UUID;

/**
* Custom directory with the user projects.
*/
projectsDirectory?: string;
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import scala.util.Try

object Cli {

val JSON_OPTION = "json"
val HELP_OPTION = "help"
val NO_LOG_MASKING = "no-log-masking"
val VERBOSE_OPTION = "verbose"
val VERSION_OPTION = "version"
val PROFILING_PATH = "profiling-path"
val PROFILING_TIME = "profiling-time"
val JSON_OPTION = "json"
val HELP_OPTION = "help"
val NO_LOG_MASKING = "no-log-masking"
val VERBOSE_OPTION = "verbose"
val VERSION_OPTION = "version"
val PROFILING_PATH = "profiling-path"
val PROFILING_TIME = "profiling-time"
val PROJECTS_DIRECTORY = "projects-directory"
val PROJECT_LIST = "project-list"

object option {

Expand Down Expand Up @@ -63,6 +65,23 @@ object Cli {
.longOpt(PROFILING_TIME)
.desc("The duration in seconds limiting the application profiling time.")
.build()

val projectsDirectory: cli.Option = cli.Option.builder
.hasArg(true)
.numberOfArgs(1)
.argName("path")
.longOpt(PROJECTS_DIRECTORY)
.desc("The path to the projects directory.")
.build()

val projectList: cli.Option = cli.Option.builder
.optionalArg(true)
.numberOfArgs(1)
.`type`(classOf[java.lang.Number])
.argName("limit")
.longOpt(PROJECT_LIST)
.desc("List user projects.")
.build()
}

val options: cli.Options =
Expand All @@ -74,6 +93,8 @@ object Cli {
.addOption(option.noLogMasking)
.addOption(option.profilingPath)
.addOption(option.profilingTime)
.addOption(option.projectsDirectory)
.addOption(option.projectList)

/** Parse the command line options. */
def parse(args: Array[String]): Either[String, cli.CommandLine] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import org.enso.projectmanager.infrastructure.languageserver.{
}
import org.enso.projectmanager.infrastructure.log.Slf4jLogging
import org.enso.projectmanager.infrastructure.random.SystemGenerator
import org.enso.projectmanager.infrastructure.repository.ProjectFileRepository
import org.enso.projectmanager.infrastructure.repository.{
ProjectFileRepository,
ProjectFileRepositoryFactory
}
import org.enso.projectmanager.infrastructure.time.RealClock
import org.enso.projectmanager.protocol.{
JsonRpcProtocolFactory,
Expand Down Expand Up @@ -68,6 +71,9 @@ class MainModule[

lazy val projectValidator = new ProjectNameValidator[F]()

lazy val projectRepositoryFactory =
new ProjectFileRepositoryFactory[F](config.storage, clock, fileSystem, gen)

lazy val projectRepository =
new ProjectFileRepository[F](
config.storage,
Expand Down Expand Up @@ -120,7 +126,7 @@ class MainModule[
lazy val projectService =
new ProjectService[F](
projectValidator,
projectRepository,
projectRepositoryFactory,
projectCreationService,
globalConfigService,
logging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package org.enso.projectmanager.boot
import akka.http.scaladsl.Http
import com.typesafe.scalalogging.LazyLogging
import org.apache.commons.cli.CommandLine

import org.enso.projectmanager.boot.Globals.{
ConfigFilename,
ConfigNamespace,
FailureExitCode,
SuccessExitCode
}
import org.enso.projectmanager.boot.command.{CommandHandler, ProjectListCommand}
import org.enso.projectmanager.boot.configuration.{
MainProcessConfig,
ProjectManagerConfig
}
import org.enso.projectmanager.protocol.JsonRpcProtocolFactory
import org.enso.version.VersionDescription
import org.slf4j.event.Level
import pureconfig.ConfigSource
Expand Down Expand Up @@ -41,6 +42,10 @@ object ProjectManager extends ZIOAppDefault with LazyLogging {
.at(ConfigNamespace)
.loadOrThrow[ProjectManagerConfig]

private lazy val commandHandler = new CommandHandler(
new JsonRpcProtocolFactory().getProtocol()
)

val computeThreadPool = new ScheduledThreadPoolExecutor(
java.lang.Runtime.getRuntime.availableProcessors()
)
Expand Down Expand Up @@ -204,6 +209,19 @@ object ProjectManager extends ZIOAppDefault with LazyLogging {
ZIO.succeed(SuccessExitCode)
} else if (options.hasOption(Cli.VERSION_OPTION)) {
displayVersion(options.hasOption(Cli.JSON_OPTION))
} else if (options.hasOption(Cli.PROJECT_LIST)) {
val projectsPathOpt =
Option(options.getOptionValue(Cli.PROJECTS_DIRECTORY))
.map(Paths.get(_).toFile)
val limitOpt = Option(
options
.getParsedOptionValue(Cli.PROJECT_LIST)
.asInstanceOf[java.lang.Number]
)
.map(_.intValue())
val projectListCommand =
ProjectListCommand[ZIO[ZAny, +*, +*]](config, projectsPathOpt, limitOpt)
commandHandler.printJson(projectListCommand.run)
} else {
val verbosity = options.getOptions.count(_ == Cli.option.verbose)
val logMasking = !options.hasOption(Cli.NO_LOG_MASKING)
Expand Down Expand Up @@ -280,5 +298,4 @@ object ProjectManager extends ZIOAppDefault with LazyLogging {
3.seconds
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.enso.projectmanager.boot.command

import org.enso.jsonrpc.{Id, JsonProtocol, Protocol}
import org.enso.projectmanager.boot.Globals.SuccessExitCode
import org.enso.projectmanager.requesthandler.FailureMapper
import zio.{Console, ExitCode, ZAny, ZIO}

final class CommandHandler(protocol: Protocol) {

def printJson[E: FailureMapper](
result: ZIO[ZAny, E, Any]
): ZIO[ZAny, Throwable, ExitCode] =
result
.foldZIO(
e => {
val error = FailureMapper[E].mapFailure(e)
val errorData =
JsonProtocol.ErrorData(error.code, error.message, error.payload)
val response = JsonProtocol.ResponseError(None, errorData)
Console.printLine(JsonProtocol.encode(response))
},
r => {
val response =
JsonProtocol.ResponseResult(
Id.Number(0),
protocol.payloadsEncoder(r)
)
Console.printLine(JsonProtocol.encode(response))
}
)
.map(_ => SuccessExitCode)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.enso.projectmanager.boot.command

import org.enso.projectmanager.boot.configuration.ProjectManagerConfig
import org.enso.projectmanager.control.core.syntax._
import org.enso.projectmanager.control.effect.syntax._
import org.enso.projectmanager.control.core.{Applicative, CovariantFlatMap}
import org.enso.projectmanager.control.effect.{ErrorChannel, Sync}
import org.enso.projectmanager.infrastructure.file.BlockingFileSystem
import org.enso.projectmanager.infrastructure.random.SystemGenerator
import org.enso.projectmanager.infrastructure.repository.{
ProjectFileRepository,
ProjectRepository
}
import org.enso.projectmanager.infrastructure.time.RealClock
import org.enso.projectmanager.protocol.ProjectManagementApi.ProjectList
import org.enso.projectmanager.service.{
ProjectService,
ProjectServiceFailure,
RecentlyUsedProjectsOrdering
}

import java.io.File

final class ProjectListCommand[
F[+_, +_]: ErrorChannel: CovariantFlatMap
](repo: ProjectRepository[F], limitOpt: Option[Int]) {

def run: F[ProjectServiceFailure, ProjectList.Result] =
repo
.getAll()
.map(
_.sorted(RecentlyUsedProjectsOrdering)
.take(limitOpt.getOrElse(Int.MaxValue))
)
.mapError(ProjectService.toServiceFailure)
.map(_.map(ProjectService.toProjectMetadata))
.map(ProjectList.Result)
}

object ProjectListCommand {

def apply[F[+_, +_]: Applicative: Sync: ErrorChannel: CovariantFlatMap](
config: ProjectManagerConfig,
projectsPath: Option[File],
limitOpt: Option[Int]
): ProjectListCommand[F] = {
val clock = new RealClock[F]
val fileSystem = new BlockingFileSystem[F](config.timeout.ioTimeout)
val gen = new SystemGenerator[F]
val storageConfig = projectsPath.fold(config.storage)(path =>
config.storage.copy(userProjectsPath = path)
)

val projectRepository =
new ProjectFileRepository[F](
storageConfig,
clock,
fileSystem,
gen
)

new ProjectListCommand[F](projectRepository, limitOpt)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.enso.projectmanager.infrastructure.repository
import org.enso.projectmanager.boot.configuration.StorageConfig
import org.enso.projectmanager.control.core.{Applicative, CovariantFlatMap}
import org.enso.projectmanager.control.effect.{ErrorChannel, Sync}
import org.enso.projectmanager.infrastructure.file.FileSystem
import org.enso.projectmanager.infrastructure.random.Generator
import org.enso.projectmanager.infrastructure.time.Clock

import java.io.File

class ProjectFileRepositoryFactory[
F[+_, +_]: Sync: ErrorChannel: CovariantFlatMap: Applicative
](
storageConfig: StorageConfig,
clock: Clock[F],
fileSystem: FileSystem[F],
gen: Generator[F]
) extends ProjectRepositoryFactory[F] {

/** @inheritdoc */
override def getProjectRepository(
projectsDirectory: Option[File]
): ProjectRepository[F] = {
val config = projectsDirectory.fold(storageConfig)(dir =>
storageConfig.copy(userProjectsPath = dir)
)
new ProjectFileRepository[F](config, clock, fileSystem, gen)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.enso.projectmanager.infrastructure.repository
import java.io.File

trait ProjectRepositoryFactory[F[+_, +_]] {

def getProjectRepository(
projectsDirectory: Option[File]
): ProjectRepository[F]
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.enso.projectmanager.protocol

import java.util.UUID

import akka.actor.{Actor, ActorRef, Props, Stash}
import com.typesafe.scalalogging.LazyLogging
import org.enso.jsonrpc.{JsonRpcServer, MessageHandler, Method, Request}
import org.enso.projectmanager.boot.configuration.TimeoutConfig
import org.enso.projectmanager.control.core.CovariantFlatMap
import org.enso.projectmanager.control.effect.{ErrorChannel, Exec}
import org.enso.projectmanager.control.effect.{ErrorChannel, Exec, Sync}
import org.enso.projectmanager.event.ClientEvent.{
ClientConnected,
ClientDisconnected
Expand All @@ -22,6 +20,8 @@ import org.enso.projectmanager.service.{
}
import org.enso.projectmanager.util.UnhandledLogging

import java.util.UUID

import scala.annotation.unused
import scala.concurrent.duration._

Expand All @@ -35,7 +35,7 @@ import scala.concurrent.duration._
* @param loggingServiceDescriptor a logging service configuration descriptor
* @param timeoutConfig a request timeout config
*/
class ClientController[F[+_, +_]: Exec: CovariantFlatMap: ErrorChannel](
class ClientController[F[+_, +_]: Exec: CovariantFlatMap: ErrorChannel: Sync](
clientId: UUID,
projectService: ProjectServiceApi[F],
globalConfigService: GlobalConfigServiceApi[F],
Expand Down Expand Up @@ -149,7 +149,7 @@ object ClientController {
* @param loggingServiceDescriptor a logging service configuration descriptor
* @return a configuration object
*/
def props[F[+_, +_]: Exec: CovariantFlatMap: ErrorChannel](
def props[F[+_, +_]: Exec: CovariantFlatMap: ErrorChannel: Sync](
clientId: UUID,
projectService: ProjectServiceApi[F],
globalConfigService: GlobalConfigServiceApi[F],
Expand Down
Loading
Loading