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 JiraProductHandler extends AbstractWebappProductHandler
14  {
15      public JiraProductHandler(final MavenProject project, final MavenGoals goals)
16      {
17          super(project, goals, new JiraPluginProvider());
18      }
19  
20      public String getId()
21      {
22          return "jira";
23      }
24  
25      @Override
26      public ProductArtifact getArtifact()
27      {
28          return new ProductArtifact("com.atlassian.jira", "atlassian-jira-webapp", "RELEASE");
29      }
30  
31      @Override
32      public ProductArtifact getTestResourcesArtifact()
33      {
34          return new ProductArtifact("com.atlassian.jira.plugins", "jira-plugin-test-resources", "LATEST");
35      }
36  
37      public int getDefaultHttpPort()
38      {
39          return 2990;
40      }
41  
42      @Override
43      public Map<String, String> getSystemProperties(final Product ctx)
44      {
45          return new HashMap<String, String>()
46          {
47              {
48                  put("jira.home", fixSlashes(getHomeDirectory(ctx).getPath()));
49                  put("cargo.datasource.datasource", "cargo.datasource.url=jdbc:hsqldb:"
50                          + fixSlashes(getHomeDirectory(ctx).getAbsolutePath()) + "/database|"
51                          + "cargo.datasource.driver=org.hsqldb.jdbcDriver|" + "cargo.datasource.username=sa|"
52                          + "cargo.datasource.password=|" + "cargo.datasource.type=javax.sql.DataSource|"
53                          + "cargo.datasource.jndi=jdbc/JiraDS");
54              }
55  
56          };
57      }
58  
59      private static String fixSlashes(final String path)
60      {
61          return path.replaceAll("\\\\", "/");
62      }
63  
64      @Override
65      public File getUserInstalledPluginsDirectory(final File webappDir, final File homeDir)
66      {
67          return new File(new File(homeDir, "plugins"), "installed-plugins");
68      }
69  
70      @Override
71      public List<ProductArtifact> getExtraContainerDependencies()
72      {
73          return Arrays.asList(
74                  new ProductArtifact("hsqldb", "hsqldb", "1.8.0.5"),
75                  new ProductArtifact("jta", "jta", "1.0.1"),
76                  new ProductArtifact("ots-jts", "ots-jts", "1.0"),
77  
78                  // for data source and transaction manager providers
79                  new ProductArtifact("jotm", "jotm", "1.4.3"),
80                  new ProductArtifact("jotm", "jotm-jrmp_stubs", "1.4.3"),
81                  new ProductArtifact("jotm", "jotm-iiop_stubs", "1.4.3"),
82                  new ProductArtifact("jotm", "jonas_timer", "1.4.3"),
83                  new ProductArtifact("jotm", "objectweb-datasource", "1.4.3"),
84                  new ProductArtifact("carol", "carol", "1.5.2"),
85                  new ProductArtifact("carol", "carol-properties", "1.0"),
86                  new ProductArtifact("xapool", "xapool", "1.3.1"),
87                  new ProductArtifact("commons-logging", "commons-logging", "1.1.1")
88          );
89      }
90  
91      @Override
92      public String getBundledPluginPath(Product ctx)
93      {
94      	String[] version = ctx.getVersion().split("-", 2)[0].split("\\.");
95      	long major = Long.parseLong(version[0]);
96      	long minor = Long.parseLong(version[1]);
97      	
98      	if (major < 4 || major == 4 && minor == 0)
99      	{
100     		return "WEB-INF/classes/com/atlassian/jira/plugin/atlassian-bundled-plugins.zip";
101     	}
102     	else
103     	{
104     		return "WEB-INF/classes/atlassian-bundled-plugins.zip";
105     	}
106     }
107 
108     @Override
109     public void processHomeDirectory(final Product ctx, final File homeDir) throws MojoExecutionException
110     {
111         ConfigFileUtils.replace(new File(homeDir, "database.script"), "@project-dir@", homeDir.getParent());
112         ConfigFileUtils.replace(new File(homeDir, "database.script"), "/jira-home/", "/home/");
113         ConfigFileUtils.replace(new File(homeDir, "database.script"), "@base-url@",
114                 "http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath());
115     }
116 
117     @Override
118     public List<ProductArtifact> getDefaultLibPlugins()
119     {
120         return Collections.emptyList();
121     }
122 
123     @Override
124     public List<ProductArtifact> getDefaultBundledPlugins()
125     {
126         return Collections.emptyList();
127     }
128 
129     private static class JiraPluginProvider extends AbstractPluginProvider
130     {
131 
132         @Override
133         protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
134         {
135             return Arrays.asList(
136                 new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
137                 new ProductArtifact("com.atlassian.sal", "sal-jira-plugin", salVersion));
138         }
139 
140         @Override
141         protected Collection<ProductArtifact> getPdkInstallArtifacts(String pdkInstallVersion)
142         {
143             List<ProductArtifact> plugins = new ArrayList<ProductArtifact>();
144             plugins.addAll(super.getPdkInstallArtifacts(pdkInstallVersion));
145             plugins.add(new ProductArtifact("commons-fileupload", "commons-fileupload", "1.2.1"));
146             return plugins;
147         }
148     }
149 }