Skip to content

Commit f8f9e6a

Browse files
authored
Bael 9012 (#18247)
* Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot * Bael-9012, Integrating Pkl with Spring Boot
1 parent 22d3389 commit f8f9e6a

File tree

9 files changed

+277
-0
lines changed

9 files changed

+277
-0
lines changed

spring-boot-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<module>spring-boot-nashorn</module>
7272
<module>spring-boot-parent</module>
7373
<module>spring-boot-performance</module>
74+
<module>spring-boot-pkl</module>
7475
<module>spring-boot-property-exp</module>
7576
<module>spring-boot-request-params</module>
7677
<module>spring-boot-runtime</module>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.baeldung.spring-boot-modules</groupId>
8+
<artifactId>spring-boot-modules</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
<name>spring-boot-pkl</name>
12+
<description>Spring Boot Integration with pkl-lang</description>
13+
<artifactId>spring-boot-pkl</artifactId>
14+
<version>1.0-SNAPSHOT</version>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-actuator</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.pkl-lang</groupId>
32+
<artifactId>pkl-spring</artifactId>
33+
<version>${pickle-spring.version}</version>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.codehaus.mojo</groupId>
42+
<artifactId>exec-maven-plugin</artifactId>
43+
<version>${exec-maven-plugin.version}</version>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.pkl-lang</groupId>
47+
<artifactId>pkl-tools</artifactId>
48+
<version>${pkl-tools.version}</version>
49+
</dependency>
50+
</dependencies>
51+
</plugin>
52+
</plugins>
53+
</pluginManagement>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-surefire-plugin</artifactId>
58+
<version>${surefire.version}</version>
59+
<configuration>
60+
<environmentVariables>
61+
<GITHUB_PASSWORD>gitpassword</GITHUB_PASSWORD>
62+
<JIRA_PASSWORD>jirapassword</JIRA_PASSWORD>
63+
</environmentVariables>
64+
</configuration>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.codehaus.mojo</groupId>
68+
<artifactId>exec-maven-plugin</artifactId>
69+
<executions>
70+
<execution>
71+
<id>gen-pkl-java-bind</id>
72+
<phase>generate-sources</phase>
73+
<goals>
74+
<goal>java</goal>
75+
</goals>
76+
<configuration>
77+
<mainClass>org.pkl.codegen.java.Main</mainClass>
78+
<includeProjectDependencies>false</includeProjectDependencies>
79+
<additionalClasspathElements>
80+
<classpathElement>${pkl-tools-filepath}/pkl-tools-0.27.2.jar</classpathElement>
81+
</additionalClasspathElements>
82+
<arguments>
83+
<argument>${pkl-template-filepath}/ToolIntegrationTemplate.pkl</argument>
84+
<argument>-o</argument>
85+
<argument>${project.build.directory}/generated-sources</argument>
86+
<argument>--generate-spring-boot</argument>
87+
<argument>--generate-getters</argument>
88+
</arguments>
89+
</configuration>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.codehaus.mojo</groupId>
95+
<artifactId>build-helper-maven-plugin</artifactId>
96+
<version>${build-helper-maven-plugin.version}</version>
97+
<executions>
98+
<execution>
99+
<id>add-source</id>
100+
<phase>generate-sources</phase>
101+
<goals>
102+
<goal>add-source</goal>
103+
</goals>
104+
<configuration>
105+
<sources>
106+
<source>target/generated-sources</source>
107+
</sources>
108+
</configuration>
109+
</execution>
110+
</executions>
111+
</plugin>
112+
</plugins>
113+
</build>
114+
115+
<properties>
116+
<maven.compiler.source>21</maven.compiler.source>
117+
<maven.compiler.target>21</maven.compiler.target>
118+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
119+
120+
<pickle-spring.version>0.16.0</pickle-spring.version>
121+
<exec-maven-plugin.version>3.3.0</exec-maven-plugin.version>
122+
<pkl-tools.version>0.27.2</pkl-tools.version>
123+
<surefire.version>3.5.0</surefire.version>
124+
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
125+
126+
<pkl-tools-filepath>${settings.localRepository}/org/pkl-lang/pkl-tools/0.27.2</pkl-tools-filepath>
127+
<pkl-template-filepath>${project.basedir}/src/main/resources</pkl-template-filepath>
128+
</properties>
129+
130+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.spring.pkl;
2+
3+
public class GitHubService {
4+
private final ToolIntegrationProperties.Connection gitConnection;
5+
6+
public GitHubService(ToolIntegrationProperties.Connection connection) {
7+
this.gitConnection = connection;
8+
}
9+
10+
public String readIssues() {
11+
return "Reading issues from GitHub URL " + gitConnection.getUrl();
12+
}
13+
14+
public ToolIntegrationProperties.Connection getGitConnection() {
15+
return gitConnection;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.spring.pkl;
2+
3+
public class JiraService {
4+
private final ToolIntegrationProperties.Connection jiraConnection;
5+
6+
public JiraService(ToolIntegrationProperties.Connection connection) {
7+
this.jiraConnection = connection;
8+
}
9+
10+
public String readIssues() {
11+
return "Reading issues from Jira URL " + jiraConnection.getUrl();
12+
}
13+
14+
public ToolIntegrationProperties.Connection getJiraConnection() {
15+
return jiraConnection;
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.spring.pkl;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
6+
7+
@SpringBootApplication
8+
@ConfigurationPropertiesScan
9+
public class SpringPklDemoApplication {
10+
public static void main(String[] args) {
11+
SpringApplication.run(SpringPklDemoApplication.class, args);
12+
}
13+
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.spring.pkl;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class ToolConfiguration {
8+
@Bean
9+
public GitHubService getGitHubService(ToolIntegrationProperties toolIntegration) {
10+
return new GitHubService(toolIntegration.getGitConnection());
11+
}
12+
13+
@Bean
14+
public JiraService getJiraService(ToolIntegrationProperties toolIntegration) {
15+
return new JiraService(toolIntegration.getJiraConnection());
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module com.baeldung.spring.pkl.ToolIntegrationProperties
2+
3+
class Connection {
4+
url:String
5+
name:String
6+
credential:Credential
7+
}
8+
9+
class Credential {
10+
user:String
11+
password:String
12+
}
13+
14+
gitConnection: Connection
15+
jiraConnection: Connection
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
amends "ToolIntegrationTemplate.pkl"
2+
gitConnection {
3+
url = "https://api.github.com"
4+
name = "GitHub"
5+
credential {
6+
user = "gituser"
7+
password = read("env:GITHUB_PASSWORD")
8+
}
9+
}
10+
jiraConnection {
11+
url = "https://jira.atlassian.com"
12+
name = "Jira"
13+
credential {
14+
user = "jirauser"
15+
password = read("env:JIRA_PASSWORD")
16+
}
17+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.baeldung.spring.pkl;
2+
3+
import static org.junit.jupiter.api.Assertions.assertAll;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
12+
@SpringBootTest
13+
public class SpringPklUnitTest {
14+
Logger logger = LoggerFactory.getLogger(SpringPklUnitTest.class);
15+
16+
@Autowired
17+
private GitHubService gitHubService;
18+
@Autowired
19+
private JiraService jiraService;
20+
21+
@Test
22+
public void whenJiraConfigsDefined_thenLoadFromApplicationPklFile() {
23+
ToolIntegrationProperties.Connection jiraConnection = jiraService.getJiraConnection();
24+
ToolIntegrationProperties.Credential jiraCredential = jiraConnection.getCredential();
25+
26+
assertAll(
27+
() -> assertEquals("Jira", jiraConnection.getName()),
28+
() -> assertEquals("https://jira.atlassian.com", jiraConnection.getUrl()),
29+
() -> assertEquals("jirauser", jiraCredential.getUser()),
30+
() -> assertEquals("jirapassword", jiraCredential.getPassword()),
31+
() -> assertEquals("Reading issues from Jira URL https://jira.atlassian.com",
32+
jiraService.readIssues())
33+
);
34+
}
35+
36+
@Test
37+
public void whenGitHubConfigsDefined_thenLoadFromApplicationPklFile() {
38+
ToolIntegrationProperties.Connection gitHubConnection = gitHubService.getGitConnection();
39+
ToolIntegrationProperties.Credential gitHubCredential = gitHubConnection.getCredential();
40+
41+
assertAll(
42+
() -> assertEquals("GitHub", gitHubConnection.getName()),
43+
() -> assertEquals("https://api.github.com", gitHubConnection.getUrl()),
44+
() -> assertEquals("gituser", gitHubCredential.getUser()),
45+
() -> assertEquals("gitpassword", gitHubCredential.getPassword()),
46+
() -> assertEquals("Reading issues from GitHub URL https://api.github.com", gitHubService.readIssues())
47+
);
48+
}
49+
}

0 commit comments

Comments
 (0)