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