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.Replacement;
8   
9   import org.apache.commons.io.FileUtils;
10  import org.apache.maven.plugin.MojoExecutionException;
11  import java.io.File;
12  import java.io.IOException;
13  import java.util.*;
14  
15  public class ConfluenceProductHandler extends AbstractWebappProductHandler
16  {
17  
18      public ConfluenceProductHandler(MavenContext context, MavenGoals goals)
19      {
20          super(context, goals, new ConfluencePluginProvider());
21      }
22  
23      public String getId()
24      {
25          return "confluence";
26      }
27  
28      @Override
29      protected boolean isStaticPlugin()
30      {
31          // assume all Confluence plugins should be installed as bundled plugins -- a pretty good assumption
32          return false;
33      }
34  
35      @Override
36      public ProductArtifact getArtifact()
37      {
38          return new ProductArtifact("com.atlassian.confluence", "confluence-webapp", "RELEASE");
39      }
40  
41      @Override
42      public ProductArtifact getTestResourcesArtifact()
43      {
44          return new ProductArtifact("com.atlassian.confluence.plugins", "confluence-plugin-test-resources");
45      }
46  
47      public int getDefaultHttpPort()
48      {
49          return 1990;
50      }
51  
52      @Override
53      public Map<String, String> getSystemProperties(Product ctx)
54      {
55          return Collections.singletonMap("confluence.home", getHomeDirectory(ctx).getPath());
56      }
57  
58      @Override
59      public File getUserInstalledPluginsDirectory(final File webappDir, File homeDir)
60      {
61          // indicates plugins should be bundled
62          return null;
63      }
64  
65      @Override
66      public List<ProductArtifact> getExtraContainerDependencies()
67      {
68          return Collections.emptyList();
69      }
70  
71      @Override
72      public String getBundledPluginPath(Product ctx)
73      {
74          return "WEB-INF/classes/com/atlassian/confluence/setup/atlassian-bundled-plugins.zip";
75      }
76  
77      @Override
78      public List<Replacement> getReplacements(Product ctx)
79      {
80          List<Replacement> replacements = super.getReplacements(ctx);
81          File homeDir = getHomeDirectory(ctx);
82          // We don't rewrap homes with these values:
83          replacements.add(new Replacement("@project-dir@", homeDir.getParent()));
84          replacements.add(new Replacement("/confluence-home/", "/home/", false));
85          replacements.add(new Replacement("<baseUrl>http://localhost:1990/confluence</baseUrl>", "<baseUrl>http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", "") + "</baseUrl>", false));
86          replacements.add(new Replacement("<baseUrl>http://localhost:8080</baseUrl>", "<baseUrl>http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", "") + "</baseUrl>", false));
87          return replacements;
88      }
89  
90      @Override
91      public List<File> getConfigFiles(Product product, File homeDirectory)
92      {
93          List<File> configFiles = super.getConfigFiles(product, homeDirectory);
94          configFiles.add(new File(new File(homeDirectory, "database"), "confluencedb.script"));
95          configFiles.add(new File(new File(homeDirectory, "database"), "confluencedb.log"));
96          configFiles.add(new File(homeDirectory, "confluence.cfg.xml"));
97          return configFiles;
98      }
99  
100     @Override
101     public List<ProductArtifact> getDefaultLibPlugins()
102     {
103         return Collections.emptyList();
104     }
105 
106     @Override
107     public List<ProductArtifact> getDefaultBundledPlugins()
108     {
109         return Collections.emptyList();
110     }
111 
112     private static class ConfluencePluginProvider extends AbstractPluginProvider
113     {
114 
115         @Override
116         protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
117         {
118             return Arrays.asList(
119                 new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
120                 new ProductArtifact("com.atlassian.sal", "sal-confluence-plugin", salVersion));
121         }
122 
123         @Override
124         protected Collection<ProductArtifact> getPdkInstallArtifacts(String pdkInstallVersion)
125         {
126             return Collections.emptyList();
127         }
128     }
129 
130     @Override
131     public void cleanupProductHomeForZip(Product product, File homeDirectory) throws MojoExecutionException, IOException
132     {
133         super.cleanupProductHomeForZip(product, homeDirectory);
134         FileUtils.deleteDirectory(new File(homeDirectory, "plugins-osgi-cache"));
135         FileUtils.deleteDirectory(new File(homeDirectory, "plugins-temp"));
136     }
137 }