View Javadoc

1   package org.kuali.maven.plugin.ksite.mojo;
2   
3   import java.util.Properties;
4   
5   import org.apache.maven.model.DistributionManagement;
6   import org.apache.maven.model.Site;
7   import org.apache.maven.plugin.AbstractMojo;
8   import org.apache.maven.plugin.MojoExecutionException;
9   import org.apache.maven.plugin.MojoFailureException;
10  import org.apache.maven.project.MavenProject;
11  import org.kuali.maven.common.SiteContext;
12  import org.kuali.maven.common.UrlBuilder;
13  
14  /**
15   * This plugin organizes/standardizes the maven site publication process for the Kuali organization
16   *
17   * @goal kualisite
18   * @phase pre-site
19   */
20  public class KualiSiteMojo extends AbstractMojo implements SiteContext {
21  
22      /**
23       * The prefix into the bucket when downloading a snapshot version
24       *
25       * @parameter expression="${downloadSnapshotPrefix}" default-value="snapshot"
26       */
27      private String downloadSnapshotPrefix;
28  
29      /**
30       * The prefix into the bucket when downloading a release version
31       *
32       * @parameter expression="${downloadReleasePrefix}" default-value="release"
33       */
34      private String downloadReleasePrefix;
35  
36      /**
37       * The protocol used when publishing the web site
38       *
39       * @parameter expression="${publishUrlProtocol}" default-value="s3"
40       */
41      private String publishUrlProtocol;
42  
43      /**
44       * The protocol for the public facing website
45       *
46       * @parameter expression="${publicUrlProtocol}" default-value="http"
47       */
48      private String publicUrlProtocol;
49  
50      /**
51       * The prefix for the location that artifacts can be downloaded from
52       *
53       * @parameter expression="${downloadPrefix}"
54       * default-value="http://s3browse.springsource.com/browse/maven.kuali.org/"
55       */
56      private String downloadPrefix;
57  
58      /**
59       * The groupId for the organization
60       *
61       * @parameter expression="${organizationGroupId}" default-value="org.kuali"
62       */
63      private String organizationGroupId;
64  
65      /**
66       * The name of the AWS bucket the site gets published to
67       *
68       * @parameter expression="${bucket}" default-value="site.origin.kuali.org"
69       * @required
70       */
71      private String bucket;
72  
73      /**
74       * The public DNS name for the site
75       *
76       * @parameter expression="${hostname}" default-value="site.kuali.org"
77       * @required
78       */
79      private String hostname;
80  
81      /**
82       * The Maven project this plugin runs in.
83       *
84       * @parameter expression="${project}"
85       * @required
86       * @readonly
87       */
88      private MavenProject project;
89  
90      @Override
91      public void execute() throws MojoExecutionException, MojoFailureException {
92          UrlBuilder builder = new UrlBuilder();
93  
94          // Generate our urls
95          String publicUrl = builder.getPublicUrl(getProject(), this);
96          String publishUrl = builder.getPublishUrl(getProject(), this);
97          String downloadUrl = builder.getDownloadUrl(getProject(), this);
98  
99          // Get a reference to the relevant model objects
100         MavenProject project = getProject();
101         DistributionManagement dm = project.getDistributionManagement();
102         Site site = dm.getSite();
103 
104         getLog().info("Public url  - " + publicUrl);
105         getLog().info("Publish url  - " + publishUrl);
106         getLog().info("Download url - " + downloadUrl);
107 
108         // Update the model with our generated urls
109         project.setUrl(publicUrl);
110         dm.setDownloadUrl(downloadUrl);
111         site.setUrl(publishUrl);
112 
113         // Update project properties
114         Properties properties = getProject().getProperties();
115         properties.setProperty("kuali.site.public.url", publicUrl);
116     }
117 
118     /**
119      * @return the project
120      */
121     public MavenProject getProject() {
122         return project;
123     }
124 
125     /**
126      * @param project
127      * the project to set
128      */
129     public void setProject(final MavenProject project) {
130         this.project = project;
131     }
132 
133     /**
134      * @return the bucket
135      */
136     @Override
137     public String getBucket() {
138         return bucket;
139     }
140 
141     /**
142      * @param bucket
143      * the bucket to set
144      */
145     public void setBucket(final String bucket) {
146         this.bucket = bucket;
147     }
148 
149     /**
150      * @return the hostname
151      */
152     @Override
153     public String getHostname() {
154         return hostname;
155     }
156 
157     /**
158      * @param hostname
159      * the hostname to set
160      */
161     public void setHostname(final String hostname) {
162         this.hostname = hostname;
163     }
164 
165     /**
166      * @return the downloadPrefix
167      */
168     @Override
169     public String getDownloadPrefix() {
170         return downloadPrefix;
171     }
172 
173     /**
174      * @param downloadPrefix
175      * the downloadPrefix to set
176      */
177     public void setDownloadPrefix(final String downloadPrefix) {
178         this.downloadPrefix = downloadPrefix;
179     }
180 
181     /**
182      * @return the parentGroupId
183      */
184     @Override
185     public String getOrganizationGroupId() {
186         return organizationGroupId;
187     }
188 
189     /**
190      * @param parentGroupId
191      * the parentGroupId to set
192      */
193     public void setOrganizationGroupId(final String parentGroupId) {
194         this.organizationGroupId = parentGroupId;
195     }
196 
197     /**
198      * @return the publishUrlProtocol
199      */
200     @Override
201     public String getPublishUrlProtocol() {
202         return publishUrlProtocol;
203     }
204 
205     /**
206      * @param publishUrlProtocol
207      * the publishUrlProtocol to set
208      */
209     public void setPublishUrlProtocol(final String publishUrlProtocol) {
210         this.publishUrlProtocol = publishUrlProtocol;
211     }
212 
213     /**
214      * @return the publicUrlProtocol
215      */
216     @Override
217     public String getPublicUrlProtocol() {
218         return publicUrlProtocol;
219     }
220 
221     /**
222      * @param publicUrlProtocol
223      * the publicUrlProtocol to set
224      */
225     public void setPublicUrlProtocol(final String publicUrlProtocol) {
226         this.publicUrlProtocol = publicUrlProtocol;
227     }
228 
229     /**
230      * @return the downloadSnapshotPrefix
231      */
232     @Override
233     public String getDownloadSnapshotPrefix() {
234         return downloadSnapshotPrefix;
235     }
236 
237     /**
238      * @param downloadSnapshotPrefix
239      * the downloadSnapshotPrefix to set
240      */
241     public void setDownloadSnapshotPrefix(final String downloadSnapshotPrefix) {
242         this.downloadSnapshotPrefix = downloadSnapshotPrefix;
243     }
244 
245     /**
246      * @return the downloadReleasePrefix
247      */
248     @Override
249     public String getDownloadReleasePrefix() {
250         return downloadReleasePrefix;
251     }
252 
253     /**
254      * @param downloadReleasePrefix
255      * the downloadReleasePrefix to set
256      */
257     public void setDownloadReleasePrefix(final String downloadReleasePrefix) {
258         this.downloadReleasePrefix = downloadReleasePrefix;
259     }
260 
261 }