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.io.IOException;
12  import java.util.ArrayList;
13  import java.util.Arrays;
14  import java.util.Collection;
15  import java.util.Collections;
16  import java.util.HashMap;
17  import java.util.List;
18  import java.util.Map;
19  
20  public class CrowdProductHandler extends AbstractWebappProductHandler
21  {
22      public CrowdProductHandler(final MavenProject project, final MavenGoals goals)
23      {
24          super(project, goals, new CrowdPluginProvider());
25      }
26  
27      public String getId()
28      {
29          return ProductHandlerFactory.CROWD;
30      }
31  
32      @Override
33      public ProductArtifact getArtifact()
34      {
35          return new ProductArtifact("com.atlassian.crowd", "crowd-web-app", "RELEASE");
36      }
37  
38      @Override
39      public ProductArtifact getTestResourcesArtifact()
40      {
41          return new ProductArtifact("com.atlassian.crowd.distribution", "crowd-plugin-test-resources", "LATEST");
42      }
43  
44      public int getDefaultHttpPort()
45      {
46          return 4990;
47      }
48  
49      @Override
50      public Map<String, String> getSystemProperties(final Product ctx)
51      {
52          return new HashMap<String, String>()
53          {{
54              put("crowd.home", getHomeDirectory(ctx).getPath());
55  
56              String contextPath = ctx.getContextPath();
57              if (!contextPath.startsWith("/"))
58              {
59                  contextPath = "/" + contextPath;
60              }
61              if (!contextPath.endsWith("/"))
62              {
63                  contextPath = contextPath + "/";
64              }
65          }};
66      }
67  
68      @Override
69      public File getUserInstalledPluginsDirectory(final File webappDir, final File homeDir)
70      {
71          return new File(homeDir, "plugins");
72      }
73  
74      @Override
75      public List<ProductArtifact> getExtraContainerDependencies()
76      {
77          return Arrays.asList(
78                  new ProductArtifact("hsqldb", "hsqldb", "1.8.0.7"),
79                  new ProductArtifact("jta", "jta", "1.0.1B"),
80                  new ProductArtifact("javax.mail", "mail", "1.4"),
81                  new ProductArtifact("javax.activation", "activation", "1.0.2")
82          );
83      }
84  
85      @Override
86      public String getBundledPluginPath(Product ctx)
87      {
88          return "WEB-INF/classes/atlassian-bundled-plugins.zip";
89      }
90  
91      @Override
92      public void processHomeDirectory(final Product ctx, final File homeDir) throws MojoExecutionException
93      {
94          try
95          {
96              ConfigFileUtils.replaceAll(new File(homeDir, "crowd.cfg.xml"),
97                      "jdbc:hsqldb:.*/(crowd-)?home/database/defaultdb",
98                      "jdbc:hsqldb:" + getHomeDirectory(ctx).getCanonicalPath().replace("\\", "/") + "/database/defaultdb");
99          }
100         catch (final IOException e)
101         {
102             throw new MojoExecutionException(e.getMessage());
103         }
104     }
105 
106     @Override
107     public List<ProductArtifact> getDefaultLibPlugins()
108     {
109         return Collections.emptyList();
110     }
111 
112     @Override
113     public List<ProductArtifact> getDefaultBundledPlugins()
114     {
115         return Collections.emptyList();
116     }
117 
118     private static class CrowdPluginProvider extends AbstractPluginProvider
119     {
120 
121         @Override
122         protected Collection<ProductArtifact> getSalArtifacts(final String salVersion)
123         {
124             return Arrays.asList(
125                     new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
126                     new ProductArtifact("com.atlassian.sal", "sal-crowd-plugin", salVersion));
127         }
128 
129         @Override
130         protected Collection<ProductArtifact> getPdkInstallArtifacts(final String pdkInstallVersion)
131         {
132             final List<ProductArtifact> plugins = new ArrayList<ProductArtifact>();
133             plugins.addAll(super.getPdkInstallArtifacts(pdkInstallVersion));
134             plugins.add(new ProductArtifact("commons-fileupload", "commons-fileupload", "1.2.1"));
135             return plugins;
136         }
137     }
138 }