1 package com.atlassian.maven.plugins.amps.product;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.List;
6
7 import org.apache.maven.plugin.MojoExecutionException;
8
9 import com.atlassian.maven.plugins.amps.Product;
10 import com.atlassian.maven.plugins.amps.util.ConfigFileUtils;
11
12 public interface ProductHandler
13 {
14 /**
15 * @return a convenient string to identify this application, especially for the context path.
16 * No further restriction is defined on this ID.
17 */
18 String getId();
19
20 /**
21 * Extracts the product and its home, prepares them and starts the product.
22 * @return the port on which the product is accessible
23 */
24 int start(Product ctx) throws MojoExecutionException;
25
26 void stop(Product ctx) throws MojoExecutionException;
27
28 int getDefaultHttpPort();
29
30 /**
31 * Return the directory to snapshot when we want to restore
32 * the state of the instance.
33 *
34 * Most often, equivalent to the home directory.
35 *
36 * Studio snapshots several homes together.
37 */
38 File getSnapshotDirectory(Product product);
39
40 File getHomeDirectory(Product product);
41
42 File getBaseDirectory(Product product);
43
44 /**
45 * Lists parameters which must be replaced in the configuration files of the home directory.
46 * <p/>
47 * Replacements returned by this method are guaranteed to be reversed when creating the home zip.
48 *
49 * @return a mutable list of replacements
50 */
51 List<ConfigFileUtils.Replacement> getReplacements(Product product);
52
53 /**
54 * List the configuration files. Used when doing a snapshot to reopen on another
55 * machine, with different port, context path, path, instanceId
56 * <p/>
57 * Files returned by this method are guaranteed to be reversed when creating the home zip.
58 *
59 * @param snapshotCopyDir A snapshot equivalent to the home in most cases. It is a copy of the folder: {@link #getSnapshotDirectory(Product)}
60 * The only exception is for the Studio product itself, as the snapshot dir is the parent of the studio home (so that it
61 * contains the homes of all products).
62 *
63 * @return a mutable list of files
64 */
65 List<File> getConfigFiles(Product product, File snapshotCopyDir);
66
67 /**
68 * Snapshots the home directory. The goal is that the state is totally restored if we restart the application
69 * with this minimal snapshot.
70 * <p/>
71 * It must call {@link #cleanupProductHomeForZip(Product, File)} to clean up the snapshot.
72 *
73 *
74 * @param homeDirectory The path to the previous run's home directory.
75 * @param targetZip The path to the final zip file.
76 * @param product The product
77 *
78 * @since 3.1-m3
79 */
80 public void createHomeZip(final File homeDirectory, final File targetZip, final Product product) throws MojoExecutionException;
81
82 /**
83 * Prepares the home directory to be zipped.
84 * <ul>
85 * <li>Removes all unnecessary files</li>
86 * <li>Perform product-specific clean-up</li>
87 * <ul>
88 * @param product the product details
89 * @param homeDirectory an image of the home directory. This is not the current home, so you're free to remove files and parametrise them.
90 */
91 public void cleanupProductHomeForZip(Product product, File homeDirectory) throws MojoExecutionException, IOException;
92 }