Skip to content

Commit

Permalink
add logic to look in filesystem if failed to find resource in classpa…
Browse files Browse the repository at this point in the history
…th, update .travis script to deploy automatically
  • Loading branch information
nabsha committed Jun 24, 2019
1 parent c87e9f6 commit 6e25300
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -14,4 +14,5 @@ deploy:
tags: true

after_success:
- mvn -Ptravisci clean test jacoco:report coveralls:report
- mvn -s .travis.settings.xml -Ptravisci clean test jacoco:report coveralls:report
- mvn -s .travis.settings.xml -Prelease --batch-mode release:prepare release:perform
Expand Up @@ -7,10 +7,12 @@
import org.mule.runtime.config.api.dsl.model.ResourceProvider;
import org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProvider;
import org.mule.runtime.config.api.dsl.model.properties.ConfigurationProperty;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

import static java.util.Optional.of;
Expand Down Expand Up @@ -41,8 +43,25 @@ public Mule4PropertyPlaceholderProvider ( String locationParameterValue, boolean
}


/**
* Tries to load properties from classpath first, if not found in classpath then tries to find in file system
* @param file
* @return InputStream to underlying resource
* @throws IOException
*/
protected InputStream getResourceInputStream ( String file ) throws IOException {
return resourceProvider.getResourceAsStream( file );
InputStream is = resourceProvider.getResourceAsStream( file );
// if failed to load from classpath, try loading from file system
if ( is == null ) {
File file1 = new File(file);
if (file1.exists()) {
logger.debug(file + " found in file system");
is = new FileInputStream( file1 );
}
} else {
logger.debug(file + " found in classpath");
}
return is;
}


Expand Down Expand Up @@ -123,7 +142,6 @@ public Optional< ConfigurationProperty > getConfigurationProperty ( String confi

@Override
public String getDescription () {
// TODO change to a meaningful name for error reporting.
return "Custom properties provider";
return "mule4-property-placeholder";
}
}
2 changes: 1 addition & 1 deletion src/test/resources/test-mule-config.xml
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/mule4-property-placeholder http://www.mulesoft.org/schema/mule/mule4-property-placeholder/current/mule-mule4-property-placeholder.xsd">

<mule4-property-placeholder:config name="config" location="config.properties,secret.properties,notfound.properties" ignore-resource-not-found="true" ignore-unresolvable="false" file-encoding="UTF-8" />
<mule4-property-placeholder:config name="config" location="config.properties,secret.properties,/notfound.properties" ignore-resource-not-found="true" ignore-unresolvable="false" file-encoding="UTF-8" />

<object name="testObject" class="com.github.nabsha.mule4.property.provider.TestObject">
<property key="valueFromProperty" value="${testKey}" />
Expand Down

0 comments on commit 6e25300

Please sign in to comment.