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.utils.io.DirectoryScanner;
26
27 final class ChangeDetector {
28
29 private ChangeDetector() {
30 }
31
32 static boolean inputFilesChangeDetected(File contractsDirectory, MojoExecution mojoExecution, MavenSession session)
33 throws MojoExecutionException {
34 if (session.getGoals().contains("clean")) {
35 return true;
36 }
37 IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper(mojoExecution, session);
38
39 DirectoryScanner scanner = incrementalBuildHelper.getDirectoryScanner();
40 scanner.setBasedir(contractsDirectory);
41 scanner.scan();
42 boolean changeDetected = incrementalBuildHelper.inputFileTreeChanged(scanner);
43 if (scanner.getIncludedFiles().length == 0) {
44
45
46 return true;
47 }
48 return changeDetected;
49 }
50
51 }