2 * Copyright (C) 2006 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.lib
;
20 import java
.io
.FileOutputStream
;
21 import java
.io
.IOException
;
23 import org
.spearce
.jgit
.errors
.IncorrectObjectTypeException
;
24 import org
.spearce
.jgit
.errors
.MissingObjectException
;
26 public class CheckoutTree
extends TreeVisitorWithCurrentDirectory
{
27 private static final String TYPE_BLOB
= Constants
.TYPE_BLOB
;
29 public CheckoutTree(final File root
) {
33 public void visitFile(final FileTreeEntry fte
) throws IOException
{
34 final File destFile
= new File(getCurrentDirectory(), fte
.getName());
35 final ObjectLoader loader
= fte
.openReader();
37 throw new MissingObjectException(fte
.getId(), TYPE_BLOB
);
38 final byte[] data
= loader
.getBytes();
39 if (!TYPE_BLOB
.equals(loader
.getType()))
40 throw new IncorrectObjectTypeException(fte
.getId(), TYPE_BLOB
);
41 final FileOutputStream fos
= new FileOutputStream(destFile
);
49 public void visitSymlink(final SymlinkTreeEntry s
) throws IOException
{
50 // TODO: handle symlinks. Only problem is that JGit is indepent of Eclipse
51 // and Pure Java does not know what to do about symbolic links.
54 public void startVisitTree(final Tree t
) throws IOException
{
55 super.startVisitTree(t
);
56 getCurrentDirectory().mkdirs();