001
014
015 package com.liferay.portal.tools.propertiesdoc;
016
017 import com.liferay.portal.freemarker.FreeMarkerUtil;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.ReleaseInfo;
020 import com.liferay.portal.tools.ArgumentsUtil;
021
022 import java.io.File;
023 import java.io.FileWriter;
024 import java.io.IOException;
025 import java.io.Writer;
026
027 import java.util.ArrayList;
028 import java.util.HashMap;
029 import java.util.List;
030 import java.util.Map;
031
032
036 public class PropertiesDocIndexBuilder {
037
038 public static void main(String[] args) {
039 try {
040 new PropertiesDocIndexBuilder(args);
041 }
042 catch (Exception e) {
043 e.printStackTrace();
044 }
045 }
046
047 public PropertiesDocIndexBuilder(String[] args) {
048 Map<String, String> arguments = ArgumentsUtil.parseArguments(args);
049
050 String propertiesDirName = GetterUtil.getString(
051 arguments.get("properties.dir"));
052
053 File propertiesDir = new File(propertiesDirName);
054
055 if (!propertiesDir.exists()) {
056 System.out.println(propertiesDirName + " not found");
057
058 return;
059 }
060
061 List<String> propertiesHTMLFileNames = new ArrayList<String>();
062
063 File[] files = propertiesDir.listFiles();
064
065 for (File file : files) {
066 String fileName = file.getName();
067
068 if (fileName.endsWith(".properties.html")) {
069 String propertiesHTMLFileName = fileName.substring(
070 0, fileName.length() - 5);
071
072 propertiesHTMLFileNames.add(propertiesHTMLFileName);
073 }
074 }
075
076 if (propertiesHTMLFileNames.isEmpty()) {
077 System.out.println(
078 "No properties HTML files found in " + propertiesDirName);
079
080 return;
081 }
082
083 Map<String, Object> context = new HashMap<String, Object>();
084
085 context.put("propertiesHTMLFileNames", propertiesHTMLFileNames);
086 context.put("releaseInfoVersion", ReleaseInfo.getVersion());
087
088 try {
089 String indexHTMLFileName = propertiesDirName + "/index.html";
090
091 File indexHTMLFile = new File(indexHTMLFileName);
092
093 System.out.println("Writing " + indexHTMLFile);
094
095 Writer writer = new FileWriter(indexHTMLFile);
096
097 try {
098 FreeMarkerUtil.process(
099 "com/liferay/portal/tools/propertiesdoc/dependencies" +
100 "/index.ftl",
101 context, writer);
102 }
103 catch (Exception e) {
104 e.printStackTrace();
105 }
106
107 writer.flush();
108 }
109 catch (IOException ioe) {
110 ioe.printStackTrace();
111 }
112 }
113
114 }