/
PropertiesVersionsFileReader.java
59 lines (43 loc) · 1.57 KB
/
PropertiesVersionsFileReader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.codehaus.mojo.versions.utils;
import org.codehaus.mojo.versions.Property;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
public class PropertiesVersionsFileReader {
/**
* Commas-separated list of properties
*/
private String propertiesCsv;
private Property[] propertiesConfig;
private String propertyFilePath;
public PropertiesVersionsFileReader(String filePath) {
propertyFilePath = filePath;
}
public void read() throws IOException {
try (InputStream input = new FileInputStream(propertyFilePath)) {
Properties prop = new Properties();
// load a properties file
prop.load(input);
prop.propertyNames();
propertiesCsv = prop.keySet().stream().map(Object::toString).collect(Collectors.joining(","));
List<Property> propertiesConfigList = new ArrayList<>();
prop.forEach((name, version) -> {
Property propertyConfig = new Property((String)name);
propertyConfig.setVersion((String)version);
propertiesConfigList.add(propertyConfig);
});
propertiesConfig = propertiesConfigList.toArray(new Property[0]);
}
}
public String getProperties() {
return propertiesCsv;
}
public Property[] getPropertiesConfig() {
return propertiesConfig;
}
}