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 ConfluenceProductHandler extends AbstractWebappProductHandler
14  {
15      public ConfluenceProductHandler(MavenProject project, MavenGoals goals)
16      {
17          super(project, goals, new ConfluencePluginProvider());
18      }
19  
20      public String getId()
21      {
22          return "confluence";
23      }
24  
25      @Override
26      protected boolean isStaticPlugin()
27      {
28          // assume all Confluence plugins should be installed as bundled plugins -- a pretty good assumption
29          return false;
30      }
31  
32      @Override
33      public ProductArtifact getArtifact()
34      {
35          return new ProductArtifact("com.atlassian.confluence", "confluence-webapp", "RELEASE");
36      }
37  
38      @Override
39      public ProductArtifact getTestResourcesArtifact()
40      {
41          return new ProductArtifact("com.atlassian.confluence.plugins", "confluence-plugin-test-resources", "LATEST");
42      }
43  
44      public int getDefaultHttpPort()
45      {
46          return 1990;
47      }
48  
49      @Override
50      public Map<String, String> getSystemProperties(Product ctx)
51      {
52          return Collections.singletonMap("confluence.home", getHomeDirectory(ctx).getPath());
53      }
54  
55      @Override
56      public File getUserInstalledPluginsDirectory(final File webappDir, File homeDir)
57      {
58          // indicates plugins should be bundled
59          return null;
60      }
61  
62      @Override
63      public List<ProductArtifact> getExtraContainerDependencies()
64      {
65          return Collections.emptyList();
66      }
67  
68      @Override
69      public String getBundledPluginPath(Product ctx)
70      {
71          return "WEB-INF/classes/com/atlassian/confluence/setup/atlassian-bundled-plugins.zip";
72      }
73  
74      @Override
75      public void processHomeDirectory(Product ctx, File homeDir) throws MojoExecutionException
76      {
77          ConfigFileUtils.replace(new File(homeDir, "confluence.cfg.xml"), "@project-dir@", homeDir.getParent());
78          ConfigFileUtils.replace(new File(homeDir, "confluence.cfg.xml"), "/confluence-home/", "/home/");
79  
80          File script = new File(new File(homeDir, "database"), "confluencedb.script");
81          if (script.exists())
82          {
83              ConfigFileUtils.replace(new File(new File(homeDir, "database"), "confluencedb.script"),
84                      "<baseUrl>http://localhost:8080</baseUrl>",
85                      "<baseUrl>http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", "") + "</baseUrl>");
86          }
87          else
88          {
89              ConfigFileUtils.replace(new File(new File(homeDir, "database"), "confluencedb.log"),
90                      "<baseUrl>http://localhost:8080</baseUrl>",
91                      "<baseUrl>http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", "") + "</baseUrl>");
92          }
93      }
94  
95      @Override
96      public List<ProductArtifact> getDefaultLibPlugins()
97      {
98          return Collections.emptyList();
99      }
100 
101     @Override
102     public List<ProductArtifact> getDefaultBundledPlugins()
103     {
104         return Collections.emptyList();
105     }
106 
107     private static class ConfluencePluginProvider extends AbstractPluginProvider
108     {
109 
110         @Override
111         protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
112         {
113             return Arrays.asList(
114                 new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
115                 new ProductArtifact("com.atlassian.sal", "sal-confluence-plugin", salVersion));
116         }
117 
118         @Override
119         protected Collection<ProductArtifact> getPdkInstallArtifacts(String pdkInstallVersion)
120         {
121             return Collections.emptyList();
122         }
123     }
124 }