| 1 |  | package org.apache.torque.mojo; | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  | import java.io.File; | 
            
  
    | 4 |  | import java.io.FileInputStream; | 
            
  
    | 5 |  | import java.io.FileOutputStream; | 
            
  
    | 6 |  | import java.io.IOException; | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  | import org.apache.maven.plugin.MojoExecutionException; | 
            
  
    | 9 |  | import org.apache.torque.mojo.morph.MorphRequest; | 
            
  
    | 10 |  | import org.apache.torque.mojo.morph.Morpher; | 
            
  
    | 11 |  | import org.codehaus.plexus.util.FileUtils; | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 14 |  |  | 
            
  
    | 15 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 43 (43) | Complexity: 12 | Complexity Density: 0.43 |  | 
  
  
    | 16 |  | public abstract class AbstractMorphSingleMojo extends BaseMojo { | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  |  | 
            
  
    | 19 |  |  | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  | private File newFile; | 
            
  
    | 22 |  |  | 
            
  
    | 23 |  |  | 
            
  
    | 24 |  |  | 
            
  
    | 25 |  |  | 
            
  
    | 26 |  | private File oldFile; | 
            
  
    | 27 |  |  | 
            
  
    | 28 |  |  | 
            
  
    | 29 |  |  | 
            
  
    | 30 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 11 (11) | Complexity: 3 | Complexity Density: 0.43 |  | 
  
  
    | 31 | 0 |  @Override... | 
            
  
    | 32 |  | protected boolean skipMojo() { | 
            
  
    | 33 |  |  | 
            
  
    | 34 | 0 | if (super.skipMojo()) { | 
            
  
    | 35 | 0 | return true; | 
            
  
    | 36 |  | } | 
            
  
    | 37 |  |  | 
            
  
    | 38 |  |  | 
            
  
    | 39 | 0 | boolean morphNeeded = isMorphNeeded(); | 
            
  
    | 40 | 0 | if (morphNeeded) { | 
            
  
    | 41 | 0 | return false; | 
            
  
    | 42 |  | } else { | 
            
  
    | 43 | 0 | getLog().info("Skipping morph.  Nothing has changed"); | 
            
  
    | 44 | 0 | return true; | 
            
  
    | 45 |  | } | 
            
  
    | 46 |  | } | 
            
  
    | 47 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 12 (12) | Complexity: 3 | Complexity Density: 0.38 |  | 
  
  
    | 48 | 0 |  protected boolean isMorphNeeded() {... | 
            
  
    | 49 |  |  | 
            
  
    | 50 | 0 | if (!getOldFile().exists()) { | 
            
  
    | 51 | 0 | getLog().debug("file:" + getOldFile().getAbsolutePath() + " does not exist"); | 
            
  
    | 52 | 0 | return false; | 
            
  
    | 53 |  | } | 
            
  
    | 54 |  |  | 
            
  
    | 55 |  |  | 
            
  
    | 56 | 0 | if (!getNewFile().exists()) { | 
            
  
    | 57 | 0 | return true; | 
            
  
    | 58 |  | } | 
            
  
    | 59 |  |  | 
            
  
    | 60 |  |  | 
            
  
    | 61 | 0 | long oldLastModified = getOldFile().lastModified(); | 
            
  
    | 62 | 0 | long newLastModified = getNewFile().lastModified(); | 
            
  
    | 63 |  |  | 
            
  
    | 64 |  |  | 
            
  
    | 65 |  |  | 
            
  
    | 66 | 0 | return oldLastModified > newLastModified; | 
            
  
    | 67 |  | } | 
            
  
    | 68 |  |  | 
            
  
    | 69 |  | protected abstract Morpher getMorpher(MorphRequest request, String artifactId); | 
            
  
    | 70 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 9 (9) | Complexity: 2 | Complexity Density: 0.22 |  | 
  
  
    | 71 | 0 |  @Override... | 
            
  
    | 72 |  | protected void executeMojo() throws MojoExecutionException { | 
            
  
    | 73 | 0 | try { | 
            
  
    | 74 | 0 | getLog().info("From: " + oldFile.getAbsolutePath()); | 
            
  
    | 75 | 0 | getLog().info("  To: " + newFile.getAbsolutePath()); | 
            
  
    | 76 | 0 | FileUtils.forceMkdir(new File(FileUtils.getPath(newFile.getAbsolutePath()))); | 
            
  
    | 77 | 0 | MorphRequest request = new MorphRequest(oldFile.getName(), new FileInputStream(oldFile), | 
            
  
    | 78 |  | new FileOutputStream(newFile)); | 
            
  
    | 79 | 0 | request.setEncoding(getEncoding()); | 
            
  
    | 80 | 0 | Morpher morpher = getMorpher(request, getProject().getArtifactId()); | 
            
  
    | 81 | 0 | morpher.executeMorph(); | 
            
  
    | 82 |  | } catch (IOException e) { | 
            
  
    | 83 | 0 | throw new MojoExecutionException("Unexpected error while attempting to morph " + oldFile.getAbsolutePath(), | 
            
  
    | 84 |  | e); | 
            
  
    | 85 |  | } | 
            
  
    | 86 |  | } | 
            
  
    | 87 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 88 | 0 |  public File getNewFile() {... | 
            
  
    | 89 | 0 | return newFile; | 
            
  
    | 90 |  | } | 
            
  
    | 91 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 92 | 0 |  public void setNewFile(final File newFile) {... | 
            
  
    | 93 | 0 | this.newFile = newFile; | 
            
  
    | 94 |  | } | 
            
  
    | 95 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 96 | 0 |  public File getOldFile() {... | 
            
  
    | 97 | 0 | return oldFile; | 
            
  
    | 98 |  | } | 
            
  
    | 99 |  |  | 
               
        |  |  | 
           
           |  | 0% | Uncovered Elements: 1 (1) | Complexity: 1 | Complexity Density: 1 |  | 
  
  
    | 100 | 0 |  public void setOldFile(final File oldFile) {... | 
            
  
    | 101 | 0 | this.oldFile = oldFile; | 
            
  
    | 102 |  | } | 
            
  
    | 103 |  | } |