[java-identity-provider] 02/02: IDP-1299 Name Replacement Property rewriter
Rod Widdowson
rdw at steadingsoftware.com
Wed Jun 6 11:57:38 EDT 2018
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=c785e1d1b1bb0fc606d4b160a2e6b2adadf22586
commit c785e1d1b1bb0fc606d4b160a2e6b2adadf22586
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Jun 6 16:55:12 2018 +0100
IDP-1299 Name Replacement Property rewriter
https://issues.shibboleth.net/jira/browse/IDP-1299
Add the ant task to do the work.
Also tidy up the MergeProperties task with changes found while testing this.
- close all streams (just in case)
- Require specific output file (even if its the input name)
---
.../installer/ant/impl/MergePropertiesTask.java | 17 ++++--
...pertiesTask.java => RewritePropertiesTask.java} | 62 ++++++++++------------
.../resources/net/shibboleth/idp/installer/ant.xml | 1 +
.../idp/installer/TestPropertiesWithComments.java | 1 -
4 files changed, 42 insertions(+), 39 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java
index fe7761c..a135d1a 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java
@@ -73,14 +73,15 @@ public class MergePropertiesTask extends Task {
public void execute() {
if (null == inFile) {
log("Input file not provided", Project.MSG_ERR);
- throw new BuildException("Non-existent input file");
+ throw new BuildException("Input file not provided");
}
if (!inFile.exists()) {
log("Input file " + inFile.getAbsolutePath() + " does not exist");
throw new BuildException("Non-existent input file");
}
if (null == outFile) {
- log("Output file not provided, input taken", Project.MSG_INFO);
+ log("Output file not provided", Project.MSG_ERR);
+ throw new BuildException("Output file not provided");
}
if (null == mergeFile) {
log("Merge file not provided", Project.MSG_ERR);
@@ -94,7 +95,9 @@ public class MergePropertiesTask extends Task {
final PropertiesWithComments in = new PropertiesWithComments();
try {
- in.load(new FileInputStream(inFile));
+ final FileInputStream stream = new FileInputStream(inFile);
+ in.load(stream);
+ stream.close();
} catch (final IOException e) {
log("Could not load input " + inFile.getAbsolutePath(), e, Project.MSG_ERR);
throw new BuildException(e);
@@ -102,7 +105,9 @@ public class MergePropertiesTask extends Task {
final Properties merge = new Properties();
try {
- merge.load(new FileInputStream(mergeFile));
+ final FileInputStream stream = new FileInputStream(mergeFile);
+ merge.load(stream);
+ stream.close();
} catch (final IOException e) {
log("Could not load merge " + mergeFile.getAbsolutePath(), e, Project.MSG_ERR);
throw new BuildException(e);
@@ -117,7 +122,9 @@ public class MergePropertiesTask extends Task {
}
try {
- in.store(new FileOutputStream(outFile));
+ final FileOutputStream stream = new FileOutputStream(outFile);
+ in.store(stream);
+ stream.close();
} catch (final IOException e) {
log("Could not store output " + outFile.getAbsolutePath(), e, Project.MSG_ERR);
throw new BuildException(e);
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/RewritePropertiesTask.java
similarity index 66%
copy from idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java
copy to idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/RewritePropertiesTask.java
index fe7761c..bda46fc 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/MergePropertiesTask.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/RewritePropertiesTask.java
@@ -21,7 +21,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.Properties;
+import java.io.InputStream;
import javax.annotation.Nonnull;
@@ -33,9 +33,9 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
/**
- * A class to merge a property file into another property file, preserving the comments.
+ * A class to rename the property names in a property file, preserving the comments.
*/
-public class MergePropertiesTask extends Task {
+public class RewritePropertiesTask extends Task {
/** The input file. */
private File inFile;
@@ -43,8 +43,8 @@ public class MergePropertiesTask extends Task {
/** The output file. */
private File outFile;
- /** The merge file. */
- private File mergeFile;
+ /** The names file. */
+ private File propertyNameFile;
/** Set the input file.
* @param what what to set
@@ -63,65 +63,61 @@ public class MergePropertiesTask extends Task {
/** Set the merge file.
* @param what what to set
*/
- public void setMergeFile(@Nonnull final File what) {
- mergeFile = Constraint.isNotNull(what, "Provided file must not be null");
+ public void setPropertyNameFile(@Nonnull final File what) {
+ propertyNameFile = Constraint.isNotNull(what, "Provided file must not be null");
}
/** {@inheritDoc} */
- // Checkstyle: CyclomaticComplexity OFF
@Override
public void execute() {
if (null == inFile) {
log("Input file not provided", Project.MSG_ERR);
- throw new BuildException("Non-existent input file");
+ throw new BuildException("Input file not provided");
}
if (!inFile.exists()) {
log("Input file " + inFile.getAbsolutePath() + " does not exist");
throw new BuildException("Non-existent input file");
}
if (null == outFile) {
- log("Output file not provided, input taken", Project.MSG_INFO);
+ log("Output file not provided", Project.MSG_ERR);
+ throw new BuildException("Non-existent output file");
}
- if (null == mergeFile) {
- log("Merge file not provided", Project.MSG_ERR);
+
+ if (null == propertyNameFile) {
+ log("Property Name file not provided", Project.MSG_ERR);
throw new BuildException("Non-existent input file");
}
- if (!mergeFile.exists()) {
- log("Input file " + mergeFile.getAbsolutePath() + " does not exist");
- throw new BuildException("Non-existent merge file");
+ if (!propertyNameFile.exists()) {
+ log("Input file " + propertyNameFile.getAbsolutePath() + " does not exist");
+ throw new BuildException("Non-existent property file");
}
- final PropertiesWithComments in = new PropertiesWithComments();
-
+ final PropertiesWithComments properties = new PropertiesWithComments();
try {
- in.load(new FileInputStream(inFile));
+ final InputStream in = new FileInputStream(propertyNameFile);
+ properties.loadNameReplacement(in);
+ in.close();
} catch (final IOException e) {
- log("Could not load input " + inFile.getAbsolutePath(), e, Project.MSG_ERR);
+ log("Could not load name replacements " + propertyNameFile.getAbsolutePath(), e, Project.MSG_ERR);
throw new BuildException(e);
}
-
- final Properties merge = new Properties();
+
try {
- merge.load(new FileInputStream(mergeFile));
+ final InputStream in = new FileInputStream(inFile);
+ properties.load(in);
+ in.close();
} catch (final IOException e) {
- log("Could not load merge " + mergeFile.getAbsolutePath(), e, Project.MSG_ERR);
+ log("Could not load input " + inFile.getAbsolutePath(), e, Project.MSG_ERR);
throw new BuildException(e);
}
-
- for (final Object propName:merge.keySet()) {
- if (propName instanceof String) {
- final String name = (String) propName;
- in.replaceProperty(name, merge.getProperty(name));
- }
- }
-
try {
- in.store(new FileOutputStream(outFile));
+ final FileOutputStream out = new FileOutputStream(outFile);
+ properties.store(out);
+ out.close();
} catch (final IOException e) {
log("Could not store output " + outFile.getAbsolutePath(), e, Project.MSG_ERR);
throw new BuildException(e);
}
}
- // Checkstyle: CyclomaticComplexity ON
}
diff --git a/idp-installer/src/main/resources/net/shibboleth/idp/installer/ant.xml b/idp-installer/src/main/resources/net/shibboleth/idp/installer/ant.xml
index 42d3cd0..2a2bdaf 100644
--- a/idp-installer/src/main/resources/net/shibboleth/idp/installer/ant.xml
+++ b/idp-installer/src/main/resources/net/shibboleth/idp/installer/ant.xml
@@ -3,5 +3,6 @@
<taskdef name="selfsignedcert" classname="net.shibboleth.idp.installer.ant.impl.SelfSignedCertificateGeneratorTask"/>
<taskdef name="keystorestrategy" classname="net.shibboleth.idp.installer.ant.impl.BasicKeystoreKeyStrategyTask"/>
<taskdef name="mergeproperties" classname="net.shibboleth.idp.installer.ant.impl.MergePropertiesTask"/>
+ <taskdef name="rewriteproperties" classname="net.shibboleth.idp.installer.ant.impl.RewritePropertiesTask"/>
<taskdef name="metadatagenerate" classname="net.shibboleth.idp.installer.ant.impl.MetadataGeneratorTask"/>
</antlib>
\ No newline at end of file
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/TestPropertiesWithComments.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/TestPropertiesWithComments.java
index 87a5c8e..bf56cef 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/TestPropertiesWithComments.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/TestPropertiesWithComments.java
@@ -114,5 +114,4 @@ public class TestPropertiesWithComments {
}
-
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list