use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.
the class DefaultFileManager method readFile.
public FileDetails readFile(final String fileIdentifier) {
Validate.notNull(fileIdentifier, "File identifier required");
final File f = new File(fileIdentifier);
if (!f.exists()) {
return null;
}
return new FileDetails(f, f.lastModified());
}
use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.
the class PollingFileMonitorService method getFileCreationEvents.
private List<FileEvent> getFileCreationEvents(final MonitoringRequest request, final Map<File, Long> priorFiles) {
final List<FileEvent> createEvents = new ArrayList<FileEvent>();
for (final Iterator<String> iter = notifyCreated.iterator(); iter.hasNext(); ) {
final String filePath = iter.next();
if (isWithin(request, filePath)) {
// We've processed it
iter.remove();
// Skip this file if it doesn't exist
final File thisFile = new File(filePath);
if (thisFile.exists()) {
// Record the notification
createEvents.add(new FileEvent(new FileDetails(thisFile, thisFile.lastModified()), FileOperation.CREATED, null));
// Update the prior execution map so it isn't notified again
// next round
priorFiles.put(thisFile, thisFile.lastModified());
}
}
}
return createEvents;
}
use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.
the class PollingFileMonitorService method findMatchingAntPath.
public SortedSet<FileDetails> findMatchingAntPath(final String antPath) {
Validate.notBlank(antPath, "Ant path required");
final SortedSet<FileDetails> result = new TreeSet<FileDetails>();
// Now we need to compute the starting directory by reference to the
// first * in the Ant Path
int index = antPath.indexOf("*");
// Conditionals are based on an index of 0 (not -1) to ensure the
// detected character is not the only character in the string
Validate.isTrue(index > 0, "'%s' is not an Ant Path as it fails to include an * character", antPath);
String newPath = antPath.substring(0, index);
index = newPath.lastIndexOf(File.separatorChar);
Validate.isTrue(index > 0, "'%s' fails to include any '%s' directory separator", antPath, File.separatorChar);
newPath = newPath.substring(0, index);
final File somePath = new File(newPath);
if (!somePath.exists()) {
// no way we'll find anything via a search
return result;
}
Validate.isTrue(somePath.isDirectory(), "Ant path '%s' appears under file system path '%s' but this is not a directory that can be searched", antPath, somePath);
recursiveAntMatch(antPath, somePath, result);
return result;
}
use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.
the class PollingFileMonitorService method getFileDeletionEvents.
private List<FileEvent> getFileDeletionEvents(final MonitoringRequest request, final Map<File, Long> priorFiles) {
final List<FileEvent> deleteEvents = new ArrayList<FileEvent>();
for (final Iterator<String> iter = notifyDeleted.iterator(); iter.hasNext(); ) {
final String filePath = iter.next();
if (isWithin(request, filePath)) {
// We've processed it
iter.remove();
// Skip this file if it suddenly exists again (it shouldn't be
// in the notify deleted in this case!)
final File thisFile = new File(filePath);
if (!thisFile.exists()) {
// Record the notification
deleteEvents.add(new FileEvent(new FileDetails(thisFile, null), FileOperation.DELETED, null));
// Update the prior execution map so it isn't notified again
// next round
priorFiles.remove(thisFile);
}
}
}
return deleteEvents;
}
use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.
the class PollingFileMonitorService method getFileUpdateEvents.
private List<FileEvent> getFileUpdateEvents(final MonitoringRequest request, final Map<File, Long> priorFiles) {
final List<FileEvent> updateEvents = new ArrayList<FileEvent>();
for (final Iterator<String> iter = notifyChanged.iterator(); iter.hasNext(); ) {
final String filePath = iter.next();
if (isWithin(request, filePath)) {
// We've processed it
iter.remove();
// Skip this file if it doesn't exist
final File thisFile = new File(filePath);
if (thisFile.exists()) {
// Record the notification
updateEvents.add(new FileEvent(new FileDetails(thisFile, thisFile.lastModified()), FileOperation.UPDATED, null));
// Update the prior execution map so it isn't notified again
// next round
priorFiles.put(thisFile, thisFile.lastModified());
// Also remove it from the created list, if it's in there
if (notifyCreated.contains(filePath)) {
notifyCreated.remove(filePath);
}
}
}
}
return updateEvents;
}
Aggregations