aboutsummaryrefslogtreecommitdiffstats
path: root/utils/provider
diff options
context:
space:
mode:
authorRich Tabedzki <richard.tabedzki@att.com>2018-01-30 21:18:21 +0000
committerRich Tabedzki <richard.tabedzki@att.com>2018-01-31 17:20:48 +0000
commitbbf595ed4b60792db86de93aa3f9707082d5bb1a (patch)
tree8960bc6cddbc446dc6ccf1862e0daa2037c42c3f /utils/provider
parentd3cd4dd5d5f300684be256eb1bf70d750a9a957e (diff)
Upgrade sli/core to Nitrogen
Changes made: * Updated JREFileResolver to retrieve data file from Bundle instead of InputStream. Change-Id: Ib2f93378117afaa2501b870aba513a77073b462f Issue-ID: CCSDK-175 Signed-off-by: Rich Tabedzki <richard.tabedzki@att.com>
Diffstat (limited to 'utils/provider')
-rwxr-xr-xutils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java43
1 files changed, 29 insertions, 14 deletions
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
index 844c6949..8da9b7ef 100755
--- a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
@@ -21,14 +21,13 @@
package org.onap.ccsdk.sli.core.utils;
import java.io.File;
-import java.net.URISyntaxException;
+import java.io.InputStream;
import java.net.URL;
-import java.nio.file.FileSystemNotFoundException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.nio.file.Files;
import java.util.Optional;
+
+import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
-import org.slf4j.LoggerFactory;
/**
* Resolves project properties files relative to the directory identified by the JRE property
@@ -41,9 +40,9 @@ public class JREFileResolver implements PropertiesFileResolver {
*/
private final String successMessage;
- private final Class clazz;
+ private final Class<?> clazz;
- public JREFileResolver(final String successMessage, final Class clazz) {
+ public JREFileResolver(final String successMessage, final Class<?> clazz) {
this.successMessage = successMessage;
this.clazz = clazz;
}
@@ -55,16 +54,32 @@ public class JREFileResolver implements PropertiesFileResolver {
*/
@Override
public Optional<File> resolveFile(final String filename) {
- final URL jreArgumentUrl = FrameworkUtil.getBundle(this.clazz)
- .getResource(filename);
+ final Bundle bundle = FrameworkUtil.getBundle(this.clazz);
+ final File dataFile;
+
try {
- if (jreArgumentUrl == null) {
+ if (bundle == null) {
+ return Optional.empty();
+ }
+
+ URL jreArgumentEntry = bundle.getEntry(filename);
+ if (jreArgumentEntry == null) {
return Optional.empty();
}
- final Path dblibPath = Paths.get(jreArgumentUrl.toURI());
- return Optional.of(dblibPath.resolve(filename).toFile());
- } catch(final URISyntaxException | FileSystemNotFoundException e) {
- LoggerFactory.getLogger(this.getClass()).error("", e);
+
+ dataFile = bundle.getDataFile(filename);
+ if(dataFile.exists()) {
+ dataFile.delete();
+ }
+
+ try (InputStream input = jreArgumentEntry.openStream()){
+ Files.copy(input, dataFile.toPath());
+ } catch(Exception exc) {
+ return Optional.empty();
+ }
+
+ return Optional.of(dataFile);
+ } catch(final Exception e) {
return Optional.empty();
}
}