Coverage Report - org.kuali.maven.mojo.BaseMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseMojo
0%
0/35
0%
0/10
1.471
 
 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  
  * Mojo essentials. Contains the "skip" logic that is the de facto standard for maven plugins. Contains a number of
 12  
  * maven related properties that are common to most mojos.
 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  
      * When <code>true</code>, skip the execution of this mojo
 20  
      *
 21  
      * @parameter default-value="false"
 22  
      */
 23  
     private boolean skip;
 24  
 
 25  
     /**
 26  
      * Setting this parameter to <code>true</code> will force the execution of this mojo, even if it would get skipped
 27  
      * usually.
 28  
      *
 29  
      * @parameter expression="${forceMojoExecution}" default-value="false"
 30  
      * @required
 31  
      */
 32  
     private boolean forceMojoExecution;
 33  
 
 34  
     /**
 35  
      * The encoding to use when reading/writing files. If not specified this defaults to the platform specific encoding
 36  
      * of whatever machine the build is running on.
 37  
      *
 38  
      * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
 39  
      */
 40  
     private String encoding;
 41  
 
 42  
     /**
 43  
      * The Maven project this plugin runs in.
 44  
      *
 45  
      * @parameter expression="${project}"
 46  
      * @required
 47  
      * @readonly
 48  
      */
 49  
     private MavenProject project;
 50  
 
 51  
     /**
 52  
      * @parameter expression="${settings}"
 53  
      * @required
 54  
      * @since 1.0
 55  
      * @readonly
 56  
      */
 57  
     private Settings settings;
 58  
 
 59  
     /**
 60  
      * @parameter default-value="${session}"
 61  
      * @required
 62  
      * @readonly
 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  
      * <p>
 86  
      * Determine if the mojo execution should get skipped.
 87  
      * </p>
 88  
      * This is the case if:
 89  
      * <ul>
 90  
      * <li>{@link #skip} is <code>true</code></li>
 91  
      * <li>if the mojo gets executed on a project with packaging type 'pom' and {@link #forceMojoExecution} is
 92  
      * <code>false</code></li>
 93  
      * </ul>
 94  
      *
 95  
      * @return <code>true</code> if the mojo execution should be skipped.
 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  
      * Returns the maven project.
 113  
      *
 114  
      * @return The maven project where this plugin runs in.
 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  
 }