1   package com.atlassian.maven.plugins.amps.product;
2   
3   import com.atlassian.maven.plugins.amps.MavenContext;
4   import com.atlassian.maven.plugins.amps.MavenGoals;
5   import com.atlassian.maven.plugins.amps.Product;
6   import com.atlassian.maven.plugins.amps.ProductArtifact;
7   import com.atlassian.maven.plugins.amps.util.ConfigFileUtils;
8   import com.atlassian.maven.plugins.amps.util.ConfigFileUtils.Replacement;
9   import org.apache.maven.plugin.MojoExecutionException;
10  import java.io.File;
11  import java.io.IOException;
12  import java.util.*;
13  
14  import static com.atlassian.maven.plugins.amps.util.FileUtils.deleteDir;
15  
16  public class BambooProductHandler extends AbstractWebappProductHandler
17  {
18      public BambooProductHandler(MavenContext context, MavenGoals goals)
19      {
20          super(context, goals, new BambooPluginProvider());
21      }
22  
23      public String getId()
24      {
25          return "bamboo";
26      }
27  
28      public ProductArtifact getArtifact()
29      {
30          return new ProductArtifact("com.atlassian.bamboo", "atlassian-bamboo-web-app", "RELEASE");
31      }
32  
33      protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
34      {
35          return Arrays.asList(
36                  new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
37                  new ProductArtifact("com.atlassian.sal", "sal-bamboo-plugin", salVersion));
38      }
39  
40      public ProductArtifact getTestResourcesArtifact()
41      {
42          return new ProductArtifact("com.atlassian.bamboo.plugins", "bamboo-plugin-test-resources");
43      }
44  
45      public int getDefaultHttpPort()
46      {
47          return 6990;
48      }
49  
50      public Map<String, String> getSystemProperties(Product ctx)
51      {
52          Map<String, String> systemProperties = new HashMap<String, String>();
53          systemProperties.put("bamboo.home", getHomeDirectory(ctx).getPath());
54          systemProperties.put("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "false");
55          return Collections.unmodifiableMap(systemProperties);
56      }
57  
58      @Override
59      public File getUserInstalledPluginsDirectory(final File webappDir, final File homeDir)
60      {
61          return new File(homeDir, "plugins");
62      }
63  
64      public List<ProductArtifact> getExtraContainerDependencies()
65      {
66          return Collections.emptyList();
67      }
68  
69      public String getBundledPluginPath(Product ctx)
70      {
71          return "WEB-INF/classes/atlassian-bundled-plugins.zip";
72      }
73  
74      public void processHomeDirectory(final Product ctx, final File homeDir) throws MojoExecutionException
75      {
76          super.processHomeDirectory(ctx, homeDir);
77  
78          // The regex in the following search text is used to match IPv4 ([^:]+) or IPv6 (\[.+]) addresses.
79          ConfigFileUtils.replaceAll(new File(homeDir, "/xml-data/configuration/administration.xml"),
80                  "http://(?:[^:]+|\\[.+]):8085", "http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", ""));
81      }
82  
83  
84  
85      @Override
86      public List<Replacement> getReplacements(Product product)
87      {
88          List<Replacement> replacements = super.getReplacements(product);
89          File homeDirectory = getHomeDirectory(product);
90          // We don't rewrap homes with these values:
91          replacements.add(new Replacement("@project-dir@", homeDirectory.getParent(), false));
92          replacements.add(new Replacement("/bamboo-home/", "/home/", false));
93          replacements.add(new Replacement("${bambooHome}", homeDirectory.getAbsolutePath(), false));
94          return replacements;
95      }
96  
97      @Override
98      public List<File> getConfigFiles(Product product, File homeDirectory)
99      {
100         List<File> configFiles = super.getConfigFiles(product, homeDirectory);
101         configFiles.add(new File(homeDirectory, "bamboo.cfg.xml"));
102         configFiles.add(new File(homeDirectory, "database.log"));
103         return configFiles;
104     }
105 
106     public List<ProductArtifact> getDefaultLibPlugins()
107     {
108         return Collections.emptyList();
109     }
110 
111     public List<ProductArtifact> getDefaultBundledPlugins()
112     {
113         return Collections.emptyList();
114     }
115 
116     @Override
117     public void cleanupProductHomeForZip(Product bamboo, File genDir) throws MojoExecutionException, IOException
118     {
119         super.cleanupProductHomeForZip(bamboo, genDir);
120         deleteDir(new File(genDir, "jms-store"));
121         deleteDir(new File(genDir, "caches"));
122         deleteDir(new File(genDir, "logs"));
123     }
124 
125     private static class BambooPluginProvider extends AbstractPluginProvider
126     {
127 
128         @Override
129         protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
130         {
131             return Arrays.asList(
132                 new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
133                 new ProductArtifact("com.atlassian.sal", "sal-bamboo-plugin", salVersion));
134         }
135 
136     }
137 }