| 1 9 package org.infozone.tools.ant; 10 11 import org.apache.tools.ant.BuildException; 12 import org.apache.tools.ant.taskdefs.Exec; 13 import org.apache.tools.ant.Project; 14 15 import java.io.File ; 16 import java.io.IOException ; 17 18 27 public class DependendExec extends Exec { 28 29 33 34 private String _target = null; 35 36 private String _source = null; 37 38 43 private boolean isOlder( String source, String target ) throws BuildException { 44 File f_src = new File ( source ); 45 46 if( !(f_src.exists() && (f_src.isFile() || f_src.isDirectory())) ) 47 throw new BuildException("Source [[" + source + "]] doesn't exists or isn't a regular entry"); 48 49 File f_dst = new File ( target ); 50 51 if( !(f_dst.exists())) 52 return true; 54 if ( f_dst.isDirectory() ) { 55 target = target + File.separator + ".depend"; 56 f_dst = new File (target); 57 if( !(f_dst.exists())) 58 return true; } 60 61 if( !(f_dst.isFile()) ) 62 throw new BuildException("Target [[" + target + "]] isn't a regular entry"); 63 64 return f_src.lastModified() > f_dst.lastModified(); 65 } 66 67 71 private void touch( String target ) throws BuildException { 72 File f_dst = new File ( target ); 73 74 if( f_dst.exists() ) { 76 if ( f_dst.isDirectory() ) { 77 target = target + File.separator + ".depend"; 78 f_dst = new File (target); 79 } 80 } 81 else 82 return; 84 if( f_dst.exists() ) { 85 f_dst.setLastModified( System.currentTimeMillis() ); 86 } 87 else { 88 try { 89 f_dst.createNewFile(); 91 } catch (IOException e) { 92 } 94 95 } 96 } 97 98 99 104 public void execute() throws BuildException { 105 if( isOlder( _source, _target ) ) { 106 super.execute(); 107 touch( _target ); 108 } 109 else { 110 System.out.println("Nothing to be done for this dependency: " + _source + Project.MSG_INFO); 111 } 113 } 114 115 116 119 public void setTarget( String s ) { 120 _target = s; 121 } 122 123 124 127 public void setDependsOn( String s ) { 128 _source = s; 129 } 130 } 131 | Popular Tags |