blob: 3fbab868a85434b00704e45889ae9807b22e2347 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*******************************************************************************
* Copyright (C) 2009, Tor Arne Vestbø <torarnv@gmail.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.core;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.Path;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.FileTreeIterator;
/**
* Java IO file tree iterator that can adapt to a {@link ContainerTreeIterator}
* <p>
* The iterator automatically adapts to a {@link ContainerTreeIterator} when
* recursing into directories that are accessible from the given workspace root.
*
* @see org.eclipse.jgit.treewalk.FileTreeIterator
* @see org.eclipse.egit.core.ContainerTreeIterator
*/
public class AdaptableFileTreeIterator extends FileTreeIterator {
IWorkspaceRoot root;
/**
* Create a new iterator to traverse the given directory and its children
* <p>
* The iterator will automatically adapt to a {@link ContainerTreeIterator}
* when encountering directories what can be mapped into the given workspace
* root.
*
* @param path
* the starting directory. This directory should correspond to
* the repository root.
* @param workspaceRoot
* the workspace root to check resource mapping against.
*
*/
public AdaptableFileTreeIterator(final File path,
final IWorkspaceRoot workspaceRoot) {
super(path);
root = workspaceRoot;
}
/**
* Create a new iterator to traverse a subdirectory.
* <p>
* The iterator will automatically adapt to a {@link ContainerTreeIterator}
* when encountering directories what can be mapped into the given workspace
* root.
*
* @param path
* the subdirectory. This should be a directory contained within
* the parent directory.
* @param parent
* the parent iterator we were created from.
* @param workspaceRoot
* the workspace root to check resource mapping against.
*/
protected AdaptableFileTreeIterator(final AdaptableFileTreeIterator parent,
File path, final IWorkspaceRoot workspaceRoot) {
super(parent, path);
root = workspaceRoot;
}
@Override
public AbstractTreeIterator createSubtreeIterator(Repository repo)
throws IncorrectObjectTypeException, IOException {
final File currentFile = ((FileEntry) current()).getFile();
final IContainer[] containers = root.findContainersForLocation(new Path(
currentFile.getAbsolutePath()));
if (containers.length > 0)
return new ContainerTreeIterator(this, containers[0]);
else
return new AdaptableFileTreeIterator(this, currentFile, root);
}
}
|