1 package org.kuali.maven.mojo;
2
3 import org.apache.maven.execution.MavenSession;
4 import org.apache.maven.plugin.AbstractMojo;
5 import org.apache.maven.plugin.MojoExecutionException;
6 import org.apache.maven.plugin.MojoFailureException;
7 import org.apache.maven.project.MavenProject;
8 import org.apache.maven.settings.Settings;
9 import org.kuali.maven.mojo.MavenLogger;
10
11
12
13
14
15
16
17
18 public abstract class BaseMojo extends AbstractMojo {
19 public static final String FS = System.getProperty("file.separator");
20 public static final String SKIP_PACKAGING_TYPE = "pom";
21
22
23
24
25
26
27
28 private boolean startMavenLogger;
29
30
31
32
33
34
35 private boolean skip;
36
37
38
39
40
41
42
43
44 private boolean forceMojoExecution;
45
46
47
48
49
50
51
52
53
54 private String encoding;
55
56
57
58
59
60
61
62
63 private MavenProject project;
64
65
66
67
68
69
70
71 private Settings settings;
72
73
74
75
76
77
78 private MavenSession mavenSession;
79
80 protected void beforeExecution() throws MojoExecutionException, MojoFailureException {
81 }
82
83 protected void afterExecution() throws MojoExecutionException, MojoFailureException {
84 }
85
86 @Override
87 public void execute() throws MojoExecutionException, MojoFailureException {
88 beforeExecution();
89 if (isStartMavenLogger()) {
90 MavenLogger.startPluginLog(this);
91 }
92 if (skipMojo()) {
93 return;
94 }
95 executeMojo();
96 if (isStartMavenLogger()) {
97 MavenLogger.endPluginLog(this);
98 }
99 afterExecution();
100 }
101
102 protected abstract void executeMojo() throws MojoExecutionException, MojoFailureException;
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 protected boolean skipMojo() {
118 if (skip) {
119 getLog().info("Skipping execution");
120 return true;
121 }
122
123 if (!forceMojoExecution && project != null && SKIP_PACKAGING_TYPE.equals(project.getPackaging())) {
124 getLog().info("Skipping execution for project with packaging type '" + SKIP_PACKAGING_TYPE + "'");
125 return true;
126 }
127
128 return false;
129 }
130
131
132
133
134
135
136 public MavenProject getProject() {
137 return project;
138 }
139
140 public String getEncoding() {
141 return encoding;
142 }
143
144 public void setEncoding(String encoding) {
145 this.encoding = encoding;
146 }
147
148 public boolean isSkip() {
149 return skip;
150 }
151
152 public void setSkip(boolean skip) {
153 this.skip = skip;
154 }
155
156 public boolean isForceMojoExecution() {
157 return forceMojoExecution;
158 }
159
160 public void setForceMojoExecution(boolean forceMojoExecution) {
161 this.forceMojoExecution = forceMojoExecution;
162 }
163
164 public Settings getSettings() {
165 return settings;
166 }
167
168 public void setSettings(Settings settings) {
169 this.settings = settings;
170 }
171
172 public MavenSession getMavenSession() {
173 return mavenSession;
174 }
175
176 public void setMavenSession(MavenSession mavenSession) {
177 this.mavenSession = mavenSession;
178 }
179
180 public void setProject(MavenProject project) {
181 this.project = project;
182 }
183
184 public boolean isStartMavenLogger() {
185 return startMavenLogger;
186 }
187
188 public void setStartMavenLogger(boolean startMavenLogger) {
189 this.startMavenLogger = startMavenLogger;
190 }
191 }