Package com.microsoft.azure.maven
Class AbstractAzureMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- com.microsoft.azure.maven.AbstractAzureMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
AbstractAppServiceMojo
public abstract class AbstractAzureMojo extends org.apache.maven.plugin.AbstractMojoBase abstract class for all Azure Mojos.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractAzureMojo.DefaultUncaughtExceptionHandlerprotected static interfaceAbstractAzureMojo.RunnableWithException
-
Field Summary
Fields Modifier and Type Field Description protected booleanallowTelemetryBoolean flag to turn on/off telemetry within current Maven plugin.protected MavenAuthConfigurationauthprivate static StringAUTH_METHODprivate static StringAUTH_TYPEprotected StringauthTypeAuthentication type, could be oauth2, device_code, azure_cli,..., seeAuthTypeIf this is not set, maven plugin try all available auth methods with certain orderprivate com.microsoft.azure.management.Azureazureprivate static StringAZURE_ENVIRONMENTprivate static StringAZURE_INIT_FAILprivate com.microsoft.azure.toolkit.lib.auth.AccountazureAccountprotected FilebuildDirectoryprivate static StringCONFIGURATION_PATHprotected static StringDEPLOYprivate static StringERROR_CLASSNAMEprivate static StringERROR_MESSAGEprivate static StringERROR_STACKprotected booleanfailsOnErrorBoolean flag to control whether throwing exception from current Maven plugin when meeting any error.private static StringFIRST_RUN_KEYprotected StringhttpProxyHostUse a HTTP proxy host for the Azure Auth Clientprotected StringhttpProxyPortUse a HTTP proxy port for the Azure Auth Clientprivate static StringINIT_FAILUREstatic StringINSTALLATION_ID_KEYprivate StringinstallationIdprivate static StringINVALID_AZURE_ENVIRONMENTprivate static StringJVM_UP_TIMEprotected org.apache.maven.shared.filtering.MavenResourcesFilteringmavenResourcesFilteringprotected org.apache.maven.plugin.descriptor.PluginDescriptorpluginstatic StringPLUGIN_NAME_KEYstatic StringPLUGIN_VERSION_KEYprivate static StringPRIVACY_STATEMENTprotected org.apache.maven.project.MavenProjectprojectprivate static StringPROXYprotected org.apache.maven.execution.MavenSessionsessionstatic StringSESSION_ID_KEYprivate StringsessionIdprotected org.apache.maven.settings.SettingssettingsThe system settings for Maven.protected org.apache.maven.settings.crypto.SettingsDecryptersettingsDecrypterstatic StringSUBSCRIPTION_ID_KEYprotected static StringSUBSCRIPTION_NOT_FOUNDprotected static StringSUBSCRIPTION_TEMPLATEprotected StringsubscriptionIdAzure subscription Id.protected Map<String,String>telemetriesprivate static StringTELEMETRY_NOT_ALLOWEDprotected com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetryClienttelemetryProxyprotected static StringUSING_AZURE_ENVIRONMENT
-
Constructor Summary
Constructors Constructor Description AbstractAzureMojo()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static com.microsoft.azure.toolkit.lib.auth.AccountaccountLogin(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)protected voidafterMojoExecution()protected voidbeforeMojoExecution()private static reactor.core.publisher.Mono<com.microsoft.azure.toolkit.lib.auth.Account>checkAccountAvailable(com.microsoft.azure.toolkit.lib.auth.Account account)protected static voidcheckSubscription(List<com.microsoft.azure.toolkit.lib.common.model.Subscription> subscriptions, String targetSubscriptionId)protected abstract voiddoExecute()Entry point of sub-class.private static com.microsoft.azure.toolkit.lib.auth.AccountdoServicePrincipalLogin(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)voidexecute()protected voidexecuteWithTimeRecorder(AbstractAzureMojo.RunnableWithException operation, String name)private static reactor.core.publisher.Mono<com.microsoft.azure.toolkit.lib.auth.Account>findFirstAvailableAccount()StringgetActualAuthType()protected StringgetAuthType()protected com.microsoft.azure.toolkit.lib.auth.AccountgetAzureAccount()StringgetBuildDirectoryAbsolutePath()intgetHttpProxyPort()StringgetInstallationId()StringgetPluginName()StringgetPluginVersion()protected StringgetTargetSubscriptionId(String defaultSubscriptionId, List<com.microsoft.azure.toolkit.lib.common.model.Subscription> subscriptions, List<com.microsoft.azure.toolkit.lib.common.model.Subscription> selectedSubscriptions)Map<String,String>getTelemetryProperties()StringgetUserAgent()private static com.microsoft.azure.toolkit.lib.auth.AccounthandleDeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.Account account)protected static StringhighlightDefaultValue(String defaultValue)voidinfoWithMultipleLines(String messages)private static voidinitMavenSettingsProxy(org.apache.maven.execution.MavenExecutionRequest request)protected voidinitTelemetryProxy()private booleanisFirstRun(Properties prop)protected booleanisSkipMojo()Sub-class can override this method to decide whether skip execution.protected com.microsoft.azure.toolkit.lib.auth.Accountlogin(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)protected voidonMojoError(Exception exception)protected voidonSkipped()protected static voidprintCredentialDescription(com.microsoft.azure.toolkit.lib.auth.Account account, boolean skipType)protected static voidprintCurrentSubscription(com.microsoft.azure.management.Azure azure)private static voidpromptAzureEnvironment(com.azure.core.management.AzureEnvironment env)private static voidpromptForOAuthOrDeviceCodeLogin(com.microsoft.azure.toolkit.lib.auth.model.AuthType authType)private Map<String,String>recordJvmUpTime(Map<String,String> properties)protected voidselectSubscription()protected StringselectSubscription(com.microsoft.azure.toolkit.lib.common.model.Subscription[] subscriptions)protected voidtrackMojoFailure(Throwable throwable)private voidupdateConfigurationFile(Properties prop)protected voidupdateTelemetryProperties()
-
-
-
Field Detail
-
PLUGIN_NAME_KEY
public static final String PLUGIN_NAME_KEY
- See Also:
- Constant Field Values
-
PLUGIN_VERSION_KEY
public static final String PLUGIN_VERSION_KEY
- See Also:
- Constant Field Values
-
INSTALLATION_ID_KEY
public static final String INSTALLATION_ID_KEY
- See Also:
- Constant Field Values
-
SESSION_ID_KEY
public static final String SESSION_ID_KEY
- See Also:
- Constant Field Values
-
SUBSCRIPTION_ID_KEY
public static final String SUBSCRIPTION_ID_KEY
- See Also:
- Constant Field Values
-
DEPLOY
protected static final String DEPLOY
- See Also:
- Constant Field Values
-
AUTH_TYPE
private static final String AUTH_TYPE
- See Also:
- Constant Field Values
-
AUTH_METHOD
private static final String AUTH_METHOD
- See Also:
- Constant Field Values
-
TELEMETRY_NOT_ALLOWED
private static final String TELEMETRY_NOT_ALLOWED
- See Also:
- Constant Field Values
-
INIT_FAILURE
private static final String INIT_FAILURE
- See Also:
- Constant Field Values
-
AZURE_INIT_FAIL
private static final String AZURE_INIT_FAIL
- See Also:
- Constant Field Values
-
ERROR_MESSAGE
private static final String ERROR_MESSAGE
- See Also:
- Constant Field Values
-
ERROR_STACK
private static final String ERROR_STACK
- See Also:
- Constant Field Values
-
ERROR_CLASSNAME
private static final String ERROR_CLASSNAME
- See Also:
- Constant Field Values
-
JVM_UP_TIME
private static final String JVM_UP_TIME
- See Also:
- Constant Field Values
-
CONFIGURATION_PATH
private static final String CONFIGURATION_PATH
-
FIRST_RUN_KEY
private static final String FIRST_RUN_KEY
- See Also:
- Constant Field Values
-
PRIVACY_STATEMENT
private static final String PRIVACY_STATEMENT
- See Also:
- Constant Field Values
-
SUBSCRIPTION_TEMPLATE
protected static final String SUBSCRIPTION_TEMPLATE
- See Also:
- Constant Field Values
-
USING_AZURE_ENVIRONMENT
protected static final String USING_AZURE_ENVIRONMENT
- See Also:
- Constant Field Values
-
SUBSCRIPTION_NOT_FOUND
protected static final String SUBSCRIPTION_NOT_FOUND
- See Also:
- Constant Field Values
-
INVALID_AZURE_ENVIRONMENT
private static final String INVALID_AZURE_ENVIRONMENT
- See Also:
- Constant Field Values
-
AZURE_ENVIRONMENT
private static final String AZURE_ENVIRONMENT
- See Also:
- Constant Field Values
-
PROXY
private static final String PROXY
- See Also:
- Constant Field Values
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) protected org.apache.maven.project.MavenProject project
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession session
-
buildDirectory
@Parameter(defaultValue="${project.build.directory}", readonly=true, required=true) protected File buildDirectory
-
plugin
@Parameter(defaultValue="${plugin}", readonly=true, required=true) protected org.apache.maven.plugin.descriptor.PluginDescriptor plugin
-
settings
@Parameter(defaultValue="${settings}", readonly=true, required=true) protected org.apache.maven.settings.Settings settingsThe system settings for Maven. This is the instance resulting from merging global and user-level settings files.
-
mavenResourcesFiltering
@Component(role=org.apache.maven.shared.filtering.MavenResourcesFiltering.class, hint="default") protected org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering
-
subscriptionId
@Parameter protected String subscriptionId
Azure subscription Id. You only need to specify it when:- you are using authentication file
- there are more than one subscription in the authentication file
- Since:
- 0.1.0
-
allowTelemetry
@Parameter(property="allowTelemetry", defaultValue="true") protected boolean allowTelemetryBoolean flag to turn on/off telemetry within current Maven plugin.- Since:
- 0.1.0
-
failsOnError
@Parameter(property="failsOnError", defaultValue="true") protected boolean failsOnErrorBoolean flag to control whether throwing exception from current Maven plugin when meeting any error.If set to true, the exception from current Maven plugin will fail the current Maven run.
- Since:
- 0.1.0
-
httpProxyHost
@Parameter(property="httpProxyHost") protected String httpProxyHost
Use a HTTP proxy host for the Azure Auth Client
-
httpProxyPort
@Parameter(property="httpProxyPort") protected String httpProxyPort
Use a HTTP proxy port for the Azure Auth Client
-
authType
@Parameter(property="authType") protected String authType
Authentication type, could be oauth2, device_code, azure_cli,..., seeAuthTypeIf this is not set, maven plugin try all available auth methods with certain order- Since:
- 1.2.13
-
auth
@Parameter(property="auth") protected MavenAuthConfiguration auth
-
settingsDecrypter
@Component protected org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter
-
azureAccount
private com.microsoft.azure.toolkit.lib.auth.Account azureAccount
-
azure
private com.microsoft.azure.management.Azure azure
-
telemetryProxy
protected com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetryClient telemetryProxy
-
sessionId
private final String sessionId
-
installationId
private final String installationId
-
-
Method Detail
-
getBuildDirectoryAbsolutePath
public String getBuildDirectoryAbsolutePath()
-
getInstallationId
public String getInstallationId()
-
getPluginName
public String getPluginName()
-
getPluginVersion
public String getPluginVersion()
-
getUserAgent
public String getUserAgent()
-
getHttpProxyPort
public int getHttpProxyPort()
-
getAuthType
protected String getAuthType()
-
selectSubscription
protected String selectSubscription(com.microsoft.azure.toolkit.lib.common.model.Subscription[] subscriptions) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
getAzureAccount
protected com.microsoft.azure.toolkit.lib.auth.Account getAzureAccount() throws MavenDecryptException, com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException, com.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException- Throws:
MavenDecryptExceptioncom.microsoft.azure.toolkit.lib.common.exception.AzureExecutionExceptioncom.microsoft.azure.toolkit.lib.auth.exception.LoginFailureException
-
selectSubscription
protected void selectSubscription()
-
login
protected com.microsoft.azure.toolkit.lib.auth.Account login(@Nonnull com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)
-
accountLogin
private static com.microsoft.azure.toolkit.lib.auth.Account accountLogin(@Nonnull com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)
-
handleDeviceCodeAccount
private static com.microsoft.azure.toolkit.lib.auth.Account handleDeviceCodeAccount(com.microsoft.azure.toolkit.lib.auth.Account account)
-
promptAzureEnvironment
private static void promptAzureEnvironment(com.azure.core.management.AzureEnvironment env)
-
promptForOAuthOrDeviceCodeLogin
private static void promptForOAuthOrDeviceCodeLogin(com.microsoft.azure.toolkit.lib.auth.model.AuthType authType)
-
findFirstAvailableAccount
private static reactor.core.publisher.Mono<com.microsoft.azure.toolkit.lib.auth.Account> findFirstAvailableAccount()
-
doServicePrincipalLogin
private static com.microsoft.azure.toolkit.lib.auth.Account doServicePrincipalLogin(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)
-
checkAccountAvailable
private static reactor.core.publisher.Mono<com.microsoft.azure.toolkit.lib.auth.Account> checkAccountAvailable(com.microsoft.azure.toolkit.lib.auth.Account account)
-
printCredentialDescription
protected static void printCredentialDescription(com.microsoft.azure.toolkit.lib.auth.Account account, boolean skipType)
-
initTelemetryProxy
protected void initTelemetryProxy()
-
printCurrentSubscription
protected static void printCurrentSubscription(com.microsoft.azure.management.Azure azure)
-
getActualAuthType
public String getActualAuthType()
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
initMavenSettingsProxy
private static void initMavenSettingsProxy(org.apache.maven.execution.MavenExecutionRequest request)
-
isSkipMojo
protected boolean isSkipMojo()
Sub-class can override this method to decide whether skip execution.- Returns:
- Boolean to indicate whether skip execution.
-
doExecute
protected abstract void doExecute() throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionExceptionEntry point of sub-class. Sub-class should implement this method to do real work.- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
onSkipped
protected void onSkipped()
-
beforeMojoExecution
protected void beforeMojoExecution()
-
afterMojoExecution
protected void afterMojoExecution()
-
trackMojoFailure
protected void trackMojoFailure(Throwable throwable)
-
onMojoError
protected void onMojoError(Exception exception) throws org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
executeWithTimeRecorder
protected void executeWithTimeRecorder(AbstractAzureMojo.RunnableWithException operation, String name) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
isFirstRun
private boolean isFirstRun(Properties prop)
-
updateConfigurationFile
private void updateConfigurationFile(Properties prop)
-
infoWithMultipleLines
public void infoWithMultipleLines(String messages)
-
getTargetSubscriptionId
protected String getTargetSubscriptionId(String defaultSubscriptionId, List<com.microsoft.azure.toolkit.lib.common.model.Subscription> subscriptions, List<com.microsoft.azure.toolkit.lib.common.model.Subscription> selectedSubscriptions) throws IOException, com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
IOExceptioncom.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
checkSubscription
protected static void checkSubscription(List<com.microsoft.azure.toolkit.lib.common.model.Subscription> subscriptions, String targetSubscriptionId) throws com.microsoft.azure.toolkit.lib.auth.exception.AzureLoginException
- Throws:
com.microsoft.azure.toolkit.lib.auth.exception.AzureLoginException
-
updateTelemetryProperties
protected void updateTelemetryProperties()
-
-