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