1   package com.atlassian.maven.plugins.amps.product;
2   
3   import com.atlassian.maven.plugins.amps.MavenGoals;
4   import com.atlassian.maven.plugins.amps.Product;
5   import com.atlassian.maven.plugins.amps.ProductArtifact;
6   import com.atlassian.maven.plugins.amps.util.ConfigFileUtils;
7   import org.apache.maven.plugin.MojoExecutionException;
8   import org.apache.maven.project.MavenProject;
9   
10  import java.io.File;
11  import java.util.*;
12  
13  public class BambooProductHandler extends AbstractWebappProductHandler
14  {
15      public BambooProductHandler(MavenProject project, MavenGoals goals)
16      {
17          super(project, goals, new BambooPluginProvider());
18      }
19  
20      public String getId()
21      {
22          return "bamboo";
23      }
24  
25      public ProductArtifact getArtifact()
26      {
27          return new ProductArtifact("com.atlassian.bamboo", "atlassian-bamboo-web-app", "RELEASE");
28      }
29  
30      protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
31      {
32          return Arrays.asList(
33                  new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
34                  new ProductArtifact("com.atlassian.sal", "sal-bamboo-plugin", salVersion));
35      }
36  
37      public ProductArtifact getTestResourcesArtifact()
38      {
39          return new ProductArtifact("com.atlassian.bamboo.plugins", "bamboo-plugin-test-resources", "LATEST");
40      }
41  
42      public int getDefaultHttpPort()
43      {
44          return 6990;
45      }
46  
47      public Map<String, String> getSystemProperties(Product ctx)
48      {
49          Map<String, String> systemProperties = new HashMap<String, String>();
50          systemProperties.put("bamboo.home", getHomeDirectory(ctx).getPath());
51          systemProperties.put("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "false");
52          return Collections.unmodifiableMap(systemProperties);
53      }
54  
55      @Override
56      public File getUserInstalledPluginsDirectory(final File webappDir, final File homeDir)
57      {
58          return new File(homeDir, "plugins");
59      }
60  
61      public List<ProductArtifact> getExtraContainerDependencies()
62      {
63          return Collections.emptyList();
64      }
65  
66      public String getBundledPluginPath(Product ctx)
67      {
68          return "WEB-INF/classes/atlassian-bundled-plugins.zip";
69      }
70  
71      public void processHomeDirectory(final Product ctx, final File homeDir) throws MojoExecutionException
72      {
73          ConfigFileUtils.replace(new File(homeDir, "bamboo.cfg.xml"), "@project-dir@", homeDir.getParent());
74          ConfigFileUtils.replace(new File(homeDir, "bamboo.cfg.xml"), "/bamboo-home/", "/home/");
75          ConfigFileUtils.replace(new File(homeDir, "bamboo.cfg.xml"), "${bambooHome}", homeDir.getAbsolutePath());
76          // The regex in the following search text is used to match IPv4 ([^:]+) or IPv6 (\[.+]) addresses.
77          ConfigFileUtils.replaceAll(new File(homeDir, "/xml-data/configuration/administration.xml"),
78                  "http://(?:[^:]+|\\[.+]):8085", "http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", ""));
79      }
80  
81      public List<ProductArtifact> getDefaultLibPlugins()
82      {
83          return Collections.emptyList();
84      }
85  
86      public List<ProductArtifact> getDefaultBundledPlugins()
87      {
88          return Collections.emptyList();
89      }
90  
91      private static class BambooPluginProvider extends AbstractPluginProvider
92      {
93  
94          @Override
95          protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
96          {
97              return Arrays.asList(
98                  new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
99                  new ProductArtifact("com.atlassian.sal", "sal-bamboo-plugin", salVersion));
100         }
101 
102     }
103 }