1 package com.atlassian.maven.plugins.amps;
2
3 import com.atlassian.maven.plugins.amps.product.ProductHandler;
4 import com.atlassian.maven.plugins.amps.product.ProductHandlerFactory;
5 import com.atlassian.maven.plugins.amps.product.studio.StudioProductHandler;
6 import com.google.common.collect.Lists;
7 import org.apache.maven.plugin.MojoExecutionException;
8 import org.apache.maven.plugin.MojoFailureException;
9 import org.jfrog.maven.annomojo.annotations.MojoGoal;
10 import org.jfrog.maven.annomojo.annotations.MojoParameter;
11
12 import java.io.File;
13 import java.util.List;
14 import java.util.Map;
15
16
17
18
19
20
21
22 @MojoGoal("create-home-zip")
23 public class CreateHomeZipMojo extends AbstractProductHandlerMojo {
24
25
26
27
28 @MojoParameter(expression = "${homeZip}", required = false)
29 protected File homeZip;
30
31 public void doExecute() throws MojoExecutionException, MojoFailureException
32 {
33 Product product = getProduct(instanceId, getProductId());
34 ProductHandler productHandler = createProductHandler(product.getId());
35
36 if (ProductHandlerFactory.STUDIO.equals(product.getId()))
37 {
38 configureStudio(product, (StudioProductHandler) productHandler);
39 }
40
41 final File snapshotDir = productHandler.getSnapshotDirectory(product);
42 if (homeZip == null)
43 {
44 homeZip = new File(productHandler.getBaseDirectory(product), "generated-test-resources.zip");
45 }
46
47 productHandler.createHomeZip(snapshotDir, homeZip, product);
48
49 getLog().info("Home directory zip created successfully at " + homeZip.getAbsolutePath());
50
51
52 getMavenGoals().attachArtifact(homeZip, "zip");
53
54 }
55
56
57
58
59
60
61
62
63
64
65 private void configureStudio(Product studioProduct, StudioProductHandler studioProductHandler) throws MojoExecutionException
66 {
67 List<ProductExecution> executions = Lists.newArrayList(new ProductExecution(studioProduct, studioProductHandler));
68 includeStudioDependentProducts(executions, getMavenGoals());
69 }
70
71
72
73
74
75
76
77
78
79
80 private Product getProduct(final String instanceId, final String productId) throws MojoExecutionException
81 {
82 Map<String, Product> contexts = getProductContexts();
83
84 Product product = null;
85 if (instanceId != null)
86 {
87 product = contexts.get(instanceId);
88 if (product == null)
89 {
90 throw new MojoExecutionException("There is no instance with name " + instanceId + " defined in the pom.xml");
91 }
92 }
93 else
94 {
95 for (Product candidate : contexts.values())
96 {
97 if (candidate.getId().equals(productId))
98 {
99 product = candidate;
100 break;
101 }
102 }
103 if (product == null)
104 {
105 throw new MojoExecutionException("There is no product with name " + productId + " defined in the pom.xml. Please use -DinstanceId=..." +
106 " to set the instance to snapshot.");
107 }
108 }
109
110 return product;
111 }
112 }