private List<BootstrapService> getArtifactBootstrapService(Object artifactClassLoader) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException { // Uses reflection to access the class loader as classes were loaded from different class loaders so they cannot be casted ClassLoader classLoader = (ClassLoader) artifactClassLoader.getClass().getMethod("getClassLoader").invoke(artifactClassLoader); final Enumeration<URL> resources = (Enumeration<URL>) classLoader.getClass().getMethod("findResources", String.class).invoke(classLoader, BOOTSTRAP_PROPERTIES); final List<BootstrapService> bootstrapServices = new ArrayList<>(); if (resources.hasMoreElements()) { while (resources.hasMoreElements()) { final URL localResource = resources.nextElement(); final Properties properties = PropertiesUtils.loadProperties(localResource); final PropertiesBootstrapService propertiesBootstrapService = new PropertiesBootstrapService(classLoader, properties); bootstrapServices.add(propertiesBootstrapService); } } return bootstrapServices; } }
/** * Loads the {@link RunnerModuleUtils#EXCLUDED_PROPERTIES_FILE} resources files, merges the entries so only one * {@link Properties} is returned with all values. * * @return a {@link Properties} loaded with the content of the file. * @throws IOException if the properties couldn't load the file. * @throws IllegalStateException if the file couldn't be found. */ public static final Properties getExcludedProperties() throws IllegalStateException, IOException { Properties excludedProperties = new Properties(); discoverProperties(EXCLUDED_PROPERTIES_FILE).stream() .forEach(properties -> properties.forEach((k, v) -> excludedProperties.merge(k, v, (v1, v2) -> v1 + "," + v2))); return excludedProperties; } }
@Test public void testMaskedProperties() { // test nulls assertNull(PropertiesUtils.maskedPropertyValue(null)); assertNull(PropertiesUtils.maskedPropertyValue(new DefaultMapEntry(null, "value"))); assertNull(PropertiesUtils.maskedPropertyValue(new DefaultMapEntry("key", null))); // try non-masked value Map.Entry property = new DefaultMapEntry("secretname", "secret"); assertTrue("secret".equals(PropertiesUtils.maskedPropertyValue(property))); // now mask value PropertiesUtils.registerMaskedPropertyName("secretname"); String masked = PropertiesUtils.maskedPropertyValue(property); assertFalse("secret".equals(masked)); assertTrue(masked.startsWith("*")); }
@Test public void testRemoveXMLNameSpacePrefix() { String temp = "j:namespace"; String result = PropertiesUtils.removeXmlNamespacePrefix(temp); assertEquals("namespace", result); temp = "this-namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("this-namespace", result); temp = "namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); }
@Test public void testRemoveNameSpacePrefix() { String temp = "this.is.a.namespace"; String result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); temp = "this.namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); temp = "namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); temp = "this_is-a-namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("this_is-a-namespace", result); }
buf.append(property.getKey()); buf.append('='); buf.append(maskedPropertyValue(property)); buf.append(lastProperty.getKey().toString()); buf.append('='); buf.append(maskedPropertyValue(lastProperty));
private ObjectBootstrapProperty createObjectBootstrapProperty(BootstrapService bootstrapService, String propertyKey, String propertyValue) { boolean optional = false; String className; Set<ArtifactType> artifactTypesParameterValue = new HashSet<>(asList(APP, DOMAIN, POLICY)); final String value = propertyValue; int index = value.indexOf(","); if (index > -1) { Properties p = PropertiesUtils.getPropertiesFromString(value.substring(index + 1), ','); if (p.containsKey(APPLY_TO_ARTIFACT_TYPE_PARAMETER_KEY)) { artifactTypesParameterValue = stream(((String) p.get(APPLY_TO_ARTIFACT_TYPE_PARAMETER_KEY)).split("\\/")) .map(t -> createFromString(t)) .collect(toSet()); } optional = p.containsKey(OPTIONAL_ATTRIBUTE); className = value.substring(0, index); } else { className = value; } return new ObjectBootstrapProperty(bootstrapService, artifactTypesParameterValue, optional, propertyKey, className); }
@Test public void noPropertiesAreFoundOnEmptyQueryString() { Properties properties = PropertiesUtils.getPropertiesFromQueryString(""); assertThat(properties.size(), is(0)); }
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; }
@Test public void testRemoveXMLNameSpacePrefix() { String temp = "j:namespace"; String result = PropertiesUtils.removeXmlNamespacePrefix(temp); assertEquals("namespace", result); temp = "this-namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("this-namespace", result); temp = "namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); }
public static Map removeNamespaces(Map properties) { HashMap props = new HashMap(properties.size()); Map.Entry entry; for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { entry = (Map.Entry) iter.next(); props.put(removeNamespacePrefix((String) entry.getKey()), entry.getValue()); } return props; }
private TransformerBootstrapProperty createTransformerBootstrapProperty(BootstrapService bootstrapService, String propertyValue) { String transString; String name = null; String returnClassName; boolean optional = false; transString = propertyValue; returnClassName = null; int index = transString.indexOf(","); if (index > -1) { Properties p = PropertiesUtils.getPropertiesFromString(transString.substring(index + 1), ','); name = p.getProperty("name", null); returnClassName = p.getProperty("returnClass", null); optional = p.containsKey(OPTIONAL_ATTRIBUTE); } String mime = null; if (returnClassName != null) { int i = returnClassName.indexOf(":"); if (i > -1) { mime = returnClassName.substring(i + 1); returnClassName = returnClassName.substring(0, i); } } final String className = index == -1 ? transString : transString.substring(0, index); final Map<String, String> properties = new HashMap<>(); properties.put(MIME_TYPE_PROPERTY, mime); properties.put(RETURN_CLASS_PROPERTY, returnClassName); return new TransformerBootstrapProperty(bootstrapService, new HashSet<>(asList(APP, POLICY)), optional, name, className, returnClassName, mime); }
@Test public void noPropertiesAreFoundOnEmptyQueryString() { Properties properties = PropertiesUtils.getPropertiesFromQueryString(""); assertThat(properties.size(), is(0)); }
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; }
void setApplicationProperties(ApplicationDescriptor desc, File appPropsFile) { // ugh, no straightforward way to convert a HashTable to a map Map<String, String> m = new HashMap<>(); if (appPropsFile.exists() && appPropsFile.canRead()) { final Properties props; try { props = PropertiesUtils.loadProperties(appPropsFile.toURI().toURL()); } catch (IOException e) { throw new IllegalArgumentException("Unable to obtain application properties file URL", e); } for (Object key : props.keySet()) { m.put(key.toString(), props.getProperty(key.toString())); } } // Override with any system properties prefixed with "-O" for ("override")) Properties sysProps = System.getProperties(); for (Map.Entry<Object, Object> entry : sysProps.entrySet()) { String key = entry.getKey().toString(); if (key.startsWith(SYSTEM_PROPERTY_OVERRIDE)) { m.put(key.substring(SYSTEM_PROPERTY_OVERRIDE.length()), entry.getValue().toString()); } } desc.setAppProperties(m); }
@Override public List<MuleModule> discover() { List<MuleModule> modules = new LinkedList<>(); Set<String> moduleNames = new HashSet<>(); try { for (Properties moduleProperties : discoverProperties(classLoader, getModulePropertiesFileName())) { final MuleModule module = createModule(moduleProperties); if (moduleNames.contains(module.getName())) { logger.warn(format("Ignoring duplicated module '%s'", module.getName())); } else { moduleNames.add(module.getName()); modules.add(module); } } } catch (IOException e) { throw new RuntimeException("Cannot discover mule modules", e); } return modules; }
@Test public void testMaskedProperties() { // test nulls assertNull(PropertiesUtils.maskedPropertyValue(null)); assertNull(PropertiesUtils.maskedPropertyValue(new DefaultMapEntry(null, "value"))); assertNull(PropertiesUtils.maskedPropertyValue(new DefaultMapEntry("key", null))); // try non-masked value Map.Entry property = new DefaultMapEntry("secretname", "secret"); assertTrue("secret".equals(PropertiesUtils.maskedPropertyValue(property))); // now mask value PropertiesUtils.registerMaskedPropertyName("secretname"); String masked = PropertiesUtils.maskedPropertyValue(property); assertFalse("secret".equals(masked)); assertTrue(masked.startsWith("*")); }
@Test public void testRemoveNameSpacePrefix() { String temp = "this.is.a.namespace"; String result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); temp = "this.namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); temp = "namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("namespace", result); temp = "this_is-a-namespace"; result = PropertiesUtils.removeNamespacePrefix(temp); assertEquals("this_is-a-namespace", result); }
private TransactionFactoryBootstrapProperty createTransactionFactoryBootstrapProperty(BootstrapService bootstrapService, Properties bootstrapProperties, String propertyKey, String propertyValue) throws InitialisationException { String transactionResourceKey = propertyKey.replace(".transaction.factory", TRANSACTION_RESOURCE_SUFFIX); String transactionResource = bootstrapProperties.getProperty(transactionResourceKey); if (transactionResource == null) { throw new InitialisationException(createStaticMessage(format("There is no transaction resource specified for transaction factory %s", propertyKey)), this); } String transactionResourceClassNameProperties = transactionResource; boolean optional = false; int index = transactionResourceClassNameProperties.indexOf(","); if (index > -1) { Properties p = PropertiesUtils.getPropertiesFromString(transactionResourceClassNameProperties.substring(index + 1), ','); optional = p.containsKey(OPTIONAL_ATTRIBUTE); } final String transactionResourceClassName = (index == -1 ? transactionResourceClassNameProperties : transactionResourceClassNameProperties.substring(0, index)); return new TransactionFactoryBootstrapProperty(bootstrapService, singleton(APP), optional, propertyValue, transactionResourceClassName); }
/** * Returns the {@link Properties} with the content of {@code pom.properties} from a given artifact folder. * * @param artifactFolder folder containing the exploded artifact file. * @return the {@link Properties} from the {@value DeployableArtifactDescriptor#MULE_POM_PROPERTIES} file if available * @throws ArtifactDescriptorCreateException if the folder does not contain a {@value DeployableArtifactDescriptor#MULE_POM_PROPERTIES} * file or the file can' be loaded */ public static Properties getPomPropertiesFolder(File artifactFolder) { final File artifactPomProperties = lookupPomPropertiesMavenLocation(artifactFolder); Properties properties; try (InputStream artifactPomPropertiesInputStream = new FileInputStream(artifactPomProperties)) { properties = PropertiesUtils.loadProperties(artifactPomPropertiesInputStream); } catch (IOException e) { throw new ArtifactDescriptorCreateException(format("There was an issue reading '%s' for the artifact '%s'", artifactPomProperties.getName(), artifactFolder.getAbsolutePath()), e); } return properties; }