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