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
13
14 @MojoParameter(expression = "${product}")
15 private String product;
16
17
18
19
20
21 @MojoParameter(expression = "${instanceId}")
22 protected String instanceId;
23
24
25
26
27
28
29
30
31
32
33
34
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 }