package com.isx.ant.jaxbtask; import org.apache.tools.ant.Task; import org.apache.tools.ant.Project; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; import java.io.*; import java.util.*; public class JaxbCheck extends Task { public JaxbCheck() { } String dtdFile; String xjsFile; String destroot; String property; String value; public void setDtdFile(String d) { dtdFile = d; } public void setXjsFile(String x) { xjsFile = x; } public void setDest(String d) { destroot = d; } public void setProperty(String s) { property = s; } public void setValue(String s) { value = s; } public void execute() { if (property == null || property.equals("")) throw new BuildException("property attribute must be set"); if (value == null || value.equals("")) throw new BuildException("value attribute must be set"); if (destroot == null || destroot.equals("")) throw new BuildException("dest attribute must be set"); if (dtdFile == null || dtdFile.equals("")) throw new BuildException("dtdFile attribute must be set"); if (xjsFile == null || xjsFile.equals("")) throw new BuildException("xjsFile attribute must be set"); File realDtdFile = project.resolveFile(project.translatePath(dtdFile)); File realXjsFile = project.resolveFile(project.translatePath(xjsFile)); File realDest = project.resolveFile(project.translatePath(destroot)); File[] files = new File[0]; try { files = JAXBFileDeterminer.findFiles(realDtdFile, realXjsFile, realDest); } catch (Exception e) { throw new BuildException("JAXBFileDeterminer problem : " + e.getMessage(), e); } boolean ok = true; for (int i = 0; i < files.length; ++i) { log(files[i] + " exists? " + files[i].exists(), Project.MSG_VERBOSE); if (!files[i].exists()) { ok = false; break; } log("File Last Modified : " + files[i].lastModified(), Project.MSG_VERBOSE); log("DTD Last Modified : " + realDtdFile.lastModified(), Project.MSG_VERBOSE); log("XJS Last Modified : " + realXjsFile.lastModified(), Project.MSG_VERBOSE); if ((files[i].lastModified() < realDtdFile.lastModified()) || (files[i].lastModified() < realXjsFile.lastModified())) { ok = false; break; } } if (!ok) { // if not ok, do the build log("Need to rebuild", Project.MSG_VERBOSE); project.setProperty(property, value); } else { log("All files up to date", Project.MSG_VERBOSE); } } }