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 is most cases. It is a copy of the folder: {@link #getSnapshotDirectory(Product)}
60       * @return a mutable list of files
61       */
62      List<File> getConfigFiles(Product product, File snapshotCopyDir);
63  
64      /**
65       * Snapshots the home directory. The goal is that the state is totally restored if we restart the application
66       * with this minimal snapshot.
67       * <p/>
68       * It must call {@link #cleanupProductHomeForZip(Product, File)} to clean up the snapshot.
69       *
70       *
71       * @param homeDirectory The path to the previous run's home directory.
72       * @param targetZip     The path to the final zip file.
73       * @param product       The product
74       *
75       * @since 3.1-m3
76       */
77      public void createHomeZip(final File homeDirectory, final File targetZip, final Product product) throws MojoExecutionException;
78  
79      /**
80       * Prepares the home directory to be zipped.
81       * <ul>
82       * <li>Removes all unnecessary files</li>
83       * <li>Perform product-specific clean-up</li>
84       * <ul>
85       * @param product the product details
86       * @param homeDirectory an image of the home directory. This is not the current home, so you're free to remove files and parametrise them.
87       */
88      public void cleanupProductHomeForZip(Product product, File homeDirectory) throws MojoExecutionException, IOException;
89  }