23
23
import org .junit .Test ;
24
24
25
25
public class BlowdryerPluginTest extends GradleHarness {
26
+
27
+ private static final String SETTINGS_GRADLE = "settings.gradle" ;
28
+ private static final String BUILD_GRADLE = "build.gradle" ;
29
+
26
30
private void settingsGithub (String tag , String ... extra ) throws IOException {
27
- write ("settings.gradle" ,
31
+ write (SETTINGS_GRADLE ,
28
32
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
29
33
"blowdryerSetup { github('diffplug/blowdryer', 'tag', '" + tag + "') }" ,
30
34
Arrays .stream (extra ).collect (Collectors .joining ("\n " )));
31
35
}
32
36
33
37
private void settingsGitlab (String tag , String ... extra ) throws IOException {
34
- write ("settings.gradle" ,
38
+ write (SETTINGS_GRADLE ,
35
39
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
36
40
"blowdryerSetup { gitlab('diffplug/blowdryer', 'tag', '" + tag + "') }" ,
37
41
Arrays .stream (extra ).collect (Collectors .joining ("\n " )));
38
42
}
39
43
40
44
private void settingsCustomGitlab (String tag , String ... extra ) throws IOException {
41
- write ("settings.gradle" ,
45
+ write (SETTINGS_GRADLE ,
42
46
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
43
47
"blowdryerSetup { gitlab('diffplug/blowdryer', 'tag', '" + tag + "').customDomainHttps('gitlab.com') }" ,
44
48
Arrays .stream (extra ).collect (Collectors .joining ("\n " )));
45
49
}
46
50
47
51
private void settingsGitlabRootFolder (String tag , String ... extra ) throws IOException {
48
- write ("settings.gradle" ,
52
+ write (SETTINGS_GRADLE ,
49
53
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
50
54
"blowdryerSetup { repoSubfolder(''); gitlab('diffplug/blowdryer', 'tag', '" + tag + "') }" ,
51
55
Arrays .stream (extra ).collect (Collectors .joining ("\n " )));
52
56
}
53
57
58
+ private void settingsLocalJar (String dependency ) throws IOException {
59
+ write (SETTINGS_GRADLE ,
60
+ "plugins { id 'com.diffplug.blowdryerSetup' }" ,
61
+ "blowdryerSetup { localJar(file('" + dependency + "')) }" );
62
+ }
63
+
54
64
@ Test
55
65
public void githubTag () throws IOException {
56
66
settingsGithub ("test/2/a" );
57
- write ("build.gradle" ,
67
+ write (BUILD_GRADLE ,
58
68
"apply plugin: 'com.diffplug.blowdryer'" ,
59
69
"assert 干.file('sample').text == 'a'" ,
60
70
"assert 干.prop('sample', 'name') == 'test'" ,
61
71
"assert 干.prop('sample', 'ver_spotless') == '1.2.0'" );
62
72
gradleRunner ().build ();
63
73
64
74
settingsGithub ("test/2/b" );
65
- write ("build.gradle" ,
75
+ write (BUILD_GRADLE ,
66
76
"apply plugin: 'com.diffplug.blowdryer'" ,
67
77
"assert 干.file('sample').text == 'b'" ,
68
78
"assert 干.prop('sample', 'name') == 'testB'" ,
@@ -71,7 +81,7 @@ public void githubTag() throws IOException {
71
81
72
82
// double-check that failures do fail
73
83
settingsGithub ("test/2/b" );
74
- write ("build.gradle" ,
84
+ write (BUILD_GRADLE ,
75
85
"plugins { id 'com.diffplug.blowdryer' }" ,
76
86
"assert Blowdryer.file('sample').text == 'a'" );
77
87
gradleRunner ().buildAndFail ();
@@ -80,15 +90,15 @@ public void githubTag() throws IOException {
80
90
@ Test
81
91
public void gitlabTag () throws IOException {
82
92
settingsGitlab ("test/2/a" );
83
- write ("build.gradle" ,
93
+ write (BUILD_GRADLE ,
84
94
"apply plugin: 'com.diffplug.blowdryer'" ,
85
95
"assert 干.file('sample').text == 'a'" ,
86
96
"assert 干.prop('sample', 'name') == 'test'" ,
87
97
"assert 干.prop('sample', 'ver_spotless') == '1.2.0'" );
88
98
gradleRunner ().build ();
89
99
90
100
settingsGitlab ("test/2/b" );
91
- write ("build.gradle" ,
101
+ write (BUILD_GRADLE ,
92
102
"apply plugin: 'com.diffplug.blowdryer'" ,
93
103
"assert 干.file('sample').text == 'b'" ,
94
104
"assert 干.prop('sample', 'name') == 'testB'" ,
@@ -97,7 +107,7 @@ public void gitlabTag() throws IOException {
97
107
98
108
// double-check that failures do fail
99
109
settingsGitlab ("test/2/b" );
100
- write ("build.gradle" ,
110
+ write (BUILD_GRADLE ,
101
111
"plugins { id 'com.diffplug.blowdryer' }" ,
102
112
"assert Blowdryer.file('sample').text == 'a'" );
103
113
gradleRunner ().buildAndFail ();
@@ -106,15 +116,15 @@ public void gitlabTag() throws IOException {
106
116
@ Test
107
117
public void customGitlabTag () throws IOException {
108
118
settingsCustomGitlab ("test/2/a" );
109
- write ("build.gradle" ,
119
+ write (BUILD_GRADLE ,
110
120
"apply plugin: 'com.diffplug.blowdryer'" ,
111
121
"assert 干.file('sample').text == 'a'" ,
112
122
"assert 干.prop('sample', 'name') == 'test'" ,
113
123
"assert 干.prop('sample', 'ver_spotless') == '1.2.0'" );
114
124
gradleRunner ().build ();
115
125
116
126
settingsCustomGitlab ("test/2/b" );
117
- write ("build.gradle" ,
127
+ write (BUILD_GRADLE ,
118
128
"apply plugin: 'com.diffplug.blowdryer'" ,
119
129
"assert 干.file('sample').text == 'b'" ,
120
130
"assert 干.prop('sample', 'name') == 'testB'" ,
@@ -123,7 +133,7 @@ public void customGitlabTag() throws IOException {
123
133
124
134
// double-check that failures do fail
125
135
settingsCustomGitlab ("test/2/b" );
126
- write ("build.gradle" ,
136
+ write (BUILD_GRADLE ,
127
137
"plugins { id 'com.diffplug.blowdryer' }" ,
128
138
"assert Blowdryer.file('sample').text == 'a'" );
129
139
gradleRunner ().buildAndFail ();
@@ -132,15 +142,15 @@ public void customGitlabTag() throws IOException {
132
142
@ Test
133
143
public void rootfolderGitlabTag () throws IOException {
134
144
settingsGitlabRootFolder ("test/2/a" );
135
- write ("build.gradle" ,
145
+ write (BUILD_GRADLE ,
136
146
"apply plugin: 'com.diffplug.blowdryer'" ,
137
147
"assert 干.file('src/main/resources/sample').text == 'a'" ,
138
148
"assert 干.prop('src/main/resources/sample', 'name') == 'test'" ,
139
149
"assert 干.prop('src/main/resources/sample', 'ver_spotless') == '1.2.0'" );
140
150
gradleRunner ().build ();
141
151
142
152
settingsGitlabRootFolder ("test/2/b" );
143
- write ("build.gradle" ,
153
+ write (BUILD_GRADLE ,
144
154
"apply plugin: 'com.diffplug.blowdryer'" ,
145
155
"assert 干.file('src/main/resources/sample').text == 'b'" ,
146
156
"assert 干.prop('src/main/resources/sample', 'name') == 'testB'" ,
@@ -149,7 +159,7 @@ public void rootfolderGitlabTag() throws IOException {
149
159
150
160
// double-check that failures do fail
151
161
settingsGitlabRootFolder ("test/2/b" );
152
- write ("build.gradle" ,
162
+ write (BUILD_GRADLE ,
153
163
"plugins { id 'com.diffplug.blowdryer' }" ,
154
164
"assert Blowdryer.file('src/main/resources/sample').text == 'a'" );
155
165
gradleRunner ().buildAndFail ();
@@ -161,10 +171,10 @@ public void devLocal() throws IOException {
161
171
write ("../blowdryer-script/src/main/resources/sample.properties" ,
162
172
"name=test" ,
163
173
"group=com.diffplug.gradle" );
164
- write ("settings.gradle" ,
174
+ write (SETTINGS_GRADLE ,
165
175
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
166
176
"blowdryerSetup { devLocal('../blowdryer-script') }" );
167
- write ("build.gradle" ,
177
+ write (BUILD_GRADLE ,
168
178
"apply plugin: 'com.diffplug.blowdryer'" ,
169
179
// .replace('\\r', '') fixes test on windows
170
180
"assert 干.file('sample').text.replace('\\ r', '') == 'c\\ n'" ,
@@ -177,7 +187,7 @@ public void devLocal() throws IOException {
177
187
public void multiproject () throws IOException {
178
188
settingsGithub ("test/2/a" ,
179
189
"include 'subproject'" );
180
- write ("build.gradle" ,
190
+ write (BUILD_GRADLE ,
181
191
"apply plugin: 'com.diffplug.blowdryer'" ,
182
192
"assert 干.file('sample').text == 'a'" ,
183
193
"assert 干.prop('sample', 'name') == 'test'" ,
@@ -199,7 +209,7 @@ public void multiproject() throws IOException {
199
209
@ Test
200
210
public void missingResourceThrowsError () throws IOException {
201
211
settingsGithub ("test/2/a" );
202
- write ("build.gradle" ,
212
+ write (BUILD_GRADLE ,
203
213
"plugins { id 'com.diffplug.blowdryer' }" ,
204
214
"干.file('notPresent')" );
205
215
Assertions .assertThat (gradleRunner ().buildAndFail ().getOutput ().replace ("\r \n " , "\n " )).contains (
@@ -213,7 +223,7 @@ public void cfgTestGroovy() throws IOException {
213
223
write ("../blowdryer-script/src/main/resources/sample.properties" ,
214
224
"name=test" ,
215
225
"group=com.diffplug.gradle" );
216
- write ("settings.gradle" ,
226
+ write (SETTINGS_GRADLE ,
217
227
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
218
228
"blowdryerSetup { devLocal('../blowdryer-script') }" );
219
229
write ("../blowdryer-script/src/main/resources/script.gradle" ,
@@ -223,7 +233,7 @@ public void cfgTestGroovy() throws IOException {
223
233
"println 干.proj(File.class, 'keyFile', 'location of the keyFile')" ,
224
234
"println 干.prop('sample', 'group')" ,
225
235
"" );
226
- write ("build.gradle" ,
236
+ write (BUILD_GRADLE ,
227
237
"apply plugin: 'com.diffplug.blowdryer'" ,
228
238
"ext.pluginPass = 'supersecret'" ,
229
239
"ext.keyFile = new File('keyFile.txt')" ,
@@ -267,7 +277,7 @@ public void cfgTestKotlin() throws IOException {
267
277
268
278
@ Test
269
279
public void settingsTest () throws IOException {
270
- write ("settings.gradle" ,
280
+ write (SETTINGS_GRADLE ,
271
281
"plugins { id 'com.diffplug.blowdryerSetup' }" ,
272
282
"blowdryerSetup { github('diffplug/blowdryer', 'tag', 'test/2/a') }" ,
273
283
"import com.diffplug.blowdryer.干" ,
@@ -277,4 +287,28 @@ public void settingsTest() throws IOException {
277
287
"println 'test was success'" );
278
288
Assertions .assertThat (gradleRunner ().build ().getOutput ().replace ("\r \n " , "\n " ));
279
289
}
290
+
291
+ @ Test
292
+ public void localJarFileDownloadExists () throws IOException {
293
+ String jarFile = BlowdryerPluginTest .class .getResource ("test.jar" ).getFile ();
294
+ settingsLocalJar (jarFile );
295
+
296
+ write (BUILD_GRADLE ,
297
+ "apply plugin: 'com.diffplug.blowdryer'" ,
298
+ "assert 干.file('sample').exists()" );
299
+
300
+ gradleRunner ().build ();
301
+ }
302
+
303
+ @ Test
304
+ public void localJarFileDownloadDoesNotExist () throws IOException {
305
+ String jarFile = BlowdryerPluginTest .class .getResource ("test.jar" ).getFile ();
306
+ settingsLocalJar (jarFile );
307
+
308
+ write (BUILD_GRADLE ,
309
+ "apply plugin: 'com.diffplug.blowdryer'" ,
310
+ "assert 干.file('invalid-file.txt').exists()" );
311
+
312
+ gradleRunner ().buildAndFail ();
313
+ }
280
314
}
0 commit comments