66
77import jakarta .inject .Inject ;
88
9- import io .quarkus .devui .runtime .config .ConfigDescriptionBean ;
10- import io .quarkus .runtime .LaunchMode ;
119import org .eclipse .microprofile .config .inject .ConfigProperty ;
1210
13- import static io .quarkus .runtime .LaunchMode . DEVELOPMENT ;
11+ import io .quarkus .devui . runtime .config . ConfigDescriptionBean ;
1412
1513public class EmbeddedPostgreSQLJsonRpcService {
1614
@@ -21,25 +19,16 @@ public class EmbeddedPostgreSQLJsonRpcService {
2119 Optional <String > jdbcUrl ;
2220
2321 public int getDatasourcePort () {
24- String port = LaunchMode . current (). equals ( DEVELOPMENT ) && jdbcUrl . isPresent () ? jdbcUrl . get ()
25- : configDescriptionBean .getAllConfig ().stream ()
22+ String port = jdbcUrl
23+ . orElseGet (() -> configDescriptionBean .getAllConfig ().stream ()
2624 .filter (c -> c .getName ().equalsIgnoreCase ("quarkus.datasource.jdbc.url" ))
2725 .map (c -> c .getConfigValue ().getValue ())
2826 .findFirst ()
2927 .orElseThrow (() -> new IllegalStateException (
30- "No JDBC URL found in configuration. Please ensure 'quarkus.datasource.jdbc.url' is set." ));
31-
32- // Define a regex pattern to match numbers
33- Pattern pattern = Pattern .compile ("\\ d+" );
34-
28+ "No JDBC URL found in configuration. Please ensure 'quarkus.datasource.jdbc.url' is set." )));
3529 // Create a matcher with the input string
36- Matcher matcher = pattern .matcher (port );
37-
30+ Matcher matcher = Pattern .compile ("\\ d+" ).matcher (port );
3831 // Find and print all numbers in the input string
39- while (matcher .find ()) {
40- String number = matcher .group ();
41- return Integer .parseInt (number );
42- }
43- return 0 ;
32+ return matcher .find () ? Integer .parseInt (matcher .group ()) : 0 ;
4433 }
4534}
0 commit comments