Class BaseCliCommand
- java.lang.Object
-
- com.e1c.g5.v8.dt.cli.api.components.BaseCliCommand
-
- All Implemented Interfaces:
ICliCommand
,ICommandSessionConsumer
,Consumer<org.apache.felix.service.command.CommandSession>
public class BaseCliCommand extends Object implements ICliCommand, ICommandSessionConsumer
Base implementation of a CLI command. Provides a number of convenient helpers to create standard commands that works with the EDT platform
-
-
Field Summary
Fields Modifier and Type Field Description protected static Duration
DT_PROJECT_STARTUP_DURATION
-
Constructor Summary
Constructors Constructor Description BaseCliCommand()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(org.apache.felix.service.command.CommandSession commandSession)
protected <R> R
backgroundOperation(String operationName, IDtProject dtProject, ProjectPipelineJob targetStage, Callable<R> callable)
Executes logic within background-priority orchestrated operation (seeIWorkspaceOrchestrator
protected <V> V
exclusiveOperation(String operationName, IDtProject dtProject, ProjectPipelineJob targetJob, Callable<V> callable)
Executes logic within exclusive-priority orchestrated operation (seeIWorkspaceOrchestrator
protected Collection<File>
findProjectsRecursively(Path[] projectDirs)
Finds project files recursively by given collection of directoriesprotected CliCommandContext
getContext()
Gets standard service context of a commandCollection<File>
getProjectsRecursively(Path path)
Gets all Eclipse .project files from a provided folder, with recursive searchprotected void
logError(String message)
Logs an error with a specified messageprotected void
logError(String message, Throwable cause)
Logs an error with a specified messageprotected IDtProject
startDtProject(Path projectDir)
Starts DT project that is pointed by a specified path.protected boolean
waitUntilStarted(IDtProject project, Duration waitDuration)
Waits until a specifiedIDtProject
is started (all service contexts are up and running)protected boolean
waitUntilStarted(org.eclipse.core.resources.IProject project, Duration waitDuration)
Waits until a specifiedIProject
is started (all service contexts are up and running)
-
-
-
Field Detail
-
DT_PROJECT_STARTUP_DURATION
protected static final Duration DT_PROJECT_STARTUP_DURATION
-
-
Method Detail
-
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 benull
- Returns:
- A collection of found projects. Never
null
but may be empty
-
accept
public void accept(org.apache.felix.service.command.CommandSession commandSession)
-
backgroundOperation
protected <R> R backgroundOperation(String operationName, IDtProject dtProject, ProjectPipelineJob targetStage, Callable<R> callable)
Executes logic within background-priority orchestrated operation (seeIWorkspaceOrchestrator
- Type Parameters:
R
- Type of return value- Parameters:
operationName
- The name of an operation to be executed. Cannot benull
dtProject
- Target project to execute the operation on. Cannot benull
targetStage
- Target stage of the project's pipeline. Cannot benull
callable
- Callable to execute. Cannot benull
- Returns:
- Result of the operation execution. Depends on the provided
Callable
. May benull
-
exclusiveOperation
protected <V> V exclusiveOperation(String operationName, IDtProject dtProject, ProjectPipelineJob targetJob, Callable<V> callable)
Executes logic within exclusive-priority orchestrated operation (seeIWorkspaceOrchestrator
- Type Parameters:
R
- Type of return value- Parameters:
operationName
- The name of an operation to be executed. Cannot benull
dtProject
- Target project to execute the operation on. Cannot benull
targetStage
- Target stage of the project's pipeline. Cannot benull
callable
- Callable to execute. Cannot benull
- Returns:
- Result of the operation execution. Depends on the provided
Callable
. May benull
-
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 returnnull
.
-
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 benull
.- 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 specifiedIDtProject
is started (all service contexts are up and running)- Parameters:
project
- The project to wait start for. Cannot benull
waitDuration
- Wait duration time. Cannot benull
- 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 specifiedIProject
is started (all service contexts are up and running)- Parameters:
project
- The project to wait start for. Cannot benull
waitDuration
- Wait duration time. Cannot benull
- 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 benull
-
-