diff options
author | James Moger <james.moger@gitblit.com> | 2011-06-18 09:02:00 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-06-18 09:02:00 -0400 |
commit | 669686f6118544bf2122f1e7f3e39c5dbc9654f5 (patch) | |
tree | dba4697ae73a06f667cf8e04d633e485a22fccc2 | |
parent | b01ca06b8d14634a2890590916450ef0e36f2b3a (diff) | |
download | gitblit-669686f6118544bf2122f1e7f3e39c5dbc9654f5.tar.gz gitblit-669686f6118544bf2122f1e7f3e39c5dbc9654f5.zip |
Improved web.xml builder. Now it includes the parameter comments.
-rw-r--r-- | src/com/gitblit/BuildWebXml.java | 77 |
1 files changed, 55 insertions, 22 deletions
diff --git a/src/com/gitblit/BuildWebXml.java b/src/com/gitblit/BuildWebXml.java index 3b687f6d..557c6a85 100644 --- a/src/com/gitblit/BuildWebXml.java +++ b/src/com/gitblit/BuildWebXml.java @@ -15,51 +15,72 @@ */
package com.gitblit;
+import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import java.util.Properties;
+import java.util.Vector;
public class BuildWebXml {
private static final String PARAMS = "<!-- PARAMS -->";
-
- private static final String [] STRIP_TOKENS = { "<!-- STRIP", "STRIP -->" };
+
+ private static final String[] STRIP_TOKENS = { "<!-- STRIP", "STRIP -->" };
+
+ private static final String COMMENT_PATTERN = "\n\t<!-- {0} -->";
private static final String PARAM_PATTERN = "\n\t<context-param>\n\t\t<param-name>{0}</param-name>\n\t\t<param-value>{1}</param-value>\n\t</context-param>\n";
public static void main(String[] args) throws Exception {
// Read the current Gitblit properties
- // TODO extract the comments and inject them into web.xml too
- FileInputStream fis = new FileInputStream(new File("distrib/gitblit.properties"));
- Properties fileSettings = new Properties();
- fileSettings.load(fis);
- fis.close();
- List<String> keys = new ArrayList<String>(fileSettings.stringPropertyNames());
- Collections.sort(keys);
-
+ BufferedReader propertiesReader = new BufferedReader(new FileReader(new File(
+ "distrib/gitblit.properties")));
+
+ Vector<Setting> settings = new Vector<Setting>();
+ List<String> comments = new ArrayList<String>();
+ String line = null;
+ while ((line = propertiesReader.readLine()) != null) {
+ if (line.length() == 0) {
+ comments.clear();
+ } else {
+ if (line.charAt(0) == '#') {
+ if (line.length() > 1) {
+ comments.add(line.substring(1).trim());
+ }
+ } else {
+ String[] kvp = line.split("=", 2);
+ String key = kvp[0].trim();
+ if (!skipKey(key)) {
+ Setting s = new Setting(key, kvp[1].trim(), comments);
+ settings.add(s);
+ }
+ comments.clear();
+ }
+ }
+ }
+ propertiesReader.close();
+
StringBuilder parameters = new StringBuilder();
- for (String key : keys) {
- if (!skipKey(key)) {
- String value = fileSettings.getProperty(key);
- parameters.append(MessageFormat.format(PARAM_PATTERN, key, value));
+
+ for (Setting setting : settings) {
+ for (String comment : setting.comments) {
+ parameters.append(MessageFormat.format(COMMENT_PATTERN, comment));
}
+ parameters.append(MessageFormat.format(PARAM_PATTERN, setting.name, setting.value));
}
// Read the prototype web.xml file
File webxml = new File("src/WEB-INF/web.xml");
- char [] buffer = new char[(int) webxml.length()];
- FileReader reader = new FileReader(webxml);
- reader.read(buffer);
- reader.close();
+ char[] buffer = new char[(int) webxml.length()];
+ FileReader webxmlReader = new FileReader(webxml);
+ webxmlReader.read(buffer);
+ webxmlReader.close();
String webXmlContent = new String(buffer);
// Insert the Gitblit properties into the prototype web.xml
- for (String stripToken:STRIP_TOKENS) {
+ for (String stripToken : STRIP_TOKENS) {
webXmlContent = webXmlContent.replace(stripToken, "");
}
int idx = webXmlContent.indexOf(PARAMS);
@@ -77,4 +98,16 @@ public class BuildWebXml { private static boolean skipKey(String key) {
return key.startsWith(Keys.server._ROOT);
}
+
+ private static class Setting {
+ final String name;
+ final String value;
+ final List<String> comments;
+
+ Setting(String name, String value, List<String> comments) {
+ this.name = name;
+ this.value = value;
+ this.comments = new ArrayList<String>(comments);
+ }
+ }
}
|