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 * See LICENSE for the full license text, also available.
7 *******************************************************************************/
9 package org
.spearce
.egit
.core
;
12 import java
.io
.IOException
;
14 import org
.eclipse
.core
.resources
.IContainer
;
15 import org
.eclipse
.core
.resources
.IWorkspaceRoot
;
16 import org
.eclipse
.core
.runtime
.Path
;
17 import org
.spearce
.jgit
.errors
.IncorrectObjectTypeException
;
18 import org
.spearce
.jgit
.lib
.Repository
;
19 import org
.spearce
.jgit
.treewalk
.AbstractTreeIterator
;
20 import org
.spearce
.jgit
.treewalk
.FileTreeIterator
;
23 * Java IO file tree iterator that can adapt to a {@link ContainerTreeIterator}
25 * The iterator automatically adapts to a {@link ContainerTreeIterator} when
26 * recursing into directories that are accessible from the given workspace root.
28 * @see org.spearce.jgit.treewalk.FileTreeIterator
29 * @see org.spearce.egit.core.ContainerTreeIterator
31 public class AdaptableFileTreeIterator
extends FileTreeIterator
{
36 * Create a new iterator to traverse the given directory and its children
38 * The iterator will automatically adapt to a {@link ContainerTreeIterator}
39 * when encountering directories what can be mapped into the given workspace
43 * the starting directory. This directory should correspond to
44 * the repository root.
45 * @param workspaceRoot
46 * the workspace root to check resource mapping against.
49 public AdaptableFileTreeIterator(final File path
,
50 final IWorkspaceRoot workspaceRoot
) {
56 * Create a new iterator to traverse a subdirectory.
58 * The iterator will automatically adapt to a {@link ContainerTreeIterator}
59 * when encountering directories what can be mapped into the given workspace
63 * the subdirectory. This should be a directory contained within
64 * the parent directory.
66 * the parent iterator we were created from.
67 * @param workspaceRoot
68 * the workspace root to check resource mapping against.
70 protected AdaptableFileTreeIterator(final AdaptableFileTreeIterator parent
,
71 File path
, final IWorkspaceRoot workspaceRoot
) {
77 public AbstractTreeIterator
createSubtreeIterator(Repository repo
)
78 throws IncorrectObjectTypeException
, IOException
{
79 final File currentFile
= ((FileEntry
) current()).getFile();
80 final IContainer
[] containers
= root
.findContainersForLocation(new Path(
81 currentFile
.getAbsolutePath()));
82 if (containers
.length
> 0)
83 return new ContainerTreeIterator(this, containers
[0]);
85 return new AdaptableFileTreeIterator(this, currentFile
, root
);