1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package br.com.ingenieux.mojo.beanstalk.config;
18
19 import com.amazonaws.services.elasticbeanstalk.model.ApplicationDescription;
20 import com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationsRequest;
21 import com.amazonaws.services.elasticbeanstalk.model.DescribeApplicationsResult;
22
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.plugin.MojoFailureException;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27
28 import java.util.List;
29
30 import br.com.ingenieux.mojo.beanstalk.AbstractBeanstalkMojo;
31
32 import static java.lang.String.format;
33
34
35
36
37
38
39
40 @Mojo(name = "list-configuration-templates", requiresDirectInvocation = true)
41 public class ListConfigurationTemplatesMojo extends AbstractBeanstalkMojo {
42
43 @Parameter(property = "beanstalk.applicationName", defaultValue = "${project.artifactId}", required = true)
44 protected String applicationName;
45
46 @Override
47 protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
48 DescribeApplicationsRequest req = new DescribeApplicationsRequest().withApplicationNames(applicationName);
49
50 DescribeApplicationsResult apps = getService().describeApplications(req);
51
52 List<ApplicationDescription> applications = apps.getApplications();
53
54 if (applications.isEmpty()) {
55 String errorMessage = "Application ('" + applicationName + "') not found!";
56
57 getLog().warn(errorMessage);
58
59 throw new MojoFailureException(errorMessage);
60 }
61
62 ApplicationDescription desc = applications.get(0);
63
64 List<String> configTemplates = desc.getConfigurationTemplates();
65
66 getLog().info(format("There are %d config templates", configTemplates.size()));
67
68 return configTemplates;
69 }
70 }