PageRenderTime 44ms CodeModel.GetById 12ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

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