1
// TAKEN FROM GLASSFISH. TODO: FIND CDDL HEADER
2
package org.jenkinsci.maven.plugins.hpi;
4
import org.apache.maven.plugin.CompilationFailureException;
5
import org.apache.maven.plugin.MojoExecutionException;
7
import java.lang.reflect.Field;
12
* @requiresDependencyResolution compile
13
* @author Kohsuke Kawaguchi
15
public class AptMojo extends CompilerMojo {
16
public void execute() throws MojoExecutionException, CompilationFailureException {
17
// overwrite the compilerId value. This seems to be the only way to
18
//do so without touching the copied files.
19
setField("compilerId", "hpi-apt");
21
if(!isMustangOrAbove())
22
throw new MojoExecutionException("JDK6 or later is necessary to build a Jenkins plugin");
28
* Are we running on JDK6 or above?
30
private static boolean isMustangOrAbove() {
32
Class.forName("javax.annotation.processing.Processor");
34
} catch(ClassNotFoundException e) {
39
private void setField(String name, String value) {
41
Field field = AbstractCompilerMojo.class.getDeclaredField(name);
42
field.setAccessible(true);
43
field.set(this, value);
44
} catch (NoSuchFieldException e) {
45
throw new AssertionError(e); // impossible
46
} catch (IllegalAccessException e) {
47
throw new AssertionError(e); // impossible