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