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,24 @@ 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
+ return getTestResource (resourceFile )
82
+ .replace ("${executor}" , "./" + executorWrapperFile ().getName ())
83
+ .replace ("${checkCommand}" , "spotless:check" )
84
+ .replace ("${applyCommand}" , "spotless:apply" );
85
+ }
86
+
87
+ private File executorWrapperFile () {
88
+ if (System .getProperty ("os.name" ).toLowerCase (Locale .ROOT ).startsWith ("win" )) {
89
+ final var bat = newFile ("mvnw.bat" );
90
+ if (bat .exists ()) {
91
+ return bat ;
92
+ }
93
+
94
+ return newFile ("mvnw.cmd" );
95
+ }
96
+
97
+ return newFile ("mvnw" );
98
+ }
83
99
}
0 commit comments