1   package com.atlassian.maven.plugins.amps;
2   
3   import com.atlassian.maven.plugins.amps.product.ProductHandlerFactory;
4   import com.atlassian.maven.plugins.amps.util.GoogleAmpsTracker;
5   
6   import org.apache.maven.plugin.MojoExecutionException;
7   import org.jfrog.maven.annomojo.annotations.MojoParameter;
8   
9   public abstract class AbstractProductAwareMojo extends AbstractAmpsMojo
10  {
11      /**
12       * Product id
13       */
14      @MojoParameter(expression = "${product}")
15      private String product;
16  
17      /**
18       * Instance to run. If provided, used to determine the product to use, instead of
19       * using the product ID.
20       */
21      @MojoParameter(expression = "${instanceId}")
22      protected String instanceId;
23  
24      /**
25       * <p>Flag to enable Google tracking.</p>
26       *
27       * <p>AMPS sends basic usage events to Google analytics by default. To disable tracking, either:</p>
28       * <ol>
29       * <li>Add <code>&lt;allow.google.tracking>false&lt;/allow.google.tracking></code> to the
30       *  <code>&lt;properties></code> section of your <code>.m2/settings.xml</code> file</li>
31       * <li>Include <code>&lt;allowGoogleTracking>false&lt;/allowGoogleTracking></code> in
32       * the amps plugin configuration in your <code>pom.xml</code></li>
33       * <li>or pass <code>-Dallow.google.tracking=false</code> on the command line.
34       * </ol>
35       */
36      @MojoParameter(expression = "${allow.google.tracking}", defaultValue = "true")
37      protected boolean allowGoogleTracking;
38  
39      private GoogleAmpsTracker googleTracker;
40  
41  
42      protected String getDefaultProductId() throws MojoExecutionException
43      {
44          return null;
45      }
46  
47      protected final String getProductId() throws MojoExecutionException
48      {
49          if (product == null)
50          {
51              product = getDefaultProductId();
52              if (product == null && ProductHandlerFactory.getIds().contains(getPluginInformation().getId()))
53              {
54                  product = getPluginInformation().getId();
55              }
56              else if (product == null)
57              {
58                  product = ProductHandlerFactory.REFAPP;
59              }
60          }
61          return product;
62      }
63  
64      protected GoogleAmpsTracker getGoogleTracker() throws MojoExecutionException
65      {
66          if(null == googleTracker)
67          {
68              googleTracker = new GoogleAmpsTracker(getProductId(),getLog());
69  
70              if(googleTrackingAllowed()) {
71                  getLog().info("Google Analytics Tracking is enabled to collect AMPS usage statistics.");
72                  getLog().info("Although no personal information is sent, you may disable tracking by adding <allowGoogleTracking>false</allowGoogleTracking> to the amps plugin configuration in your pom.xml");
73              }
74          }
75  
76          googleTracker.setEnabled(googleTrackingAllowed());
77  
78          return googleTracker;
79      }
80  
81      protected boolean googleTrackingAllowed() {
82          return allowGoogleTracking;
83      }
84  }