17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
19
20
+ import java .io .File ;
20
21
import java .io .IOException ;
22
+ import java .util .Locale ;
21
23
22
24
import org .junit .jupiter .api .Test ;
23
25
@@ -41,11 +43,8 @@ public void should_create_pre_hook_file_when_hook_file_does_not_exists() throws
41
43
assertThat (output ).contains ("Git pre-push hook not found, creating it" );
42
44
assertThat (output ).contains ("Git pre-push hook installed successfully to the file " + newFile (".git/hooks/pre-push" ));
43
45
44
- final var content = getTestResource ("git_pre_hook/pre-push.created-tpl" )
45
- .replace ("${executor}" , newFile ("mvnw" ).getAbsolutePath ())
46
- .replace ("${checkCommand}" , "spotless:check" )
47
- .replace ("${applyCommand}" , "spotless:apply" );
48
- assertFile (".git/hooks/pre-push" ).hasContent (content );
46
+ final var hookContent = getHookContent ("git_pre_hook/pre-push.created-tpl" );
47
+ assertFile (".git/hooks/pre-push" ).hasContent (hookContent );
49
48
}
50
49
51
50
@ Test
@@ -67,11 +66,8 @@ public void should_append_to_existing_pre_hook_file_when_hook_file_exists() thro
67
66
assertThat (output ).contains ("Installing git pre-push hook" );
68
67
assertThat (output ).contains ("Git pre-push hook installed successfully to the file " + newFile (".git/hooks/pre-push" ));
69
68
70
- final var content = getTestResource ("git_pre_hook/pre-push.existing-installed-end-tpl" )
71
- .replace ("${executor}" , newFile ("mvnw" ).getAbsolutePath ())
72
- .replace ("${checkCommand}" , "spotless:check" )
73
- .replace ("${applyCommand}" , "spotless:apply" );
74
- assertFile (".git/hooks/pre-push" ).hasContent (content );
69
+ final var hookContent = getHookContent ("git_pre_hook/pre-push.existing-installed-end-tpl" );
70
+ assertFile (".git/hooks/pre-push" ).hasContent (hookContent );
75
71
}
76
72
77
73
private void writePomWithJavaLicenseHeaderStep () throws IOException {
@@ -80,4 +76,26 @@ private void writePomWithJavaLicenseHeaderStep() throws IOException {
80
76
" <file>${basedir}/license.txt</file>" ,
81
77
"</licenseHeader>" );
82
78
}
79
+
80
+ private String getHookContent (String resourceFile ) {
81
+ final var executorFile = executorWrapperFile ();
82
+ final var executorPath = executorFile .exists () ? executorFile .getName () : "mvn" ;
83
+ return getTestResource (resourceFile )
84
+ .replace ("${executor}" , "./" + executorPath )
85
+ .replace ("${checkCommand}" , "spotless:check" )
86
+ .replace ("${applyCommand}" , "spotless:apply" );
87
+ }
88
+
89
+ private File executorWrapperFile () {
90
+ if (System .getProperty ("os.name" ).toLowerCase (Locale .ROOT ).startsWith ("win" )) {
91
+ final var bat = newFile ("mvnw.bat" );
92
+ if (bat .exists ()) {
93
+ return bat ;
94
+ }
95
+
96
+ return newFile ("mvnw.cmd" );
97
+ }
98
+
99
+ return newFile ("mvnw" );
100
+ }
83
101
}
0 commit comments