Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core/src/main/java/com/adobe/aio/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
package com.adobe.aio.util;

import com.adobe.aio.exception.AIOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -34,23 +35,25 @@ public static Map<String, String> getMapFromProperties(final Properties properti
return map;
}

public static Optional<Properties> readPropertiesFromFile(final String configFilePath)
throws IOException {
public static Optional<Properties> readPropertiesFromFile(final String configFilePath) {
if (StringUtils.isEmpty(configFilePath)) {
return Optional.empty();
} else {
try (InputStream in = new FileInputStream(configFilePath)) {
return Optional.of(read(in));
} catch (FileNotFoundException e) {
return Optional.empty();
} catch (IOException e) {
throw new AIOException("Unable to load your Properties from File " + configFilePath, e);
}
}
}

public static Properties readPropertiesFromClassPath(final String configClassPath)
throws IOException {
public static Properties readPropertiesFromClassPath(final String configClassPath) {
try (InputStream in = FileUtil.class.getClassLoader().getResourceAsStream(configClassPath)) {
return read(in);
} catch (IOException e) {
throw new AIOException("Unable to load your Properties from class path " + configClassPath, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/adobe/aio/workspace/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public Builder systemEnv() {
return configMap(System.getenv());
}

public Builder propertiesPath(final String propertiesPath) throws IOException {
public Builder propertiesPath(final String propertiesPath) {
return properties(
readPropertiesFromFile(propertiesPath)
.orElse(readPropertiesFromClassPath(propertiesPath)));
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/com/adobe/aio/util/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void testGetMapFromProperties() {
}

@Test
public void testReadPropertiesFromFile() throws Exception {
public void testReadPropertiesFromFile() {
Assert.assertTrue(FileUtil.readPropertiesFromFile("").isEmpty());
Assert.assertTrue(FileUtil.readPropertiesFromFile(null).isEmpty());
}

@Test
public void testReadPropertiesFromClassPath() throws Exception {
public void testReadPropertiesFromClassPath() {
assertEquals(getTestProperties(), FileUtil.readPropertiesFromClassPath(TEST_PROPERTIES_FILE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class WorkspaceTest {
private static final String TEST_PROPERTIES = "workspace.properties";
private static final String TEST_VALUE = "_changeMe";

private static Workspace getTestWorkspaceFromProperties() throws IOException {
private static Workspace getTestWorkspaceFromProperties() {
return Workspace.builder()
.propertiesPath(TEST_PROPERTIES)
.build();
Expand Down

This file was deleted.

Loading