1 9 package org.infozone.tools.ant; 10 11 import org.apache.tools.ant.BuildException; 12 import org.apache.tools.ant.taskdefs.Java; 13 import org.apache.tools.ant.Project; 14 15 import java.io.File ; 16 import java.io.IOException ; 17 18 26 public class DependendJava extends Java { 27 28 32 33 private String _target = null; 34 35 private String _source = null; 36 37 42 private boolean isOlder( String source, String target ) throws BuildException { 43 File f_src = new File ( source ); 44 45 if( !(f_src.exists() && (f_src.isFile() || f_src.isDirectory())) ) 46 throw new BuildException("Source [[" + source + "]] doesn't exists or isn't a regular entry"); 47 48 File f_dst = new File ( target ); 49 50 if( !(f_dst.exists())) 51 return true; 53 if ( f_dst.isDirectory() ) { 54 target = target + File.separator + ".depend"; 55 f_dst = new File (target); 56 if( !(f_dst.exists())) 57 return true; } 59 60 if( !(f_dst.isFile()) ) 61 throw new BuildException("Target [[" + target + "]] isn't a regular entry"); 62 63 return f_src.lastModified() > f_dst.lastModified(); 64 } 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 126 public void setDependsOn( String s ) { 127 _source = s; 128 } 129 130 } 131 | Popular Tags |