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
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 MavenAuthConfigurationauthConfiguration for maven plugin authentication Parameters for authentication type: specify which authentication method to use, default to be `auto`: service_principal : Will use credential specified in plugin configuration or Maven settings.xml, this is also the first priority authentication method in auto managed_identity : Will use the system managed credential managed by azure azure_cli : Will use credential provided by Azure CLI, this could also be used in Azure Cloud Shell oauth2 : Will use credential provided by oauth2, a browser will be opened, you need to follow the page to follow the login process device_code : Similar to oauth2, it provides you a login-code together with an url, you need to open a browser at any machine and fill-in the login-code, then you can follow the page to follow to finish the login process on the web page auto: The default auth type, it will try all the auth methods in the following sequence: service_principal, managed_identity, azure_cli, oauth2, device_code environment: Specifies the target Azure cloud environmentprivate static StringAUTH_METHODprivate static StringAUTH_TYPEprotected StringauthTypeDeprecated.private static StringAZURE_ENVIRONMENTprotected FilebuildDirectoryprivate static StringCONFIGURATION_PATHprotected booleanfailsOnErrorBoolean flag to control whether throwing exception from current Maven plugin when meeting any error.private static StringFIRST_RUN_KEYstatic StringINSTALLATION_ID_KEYprivate StringinstallationIdprivate 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 protected voidafterMojoExecution()protected voidbeforeMojoExecution()protected static voidcheckSubscription(List<com.microsoft.azure.toolkit.lib.common.model.Subscription> subscriptions, String targetSubscriptionId)protected abstract voiddoExecute()Entry point of sub-class.voidexecute()protected voidexecuteWithTimeRecorder(AbstractAzureMojo.RunnableWithException operation, String name)StringgetActualAuthType()StringgetBuildDirectoryAbsolutePath()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()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.AccountloginAzure()protected com.microsoft.azure.toolkit.lib.auth.AccountloginAzure(MavenAuthConfiguration auth)protected voidonMojoError(Throwable exception)protected voidonSkipped()protected static voidprintCredentialDescription(com.microsoft.azure.toolkit.lib.auth.Account account)private static voidpromptAzureEnvironment(com.azure.core.management.AzureEnvironment env)private Map<String,String>recordJvmUpTime(Map<String,String> properties)protected voidselectSubscription()protected StringselectSubscription(com.microsoft.azure.toolkit.lib.common.model.Subscription[] subscriptions)private com.microsoft.azure.toolkit.lib.auth.AuthConfigurationtoAuthConfiguration(MavenAuthConfiguration auth)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
-
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
-
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
-
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. Required only if there are more than one subscription in your account- 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
-
authType
@Deprecated @Parameter(property="authType") protected String authType
Deprecated.Deprecated, please set the authentication type in `auth`- Since:
- 1.2.13
-
auth
@Parameter(property="auth") protected MavenAuthConfiguration auth
Configuration for maven plugin authentication Parameters for authentication- type: specify which authentication method to use, default to be `auto`:
- service_principal : Will use credential specified in plugin configuration or Maven settings.xml, this is also the first priority authentication method in auto
- managed_identity : Will use the system managed credential managed by azure
- azure_cli : Will use credential provided by Azure CLI, this could also be used in Azure Cloud Shell
- oauth2 : Will use credential provided by oauth2, a browser will be opened, you need to follow the page to follow the login process
- device_code : Similar to oauth2, it provides you a login-code together with an url, you need to open a browser at any machine and fill-in the login-code, then you can follow the page to follow to finish the login process on the web page
- auto: The default auth type, it will try all the auth methods in the following sequence: service_principal, managed_identity, azure_cli, oauth2, device_code
- environment: Specifies the target Azure cloud environment
Supported values are: `azure`, `azure_china`, `azure_germany`, `azure_us_government`
- client: Client ID of the service principal.
- tenant: Tenant ID of the service principal.
- key: Specifies the password if your service principal uses password authentication.
- certificate: The absolute path of certificate, required if your service principal uses certificate authentication.
Note: Only PKCS12 certificates are supported.
- certificatePassword: Password for the certificate
- serverId: Reference for service principal configuration in Maven settings.xml, please see the example below
Sample: Service principal configuration within maven settings.xml<configuration> <auth> <client>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</client> <tenant>yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy</tenant> <key>zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz</key> <environment>azure</environment> </auth> </configuration>Pom.xml
Settings.xml<configuration> <auth> <type>service_principal</type> <serverId>azure-sp-auth1</serverId> </auth> </configuration><server> <id>azure-sp-auth1</id> <configuration> <client>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</client> <tenant>yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy</tenant> <key>xxx</key> <environment>azure</environment> </configuration> </server> - type: specify which authentication method to use, default to be `auto`:
-
settingsDecrypter
@Component protected org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter
-
telemetryProxy
protected com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetryClient telemetryProxy
-
sessionId
private final String sessionId
-
installationId
private final String installationId
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getBuildDirectoryAbsolutePath
public String getBuildDirectoryAbsolutePath()
-
getPluginName
public String getPluginName()
-
getPluginVersion
public String getPluginVersion()
-
getUserAgent
public String getUserAgent()
-
loginAzure
protected com.microsoft.azure.toolkit.lib.auth.Account loginAzure() throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException, MavenDecryptException- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionExceptionMavenDecryptException
-
loginAzure
protected com.microsoft.azure.toolkit.lib.auth.Account loginAzure(MavenAuthConfiguration auth) throws MavenDecryptException, com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
- Throws:
MavenDecryptExceptioncom.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
-
toAuthConfiguration
private com.microsoft.azure.toolkit.lib.auth.AuthConfiguration toAuthConfiguration(MavenAuthConfiguration auth) throws com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException, MavenDecryptException
- Throws:
com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionExceptionMavenDecryptException
-
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
-
selectSubscription
protected void selectSubscription()
-
promptAzureEnvironment
private static void promptAzureEnvironment(com.azure.core.management.AzureEnvironment env)
-
printCredentialDescription
protected static void printCredentialDescription(com.microsoft.azure.toolkit.lib.auth.Account account)
-
initTelemetryProxy
protected void initTelemetryProxy()
-
getActualAuthType
public String getActualAuthType()
-
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 ThrowableEntry point of sub-class. Sub-class should implement this method to do real work.- Throws:
Throwable
-
onSkipped
protected void onSkipped()
-
beforeMojoExecution
protected void beforeMojoExecution()
-
afterMojoExecution
protected void afterMojoExecution()
-
trackMojoFailure
protected void trackMojoFailure(Throwable throwable)
-
onMojoError
protected void onMojoError(Throwable 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.AzureToolkitAuthenticationException
- Throws:
com.microsoft.azure.toolkit.lib.auth.AzureToolkitAuthenticationException
-
updateTelemetryProperties
protected void updateTelemetryProperties()
-
-