1   package com.atlassian.maven.plugins.amps;
2   
3   import com.atlassian.maven.plugins.amps.product.studio.StudioProperties;
4   import com.atlassian.maven.plugins.amps.util.ArtifactRetriever;
5   
6   import java.io.File;
7   import java.util.HashMap;
8   import java.util.List;
9   import java.util.ArrayList;
10  import java.util.Map;
11  import java.util.Properties;
12  
13  public class Product
14  {
15      /**
16       * Container to run in
17       */
18      protected String containerId;
19  
20      /**
21       * HTTP port for the servlet containers
22       */
23      private int httpPort = 0;
24  
25      /**
26       * Application context path
27       */
28      protected String contextPath;
29  
30      /**
31       * Application server
32       */
33      protected String server;
34  
35      /**
36       * Webapp version
37       */
38      protected String version;
39  
40      /**
41       * JVM arguments to pass to cargo
42       */
43      protected String jvmArgs = null;
44  
45      /**
46       * A log4j properties file
47       */
48      protected File log4jProperties;
49  
50      /**
51       * The test resources version
52       */
53      protected String productDataVersion;
54  
55      /**
56       * The path to a custom test resources zip
57       */
58      protected String productDataPath = "";
59  
60      /**
61       */
62      private List<ProductArtifact> pluginArtifacts = new ArrayList<ProductArtifact>();
63  
64      /**
65       */
66      private List<ProductArtifact> libArtifacts = new ArrayList<ProductArtifact>();
67  
68      /**
69       */
70      private List<ProductArtifact> bundledArtifacts = new ArrayList<ProductArtifact>();
71  
72      /**
73       * SAL version
74       */
75      private String salVersion;
76  
77      /**
78       * Atlassian Plugin Development Kit (PDK) version
79       */
80      private String pdkVersion;
81  
82      /**
83       * Atlassian REST module version
84       */
85      private String restVersion;
86  
87      /**
88       * Version of the Felix OSGi web console
89       */
90      private String webConsoleVersion;
91  
92      /**
93       * Product id - nickname of the product to run
94       */
95      private String id;
96  
97      /**
98       * The name of the instance of the product
99       */
100     private String instanceId;
101 
102     private ArtifactRetriever artifactRetriever;
103 
104     /**
105      * Flag to indicate whether or not to install the plugin
106      */
107     private Boolean installPlugin;
108 
109     /**
110      * The system properties to set for the product
111      */
112     private Map<String,Object> systemProperties = new HashMap<String,Object>();
113 
114     /**
115      * File the container should log to.
116      */
117     private String output;
118 
119     /**
120      * Port for debugging
121      */
122     private int jvmDebugPort;
123 
124     /**
125      * How long to wait for product startup, in milliseconds; if not specified, default is determined by AbstractProductHandlerMojo
126      */
127     private int startupTimeout = 0;
128 
129     /**
130      * How long to wait for product shutdown, in milliseconds; if not specified, default is determined by AbstractProductHandlerMojo
131      */
132     private int shutdownTimeout = 0;
133 
134     /**
135      * An optional override of the webapp's groupId
136      */
137     private String groupId;
138 
139     /**
140      * An optional override of the webapp's artifactId
141      */
142     private String artifactId;
143 
144 
145 
146     /**
147      * The studio configuration which is shared for all products in the same
148      * studio instance. Null if products are not studio or not yet configured.
149      * <p>
150      * {@link StudioProductHandler#configure(Product, List)} will set this value.
151      * It must be called before Studio products are launched.
152      */
153     protected StudioProperties studioProperties;
154 
155 
156     /**
157      * Only applies to Studio
158      * List of 'sub'-products that are managed by this Studio instance.
159      * Optional. Default value is: studio-crowd, studio-confluence, studio-fecru, studio-bamboo, studio-jira.
160      */
161     protected List<String> instanceIds = new ArrayList<String>();
162 
163     /**
164      * Only applies to Studio
165      * Set 'true' if GApps is enabled. Default is 'false'
166      */
167     protected String gappsEnabled;
168 
169     /**
170      * Only applies to Studio
171      * The GApps domain, if GApps is enabled
172      */
173     protected String gappsDomain;
174 
175 
176 
177     /**
178      * Creates a new product that is merged with this one, where the properties in this one override the passed
179      * in product.
180      * @param product The product to merge with
181      * @return A new product
182      */
183     public Product merge(Product product)
184     {
185         Product prod = new Product();
186         prod.setOutput(output == null ? product.getOutput() : output);
187 
188         Map<String,Object> sysProps = new HashMap<String,Object>();
189         sysProps.putAll(product.getSystemPropertyVariables());
190         sysProps.putAll(systemProperties);
191         prod.setSystemPropertyVariables(sysProps);
192 
193         prod.setInstallPlugin(installPlugin == null ? product.isInstallPlugin() : installPlugin);
194         prod.setArtifactRetriever(artifactRetriever == null ? product.getArtifactRetriever() : artifactRetriever);
195         prod.setId(id == null ? product.getId() : id);
196         prod.setInstanceId(instanceId == null ? product.getInstanceId() : instanceId);
197         prod.setWebConsoleVersion(webConsoleVersion == null ? product.getWebConsoleVersion() : webConsoleVersion);
198         prod.setRestVersion(restVersion == null ? product.getRestVersion() : restVersion);
199         prod.setPdkVersion(pdkVersion == null ? product.getPdkVersion() : pdkVersion);
200         prod.setSalVersion(salVersion == null ? product.getSalVersion() : salVersion);
201 
202         prod.setBundledArtifacts(bundledArtifacts.isEmpty() ? product.getBundledArtifacts() : bundledArtifacts);
203         prod.setPluginArtifacts(pluginArtifacts.isEmpty() ? product.getPluginArtifacts() : pluginArtifacts);
204         prod.setLibArtifacts(libArtifacts.isEmpty() ? product.getLibArtifacts() : libArtifacts);
205 
206         prod.setDataPath(productDataPath.length() == 0 ? product.getDataPath() : productDataPath);
207         prod.setDataVersion(productDataVersion == null ? product.getDataVersion() : productDataVersion);
208         prod.setLog4jProperties(log4jProperties == null ? product.getLog4jProperties() : log4jProperties);
209         prod.setJvmArgs(jvmArgs == null ? product.getJvmArgs() : jvmArgs);
210         prod.setVersion(groupId == null ? product.getGroupId() : groupId);
211         prod.setVersion(artifactId == null ? product.getArtifactId() : artifactId);
212         prod.setVersion(version == null ? product.getVersion() : version);
213 
214         prod.setServer(server == null ? product.getServer() : server);
215         prod.setContextPath(contextPath == null ? product.getContextPath() : contextPath);
216         prod.setContainerId(containerId == null ? product.getContainerId() : containerId);
217         prod.setHttpPort(httpPort == 0 ? product.getHttpPort() : httpPort);
218         prod.setJvmDebugPort(jvmDebugPort == 0 ? product.getJvmDebugPort() : jvmDebugPort);
219 
220         prod.setStartupTimeout(startupTimeout == 0 ? product.getStartupTimeout() : startupTimeout);
221         prod.setShutdownTimeout(shutdownTimeout == 0 ? product.getShutdownTimeout() : shutdownTimeout);
222 
223         // Studio-related properties
224         prod.setStudioProperties(studioProperties == null ? product.getStudioProperties() : studioProperties);
225         prod.setInstanceIds(instanceIds == null ? product.getInstanceIds() : instanceIds);
226 
227         return prod;
228     }
229 
230     public String getContainerId()
231     {
232         return containerId;
233     }
234 
235     public void setContainerId(String containerId)
236     {
237         this.containerId = containerId;
238     }
239 
240     public String getServer()
241     {
242         return server;
243     }
244 
245     public void setServer(String server)
246     {
247         this.server = server;
248     }
249 
250     public int getHttpPort()
251     {
252         return httpPort;
253     }
254 
255     public void setHttpPort(int httpPort)
256     {
257         this.httpPort = httpPort;
258     }
259 
260     public String getContextPath()
261     {
262         return contextPath;
263     }
264 
265     public void setContextPath(String contextPath)
266     {
267         this.contextPath = contextPath;
268     }
269 
270     public String getJvmArgs()
271     {
272         return jvmArgs;
273     }
274 
275     public void setJvmArgs(String jvmArgs)
276     {
277         this.jvmArgs = jvmArgs;
278     }
279 
280     public ArtifactRetriever getArtifactRetriever()
281     {
282         return artifactRetriever;
283     }
284 
285     public void setArtifactRetriever(ArtifactRetriever artifactRetriever)
286     {
287         this.artifactRetriever = artifactRetriever;
288     }
289 
290     public String getVersion()
291     {
292         return version;
293     }
294 
295     public void setVersion(String version)
296     {
297         this.version = version;
298     }
299 
300     public String getDataVersion()
301     {
302         return productDataVersion;
303     }
304 
305     public void setDataVersion(String productDataVersion)
306     {
307         this.productDataVersion = productDataVersion;
308     }
309 
310     /**
311      * @deprecated since 3.2
312      */
313     public String getProductDataVersion()
314     {
315         return productDataVersion;
316     }
317 
318     /**
319      * @deprecated since 3.2
320      */
321     public void setProductDataVersion(String productDataVersion)
322     {
323         this.productDataVersion = productDataVersion;
324     }
325 
326     public String getDataPath()
327     {
328         return productDataPath;
329     }
330 
331     public void setDataPath(String productDataPath)
332     {
333         this.productDataPath = productDataPath;
334     }
335 
336     /**
337      * @deprecated since 3.2
338      */
339     public String getProductDataPath()
340     {
341         return productDataPath;
342     }
343 
344     /**
345      * @deprecated since 3.2
346      */
347     public void setProductDataPath(String productDataPath)
348     {
349         this.productDataPath = productDataPath;
350     }
351 
352     public List<ProductArtifact> getPluginArtifacts()
353     {
354         return pluginArtifacts;
355     }
356 
357     public void setPluginArtifacts(List<ProductArtifact> pluginArtifacts)
358     {
359         this.pluginArtifacts = pluginArtifacts;
360     }
361 
362     public List<ProductArtifact> getLibArtifacts()
363     {
364         return libArtifacts;
365     }
366 
367     public void setLibArtifacts(List<ProductArtifact> libArtifacts)
368     {
369         this.libArtifacts = libArtifacts;
370     }
371 
372     public List<ProductArtifact> getBundledArtifacts()
373     {
374         return bundledArtifacts;
375     }
376 
377     public void setBundledArtifacts(List<ProductArtifact> bundledArtifacts)
378     {
379         this.bundledArtifacts = bundledArtifacts;
380     }
381 
382     public File getLog4jProperties()
383     {
384         return log4jProperties;
385     }
386 
387     public void setLog4jProperties(File log4jProperties)
388     {
389         this.log4jProperties = log4jProperties;
390     }
391 
392     public String getRestVersion()
393     {
394         return restVersion;
395     }
396 
397     public void setRestVersion(String restVersion)
398     {
399         this.restVersion = restVersion;
400     }
401 
402     public String getSalVersion()
403     {
404         return salVersion;
405     }
406 
407     public void setSalVersion(String salVersion)
408     {
409         this.salVersion = salVersion;
410     }
411 
412     public String getPdkVersion()
413     {
414         return pdkVersion;
415     }
416 
417     public void setPdkVersion(String pdkVersion)
418     {
419         this.pdkVersion = pdkVersion;
420     }
421 
422     public String getId()
423     {
424         return id;
425     }
426 
427     public void setId(String id)
428     {
429         this.id = id;
430     }
431 
432     public String getInstanceId()
433     {
434         return instanceId;
435     }
436 
437     public void setInstanceId(String instanceId)
438     {
439         this.instanceId = instanceId;
440     }
441 
442     public Boolean isInstallPlugin()
443     {
444         return installPlugin;
445     }
446 
447     public void setInstallPlugin(final Boolean installPlugin)
448     {
449         this.installPlugin = installPlugin;
450     }
451 
452     public String getWebConsoleVersion()
453     {
454         return webConsoleVersion;
455     }
456 
457     public void setWebConsoleVersion(String webConsoleVersion)
458     {
459         this.webConsoleVersion = webConsoleVersion;
460     }
461 
462     /**
463      * @deprecated Since 3.2, use systemPropertyVariables
464      */
465     public void setSystemProperties(Properties systemProperties)
466     {
467         this.systemProperties.putAll((Map) systemProperties);
468     }
469 
470     /**
471      * @deprecated Since 3.2, use systemPropertyVariables
472      */
473     public Properties getSystemProperties()
474     {
475         Properties props = new Properties();
476         props.putAll(systemProperties);
477         return props;
478     }
479 
480     public void setSystemPropertyVariables(Map<String,Object> systemProperties)
481     {
482         this.systemProperties = systemProperties;
483     }
484 
485     public Map<String,Object> getSystemPropertyVariables()
486     {
487         return systemProperties;
488     }
489 
490     public String getOutput()
491     {
492         return output;
493     }
494 
495     public void setOutput(String output)
496     {
497         this.output = output;
498     }
499 
500     public int getJvmDebugPort()
501     {
502         return jvmDebugPort;
503     }
504 
505     public void setJvmDebugPort(int jvmDebugPort)
506     {
507         this.jvmDebugPort = jvmDebugPort;
508     }
509 
510     public int getStartupTimeout()
511     {
512         return startupTimeout;
513     }
514 
515     public void setStartupTimeout(int startupTimeout)
516     {
517         this.startupTimeout = startupTimeout;
518     }
519 
520     public int getShutdownTimeout()
521     {
522         return shutdownTimeout;
523     }
524 
525     public void setShutdownTimeout(int shutdownTimeout)
526     {
527         this.shutdownTimeout = shutdownTimeout;
528     }
529 
530     public String getGroupId()
531     {
532         return groupId;
533     }
534 
535     public void setGroupId(String groupId)
536     {
537         this.groupId = groupId;
538     }
539 
540     public String getArtifactId()
541     {
542         return artifactId;
543     }
544 
545     public void setArtifactId(String artifactId)
546     {
547         this.artifactId = artifactId;
548     }
549 
550     public StudioProperties getStudioProperties()
551     {
552         return studioProperties;
553     }
554 
555     public void setStudioProperties(StudioProperties studioProperties)
556     {
557         this.studioProperties = studioProperties;
558     }
559 
560     public List<String> getInstanceIds()
561     {
562         return instanceIds;
563     }
564 
565     public void setInstanceIds(List<String> instanceIds)
566     {
567         this.instanceIds = instanceIds;
568     }
569 
570     public String getGappsEnabled()
571     {
572         return gappsEnabled;
573     }
574 
575     public void setGappsEnabled(String gappsEnabled)
576     {
577         this.gappsEnabled = gappsEnabled;
578     }
579 
580     public String getGappsDomain()
581     {
582         return gappsDomain;
583     }
584 
585     public void setGappsDomain(String gappsDomain)
586     {
587         this.gappsDomain = gappsDomain;
588     }
589 
590     public void setSystemProperties(Map<String, Object> systemProperties)
591     {
592         this.systemProperties = systemProperties;
593     }
594 
595     @Override
596     public String toString()
597     {
598         return "Product " + id + " [instanceId=" + instanceId + ", localhost:" + httpPort + contextPath + "]";
599     }
600 
601 }