1   package com.atlassian.maven.plugins.amps;
2   
3   import com.atlassian.maven.plugins.amps.product.studio.StudioProductHandler;
4   import com.atlassian.maven.plugins.amps.product.studio.StudioProperties;
5   import com.atlassian.maven.plugins.amps.util.ArtifactRetriever;
6   
7   import java.io.File;
8   import java.util.HashMap;
9   import java.util.List;
10  import java.util.ArrayList;
11  import java.util.Map;
12  import java.util.Properties;
13  
14  import org.apache.maven.surefire.shade.org.apache.commons.lang.StringUtils;
15  
16  public class Product
17  {
18      /**
19       * Container to run in
20       */
21      protected String containerId;
22  
23      /**
24       * HTTP port for the servlet containers
25       */
26      private int httpPort = 0;
27  
28      /**
29       * Application context path, in the format: /context-path
30       */
31      protected String contextPath;
32  
33      /**
34       * Application server
35       */
36      protected String server;
37  
38      /**
39       * Webapp version
40       */
41      protected String version;
42  
43      /**
44       * JVM arguments to pass to cargo
45       */
46      protected String jvmArgs = null;
47  
48      /**
49       * A log4j properties file
50       */
51      protected File log4jProperties;
52  
53      /**
54       * The test resources version
55       */
56      protected String productDataVersion;
57  
58      /**
59       * The path to a custom test resources zip or a directory. Takes precedence over dataVersion.
60       * The data from this path will be copied into the home directory.
61       */
62      protected String productDataPath = "";
63  
64      /**
65       * The path to the product's home directory. Takes precedence over dataPath.
66       * The data from this path will be used directly (read/write) by the product.
67       */
68      protected String dataHome = "";
69  
70      /**
71       */
72      private List<ProductArtifact> pluginArtifacts = new ArrayList<ProductArtifact>();
73  
74      /**
75       */
76      private List<ProductArtifact> libArtifacts = new ArrayList<ProductArtifact>();
77  
78      /**
79       */
80      private List<ProductArtifact> bundledArtifacts = new ArrayList<ProductArtifact>();
81  
82      /**
83       * SAL version
84       */
85      private String salVersion;
86  
87      /**
88       * Atlassian Plugin Development Kit (PDK) version
89       */
90      private String pdkVersion;
91  
92      /**
93       * Atlassian REST module version
94       */
95      private String restVersion;
96  
97      /**
98       * Version of the Felix OSGi web console
99       */
100     private String webConsoleVersion;
101 
102     /**
103      * Flag to indicate whether or not to enable automatic bundling of Fastdev.
104      */
105     private Boolean enableFastdev;
106 
107     /**
108      * Version of the Fastdev plugin
109      */
110     private String fastdevVersion;
111 
112     /**
113      * Flag to indicate whether or not to enable automatic bundling of DevToolbox.
114      */
115     private Boolean enableDevToolbox;
116 
117     /**
118      * Version of the Developer Toolbox plugin
119      */
120     private String devToolboxVersion;
121 
122     /**
123      * Flag to indicate whether or not to enable automatic bundling of PDE.
124      */
125     private Boolean enablePde;
126 
127     /**
128      * Version of the PDE plugin
129      */
130     private String pdeVersion;
131     
132     /**
133      * Product id - nickname of the product to run
134      */
135     private String id;
136 
137     /**
138      * The name of the instance of the product
139      */
140     private String instanceId;
141 
142     private ArtifactRetriever artifactRetriever;
143 
144     /**
145      * Flag to indicate whether or not to install the plugin
146      */
147     private Boolean installPlugin;
148 
149     /**
150      * The system properties to set for the product
151      */
152     private Map<String,Object> systemProperties = new HashMap<String,Object>();
153 
154     /**
155      * File the container should log to.
156      */
157     private String output;
158 
159     /**
160      * Port for debugging
161      */
162     private int jvmDebugPort;
163 
164     /**
165      * How long to wait for product startup, in milliseconds; if not specified, default is determined by AbstractProductHandlerMojo
166      */
167     private int startupTimeout = 0;
168 
169     /**
170      * How long to wait for product shutdown, in milliseconds; if not specified, default is determined by AbstractProductHandlerMojo
171      */
172     private int shutdownTimeout = 0;
173 
174     /**
175      * Waits until the application is up before proceeding to the next one (blocking call).<ul>
176      * <li>If -Dparallel is not specified, default is TRUE for all products.</li>
177      * <li>If -Dparallel is specified, default is FALSE except for Studio-Crowd and FeCru.</li>
178      * <li>The pom.xml overrides the default values.</li>
179      * <li>Use -Dparallel to start products in parallel. {@link AbstractProductHandlerMojo#setParallelMode(List)} sets the default values according to this parameter.</li>
180      * </ul>
181      */
182     private Boolean synchronousStartup;
183 
184     /**
185      * An optional override of the webapp's groupId
186      */
187     private String groupId;
188 
189     /**
190      * An optional override of the webapp's artifactId
191      */
192     private String artifactId;
193 
194 
195 
196     /**
197      * The studio configuration which is shared for all products in the same
198      * studio instance. Null if products are not studio or not yet configured.
199      * <p>
200      * {@link StudioProductHandler#configure(Product, List)} will set this value.
201      * It must be called before Studio products are launched.
202      */
203     protected StudioProperties studioProperties;
204 
205 
206     /**
207      * Only applies to Studio
208      * List of 'sub'-products that are managed by this Studio instance.
209      * Optional. Default value is: studio-crowd, studio-confluence, studio-fecru, studio-bamboo, studio-jira.
210      */
211     protected List<String> instanceIds = new ArrayList<String>();
212 
213     /**
214      * Only applies to Studio
215      * Set 'true' if GApps is enabled. Default is 'false'
216      */
217     protected String gappsEnabled;
218 
219     /**
220      * Only applies to Studio
221      * The GApps domain, if GApps is enabled
222      */
223     protected String gappsDomain;
224 
225     /**
226      * Only applies to StudioFecru
227      * Tells whether shutdown is enabled for Fisheye. This property is passed on in the properties files.
228      */
229     protected Boolean shutdownEnabled;
230 
231 
232 
233     /**
234      * Creates a new product that is merged with this one, where the properties in this one override the passed
235      * in product.
236      * @param product The product to merge with
237      * @return A new product
238      */
239     public Product merge(Product product)
240     {
241         Product prod = new Product();
242         prod.setOutput(output == null ? product.getOutput() : output);
243 
244         Map<String,Object> sysProps = new HashMap<String,Object>();
245         sysProps.putAll(product.getSystemPropertyVariables());
246         sysProps.putAll(systemProperties);
247         prod.setSystemPropertyVariables(sysProps);
248 
249         prod.setInstallPlugin(installPlugin == null ? product.isInstallPlugin() : installPlugin);
250         prod.setArtifactRetriever(artifactRetriever == null ? product.getArtifactRetriever() : artifactRetriever);
251         prod.setId(id == null ? product.getId() : id);
252         prod.setInstanceId(instanceId == null ? product.getInstanceId() : instanceId);
253         prod.setWebConsoleVersion(webConsoleVersion == null ? product.getWebConsoleVersion() : webConsoleVersion);
254         prod.setEnableFastdev(enableFastdev == null ? product.isEnableFastdev() : enableFastdev);
255         prod.setFastdevVersion(fastdevVersion == null ? product.getFastdevVersion() : fastdevVersion);
256         prod.setEnableDevToolbox(enableDevToolbox == null ? product.isEnableDevToolbox() : enableDevToolbox);
257         prod.setDevToolboxVersion(devToolboxVersion == null ? product.getDevToolboxVersion() : devToolboxVersion);
258         prod.setEnablePde(enablePde == null ? product.isEnablePde() : enablePde);
259         prod.setPdeVersion(pdeVersion == null ? product.getPdeVersion() : pdeVersion);
260         prod.setRestVersion(restVersion == null ? product.getRestVersion() : restVersion);
261         prod.setPdkVersion(pdkVersion == null ? product.getPdkVersion() : pdkVersion);
262         prod.setSalVersion(salVersion == null ? product.getSalVersion() : salVersion);
263 
264         prod.setBundledArtifacts(bundledArtifacts.isEmpty() ? product.getBundledArtifacts() : bundledArtifacts);
265         prod.setPluginArtifacts(pluginArtifacts.isEmpty() ? product.getPluginArtifacts() : pluginArtifacts);
266         prod.setLibArtifacts(libArtifacts.isEmpty() ? product.getLibArtifacts() : libArtifacts);
267 
268         prod.setDataPath(StringUtils.isBlank(productDataPath) ? product.getDataPath() : productDataPath);
269         prod.setDataVersion(productDataVersion == null ? product.getDataVersion() : productDataVersion);
270         prod.setDataHome(dataHome == null ? product.getDataHome() : dataHome);
271         prod.setLog4jProperties(log4jProperties == null ? product.getLog4jProperties() : log4jProperties);
272         prod.setJvmArgs(jvmArgs == null ? product.getJvmArgs() : jvmArgs);
273         prod.setGroupId(groupId == null ? product.getGroupId() : groupId);
274         prod.setArtifactId(artifactId == null ? product.getArtifactId() : artifactId);
275         prod.setVersion(version == null ? product.getVersion() : version);
276 
277         prod.setServer(server == null ? product.getServer() : server);
278         prod.setContextPath(contextPath == null ? product.getContextPath() : contextPath);
279         prod.setContainerId(containerId == null ? product.getContainerId() : containerId);
280         prod.setHttpPort(httpPort == 0 ? product.getHttpPort() : httpPort);
281         prod.setJvmDebugPort(jvmDebugPort == 0 ? product.getJvmDebugPort() : jvmDebugPort);
282 
283         prod.setStartupTimeout(startupTimeout == 0 ? product.getStartupTimeout() : startupTimeout);
284         prod.setShutdownTimeout(shutdownTimeout == 0 ? product.getShutdownTimeout() : shutdownTimeout);
285         prod.setSynchronousStartup(synchronousStartup == null ? product.getSynchronousStartup() : synchronousStartup);
286 
287         // Studio-related properties
288         prod.setStudioProperties(studioProperties == null ? product.getStudioProperties() : studioProperties);
289         prod.setInstanceIds(instanceIds == null ? product.getInstanceIds() : instanceIds);
290         prod.setShutdownEnabled(shutdownEnabled == null ? product.getShutdownEnabled() : shutdownEnabled);
291 
292         return prod;
293     }
294 
295     public String getContainerId()
296     {
297         return containerId;
298     }
299 
300     public void setContainerId(String containerId)
301     {
302         this.containerId = containerId;
303     }
304 
305     public String getServer()
306     {
307         return server;
308     }
309 
310     public void setServer(String server)
311     {
312         this.server = server;
313     }
314 
315     public int getHttpPort()
316     {
317         return httpPort;
318     }
319 
320     public void setHttpPort(int httpPort)
321     {
322         this.httpPort = httpPort;
323     }
324 
325     public String getContextPath()
326     {
327         return contextPath;
328     }
329 
330     public void setContextPath(String contextPath)
331     {
332         this.contextPath = contextPath;
333     }
334 
335     public String getJvmArgs()
336     {
337         return jvmArgs;
338     }
339 
340     public void setJvmArgs(String jvmArgs)
341     {
342         this.jvmArgs = jvmArgs;
343     }
344 
345     public ArtifactRetriever getArtifactRetriever()
346     {
347         return artifactRetriever;
348     }
349 
350     public void setArtifactRetriever(ArtifactRetriever artifactRetriever)
351     {
352         this.artifactRetriever = artifactRetriever;
353     }
354 
355     public String getVersion()
356     {
357         return version;
358     }
359 
360     public void setVersion(String version)
361     {
362         this.version = version;
363     }
364 
365     public String getDataVersion()
366     {
367         return productDataVersion;
368     }
369 
370     public void setDataVersion(String productDataVersion)
371     {
372         this.productDataVersion = productDataVersion;
373     }
374 
375     /**
376      * @deprecated since 3.2
377      */
378     public String getProductDataVersion()
379     {
380         return productDataVersion;
381     }
382 
383     /**
384      * @deprecated since 3.2
385      */
386     public void setProductDataVersion(String productDataVersion)
387     {
388         this.productDataVersion = productDataVersion;
389     }
390 
391     /**
392      * The path to a custom test resources zip or a directory. Takes precedence over dataVersion.
393      * The data from this path will be copied into the home directory.
394      */
395     public String getDataPath()
396     {
397         return productDataPath;
398     }
399 
400     /**
401      * The path to a custom test resources zip or a directory. Takes precedence over dataVersion.
402      * The data from this path will be copied into the home directory.
403      */
404     public void setDataPath(String productDataPath)
405     {
406         this.productDataPath = productDataPath;
407     }
408 
409     /**
410      * @deprecated since 3.2
411      */
412     public String getProductDataPath()
413     {
414         return productDataPath;
415     }
416 
417     /**
418      * @deprecated since 3.2
419      */
420     public void setProductDataPath(String productDataPath)
421     {
422         this.productDataPath = productDataPath;
423     }
424 
425     public List<ProductArtifact> getPluginArtifacts()
426     {
427         return pluginArtifacts;
428     }
429 
430     public void setPluginArtifacts(List<ProductArtifact> pluginArtifacts)
431     {
432         this.pluginArtifacts = pluginArtifacts;
433     }
434 
435     public List<ProductArtifact> getLibArtifacts()
436     {
437         return libArtifacts;
438     }
439 
440     public void setLibArtifacts(List<ProductArtifact> libArtifacts)
441     {
442         this.libArtifacts = libArtifacts;
443     }
444 
445     public List<ProductArtifact> getBundledArtifacts()
446     {
447         return bundledArtifacts;
448     }
449 
450     public void setBundledArtifacts(List<ProductArtifact> bundledArtifacts)
451     {
452         this.bundledArtifacts = bundledArtifacts;
453     }
454 
455     public File getLog4jProperties()
456     {
457         return log4jProperties;
458     }
459 
460     public void setLog4jProperties(File log4jProperties)
461     {
462         this.log4jProperties = log4jProperties;
463     }
464 
465     public String getRestVersion()
466     {
467         return restVersion;
468     }
469 
470     public void setRestVersion(String restVersion)
471     {
472         this.restVersion = restVersion;
473     }
474 
475     public String getSalVersion()
476     {
477         return salVersion;
478     }
479 
480     public void setSalVersion(String salVersion)
481     {
482         this.salVersion = salVersion;
483     }
484 
485     public String getPdkVersion()
486     {
487         return pdkVersion;
488     }
489 
490     public void setPdkVersion(String pdkVersion)
491     {
492         this.pdkVersion = pdkVersion;
493     }
494 
495     public String getId()
496     {
497         return id;
498     }
499 
500     public void setId(String id)
501     {
502         this.id = id;
503     }
504 
505     public String getInstanceId()
506     {
507         return instanceId;
508     }
509 
510     public void setInstanceId(String instanceId)
511     {
512         this.instanceId = instanceId;
513     }
514 
515     public Boolean isInstallPlugin()
516     {
517         return installPlugin;
518     }
519 
520     public void setInstallPlugin(final Boolean installPlugin)
521     {
522         this.installPlugin = installPlugin;
523     }
524 
525     public String getWebConsoleVersion()
526     {
527         return webConsoleVersion;
528     }
529 
530     public Boolean isEnableFastdev()
531     {
532         return enableFastdev;
533     }
534 
535     public void setEnableFastdev(final Boolean enableFastdev)
536     {
537         this.enableFastdev = enableFastdev;
538     }
539 
540     public String getFastdevVersion()
541     {
542         return fastdevVersion;
543     }
544 
545     public void setFastdevVersion(String fastdevVersion)
546     {
547         this.fastdevVersion = fastdevVersion;
548     }
549 
550     public Boolean isEnableDevToolbox()
551     {
552         return enableDevToolbox;
553     }
554 
555     public void setEnableDevToolbox(final Boolean enableDevToolbox)
556     {
557         this.enableDevToolbox = enableDevToolbox;
558     }
559 
560     public String getDevToolboxVersion()
561     {
562         return devToolboxVersion;
563     }
564 
565     public void setDevToolboxVersion(String devToolboxVersion)
566     {
567         this.devToolboxVersion = devToolboxVersion;
568     }
569 
570     public Boolean isEnablePde()
571     {
572         return enablePde;
573     }
574 
575     public void setEnablePde(Boolean enablePde)
576     {
577         this.enablePde = enablePde;
578     }
579 
580     public String getPdeVersion()
581     {
582         return pdeVersion;
583     }
584 
585     public void setPdeVersion(String pdeVersion)
586     {
587         this.pdeVersion = pdeVersion;
588     }
589 
590     public void setWebConsoleVersion(String webConsoleVersion)
591     {
592         this.webConsoleVersion = webConsoleVersion;
593     }
594 
595     /**
596      * @deprecated Since 3.2, use systemPropertyVariables
597      */
598     public void setSystemProperties(Properties systemProperties)
599     {
600         this.systemProperties.putAll((Map) systemProperties);
601     }
602 
603     /**
604      * @deprecated Since 3.2, use systemPropertyVariables
605      */
606     public Properties getSystemProperties()
607     {
608         Properties props = new Properties();
609         props.putAll(systemProperties);
610         return props;
611     }
612 
613     public void setSystemPropertyVariables(Map<String,Object> systemProperties)
614     {
615         this.systemProperties = systemProperties;
616     }
617 
618     public Map<String,Object> getSystemPropertyVariables()
619     {
620         return systemProperties;
621     }
622 
623     public String getOutput()
624     {
625         return output;
626     }
627 
628     public void setOutput(String output)
629     {
630         this.output = output;
631     }
632 
633     public int getJvmDebugPort()
634     {
635         return jvmDebugPort;
636     }
637 
638     public void setJvmDebugPort(int jvmDebugPort)
639     {
640         this.jvmDebugPort = jvmDebugPort;
641     }
642 
643     public int getStartupTimeout()
644     {
645         return startupTimeout;
646     }
647 
648     public void setStartupTimeout(int startupTimeout)
649     {
650         this.startupTimeout = startupTimeout;
651     }
652 
653     public int getShutdownTimeout()
654     {
655         return shutdownTimeout;
656     }
657 
658     public void setShutdownTimeout(int shutdownTimeout)
659     {
660         this.shutdownTimeout = shutdownTimeout;
661     }
662 
663     public String getGroupId()
664     {
665         return groupId;
666     }
667 
668     public void setGroupId(String groupId)
669     {
670         this.groupId = groupId;
671     }
672 
673     public String getArtifactId()
674     {
675         return artifactId;
676     }
677 
678     public void setArtifactId(String artifactId)
679     {
680         this.artifactId = artifactId;
681     }
682 
683     public StudioProperties getStudioProperties()
684     {
685         return studioProperties;
686     }
687 
688     public void setStudioProperties(StudioProperties studioProperties)
689     {
690         this.studioProperties = studioProperties;
691     }
692 
693     public List<String> getInstanceIds()
694     {
695         return instanceIds;
696     }
697 
698     public void setInstanceIds(List<String> instanceIds)
699     {
700         this.instanceIds = instanceIds;
701     }
702 
703     public String getGappsEnabled()
704     {
705         return gappsEnabled;
706     }
707 
708     public void setGappsEnabled(String gappsEnabled)
709     {
710         this.gappsEnabled = gappsEnabled;
711     }
712 
713     public String getGappsDomain()
714     {
715         return gappsDomain;
716     }
717 
718     public void setGappsDomain(String gappsDomain)
719     {
720         this.gappsDomain = gappsDomain;
721     }
722 
723     public void setSystemProperties(Map<String, Object> systemProperties)
724     {
725         this.systemProperties = systemProperties;
726     }
727 
728     public Boolean getShutdownEnabled()
729     {
730         return shutdownEnabled;
731     }
732 
733     public void setShutdownEnabled(Boolean shutdownEnabled)
734     {
735         this.shutdownEnabled = shutdownEnabled;
736     }
737 
738     public Boolean getSynchronousStartup()
739     {
740         return synchronousStartup;
741     }
742 
743     public void setSynchronousStartup(Boolean synchronousStartup)
744     {
745         this.synchronousStartup = synchronousStartup;
746     }
747 
748 
749     public String getDataHome()
750     {
751         return dataHome;
752     }
753 
754     /**
755      * The path to the product's home directory. Takes precedence over dataPath.
756      * The data from this path will be used directly (read/write) by the product.
757      */
758     public void setDataHome(String dataHome)
759     {
760         this.dataHome = dataHome;
761     }
762 
763     @Override
764     public String toString()
765     {
766         return "Product " + id + " [instanceId=" + instanceId + ", localhost:" + httpPort + contextPath + "]";
767     }
768 
769 }