Package com.sap.cds.maven.plugin.build
Class CdsMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
com.sap.cds.maven.plugin.AbstractCdsMojo
com.sap.cds.maven.plugin.build.CdsMojo
- All Implemented Interfaces:
CdsMojoLogger
,org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
@Mojo(name="cds",
defaultPhase=GENERATE_SOURCES,
aggregator=true)
public class CdsMojo
extends AbstractCdsMojo
Execute CDS commands on the CAP Java project.
Call
Several CDS commands can be configured in one execution block and they’re executed in the specified order. If a command execution fails, the overall goal execution is stopped and the Maven build fails.
Note: This goal requires the installation of the @sap/cds-dk with a minimum version 4.0.0, either locally or globally. The goal cds:install-cdsdk can be used for this task.
Call
mvn cds:cds
or mvn com.sap.cds:cds-maven-plugin:cds
on the command line to execute all
configured CDS commands of the project in current directory.Several CDS commands can be configured in one execution block and they’re executed in the specified order. If a command execution fails, the overall goal execution is stopped and the Maven build fails.
Note: This goal requires the installation of the @sap/cds-dk with a minimum version 4.0.0, either locally or globally. The goal cds:install-cdsdk can be used for this task.
- Since:
- 1.7.0
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected org.eclipse.aether.RepositorySystemSession
Defines settings and components that control the repository system.Fields inherited from class com.sap.cds.maven.plugin.AbstractCdsMojo
buildContext, CDS_SERVICES_GROUPID, mojoExecution, PLUGIN_KEY, project, session, settings
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute()
protected void
execute
(File workDir, File execFile, OutputStream outputStream, Map<String, String> additionalEnv, int[] exitValues, String... args) Executes a program as child process.protected void
executeCds
(File workDir, String args, OutputStream output, Map<String, String> additionalEnv) Executes a cds command with given arguments in given working directory.protected String
Executes commandcds version
and returns console output.protected File
Finds the cds working directory by going upwards and looking for a .cdsrc.json file.protected File
void
setNpxExec
(File npxExec) Gets called to inject parameter "npxExec".Methods inherited from class com.sap.cds.maven.plugin.AbstractCdsMojo
ensureCliExecuted, findGoalExecution, findSrvProject, getReactorBaseDirectory, isCliExecuted, logDebug, logDebug, logError, logError, logError, logInfo, logWarn, logWarn, logWarn, scanDirectory, setProperty, strong
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
PROP_NODE_DIR
- See Also:
-
PROP_NODE_EXECUTABLE
- See Also:
-
PROP_NPM_EXECUTABLE
- See Also:
-
PROP_NPX_EXECUTABLE
- See Also:
-
PARAM_NODE_DIR
- See Also:
-
PARAM_NPX_EXECUTABLE
- See Also:
-
PARAM_NPM_EXECUTABLE
- See Also:
-
repositorySystemSession
@Parameter(defaultValue="${repositorySystemSession}", required=true, readonly=true) protected org.eclipse.aether.RepositorySystemSession repositorySystemSessionDefines settings and components that control the repository system.
-
-
Constructor Details
-
CdsMojo
public CdsMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
setNpxExec
Gets called to inject parameter "npxExec".- Parameters:
npxExec
- aFile
pointing to npx executable
-
executeCds
protected void executeCds(File workDir, String args, OutputStream output, Map<String, String> additionalEnv) throws IOExceptionExecutes a cds command with given arguments in given working directory.- Parameters:
workDir
- the working directory to useargs
- the cds command line argumentsoutput
- an optionalOutputStream
- Throws:
org.apache.commons.exec.ExecuteException
- if CDS execution failed with an errorIOException
- if an I/O error occurred
-
getWorkingDirectory
-
executeCdsVersion
Executes commandcds version
and returns console output.- Returns:
- the console output of the
cds version
command - Throws:
org.apache.maven.plugin.MojoExecutionException
- if execution fails
-
execute
protected void execute(File workDir, File execFile, OutputStream outputStream, Map<String, String> additionalEnv, int[] exitValues, String... args) throws IOExceptionExecutes a program as child process.- Parameters:
workDir
- the working directory of child processexecFile
- the executable to useoutputStream
- an optional standard output streamadditionalEnv
- additional environment variables, can benull
exitValues
- an optional list with exit values of the process to be considered successful, can benull
args
- an optional command line arguments passed to the process- Throws:
IOException
- if an I/O exception occurredorg.apache.commons.exec.ExecuteException
- if process execution failed
-
findCdsWorkingDir
Finds the cds working directory by going upwards and looking for a .cdsrc.json file. It stops at the top-most project directory.- Returns:
- the cds working directory or
null
if not found.
-