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          replacements.add(new Replacement("@project-dir@", homeDir.getParent()));
83          replacements.add(new Replacement("/confluence-home/", "/home/"));
84          replacements.add(new Replacement("<baseUrl>http://localhost:8080</baseUrl>", "<baseUrl>http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", "") + "</baseUrl>"));
85          return replacements;
86      }
87  
88      @Override
89      public List<File> getConfigFiles(Product product, File homeDirectory)
90      {
91          List<File> configFiles = super.getConfigFiles(product, homeDirectory);
92          File script = new File(new File(homeDirectory, "database"), "confluencedb.script");
93          if (!script.exists())
94          {
95              script = new File(new File(homeDirectory, "database"), "confluencedb.log");
96          }
97  
98          configFiles.add(script);
99          configFiles.add(new File(homeDirectory, "confluence.cfg.xml"));
100         return configFiles;
101     }
102 
103     @Override
104     public List<ProductArtifact> getDefaultLibPlugins()
105     {
106         return Collections.emptyList();
107     }
108 
109     @Override
110     public List<ProductArtifact> getDefaultBundledPlugins()
111     {
112         return Collections.emptyList();
113     }
114 
115     private static class ConfluencePluginProvider extends AbstractPluginProvider
116     {
117 
118         @Override
119         protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
120         {
121             return Arrays.asList(
122                 new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
123                 new ProductArtifact("com.atlassian.sal", "sal-confluence-plugin", salVersion));
124         }
125 
126         @Override
127         protected Collection<ProductArtifact> getPdkInstallArtifacts(String pdkInstallVersion)
128         {
129             return Collections.emptyList();
130         }
131     }
132 
133     @Override
134     public void cleanupProductHomeForZip(Product product, File homeDirectory) throws MojoExecutionException, IOException
135     {
136         super.cleanupProductHomeForZip(product, homeDirectory);
137         FileUtils.deleteDirectory(new File(homeDirectory, "plugins-osgi-cache"));
138         FileUtils.deleteDirectory(new File(homeDirectory, "plugins-temp"));
139     }
140 }