Search in sources :

Example 1 with TaskStateChange

use of org.gradle.api.internal.changedetection.rules.TaskStateChange in project gradle by gradle.

the class OrderSensitiveTaskFilePropertyCompareStrategy method iterateContentChangesSince.

@Override
public Iterator<TaskStateChange> iterateContentChangesSince(Map<String, NormalizedFileSnapshot> current, Map<String, NormalizedFileSnapshot> previous, final String fileType, boolean isPathAbsolute) {
    final Iterator<Map.Entry<String, NormalizedFileSnapshot>> currentEntries = current.entrySet().iterator();
    final Iterator<Map.Entry<String, NormalizedFileSnapshot>> previousEntries = previous.entrySet().iterator();
    return new AbstractIterator<TaskStateChange>() {

        private TaskStateChange remaining;

        @Override
        protected TaskStateChange computeNext() {
            if (remaining != null) {
                TaskStateChange next = this.remaining;
                remaining = null;
                return next;
            }
            while (true) {
                if (currentEntries.hasNext()) {
                    Map.Entry<String, NormalizedFileSnapshot> current = currentEntries.next();
                    String absolutePath = current.getKey();
                    if (previousEntries.hasNext()) {
                        Map.Entry<String, NormalizedFileSnapshot> other = previousEntries.next();
                        NormalizedFileSnapshot normalizedSnapshot = current.getValue();
                        NormalizedFileSnapshot otherNormalizedSnapshot = other.getValue();
                        String normalizedPath = normalizedSnapshot.getNormalizedPath();
                        String otherNormalizedPath = otherNormalizedSnapshot.getNormalizedPath();
                        if (normalizedPath.equals(otherNormalizedPath)) {
                            if (normalizedSnapshot.getSnapshot().isContentUpToDate(otherNormalizedSnapshot.getSnapshot())) {
                                continue;
                            } else {
                                return new FileChange(absolutePath, ChangeType.MODIFIED, fileType);
                            }
                        } else {
                            String otherAbsolutePath = other.getKey();
                            remaining = new FileChange(absolutePath, ChangeType.ADDED, fileType);
                            return new FileChange(otherAbsolutePath, ChangeType.REMOVED, fileType);
                        }
                    } else {
                        return new FileChange(absolutePath, ChangeType.ADDED, fileType);
                    }
                } else {
                    if (previousEntries.hasNext()) {
                        return new FileChange(previousEntries.next().getKey(), ChangeType.REMOVED, fileType);
                    } else {
                        return endOfData();
                    }
                }
            }
        }
    };
}
Also used : TaskStateChange(org.gradle.api.internal.changedetection.rules.TaskStateChange) FileChange(org.gradle.api.internal.changedetection.rules.FileChange) AbstractIterator(com.google.common.collect.AbstractIterator) Map(java.util.Map)

Aggregations

AbstractIterator (com.google.common.collect.AbstractIterator)1 Map (java.util.Map)1 FileChange (org.gradle.api.internal.changedetection.rules.FileChange)1 TaskStateChange (org.gradle.api.internal.changedetection.rules.TaskStateChange)1