1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.cloud.contract.maven.verifier;
18
19 import java.io.File;
20
21 import org.apache.maven.execution.MavenSession;
22 import org.apache.maven.plugin.MojoExecution;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.shared.incremental.IncrementalBuildHelper;
25 import org.apache.maven.shared.incremental.IncrementalBuildHelperRequest;
26
27
28
29
30
31
32
33
34
35
36
37
38 class LeftOverPrevention {
39
40 private final IncrementalBuildHelper incrementalBuildHelper;
41
42 private final File generatedDirectory;
43
44 LeftOverPrevention(File generatedDirectory, MojoExecution mojoExecution, MavenSession session)
45 throws MojoExecutionException {
46 this.generatedDirectory = generatedDirectory;
47 this.incrementalBuildHelper = new IncrementalBuildHelper(mojoExecution, session);
48 this.incrementalBuildHelper
49 .beforeRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
50 }
51
52 void deleteLeftOvers() throws MojoExecutionException {
53 if (generatedDirectory.exists()) {
54 incrementalBuildHelper
55 .afterRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
56 }
57 }
58
59 }