| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BaseMojo | 
 | 
 | 1.5333333333333334;1.533 | 
| 1 |  package org.kuali.maven.mojo.s3; | |
| 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. Also sets up logging so that if libraries called by a mojo | |
| 13 |   * issue log statements to Jakarta Commons Logging or Log4j, those log messages are shown in maven's output | |
| 14 |   */ | |
| 15 | 0 |  public abstract class BaseMojo extends AbstractMojo { | 
| 16 | ||
| 17 |      /** | |
| 18 |       * Convenience reference to System.getProperty("file.separator"). | |
| 19 |       */ | |
| 20 | 0 |      public static final String FS = System.getProperty("file.separator"); | 
| 21 | ||
| 22 |      /** | |
| 23 |       * Skip packaging if type is "pom". | |
| 24 |       */ | |
| 25 | public static final String SKIP_PACKAGING_TYPE = "pom"; | |
| 26 | ||
| 27 |      /** | |
| 28 |       * When <code>true</code>, skip the execution of this mojo. | |
| 29 |       * | |
| 30 |       * @parameter default-value="false" | |
| 31 |       */ | |
| 32 | private boolean skip; | |
| 33 | ||
| 34 |      /** | |
| 35 |       * Setting this parameter to <code>true</code> will force the execution of this mojo, even if it would get skipped | |
| 36 |       * usually. | |
| 37 |       * | |
| 38 |       * @parameter expression="${forceMojoExecution}" default-value="false" | |
| 39 |       * @required | |
| 40 |       */ | |
| 41 | private boolean forceMojoExecution; | |
| 42 | ||
| 43 |      /** | |
| 44 |       * The encoding to use when reading/writing files. If not specified this defaults to the platform specific encoding | |
| 45 |       * of whatever machine the build is running on. | |
| 46 |       * | |
| 47 |       * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}" | |
| 48 |       */ | |
| 49 |      private String encoding; | |
| 50 | ||
| 51 |      /** | |
| 52 |       * The Maven project this plugin runs in. | |
| 53 |       * | |
| 54 |       * @parameter expression="${project}" | |
| 55 |       * @required | |
| 56 |       * @readonly | |
| 57 |       */ | |
| 58 |      private MavenProject project; | |
| 59 | ||
| 60 |      /** | |
| 61 |       * @parameter expression="${settings}" | |
| 62 |       * @required | |
| 63 |       * @since 1.0 | |
| 64 |       * @readonly | |
| 65 |       */ | |
| 66 |      private Settings settings; | |
| 67 | ||
| 68 |      /** | |
| 69 |       * @parameter default-value="${session}" | |
| 70 |       * @required | |
| 71 |       * @readonly | |
| 72 |       */ | |
| 73 |      private MavenSession mavenSession; | |
| 74 | ||
| 75 | public void execute() throws MojoExecutionException, MojoFailureException { | |
| 76 | 0 |          if (skipMojo()) { | 
| 77 | 0 |              return; | 
| 78 | } | |
| 79 | 0 |          executeMojo(); | 
| 80 | 0 |      } | 
| 81 | ||
| 82 |      /** | |
| 83 |       * This method is called after logging has been configured and only if mojo execution should not be skipped. | |
| 84 |       * | |
| 85 |       * @throws MojoExecutionException | |
| 86 |       * @throws MojoFailureException | |
| 87 |       */ | |
| 88 | protected abstract void executeMojo() throws MojoExecutionException, MojoFailureException; | |
| 89 | ||
| 90 |      /** | |
| 91 |       * <p> | |
| 92 |       * Determine if the mojo execution should get skipped. | |
| 93 |       * </p> | |
| 94 |       * This is the case if: | |
| 95 |       * <ul> | |
| 96 |       * <li>{@link #skip} is <code>true</code></li> | |
| 97 |       * <li>if the mojo gets executed on a project with packaging type 'pom' and {@link #forceMojoExecution} is | |
| 98 |       * <code>false</code></li> | |
| 99 |       * </ul> | |
| 100 |       * | |
| 101 |       * @return <code>true</code> if the mojo execution should be skipped. | |
| 102 |       */ | |
| 103 | protected boolean skipMojo() { | |
| 104 | 0 |          if (skip) { | 
| 105 | 0 |              getLog().info("Skipping execution"); | 
| 106 | 0 |              return true; | 
| 107 | } | |
| 108 | ||
| 109 | 0 |          if (!forceMojoExecution && project != null && SKIP_PACKAGING_TYPE.equals(project.getPackaging())) { | 
| 110 | 0 |              getLog().info("Skipping execution for project with packaging type '" + SKIP_PACKAGING_TYPE + "'"); | 
| 111 | 0 |              return true; | 
| 112 | } | |
| 113 | ||
| 114 | 0 |          return false; | 
| 115 | } | |
| 116 | ||
| 117 |      /** | |
| 118 |       * @return the skip | |
| 119 |       */ | |
| 120 | public boolean isSkip() { | |
| 121 | 0 |          return skip; | 
| 122 | } | |
| 123 | ||
| 124 |      /** | |
| 125 |       * @param skip | |
| 126 |       * the skip to set | |
| 127 |       */ | |
| 128 | public void setSkip(final boolean skip) { | |
| 129 | 0 |          this.skip = skip; | 
| 130 | 0 |      } | 
| 131 | ||
| 132 |      /** | |
| 133 |       * @return the forceMojoExecution | |
| 134 |       */ | |
| 135 | public boolean isForceMojoExecution() { | |
| 136 | 0 |          return forceMojoExecution; | 
| 137 | } | |
| 138 | ||
| 139 |      /** | |
| 140 |       * @param forceMojoExecution | |
| 141 |       * the forceMojoExecution to set | |
| 142 |       */ | |
| 143 | public void setForceMojoExecution(final boolean forceMojoExecution) { | |
| 144 | 0 |          this.forceMojoExecution = forceMojoExecution; | 
| 145 | 0 |      } | 
| 146 | ||
| 147 |      /** | |
| 148 |       * @return the encoding | |
| 149 |       */ | |
| 150 |      public String getEncoding() { | |
| 151 | 0 |          return encoding; | 
| 152 | } | |
| 153 | ||
| 154 |      /** | |
| 155 |       * @param encoding | |
| 156 |       * the encoding to set | |
| 157 |       */ | |
| 158 | public void setEncoding(final String encoding) { | |
| 159 | 0 |          this.encoding = encoding; | 
| 160 | 0 |      } | 
| 161 | ||
| 162 |      /** | |
| 163 |       * @return the project | |
| 164 |       */ | |
| 165 |      public MavenProject getProject() { | |
| 166 | 0 |          return project; | 
| 167 | } | |
| 168 | ||
| 169 |      /** | |
| 170 |       * @param project | |
| 171 |       * the project to set | |
| 172 |       */ | |
| 173 | public void setProject(final MavenProject project) { | |
| 174 | 0 |          this.project = project; | 
| 175 | 0 |      } | 
| 176 | ||
| 177 |      /** | |
| 178 |       * @return the settings | |
| 179 |       */ | |
| 180 |      public Settings getSettings() { | |
| 181 | 0 |          return settings; | 
| 182 | } | |
| 183 | ||
| 184 |      /** | |
| 185 |       * @param settings | |
| 186 |       * the settings to set | |
| 187 |       */ | |
| 188 | public void setSettings(final Settings settings) { | |
| 189 | 0 |          this.settings = settings; | 
| 190 | 0 |      } | 
| 191 | ||
| 192 |      /** | |
| 193 |       * @return the mavenSession | |
| 194 |       */ | |
| 195 |      public MavenSession getMavenSession() { | |
| 196 | 0 |          return mavenSession; | 
| 197 | } | |
| 198 | ||
| 199 |      /** | |
| 200 |       * @param mavenSession | |
| 201 |       * the mavenSession to set | |
| 202 |       */ | |
| 203 | public void setMavenSession(final MavenSession mavenSession) { | |
| 204 | 0 |          this.mavenSession = mavenSession; | 
| 205 | 0 |      } | 
| 206 | ||
| 207 | } |