1 28 29 package com.caucho.make.task; 30 31 import java.util.logging.*; 32 33 import com.caucho.log.Log; 34 35 import com.caucho.vfs.Path; 36 import com.caucho.vfs.Vfs; 37 38 import com.caucho.java.JavaCompiler; 39 40 import com.caucho.make.Make; 41 42 46 public class JavacTask implements Make { 47 private static final Logger log = Log.open(JavacTask.class); 48 49 private Path _srcdir; 50 private Path _dstdir; 51 52 public void setSrcdir(Path path) 53 { 54 _srcdir = path; 55 } 56 57 public void setDstdir(Path path) 58 { 59 _dstdir = path; 60 } 61 62 public void make() 63 throws Exception 64 { 65 Path dstDir = _dstdir; 66 67 if (dstDir == null) 68 dstDir = Vfs.lookup("WEB-INF/classes"); 69 70 Path srcDir = _srcdir; 71 72 if (srcDir == null) 73 srcDir = dstDir; 74 75 JavaCompiler compiler = JavaCompiler.create(); 76 compiler.setClassDir(dstDir); 77 78 makeAll(compiler, srcDir, dstDir); 79 } 80 81 public void makeAll(JavaCompiler compiler, Path srcDir, Path dstDir) 82 throws Exception 83 { 84 String []list = srcDir.list(); 85 86 for (int i = 0; i < list.length; i++) { 87 Path subSrc = srcDir.lookup(list[i]); 88 89 if (subSrc.isDirectory()) 90 makeAll(compiler, subSrc, dstDir.lookup(list[i])); 91 else if (list[i].endsWith(".java")) 92 makeJava(compiler, subSrc, dstDir); 93 } 94 } 95 96 public void makeJava(JavaCompiler compiler, Path javaSrc, Path dstDir) 97 throws Exception 98 { 99 String tail = javaSrc.getTail(); 100 Path classFile = dstDir.lookup(tail.substring(0, tail.length() - 5) + ".class"); 101 102 if (javaSrc.getLastModified() <= classFile.getLastModified()) 103 return; 104 105 compiler.compileIfModified(javaSrc.getPath(), null); 106 } 107 } 108 | Popular Tags |