[java-identity-provider COMMIT] in /trunk/idp-installer/src: main/java/net/shibboleth/idp/installer/PropertiesWithCom...
noreply at shibboleth.net
noreply at shibboleth.net
Sat Oct 18 12:04:17 EDT 2014
Author: rdw
Date: Sat Oct 18 12:04:17 2014
New Revision: 6742
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=6742&view=rev
Log:
IDP-493 amend property replacement to understand commented line of the form # property=value and replay them appropriately
Modified:
trunk/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
trunk/idp-installer/src/test/java/net/shibboleth/idp/installer/TestPropertiesWithComments.java
trunk/idp-installer/src/test/resources/net/shibboleth/idp/installer/file.properties
Modified: trunk/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java?rev=6742&r1=6741&r2=6742&view=diff
==============================================================================
--- trunk/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java (original)
+++ trunk/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java Sat Oct 18 12:04:17 2014
@@ -31,7 +31,9 @@
import java.util.Map;
import java.util.Properties;
-import net.shibboleth.utilities.java.support.collection.Pair;
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
/**
@@ -44,7 +46,47 @@
private List<Object> contents;
/** The properties bit. */
- private Map<String, Pair<String, String>> properties;
+ private Map<String, CommentedProperty> properties;
+
+ /**
+ * Add a property, either as a key/vsalue pair or as a key/comment pair.
+ *
+ * @param line what to look at
+ * @param isComment whether this is a comment or not.
+ * @throws IOException when badness happens.
+ */
+ protected void addCommentedProperty(@Nonnull @NotEmpty final String line, boolean isComment) throws IOException {
+ final Properties parser = new Properties();
+ final String modifiedLine;
+
+ if (isComment) {
+ modifiedLine = line.substring(1);
+ } else {
+ modifiedLine = line;
+ }
+
+ parser.load(new ByteArrayInputStream(modifiedLine.getBytes()));
+ if (!parser.isEmpty()) {
+ final String propName = StringSupport.trimOrNull(parser.stringPropertyNames().iterator().next());
+ if (propName != null) {
+ final CommentedProperty commentedProperty;
+
+ if (isComment) {
+ commentedProperty = new CommentedProperty(propName, line, true);
+
+ } else {
+ commentedProperty = new CommentedProperty(propName, parser.getProperty(propName), false);
+
+ }
+ properties.put(propName, commentedProperty);
+ contents.add(commentedProperty);
+ }
+ } else {
+ contents.add(line);
+ }
+ parser.clear();
+
+ }
/**
* Read the input stream into our structures.
@@ -53,7 +95,6 @@
* @throws IOException if readline fails
*/
public void load(InputStream input) throws IOException {
- final Properties parser = new Properties();
final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
contents = new ArrayList<>();
properties = new HashMap<>();
@@ -65,26 +106,22 @@
if (what == null) {
contents.add("");
} else if (what.startsWith("#")) {
- contents.add(what);
+ if (what.contains("=")) {
+ addCommentedProperty(s, true);
+ } else {
+ contents.add(what);
+ }
} else {
- parser.load(new ByteArrayInputStream(s.getBytes()));
- if (!parser.isEmpty()) {
- final String propName = StringSupport.trimOrNull(parser.stringPropertyNames().iterator().next());
- if (propName != null) {
- final Pair<String, String> pair = new Pair<>();
- pair.setFirst(propName);
- pair.setSecond(parser.getProperty(propName));
- properties.put(propName, pair);
- contents.add(pair);
- }
- }
- parser.clear();
+
+ addCommentedProperty(s, false);
}
s = reader.readLine();
}
}
-
- /** Put the output to the supplied stream.
+
+ /**
+ * Put the output to the supplied stream.
+ *
* @param output where to write
* @throws IOException is the write fails
*/
@@ -94,11 +131,9 @@
for (Object o : contents) {
if (o instanceof String) {
[... 169 lines stripped ...]
More information about the commits
mailing list