Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

BuildWebXml.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit;
  17. import java.io.File;
  18. import java.io.FileInputStream;
  19. import java.io.FileOutputStream;
  20. import java.io.FileReader;
  21. import java.text.MessageFormat;
  22. import java.util.ArrayList;
  23. import java.util.Collections;
  24. import java.util.List;
  25. import java.util.Properties;
  26. public class BuildWebXml {
  27. private static final String PARAMS = "<!-- PARAMS -->";
  28. private static final String [] STRIP_TOKENS = { "<!-- STRIP", "STRIP -->" };
  29. 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";
  30. public static void main(String[] args) throws Exception {
  31. // Read the current Gitblit properties
  32. // TODO extract the comments and inject them into web.xml too
  33. FileInputStream fis = new FileInputStream(new File("distrib/gitblit.properties"));
  34. Properties fileSettings = new Properties();
  35. fileSettings.load(fis);
  36. fis.close();
  37. List<String> keys = new ArrayList<String>(fileSettings.stringPropertyNames());
  38. Collections.sort(keys);
  39. StringBuilder parameters = new StringBuilder();
  40. for (String key : keys) {
  41. if (!skipKey(key)) {
  42. String value = fileSettings.getProperty(key);
  43. parameters.append(MessageFormat.format(PARAM_PATTERN, key, value));
  44. }
  45. }
  46. // Read the prototype web.xml file
  47. File webxml = new File("src/WEB-INF/web.xml");
  48. char [] buffer = new char[(int) webxml.length()];
  49. FileReader reader = new FileReader(webxml);
  50. reader.read(buffer);
  51. reader.close();
  52. String webXmlContent = new String(buffer);
  53. // Insert the Gitblit properties into the prototype web.xml
  54. for (String stripToken:STRIP_TOKENS) {
  55. webXmlContent = webXmlContent.replace(stripToken, "");
  56. }
  57. int idx = webXmlContent.indexOf(PARAMS);
  58. StringBuilder sb = new StringBuilder();
  59. sb.append(webXmlContent.substring(0, idx));
  60. sb.append(parameters.toString());
  61. sb.append(webXmlContent.substring(idx + PARAMS.length()));
  62. // Save the merged web.xml to the war build folder
  63. FileOutputStream os = new FileOutputStream(new File("war/WEB-INF/web.xml"), false);
  64. os.write(sb.toString().getBytes());
  65. os.close();
  66. }
  67. private static boolean skipKey(String key) {
  68. return key.startsWith(Keys.server._ROOT);
  69. }
  70. }