Search in sources :

Example 1 with FileDetails

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());
}
Also used : FileDetails(org.springframework.roo.file.monitor.event.FileDetails) MutableFile(org.springframework.roo.process.manager.MutableFile) CreateFile(org.springframework.roo.file.undo.CreateFile) File(java.io.File) DeleteFile(org.springframework.roo.file.undo.DeleteFile) UpdateFile(org.springframework.roo.file.undo.UpdateFile)

Example 2 with FileDetails

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;
}
Also used : FileEvent(org.springframework.roo.file.monitor.event.FileEvent) ArrayList(java.util.ArrayList) FileDetails(org.springframework.roo.file.monitor.event.FileDetails) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 3 with FileDetails

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;
}
Also used : TreeSet(java.util.TreeSet) FileDetails(org.springframework.roo.file.monitor.event.FileDetails) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with FileDetails

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;
}
Also used : FileEvent(org.springframework.roo.file.monitor.event.FileEvent) ArrayList(java.util.ArrayList) FileDetails(org.springframework.roo.file.monitor.event.FileDetails) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 5 with FileDetails

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;
}
Also used : FileEvent(org.springframework.roo.file.monitor.event.FileEvent) ArrayList(java.util.ArrayList) FileDetails(org.springframework.roo.file.monitor.event.FileDetails) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

FileDetails (org.springframework.roo.file.monitor.event.FileDetails)12 File (java.io.File)9 JarFile (java.util.jar.JarFile)7 ArrayList (java.util.ArrayList)6 FileEvent (org.springframework.roo.file.monitor.event.FileEvent)5 IOException (java.io.IOException)3 CreateFile (org.springframework.roo.file.undo.CreateFile)2 DeleteFile (org.springframework.roo.file.undo.DeleteFile)2 UpdateFile (org.springframework.roo.file.undo.UpdateFile)2 MutableFile (org.springframework.roo.process.manager.MutableFile)2 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 WeakHashMap (java.util.WeakHashMap)1 DirectoryMonitoringRequest (org.springframework.roo.file.monitor.DirectoryMonitoringRequest)1 MonitoringRequest (org.springframework.roo.file.monitor.MonitoringRequest)1 CreateDirectory (org.springframework.roo.file.undo.CreateDirectory)1 Pom (org.springframework.roo.project.maven.Pom)1