/** * Gets last modified date/time for the module. * @return the date/time */ public static DateTime getDateTime() { try { final Class clazz = CasVersion.class; final URL resource = clazz.getResource(clazz.getSimpleName() + ".class"); if ("file".equals(resource.getProtocol())) { return new DateTime(new File(resource.toURI()).lastModified()); } if ("jar".equals(resource.getProtocol())) { final String path = resource.getPath(); final File file = new File(path.substring(5, path.indexOf('!'))); return new DateTime(file.lastModified()); } if ("vfs".equals(resource.getProtocol())) { final File file = new VfsResource(resource.openConnection().getContent()).getFile(); return new DateTime(file.lastModified()); } LOGGER.warn("Unhandled url protocol: {} resource: {}", resource.getProtocol(), resource); return DateTime.now(); } catch (final Exception e) { throw Throwables.propagate(e); } } }
/** * Gets last modified date/time for the module. * * @return the date/time */ @SneakyThrows public static ZonedDateTime getDateTime() { val clazz = CasVersion.class; val resource = clazz.getResource(clazz.getSimpleName() + ".class"); if ("file".equals(resource.getProtocol())) { return DateTimeUtils.zonedDateTimeOf(new File(resource.toURI()).lastModified()); } if ("jar".equals(resource.getProtocol())) { val path = resource.getPath(); val file = new File(path.substring(JAR_PROTOCOL_STARTING_INDEX, path.indexOf('!'))); return DateTimeUtils.zonedDateTimeOf(file.lastModified()); } if ("vfs".equals(resource.getProtocol())) { val file = new VfsResource(resource.openConnection().getContent()).getFile(); return DateTimeUtils.zonedDateTimeOf(file.lastModified()); } LOGGER.warn("Unhandled url protocol: [{}] resource: [{}]", resource.getProtocol(), resource); return ZonedDateTime.now(); } }