James Moger
2011-07-07 a3f4748183623fa0e92381f3e49c29ebcdcbb56e
Documentation. Generate properties site page at build time.
1 files added
5 files modified
137 ■■■■ changed files
build.xml 12 ●●●● patch | view | raw | blame | history
distrib/gitblit.properties 23 ●●●●● patch | view | raw | blame | history
docs/.gitignore 3 ●●●●● patch | view | raw | blame | history
docs/03_properties.mkd 2 ●●●●● patch | view | raw | blame | history
docs/site_header.html 6 ●●●●● patch | view | raw | blame | history
src/com/gitblit/build/BuildSite.java 91 ●●●●● patch | view | raw | blame | history
build.xml
@@ -382,14 +382,6 @@
            </fileset>
        </copy>
        <!-- Copy google-code-prettify -->
        <mkdir dir="${basedir}/src/com/gitblit/wicket/pages/prettify" />
        <copy todir="${project.site.dir}/prettify">
            <fileset dir="${basedir}/src/com/gitblit/wicket/pages/prettify">
                <exclude name="thumbs.db" />
            </fileset>
        </copy>
        <!-- Generate thumbnails of screenshots -->
        <java classpath="${project.build.dir}" classname="com.gitblit.build.BuildThumbnails">
            <classpath refid="master-classpath" />
@@ -454,10 +446,10 @@
            <arg value="--substitute" />
            <arg value="%JGIT%=${jgit.version}" />
            <arg value="--load" />
            <arg value="--properties" />
            <arg value="%PROPERTIES%=${basedir}/distrib/gitblit.properties" />
        </java>
        </java>
    </target>
        
distrib/gitblit.properties
@@ -22,7 +22,7 @@
# Allow push/pull over http/https with JGit servlet.
# If you do NOT want to allow Git clients to clone/push to Gitblit set this
# to false.  You might want to do this if you are only using ssh:// or git://.
# If you set this false, consider changing the [web.otherUrls] setting to
# If you set this false, consider changing the *web.otherUrls* setting to
# indicate your clone/push urls.
#
# SINCE 0.5.0
@@ -78,10 +78,10 @@
# SINCE 0.5.0
web.siteName =
# If web.authenticateAdminPages=true, users with "admin" role can create
# If *web.authenticateAdminPages*=true, users with "admin" role can create
# repositories, create users, and edit repository metadata.
#
# If web.authenticateAdminPages=false, any user can execute the aforementioned
# If *web.authenticateAdminPages*=false, any user can execute the aforementioned
# functions. 
#
# SINCE 0.5.0 
@@ -113,16 +113,23 @@
# RESTART REQUIRED
web.useClientTimezone = false
# Date and Time formats
# http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
# Short date format
# <http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html>
#
# SINCE 0.5.0
web.datestampShortFormat = yyyy-MM-dd
# Long timestamp format
# <http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html>
#
# SINCE 0.5.0
web.datetimestampLongFormat = EEEE, MMMM d, yyyy h:mm a z
# Mount parameters
# true: http://localhost/commit/myrepo/abcdef
# false: http://localhost/commit/?r=myrepo&h=abcdef
# Mount URL parameters
# This setting controls if pretty or parameter URLs are used.
# i.e.
# if true: http://localhost/commit/myrepo/abcdef
# if false: http://localhost/commit/?r=myrepo&h=abcdef
#
# SINCE 0.5.0
# RESTART REQUIRED
docs/.gitignore
New file
@@ -0,0 +1,3 @@
/site_ad.html
/site_analytics.html
/site_ads.html
docs/03_properties.mkd
@@ -1,4 +1,2 @@
## gitblit.properties
<pre class='prettyprint'>
%PROPERTIES%
</pre>
docs/site_header.html
@@ -27,6 +27,10 @@
        
        <script type="text/javascript" src="prettify/prettify.js"></script>
        <link href="prettify/prettify.css" type="text/css" rel="stylesheet" />
        <!-- Place this tag in your head or just before your close body tag -->
        <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
        <!-- ANALYTICS -->
    </head>
    <body style="width:900px"  onload="prettyPrint()">
@@ -36,6 +40,8 @@
                <img src="./gitblt_25.png" width="79" height="25" alt="gitblit" class="logo"/>
            </a>
            <span style="color:black;">{0}</span>
            <!-- Google Plus One -->
            <g:plusone></g:plusone>
        </div>
        <div class="page_nav">{1}</div>
        <div class="markdown">
src/com/gitblit/build/BuildSite.java
@@ -15,14 +15,17 @@
 */
package com.gitblit.build;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
@@ -52,6 +56,12 @@
 * 
 */
public class BuildSite {
    private final static String CASE_SENSITIVE = "CASE-SENSITIVE";
    private final static String RESTART_REQUIRED = "RESTART REQUIRED";
    private final static String SINCE = "SINCE";
    public static void main(String... args) {
        Params params = new Params();
@@ -99,7 +109,7 @@
        sb.trimToSize();
        String htmlHeader = FileUtils.readContent(new File(params.pageHeader), "\n");
        String htmlAdSnippet = null;
        if (!StringUtils.isEmpty(params.adSnippet)) {
            File snippet = new File(params.adSnippet);
@@ -116,7 +126,7 @@
                String htmlSnippet = FileUtils.readContent(snippet, "\n");
                header = header.replace("<!-- ANALYTICS -->", htmlSnippet);
            }
        }
        }
        final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        final String footer = MessageFormat.format(htmlFooter, "generated " + date);
        for (File file : markdownFiles) {
@@ -132,6 +142,11 @@
                    for (String token : params.substitutions) {
                        String[] kv = token.split("=");
                        content = content.replace(kv[0], kv[1]);
                    }
                    for (String alias : params.properties) {
                        String[] kv = alias.split("=");
                        String loadedContent = generatePropertiesContent(new File(kv[1]));
                        content = content.replace(kv[0], loadedContent);
                    }
                    for (String alias : params.loads) {
                        String[] kv = alias.split("=");
@@ -169,6 +184,63 @@
        return displayName;
    }
    private static String generatePropertiesContent(File propertiesFile) throws Exception {
        // Read the current Gitblit properties
        BufferedReader propertiesReader = new BufferedReader(new FileReader(propertiesFile));
        Vector<Setting> settings = new Vector<Setting>();
        List<String> comments = new ArrayList<String>();
        String line = null;
        while ((line = propertiesReader.readLine()) != null) {
            if (line.length() == 0) {
                Setting s = new Setting("", "", comments);
                settings.add(s);
                comments.clear();
            } else {
                if (line.charAt(0) == '#') {
                    comments.add(line.substring(1).trim());
                } else {
                    String[] kvp = line.split("=", 2);
                    String key = kvp[0].trim();
                    Setting s = new Setting(key, kvp[1].trim(), comments);
                    settings.add(s);
                    comments.clear();
                }
            }
        }
        propertiesReader.close();
        StringBuilder sb = new StringBuilder();
        for (Setting setting : settings) {
            for (String comment : setting.comments) {
                if (comment.contains(SINCE) || comment.contains(RESTART_REQUIRED)
                        || comment.contains(CASE_SENSITIVE)) {
                    sb.append(MessageFormat.format("<span style=\"color:#004000;\"># <i>{0}</i></span>", transformMarkdown(comment)));
                } else {
                    sb.append(MessageFormat.format("<span style=\"color:#004000;\"># {0}</span>", transformMarkdown(comment)));
                }
                sb.append("<br/>\n");
            }
            if (!StringUtils.isEmpty(setting.name)) {
                sb.append(MessageFormat.format("<span style=\"color:#000080;\">{0}</span> = <span style=\"color:#800000;\">{1}</span>", setting.name, StringUtils.escapeForHtml(setting.value, false)));
            }
            sb.append("<br/>\n");
        }
        return sb.toString();
    }
    private static String transformMarkdown(String comment) throws ParseException {
        String md = MarkdownUtils.transformMarkdown(comment);
        if (md.startsWith("<p>")) {
            md = md.substring(3);
        }
        if (md.endsWith("</p>")) {
            md = md.substring(0, md.length() - 4);
        }
        return md;
    }
    private static void usage(JCommander jc, ParameterException t) {
        System.out.println(Constants.getGitBlitVersion());
        System.out.println();
@@ -180,6 +252,18 @@
            jc.usage();
        }
        System.exit(0);
    }
    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);
        }
    }
    @Parameters(separators = " ")
@@ -215,5 +299,8 @@
        @Parameter(names = { "--load" }, description = "%TOKEN%=filename", required = false)
        public List<String> loads = new ArrayList<String>();
        @Parameter(names = { "--properties" }, description = "%TOKEN%=filename", required = false)
        public List<String> properties = new ArrayList<String>();
    }
}