/maven-amps-plugin/src/main/java/com/atlassian/maven/plugins/amps/product/BambooProductHandler.java

https://bitbucket.org/mmeinhold/amps · Java · 139 lines · 113 code · 24 blank · 2 comment · 0 complexity · 28522c9503d828711111101b35ec0e27 MD5 · raw file

  1. package com.atlassian.maven.plugins.amps.product;
  2. import com.atlassian.maven.plugins.amps.MavenContext;
  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 com.atlassian.maven.plugins.amps.util.ConfigFileUtils.Replacement;
  8. import com.google.common.collect.ImmutableMap;
  9. import org.apache.maven.plugin.MojoExecutionException;
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.util.*;
  13. import static com.atlassian.maven.plugins.amps.util.FileUtils.deleteDir;
  14. public class BambooProductHandler extends AbstractWebappProductHandler
  15. {
  16. public BambooProductHandler(MavenContext context, MavenGoals goals)
  17. {
  18. super(context, goals, new BambooPluginProvider());
  19. }
  20. public String getId()
  21. {
  22. return "bamboo";
  23. }
  24. public ProductArtifact getArtifact()
  25. {
  26. return new ProductArtifact("com.atlassian.bamboo", "atlassian-bamboo-web-app", "RELEASE");
  27. }
  28. protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
  29. {
  30. return Arrays.asList(
  31. new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
  32. new ProductArtifact("com.atlassian.sal", "sal-bamboo-plugin", salVersion));
  33. }
  34. public ProductArtifact getTestResourcesArtifact()
  35. {
  36. return new ProductArtifact("com.atlassian.bamboo.plugins", "bamboo-plugin-test-resources");
  37. }
  38. public int getDefaultHttpPort()
  39. {
  40. return 6990;
  41. }
  42. public Map<String, String> getSystemProperties(Product ctx)
  43. {
  44. ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
  45. properties.putAll(super.getSystemProperties(ctx));
  46. properties.put("bamboo.home", getHomeDirectory(ctx).getPath());
  47. properties.put("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "false");
  48. return properties.build();
  49. }
  50. @Override
  51. public File getUserInstalledPluginsDirectory(final File webappDir, final File homeDir)
  52. {
  53. return new File(homeDir, "plugins");
  54. }
  55. public List<ProductArtifact> getExtraContainerDependencies()
  56. {
  57. return Collections.emptyList();
  58. }
  59. public File getBundledPluginPath(Product ctx, File appDir)
  60. {
  61. return new File(appDir, "WEB-INF/classes/atlassian-bundled-plugins.zip");
  62. }
  63. public void processHomeDirectory(final Product ctx, final File homeDir) throws MojoExecutionException
  64. {
  65. super.processHomeDirectory(ctx, homeDir);
  66. // The regex in the following search text is used to match IPv4 ([^:]+) or IPv6 (\[.+]) addresses.
  67. ConfigFileUtils.replaceAll(new File(homeDir, "/xml-data/configuration/administration.xml"),
  68. "http://(?:[^:]+|\\[.+]):8085", "http://" + ctx.getServer() + ":" + ctx.getHttpPort() + "/" + ctx.getContextPath().replaceAll("^/|/$", ""));
  69. }
  70. @Override
  71. public List<Replacement> getReplacements(Product product)
  72. {
  73. List<Replacement> replacements = super.getReplacements(product);
  74. File homeDirectory = getHomeDirectory(product);
  75. // We don't rewrap homes with these values:
  76. replacements.add(new Replacement("@project-dir@", homeDirectory.getParent(), false));
  77. replacements.add(new Replacement("/bamboo-home/", "/home/", false));
  78. replacements.add(new Replacement("${bambooHome}", homeDirectory.getAbsolutePath(), false));
  79. return replacements;
  80. }
  81. @Override
  82. public List<File> getConfigFiles(Product product, File homeDirectory)
  83. {
  84. List<File> configFiles = super.getConfigFiles(product, homeDirectory);
  85. configFiles.add(new File(homeDirectory, "bamboo.cfg.xml"));
  86. configFiles.add(new File(homeDirectory, "database.log"));
  87. return configFiles;
  88. }
  89. public List<ProductArtifact> getDefaultLibPlugins()
  90. {
  91. return Collections.emptyList();
  92. }
  93. public List<ProductArtifact> getDefaultBundledPlugins()
  94. {
  95. return Collections.emptyList();
  96. }
  97. @Override
  98. public void cleanupProductHomeForZip(Product bamboo, File genDir) throws MojoExecutionException, IOException
  99. {
  100. super.cleanupProductHomeForZip(bamboo, genDir);
  101. deleteDir(new File(genDir, "jms-store"));
  102. deleteDir(new File(genDir, "caches"));
  103. deleteDir(new File(genDir, "logs"));
  104. }
  105. private static class BambooPluginProvider extends AbstractPluginProvider
  106. {
  107. @Override
  108. protected Collection<ProductArtifact> getSalArtifacts(String salVersion)
  109. {
  110. return Arrays.asList(
  111. new ProductArtifact("com.atlassian.sal", "sal-api", salVersion),
  112. new ProductArtifact("com.atlassian.sal", "sal-bamboo-plugin", salVersion));
  113. }
  114. }
  115. }