Class AddMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- com.microsoft.azure.maven.AbstractAzureMojo
-
- com.microsoft.azure.maven.appservice.AbstractAppServiceMojo
-
- com.microsoft.azure.maven.function.AbstractFunctionMojo
-
- com.microsoft.azure.maven.function.AddMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="add") public class AddMojo extends AbstractFunctionMojo
Create new Azure Functions (as Java class) and add to current project.
-
-
Field Summary
Fields Modifier and Type Field Description protected Filebasedirprotected List<String>compileSourceRootsprivate static StringDEFAULT_INPUT_ERROR_MESSAGEprivate static StringFILE_EXISTprivate static StringFIND_TEMPLATEprivate static StringFIND_TEMPLATE_DONEprivate static StringFIND_TEMPLATE_FAILprivate static StringFOUND_VALID_VALUEprivate static StringFUNCTION_NAME_REGEXPprotected StringfunctionNameName of the new function.protected StringfunctionPackageNamePackage name of the new function.protected StringfunctionTemplateTemplate for the new functionprivate static StringLOAD_TEMPLATESprivate static StringLOAD_TEMPLATES_DONEprivate static StringPREPARE_PARAMSprivate static StringPROMPT_STRING_WITH_DEFAULT_VALUEprivate static StringPROMPT_STRING_WITHOUT_DEFAULT_VALUEprivate static StringSAVE_FILEprivate static StringSAVE_FILE_DONE-
Fields inherited from class com.microsoft.azure.maven.function.AbstractFunctionMojo
alwaysReadyInstances, appInsightsInstance, appInsightsKey, artifactPath, AZURE_FUNCTIONS_JAVA_LIBRARY, CAN_NOT_FIND_ARTIFACT, disableAppInsights, enableDistributedTracing, environment, finalName, FUNCTION_EXTENSION_LIBRARY_MAP, HOST_JSON, hostJson, instanceSize, LOCAL_SETTINGS_JSON, localSettingsJson, maximumInstances, maxReplicas, minReplicas, outputDirectory, parser, pricingTier, region, runtime, skip, storageAccountName, storageAccountResourceGroup, TRIGGER_TYPE
-
Fields inherited from class com.microsoft.azure.maven.appservice.AbstractAppServiceMojo
appName, appServiceClient, appServicePlanName, appServicePlanResourceGroup, appSettings, deploymentSlotSetting, MAVEN_PLUGIN_POSTFIX, resourceGroup
-
Fields inherited from class com.microsoft.azure.maven.AbstractAzureMojo
allowTelemetry, auth, authType, buildDirectory, COMPILE_LEVEL_NOT_SUPPORTED, FAILED_TO_GET_VALID_RUNTIMES, failsOnError, failsOnRuntimeValidationError, INSTALLATION_ID_KEY, mavenResourcesFiltering, plugin, PLUGIN_NAME_KEY, PLUGIN_VERSION_KEY, project, session, SESSION_ID_KEY, settings, settingsDecrypter, SUBSCRIPTION_ID_KEY, SUBSCRIPTION_NOT_FOUND, SUBSCRIPTION_TEMPLATE, subscriptionId, telemetries, telemetryProxy, USING_AZURE_ENVIRONMENT
-
-
Constructor Summary
Constructors Constructor Description AddMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassureInputFromUser(String prompt, String initValue, java.util.function.Function<String,Boolean> validator, String errorMessage, java.util.function.Consumer<String> setter)protected voidassureInputFromUser(String prompt, String initValue, List<String> options, java.util.function.Consumer<String> setter)protected voidassureInputInBatchMode(String input, java.util.function.Function<String,Boolean> validator, java.util.function.Consumer<String> setter, boolean required)protected voidcreatePackageDirIfNotExist(File packageDir)protected voiddisplayParameters(Map<String,String> params)protected voiddoExecute()private StringfindElementInOptions(List<String> options, String item)protected com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplatefindTemplateByName(List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> templates, String templateName)protected StringgetBasedir()StringgetClassName()StringgetFunctionName()StringgetFunctionPackageName()StringgetFunctionTemplate()protected com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplategetFunctionTemplate(List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> templates)private List<String>getOptionsForUserPrompt(String promptName)protected FilegetPackageDir()protected ScannergetScanner()protected StringgetSourceRoot()protected StringgetStringInputErrorMessage(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionSettingTemplate template)protected StringgetStringInputFromUser(String attributeName, String initValue, com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionSettingTemplate template)protected StringgetStringInputPromptString(String attributeName, String defaultValue)protected java.util.function.Function<String,Boolean>getStringInputValidator(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionSettingTemplate template)protected FilegetTargetFile(File packageDir)protected List<String>getTemplateNames(List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> templates)protected List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate>loadAllFunctionTemplates(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionExtensionVersion bundleVersion)protected voidprepareFunctionName()protected voidpreparePackageName()protected Map<String,String>prepareRequiredParameters(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate template, com.microsoft.azure.toolkit.lib.legacy.function.template.BindingTemplate bindingTemplate)protected Map<String,String>prepareTemplateParameters(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate template, com.microsoft.azure.toolkit.lib.legacy.function.template.BindingTemplate bindingTemplate, Map<String,String> params)protected voidsaveNewFunctionToFile(String newFunctionClass)protected voidsaveToTargetFile(File targetFile, String newFunctionClass)protected voidsetFunctionName(String functionName)protected voidsetFunctionPackageName(String functionPackageName)protected voidsetFunctionTemplate(String functionTemplate)protected StringsubstituteParametersInTemplate(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate template, Map<String,String> params)-
Methods inherited from class com.microsoft.azure.maven.function.AbstractFunctionMojo
getAppInsightsInstance, getAppInsightsKey, getArtifact, getBundleVersion, getFinalName, getFunctionLibraryVersion, getHostJsonFile, getLocalSettingsJsonFile, getRegion, getRuntimeConfiguration, getTelemetryProperties, isDisableAppInsights, isSkipMojo, readHostJson, validateAppName, validateFunctionCompatibility
-
Methods inherited from class com.microsoft.azure.maven.appservice.AbstractAppServiceMojo
getAppName, getAppServicePlanName, getAppServicePlanResourceGroup, getAppSettings, getDeploymentSlotSetting, getDeploymentStagingDirectoryPath, getResourceGroup, getResources, initAzureAppServiceClient, printCurrentSubscription
-
Methods inherited from class com.microsoft.azure.maven.AbstractAzureMojo
afterMojoExecution, beforeMojoExecution, checkSubscription, execute, executeWithTimeRecorder, getActualAuthType, getAllowTelemetry, getBuildDirectoryAbsolutePath, getCompileLevel, getFailsOnError, getFailsOnRuntimeValidationError, getInstallationId, getMavenResourcesFiltering, getPluginName, getPluginVersion, getProject, getSession, getSessionId, getSettings, getSubscriptionId, getTargetSubscriptionId, getTelemetries, getTelemetryProxy, getUserAgent, getValidRuntimes, highlightDefaultValue, infoWithMultipleLines, initTelemetryProxy, loginAzure, loginAzure, onMojoError, onSkipped, printCredentialDescription, selectSubscription, selectSubscription, trackMojoFailure, updateTelemetryProperties, validateArtifactCompileVersion
-
-
-
-
Field Detail
-
LOAD_TEMPLATES
private static final String LOAD_TEMPLATES
- See Also:
- Constant Field Values
-
LOAD_TEMPLATES_DONE
private static final String LOAD_TEMPLATES_DONE
- See Also:
- Constant Field Values
-
FIND_TEMPLATE
private static final String FIND_TEMPLATE
- See Also:
- Constant Field Values
-
FIND_TEMPLATE_DONE
private static final String FIND_TEMPLATE_DONE
- See Also:
- Constant Field Values
-
FIND_TEMPLATE_FAIL
private static final String FIND_TEMPLATE_FAIL
- See Also:
- Constant Field Values
-
PREPARE_PARAMS
private static final String PREPARE_PARAMS
- See Also:
- Constant Field Values
-
FOUND_VALID_VALUE
private static final String FOUND_VALID_VALUE
- See Also:
- Constant Field Values
-
SAVE_FILE
private static final String SAVE_FILE
- See Also:
- Constant Field Values
-
SAVE_FILE_DONE
private static final String SAVE_FILE_DONE
- See Also:
- Constant Field Values
-
FILE_EXIST
private static final String FILE_EXIST
- See Also:
- Constant Field Values
-
DEFAULT_INPUT_ERROR_MESSAGE
private static final String DEFAULT_INPUT_ERROR_MESSAGE
- See Also:
- Constant Field Values
-
PROMPT_STRING_WITH_DEFAULT_VALUE
private static final String PROMPT_STRING_WITH_DEFAULT_VALUE
- See Also:
- Constant Field Values
-
PROMPT_STRING_WITHOUT_DEFAULT_VALUE
private static final String PROMPT_STRING_WITHOUT_DEFAULT_VALUE
- See Also:
- Constant Field Values
-
FUNCTION_NAME_REGEXP
private static final String FUNCTION_NAME_REGEXP
- See Also:
- Constant Field Values
-
basedir
@Parameter(defaultValue="${project.basedir}", readonly=true, required=true) protected File basedir
-
compileSourceRoots
@Parameter(defaultValue="${project.compileSourceRoots}", readonly=true, required=true) protected List<String> compileSourceRoots
-
functionPackageName
@Parameter(property="functions.package") protected String functionPackageName
Package name of the new function.- Since:
- 0.1.0
-
functionName
@Parameter(property="functions.name") protected String functionName
Name of the new function.- Since:
- 0.1.0
-
functionTemplate
@Parameter(property="functions.template") protected String functionTemplate
Template for the new function- Since:
- 0.1.0
-
-
Method Detail
-
getFunctionPackageName
public String getFunctionPackageName()
-
getFunctionName
public String getFunctionName()
-
getClassName
public String getClassName()
-
getFunctionTemplate
public String getFunctionTemplate()
-
getBasedir
protected String getBasedir()
-
getSourceRoot
protected String getSourceRoot()
-
setFunctionPackageName
protected void setFunctionPackageName(String functionPackageName)
-
setFunctionName
protected void setFunctionName(String functionName)
-
setFunctionTemplate
protected void setFunctionTemplate(String functionTemplate)
-
doExecute
protected void doExecute() throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException- Specified by:
doExecutein classcom.microsoft.azure.maven.AbstractAzureMojo- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
loadAllFunctionTemplates
protected List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> loadAllFunctionTemplates(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionExtensionVersion bundleVersion) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
getFunctionTemplate
protected com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate getFunctionTemplate(List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> templates) throws IOException, com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException, org.apache.maven.plugin.MojoFailureException
- Throws:
IOExceptioncom.microsoft.azure.toolkit.lib.common.exception.AzureExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
getTemplateNames
protected List<String> getTemplateNames(List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> templates)
-
findTemplateByName
protected com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate findTemplateByName(List<com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate> templates, String templateName) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
prepareRequiredParameters
protected Map<String,String> prepareRequiredParameters(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate template, com.microsoft.azure.toolkit.lib.legacy.function.template.BindingTemplate bindingTemplate) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
prepareFunctionName
protected void prepareFunctionName() throws org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoFailureException
-
preparePackageName
protected void preparePackageName() throws org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoFailureException
-
prepareTemplateParameters
protected Map<String,String> prepareTemplateParameters(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate template, com.microsoft.azure.toolkit.lib.legacy.function.template.BindingTemplate bindingTemplate, Map<String,String> params) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
getStringInputFromUser
protected String getStringInputFromUser(String attributeName, String initValue, com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionSettingTemplate template)
-
getStringInputErrorMessage
protected String getStringInputErrorMessage(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionSettingTemplate template)
-
getStringInputPromptString
protected String getStringInputPromptString(String attributeName, String defaultValue)
-
getStringInputValidator
protected java.util.function.Function<String,Boolean> getStringInputValidator(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionSettingTemplate template)
-
substituteParametersInTemplate
protected String substituteParametersInTemplate(com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate template, Map<String,String> params)
-
saveNewFunctionToFile
protected void saveNewFunctionToFile(String newFunctionClass) throws IOException, com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
IOExceptioncom.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
getPackageDir
protected File getPackageDir()
-
getTargetFile
protected File getTargetFile(File packageDir) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
createPackageDirIfNotExist
protected void createPackageDirIfNotExist(File packageDir)
-
saveToTargetFile
protected void saveToTargetFile(File targetFile, String newFunctionClass) throws IOException
- Throws:
IOException
-
assureInputFromUser
protected void assureInputFromUser(String prompt, String initValue, List<String> options, java.util.function.Consumer<String> setter)
-
assureInputFromUser
protected void assureInputFromUser(String prompt, String initValue, java.util.function.Function<String,Boolean> validator, String errorMessage, java.util.function.Consumer<String> setter)
-
assureInputInBatchMode
protected void assureInputInBatchMode(String input, java.util.function.Function<String,Boolean> validator, java.util.function.Consumer<String> setter, boolean required) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
getScanner
protected Scanner getScanner()
-
findElementInOptions
@Nullable private String findElementInOptions(List<String> options, String item)
-
-