forked from rockcrafters/java-rockcraft-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rockcrafters#12 from vpa1977/beryx-gradle
feat: beryx jlink plugin support for gradle
- Loading branch information
Showing
13 changed files
with
197 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
rockcraft-gradle/src/main/java/com/canonical/rockcraft/gradle/ITaskNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.canonical.rockcraft.gradle; | ||
|
||
public interface ITaskNames { | ||
public String JAR = "jar"; | ||
public String BOOT_JAR = "bootJar"; | ||
public String JLINK = "jlink"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
rockcraft-gradle/src/test/java/com/canonical/rockcraft/gradle/BeryxJLinkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.canonical.rockcraft.gradle; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class BeryxJLinkTest extends BaseRockcraftTest { | ||
|
||
protected File getJavaSource() { | ||
return Paths.get(projectDir.getAbsolutePath(), "src", "main", "java", "beryxtest", "Test.java").toFile(); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() throws IOException { | ||
super.setUp(); | ||
writeString(getJavaSource(), getResource("beryx-test-class.in")); | ||
writeString(getBuildFile(), getResource("beryx-project-build.in")); | ||
writeString(Paths.get(projectDir.getAbsolutePath(), "src", "main", "java", "module-info.java").toFile(), | ||
getResource("beryx-module-info.in")); | ||
} | ||
|
||
/** | ||
* Integration test - the rock should build successfully | ||
* | ||
* @throws IOException | ||
*/ | ||
@Test | ||
public void testBeryxJlinkBuild() throws IOException { | ||
BuildResult result = runBuild("build-rock", "--stacktrace"); | ||
assertEquals(TaskOutcome.SUCCESS, getLastTaskOutcome(result)); // the build needs to succeed | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
public void testBeryxJlinkRockcraft() throws IOException { | ||
BuildResult result = runBuild("create-rock", "--stacktrace"); | ||
assertEquals(TaskOutcome.SUCCESS, getLastTaskOutcome(result)); // the build needs to succeed | ||
try (FileInputStream is = new FileInputStream(Paths.get(getProjectDir().getAbsolutePath(), "build", "rockcraft.yaml").toFile())) { | ||
Yaml yaml = new Yaml(); | ||
Map<String, Object> parsed = yaml.load(is); | ||
Map<String, Object> services = (Map<String, Object>)parsed.get("services"); | ||
assertTrue(services.containsKey("hello")); | ||
Map<String, Object> helloService =(Map<String, Object>)services.get("hello"); | ||
assertEquals("/image/bin/hello", helloService.get("command")); | ||
|
||
Map<String, Object> parts = (Map<String, Object>)parsed.get("parts"); | ||
Map<String, Object> dump0 = (Map<String, Object>)parts.get("gradle/rockcraft/dump0"); | ||
String overrideBuild = (String) dump0.get("override-build"); | ||
assertEquals("cp --archive --link --no-dereference image /", overrideBuild); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
rockcraft-gradle/src/test/resources/com/canonical/rockcraft/gradle/beryx-module-info.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module test { | ||
exports beryxtest; | ||
} |
28 changes: 28 additions & 0 deletions
28
rockcraft-gradle/src/test/resources/com/canonical/rockcraft/gradle/beryx-project-build.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id('java') | ||
id('org.beryx.jlink') version "2.24.1" | ||
id('io.rockcrafters.rockcraft') | ||
} | ||
version = 0.01 | ||
|
||
java.toolchain.languageVersion = JavaLanguageVersion.of(17) | ||
|
||
jar { | ||
manifest { | ||
attributes 'Main-Class': 'beryxtest.Test' | ||
} | ||
} | ||
|
||
jlink { | ||
mainClass = 'beryxtest.Test' | ||
mergedModule { | ||
requires 'java.naming' | ||
requires 'java.xml' | ||
} | ||
launcher { | ||
name = 'hello' | ||
} | ||
} | ||
|
||
rockcraft { | ||
} |
7 changes: 7 additions & 0 deletions
7
rockcraft-gradle/src/test/resources/com/canonical/rockcraft/gradle/beryx-test-class.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package beryxtest; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
System.out.println("Hello!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters