Class AbstractAzureMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    public abstract class AbstractAzureMojo
    extends org.apache.maven.plugin.AbstractMojo
    Base abstract class for all Azure Mojos.
    • Field Detail

      • CONFIGURATION_PATH

        private static final String CONFIGURATION_PATH
      • 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 settings
        The 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 allowTelemetry
        Boolean flag to turn on/off telemetry within current Maven plugin.
        Since:
        0.1.0
      • failsOnError

        @Parameter(property="failsOnError",
                   defaultValue="true")
        protected boolean failsOnError
        Boolean 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

         
         <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>
         
         
        Sample: Service principal configuration within maven settings.xml

        Pom.xml

         
         <configuration>
              <auth>
                  <type>service_principal</type>
                  <serverId>azure-sp-auth1</serverId>
               </auth>
         </configuration>
         
         
        Settings.xml
         
         <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>
         
         
      • settingsDecrypter

        @Component
        protected org.apache.maven.settings.crypto.SettingsDecrypter settingsDecrypter
      • azureAccount

        private com.microsoft.azure.toolkit.lib.auth.Account azureAccount
      • telemetryProxy

        protected com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetryClient telemetryProxy
      • sessionId

        private final String sessionId
      • installationId

        private final String installationId
    • Constructor Detail

      • AbstractAzureMojo

        public AbstractAzureMojo()
    • Method Detail

      • getBuildDirectoryAbsolutePath

        public String getBuildDirectoryAbsolutePath()
      • getInstallationId

        public String getInstallationId()
      • getPluginName

        public String getPluginName()
      • getPluginVersion

        public String getPluginVersion()
      • getUserAgent

        public String getUserAgent()
      • 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:
        MavenDecryptException
        com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException
        com.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​(com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration auth)
      • 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()
      • getTelemetryProperties

        public Map<String,​String> getTelemetryProperties()
      • 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 Throwable
        Entry 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)
      • highlightDefaultValue

        protected static String highlightDefaultValue​(String defaultValue)
      • 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:
        IOException
        com.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()