diff --git a/core-tests/src/test/java/org/mule/runtime/core/internal/util/StandaloneServerUtilsTestCase.java b/core-tests/src/test/java/org/mule/runtime/core/internal/util/StandaloneServerUtilsTestCase.java
deleted file mode 100644
index 31ce3296bcb0..000000000000
--- a/core-tests/src/test/java/org/mule/runtime/core/internal/util/StandaloneServerUtilsTestCase.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2023 Salesforce, Inc. All rights reserved.
- * The software in this package is published under the terms of the CPAL v1.0
- * license, a copy of which has been included with this distribution in the
- * LICENSE.txt file.
- */
-package org.mule.runtime.core.internal.util;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.mule.runtime.core.api.config.MuleProperties.MULE_BASE_DIRECTORY_PROPERTY;
-import static org.mule.runtime.core.api.config.MuleProperties.MULE_HOME_DIRECTORY_PROPERTY;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleBase;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleHome;
-import static org.mule.tck.MuleTestUtils.testWithSystemProperty;
-import org.mule.tck.junit4.AbstractMuleTestCase;
-import org.mule.tck.size.SmallTest;
-
-import org.junit.Test;
-
-@SmallTest
-public class StandaloneServerUtilsTestCase extends AbstractMuleTestCase {
-
- private static final String EXPECTED_MULE_HOME_VALUE = "expected-mule-home-value";
- private static final String EXPECTED_MULE_BASE_VALUE = "expected-mule-base-value";
-
- @Test
- public void muleHome() throws Exception {
- testWithSystemProperty(MULE_HOME_DIRECTORY_PROPERTY, EXPECTED_MULE_HOME_VALUE,
- () -> assertThat(getMuleHome().get().getName(), is(EXPECTED_MULE_HOME_VALUE)));
- }
-
- @Test
- public void muleHomeIsNullWhenNotDefined() throws Exception {
- assertThat(getMuleHome().isPresent(), is(false));
- }
-
- @Test
- public void muleBase() throws Exception {
- testWithSystemProperty(MULE_BASE_DIRECTORY_PROPERTY, EXPECTED_MULE_BASE_VALUE,
- () -> assertThat(getMuleBase().get().getName(), is(EXPECTED_MULE_BASE_VALUE)));
- }
-
- @Test
- public void muleBaseReturnsMuleHomeWhenNotSet() throws Exception {
- testWithSystemProperty(MULE_HOME_DIRECTORY_PROPERTY, EXPECTED_MULE_HOME_VALUE,
- () -> assertThat(getMuleBase().get().getName(), is(EXPECTED_MULE_HOME_VALUE)));
- }
-
- @Test
- public void muleBaseReturnsNullIfNetherMuleHomeOrMuleBaseIsSet() throws Exception {
- assertThat(getMuleBase().isPresent(), is(false));
- }
-}
diff --git a/core-utils/pom.xml b/core-utils/pom.xml
new file mode 100644
index 000000000000..10e1530598ae
--- /dev/null
+++ b/core-utils/pom.xml
@@ -0,0 +1,77 @@
+
+
+ 4.0.0
+
+ org.mule.runtime
+ mule
+ 4.8.0-SNAPSHOT
+
+ mule-core-utils
+ jar
+ Mule Core Utils
+ Mule server and core utilities
+
+
+ org.mule.runtime.core.utils
+
+ true
+ ../formatter.xml
+
+
+
+
+
+ org.mule.runtime
+ mule-api
+
+
+
+ com.google.guava
+ guava
+
+
+ org.apache.commons
+ commons-collections4
+
+
+ commons-io
+ commons-io
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+ junit
+ junit
+ test
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+ org.hamcrest
+ hamcrest
+ test
+
+
+ io.qameta.allure
+ allure-junit4
+ test
+
+
+ org.mule.tests
+ mule-tests-allure
+ ${project.version}
+ test
+
+
+
diff --git a/core-utils/src/main/java/module-info.java b/core-utils/src/main/java/module-info.java
new file mode 100644
index 000000000000..216a728edb85
--- /dev/null
+++ b/core-utils/src/main/java/module-info.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2023 Salesforce, Inc. All rights reserved.
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+/**
+ * Mule server and core utilities.
+ *
+ * @moduleGraph
+ * @since 4.8
+ */
+module org.mule.runtime.core.utils {
+
+ requires org.mule.runtime.api;
+
+ requires com.google.common;
+ requires org.apache.commons.collections4;
+ requires org.apache.commons.io;
+ requires org.apache.commons.lang3;
+
+ exports org.mule.runtime.core.util.api;
+
+ exports org.mule.runtime.core.util.internal to
+ org.mule.runtime.core,
+ org.mule.runtime.container,
+ org.mule.runtime.deployment.model.impl;
+}
diff --git a/core-utils/src/main/java/org/mule/runtime/core/util/api/PropertiesUtils.java b/core-utils/src/main/java/org/mule/runtime/core/util/api/PropertiesUtils.java
new file mode 100644
index 000000000000..ec04fb58f9e8
--- /dev/null
+++ b/core-utils/src/main/java/org/mule/runtime/core/util/api/PropertiesUtils.java
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2023 Salesforce, Inc. All rights reserved.
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.runtime.core.util.api;
+
+import static org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage;
+import static com.google.common.base.Preconditions.checkArgument;
+
+import static java.lang.String.format;
+import static java.util.Objects.requireNonNull;
+
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+
+import org.mule.runtime.api.exception.MuleRuntimeException;
+import org.mule.runtime.core.util.internal.OrderedProperties;
+
+import java.io.BufferedInputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * PropertiesHelper
is a utility class for manipulating and filtering property Maps.
+ */
+// @ThreadSafe
+public final class PropertiesUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
+
+ // @GuardedBy(itself)
+ private static final List maskedProperties = new CopyOnWriteArrayList<>();
+
+ static {
+ // When printing property lists mask password fields
+ // Users can register their own fields to mask
+ registerMaskedPropertyName("password");
+ }
+
+ /** Do not instanciate. */
+ private PropertiesUtils() {
+ // no-op
+ }
+
+ /**
+ * Register a property name for masking. This will prevent certain values from leaking e.g. into debugging output or logfiles.
+ *
+ * @param name the key of the property to be masked.
+ * @throws IllegalArgumentException is name is null or empty.
+ */
+ public static void registerMaskedPropertyName(String name) {
+ if (!isEmpty(name)) {
+ maskedProperties.add(name);
+ } else {
+ throw new IllegalArgumentException("Cannot mask empty property name.");
+ }
+ }
+
+ /**
+ * Returns the String representation of the property value or a masked String if the property key has been registered previously
+ * via {@link #registerMaskedPropertyName(String)}.
+ *
+ * @param property a key/value pair
+ * @return String of the property value or a "masked" String that hides the contents, or null
if the property, its
+ * key or its value is null
.
+ */
+ public static String maskedPropertyValue(Map.Entry, ?> property) {
+ if (property == null) {
+ return null;
+ }
+
+ Object key = property.getKey();
+ Object value = property.getValue();
+
+ if (key == null || value == null) {
+ return null;
+ }
+
+ if (maskedProperties.contains(key)) {
+ return ("*****");
+ } else {
+ return value.toString();
+ }
+ }
+
+ /**
+ * Read in the properties from a properties file. The file may be on the file system or the classpath.
+ *
+ * @param fileName - The name of the properties file
+ * @param callingClass - The Class which is calling this method. This is used to determine the classpath.
+ * @return a java.util.Properties object containing the properties.
+ */
+ public static synchronized Properties loadProperties(String fileName, final Class> callingClass) throws IOException {
+ InputStream is = requireNonNull(callingClass.getClassLoader().getResourceAsStream(fileName));
+
+ try {
+ return loadProperties(is);
+ } catch (IOException e) {
+ throw new MuleRuntimeException(createStaticMessage("Failed to load resource from fileName: " + fileName + "; callingClass: "
+ + callingClass), e);
+ }
+ }
+
+ public static Properties loadProperties(URL url) throws IOException {
+ requireNonNull(url);
+
+ try {
+ return loadProperties(url.openStream());
+ } catch (IOException e) {
+ throw new MuleRuntimeException(createStaticMessage("Failed to load resource from url: " + url), e);
+ }
+ }
+
+ /**
+ * Load all properties files in the classpath with the given properties file name.
+ */
+ public static Properties loadAllProperties(String fileName, ClassLoader classLoader) {
+ Properties p = new Properties();
+ List resourcesUrl = new ArrayList<>();
+ Enumeration resources;
+ try {
+ resources = classLoader.getResources(fileName);
+ while (resources.hasMoreElements()) {
+ resourcesUrl.add(resources.nextElement());
+ }
+ Collections.sort(resourcesUrl, (url, url1) -> {
+ if ("file".equals(url.getProtocol())) {
+ return 1;
+ }
+ return -1;
+ });
+ for (URL resourceUrl : resourcesUrl) {
+ InputStream in = resourceUrl.openStream();
+ p.load(in);
+ in.close();
+ }
+ } catch (IOException e) {
+ throw new MuleRuntimeException(createStaticMessage("Failed to load resource: " + fileName), e);
+ }
+ return p;
+ }
+
+ public static Properties loadProperties(InputStream is) throws IOException {
+ requireNonNull(is);
+
+ try {
+ Properties props = new Properties();
+ props.load(is);
+ return props;
+ } finally {
+ is.close();
+ }
+ }
+
+ public static String removeXmlNamespacePrefix(String eleName) {
+ int i = eleName.indexOf(':');
+ return (i == -1 ? eleName : eleName.substring(i + 1, eleName.length()));
+ }
+
+ public static String removeNamespacePrefix(String eleName) {
+ int i = eleName.lastIndexOf('.');
+ return (i == -1 ? eleName : eleName.substring(i + 1, eleName.length()));
+ }
+
+ public static Map removeNamespaces(Map properties) {
+ HashMap props = new HashMap(properties.size());
+ Map.Entry entry;
+ for (Object element : properties.entrySet()) {
+ entry = (Map.Entry) element;
+ props.put(removeNamespacePrefix((String) entry.getKey()), entry.getValue());
+
+ }
+ return props;
+ }
+
+ /**
+ * Will create a map of properties where the names have a prefix Allows the callee to supply the target map so a comparator can
+ * be set
+ *
+ * @param props the source set of properties
+ * @param prefix the prefix to filter on
+ * @param newProps return map containing the filtered list of properties or an empty map if no properties matched the prefix
+ */
+ public static void getPropertiesWithPrefix(Map props, String prefix, Map newProps) {
+ if (props == null) {
+ return;
+ }
+
+ for (Object element : props.entrySet()) {
+ Map.Entry entry = (Map.Entry) element;
+ Object key = entry.getKey();
+ if (key.toString().startsWith(prefix)) {
+ newProps.put(key, entry.getValue());
+ }
+ }
+ }
+
+ public static Properties getPropertiesFromQueryString(String query) {
+ Properties props = new Properties();
+
+ if (isEmpty(query)) {
+ return props;
+ }
+
+ query = new StringBuilder(query.length() + 1).append('&').append(query).toString();
+
+ int x = 0;
+ while ((x = addProperty(query, x, '&', props)) != -1);
+
+ return props;
+ }
+
+ public static Properties getPropertiesFromString(String query, char separator) {
+ Properties props = new Properties();
+
+ if (query == null) {
+ return props;
+ }
+
+ query = new StringBuilder(query.length() + 1).append(separator).append(query).toString();
+
+ int x = 0;
+ while ((x = addProperty(query, x, separator, props)) != -1) {
+ // run
+ }
+
+ return props;
+ }
+
+ private static int addProperty(String query, int start, char separator, Properties properties) {
+ int i = query.indexOf(separator, start);
+ int i2 = query.indexOf(separator, i + 1);
+ String pair;
+ if (i > -1 && i2 > -1) {
+ pair = query.substring(i + 1, i2);
+ } else if (i > -1) {
+ pair = query.substring(i + 1);
+ } else {
+ return -1;
+ }
+ int eq = pair.indexOf('=');
+
+ if (eq <= 0) {
+ String key = pair;
+ String value = StringUtils.EMPTY;
+ properties.setProperty(key, value);
+ } else {
+ String key = pair.substring(0, eq);
+ String value = (eq == pair.length() ? StringUtils.EMPTY : pair.substring(eq + 1));
+ properties.setProperty(key, value);
+ }
+ return i2;
+ }
+
+ /**
+ * Discovers properties files available on the classloader that loaded {@link PropertiesUtils} class
+ *
+ * @param resource resource to find. Not empty
+ * @return a non null list of Properties
+ * @throws IOException when a property file cannot be processed
+ */
+ public static List discoverProperties(String resource) throws IOException {
+ return discoverProperties(PropertiesUtils.class.getClassLoader(), resource);
+ }
+
+ /**
+ * Discovers properties files available on the given classloader.
+ *
+ * @param classLoader classloader used to find properties resources. Not null.
+ * @param resource resource to find. Not empty
+ * @return a non null list of Properties
+ * @throws IOException when a property file cannot be processed
+ */
+ public static List discoverProperties(ClassLoader classLoader, String resource) throws IOException {
+ checkArgument(!isEmpty(resource), "Resource cannot be empty");
+ checkArgument(classLoader != null, "ClassLoader cannot be null");
+
+ List result = new LinkedList<>();
+
+ Enumeration allPropertiesResources;
+ try {
+ allPropertiesResources = classLoader.getResources(resource);
+ } catch (IOException e) {
+ throw new IOException(format("Error getting resources '%s' from classLoader '%s'", resource, classLoader.toString()), e);
+ }
+
+ while (allPropertiesResources.hasMoreElements()) {
+ URL propertiesResource = allPropertiesResources.nextElement();
+ if (logger.isDebugEnabled()) {
+ logger.debug("Reading properties from: " + propertiesResource.toString());
+ }
+ Properties properties = new OrderedProperties();
+
+ try (InputStream resourceStream = new BufferedInputStream(propertiesResource.openStream())) {
+ properties.load(resourceStream);
+ } catch (IOException e) {
+ throw new IOException(format("Error loading properties from '%s'", propertiesResource.toString()), e);
+ }
+
+ result.add(properties);
+ }
+
+ return result;
+ }
+}
diff --git a/core/src/main/java/org/mule/runtime/core/internal/util/OrderedProperties.java b/core-utils/src/main/java/org/mule/runtime/core/util/internal/OrderedProperties.java
similarity index 91%
rename from core/src/main/java/org/mule/runtime/core/internal/util/OrderedProperties.java
rename to core-utils/src/main/java/org/mule/runtime/core/util/internal/OrderedProperties.java
index 1669509d64ea..9032069d4d14 100644
--- a/core/src/main/java/org/mule/runtime/core/internal/util/OrderedProperties.java
+++ b/core-utils/src/main/java/org/mule/runtime/core/util/internal/OrderedProperties.java
@@ -4,7 +4,7 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
-package org.mule.runtime.core.internal.util;
+package org.mule.runtime.core.util.internal;
import java.util.Enumeration;
import java.util.LinkedHashSet;
@@ -29,7 +29,7 @@ public Set> entrySet() {
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
- entries.add(new DefaultMapEntry(key, this.getProperty((String) key)));
+ entries.add(new DefaultMapEntry<>(key, this.getProperty((String) key)));
}
return entries;
diff --git a/core/src/main/java/org/mule/runtime/core/internal/util/StandaloneServerUtils.java b/core-utils/src/main/java/org/mule/runtime/core/util/internal/StandaloneServerUtils.java
similarity index 89%
rename from core/src/main/java/org/mule/runtime/core/internal/util/StandaloneServerUtils.java
rename to core-utils/src/main/java/org/mule/runtime/core/util/internal/StandaloneServerUtils.java
index aa82e6f182cd..f23a74367bb3 100644
--- a/core/src/main/java/org/mule/runtime/core/internal/util/StandaloneServerUtils.java
+++ b/core-utils/src/main/java/org/mule/runtime/core/util/internal/StandaloneServerUtils.java
@@ -4,12 +4,10 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
-package org.mule.runtime.core.internal.util;
+package org.mule.runtime.core.util.internal;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
-import static org.mule.runtime.core.api.config.MuleProperties.MULE_BASE_DIRECTORY_PROPERTY;
-import static org.mule.runtime.core.api.config.MuleProperties.MULE_HOME_DIRECTORY_PROPERTY;
import java.io.File;
import java.io.IOException;
@@ -24,6 +22,9 @@
*/
public class StandaloneServerUtils {
+ public static final String MULE_HOME_DIRECTORY_PROPERTY = "mule.home";
+ public static final String MULE_BASE_DIRECTORY_PROPERTY = "mule.base";
+
/**
* @return the MULE_HOME directory of this instance. Returns null if the property is not set
*/
diff --git a/core-tests/src/test/java/org/mule/runtime/core/internal/util/OrderedPropertiesTestCase.java b/core-utils/src/test/java/org/mule/runtime/core/util/internal/OrderedPropertiesTestCase.java
similarity index 92%
rename from core-tests/src/test/java/org/mule/runtime/core/internal/util/OrderedPropertiesTestCase.java
rename to core-utils/src/test/java/org/mule/runtime/core/util/internal/OrderedPropertiesTestCase.java
index 29464341dde8..570ad67e7215 100644
--- a/core-tests/src/test/java/org/mule/runtime/core/internal/util/OrderedPropertiesTestCase.java
+++ b/core-utils/src/test/java/org/mule/runtime/core/util/internal/OrderedPropertiesTestCase.java
@@ -4,10 +4,9 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
-package org.mule.runtime.core.internal.util;
+package org.mule.runtime.core.util.internal;
-import static junit.framework.Assert.assertEquals;
-import org.mule.tck.size.SmallTest;
+import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -16,10 +15,10 @@
import java.util.Properties;
import org.apache.commons.lang3.RandomStringUtils;
+
import org.junit.Before;
import org.junit.Test;
-@SmallTest
public class OrderedPropertiesTestCase {
private final int count = 100;
diff --git a/core-utils/src/test/java/org/mule/runtime/core/util/internal/StandaloneServerUtilsTestCase.java b/core-utils/src/test/java/org/mule/runtime/core/util/internal/StandaloneServerUtilsTestCase.java
new file mode 100644
index 000000000000..e7c3e7070a70
--- /dev/null
+++ b/core-utils/src/test/java/org/mule/runtime/core/util/internal/StandaloneServerUtilsTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2023 Salesforce, Inc. All rights reserved.
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.runtime.core.util.internal;
+
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.MULE_BASE_DIRECTORY_PROPERTY;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.MULE_HOME_DIRECTORY_PROPERTY;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleBase;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleHome;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class StandaloneServerUtilsTestCase {
+
+ private static final String EXPECTED_MULE_HOME_VALUE = "expected-mule-home-value";
+ private static final String EXPECTED_MULE_BASE_VALUE = "expected-mule-base-value";
+
+ @Test
+ public void muleHome() throws Exception {
+ testWithSystemProperty(MULE_HOME_DIRECTORY_PROPERTY, EXPECTED_MULE_HOME_VALUE,
+ () -> assertThat(getMuleHome().get().getName(), is(EXPECTED_MULE_HOME_VALUE)));
+ }
+
+ @Test
+ public void muleHomeIsNullWhenNotDefined() throws Exception {
+ assertThat(getMuleHome().isPresent(), is(false));
+ }
+
+ @Test
+ public void muleBase() throws Exception {
+ testWithSystemProperty(MULE_BASE_DIRECTORY_PROPERTY, EXPECTED_MULE_BASE_VALUE,
+ () -> assertThat(getMuleBase().get().getName(), is(EXPECTED_MULE_BASE_VALUE)));
+ }
+
+ @Test
+ public void muleBaseReturnsMuleHomeWhenNotSet() throws Exception {
+ testWithSystemProperty(MULE_HOME_DIRECTORY_PROPERTY, EXPECTED_MULE_HOME_VALUE,
+ () -> assertThat(getMuleBase().get().getName(), is(EXPECTED_MULE_HOME_VALUE)));
+ }
+
+ @Test
+ public void muleBaseReturnsNullIfNetherMuleHomeOrMuleBaseIsSet() throws Exception {
+ assertThat(getMuleBase().isPresent(), is(false));
+ }
+
+
+ /**
+ * Executes callback with a given system property set and replaces the system property with it's original value once done.
+ * Useful for asserting behaviour that is dependent on the presence of a system property.
+ *
+ * @param propertyName Name of system property to set
+ * @param propertyValue Value of system property
+ * @param callback Callback implementing the the test code and assertions to be run with system property set.
+ * @throws Exception any exception thrown by the execution of callback
+ */
+ public static void testWithSystemProperty(String propertyName, Object propertyValue, Runnable callback)
+ throws Exception {
+ assert propertyName != null && callback != null;
+ Object originalPropertyValue = null;
+ try {
+ if (propertyValue == null) {
+ originalPropertyValue = System.getProperties().remove(propertyName);
+ } else {
+ originalPropertyValue = System.getProperties().put(propertyName, propertyValue);
+ }
+ callback.run();
+ } finally {
+ if (originalPropertyValue == null) {
+ System.getProperties().remove(propertyName);
+ } else {
+ System.getProperties().put(propertyName, originalPropertyValue);
+ }
+ }
+ }
+}
diff --git a/core/pom.xml b/core/pom.xml
index 11108cac5904..fbf28959db99 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -78,6 +78,11 @@
org.mule.runtime
mule-api
+
+ org.mule.runtime
+ mule-core-utils
+ ${project.version}
+
org.mule.runtime
mule-tracer-api
diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java
index 80284ce96314..03ed325fd81f 100644
--- a/core/src/main/java/module-info.java
+++ b/core/src/main/java/module-info.java
@@ -57,6 +57,7 @@
requires org.mule.runtime.dsl.api;
requires org.mule.runtime.artifact.ast;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.metrics.api;
requires org.mule.runtime.tracer.api;
requires org.mule.runtime.tracer.customization.api;
diff --git a/core/src/main/java/org/mule/runtime/core/api/config/DefaultMuleConfiguration.java b/core/src/main/java/org/mule/runtime/core/api/config/DefaultMuleConfiguration.java
index 3a8e7142f3d1..2a85394a0392 100644
--- a/core/src/main/java/org/mule/runtime/core/api/config/DefaultMuleConfiguration.java
+++ b/core/src/main/java/org/mule/runtime/core/api/config/DefaultMuleConfiguration.java
@@ -13,8 +13,8 @@
import static org.mule.runtime.core.api.config.i18n.CoreMessages.initialisationFailure;
import static org.mule.runtime.core.api.config.i18n.CoreMessages.propertyHasInvalidValue;
import static org.mule.runtime.core.api.util.ClassUtils.instantiateClass;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleBase;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleHome;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleBase;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleHome;
import static java.lang.Boolean.parseBoolean;
import static java.lang.String.format;
diff --git a/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java b/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java
index fbddd97a1066..25777e5dcb07 100644
--- a/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java
+++ b/core/src/main/java/org/mule/runtime/core/api/config/MuleProperties.java
@@ -11,6 +11,7 @@
import org.mule.runtime.api.deployment.management.ComponentInitialStateManager;
import org.mule.runtime.api.util.MuleSystemProperties;
import org.mule.runtime.core.internal.connection.DefaultConnectivityTesterFactory;
+import org.mule.runtime.core.util.internal.StandaloneServerUtils;
/**
* MuleProperties
is a set of constants pertaining to Mule properties.
@@ -104,8 +105,8 @@ public class MuleProperties {
// End Connector Service descriptor properties
public static final String MULE_WORKING_DIRECTORY_PROPERTY = "mule.working.dir";
- public static final String MULE_HOME_DIRECTORY_PROPERTY = "mule.home";
- public static final String MULE_BASE_DIRECTORY_PROPERTY = "mule.base";
+ public static final String MULE_HOME_DIRECTORY_PROPERTY = StandaloneServerUtils.MULE_HOME_DIRECTORY_PROPERTY;
+ public static final String MULE_BASE_DIRECTORY_PROPERTY = StandaloneServerUtils.MULE_BASE_DIRECTORY_PROPERTY;
public static final String APP_HOME_DIRECTORY_PROPERTY = "app.home";
public static final String DOMAIN_HOME_DIRECTORY_PROPERTY = "domain.home";
public static final String APP_NAME_PROPERTY = "app.name";
diff --git a/core/src/main/java/org/mule/runtime/core/api/util/PropertiesUtils.java b/core/src/main/java/org/mule/runtime/core/api/util/PropertiesUtils.java
index f8294b2d045d..0c312e85b376 100644
--- a/core/src/main/java/org/mule/runtime/core/api/util/PropertiesUtils.java
+++ b/core/src/main/java/org/mule/runtime/core/api/util/PropertiesUtils.java
@@ -6,68 +6,29 @@
*/
package org.mule.runtime.core.api.util;
-import static org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage;
-import static org.mule.runtime.api.util.Preconditions.checkArgument;
-import static org.mule.runtime.core.api.util.StringUtils.isEmpty;
-
-import static java.lang.String.format;
-
-import org.mule.runtime.api.exception.MuleRuntimeException;
-import org.mule.runtime.api.i18n.I18nMessage;
-import org.mule.runtime.core.api.config.i18n.CoreMessages;
-import org.mule.runtime.core.internal.util.OrderedProperties;
-
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* PropertiesHelper
is a utility class for manipulating and filtering property Maps.
+ *
+ * @deprecated Use {@link org.mule.runtime.core.util.api.PropertiesUtils} instead.
*/
// @ThreadSafe
+@Deprecated
public final class PropertiesUtils {
- private static final Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
-
- // @GuardedBy(itself)
- private static final List maskedProperties = new CopyOnWriteArrayList<>();
-
- static {
- // When printing property lists mask password fields
- // Users can register their own fields to mask
- registerMaskedPropertyName("password");
- }
-
/** Do not instanciate. */
private PropertiesUtils() {
// no-op
}
- /**
- * Register a property name for masking. This will prevent certain values from leaking e.g. into debugging output or logfiles.
- *
- * @param name the key of the property to be masked.
- * @throws IllegalArgumentException is name is null or empty.
- */
public static void registerMaskedPropertyName(String name) {
- if (!isEmpty(name)) {
- maskedProperties.add(name);
- } else {
- throw new IllegalArgumentException("Cannot mask empty property name.");
- }
+ org.mule.runtime.core.util.api.PropertiesUtils.registerMaskedPropertyName(name);
}
/**
@@ -79,22 +40,7 @@ public static void registerMaskedPropertyName(String name) {
* key or its value is null
.
*/
public static String maskedPropertyValue(Map.Entry, ?> property) {
- if (property == null) {
- return null;
- }
-
- Object key = property.getKey();
- Object value = property.getValue();
-
- if (key == null || value == null) {
- return null;
- }
-
- if (maskedProperties.contains(key)) {
- return ("*****");
- } else {
- return value.toString();
- }
+ return org.mule.runtime.core.util.api.PropertiesUtils.maskedPropertyValue(property);
}
/**
@@ -105,96 +51,34 @@ public static String maskedPropertyValue(Map.Entry, ?> property) {
* @return a java.util.Properties object containing the properties.
*/
public static synchronized Properties loadProperties(String fileName, final Class> callingClass) throws IOException {
- InputStream is = IOUtils.getResourceAsStream(fileName, callingClass, /* tryAsFile */true, /* tryAsUrl */false);
- if (is == null) {
- I18nMessage error = CoreMessages.cannotLoadFromClasspath(fileName);
- throw new IOException(error.toString());
- }
-
- try {
- return loadProperties(is);
- } catch (IOException e) {
- throw new MuleRuntimeException(createStaticMessage("Failed to load resource from fileName: " + fileName + "; callingClass: "
- + callingClass), e);
- }
+ return org.mule.runtime.core.util.api.PropertiesUtils.loadProperties(fileName, callingClass);
}
public static Properties loadProperties(URL url) throws IOException {
- if (url == null) {
- I18nMessage error = CoreMessages.objectIsNull("url");
- throw new IOException(error.toString());
- }
-
- try {
- return loadProperties(url.openStream());
- } catch (IOException e) {
- throw new MuleRuntimeException(createStaticMessage("Failed to load resource from url: " + url), e);
- }
+ return org.mule.runtime.core.util.api.PropertiesUtils.loadProperties(url);
}
/**
* Load all properties files in the classpath with the given properties file name.
*/
public static Properties loadAllProperties(String fileName, ClassLoader classLoader) {
- Properties p = new Properties();
- List resourcesUrl = new ArrayList<>();
- Enumeration resources;
- try {
- resources = classLoader.getResources(fileName);
- while (resources.hasMoreElements()) {
- resourcesUrl.add(resources.nextElement());
- }
- Collections.sort(resourcesUrl, (url, url1) -> {
- if ("file".equals(url.getProtocol())) {
- return 1;
- }
- return -1;
- });
- for (URL resourceUrl : resourcesUrl) {
- InputStream in = resourceUrl.openStream();
- p.load(in);
- in.close();
- }
- } catch (IOException e) {
- throw new MuleRuntimeException(createStaticMessage("Failed to load resource: " + fileName), e);
- }
- return p;
+ return org.mule.runtime.core.util.api.PropertiesUtils.loadAllProperties(fileName, classLoader);
}
public static Properties loadProperties(InputStream is) throws IOException {
- if (is == null) {
- I18nMessage error = CoreMessages.objectIsNull("input stream");
- throw new IOException(error.toString());
- }
-
- try {
- Properties props = new Properties();
- props.load(is);
- return props;
- } finally {
- is.close();
- }
+ return org.mule.runtime.core.util.api.PropertiesUtils.loadProperties(is);
}
public static String removeXmlNamespacePrefix(String eleName) {
- int i = eleName.indexOf(':');
- return (i == -1 ? eleName : eleName.substring(i + 1, eleName.length()));
+ return org.mule.runtime.core.util.api.PropertiesUtils.removeXmlNamespacePrefix(eleName);
}
public static String removeNamespacePrefix(String eleName) {
- int i = eleName.lastIndexOf('.');
- return (i == -1 ? eleName : eleName.substring(i + 1, eleName.length()));
+ return org.mule.runtime.core.util.api.PropertiesUtils.removeNamespacePrefix(eleName);
}
public static Map removeNamespaces(Map properties) {
- HashMap props = new HashMap(properties.size());
- Map.Entry entry;
- for (Object element : properties.entrySet()) {
- entry = (Map.Entry) element;
- props.put(removeNamespacePrefix((String) entry.getKey()), entry.getValue());
-
- }
- return props;
+ return org.mule.runtime.core.util.api.PropertiesUtils.removeNamespaces(properties);
}
/**
@@ -206,74 +90,15 @@ public static Map removeNamespaces(Map properties) {
* @param newProps return map containing the filtered list of properties or an empty map if no properties matched the prefix
*/
public static void getPropertiesWithPrefix(Map props, String prefix, Map newProps) {
- if (props == null) {
- return;
- }
-
- for (Object element : props.entrySet()) {
- Map.Entry entry = (Map.Entry) element;
- Object key = entry.getKey();
- if (key.toString().startsWith(prefix)) {
- newProps.put(key, entry.getValue());
- }
- }
+ org.mule.runtime.core.util.api.PropertiesUtils.getPropertiesWithPrefix(props, prefix, newProps);
}
public static Properties getPropertiesFromQueryString(String query) {
- Properties props = new Properties();
-
- if (isEmpty(query)) {
- return props;
- }
-
- query = new StringBuilder(query.length() + 1).append('&').append(query).toString();
-
- int x = 0;
- while ((x = addProperty(query, x, '&', props)) != -1);
-
- return props;
+ return org.mule.runtime.core.util.api.PropertiesUtils.getPropertiesFromQueryString(query);
}
public static Properties getPropertiesFromString(String query, char separator) {
- Properties props = new Properties();
-
- if (query == null) {
- return props;
- }
-
- query = new StringBuilder(query.length() + 1).append(separator).append(query).toString();
-
- int x = 0;
- while ((x = addProperty(query, x, separator, props)) != -1) {
- // run
- }
-
- return props;
- }
-
- private static int addProperty(String query, int start, char separator, Properties properties) {
- int i = query.indexOf(separator, start);
- int i2 = query.indexOf(separator, i + 1);
- String pair;
- if (i > -1 && i2 > -1) {
- pair = query.substring(i + 1, i2);
- } else if (i > -1) {
- pair = query.substring(i + 1);
- } else {
- return -1;
- }
- int eq = pair.indexOf('=');
-
- if (eq <= 0) {
- String key = pair;
- String value = StringUtils.EMPTY;
- properties.setProperty(key, value);
- } else {
- String key = pair.substring(0, eq);
- String value = (eq == pair.length() ? StringUtils.EMPTY : pair.substring(eq + 1));
- properties.setProperty(key, value);
- }
- return i2;
+ return org.mule.runtime.core.util.api.PropertiesUtils.getPropertiesFromString(query, separator);
}
/**
@@ -284,7 +109,7 @@ private static int addProperty(String query, int start, char separator, Properti
* @throws IOException when a property file cannot be processed
*/
public static List discoverProperties(String resource) throws IOException {
- return discoverProperties(PropertiesUtils.class.getClassLoader(), resource);
+ return org.mule.runtime.core.util.api.PropertiesUtils.discoverProperties(resource);
}
/**
@@ -296,34 +121,6 @@ public static List discoverProperties(String resource) throws IOExce
* @throws IOException when a property file cannot be processed
*/
public static List discoverProperties(ClassLoader classLoader, String resource) throws IOException {
- checkArgument(!isEmpty(resource), "Resource cannot be empty");
- checkArgument(classLoader != null, "ClassLoader cannot be null");
-
- List result = new LinkedList<>();
-
- Enumeration allPropertiesResources;
- try {
- allPropertiesResources = classLoader.getResources(resource);
- } catch (IOException e) {
- throw new IOException(format("Error getting resources '%s' from classLoader '%s'", resource, classLoader.toString()), e);
- }
-
- while (allPropertiesResources.hasMoreElements()) {
- URL propertiesResource = allPropertiesResources.nextElement();
- if (logger.isDebugEnabled()) {
- logger.debug("Reading properties from: " + propertiesResource.toString());
- }
- Properties properties = new OrderedProperties();
-
- try (InputStream resourceStream = new BufferedInputStream(propertiesResource.openStream())) {
- properties.load(resourceStream);
- } catch (IOException e) {
- throw new IOException(format("Error loading properties from '%s'", propertiesResource.toString()), e);
- }
-
- result.add(properties);
- }
-
- return result;
+ return org.mule.runtime.core.util.api.PropertiesUtils.discoverProperties(classLoader, resource);
}
}
diff --git a/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/AbstractRegistryBootstrap.java b/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/AbstractRegistryBootstrap.java
index 555ef58b9820..672daabe431b 100644
--- a/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/AbstractRegistryBootstrap.java
+++ b/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/AbstractRegistryBootstrap.java
@@ -24,7 +24,7 @@
import org.mule.runtime.core.api.config.bootstrap.BootstrapService;
import org.mule.runtime.core.api.config.builders.RegistryBootstrap;
import org.mule.runtime.core.api.transformer.Transformer;
-import org.mule.runtime.core.api.util.PropertiesUtils;
+import org.mule.runtime.core.util.api.PropertiesUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
diff --git a/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/ClassLoaderRegistryBootstrapDiscoverer.java b/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/ClassLoaderRegistryBootstrapDiscoverer.java
index 5a8cf9c52140..578f43aa83ac 100644
--- a/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/ClassLoaderRegistryBootstrapDiscoverer.java
+++ b/core/src/main/java/org/mule/runtime/core/internal/config/bootstrap/ClassLoaderRegistryBootstrapDiscoverer.java
@@ -8,7 +8,7 @@
import static org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage;
import static org.mule.runtime.api.util.Preconditions.checkArgument;
-import static org.mule.runtime.core.api.util.PropertiesUtils.discoverProperties;
+import static org.mule.runtime.core.util.api.PropertiesUtils.discoverProperties;
import org.mule.runtime.core.api.config.bootstrap.BootstrapException;
import org.mule.runtime.core.api.config.bootstrap.RegistryBootstrapDiscoverer;
diff --git a/core/src/main/java/org/mule/runtime/core/internal/config/builders/AutoConfigurationBuilder.java b/core/src/main/java/org/mule/runtime/core/internal/config/builders/AutoConfigurationBuilder.java
index 50c516cb3a58..b707f0e4512d 100644
--- a/core/src/main/java/org/mule/runtime/core/internal/config/builders/AutoConfigurationBuilder.java
+++ b/core/src/main/java/org/mule/runtime/core/internal/config/builders/AutoConfigurationBuilder.java
@@ -6,12 +6,14 @@
*/
package org.mule.runtime.core.internal.config.builders;
-import static java.lang.String.format;
-import static org.apache.commons.lang3.StringUtils.substringAfterLast;
import static org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage;
import static org.mule.runtime.core.api.config.i18n.CoreMessages.configurationBuilderNoMatching;
import static org.mule.runtime.core.api.util.ClassUtils.getResource;
-import static org.mule.runtime.core.api.util.PropertiesUtils.loadProperties;
+import static org.mule.runtime.core.util.api.PropertiesUtils.loadProperties;
+
+import static java.lang.String.format;
+
+import static org.apache.commons.lang3.StringUtils.substringAfterLast;
import org.mule.runtime.api.exception.MuleRuntimeException;
import org.mule.runtime.ast.api.ArtifactAst;
diff --git a/modules/artifact-activation/src/main/java/module-info.java b/modules/artifact-activation/src/main/java/module-info.java
index 80f44e0fc8bc..44360eef9a68 100644
--- a/modules/artifact-activation/src/main/java/module-info.java
+++ b/modules/artifact-activation/src/main/java/module-info.java
@@ -17,6 +17,7 @@
requires org.mule.runtime.artifact.ast;
requires org.mule.runtime.artifact.ast.xmlParser;
requires org.mule.runtime.container;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.core;
requires org.mule.runtime.extension.model;
requires org.mule.runtime.extensions.api;
diff --git a/modules/artifact-activation/src/main/java/org/mule/runtime/module/artifact/activation/internal/maven/MavenUtilsForArtifact.java b/modules/artifact-activation/src/main/java/org/mule/runtime/module/artifact/activation/internal/maven/MavenUtilsForArtifact.java
index a7afcd80de20..568674bac20a 100644
--- a/modules/artifact-activation/src/main/java/org/mule/runtime/module/artifact/activation/internal/maven/MavenUtilsForArtifact.java
+++ b/modules/artifact-activation/src/main/java/org/mule/runtime/module/artifact/activation/internal/maven/MavenUtilsForArtifact.java
@@ -12,7 +12,7 @@
import static org.apache.commons.io.FileUtils.listFiles;
import static org.apache.commons.io.filefilter.TrueFileFilter.INSTANCE;
-import org.mule.runtime.core.api.util.PropertiesUtils;
+import org.mule.runtime.core.util.api.PropertiesUtils;
import org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException;
import java.io.File;
diff --git a/modules/container/pom.xml b/modules/container/pom.xml
index 8ec0b1d4713f..908bf1fa775f 100644
--- a/modules/container/pom.xml
+++ b/modules/container/pom.xml
@@ -98,7 +98,7 @@
org.mule.runtime
- mule-core
+ mule-core-utils
${project.version}
diff --git a/modules/container/src/main/java/module-info.java b/modules/container/src/main/java/module-info.java
index dddd69ef89e5..22ced09804d6 100644
--- a/modules/container/src/main/java/module-info.java
+++ b/modules/container/src/main/java/module-info.java
@@ -13,7 +13,7 @@
module org.mule.runtime.container {
requires org.mule.runtime.api;
- requires org.mule.runtime.core;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.jar.handling.utils;
requires org.mule.runtime.artifact;
requires org.mule.runtime.jpms.utils;
diff --git a/modules/container/src/main/java/org/mule/runtime/container/api/MuleFoldersUtil.java b/modules/container/src/main/java/org/mule/runtime/container/api/MuleFoldersUtil.java
index 5fdc2f997261..afd4d4f58de9 100644
--- a/modules/container/src/main/java/org/mule/runtime/container/api/MuleFoldersUtil.java
+++ b/modules/container/src/main/java/org/mule/runtime/container/api/MuleFoldersUtil.java
@@ -6,11 +6,13 @@
*/
package org.mule.runtime.container.api;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleBase;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleHome;
+
import static java.io.File.separator;
-import static org.mule.runtime.api.util.Preconditions.checkArgument;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleBase;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleHome;
-import org.mule.runtime.core.api.util.StringUtils;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
import java.io.File;
@@ -74,7 +76,7 @@ public static File getServicesFolder() {
* @return a {@link File} pointing to the folder that corresponds to the provided service name when installed.
*/
public static File getServiceFolder(String name) {
- checkArgument(!StringUtils.isEmpty(name), "name cannot be empty");
+ checkArgument(!isEmpty(name), "name cannot be empty");
return new File(getServicesFolder(), name);
}
diff --git a/modules/container/src/main/java/org/mule/runtime/container/api/MuleModule.java b/modules/container/src/main/java/org/mule/runtime/container/api/MuleModule.java
index efa642aba282..c69d27cbce0c 100644
--- a/modules/container/src/main/java/org/mule/runtime/container/api/MuleModule.java
+++ b/modules/container/src/main/java/org/mule/runtime/container/api/MuleModule.java
@@ -11,13 +11,14 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableSet;
-import org.mule.runtime.core.api.util.StringUtils;
import org.mule.runtime.jpms.api.MuleContainerModule;
import org.mule.runtime.module.artifact.api.classloader.ExportedService;
import java.util.List;
import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+
/**
* Defines a module on the Mule container as defined by a {@code mule-module.properties} descriptor.
*/
diff --git a/modules/container/src/main/java/org/mule/runtime/container/internal/ClasspathModuleDiscoverer.java b/modules/container/src/main/java/org/mule/runtime/container/internal/ClasspathModuleDiscoverer.java
index 9bb78a094602..0175b775024a 100644
--- a/modules/container/src/main/java/org/mule/runtime/container/internal/ClasspathModuleDiscoverer.java
+++ b/modules/container/src/main/java/org/mule/runtime/container/internal/ClasspathModuleDiscoverer.java
@@ -8,19 +8,19 @@
import static org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage;
import static org.mule.runtime.container.api.MuleFoldersUtil.getModulesTempFolder;
-import static org.mule.runtime.core.api.util.FileUtils.stringToFile;
-import static org.mule.runtime.core.api.util.PropertiesUtils.discoverProperties;
+import static org.mule.runtime.core.util.api.PropertiesUtils.discoverProperties;
import static java.lang.String.format;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.createTempFile;
import static java.util.Collections.emptyList;
import static org.apache.commons.io.FileUtils.cleanDirectory;
+import static org.apache.commons.io.FileUtils.writeStringToFile;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import org.mule.runtime.api.exception.MuleRuntimeException;
import org.mule.runtime.container.api.MuleModule;
-import org.mule.runtime.core.api.util.func.CheckedSupplier;
import org.mule.runtime.jpms.api.MuleContainerModule;
import org.mule.runtime.module.artifact.api.classloader.ExportedService;
@@ -73,22 +73,27 @@ public ClasspathModuleDiscoverer(File temporaryFolder) {
public ClasspathModuleDiscoverer(File temporaryFolder, String modulePropertiesResource) {
this.serviceInterfaceToServiceFile =
- serviceInterface -> wrappingInIllegalStateException(() -> createTempFile(temporaryFolder.toPath(), serviceInterface,
- TMP_FOLDER_SUFFIX).toFile(),
- serviceInterface);
+ serviceInterface -> {
+ try {
+ return createTempFile(temporaryFolder.toPath(), serviceInterface,
+ TMP_FOLDER_SUFFIX).toFile();
+ } catch (Exception e) {
+ throw new IllegalStateException(format("Error creating temporary service provider file for '%s'", serviceInterface),
+ e);
+ }
+ };
this.fileToResource =
- (serviceInterface, serviceFile) -> wrappingInIllegalStateException(() -> serviceFile.toURI().toURL(), serviceInterface);
+ (serviceInterface, serviceFile) -> {
+ try {
+ return serviceFile.toURI().toURL();
+ } catch (Exception e) {
+ throw new IllegalStateException(format("Error creating temporary service provider file for '%s'", serviceInterface),
+ e);
+ }
+ };
this.modulePropertiesResource = modulePropertiesResource;
}
- private T wrappingInIllegalStateException(CheckedSupplier supplier, String serviceInterface) {
- try {
- return supplier.get();
- } catch (Exception e) {
- throw new IllegalStateException(format("Error creating temporary service provider file for '%s'", serviceInterface), e);
- }
- }
-
public ClasspathModuleDiscoverer(Function serviceInterfaceToServiceFile,
BiFunction fileToResource,
String modulePropertiesResource) {
@@ -180,7 +185,7 @@ private List getServicesFromProperty(String exportedPackagesPro
File serviceFile = serviceInterfaceToServiceFile.apply(serviceInterface);
serviceFile.deleteOnExit();
- stringToFile(serviceFile.getAbsolutePath(), serviceImplementation);
+ writeStringToFile(serviceFile, serviceImplementation, UTF_8);
resource = fileToResource.apply(serviceInterface, serviceFile);
} catch (IOException e) {
throw new IllegalStateException(format("Error creating temporary service provider file for '%s'", serviceInterface), e);
diff --git a/modules/deployment-model-impl/src/main/java/module-info.java b/modules/deployment-model-impl/src/main/java/module-info.java
index 00decab9fdd2..05226db51dc4 100644
--- a/modules/deployment-model-impl/src/main/java/module-info.java
+++ b/modules/deployment-model-impl/src/main/java/module-info.java
@@ -17,6 +17,7 @@
requires org.mule.runtime.artifact.activation;
requires org.mule.runtime.artifact.declaration;
requires org.mule.runtime.container;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.core;
requires org.mule.runtime.deployment.model;
requires org.mule.runtime.extension.model;
diff --git a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/application/ApplicationDescriptorFactory.java b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/application/ApplicationDescriptorFactory.java
index 17ec830a7b3d..c92380597db2 100644
--- a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/application/ApplicationDescriptorFactory.java
+++ b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/application/ApplicationDescriptorFactory.java
@@ -13,7 +13,7 @@
import org.mule.runtime.api.deployment.persistence.AbstractMuleArtifactModelJsonSerializer;
import org.mule.runtime.api.deployment.persistence.MuleApplicationModelJsonSerializer;
import org.mule.runtime.core.api.config.bootstrap.ArtifactType;
-import org.mule.runtime.core.api.util.PropertiesUtils;
+import org.mule.runtime.core.util.api.PropertiesUtils;
import org.mule.runtime.module.artifact.api.descriptor.ApplicationDescriptor;
import org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorValidatorBuilder;
import org.mule.runtime.module.artifact.api.descriptor.DescriptorLoaderRepository;
diff --git a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/artifact/ArtifactBootstrapServiceDiscovererConfigurationBuilder.java b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/artifact/ArtifactBootstrapServiceDiscovererConfigurationBuilder.java
index 0a58915ea135..390f2611e9ed 100644
--- a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/artifact/ArtifactBootstrapServiceDiscovererConfigurationBuilder.java
+++ b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/artifact/ArtifactBootstrapServiceDiscovererConfigurationBuilder.java
@@ -6,16 +6,17 @@
*/
package org.mule.runtime.module.deployment.impl.internal.artifact;
-import static org.mule.runtime.api.util.Preconditions.checkArgument;
import static org.mule.runtime.core.api.config.bootstrap.RegistryBootstrapDiscoverer.BOOTSTRAP_PROPERTIES;
+import static java.util.Objects.requireNonNull;
+
import org.mule.runtime.core.api.MuleContext;
import org.mule.runtime.core.api.config.bootstrap.BootstrapService;
import org.mule.runtime.core.api.config.bootstrap.BootstrapServiceDiscoverer;
import org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService;
import org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer;
import org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder;
-import org.mule.runtime.core.api.util.PropertiesUtils;
+import org.mule.runtime.core.util.api.PropertiesUtils;
import org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin;
import java.net.URL;
@@ -46,7 +47,7 @@ public class ArtifactBootstrapServiceDiscovererConfigurationBuilder extends Abst
* @param artifactPlugins artifact plugins deployed inside an artifact. Non null.
*/
public ArtifactBootstrapServiceDiscovererConfigurationBuilder(List artifactPlugins) {
- checkArgument(artifactPlugins != null, "ArtifactPlugins cannot be null");
+ requireNonNull(artifactPlugins, "ArtifactPlugins cannot be null");
this.artifactPlugins = artifactPlugins;
}
diff --git a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/maven/MavenUtils.java b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/maven/MavenUtils.java
index 472c01fb36a2..226287870e5d 100644
--- a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/maven/MavenUtils.java
+++ b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/maven/MavenUtils.java
@@ -7,12 +7,12 @@
package org.mule.runtime.module.deployment.impl.internal.maven;
import static org.mule.runtime.api.util.Preconditions.checkState;
-import static org.mule.runtime.core.internal.util.jar.JarLoadingUtils.loadFileContentFrom;
import static org.mule.runtime.core.internal.util.jar.JarLoadingUtils.getJarConnection;
-import static org.mule.runtime.deployment.model.api.DeployableArtifactDescriptor.MULE_POM;
-import static org.mule.runtime.deployment.model.api.DeployableArtifactDescriptor.MULE_POM_PROPERTIES;
+import static org.mule.runtime.core.internal.util.jar.JarLoadingUtils.loadFileContentFrom;
import static org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor.META_INF;
import static org.mule.runtime.module.artifact.api.descriptor.ArtifactPluginDescriptor.MULE_ARTIFACT_PATH_INSIDE_JAR;
+import static org.mule.runtime.module.artifact.api.descriptor.DeployableArtifactDescriptor.MULE_POM;
+import static org.mule.runtime.module.artifact.api.descriptor.DeployableArtifactDescriptor.MULE_POM_PROPERTIES;
import static org.mule.runtime.module.deployment.impl.internal.util.JarUtils.getUrlWithinJar;
import static org.mule.runtime.module.deployment.impl.internal.util.JarUtils.getUrlsWithinJar;
@@ -22,7 +22,7 @@
import static org.apache.commons.io.filefilter.DirectoryFileFilter.DIRECTORY;
import org.mule.runtime.api.exception.MuleRuntimeException;
-import org.mule.runtime.core.api.util.PropertiesUtils;
+import org.mule.runtime.core.util.api.PropertiesUtils;
import org.mule.runtime.deployment.model.api.DeployableArtifactDescriptor;
import org.mule.runtime.module.artifact.api.descriptor.ArtifactDescriptorCreateException;
@@ -39,7 +39,7 @@
import java.util.Properties;
/**
- * Provides utility methods to wrk with Maven
+ * Provides utility methods to work with Maven
*/
public class MavenUtils {
diff --git a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/util/JarUtils.java b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/util/JarUtils.java
index 87418aee2491..5f4b32e8bd45 100644
--- a/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/util/JarUtils.java
+++ b/modules/deployment-model-impl/src/main/java/org/mule/runtime/module/deployment/impl/internal/util/JarUtils.java
@@ -6,7 +6,7 @@
*/
package org.mule.runtime.module.deployment.impl.internal.util;
-import static org.mule.runtime.core.internal.util.StandaloneServerUtils.getMuleHome;
+import static org.mule.runtime.core.util.internal.StandaloneServerUtils.getMuleHome;
import static java.nio.file.Files.createTempFile;
import static java.util.Optional.empty;
diff --git a/modules/launcher/src/main/java/module-info.java b/modules/launcher/src/main/java/module-info.java
index 4916ae7bfd0b..0106853c97bf 100644
--- a/modules/launcher/src/main/java/module-info.java
+++ b/modules/launcher/src/main/java/module-info.java
@@ -19,6 +19,7 @@
requires org.mule.runtime.artifact.activation;
requires org.mule.runtime.boot.log4j;
requires org.mule.runtime.container;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.core;
requires org.mule.runtime.deployment;
requires org.mule.runtime.deployment.model.impl;
diff --git a/modules/launcher/src/main/java/org/mule/runtime/module/launcher/coreextension/ClasspathMuleCoreExtensionDiscoverer.java b/modules/launcher/src/main/java/org/mule/runtime/module/launcher/coreextension/ClasspathMuleCoreExtensionDiscoverer.java
index 487555a402d0..fa59fa78c097 100644
--- a/modules/launcher/src/main/java/org/mule/runtime/module/launcher/coreextension/ClasspathMuleCoreExtensionDiscoverer.java
+++ b/modules/launcher/src/main/java/org/mule/runtime/module/launcher/coreextension/ClasspathMuleCoreExtensionDiscoverer.java
@@ -9,7 +9,7 @@
import static java.lang.String.format;
import static java.util.Comparator.comparingInt;
import static org.mule.runtime.api.util.Preconditions.checkArgument;
-import static org.mule.runtime.core.api.util.PropertiesUtils.loadProperties;
+import static org.mule.runtime.core.util.api.PropertiesUtils.loadProperties;
import org.mule.runtime.api.exception.MuleException;
import org.mule.runtime.container.api.MuleCoreExtension;
import org.mule.runtime.api.exception.DefaultMuleException;
diff --git a/modules/tls/src/main/java/module-info.java b/modules/tls/src/main/java/module-info.java
index dfa51d848904..aa7c89b4652c 100644
--- a/modules/tls/src/main/java/module-info.java
+++ b/modules/tls/src/main/java/module-info.java
@@ -15,6 +15,7 @@
requires org.mule.runtime.api;
requires org.mule.runtime.container;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.core;
requires org.mule.runtime.dsl.api;
requires org.mule.runtime.extension.model;
diff --git a/modules/tls/src/main/java/org/mule/runtime/module/tls/internal/socket/TlsProperties.java b/modules/tls/src/main/java/org/mule/runtime/module/tls/internal/socket/TlsProperties.java
index 1cffa970698f..75189482bcab 100644
--- a/modules/tls/src/main/java/org/mule/runtime/module/tls/internal/socket/TlsProperties.java
+++ b/modules/tls/src/main/java/org/mule/runtime/module/tls/internal/socket/TlsProperties.java
@@ -7,7 +7,7 @@
package org.mule.runtime.module.tls.internal.socket;
-import static org.mule.runtime.core.api.util.PropertiesUtils.loadProperties;
+import static org.mule.runtime.core.util.api.PropertiesUtils.loadProperties;
import org.mule.runtime.core.api.util.IOUtils;
import org.mule.runtime.core.api.util.StringUtils;
diff --git a/pom.xml b/pom.xml
index 4ed1f61aec2e..a7880610858f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,7 @@
errors
runtime-extension-model
+ core-utils
core
core-tests
modules
diff --git a/tests/functional/src/main/java/org/mule/functional/junit4/TestBootstrapServiceDiscovererConfigurationBuilder.java b/tests/functional/src/main/java/org/mule/functional/junit4/TestBootstrapServiceDiscovererConfigurationBuilder.java
index 9d12920ab4d5..0ec211dcafe7 100644
--- a/tests/functional/src/main/java/org/mule/functional/junit4/TestBootstrapServiceDiscovererConfigurationBuilder.java
+++ b/tests/functional/src/main/java/org/mule/functional/junit4/TestBootstrapServiceDiscovererConfigurationBuilder.java
@@ -7,14 +7,16 @@
package org.mule.functional.junit4;
import static org.mule.runtime.core.internal.config.bootstrap.ClassLoaderRegistryBootstrapDiscoverer.BOOTSTRAP_PROPERTIES;
-import static org.mule.runtime.api.util.Preconditions.checkArgument;
+
+import static java.util.Objects.requireNonNull;
+
import org.mule.runtime.core.api.MuleContext;
import org.mule.runtime.core.api.config.bootstrap.BootstrapService;
import org.mule.runtime.core.api.config.bootstrap.BootstrapServiceDiscoverer;
import org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService;
import org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer;
import org.mule.runtime.core.api.config.builders.AbstractConfigurationBuilder;
-import org.mule.runtime.core.api.util.PropertiesUtils;
+import org.mule.runtime.core.util.api.PropertiesUtils;
import org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader;
import java.io.IOException;
@@ -24,6 +26,7 @@
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
+import java.util.Objects;
import java.util.Properties;
/**
@@ -49,9 +52,9 @@ public class TestBootstrapServiceDiscovererConfigurationBuilder extends Abstract
*/
public TestBootstrapServiceDiscovererConfigurationBuilder(ClassLoader containerClassLoader, ClassLoader executionClassLoader,
List pluginClassLoaders) {
- checkArgument(containerClassLoader != null, "ContainerClassLoader cannot be null");
- checkArgument(executionClassLoader != null, "ExecutionClassLoader cannot be null");
- checkArgument(pluginClassLoaders != null, "PluginClassLoaders cannot be null");
+ requireNonNull(containerClassLoader, "ContainerClassLoader cannot be null");
+ requireNonNull(executionClassLoader, "ExecutionClassLoader cannot be null");
+ requireNonNull(pluginClassLoaders, "PluginClassLoaders cannot be null");
this.containerClassLoader = containerClassLoader;
this.executionClassLoader = executionClassLoader;
this.pluginClassLoaders = pluginClassLoaders;
diff --git a/tests/runner/src/main/java/module-info.java b/tests/runner/src/main/java/module-info.java
index 6cfd0fff5ea4..a91b87fb2c0f 100644
--- a/tests/runner/src/main/java/module-info.java
+++ b/tests/runner/src/main/java/module-info.java
@@ -17,6 +17,7 @@
requires org.mule.sdk.compatibility.api;
requires org.mule.runtime.extensions.api;
requires org.mule.runtime.extension.model;
+ requires org.mule.runtime.core.utils;
requires org.mule.runtime.core;
requires org.mule.runtime.jpms.utils;
requires org.mule.runtime.container;
diff --git a/tests/runner/src/main/java/org/mule/test/runner/utils/RunnerModuleUtils.java b/tests/runner/src/main/java/org/mule/test/runner/utils/RunnerModuleUtils.java
index 02dd2c3bd9db..2e562a0092e6 100644
--- a/tests/runner/src/main/java/org/mule/test/runner/utils/RunnerModuleUtils.java
+++ b/tests/runner/src/main/java/org/mule/test/runner/utils/RunnerModuleUtils.java
@@ -7,7 +7,7 @@
package org.mule.test.runner.utils;
import static org.mule.runtime.api.util.MuleSystemProperties.SYSTEM_PROPERTY_PREFIX;
-import static org.mule.runtime.core.api.util.PropertiesUtils.discoverProperties;
+import static org.mule.runtime.core.util.api.PropertiesUtils.discoverProperties;
import static java.lang.String.format;
import static java.lang.System.getProperty;