1   package com.atlassian.maven.plugins.amps.product.studio;
2   
3   import static com.atlassian.maven.plugins.amps.util.ProjectUtils.firstNotNull;
4   
5   import java.io.File;
6   import java.util.Map;
7   
8   import org.apache.maven.surefire.shade.org.apache.commons.lang.StringUtils;
9   
10  import com.atlassian.maven.plugins.amps.Product;
11  import com.atlassian.maven.plugins.amps.product.FeCruProductHandler;
12  import com.atlassian.maven.plugins.amps.product.ProductHandlerFactory;
13  import com.google.common.collect.ImmutableMap;
14  import com.google.common.collect.Maps;
15  
16  /**
17   * This bean shares the configuration of Studio across all products
18   * @since 3.6
19   */
20  public class StudioProperties
21  {
22  
23      /**
24       * The Studio version, which will be used to retrieve each product artifact.
25       */
26      protected String version;
27  
28      /** The runtime place where studio-home will be. */
29      private String studioHome;
30      /** This property is required by the studio.properties files, but is different from studioHome. */
31      private String studioDataLocation;
32      private Product studioProduct;
33      private boolean modeConfluenceStandalone = false;
34  
35      private String svnRoot;
36      private String svnPublicUrl;
37      private String svnImportStagingDirectory;
38  
39      private String webDavHome;
40  
41      private Product jira;
42      private String greenHopperLicense;
43  
44      private Product confluence;
45  
46      private Product fisheye;
47  
48      private Product bamboo;
49      private Product crowd;
50  
51      private boolean gappsEnabled;
52      private String gappsDomain;
53  
54      private Map<String, String> systemProperties = Maps.newHashMap();
55  
56      /**
57       * Constructs the StudioProperties using the values from the studio product
58       *
59       * @param studioContext
60       *            the Studio product
61       */
62      public StudioProperties(Product studioContext)
63      {
64          if (!ProductHandlerFactory.STUDIO.equals(studioContext.getId()))
65          {
66              throw new IllegalArgumentException("The Studio Properties should be based on the Studio product");
67          }
68          version = firstNotNull(studioContext.getVersion(), "RELEASE");
69          studioProduct = studioContext;
70  
71          gappsEnabled = Boolean.getBoolean(studioContext.getGappsEnabled());
72          gappsDomain = firstNotNull(studioContext.getGappsDomain(), "");
73      }
74  
75      public void setVersion(String version)
76      {
77          this.version = version;
78      }
79  
80      public void setStudioHome(String studioHome)
81      {
82          this.studioHome = studioHome;
83      }
84  
85      public void setStudioDataLocation(String studioDataLocation)
86      {
87          this.studioDataLocation = studioDataLocation;
88      }
89  
90      public void setModeConfluenceStandalone(boolean modeConfluenceStandalone)
91      {
92          this.modeConfluenceStandalone = modeConfluenceStandalone;
93      }
94  
95      public void setSvnRoot(String svnRoot)
96      {
97          this.svnRoot = svnRoot;
98      }
99  
100     public void setSvnPublicUrl(String svnPublicUrl)
101     {
102         this.svnPublicUrl = svnPublicUrl;
103     }
104 
105     public void setSvnImportStagingDirectory(String svnImportStagingDirectory)
106     {
107         this.svnImportStagingDirectory = svnImportStagingDirectory;
108     }
109 
110     public void setWebDavHome(String webDavHome)
111     {
112         this.webDavHome = webDavHome;
113     }
114 
115     public void setJira(Product jira)
116     {
117         this.jira = jira;
118     }
119 
120     public void setGreenHopperLicense(String greenHopperLicense)
121     {
122         this.greenHopperLicense = greenHopperLicense;
123     }
124 
125     public void setConfluence(Product confluence)
126     {
127         this.confluence = confluence;
128     }
129 
130     public void setFisheye(Product fisheye)
131     {
132         this.fisheye = fisheye;
133     }
134 
135     public void setBamboo(Product bamboo)
136     {
137         this.bamboo = bamboo;
138     }
139 
140     public void setCrowd(Product crowd)
141     {
142         this.crowd = crowd;
143     }
144 
145     public void setGappsEnabled(boolean gappsEnabled)
146     {
147         this.gappsEnabled = gappsEnabled;
148     }
149 
150     public void setGappsDomain(String gappsDomain)
151     {
152         this.gappsDomain = gappsDomain;
153     }
154 
155     public String getVersion()
156     {
157         return version;
158     }
159 
160     public String getStudioHome()
161     {
162         return studioHome;
163     }
164 
165     public String getStudioDataLocation()
166     {
167         return studioDataLocation;
168     }
169 
170     public Product getStudioProduct()
171     {
172         return studioProduct;
173     }
174 
175     public void setStudioProduct(Product studioProduct)
176     {
177         this.studioProduct = studioProduct;
178     }
179 
180     public Map<String, String> getSystemProperties()
181     {
182         return ImmutableMap.copyOf(systemProperties);
183     }
184 
185     public void overrideSystemProperty(String key, String value)
186     {
187         this.systemProperties.put(key, value);
188     }
189 
190     public boolean isModeConfluenceStandalone()
191     {
192         return modeConfluenceStandalone;
193     }
194 
195     public String getSvnRoot()
196     {
197         return svnRoot;
198     }
199 
200     public String getSvnPublicUrl()
201     {
202         return svnPublicUrl;
203     }
204 
205     public String getSvnHooks()
206     {
207         if (svnRoot != null)
208         {
209             return new File(svnRoot, "hooks").getAbsolutePath();
210         }
211         return null;
212     }
213 
214     public String getSvnImportStagingDirectory()
215     {
216         return svnImportStagingDirectory;
217     }
218 
219     public String getWebDavHome()
220     {
221         return webDavHome;
222     }
223 
224     public String getGreenHopperLicense()
225     {
226         return greenHopperLicense;
227     }
228 
229     public Product getConfluence()
230     {
231         return confluence;
232     }
233     public Product getJira()
234     {
235         return jira;
236     }
237 
238     public Product getFisheye()
239     {
240         return fisheye;
241     }
242 
243     public boolean getFisheyeShutdownEnabled()
244     {
245         return fisheye.getShutdownEnabled();
246     }
247 
248     public String getFisheyeControlPort()
249     {
250         return String.valueOf(FeCruProductHandler.controlPort(fisheye.getHttpPort()));
251     }
252 
253     public Product getBamboo()
254     {
255         return bamboo;
256     }
257 
258     public Product getCrowd()
259     {
260         return crowd;
261     }
262 
263     public boolean isGappsEnabled()
264     {
265         return gappsEnabled;
266     }
267 
268     public String getGappsDomain()
269     {
270         return firstNotNull(gappsDomain, "");
271     }
272 
273 
274 
275 
276     // Custom getters
277 
278     // JIRA getters
279     public int getJiraPort()
280     {
281         return jira != null ? jira.getHttpPort() : 0;
282     }
283 
284     public String getJiraContextPath()
285     {
286         if (jira == null || StringUtils.isBlank(jira.getContextPath()))
287         {
288             return "";
289         }
290         return jira.getContextPath().replaceAll("/", "");
291     }
292 
293     public String getJiraUrl()
294     {
295         if (jira == null)
296         {
297             return "";
298         }
299         return String.format("http://localhost:%d%s", jira.getHttpPort(), jira.getContextPath());
300     }
301 
302     public String getJiraHostUrl()
303     {
304         if (jira == null)
305         {
306             return "";
307         }
308         return String.format("http://localhost:%d", jira.getHttpPort());
309     }
310 
311     public boolean isJiraEnabled()
312     {
313         return !modeConfluenceStandalone;
314     }
315 
316     // Confluence getters
317     public int getConfluencePort()
318     {
319         return confluence != null ? confluence.getHttpPort() : 0;
320     }
321 
322     public String getConfluenceContextPath()
323     {
324         if (confluence == null || StringUtils.isBlank(confluence.getContextPath()))
325         {
326             return "";
327         }
328         return confluence.getContextPath().replaceAll("/", "");
329     }
330 
331     public String getConfluenceUrl()
332     {
333         if (confluence == null)
334         {
335             return "";
336         }
337         return String.format("http://localhost:%d%s", confluence.getHttpPort(), confluence.getContextPath());
338     }
339 
340     public String getConfluenceHostUrl()
341     {
342         if (confluence == null)
343         {
344             return "";
345         }
346         return String.format("http://localhost:%d", confluence.getHttpPort());
347     }
348 
349     public boolean isConfluenceEnabled()
350     {
351         return confluence != null;
352     }
353 
354     // FishEye getters
355     public int getFisheyePort()
356     {
357         return fisheye != null ? fisheye.getHttpPort() : 0;
358     }
359     public String getFisheyeContextPath()
360     {
361         if (fisheye == null || StringUtils.isBlank(fisheye.getContextPath()))
362         {
363             return "";
364         }
365         return fisheye.getContextPath().replaceAll("/", "");
366     }
367 
368     public String getFisheyeUrl()
369     {
370         if (fisheye == null)
371         {
372             return "";
373         }
374         if (StringUtils.isNotBlank(fisheye.getContextPath()) && !"/".equals(fisheye.getContextPath()))
375         {
376             return String.format("http://localhost:%d%s", fisheye.getHttpPort(), fisheye.getContextPath());
377         }
378         else
379         {
380             return String.format("http://localhost:%d", fisheye.getHttpPort());
381         }
382     }
383 
384     public String getFisheyeHostUrl()
385     {
386         return getFisheyeUrl();
387     }
388 
389     public boolean isFisheyeEnabled()
390     {
391         return fisheye != null;
392     }
393 
394     // Bamboo getters
395     public String getBambooContextPath()
396     {
397         if (bamboo == null || StringUtils.isBlank(bamboo.getContextPath()))
398         {
399             return "";
400         }
401         return bamboo.getContextPath().replaceAll("/", "");
402     }
403 
404     public int getBambooPort()
405     {
406         return bamboo != null ? bamboo.getHttpPort() : 0;
407     }
408 
409     public String getBambooUrl()
410     {
411         if (bamboo == null)
412         {
413             return "";
414         }
415         return String.format("http://localhost:%d%s", bamboo.getHttpPort(), bamboo.getContextPath());
416     }
417 
418     public String getBambooHostUrl()
419     {
420         if (bamboo == null)
421         {
422             return "";
423         }
424         return String.format("http://localhost:%d", bamboo.getHttpPort());
425     }
426 
427     public boolean isBambooEnabled()
428     {
429         return bamboo != null;
430     }
431 
432     // Crowd getters
433     public String getCrowdUrl()
434     {
435         if (crowd == null)
436         {
437             return "";
438         }
439         return String.format("http://localhost:%d%s", crowd.getHttpPort(), crowd.getContextPath());
440     }
441 
442     public String getCrowdHostUrl()
443     {
444         if (crowd == null)
445         {
446             return "";
447         }
448         return String.format("http://localhost:%d", crowd.getHttpPort());
449     }
450 
451     public String getCrowdContextPath()
452     {
453         if (crowd == null || StringUtils.isBlank(crowd.getContextPath()))
454         {
455             return "";
456         }
457         return crowd.getContextPath().replaceAll("/", "");
458     }
459 
460     public int getCrowdPort()
461     {
462         return crowd != null ? crowd.getHttpPort() : 0;
463     }
464 
465 
466 }