Search in sources :

Example 6 with FileDetails

use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.

the class PollingFileMonitorService method remove.

public boolean remove(final MonitoringRequest request) {
    synchronized (lock) {
        Validate.notNull(request, "MonitoringRequest required");
        // Advise of the cessation to monitoring
        if (priorExecution.containsKey(request)) {
            final List<FileEvent> eventsToPublish = new ArrayList<FileEvent>();
            final Map<File, Long> priorFiles = priorExecution.get(request);
            for (final Entry<File, Long> entry : priorFiles.entrySet()) {
                final File thisFile = entry.getKey();
                final Long lastModified = entry.getValue();
                eventsToPublish.add(new FileEvent(new FileDetails(thisFile, lastModified), FileOperation.MONITORING_FINISH, null));
            }
            publish(eventsToPublish);
        }
        priorExecution.remove(request);
        return requests.remove(request);
    }
}
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 7 with FileDetails

use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.

the class ApplicationConfigServiceImpl method getApplicationProfiles.

@Override
public List<String> getApplicationProfiles(String moduleName) {
    List<String> profiles = new ArrayList<String>();
    final String applicationConfigFilename = StringUtils.removeEnd(getSpringConfigLocation(moduleName), DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION);
    // Find application config files
    for (final FileDetails applicationConfig : fileManager.findMatchingAntPath(applicationConfigFilename + "*" + DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION)) {
        final String applicationConfigPath = applicationConfig.getCanonicalPath();
        if (!fileManager.exists(applicationConfigPath)) {
            continue;
        }
        // Extract profile
        String profile = StringUtils.substringBetween(applicationConfigPath, applicationConfigFilename, ".properties");
        profiles.add(StringUtils.removeStart(profile, "-"));
    }
    return profiles;
}
Also used : ArrayList(java.util.ArrayList) FileDetails(org.springframework.roo.file.monitor.event.FileDetails)

Example 8 with FileDetails

use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.

the class DefaultFileManager method createDirectory.

public FileDetails createDirectory(final String fileIdentifier) {
    if (fileMonitorService == null) {
        fileMonitorService = getFileMonitorService();
    }
    if (filenameResolver == null) {
        filenameResolver = getFileNameResolver();
    }
    if (undoManager == null) {
        undoManager = getUndoManager();
    }
    Validate.notNull(fileIdentifier, "File identifier required");
    Validate.notNull(fileMonitorService, "FileMonitorService required");
    Validate.notNull(filenameResolver, "FilenameResolver required");
    Validate.notNull(undoManager, "UndoManager required");
    final File actual = new File(fileIdentifier);
    Validate.isTrue(!actual.exists(), "File '%s' already exists", fileIdentifier);
    try {
        fileMonitorService.notifyCreated(actual.getCanonicalPath());
    } catch (final IOException ignored) {
    }
    new CreateDirectory(undoManager, filenameResolver, actual);
    return new FileDetails(actual, actual.lastModified());
}
Also used : FileDetails(org.springframework.roo.file.monitor.event.FileDetails) IOException(java.io.IOException) 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) CreateDirectory(org.springframework.roo.file.undo.CreateDirectory)

Example 9 with FileDetails

use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.

the class AbstractPathResolvingStrategy method getRelativeSegment.

public String getRelativeSegment(final String identifier) {
    final PhysicalPath parent = getApplicablePhysicalPath(identifier);
    if (parent == null) {
        return null;
    }
    final FileDetails parentFile = new FileDetails(parent.getLocation(), null);
    return parentFile.getRelativeSegment(identifier);
}
Also used : FileDetails(org.springframework.roo.file.monitor.event.FileDetails)

Example 10 with FileDetails

use of org.springframework.roo.file.monitor.event.FileDetails in project spring-roo by spring-projects.

the class MavenPathResolvingStrategy method getApplicablePhysicalPath.

/**
 * Locates the first {@link PhysicalPath} which can be construed as a parent
 * of the presented identifier.
 *
 * @param identifier to locate the parent of (required)
 * @return the first matching parent, or null if not found
 */
@Override
protected PhysicalPath getApplicablePhysicalPath(final String identifier) {
    Validate.notNull(identifier, "Identifier required");
    PhysicalPath physicalPath = null;
    int longest = 0;
    for (final Pom pom : pomManagementService.getPoms()) {
        if (removeTrailingSeparator(identifier).startsWith(removeTrailingSeparator(pom.getRoot())) && removeTrailingSeparator(pom.getRoot()).length() > longest) {
            longest = removeTrailingSeparator(pom.getRoot()).length();
            int nextLongest = 0;
            for (final PhysicalPath thisPhysicalPath : pom.getPhysicalPaths()) {
                String possibleParent = new FileDetails(thisPhysicalPath.getLocation(), null).getCanonicalPath();
                if (!possibleParent.endsWith(File.separator)) {
                    possibleParent = possibleParent.concat(File.separator);
                }
                if (removeTrailingSeparator(identifier).startsWith(possibleParent) && possibleParent.length() > nextLongest) {
                    nextLongest = possibleParent.length();
                    physicalPath = thisPhysicalPath;
                }
            }
        }
    }
    return physicalPath;
}
Also used : FileDetails(org.springframework.roo.file.monitor.event.FileDetails) Pom(org.springframework.roo.project.maven.Pom)

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