Class BaseCliCommand

java.lang.Object
com.e1c.g5.v8.dt.cli.api.components.BaseCliCommand
All Implemented Interfaces:
ICliCommand, ICliSessionConsumer, Consumer<ICliSession>
Direct Known Subclasses:
BaseProjectCmds, FormatBslFilesCmd, ImportConfigurationFilesCmd, PlatformSupportCommand

public class BaseCliCommand extends Object implements ICliCommand, ICliSessionConsumer
Base implementation of a CLI command provider. Provides a number of convenient helpers to create standard commands that works with the EDT platform.
  • Field Details

    • DT_PROJECT_STARTUP_DURATION

      protected static final Duration DT_PROJECT_STARTUP_DURATION
  • Constructor Details

    • BaseCliCommand

      public BaseCliCommand()
  • Method Details

    • getProjectsRecursively

      public Collection<File> getProjectsRecursively(Path path)
      Gets all Eclipse .project files from a provided folder, with recursive search.
      Parameters:
      path - The path to a folder which may contain projects. Cannot be null
      Returns:
      A collection of found projects. Never null but may be empty
    • accept

      public void accept(ICliSession cliSession)
      Specified by:
      accept in interface Consumer<ICliSession>
    • getCurrentWorkDir

      protected Path getCurrentWorkDir()
      Returns the current session's working directory. You should resolve all relative paths against this directory (except for workspace relative paths). This is not the workspace directory. Initially this value is the directory the 1C:EDT CLI process is executed from. But the user (or other commands) can change it later for each session separately either by calling the builtin cd command, or by changing the _cwd session variable. Because of this you should not rely on the JVM process working directory (System.getProperty("user.dir") or File.getAbsolutePath() or other methods like this).
      Returns:
      the current working directory of the current session. Never null.
      See Also:
    • backgroundOperation

      protected <R> R backgroundOperation(String operationName, IDtProject dtProject, ProjectPipelineJob targetStage, Callable<R> callable)
      Executes logic within background-priority orchestrated operation (see IWorkspaceOrchestrator
      Type Parameters:
      R - Type of return value
      Parameters:
      operationName - The name of an operation to be executed. Cannot be null
      dtProject - Target project to execute the operation on. Cannot be null
      targetStage - Target stage of the project's pipeline. Cannot be null
      callable - Callable to execute. Cannot be null
      Returns:
      Result of the operation execution. Depends on the provided Callable. May be null
    • exclusiveOperation

      protected <V> V exclusiveOperation(String operationName, IDtProject dtProject, ProjectPipelineJob targetJob, Callable<V> callable)
      Executes logic within exclusive-priority orchestrated operation (see IWorkspaceOrchestrator
      Type Parameters:
      R - Type of return value
      Parameters:
      operationName - The name of an operation to be executed. Cannot be null
      dtProject - Target project to execute the operation on. Cannot be null
      targetStage - Target stage of the project's pipeline. Cannot be null
      callable - Callable to execute. Cannot be null
      Returns:
      Result of the operation execution. Depends on the provided Callable. May be null
    • findProjectsRecursively

      protected Collection<File> findProjectsRecursively(Path[] projectDirs)
      Finds project files recursively by given collection of directories
      Parameters:
      projectDirs - the project directories
      Returns:
      the collection of .../ProjectName/.project files, cannot return null.
    • getContext

      protected CliCommandContext getContext()
      Gets standard service context of a command.
      Returns:
      A command context. May not be null in case of proper command initialization
    • startDtProject

      protected IDtProject startDtProject(Path projectDir)
      Starts DT project that is pointed by a specified path. Do nothing if the project is already started to allow easy chaining of commands This method waits when DT project has started but it doesn't wait build completion Use workspace orchestration operation to do the job on correct lifecycle stage
      Parameters:
      projectDir - the project directory, cannot be null.
      Returns:
      the started DT project, cannot return null. May throw exception in case of errors during the project start
    • waitUntilStarted

      protected boolean waitUntilStarted(IDtProject project, Duration waitDuration)
      Waits until a specified IDtProject is started (all service contexts are up and running)
      Parameters:
      project - The project to wait start for. Cannot be null
      waitDuration - Wait duration time. Cannot be null
      Returns:
      True if the project is started before the timeout
    • waitUntilStarted

      protected boolean waitUntilStarted(org.eclipse.core.resources.IProject project, Duration waitDuration)
      Waits until a specified IProject is started (all service contexts are up and running)
      Parameters:
      project - The project to wait start for. Cannot be null
      waitDuration - Wait duration time. Cannot be null
      Returns:
      True if the project is started before the timeout
    • logError

      protected void logError(String message)
      Logs an error with a specified message
      Parameters:
      message - Message to log as en error. Cannot be null
    • logError

      protected void logError(String message, Throwable cause)
      Logs an error with a specified message
      Parameters:
      message - Message to log as en error. Cannot be null
      cause - Throwable that caused/indicates error. Cannot be null