forked from mojohaus/versions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed mojohaus#469 Support.property file in set-property
Possibility to use set-property with `-DpropertiesVersionsFile=test.properties` to set multiple properties.
- Loading branch information
Showing
6 changed files
with
169 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/org/codehaus/mojo/versions/utils/PropertiesVersionsFileReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/test/java/org/codehaus/mojo/versions/utils/PropertiesVersionsFileReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.codehaus.mojo.versions.utils; | ||
|
||
import junit.framework.TestCase; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Test; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
public class PropertiesVersionsFileReaderTest extends TestCase { | ||
|
||
private static final String TEST_PROPERTIES_FILE = "src/test/resources/org/codehaus/mojo/versions/utils/testPropertiesVersionsFile.properties"; | ||
|
||
@Test | ||
public void testRead() { | ||
PropertiesVersionsFileReader reader = new PropertiesVersionsFileReader(TEST_PROPERTIES_FILE); | ||
try { | ||
reader.read(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
int numberOfPropertiesConfig=3; | ||
assertTrue(equalsCvsUnordered("booking-api.version,booking-lib.version,be-air-impl.version", reader.getProperties())); | ||
assertEquals(numberOfPropertiesConfig, reader.getPropertiesConfig().length); | ||
} | ||
|
||
private boolean equalsCvsUnordered(String csvExpected, String csvActual) { | ||
if (StringUtils.isEmpty(csvExpected)) { | ||
return false; | ||
} | ||
Set<String> listExpected = new HashSet<String>(Arrays.asList(csvExpected.split(","))); | ||
Set<String> listActual = new HashSet<String>(Arrays.asList(csvActual.split(","))); | ||
return listExpected.equals(listActual); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/resources/org/codehaus/mojo/versions/utils/testPropertiesVersionsFile.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
booking-api.version=1.2.3 | ||
booking-lib.version=4.5.6 | ||
be-air-impl.version=7.8.9 |