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
;
24 * Java IO file tree iterator that can adapt to a {@link ContainerTreeIterator}
26 * The iterator automatically adapts to a {@link ContainerTreeIterator} when
27 * recursing into directories that are accessible from the given workspace root.
29 * @see org.eclipse.jgit.treewalk.FileTreeIterator
30 * @see org.eclipse.egit.core.ContainerTreeIterator
32 public class AdaptableFileTreeIterator
extends FileTreeIterator
{
37 * Create a new iterator to traverse the given directory and its children
39 * The iterator will automatically adapt to a {@link ContainerTreeIterator}
40 * when encountering directories what can be mapped into the given workspace
44 * the starting directory. This directory should correspond to
45 * the repository root.
46 * @param workspaceRoot
47 * the workspace root to check resource mapping against.
50 public AdaptableFileTreeIterator(final File path
,
51 final IWorkspaceRoot workspaceRoot
) {
57 * Create a new iterator to traverse a subdirectory.
59 * The iterator will automatically adapt to a {@link ContainerTreeIterator}
60 * when encountering directories what can be mapped into the given workspace
64 * the subdirectory. This should be a directory contained within
65 * the parent directory.
67 * the parent iterator we were created from.
68 * @param workspaceRoot
69 * the workspace root to check resource mapping against.
71 protected AdaptableFileTreeIterator(final AdaptableFileTreeIterator parent
,
72 File path
, final IWorkspaceRoot workspaceRoot
) {
78 public AbstractTreeIterator
createSubtreeIterator(Repository repo
)
79 throws IncorrectObjectTypeException
, IOException
{
80 final File currentFile
= ((FileEntry
) current()).getFile();
81 final IContainer
[] containers
= root
.findContainersForLocation(new Path(
82 currentFile
.getAbsolutePath()));
83 if (containers
.length
> 0)
84 return new ContainerTreeIterator(this, containers
[0]);
86 return new AdaptableFileTreeIterator(this, currentFile
, root
);