Added
Link Here
|
1 |
/* |
2 |
* Copyright (C) 2009-2010, Google Inc. |
3 |
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> |
4 |
* Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org> |
5 |
* and other copyright owners as documented in the project's IP log. |
6 |
* |
7 |
* This class was originally copied from |
8 |
* org.eclipse.jgit.junit.LocalDiskRepositoryTest |
9 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=378047 |
10 |
* |
11 |
* This program and the accompanying materials are made available |
12 |
* under the terms of the Eclipse Distribution License v1.0 which |
13 |
* accompanies this distribution, is reproduced below, and is |
14 |
* available at http://www.eclipse.org/org/documents/edl-v10.php |
15 |
* |
16 |
* All rights reserved. |
17 |
* |
18 |
* Redistribution and use in source and binary forms, with or |
19 |
* without modification, are permitted provided that the following |
20 |
* conditions are met: |
21 |
* |
22 |
* - Redistributions of source code must retain the above copyright |
23 |
* notice, this list of conditions and the following disclaimer. |
24 |
* |
25 |
* - Redistributions in binary form must reproduce the above |
26 |
* copyright notice, this list of conditions and the following |
27 |
* disclaimer in the documentation and/or other materials provided |
28 |
* with the distribution. |
29 |
* |
30 |
* - Neither the name of the Eclipse Foundation, Inc. nor the |
31 |
* names of its contributors may be used to endorse or promote |
32 |
* products derived from this software without specific prior |
33 |
* written permission. |
34 |
* |
35 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
36 |
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
37 |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
38 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
39 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
40 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
41 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
42 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
43 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
44 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
45 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
46 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
47 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
48 |
*/ |
49 |
package org.eclipse.releng.tests; |
50 |
|
51 |
import java.io.File; |
52 |
import java.io.IOException; |
53 |
import java.util.ArrayList; |
54 |
import java.util.Iterator; |
55 |
import java.util.List; |
56 |
|
57 |
import junit.framework.TestCase; |
58 |
|
59 |
import org.eclipse.jgit.internal.storage.file.FileRepository; |
60 |
import org.eclipse.jgit.lib.Constants; |
61 |
import org.eclipse.jgit.lib.PersonIdent; |
62 |
import org.eclipse.jgit.lib.Repository; |
63 |
import org.eclipse.jgit.lib.RepositoryCache; |
64 |
import org.junit.Assert; |
65 |
|
66 |
/** |
67 |
* This class is a modified version of org.eclipse.jgit.junit.LocalDiskRepositoryTestCase |
68 |
* |
69 |
*/ |
70 |
public class LocalDiskRepositoryTest extends TestCase { |
71 |
private static int testCount; |
72 |
protected PersonIdent committer; |
73 |
private final File trash = new File(new File("target"), "trash"); |
74 |
private final List toClose = new ArrayList(); |
75 |
|
76 |
protected void setUp() throws Exception { |
77 |
committer = new PersonIdent("J. Committer", "jcommitter@example.com"); |
78 |
} |
79 |
|
80 |
protected void tearDown() throws Exception { |
81 |
RepositoryCache.clear(); |
82 |
for (Iterator it = toClose.iterator(); it.hasNext();) { |
83 |
Repository r = (Repository) it.next(); |
84 |
r.close(); |
85 |
} |
86 |
toClose.clear(); |
87 |
} |
88 |
|
89 |
/** |
90 |
* Creates a new empty repository within a new empty working directory. |
91 |
* |
92 |
* @return the newly created repository, opened for access |
93 |
* @throws IOException |
94 |
* the repository could not be created in the temporary area |
95 |
*/ |
96 |
protected Repository createWorkRepository() throws IOException { |
97 |
return createRepository(false /* not bare */); |
98 |
} |
99 |
|
100 |
/** |
101 |
* Creates a new empty repository. |
102 |
* |
103 |
* @param bare |
104 |
* true to create a bare repository; false to make a repository |
105 |
* within its working directory |
106 |
* @return the newly created repository, opened for access |
107 |
* @throws IOException |
108 |
* the repository could not be created in the temporary area |
109 |
*/ |
110 |
private Repository createRepository(boolean bare) throws IOException { |
111 |
File gitdir = createUniqueTestGitDir(bare); |
112 |
Repository db = new FileRepository(gitdir); |
113 |
Assert.assertFalse(gitdir.exists()); |
114 |
db.create(); |
115 |
toClose.add(db); |
116 |
return db; |
117 |
} |
118 |
|
119 |
/** |
120 |
* Creates a new unique directory for a test repository |
121 |
* |
122 |
* @param bare |
123 |
* true for a bare repository; false for a repository with a |
124 |
* working directory |
125 |
* @return a unique directory for a test repository |
126 |
* @throws IOException |
127 |
*/ |
128 |
protected File createUniqueTestGitDir(boolean bare) throws IOException { |
129 |
String gitdirName = createUniqueTestFolderPrefix(); |
130 |
if (!bare) |
131 |
gitdirName += "/"; |
132 |
gitdirName += Constants.DOT_GIT; |
133 |
File gitdir = new File(trash, gitdirName); |
134 |
return gitdir.getCanonicalFile(); |
135 |
} |
136 |
|
137 |
private String createUniqueTestFolderPrefix() { |
138 |
return "test" + (System.currentTimeMillis() + "_" + (testCount++)); |
139 |
} |
140 |
} |