1   package com.atlassian.maven.plugins.amps;
2   
3   import com.atlassian.maven.plugins.amps.util.ArtifactRetriever;
4   
5   import java.io.File;
6   import java.util.HashMap;
7   import java.util.List;
8   import java.util.ArrayList;
9   import java.util.Map;
10  import java.util.Properties;
11  
12  public class Product
13  {
14      /**
15       * Container to run in
16       */
17      protected String containerId;
18  
19      /**
20       * HTTP port for the servlet containers
21       */
22      private int httpPort = 0;
23  
24      /**
25       * Application context path
26       */
27      protected String contextPath;
28  
29      /**
30       * Application server
31       */
32      protected String server;
33  
34      /**
35       * Webapp version
36       */
37      protected String version;
38  
39      /**
40       * JVM arguments to pass to cargo
41       */
42      protected String jvmArgs = null;
43  
44      /**
45       * A log4j properties file
46       */
47      protected File log4jProperties;
48  
49      /**
50       * The test resources version
51       */
52      protected String productDataVersion;
53  
54      /**
55       * The path to a custom test resources zip
56       */
57      protected String productDataPath = "";
58  
59      /**
60       */
61      private List<ProductArtifact> pluginArtifacts = new ArrayList<ProductArtifact>();
62  
63      /**
64       */
65      private List<ProductArtifact> libArtifacts = new ArrayList<ProductArtifact>();
66  
67      /**
68       */
69      private List<ProductArtifact> bundledArtifacts = new ArrayList<ProductArtifact>();
70  
71      /**
72       * SAL version
73       */
74      private String salVersion;
75  
76      /**
77       * Atlassian Plugin Development Kit (PDK) version
78       */
79      private String pdkVersion;
80  
81      /**
82       * Atlassian REST module version
83       */
84      private String restVersion;
85  
86      /**
87       * Version of the Felix OSGi web console
88       */
89      private String webConsoleVersion;
90  
91      /**
92       * Product id
93       */
94      private String id;
95  
96      /**
97       * The name of the instance of the product
98       */
99      private String instanceId;
100 
101     private ArtifactRetriever artifactRetriever;
102 
103     /**
104      * Flag to indicate whether or not to install the plugin
105      */
106     private Boolean installPlugin;
107 
108     /**
109      * The system properties to set for the product
110      */
111     private Map<String,Object> systemProperties = new HashMap<String,Object>();
112 
113     /**
114      * File the container should log to.
115      */
116     private String output;
117 
118     /**
119      * Creates a new product that is merged with this one, where the properties in this one override the passed
120      * in product.
121      * @param product The product to merge with
122      * @return A new product
123      */
124     public Product merge(Product product)
125     {
126         Product prod = new Product();
127         prod.setOutput(output == null ? product.getOutput() : output);
128 
129         Map<String,Object> sysProps = new HashMap<String,Object>();
130         sysProps.putAll(product.getSystemPropertyVariables());
131         sysProps.putAll(systemProperties);
132         prod.setSystemPropertyVariables(sysProps);
133 
134         prod.setInstallPlugin(installPlugin == null ? product.isInstallPlugin() : installPlugin);
135         prod.setArtifactRetriever(artifactRetriever == null ? product.getArtifactRetriever() : artifactRetriever);
136         prod.setId(id == null ? product.getId() : id);
137         prod.setInstanceId(instanceId == null ? product.getInstanceId() : instanceId);
138         prod.setWebConsoleVersion(webConsoleVersion == null ? product.getWebConsoleVersion() : webConsoleVersion);
139         prod.setRestVersion(restVersion == null ? product.getRestVersion() : restVersion);
140         prod.setPdkVersion(pdkVersion == null ? product.getPdkVersion() : pdkVersion);
141         prod.setSalVersion(salVersion == null ? product.getSalVersion() : salVersion);
142         
143         prod.setBundledArtifacts(bundledArtifacts.isEmpty() ? product.getBundledArtifacts() : bundledArtifacts);
144         prod.setPluginArtifacts(pluginArtifacts.isEmpty() ? product.getPluginArtifacts() : pluginArtifacts);
145         prod.setLibArtifacts(libArtifacts.isEmpty() ? product.getLibArtifacts() : libArtifacts);
146 
147         prod.setDataPath(productDataPath.length() == 0 ? product.getDataPath() : productDataPath);
148         prod.setDataVersion(productDataVersion == null ? product.getDataVersion() : productDataVersion);
149         prod.setLog4jProperties(log4jProperties == null ? product.getLog4jProperties() : log4jProperties);
150         prod.setJvmArgs(jvmArgs == null ? product.getJvmArgs() : jvmArgs);
151         prod.setVersion(version == null ? product.getVersion() : version);
152 
153         prod.setServer(server == null ? product.getServer() : server);
154         prod.setContextPath(contextPath == null ? product.getContextPath() : contextPath);
155         prod.setContainerId(containerId == null ? product.getContainerId() : containerId);
156         prod.setHttpPort(httpPort == 0 ? product.getHttpPort() : httpPort);
157 
158         return prod;
159     }
160 
161     public String getContainerId()
162     {
163         return containerId;
164     }
165 
166     public void setContainerId(String containerId)
167     {
168         this.containerId = containerId;
169     }
170 
171     public String getServer()
172     {
173         return server;
174     }
175 
176     public void setServer(String server)
177     {
178         this.server = server;
179     }
180 
181     public int getHttpPort()
182     {
183         return httpPort;
184     }
185 
186     public void setHttpPort(int httpPort)
187     {
188         this.httpPort = httpPort;
189     }
190 
191     public String getContextPath()
192     {
193         return contextPath;
194     }
195 
196     public void setContextPath(String contextPath)
197     {
198         this.contextPath = contextPath;
199     }
200 
201     public String getJvmArgs()
202     {
203         return jvmArgs;
204     }
205 
206     public void setJvmArgs(String jvmArgs)
207     {
208         this.jvmArgs = jvmArgs;
209     }
210 
211     public ArtifactRetriever getArtifactRetriever()
212     {
213         return artifactRetriever;
214     }
215 
216     public void setArtifactRetriever(ArtifactRetriever artifactRetriever)
217     {
218         this.artifactRetriever = artifactRetriever;
219     }
220 
221     public String getVersion()
222     {
223         return version;
224     }
225 
226     public void setVersion(String version)
227     {
228         this.version = version;
229     }
230 
231     public String getDataVersion()
232     {
233         return productDataVersion;
234     }
235 
236     public void setDataVersion(String productDataVersion)
237     {
238         this.productDataVersion = productDataVersion;
239     }
240 
241     /**
242      * @deprecated since 3.2
243      */
244     public String getProductDataVersion()
245     {
246         return productDataVersion;
247     }
248 
249     /**
250      * @deprecated since 3.2
251      */
252     public void setProductDataVersion(String productDataVersion)
253     {
254         this.productDataVersion = productDataVersion;
255     }
256 
257     public String getDataPath()
258     {
259         return productDataPath;
260     }
261 
262     public void setDataPath(String productDataPath)
263     {
264         this.productDataPath = productDataPath;
265     }
266 
267     /**
268      * @deprecated since 3.2
269      */
270     public String getProductDataPath()
271     {
272         return productDataPath;
273     }
274 
275     /**
276      * @deprecated since 3.2
277      */
278     public void setProductDataPath(String productDataPath)
279     {
280         this.productDataPath = productDataPath;
281     }
282 
283     public List<ProductArtifact> getPluginArtifacts()
284     {
285         return pluginArtifacts;
286     }
287 
288     public void setPluginArtifacts(List<ProductArtifact> pluginArtifacts)
289     {
290         this.pluginArtifacts = pluginArtifacts;
291     }
292 
293     public List<ProductArtifact> getLibArtifacts()
294     {
295         return libArtifacts;
296     }
297 
298     public void setLibArtifacts(List<ProductArtifact> libArtifacts)
299     {
300         this.libArtifacts = libArtifacts;
301     }
302 
303     public List<ProductArtifact> getBundledArtifacts()
304     {
305         return bundledArtifacts;
306     }
307 
308     public void setBundledArtifacts(List<ProductArtifact> bundledArtifacts)
309     {
310         this.bundledArtifacts = bundledArtifacts;
311     }
312 
313     public File getLog4jProperties()
314     {
315         return log4jProperties;
316     }
317 
318     public void setLog4jProperties(File log4jProperties)
319     {
320         this.log4jProperties = log4jProperties;
321     }
322 
323     public String getRestVersion()
324     {
325         return restVersion;
326     }
327 
328     public void setRestVersion(String restVersion)
329     {
330         this.restVersion = restVersion;
331     }
332 
333     public String getSalVersion()
334     {
335         return salVersion;
336     }
337 
338     public void setSalVersion(String salVersion)
339     {
340         this.salVersion = salVersion;
341     }
342 
343     public String getPdkVersion()
344     {
345         return pdkVersion;
346     }
347 
348     public void setPdkVersion(String pdkVersion)
349     {
350         this.pdkVersion = pdkVersion;
351     }
352 
353     public String getId()
354     {
355         return id;
356     }
357 
358     public void setId(String id)
359     {
360         this.id = id;
361     }
362 
363     public String getInstanceId()
364     {
365         return instanceId;
366     }
367 
368     public void setInstanceId(String instanceId)
369     {
370         this.instanceId = instanceId;
371     }
372 
373     public Boolean isInstallPlugin()
374     {
375         return installPlugin;
376     }
377 
378     public void setInstallPlugin(final Boolean installPlugin)
379     {
380         this.installPlugin = installPlugin;
381     }
382 
383     public String getWebConsoleVersion()
384     {
385         return webConsoleVersion;
386     }
387 
388     public void setWebConsoleVersion(String webConsoleVersion)
389     {
390         this.webConsoleVersion = webConsoleVersion;
391     }
392 
393     /**
394      * @deprecated Since 3.2, use systemPropertyVariables
395      */
396     public void setSystemProperties(Properties systemProperties)
397     {
398         this.systemProperties.putAll((Map) systemProperties);
399     }
400 
401     /**
402      * @deprecated Since 3.2, use systemPropertyVariables
403      */
404     public Properties getSystemProperties()
405     {
406         Properties props = new Properties();
407         props.putAll(systemProperties);
408         return props;
409     }
410 
411     public void setSystemPropertyVariables(Map<String,Object> systemProperties)
412     {
413         this.systemProperties = systemProperties;
414     }
415 
416     public Map<String,Object> getSystemPropertyVariables()
417     {
418         return systemProperties;
419     }
420 
421 	public String getOutput()
422 	{
423 		return output;
424 	}
425 	
426 	public void setOutput(String output)
427 	{
428 		this.output = output;
429 	}
430 
431 }