Skip to content

Commit 0beaca6

Browse files
committed
add tests for Gradle 9+
1 parent c0d88e8 commit 0beaca6

5 files changed

Lines changed: 160 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.beryx.runtime
17+
18+
import org.gradle.testkit.runner.BuildResult
19+
import org.gradle.testkit.runner.GradleRunner
20+
import spock.lang.Specification
21+
import spock.lang.TempDir
22+
import spock.lang.Unroll
23+
import spock.util.environment.OperatingSystem
24+
25+
import java.nio.file.Path
26+
27+
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
28+
29+
class RuntimePluginSpecGradle9 extends Specification {
30+
@TempDir Path testProjectDir
31+
32+
def cleanup() {
33+
println "CLEANUP"
34+
}
35+
36+
def setUpBuild(Collection<String> modules) {
37+
new AntBuilder().copy( todir: testProjectDir ) {
38+
fileset( dir: 'src/test/resources/hello-logback-gradle9' )
39+
}
40+
41+
File buildFile = new File(testProjectDir.toFile(), "build.gradle")
42+
buildFile << '''
43+
runtime {
44+
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
45+
'''.stripIndent()
46+
if(modules != null) {
47+
buildFile << " modules = [${modules.collect{'\'' + it + '\''}.join(', ')}]\n"
48+
}
49+
buildFile << '}\n'
50+
println "Executing build script:\n${buildFile.text}"
51+
}
52+
53+
@Unroll
54+
def "if modules=#modules, then buildSucceeds=#buildShouldSucceed and runSucceeds=#runShouldSucceed with Gradle #gradleVersion"() {
55+
when:
56+
setUpBuild(modules)
57+
BuildResult result
58+
try {
59+
result = GradleRunner.create()
60+
.withDebug(true)
61+
.withProjectDir(testProjectDir.toFile())
62+
.withGradleVersion(gradleVersion)
63+
.withPluginClasspath()
64+
.withArguments(RuntimePlugin.TASK_NAME_RUNTIME, "-is")
65+
.build()
66+
} catch (Exception e) {
67+
if(buildShouldSucceed) {
68+
e.printStackTrace()
69+
}
70+
assert !buildShouldSucceed
71+
return
72+
}
73+
def imageBinDir = new File(testProjectDir.toFile(), 'build/image/bin')
74+
def launcherExt = OperatingSystem.current.windows ? '.bat' : ''
75+
def imageLauncher = new File(imageBinDir, "runtime-hello-gradle9$launcherExt")
76+
77+
then:
78+
result.task(":$RuntimePlugin.TASK_NAME_RUNTIME").outcome == SUCCESS
79+
imageLauncher.exists()
80+
81+
when:
82+
imageLauncher.setExecutable(true)
83+
def process = imageLauncher.absolutePath.execute([], imageBinDir)
84+
def out = new ByteArrayOutputStream(2048)
85+
def err = new ByteArrayOutputStream(2048)
86+
process.waitForProcessOutput(out, err)
87+
def outputText = out.toString()
88+
89+
then:
90+
(outputText.trim() == 'LOG: Hello, runtime!') == runShouldSucceed
91+
92+
where:
93+
modules | buildShouldSucceed | runShouldSucceed | gradleVersion
94+
null | true | true | '9.1.0'
95+
[] | true | true | '9.0.0'
96+
['java.base'] | true | false | '9.0.0'
97+
['foo.bar'] | false | false | '9.0.0'
98+
['java.naming'] | true | false | '9.0.0'
99+
['java.naming', 'java.xml'] | true | true | '9.0.0'
100+
['java.naming', 'java.xml', 'java.logging'] | true | true | '9.0.0'
101+
['java.naming', 'java.xml', 'foo.bar'] | false | false | '9.0.0'
102+
['java.naming', 'java.xml', 'java.logging'] | true | true | '9.0.0'
103+
['java.naming', 'java.xml', 'java.logging'] | true | true | '9.1.0'
104+
}
105+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
id 'org.beryx.runtime'
3+
id 'com.gradleup.shadow' version '8.3.9'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
11+
12+
dependencies {
13+
implementation 'org.slf4j:slf4j-api:2.0.17'
14+
implementation 'ch.qos.logback:logback-classic:1.5.18'
15+
implementation 'javax.xml.bind:jaxb-api:2.3.1'
16+
}
17+
18+
application {
19+
mainClass = 'org.example.runtime.HelloGradle9'
20+
}
21+
22+
jar {
23+
manifest {
24+
attributes 'Implementation-Title': "runtime-hello-gradle9",
25+
'Main-Class': 'org.example.runtime.HelloGradle9'
26+
}
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'runtime-hello-gradle9'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.example.runtime;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class HelloGradle9 {
7+
private static final Logger logger = LoggerFactory.getLogger(HelloGradle9.class);
8+
9+
public static void main(String[] args) {
10+
logger.info("Hello, runtime!");
11+
}
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<configuration>
2+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3+
<encoder>
4+
<pattern>
5+
LOG: %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
<root level="WARN">
10+
<appender-ref ref="STDOUT" />
11+
</root>
12+
<logger name="org.example.runtime" level="info" additivity="false">
13+
<appender-ref ref="STDOUT" />
14+
</logger>
15+
</configuration>

0 commit comments

Comments
 (0)