diff --git a/boot/pom.xml b/boot/pom.xml
index 5d964b4..05a22d7 100644
--- a/boot/pom.xml
+++ b/boot/pom.xml
@@ -33,12 +33,7 @@
Apache Karaf Minho :: Boot
-
- org.projectlombok
- lombok
- ${lombok.version}
- provided
-
+
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/Main.java b/boot/src/main/java/org/apache/karaf/minho/boot/Main.java
index 03efb62..5daee31 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/Main.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/Main.java
@@ -17,44 +17,57 @@
*/
package org.apache.karaf.minho.boot;
-import lombok.extern.java.Log;
-
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.nio.file.*;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.function.Predicate;
+import java.util.logging.Logger;
+
+import static java.util.Optional.ofNullable;
-@Log
public class Main {
+ private Main() {
+ // no-op
+ }
- public static final void main(String[] args) throws Exception {
- boolean minhoJar = false;
- minhoJar = (System.getenv("MINHO_JAR") != null) ? System.getenv("MINHO_JAR").equalsIgnoreCase("true") : minhoJar;
- minhoJar = (System.getProperty("minho.jar") != null) ? System.getProperty("minho.jar").equalsIgnoreCase("true") : minhoJar;
+ public static void main(final String... args) throws Exception {
+ final boolean minhoJar = Boolean.parseBoolean(System.getenv("MINHO_JAR")) || Boolean.parseBoolean(System.getProperty("minho.jar"));
+ final var log = Logger.getLogger(Main.class.getName());
if (!minhoJar) {
log.info("Starting runtime in exploded mode");
// try to load classpath
- String minhoLib = (System.getProperty("minho.lib") != null) ? System.getProperty("minho.lib") : System.getProperty("user.dir");
+ final var minhoLib = ofNullable(System.getProperty("minho.lib"))
+ .orElseGet(() -> System.getProperty("user.dir"));
System.out.println("Minho lib: " + minhoLib);
- Path libFolder = Paths.get(minhoLib);
- ArrayList urls = new ArrayList();
- Files.walkFileTree(libFolder, new SimpleFileVisitor<>() {
- public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
- if (!Files.isDirectory(file)) {
- urls.add(file.toFile().toURI().toURL());
+ final var libFolder = Paths.get(minhoLib);
+ try (final var walk = Files.walk(libFolder)) {
+ final var urls = walk
+ .filter(Predicate.not(Files::isDirectory))
+ .map(it -> {
+ try {
+ return it.toUri().toURL();
+ } catch (final MalformedURLException e) {
+ throw new IllegalStateException(e);
+ }
+ })
+ .toArray(URL[]::new);
+ final var classLoader = new URLClassLoader(urls);
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ classLoader.close();
+ } catch (final IOException e) {
+ // no-op, not critical
}
- return FileVisitResult.CONTINUE;
- }
- });
- URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[]{}));
- Thread.currentThread().setContextClassLoader(classLoader);
+ }, Main.class.getName() + "-classloader-close"));
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
} else {
log.info("Starting runtime in uber jar mode");
}
- Minho.builder().build().start();
+ SimpleMain.main(args);
}
-
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/Minho.java b/boot/src/main/java/org/apache/karaf/minho/boot/Minho.java
index e225169..ebea9a7 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/Minho.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/Minho.java
@@ -17,28 +17,38 @@
*/
package org.apache.karaf.minho.boot;
-import lombok.Builder;
-import lombok.Data;
-import lombok.extern.java.Log;
import org.apache.karaf.minho.boot.service.ServiceRegistry;
import org.apache.karaf.minho.boot.spi.Service;
import org.apache.karaf.minho.boot.spi.ServiceLoader;
+import org.apache.karaf.minho.boot.spi.impl.DefaultLoaderService;
-import java.util.Comparator;
-import java.util.stream.Stream;
+import java.util.Objects;
/**
* Main Karaf runtime.
*/
-@Log
-@Builder
-@Data
-public class Minho implements AutoCloseable {
-
- private static Minho instance;
-
+public class Minho implements AutoCloseable, Service {
private final ServiceLoader loader;
private final ServiceRegistry serviceRegistry = new ServiceRegistry();
+ private volatile boolean closed = false;
+
+ protected Minho(final ServiceLoader loader) {
+ this.loader = loader;
+ }
+
+ public ServiceRegistry getServiceRegistry() {
+ return serviceRegistry;
+ }
+
+ @Override
+ public String name() {
+ return "minho";
+ }
+
+ @Override
+ public int priority() {
+ return Integer.MIN_VALUE;
+ }
/**
* Start the Karaf runtime.
@@ -47,40 +57,43 @@ public class Minho implements AutoCloseable {
*/
public Minho start() {
// log format
- if (System.getProperty("java.util.logging.config.file") == null) {
- if (System.getenv("KARAF_LOG_FORMAT") != null) {
- System.setProperty("java.util.logging.SimpleFormatter.format", System.getenv("KARAF_LOG_FORMAT"));
- }
- if (System.getProperty("java.util.logging.SimpleFormatter.format") == null) {
- System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tF %1$tT.%1$tN %4$s [ %2$s ] : %5$s%6$s%n");
- }
+ if (System.getProperty("java.util.logging.config.file") == null &&
+ System.getProperty("java.util.logging.SimpleFormatter.format") == null) {
+ System.setProperty("java.util.logging.SimpleFormatter.format",
+ Objects.requireNonNullElse(System.getenv("MINHO_LOG_FORMAT"), "%1$tF %1$tT.%1$tN %4$s [ %2$s ] : %5$s%6$s%n"));
}
- (this.loader == null ? loadServices() : this.loader.load()).forEach(serviceRegistry::add);
+ serviceRegistry.add(this);
+ loader.load().forEach(serviceRegistry::add);
serviceRegistry.start();
- instance = this;
- return instance;
- }
-
- private Stream loadServices() {
- return java.util.ServiceLoader.load(Service.class).stream().map(java.util.ServiceLoader.Provider::get)
- .sorted(Comparator.comparingInt(service -> Integer.getInteger(service.name() + ".priority", service.priority())));
+ return this;
}
/**
- * Close (stop) the Karaf runtime.
+ * Close (stop) the Minho runtime.
*/
@Override
public void close() {
+ if (closed) {
+ return;
+ }
+ closed = true;
serviceRegistry.close();
}
- /**
- * Retrieve the Minho instance.
- *
- * @return the Minho instance.
- */
- public static Minho getInstance() {
- return instance;
+ public static Builder builder() {
+ return new Builder();
}
+ public static class Builder {
+ private ServiceLoader loader = new DefaultLoaderService();
+
+ public Builder loader(final ServiceLoader loader) {
+ this.loader = loader;
+ return this;
+ }
+
+ public Minho build() {
+ return new Minho(loader);
+ }
+ }
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/SimpleMain.java b/boot/src/main/java/org/apache/karaf/minho/boot/SimpleMain.java
new file mode 100644
index 0000000..2a3c1a0
--- /dev/null
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/SimpleMain.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.minho.boot;
+
+import org.apache.karaf.minho.boot.service.ConfigService;
+
+import java.util.concurrent.CountDownLatch;
+
+public class SimpleMain {
+ private SimpleMain() {
+ // no-op
+ }
+
+ public static void main(final String... args) throws Exception {
+ try (final var instance = Minho.builder().build().start()) {
+ final var registry = instance.getServiceRegistry();
+ final var awaiter = registry.get(Awaiter.class);
+ if (awaiter != null) {
+ awaiter.await();
+ } else if (Boolean.getBoolean(registry.get(ConfigService.class).property("minho.awaiter.implicit", "false"))) {
+ new CountDownLatch(1).await();
+ }
+ }
+ }
+
+ /**
+ * Service implementation enabling the main to not quit immediately if set.
+ * Often used for servers.
+ */
+ public interface Awaiter {
+ /**
+ * Wait until the application completes and can exit.
+ */
+ void await();
+ }
+}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/config/Application.java b/boot/src/main/java/org/apache/karaf/minho/boot/config/Application.java
index 1e8e266..6062940 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/config/Application.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/config/Application.java
@@ -17,14 +17,11 @@
*/
package org.apache.karaf.minho.boot.config;
-import lombok.Data;
-
import java.util.HashMap;
import java.util.Map;
-@Data
+// todo: move to record
public class Application {
-
private String name;
private String version;
private String url;
@@ -32,12 +29,59 @@ public class Application {
private String profile;
private Map properties = new HashMap<>();
- public String getProperty(String key) {
- return getProperty(key, null);
+ public String property(final String key) {
+ return property(key, null);
+ }
+
+ public String property(String key, String defaultValue) {
+ return Config.property(key, properties, defaultValue);
}
- public String getProperty(String key, String defaultValue) {
- return Config.getProperty(key, properties, defaultValue);
+ public String getName() {
+ return name;
}
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(final String version) {
+ this.version = version;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(final String url) {
+ this.url = url;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getProfile() {
+ return profile;
+ }
+
+ public void setProfile(final String profile) {
+ this.profile = profile;
+ }
+
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(final Map properties) {
+ this.properties = properties;
+ }
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/config/Config.java b/boot/src/main/java/org/apache/karaf/minho/boot/config/Config.java
index 37588e6..3a4113e 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/config/Config.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/config/Config.java
@@ -17,7 +17,6 @@
*/
package org.apache.karaf.minho.boot.config;
-import lombok.Data;
import java.util.ArrayList;
import java.util.HashMap;
@@ -25,10 +24,9 @@
import java.util.Map;
import java.util.regex.Pattern;
-@Data
+// todo: move to record
public class Config {
-
- private static Pattern envKeyPattern = Pattern.compile("\\.");
+ private static Pattern TO_ENV_KEY = Pattern.compile("\\.");
private Map properties = new HashMap<>();
private List profiles = new ArrayList<>();
@@ -44,16 +42,16 @@ public void merge(final Config config) {
applications.addAll(config.getApplications());
}
- public String getProperty(String key) {
- return getProperty(key, null);
+ public String property(String key) {
+ return property(key, null);
}
- public String getProperty(String key, String defaultValue) {
- return getProperty(key, this.properties, defaultValue);
+ public String property(String key, String defaultValue) {
+ return property(key, this.properties, defaultValue);
}
- protected static String getProperty(String key, Map properties, String defaultValue) {
- String envKey = envKeyPattern.matcher(key).replaceAll("_").toUpperCase();
+ protected static String property(String key, Map properties, String defaultValue) {
+ String envKey = TO_ENV_KEY.matcher(key).replaceAll("_").toUpperCase();
if (System.getenv(envKey) != null) {
return System.getenv(envKey);
}
@@ -66,4 +64,27 @@ protected static String getProperty(String key, Map properties,
return defaultValue;
}
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(final Map properties) {
+ this.properties = properties;
+ }
+
+ public List getProfiles() {
+ return profiles;
+ }
+
+ public void setProfiles(final List profiles) {
+ this.profiles = profiles;
+ }
+
+ public List getApplications() {
+ return applications;
+ }
+
+ public void setApplications(final List applications) {
+ this.applications = applications;
+ }
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/config/Priority.java b/boot/src/main/java/org/apache/karaf/minho/boot/config/Priority.java
index de0a0ca..37d5209 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/config/Priority.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/config/Priority.java
@@ -17,13 +17,33 @@
*/
package org.apache.karaf.minho.boot.config;
-import lombok.Data;
-
-@Data
+// todo: move to record
public class Priority {
-
private String type;
private String pattern;
private String name;
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getPattern() {
+ return pattern;
+ }
+
+ public void setPattern(final String pattern) {
+ this.pattern = pattern;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/config/Profile.java b/boot/src/main/java/org/apache/karaf/minho/boot/config/Profile.java
index ba0d7bf..081cc5a 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/config/Profile.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/config/Profile.java
@@ -17,26 +17,37 @@
*/
package org.apache.karaf.minho.boot.config;
-import lombok.Data;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-@Data
public class Profile {
-
private String name;
private Map properties = new HashMap<>();
private List urls = new ArrayList<>();
- public String getProperty(String key) {
- return getProperty(key, null);
+ public String getName() {
+ return name;
}
- public String getProperty(String key, String defaultValue) {
- return Config.getProperty(key, properties, defaultValue);
+ public void setName(final String name) {
+ this.name = name;
}
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(final Map properties) {
+ this.properties = properties;
+ }
+
+ public List getUrls() {
+ return urls;
+ }
+
+ public void setUrls(final List urls) {
+ this.urls = urls;
+ }
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/service/ClassLoaderService.java b/boot/src/main/java/org/apache/karaf/minho/boot/service/ClassLoaderService.java
index d210d93..db9f9c3 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/service/ClassLoaderService.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/service/ClassLoaderService.java
@@ -20,6 +20,7 @@
import org.apache.karaf.minho.boot.config.Config;
import org.apache.karaf.minho.boot.spi.Service;
+import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
@@ -30,7 +31,7 @@
*/
public class ClassLoaderService implements Service, AutoCloseable {
- private Map profiles = new HashMap<>();
+ private final Map profiles = new HashMap<>();
@Override
public String name() {
@@ -44,19 +45,25 @@ public int priority() {
@Override
public void close() {
- // no-op
+ profiles.values().forEach(it -> {
+ try {
+ it.close();
+ } catch (final IOException e) {
+ // no-op, not critical
+ }
+ });
}
@Override
public void onRegister(ServiceRegistry serviceRegistry) throws Exception {
Config configService = serviceRegistry.get(Config.class);
- configService.getProfiles().stream().forEach(profile -> {
- URLClassLoader profileClassLoader = new URLClassLoader(profile.getUrls().toArray(new URL[]{}), this.getClass().getClassLoader());
+ configService.getProfiles().forEach(profile -> {
+ URLClassLoader profileClassLoader = new URLClassLoader(profile.getUrls().toArray(new URL[0]), this.getClass().getClassLoader());
profiles.put(profile.getName(), profileClassLoader);
});
}
- public URLClassLoader getClassLoader(String profile) {
+ public URLClassLoader getClassLoader(final String profile) {
return profiles.get(profile);
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/service/ConfigService.java b/boot/src/main/java/org/apache/karaf/minho/boot/service/ConfigService.java
index 1e30546..38579a9 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/service/ConfigService.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/service/ConfigService.java
@@ -31,6 +31,6 @@ public String name() {
@Override
public int priority() {
- return -Integer.MAX_VALUE;
+ return Integer.MIN_VALUE + 1;
}
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/service/InstanceSingletonService.java b/boot/src/main/java/org/apache/karaf/minho/boot/service/InstanceSingletonService.java
new file mode 100644
index 0000000..4bbbfa0
--- /dev/null
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/service/InstanceSingletonService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.minho.boot.service;
+
+import org.apache.karaf.minho.boot.Minho;
+import org.apache.karaf.minho.boot.spi.Service;
+
+public class InstanceSingletonService implements Service, AutoCloseable {
+ private static Minho instance;
+
+ @Override
+ public void onRegister(final ServiceRegistry serviceRegistry) throws Exception {
+ instance = serviceRegistry.get(Minho.class);
+ }
+
+ @Override
+ public void close() throws Exception {
+ instance = null;
+ }
+
+ public static Minho getInstance() {
+ return instance;
+ }
+}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/service/LifeCycleService.java b/boot/src/main/java/org/apache/karaf/minho/boot/service/LifeCycleService.java
index caa567b..1847d4e 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/service/LifeCycleService.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/service/LifeCycleService.java
@@ -17,20 +17,19 @@
*/
package org.apache.karaf.minho.boot.service;
-import lombok.extern.java.Log;
import org.apache.karaf.minho.boot.spi.Service;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Logger;
/**
- * Core LifeCycle service responsible of starting the registered (hooked) services.
+ * Core LifeCycle service responsible for starting the registered (hooked) services.
*/
-@Log
public class LifeCycleService implements Service, AutoCloseable {
-
- private List startCallbacks = new ArrayList<>();
- private List shutdownCallbacks = new ArrayList<>();
+ private final Logger log = Logger.getLogger(LifeCycleService.class.getName());
+ private final List startCallbacks = new ArrayList<>();
+ private final List shutdownCallbacks = new ArrayList<>();
@Override
public String name() {
@@ -46,7 +45,7 @@ public int priority() {
* Add a start callback in the lifecycle.
* @param callback The runnable start callback.
*/
- public void onStart(Runnable callback) {
+ public void onStart(final Runnable callback) {
startCallbacks.add(callback);
}
@@ -54,7 +53,7 @@ public void onStart(Runnable callback) {
* Add a stop callback in the lifecycle.
* @param callback The runnable stop callback.
*/
- public void onShutdown(Runnable callback) {
+ public void onShutdown(final Runnable callback) {
shutdownCallbacks.add(callback);
}
@@ -94,5 +93,4 @@ public void close() {
throw ise;
}
}
-
}
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/service/ServiceRegistry.java b/boot/src/main/java/org/apache/karaf/minho/boot/service/ServiceRegistry.java
index 9530854..cad94a6 100644
--- a/boot/src/main/java/org/apache/karaf/minho/boot/service/ServiceRegistry.java
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/service/ServiceRegistry.java
@@ -17,11 +17,11 @@
*/
package org.apache.karaf.minho.boot.service;
-import lombok.extern.java.Log;
import org.apache.karaf.minho.boot.spi.Service;
-import java.util.*;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
import java.util.stream.Stream;
import static java.util.Optional.ofNullable;
@@ -30,9 +30,8 @@
/**
* Main service registry.
*/
-@Log
public class ServiceRegistry implements AutoCloseable {
-
+ private final Logger log = Logger.getLogger(LifeCycleService.class.getName());
private final Map, Service> registry = new ConcurrentHashMap<>();
public Map, Service> getAll() {
@@ -79,16 +78,17 @@ public Stream findByType(final Class serviceClass) {
* @return true if the service has been added, false else.
*/
public boolean add(final Service service) {
- boolean added = registry.putIfAbsent(service.getClass(), service) == null;
- if (added) {
- log.info("Adding " + service.name() + " service (" + service.priority() + ")");
- try {
- service.onRegister(this);
- } catch (Exception e) {
- throw new IllegalStateException("Can't register " + service.name(), e);
- }
+ if (registry.putIfAbsent(service.getClass(), service) != null) {
+ return false;
+ }
+
+ log.info(() -> "Adding " + service.name() + " service (" + service.priority() + ")");
+ try {
+ service.onRegister(this);
+ } catch (final Exception e) {
+ throw new IllegalStateException("Can't register " + service.name(), e);
}
- return added;
+ return true;
}
/**
@@ -106,7 +106,7 @@ public void remove(final Service service) {
@Override
public void close() {
log.info("Closing service registry");
- final IllegalStateException ise = new IllegalStateException("Can't stop service registry");
+ final var ise = new IllegalStateException("Can't stop service registry");
registry.values().stream() // we should filter only for lifecycle service as others must use it
.filter(AutoCloseable.class::isInstance)
.map(AutoCloseable.class::cast)
diff --git a/boot/src/main/java/org/apache/karaf/minho/boot/spi/impl/DefaultLoaderService.java b/boot/src/main/java/org/apache/karaf/minho/boot/spi/impl/DefaultLoaderService.java
new file mode 100644
index 0000000..f5651e8
--- /dev/null
+++ b/boot/src/main/java/org/apache/karaf/minho/boot/spi/impl/DefaultLoaderService.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.minho.boot.spi.impl;
+
+import org.apache.karaf.minho.boot.service.ConfigService;
+import org.apache.karaf.minho.boot.spi.Service;
+import org.apache.karaf.minho.boot.spi.ServiceLoader;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toList;
+
+public class DefaultLoaderService implements ServiceLoader {
+ private final List custom = new ArrayList<>();
+
+ public DefaultLoaderService add(final Service service) {
+ custom.add(service);
+ return this;
+ }
+
+ @Override
+ public Stream load() {
+ final var services = Stream.concat(
+ java.util.ServiceLoader.load(Service.class).stream()
+ .map(java.util.ServiceLoader.Provider::get),
+ custom.stream())
+ .collect(toList());
+ final var conf = services.stream().filter(ConfigService.class::isInstance).findFirst();
+ return services.stream()
+ .sorted(Comparator.comparingInt(service -> {
+ final var key = service.name() + ".priority";
+ return conf
+ .map(c -> ofNullable(c.properties().getProperty(key)).map(Integer::parseInt).orElse(service.priority()))
+ .orElseGet(() -> Integer.getInteger(key, service.priority()));
+ }));
+ }
+}
diff --git a/boot/src/main/resources/META-INF/services/org.apache.karaf.minho.boot.spi.Service b/boot/src/main/resources/META-INF/services/org.apache.karaf.minho.boot.spi.Service
index bb7957b..0e1e25e 100644
--- a/boot/src/main/resources/META-INF/services/org.apache.karaf.minho.boot.spi.Service
+++ b/boot/src/main/resources/META-INF/services/org.apache.karaf.minho.boot.spi.Service
@@ -16,6 +16,12 @@
# specific language governing permissions and limitations
# under the License.
#
+
+# IMPORTANT: don't register all services, only minimal ones
+
+# required
org.apache.karaf.minho.boot.service.ConfigService
org.apache.karaf.minho.boot.service.LifeCycleService
-org.apache.karaf.minho.boot.service.ClassLoaderService
+
+# optional
+# org.apache.karaf.minho.boot.service.ClassLoaderService
diff --git a/boot/src/test/java/org/apache/karaf/boot/minho/ConfigTest.java b/boot/src/test/java/org/apache/karaf/boot/minho/ConfigTest.java
index 6cbd742..de7f884 100644
--- a/boot/src/test/java/org/apache/karaf/boot/minho/ConfigTest.java
+++ b/boot/src/test/java/org/apache/karaf/boot/minho/ConfigTest.java
@@ -30,10 +30,10 @@ public void defaultTest() {
Config config = new Config();
config.getProperties().put("foo", "bar");
- Assertions.assertEquals("world", config.getProperty("hello", "world"));
- Assertions.assertEquals("bar", config.getProperty("foo"));
- Assertions.assertEquals("bar.test", config.getProperty("foo.test"));
- Assertions.assertNull(config.getProperty("not.defined"));
+ Assertions.assertEquals("world", config.property("hello", "world"));
+ Assertions.assertEquals("bar", config.property("foo"));
+ Assertions.assertEquals("bar.test", config.property("foo.test"));
+ Assertions.assertNull(config.property("not.defined"));
}
}
diff --git a/boot/src/test/java/org/apache/karaf/boot/minho/MinhoTest.java b/boot/src/test/java/org/apache/karaf/boot/minho/MinhoTest.java
index 21e4755..9595b2f 100644
--- a/boot/src/test/java/org/apache/karaf/boot/minho/MinhoTest.java
+++ b/boot/src/test/java/org/apache/karaf/boot/minho/MinhoTest.java
@@ -21,7 +21,6 @@
import org.apache.karaf.minho.boot.config.Config;
import org.apache.karaf.minho.boot.service.ConfigService;
import org.apache.karaf.minho.boot.service.LifeCycleService;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.stream.Stream;
@@ -48,20 +47,8 @@ void simpleRunWithConfig() {
.start()) {
final var configService = minho.getServiceRegistry().get(Config.class);
assertNotNull(configService);
- assertEquals("bar", configService.getProperty("foo"));
- assertEquals("world", configService.getProperty("hello"));
+ assertEquals("bar", configService.property("foo"));
+ assertEquals("world", configService.property("hello"));
}
}
-
- @Test
- void getInstance() throws Exception {
- Minho minho = Minho.builder().build().start();
-
- Minho instance = Minho.getInstance();
-
- Assertions.assertTrue(minho == instance);
-
- Assertions.assertNotNull(instance.getServiceRegistry().get(ConfigService.class));
- }
-
}
diff --git a/boot/src/test/java/org/apache/karaf/minho/boot/service/InstanceSingletonServiceTest.java b/boot/src/test/java/org/apache/karaf/minho/boot/service/InstanceSingletonServiceTest.java
new file mode 100644
index 0000000..c31849e
--- /dev/null
+++ b/boot/src/test/java/org/apache/karaf/minho/boot/service/InstanceSingletonServiceTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.minho.boot.service;
+
+import org.apache.karaf.minho.boot.Minho;
+import org.apache.karaf.minho.boot.spi.impl.DefaultLoaderService;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+class InstanceSingletonServiceTest {
+ @Test
+ void singleton() {
+ final var holder = new InstanceSingletonService();
+ assertNull(InstanceSingletonService.getInstance());
+ try (final var minho = Minho.builder()
+ .loader(new DefaultLoaderService()
+ .add(holder))
+ .build()
+ .start()) {
+ assertSame(minho, InstanceSingletonService.getInstance());
+ }
+ assertNull(InstanceSingletonService.getInstance());
+ }
+}
diff --git a/pom.xml b/pom.xml
index 6af052b..fc4a2c9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,6 +101,18 @@
minho-http
${project.version}
+
+ io.yupiik.uship
+ json-dependencies
+ 1.0.15
+ pom
+
+
+ io.yupiik.uship
+ backbone-johnzon
+ 1.0.15
+ pom
+
diff --git a/services/minho-banner/src/main/java/org/apache/karaf/minho/banner/WelcomeBannerService.java b/services/minho-banner/src/main/java/org/apache/karaf/minho/banner/WelcomeBannerService.java
index ce16f67..65e6bf8 100644
--- a/services/minho-banner/src/main/java/org/apache/karaf/minho/banner/WelcomeBannerService.java
+++ b/services/minho-banner/src/main/java/org/apache/karaf/minho/banner/WelcomeBannerService.java
@@ -43,8 +43,8 @@ public int priority() {
public void onRegister(ServiceRegistry serviceRegistry) {
if (serviceRegistry.get(ConfigService.class) != null) {
ConfigService configService = serviceRegistry.get(ConfigService.class);
- if (configService.getProperty("minho.banner") != null) {
- log.info(configService.getProperty("minho.banner"));
+ if (configService.property("minho.banner") != null) {
+ log.info(configService.property("minho.banner"));
return;
}
}
diff --git a/services/minho-banner/src/test/java/org/apache/karaf/minho/banner/WelcomeBannerServiceTest.java b/services/minho-banner/src/test/java/org/apache/karaf/minho/banner/WelcomeBannerServiceTest.java
index b54ef5e..f5357a8 100644
--- a/services/minho-banner/src/test/java/org/apache/karaf/minho/banner/WelcomeBannerServiceTest.java
+++ b/services/minho-banner/src/test/java/org/apache/karaf/minho/banner/WelcomeBannerServiceTest.java
@@ -32,9 +32,9 @@ public void defaultBannerTest() throws Exception {
TestHandler testHandler = new TestHandler();
Logger logger = Logger.getLogger("org.apache.karaf.minho.banner");
logger.addHandler(testHandler);
- Minho.builder().build().start();
-
- Assertions.assertTrue(testHandler.getMessages().contains("Apache Karaf Minho 1.x"));
+ try (final var m = Minho.builder().build().start()) {
+ Assertions.assertTrue(testHandler.getMessages().contains("Apache Karaf Minho 1.x"));
+ }
}
@Test
@@ -44,14 +44,13 @@ public void systemPropertyBannerTest() throws Exception {
TestHandler testHandler = new TestHandler();
Logger logger = Logger.getLogger("org.apache.karaf.minho.banner");
logger.addHandler(testHandler);
- Minho.builder().build().start();
-
- Assertions.assertTrue(testHandler.getMessages().contains("My Test Banner"));
+ try (final var m = Minho.builder().build().start()) {
+ Assertions.assertTrue(testHandler.getMessages().contains("My Test Banner"));
+ }
}
- class TestHandler extends Handler {
-
- StringBuilder builder = new StringBuilder();
+ static class TestHandler extends Handler {
+ private final StringBuilder builder = new StringBuilder();
@Override
public void publish(LogRecord record) {
diff --git a/services/minho-camel/src/test/java/org/apache/karaf/minho/camel/CamelServiceTest.java b/services/minho-camel/src/test/java/org/apache/karaf/minho/camel/CamelServiceTest.java
index 6f312b0..ab09c93 100644
--- a/services/minho-camel/src/test/java/org/apache/karaf/minho/camel/CamelServiceTest.java
+++ b/services/minho-camel/src/test/java/org/apache/karaf/minho/camel/CamelServiceTest.java
@@ -32,18 +32,17 @@ public class CamelServiceTest {
public void routeBuilderServiceTest() throws Exception {
CamelService camelService = new CamelService();
MyRouteBuilder routeBuilder = new MyRouteBuilder();
- Minho karaf = Minho.builder().loader(() -> Stream.of(new ConfigService(), new LifeCycleService(), routeBuilder, camelService)).build().start();
+ try (final var karaf = Minho.builder()
+ .loader(() -> Stream.of(new ConfigService(), new LifeCycleService(), routeBuilder, camelService)).build().start()) {
+ MockEndpoint mockEndpoint = camelService.getCamelContext().getEndpoint("mock:test", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+ mockEndpoint.expectedBodiesReceived("Hello world!");
- MockEndpoint mockEndpoint = camelService.getCamelContext().getEndpoint("mock:test", MockEndpoint.class);
- mockEndpoint.expectedMessageCount(1);
- mockEndpoint.expectedBodiesReceived("Hello world!");
+ ProducerTemplate producerTemplate = camelService.getCamelContext().createProducerTemplate();
+ producerTemplate.sendBody("direct:test", "Hello world!");
- ProducerTemplate producerTemplate = camelService.getCamelContext().createProducerTemplate();
- producerTemplate.sendBody("direct:test", "Hello world!");
-
- mockEndpoint.assertIsSatisfied();
-
- karaf.close();
+ mockEndpoint.assertIsSatisfied();
+ }
}
}
diff --git a/services/minho-classpath/src/test/java/org/apache/karaf/minho/classpathprotocolhandler/ClasspathProtocolHandlerTest.java b/services/minho-classpath/src/test/java/org/apache/karaf/minho/classpathprotocolhandler/ClasspathProtocolHandlerTest.java
index 24812e2..5776850 100644
--- a/services/minho-classpath/src/test/java/org/apache/karaf/minho/classpathprotocolhandler/ClasspathProtocolHandlerTest.java
+++ b/services/minho-classpath/src/test/java/org/apache/karaf/minho/classpathprotocolhandler/ClasspathProtocolHandlerTest.java
@@ -18,6 +18,7 @@
package org.apache.karaf.minho.classpathprotocolhandler;
import org.apache.karaf.minho.boot.Minho;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -29,9 +30,16 @@
public class ClasspathProtocolHandlerTest {
+ private static Minho minho;
+
@BeforeAll
- public static void setup() throws Exception {
- Minho karaf = Minho.builder().build().start();
+ public static void setup() {
+ minho = Minho.builder().build().start();
+ }
+
+ @AfterAll
+ public static void teardown() {
+ minho.close();
}
@Test
diff --git a/services/minho-config-json/pom.xml b/services/minho-config-json/pom.xml
index 56573ae..6d0133f 100644
--- a/services/minho-config-json/pom.xml
+++ b/services/minho-config-json/pom.xml
@@ -48,14 +48,14 @@
1.4
- org.apache.geronimo.specs
- geronimo-json_1.1_spec
- 1.5
+ io.yupiik.uship
+ json-dependencies
+ pom
- org.apache.johnzon
- johnzon-jsonb
- 1.2.19
+ io.yupiik.uship
+ backbone-johnzon
+ pom
diff --git a/services/minho-config-json/src/main/java/org/apache/karaf/minho/config/json/JsonConfigLoaderService.java b/services/minho-config-json/src/main/java/org/apache/karaf/minho/config/json/JsonConfigLoaderService.java
index 1cc07a8..65fd509 100644
--- a/services/minho-config-json/src/main/java/org/apache/karaf/minho/config/json/JsonConfigLoaderService.java
+++ b/services/minho-config-json/src/main/java/org/apache/karaf/minho/config/json/JsonConfigLoaderService.java
@@ -22,18 +22,19 @@
import org.apache.karaf.minho.boot.service.ServiceRegistry;
import org.apache.karaf.minho.boot.spi.Service;
-import javax.json.bind.Jsonb;
-import javax.json.bind.JsonbBuilder;
-import java.io.*;
+import jakarta.json.bind.JsonbBuilder;
+import jakarta.json.bind.JsonbConfig;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.nio.file.Files;
+import java.nio.file.Path;
/**
* Load Config from a JSON file.
*/
@Log
public class JsonConfigLoaderService implements Service {
-
- private Jsonb jsonb = null;
-
@Override
public String name() {
return "minho-config-json-service";
@@ -46,44 +47,61 @@ public int priority() {
@Override
public void onRegister(final ServiceRegistry serviceRegistry) throws Exception {
- Config config = null;
- if (System.getenv("MINHO_CONFIG") != null) {
+ final var config = System.getProperty("minho.config");
+ if (config != null) {
+ log.info(() -> "Loading JSON configuration from " + config);
+ try (final var in = Files.newBufferedReader(Path.of(config))) {
+ doMerge(serviceRegistry, loadJson(in));
+ }
+ return;
+ }
+
+ final var envConfigFile = System.getenv("MINHO_CONFIG_FILE");
+ if (envConfigFile != null) {
+ log.info(() -> "Loading JSON configuration from " + envConfigFile);
+ try (final var in = Files.newBufferedReader(Path.of(envConfigFile))) {
+ doMerge(serviceRegistry, loadJson(in));
+ }
+ return;
+ }
+
+ final var envConfig = System.getenv("MINHO_CONFIG");
+ if (envConfig != null) {
log.info("Loading JSON configuration from MINHO_CONFIG env variable");
- StringReader reader = new StringReader(System.getenv("MINHO_CONFIG"));
- config = loadJson(new StringReader(System.getenv("MINHO_CONFIG")));
- } else if (System.getenv("MINHO_CONFIG_FILE") != null) {
- log.info("Loading JSON configuration from " + System.getenv("MINHO_CONFIG_FILE"));
- config = loadJson(new FileInputStream(System.getenv("MINHO_CONFIG_FILE")));
- } else if (System.getProperty("minho.config") != null) {
- log.info("Loading JSON configuration from " + System.getProperty("minho.config"));
- config = loadJson(new FileInputStream(System.getProperty("minho.config")));
- } else if (JsonConfigLoaderService.class.getResourceAsStream("/META-INF/minho.json") != null) {
+ try (final var reader = new StringReader(envConfig)) {
+ doMerge(serviceRegistry, loadJson(reader));
+ }
+ return;
+ }
+
+ final var metaInfMinHo = JsonConfigLoaderService.class.getResourceAsStream("/META-INF/minho.json");
+ if (metaInfMinHo != null) {
log.info("Loading JSON configuration from classpath META-INF/minho.json");
- config = loadJson(JsonConfigLoaderService.class.getResourceAsStream("/META-INF/minho.json"));
- } else if (JsonConfigLoaderService.class.getResourceAsStream("/minho.json") != null) {
+ try (final var reader = new InputStreamReader(metaInfMinHo)) {
+ doMerge(serviceRegistry, loadJson(reader));
+ }
+ return;
+ }
+
+ final var rootMinho = JsonConfigLoaderService.class.getResourceAsStream("/minho.json");
+ if (rootMinho != null) {
log.info("Loading JSON configuration from classpath minho.json");
- config = loadJson(JsonConfigLoaderService.class.getResourceAsStream("/minho.json"));
- } else {
- log.info("JSON configuration not found");
+ try (final var reader = new InputStreamReader(rootMinho)) {
+ doMerge(serviceRegistry, loadJson(reader));
+ }
return;
}
- final var existing = serviceRegistry.get(Config.class);
- existing.merge(config);
+ log.info("JSON configuration not found");
}
- private Config loadJson(InputStream inputStream) {
- if (jsonb == null) {
- jsonb = JsonbBuilder.create();
- }
- return jsonb.fromJson(inputStream, Config.class);
+ private void doMerge(final ServiceRegistry serviceRegistry, final Config config) {
+ serviceRegistry.get(Config.class).merge(config);
}
- private Config loadJson(Reader reader) {
- if (jsonb == null) {
- jsonb = JsonbBuilder.create();
+ private Config loadJson(final Reader reader) throws Exception {
+ try (final var jsonb = JsonbBuilder.create(new JsonbConfig().setProperty("johnzon.skip-cdi", true))) {
+ return jsonb.fromJson(reader, Config.class);
}
- return jsonb.fromJson(reader, Config.class);
}
-
}
diff --git a/services/minho-config-json/src/test/java/org/apache/karaf/minho/config/json/JsonConfigLoaderServiceTest.java b/services/minho-config-json/src/test/java/org/apache/karaf/minho/config/json/JsonConfigLoaderServiceTest.java
index 732b58d..a1808ef 100644
--- a/services/minho-config-json/src/test/java/org/apache/karaf/minho/config/json/JsonConfigLoaderServiceTest.java
+++ b/services/minho-config-json/src/test/java/org/apache/karaf/minho/config/json/JsonConfigLoaderServiceTest.java
@@ -22,9 +22,11 @@
import org.apache.karaf.minho.boot.config.Config;
import org.apache.karaf.minho.boot.service.ConfigService;
import org.apache.karaf.minho.boot.service.ServiceRegistry;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class JsonConfigLoaderServiceTest {
@Test
@@ -39,9 +41,9 @@ public void loadingTestFromSystemProp() throws Exception {
Config config = serviceRegistry.get(ConfigService.class);
- Assertions.assertEquals("bar", config.getProperty("foo"));
- Assertions.assertEquals(0, config.getProfiles().size());
- Assertions.assertEquals(0, config.getApplications().size());
+ assertEquals("bar", config.property("foo"));
+ assertEquals(0, config.getProfiles().size());
+ assertEquals(0, config.getApplications().size());
System.clearProperty("minho.config");
}
@@ -57,32 +59,29 @@ public void loadingTestFromClasspath() throws Exception {
Config config = serviceRegistry.get(Config.class);
// properties
- Assertions.assertEquals("bar", config.getProperty("foo"));
- Assertions.assertTrue(Boolean.parseBoolean(config.getProperty("lifecycle.enabled")));
- Assertions.assertEquals("%m %n", config.getProperty("log.patternLayout"));
- Assertions.assertEquals("./osgi/cache", config.getProperty("osgi.storageDirectory"));
- Assertions.assertEquals(1, Long.parseLong(config.getProperty("osgi.priority")));
+ assertEquals("bar", config.property("foo"));
+ assertTrue(Boolean.parseBoolean(config.property("lifecycle.enabled")));
+ assertEquals("%m %n", config.property("log.patternLayout"));
+ assertEquals("./osgi/cache", config.property("osgi.storageDirectory"));
+ assertEquals(1, Long.parseLong(config.property("osgi.priority")));
// profiles
- Assertions.assertEquals(1, config.getProfiles().size());
+ assertEquals(1, config.getProfiles().size());
// applications
- Assertions.assertEquals(2, config.getApplications().size());
+ assertEquals(2, config.getApplications().size());
Application springBootApp = config.getApplications().get(0);
- Assertions.assertEquals("/path/to/app/spring-boot.jar", springBootApp.getUrl());
- Assertions.assertEquals("spring-boot", springBootApp.getType());
- Assertions.assertTrue(Boolean.parseBoolean(springBootApp.getProperty("enableHttp")));
- Assertions.assertTrue(Boolean.parseBoolean(springBootApp.getProperty("enablePrometheus")));
+ assertEquals("/path/to/app/spring-boot.jar", springBootApp.getUrl());
+ assertEquals("spring-boot", springBootApp.getType());
+ assertTrue(Boolean.parseBoolean(springBootApp.property("enableHttp")));
+ assertTrue(Boolean.parseBoolean(springBootApp.property("enablePrometheus")));
}
@Test
- public void runTest() throws Exception {
- Minho minho = Minho.builder().build();
- minho.start();
-
- Config config = minho.getServiceRegistry().get(Config.class);
-
- Assertions.assertEquals(2, config.getApplications().size());
+ public void runTest() {
+ try (final var minho = Minho.builder().build().start()) {
+ final var config = minho.getServiceRegistry().get(Config.class);
+ assertEquals(2, config.getApplications().size());
+ }
}
-
}
diff --git a/services/minho-config-properties/src/main/java/org/apache/karaf/minho/config/properties/PropertiesConfigLoaderService.java b/services/minho-config-properties/src/main/java/org/apache/karaf/minho/config/properties/PropertiesConfigLoaderService.java
index 663a1db..d6d5ce8 100644
--- a/services/minho-config-properties/src/main/java/org/apache/karaf/minho/config/properties/PropertiesConfigLoaderService.java
+++ b/services/minho-config-properties/src/main/java/org/apache/karaf/minho/config/properties/PropertiesConfigLoaderService.java
@@ -25,10 +25,12 @@
import java.io.FileInputStream;
import java.io.StringReader;
-import java.util.List;
-import java.util.Map;
import java.util.Properties;
-import java.util.stream.Collectors;
+
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
/**
* Load Config from a properties.
@@ -49,6 +51,10 @@ public int priority() {
@Override
public void onRegister(final ServiceRegistry serviceRegistry) throws Exception {
Properties properties = new Properties();
+
+ // todo:
+ // - revisit, it uses the same keys than json service so it can't work reliably since both should be usable at the same time
+ // - avoid the leaks -- see json config loader service
if (System.getenv("MINHO_CONFIG") != null) {
log.info("Loading properties from MINHO_CONFIG env variable");
properties.load(new StringReader(System.getenv("MINHO_CONFIG")));
@@ -71,32 +77,32 @@ public void onRegister(final ServiceRegistry serviceRegistry) throws Exception {
}
private Config parse(final Properties properties) {
- Config config = new Config();
+ final var config = new Config();
- properties.keySet().stream().filter(key -> !((String) key).startsWith("application."))
- .forEach(key -> {
- config.getProperties().put(((String) key), properties.get(key).toString());
- });
+ config.getProperties()
+ .putAll(properties.stringPropertyNames().stream()
+ .filter(key -> !key.startsWith("application."))
+ .collect(toMap(identity(), properties::getProperty)));
- List