@@ -9,6 +9,8 @@ import spock.lang.Issue
9
9
import java.util.zip.ZipEntry
10
10
import java.util.zip.ZipFile
11
11
12
+ import static com.github.jrubygradle.jar.JRubyJar.DEFAULT_MAIN_CLASS
13
+
12
14
class JRubyJarTestKitSpec extends IntegrationSpecification {
13
15
14
16
public static final String DEFAULT_TASK_NAME = ' jrubyJar'
@@ -17,6 +19,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
17
19
String jrubyJarConfig
18
20
String repoSetup
19
21
String deps
22
+ String preamble
20
23
String additionalContent
21
24
22
25
def setup () {
@@ -36,8 +39,8 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
36
39
}
37
40
38
41
void " executing the jrubyJar task produces an executable artifact" () {
39
- given :
40
- withJRubyConfig """
42
+ setup :
43
+ withJRubyJarConfig """
41
44
initScript 'main.rb'
42
45
"""
43
46
@@ -59,8 +62,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
59
62
result. task(" :validateJar" ). outcome == TaskOutcome . SUCCESS
60
63
61
64
and : " the should not be a jruby-mains.jar or jruby-complete.jar inside the archive"
62
- ZipFile zip = new ZipFile (" ${ projectDir} /build/libs/testproject-jruby.jar" )
63
- ! zip. entries(). findAll { ZipEntry entry ->
65
+ ! jarEntries. findAll { ZipEntry entry ->
64
66
entry. name. matches(/ (.*)jruby-complete-(.*).jar/ ) || entry. name. matches(/ (.*)jruby-mains-(.*).jar/ )
65
67
}
66
68
@@ -70,7 +72,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
70
72
71
73
@Issue (" https://github.com/jruby-gradle/jruby-gradle-plugin/issues/183" )
72
74
void " creating a new task based on JRubyJar produces a jar artifact" () {
73
- given :
75
+ setup :
74
76
withAdditionalContent '''
75
77
task someDifferentJar(type: JRubyJar) {
76
78
initScript 'main.rb'
@@ -96,13 +98,13 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
96
98
@IgnoreIf ({ IntegrationSpecification .OFFLINE })
97
99
@Issue (' https://github.com/jruby-gradle/jruby-gradle-plugin/pull/271' )
98
100
def ' using a more recent jar-dependencies should work' () {
99
- given :
101
+ setup :
100
102
withRepoSetup """
101
103
maven { url 'http://rubygems-proxy.torquebox.org/releases' }
102
104
mavenCentral()
103
105
"""
104
106
withDependencies " jrubyJar 'rubygems:jar-dependencies:0.2.3'"
105
- withJRubyConfig " initScript 'main.rb'"
107
+ withJRubyJarConfig " initScript 'main.rb'"
106
108
107
109
withAdditionalContent '''
108
110
task validateJar(type: JavaExec) {
@@ -122,7 +124,36 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
122
124
result. output. contains(" Hello from JRuby" )
123
125
}
124
126
125
- private void withJRubyConfig (String content ) {
127
+ void " Building a Jar with a custom configuration and 'java' plugin is applied" () {
128
+ setup :
129
+ withPreamble ' apply plugin: "java"'
130
+ withJRubyJarConfig " mainClass 'bogus.does.not.exist'"
131
+
132
+ when :
133
+ build()
134
+
135
+ then : " I expect to see jruby.home unpacked inside the jar"
136
+ jarEntries. find { entry ->
137
+ entry. name == ' META-INF/jruby.home/bin/'
138
+ }
139
+
140
+ and : " I expect the new main class to be listed in the manifest"
141
+ jarManifestContent. contains ' Main-Class: bogus.does.not.exist'
142
+ }
143
+
144
+ void " Adding a default main class" () {
145
+ setup :
146
+ withPreamble ' apply plugin: "java"'
147
+ withJRubyJarConfig " defaultMainClass()"
148
+
149
+ when :
150
+ build()
151
+
152
+ then : " Then the attribute should be set to the default in the manifest"
153
+ jarManifestContent. contains " Main-Class: ${ DEFAULT_MAIN_CLASS} "
154
+ }
155
+
156
+ private void withJRubyJarConfig (String content ) {
126
157
jrubyJarConfig = """
127
158
jrubyJar {
128
159
${ content}
@@ -159,6 +190,10 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
159
190
"""
160
191
}
161
192
193
+ private void withPreamble (String content ) {
194
+ this . preamble = content
195
+ }
196
+
162
197
private void writeBuildFile () {
163
198
buildFile. text = """
164
199
import com.github.jrubygradle.jar.JRubyJar
@@ -167,6 +202,8 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
167
202
id 'com.github.jruby-gradle.jar'
168
203
}
169
204
205
+ ${ preamble ?: ''}
206
+
170
207
jruby.defaultRepositories = false
171
208
172
209
${ repoSetup ?: ''}
@@ -195,4 +232,19 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
195
232
tasks. addAll(additionalTasks)
196
233
gradleRunner(tasks). build()
197
234
}
235
+
236
+ private def getJarEntries () {
237
+ ZipFile zip = new ZipFile (" ${ projectDir} /build/libs/testproject-jruby.jar" )
238
+ zip. entries()
239
+ }
240
+
241
+ private String getJarManifestContent () {
242
+ ZipFile zip = new ZipFile (" ${ projectDir} /build/libs/testproject-jruby.jar" )
243
+
244
+ ZipEntry entry = zip. entries(). find { entry ->
245
+ entry. name == ' META-INF/MANIFEST.MF'
246
+ }
247
+
248
+ zip. getInputStream(entry). text
249
+ }
198
250
}
0 commit comments