Skip to content

Commit ac6ced4

Browse files
committed
removed CLEANUP_FIRST - not needed anymore, sandbox repositories are unique per test to avoid test lock-ups on Windows due to locked files (also enables parallel testing)
1 parent 38a94f9 commit ac6ced4

10 files changed

+79
-106
lines changed

src/test/java/pl/project13/jgit/DescribeCommandAbbrevIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.jetbrains.annotations.NotNull;
2323
import org.junit.Test;
2424
import pl.project13.maven.git.AvailableGitTestRepo;
25-
import pl.project13.maven.git.FileSystemMavenSandbox;
2625
import pl.project13.maven.git.GitIntegrationTest;
2726

2827
import static org.fest.assertions.Assertions.assertThat;
@@ -63,7 +62,7 @@ public void shouldGiveTheCommitIdAndDirtyMarkerWhenNothingElseCanBeFound() throw
6362
.withParentProject(PROJECT_NAME, "jar")
6463
.withNoChildProject()
6564
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
66-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
65+
.create();
6766

6867
Repository repo = git().getRepository();
6968

@@ -88,7 +87,7 @@ public void onGitCommitIdsRepo_shouldNoticeThat2CharsIsTooLittleToBeUniqueAndUse
8887
.withParentProject(PROJECT_NAME, "jar")
8988
.withNoChildProject()
9089
.withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
91-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
90+
.create();
9291

9392
Repository repo = git().getRepository();
9493

src/test/java/pl/project13/jgit/DescribeCommandIntegrationTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.jetbrains.annotations.NotNull;
2828
import org.junit.Test;
2929
import pl.project13.maven.git.AvailableGitTestRepo;
30-
import pl.project13.maven.git.FileSystemMavenSandbox;
3130
import pl.project13.maven.git.GitIntegrationTest;
3231

3332
import static java.util.Collections.singletonList;
@@ -54,7 +53,7 @@ public void shouldGiveTheCommitIdAndDirtyMarkerWhenNothingElseCanBeFound() throw
5453
.withParentProject(PROJECT_NAME, "jar")
5554
.withNoChildProject()
5655
.withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT_DIRTY)
57-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
56+
.create();
5857

5958
Repository repo = git().getRepository();
6059

@@ -78,7 +77,7 @@ public void shouldGiveTheCommitIdWhenNothingElseCanBeFound() throws Exception {
7877
.withParentProject(PROJECT_NAME, "jar")
7978
.withNoChildProject()
8079
.withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT)
81-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
80+
.create();
8281

8382
Repository repo = git().getRepository();
8483

@@ -102,7 +101,7 @@ public void shouldGiveTheCommitIdWhenTagIsOnOtherBranch() throws Exception {
102101
.withParentProject(PROJECT_NAME, "jar")
103102
.withNoChildProject()
104103
.withGitRepoInParent(AvailableGitTestRepo.WITH_TAG_ON_DIFFERENT_BRANCH)
105-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
104+
.create();
106105

107106
Repository repo = git().getRepository();
108107

@@ -126,7 +125,7 @@ public void shouldGiveTheCommitIdWhenNothingElseCanBeFoundAndUseAbbrevVersionOfI
126125
.withParentProject(PROJECT_NAME, "jar")
127126
.withNoChildProject()
128127
.withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT)
129-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
128+
.create();
130129

131130
int abbrevLength = 10;
132131
Repository repo = git().getRepository();
@@ -153,7 +152,7 @@ public void shouldGiveTagWithDistanceToCurrentCommitAndItsIdAndDirtyMarker() thr
153152
.withParentProject(PROJECT_NAME, "jar")
154153
.withNoChildProject()
155154
.withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
156-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
155+
.create();
157156

158157
Repository repo = git().getRepository();
159158

@@ -175,7 +174,7 @@ public void shouldGiveTagWithDistanceToCurrentCommitAndItsIdAndCustomDirtyMarker
175174
.withParentProject(PROJECT_NAME, "jar")
176175
.withNoChildProject()
177176
.withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
178-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
177+
.create();
179178

180179
String customDirtySuffix = "-DEV";
181180

@@ -201,7 +200,7 @@ public void shouldGiveTagWithDistanceToCurrentCommitAndItsId() throws Exception
201200
.withParentProject(PROJECT_NAME, "jar")
202201
.withNoChildProject()
203202
.withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID)
204-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
203+
.create();
205204

206205
Repository repo = git().getRepository();
207206
Git.wrap(repo).reset().setMode(ResetCommand.ResetType.HARD).call();
@@ -223,7 +222,7 @@ public void shouldGiveTag() throws Exception {
223222
.withParentProject(PROJECT_NAME, "jar")
224223
.withNoChildProject()
225224
.withGitRepoInParent(AvailableGitTestRepo.ON_A_TAG)
226-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
225+
.create();
227226

228227
Repository repo = git().getRepository();
229228
git().reset().setMode(ResetCommand.ResetType.HARD).call();
@@ -248,7 +247,7 @@ public void shouldNotGiveDirtyMarkerWhenOnATagAndDirtyButNoDirtyOptionConfigured
248247
.withParentProject(PROJECT_NAME, "jar")
249248
.withNoChildProject()
250249
.withGitRepoInParent(AvailableGitTestRepo.ON_A_TAG)
251-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
250+
.create();
252251

253252
Repository repo = git().getRepository();
254253
git().checkout().setName("v1.0.0").call();
@@ -275,7 +274,7 @@ public void shouldGiveTagWithCustomDirtyMarker() throws Exception {
275274
.withParentProject(PROJECT_NAME, "jar")
276275
.withNoChildProject()
277276
.withGitRepoInParent(AvailableGitTestRepo.ON_A_TAG)
278-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
277+
.create();
279278

280279
Repository repo = git().getRepository();
281280
git().checkout().setName("v1.0.0").call();
@@ -301,7 +300,7 @@ public void shouldNotGiveDirtyTagByDefault() throws Exception {
301300
.withParentProject(PROJECT_NAME, "jar")
302301
.withNoChildProject()
303302
.withGitRepoInParent(AvailableGitTestRepo.ON_A_TAG)
304-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
303+
.create();
305304

306305
Repository repo = git().getRepository();
307306

@@ -323,7 +322,7 @@ public void shouldGiveAnnotatedTagWithDirtyMarker() throws Exception {
323322
.withParentProject(PROJECT_NAME, "jar")
324323
.withNoChildProject()
325324
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
326-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
325+
.create();
327326

328327
Repository repo = git().getRepository();
329328

@@ -348,7 +347,7 @@ public void shouldGiveLightweightTagWithDirtyMarker() throws Exception {
348347
.withParentProject(PROJECT_NAME, "jar")
349348
.withNoChildProject()
350349
.withGitRepoInParent(AvailableGitTestRepo.ON_A_TAG_DIRTY)
351-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
350+
.create();
352351

353352
Repository repo = git().getRepository();
354353

@@ -407,7 +406,7 @@ public void shouldReturnJustTheNearestTagWhenAbbrevIsZero() throws Exception {
407406
.withParentProject(PROJECT_NAME, "jar")
408407
.withNoChildProject()
409408
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
410-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
409+
.create();
411410

412411
Repository repo = git().getRepository();
413412
Git.wrap(repo).reset().setMode(ResetCommand.ResetType.HARD).call();

src/test/java/pl/project13/jgit/DescribeCommandTagsIntegrationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.Before;
2525
import org.junit.Test;
2626
import pl.project13.maven.git.AvailableGitTestRepo;
27-
import pl.project13.maven.git.FileSystemMavenSandbox;
2827
import pl.project13.maven.git.GitIntegrationTest;
2928

3029
import static org.fest.assertions.Assertions.assertThat;
@@ -42,7 +41,7 @@ public void setUp() throws Exception {
4241
.withParentProject(PROJECT_NAME, "jar")
4342
.withNoChildProject()
4443
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
45-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
44+
.create();
4645
}
4746

4847
@Override
@@ -163,7 +162,7 @@ public void shouldUseTheNewestTagOnACommitIfItHasMoreThanOneTags() throws Except
163162
.withParentProject(PROJECT_NAME, "jar")
164163
.withNoChildProject()
165164
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
166-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
165+
.create();
167166

168167
String snapshotTag = "0.0.1-SNAPSHOT";
169168
String latestTag = "OName-0.0.1";
@@ -194,7 +193,7 @@ public void shouldUseTheNewestTagOnACommitIfItHasMoreThanOneTagsReversedCase() t
194193
.withParentProject(PROJECT_NAME, "jar")
195194
.withNoChildProject()
196195
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
197-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
196+
.create();
198197

199198
String beforeTag = "OName-0.0.1";
200199
String latestTag = "0.0.1-SNAPSHOT";

src/test/java/pl/project13/jgit/DescribeResultTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.Before;
2525
import org.junit.Test;
2626
import pl.project13.maven.git.AvailableGitTestRepo;
27-
import pl.project13.maven.git.FileSystemMavenSandbox;
2827
import pl.project13.maven.git.GitIntegrationTest;
2928

3029
import static org.fest.assertions.Assertions.assertThat;
@@ -49,7 +48,7 @@ public void setUp() throws Exception {
4948
.withParentProject(PROJECT_NAME, "jar")
5049
.withNoChildProject()
5150
.withGitRepoInParent(AvailableGitTestRepo.WITH_LIGHTWEIGHT_TAG_BEFORE_ANNOTATED_TAG)
52-
.create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST);
51+
.create();
5352
}
5453

5554
@Override

src/test/java/pl/project13/maven/git/FileSystemMavenSandbox.java

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@
2828
import com.google.common.io.Files;
2929

3030
/**
31-
* Quick and dirty maven projects tree structure to create on disk during integration tests
32-
* Can have both parent and child projects set up
33-
* Copies sample git repository from prototype location to newly created project
34-
* Has ability to set target project for storing git repository
35-
*
31+
* Quick and dirty maven projects tree structure to create on disk during integration tests.
32+
* Can have both parent and child projects set up.
33+
* Copies sample git repository from prototype location to newly created project.
34+
* Has ability to set target project for storing git repository.
3635
*/
3736
public class FileSystemMavenSandbox {
3837

39-
private static final String FILE_SEPARATOR = System.getProperty("file.separator");
40-
4138
private MavenProject childProject;
4239
private String rootSandboxPath;
4340
private MavenProject parentProject;
@@ -57,7 +54,7 @@ public FileSystemMavenSandbox(String rootSandboxPath) {
5754

5855
@NotNull
5956
public FileSystemMavenSandbox withParentProject(String parentProjectDirName, String packaging) {
60-
parentProject = createProject(new File(rootSandboxPath + FILE_SEPARATOR + parentProjectDirName), packaging);
57+
parentProject = createProject(new File(rootSandboxPath + File.separator + parentProjectDirName), packaging);
6158
return this;
6259
}
6360

@@ -104,9 +101,8 @@ public FileSystemMavenSandbox withNoGitRepoAvailable() {
104101
}
105102

106103
@NotNull
107-
public FileSystemMavenSandbox create(CleanUp cleanupMode) throws RuntimeException {
104+
public FileSystemMavenSandbox create() throws RuntimeException {
108105
try {
109-
cleanupIfRequired(cleanupMode);
110106
createParentDir();
111107
createChildDirIfRequired();
112108
createGitRepoIfRequired();
@@ -140,23 +136,6 @@ private void createChildDirIfRequired() throws IOException {
140136
}
141137
}
142138

143-
private void cleanupIfRequired(CleanUp cleanupMode) throws IOException {
144-
if (CleanUp.CLEANUP_FIRST == cleanupMode) {
145-
cleanup();
146-
}
147-
}
148-
149-
public void cleanup() {
150-
try {
151-
final File sandbox = new File(rootSandboxPath);
152-
if (sandbox.exists()) {
153-
FileUtils.deleteDirectory(sandbox);
154-
}
155-
} catch (IOException e) {
156-
System.out.println("Unable to delete the directory: " + rootSandboxPath);
157-
}
158-
}
159-
160139
public MavenProject getParentProject() {
161140
return parentProject;
162141
}
@@ -165,21 +144,14 @@ public MavenProject getChildProject() {
165144
return childProject;
166145
}
167146

168-
public File getSandboxDir() { return gitRepoTargetDir.getAbsoluteFile(); }
169-
170147
@NotNull
171148
private MavenProject createProject(File basedir, String packaging) {
172149
MavenProject project = new MavenProject();
173-
project.setFile(new File(basedir + FILE_SEPARATOR + "pom.xml"));
150+
project.setFile(new File(basedir + File.separator + "pom.xml"));
174151
project.setPackaging(packaging);
175152
return project;
176153
}
177154

178-
public static enum CleanUp {
179-
CLEANUP_FIRST,
180-
NO_CLEANUP
181-
}
182-
183155
@Override
184156
public String toString() {
185157
return "FileSystemMavenSandbox{" +
@@ -188,4 +160,4 @@ public String toString() {
188160
", rootSandboxPath='" + rootSandboxPath + '\'' +
189161
'}';
190162
}
191-
}
163+
}

0 commit comments

Comments
 (0)