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