/** * Returns dependency information on these two resources. If src has been * modified later than target, it returns true. If target doesn't exist, * it likewise returns true. Otherwise, target is newer than src and * is not out of date, thus the method returns false. It also returns * false if the src file doesn't even exist, since how could the * target then be out of date. * * @param src the original resource * @param target the resource being compared against * @param granularity the long amount in seconds of slack we will give in * determining out of dateness * @return whether the target is out of date */ public static boolean isOutOfDate(Resource src, Resource target, long granularity) { long sourceLastModified = src.getLastModified(); long targetLastModified = target.getLastModified(); return src.isExists() && (sourceLastModified == Resource.UNKNOWN_DATETIME || targetLastModified == Resource.UNKNOWN_DATETIME || (sourceLastModified - granularity) > targetLastModified); }
/** * Tells the modification time in milliseconds since 01.01.1970 . * * @return 0 if the resource does not exist to mirror the behavior * of {@link java.io.File File}. */ @Override public long getLastModified() { return getResource().getLastModified(); }
/** * Set the stylesheet file. * @param stylesheet a {@link org.apache.tools.ant.types.Resource} value * @throws Exception on error */ public void setStylesheet(final Resource stylesheet) throws Exception { if (this.stylesheet != null) { // resetting the stylesheet - reset transformer transformer = null; // do we need to reset templates as well if (!this.stylesheet.equals(stylesheet) || (stylesheet.getLastModified() != templatesModTime)) { templates = null; } } this.stylesheet = stylesheet; }
private void logWithModificationTime(Resource r, String what) { log(r.toLongString() + " is " + what + ", modified at " + new Date(r.getLastModified()), verbose ? Project.MSG_INFO : Project.MSG_VERBOSE); }
/** * Return true if this Resource is selected. * @param r the Resource to check. * @return whether the Resource was selected. */ public synchronized boolean isSelected(Resource r) { if (dateTime == null && millis == null) { throw new BuildException(MILLIS_OR_DATETIME); } if (millis == null) { String p = pattern == null ? "MM/dd/yyyy hh:mm a" : pattern; DateFormat df = pattern == null ? new SimpleDateFormat(p, Locale.US) : new SimpleDateFormat(p); try { long m = df.parse(dateTime).getTime(); if (m < 0) { throw new BuildException( "Date of %s results in negative milliseconds value relative to epoch (January 1, 1970, 00:00:00 GMT).", dateTime); } setMillis(m); } catch (ParseException pe) { throw new BuildException( "Date of %s Cannot be parsed correctly. It should be in '%s' format.", dateTime, p); } } return when.evaluate(r.getLastModified(), millis, granularity); }
/** * Implement the gunzipping. */ @Override protected void extract() { if (srcResource.getLastModified() > dest.lastModified()) { log("Expanding " + srcResource.getName() + " to " + dest.getAbsolutePath()); try (OutputStream out = Files.newOutputStream(dest.toPath()); GZIPInputStream zIn = new GZIPInputStream(srcResource.getInputStream())) { byte[] buffer = new byte[BUFFER_SIZE]; int count = 0; do { out.write(buffer, 0, count); count = zIn.read(buffer, 0, buffer.length); } while (count != -1); } catch (IOException ioe) { String msg = "Problem expanding gzip " + ioe.getMessage(); throw new BuildException(msg, ioe, getLocation()); } } }
/** * Read in templates from the stylesheet */ private void readTemplates() throws IOException, TransformerConfigurationException, ParserConfigurationException, SAXException { // Use a stream so that you can close it yourself quickly // and avoid keeping the handle until the object is garbaged. // (always keep control), otherwise you won't be able to delete // the file quickly on windows. try (InputStream xslStream = new BufferedInputStream(stylesheet.getInputStream())) { templatesModTime = stylesheet.getLastModified(); final Source src = getSource(xslStream, stylesheet); templates = getFactory().newTemplates(src); } }
src.getLastModified()); && lastScannedResource.getLastModified() == thisresource.getLastModified()) { return;
/** * Tells the modification time in milliseconds since 01.01.1970 . * * @return 0 if the resource does not exist to mirror the behavior * of {@link java.io.File File}. */ public synchronized long getLastModified() { if (isReference()) { return getCheckedRef().getLastModified(); } if (!isExists(false)) { return UNKNOWN_DATETIME; } return withConnection(c -> conn.getLastModified(), UNKNOWN_DATETIME); }
/** * Get the last modified date of this Resource. * @return the last modification date. */ @Override public long getLastModified() { if (isReference()) { return getCheckedRef().getLastModified(); } checkEntry(); return super.getLastModified(); }
/** * Tells the modification time in milliseconds since 01.01.1970 (the "epoch"). * * @return the modification time, if that is meaningful * (e.g. for a file resource which exists); * 0 if the resource does not exist, to mirror the behavior * of {@link java.io.File#lastModified}; * or 0 if the notion of modification time is meaningless for this class * of resource (e.g. an inline string) */ public long getLastModified() { if (isReference()) { return getCheckedRef().getLastModified(); } if (!isExists() || lastmodified == null) { return UNKNOWN_DATETIME; } long result = lastmodified; return result < UNKNOWN_DATETIME ? UNKNOWN_DATETIME : result; }
/** * evaluate the condition * @return true or false depending on the comparison mode and the time of the resource * @throws BuildException if something goes wrong */ @Override public boolean eval() throws BuildException { validate(); long expected = getMillis(); long actual = resource.getLastModified(); log("expected timestamp: " + expected + " (" + new Date(expected) + ")" + ", actual timestamp: " + actual + " (" + new Date(actual) + ")", Project.MSG_VERBOSE); if (CompareMode.EQUALS_TEXT.equals(mode.getValue())) { return expected == actual; } if (CompareMode.BEFORE_TEXT.equals(mode.getValue())) { return expected > actual; } if (CompareMode.NOT_BEFORE_TEXT.equals(mode.getValue())) { return expected <= actual; } if (CompareMode.AFTER_TEXT.equals(mode.getValue())) { return expected < actual; } if (CompareMode.NOT_AFTER_TEXT.equals(mode.getValue())) { return expected >= actual; } throw new BuildException("Unknown mode " + mode.getValue()); }
if (srcResource.getLastModified() > dest.lastModified()) { log("Expanding " + srcResource.getName() + " to " + dest.getAbsolutePath());
/** * validate, then hand off to the subclass * @throws BuildException on error */ @Override public void execute() throws BuildException { validate(); Resource s = getSrcResource(); if (!s.isExists()) { log("Nothing to do: " + s.toString() + " doesn't exist."); } else if (zipFile.lastModified() < s.getLastModified()) { log("Building: " + zipFile.getAbsolutePath()); pack(); } else { log("Nothing to do: " + zipFile.getAbsolutePath() + " is up to date."); } }
final long styleSheetLastModified = stylesheet.getLastModified(); log("In file " + inFile + " time: " + inFile.lastModified(), Project.MSG_DEBUG); log("Out file " + outFile + " time: " + outFile.lastModified(), Project.MSG_DEBUG);
final long styleSheetLastModified = stylesheet.getLastModified(); File inF = new File(baseDir, xmlFile);
/** * Add a file entry. */ private void addResource(final Resource r, final String name, final String prefix, final ZipOutputStream zOut, final int mode, final ZipFile zf, final File fromArchive) throws IOException { if (zf != null) { final ZipEntry ze = zf.getEntry(r.getName()); if (ze != null) { final boolean oldCompress = doCompress; if (keepCompression) { doCompress = (ze.getMethod() == ZipEntry.DEFLATED); } try (final BufferedInputStream is = new BufferedInputStream(zf.getInputStream(ze))) { zipFile(is, zOut, prefix + name, ze.getTime(), fromArchive, mode, ze.getExtraFields(true)); } finally { doCompress = oldCompress; } } } else { try (final BufferedInputStream is = new BufferedInputStream(r.getInputStream())) { zipFile(is, zOut, prefix + name, r.getLastModified(), fromArchive, mode, r instanceof ZipResource ? ((ZipResource) r).getExtraFields() : null); } } }
ze.setTime(modTimeMillis); } else if (dir != null && dir.isExists()) { ze.setTime(dir.getLastModified() + millisToAdd); } else { ze.setTime(System.currentTimeMillis() + millisToAdd);
private boolean uptodate(ResourceCollection src, ResourceCollection target) { org.apache.tools.ant.types.resources.selectors.Date datesel = new org.apache.tools.ant.types.resources.selectors.Date(); datesel.setMillis(System.currentTimeMillis()); datesel.setWhen(TimeComparison.AFTER); // don't whine because a file has changed during the last // second (or whatever our current granularity may be) datesel.setGranularity(0); logFuture(targets, datesel); NonExistent missingTargets = new NonExistent(targets); int neTargets = missingTargets.size(); if (neTargets > 0) { log(neTargets + " nonexistent targets", Project.MSG_VERBOSE); logMissing(missingTargets, "target"); return false; } Resource oldestTarget = getOldest(targets); logWithModificationTime(oldestTarget, "oldest target file"); logFuture(sources, datesel); NonExistent missingSources = new NonExistent(sources); int neSources = missingSources.size(); if (neSources > 0) { log(neSources + " nonexistent sources", Project.MSG_VERBOSE); logMissing(missingSources, "source"); return false; } Resource newestSource = getNewest(sources); logWithModificationTime(newestSource, "newest source"); return oldestTarget.getLastModified() >= newestSource.getLastModified(); }
private void touch(Resource r, long defaultTimestamp) { if (fileNameMapper == null) { FileProvider fp = r.as(FileProvider.class); if (fp != null) { // use this to create file and deal with non-writable files touch(fp.getFile(), defaultTimestamp); } else { r.as(Touchable.class).touch(defaultTimestamp); } } else { String[] mapped = fileNameMapper.mapFileName(r.getName()); if (mapped != null && mapped.length > 0) { long modTime = defaultTimestamp; if (millis < 0 && r.isExists()) { modTime = r.getLastModified(); } for (String fileName : mapped) { touch(getProject().resolveFile(fileName), modTime); } } } }