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