1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package br.com.ingenieux.mojo.beanstalk.cmd;
18
19 import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient;
20
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.maven.plugin.MojoFailureException;
23 import org.apache.maven.plugin.logging.Log;
24
25 import br.com.ingenieux.mojo.beanstalk.AbstractBeanstalkMojo;
26
27 public abstract class BaseCommand<I, O> implements Command<I, O> {
28
29
30
31
32 protected Log logger;
33
34
35
36
37 protected AWSElasticBeanstalkClient service;
38
39
40
41
42 protected AbstractBeanstalkMojo parentMojo;
43
44
45
46
47
48
49 protected BaseCommand(AbstractBeanstalkMojo parentMojo) throws MojoExecutionException {
50 this.parentMojo = parentMojo;
51
52 this.service = parentMojo.getService();
53
54 this.logger = parentMojo.getLog();
55 }
56
57 public boolean isDebugEnabled() {
58 return logger.isDebugEnabled();
59 }
60
61 public void debug(CharSequence message, Object... args) {
62 logger.debug(String.format("" + message, args));
63 }
64
65 public boolean isInfoEnabled() {
66 return logger.isInfoEnabled();
67 }
68
69 public void info(CharSequence message, Object... args) {
70 logger.info(String.format("" + message, args));
71 }
72
73 public final O execute(I context) throws MojoFailureException, MojoExecutionException {
74 try {
75 return executeInternal(context);
76 } catch (Exception exc) {
77 handleException(exc);
78
79 throw new RuntimeException("Unlikely");
80 }
81 }
82
83 private void handleException(Exception exc) throws MojoExecutionException, MojoFailureException {
84 parentMojo.handleException(exc);
85 }
86
87 protected abstract O executeInternal(I context) throws Exception;
88 }