<delete dir="${project.build.dir}" />\r
<mkdir dir="${project.build.dir}" />\r
<javac srcdir="${basedir}/src" destdir="${project.build.dir}">\r
- <include name="com/gitblit/Build.java" /> \r
+ <include name="com/gitblit/build/Build.java" /> \r
<include name="com/gitblit/Constants.java" />\r
<include name="com/gitblit/utils/StringUtils.java" /> \r
</javac>\r
- <java classpath="${project.build.dir}" classname="com.gitblit.Build" />\r
+ <java classpath="${project.build.dir}" classname="com.gitblit.build.Build" />\r
\r
<!-- Compile Project -->\r
<path id="master-classpath">\r
</copy>\r
\r
<!-- Build deployment doc pages -->\r
- <java classpath="${project.build.dir}" classname="com.gitblit.BuildSite">\r
+ <java classpath="${project.build.dir}" classname="com.gitblit.build.BuildSite">\r
<classpath refid="master-classpath" />\r
<arg value="--sourceFolder" />\r
<arg value="${basedir}/docs" />\r
</antcall>\r
\r
<!-- Build the WAR web.xml from the prototype web.xml and gitblit.properties --> \r
- <java classpath="${project.build.dir}" classname="com.gitblit.BuildWebXml">\r
+ <java classpath="${project.build.dir}" classname="com.gitblit.build.BuildWebXml">\r
<classpath refid="master-classpath" />\r
\r
<arg value="--sourceFile" />\r
<fileset dir="${project.build.dir}">\r
<exclude name="WEB-INF/web.xml" />\r
<exclude name="com/gitblit/tests/" />\r
- <exclude name="com/gitblit/Build*.class" />\r
+ <exclude name="com/gitblit/build/**" />\r
<exclude name="com/gitblit/GitBlitServer*.class" />\r
<exclude name="com/gitblit/Launcher*.class" />\r
<exclude name="com/gitblit/MakeCertificate*.class" /> \r
</copy>\r
\r
<!-- Generate thumbnails of screenshots -->\r
- <java classpath="${project.build.dir}" classname="com.gitblit.BuildThumbnails">\r
+ <java classpath="${project.build.dir}" classname="com.gitblit.build.BuildThumbnails">\r
<classpath refid="master-classpath" />\r
\r
<arg value="--sourceFolder" />\r
</copy>\r
\r
<!-- Build site pages -->\r
- <java classpath="${project.build.dir}" classname="com.gitblit.BuildSite">\r
+ <java classpath="${project.build.dir}" classname="com.gitblit.build.BuildSite">\r
<classpath refid="master-classpath" />\r
<arg value="--sourceFolder" />\r
<arg value="${basedir}/docs" />\r
+++ /dev/null
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit;\r
-\r
-import java.io.BufferedInputStream;\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.RandomAccessFile;\r
-import java.net.URL;\r
-import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Properties;\r
-\r
-import com.gitblit.utils.StringUtils;\r
-\r
-public class Build {\r
-\r
- public static enum BuildType {\r
- RUNTIME, COMPILETIME;\r
- }\r
-\r
- public static void main(String... args) {\r
- runtime();\r
- compiletime();\r
- buildSettingKeys();\r
- }\r
-\r
- public static void runtime() {\r
- downloadFromApache(MavenObject.JCOMMANDER, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.JETTY, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.SERVLET, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.SLF4JAPI, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.SLF4LOG4J, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.LOG4J, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.WICKET, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.WICKET_EXT, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.WICKET_AUTH_ROLES, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.WICKET_GOOGLE_CHARTS, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.BOUNCYCASTLE, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.BOUNCYCASTLE_MAIL, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.JSCH, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.ROME, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.JDOM, BuildType.RUNTIME);\r
-\r
- downloadFromEclipse(MavenObject.JGIT, BuildType.RUNTIME);\r
- downloadFromEclipse(MavenObject.JGIT_HTTP, BuildType.RUNTIME);\r
- }\r
-\r
- public static void compiletime() {\r
- downloadFromApache(MavenObject.JUNIT, BuildType.RUNTIME);\r
- downloadFromApache(MavenObject.JCOMMANDER, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.JETTY, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.SERVLET, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.SLF4JAPI, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.SLF4LOG4J, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.LOG4J, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.WICKET, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.WICKET_EXT, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.WICKET_AUTH_ROLES, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.WICKET_GOOGLE_CHARTS, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.BOUNCYCASTLE, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.BOUNCYCASTLE_MAIL, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.JSCH, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.ROME, BuildType.COMPILETIME);\r
- downloadFromApache(MavenObject.JDOM, BuildType.COMPILETIME);\r
-\r
- downloadFromEclipse(MavenObject.JGIT, BuildType.COMPILETIME);\r
- downloadFromEclipse(MavenObject.JGIT_HTTP, BuildType.COMPILETIME);\r
-\r
- // needed for site publishing\r
- downloadFromApache(MavenObject.COMMONSNET, BuildType.RUNTIME);\r
- }\r
-\r
- public static void buildSettingKeys() {\r
- // Load all keys\r
- Properties properties = new Properties();\r
- FileInputStream is = null;\r
- try {\r
- is = new FileInputStream(Constants.PROPERTIES_FILE);\r
- properties.load(is);\r
- } catch (Throwable t) {\r
- t.printStackTrace();\r
- } finally {\r
- if (is != null) {\r
- try {\r
- is.close();\r
- } catch (Throwable t) {\r
- // IGNORE\r
- }\r
- }\r
- }\r
- List<String> keys = new ArrayList<String>(properties.stringPropertyNames());\r
- Collections.sort(keys);\r
-\r
- // Determine static key group classes\r
- Map<String, List<String>> staticClasses = new HashMap<String, List<String>>();\r
- staticClasses.put("", new ArrayList<String>());\r
- for (String key : keys) {\r
- String clazz = "";\r
- String field = key;\r
- if (key.indexOf('.') > -1) {\r
- clazz = key.substring(0, key.indexOf('.'));\r
- field = key.substring(key.indexOf('.') + 1);\r
- }\r
- if (!staticClasses.containsKey(clazz)) {\r
- staticClasses.put(clazz, new ArrayList<String>());\r
- }\r
- staticClasses.get(clazz).add(field);\r
- }\r
-\r
- // Assemble Keys source file\r
- StringBuilder sb = new StringBuilder();\r
- sb.append("package com.gitblit;\n");\r
- sb.append('\n');\r
- sb.append("/*\n");\r
- sb.append(" * This class is auto-generated from the properties file.\n");\r
- sb.append(" * Do not version control!\n");\r
- sb.append(" */\n");\r
- sb.append("public final class Keys {\n");\r
- sb.append('\n');\r
- List<String> classSet = new ArrayList<String>(staticClasses.keySet());\r
- Collections.sort(classSet);\r
- for (String clazz : classSet) {\r
- List<String> keySet = staticClasses.get(clazz);\r
- if (clazz.equals("")) {\r
- // root keys\r
- for (String key : keySet) {\r
- sb.append(MessageFormat.format(\r
- "\tpublic static final String {0} = \"{1}\";\n\n",\r
- key.replace('.', '_'), key));\r
- }\r
- } else {\r
- // class keys\r
- sb.append(MessageFormat.format("\tpublic static final class {0} '{'\n\n", clazz));\r
- sb.append(MessageFormat.format(\r
- "\t\tpublic static final String _ROOT = \"{0}\";\n\n", clazz));\r
- for (String key : keySet) {\r
- sb.append(MessageFormat.format(\r
- "\t\tpublic static final String {0} = \"{1}\";\n\n",\r
- key.replace('.', '_'), clazz + "." + key));\r
- }\r
- sb.append("\t}\n\n");\r
- }\r
- }\r
- sb.append('}');\r
-\r
- // Save Keys class definition\r
- try {\r
- File file = new File("src/com/gitblit/Keys.java");\r
- FileWriter fw = new FileWriter(file, false);\r
- fw.write(sb.toString());\r
- fw.close();\r
- } catch (Throwable t) {\r
- t.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- * Download a file from the official Apache Maven repository.\r
- * \r
- * @param mo\r
- * the maven object to download.\r
- * @return\r
- */\r
- private static List<File> downloadFromApache(MavenObject mo, BuildType type) {\r
- return downloadFromMaven("http://repo1.maven.org/maven2/", mo, type);\r
- }\r
-\r
- /**\r
- * Download a file from the official Eclipse Maven repository.\r
- * \r
- * @param mo\r
- * the maven object to download.\r
- * @return\r
- */\r
- private static List<File> downloadFromEclipse(MavenObject mo, BuildType type) {\r
- return downloadFromMaven("http://download.eclipse.org/jgit/maven/", mo, type);\r
- }\r
-\r
- /**\r
- * Download a file from a Maven repository.\r
- * \r
- * @param mo\r
- * the maven object to download.\r
- * @return\r
- */\r
- private static List<File> downloadFromMaven(String mavenRoot, MavenObject mo, BuildType type) {\r
- List<File> downloads = new ArrayList<File>();\r
- String[] jars = { "" };\r
- if (BuildType.RUNTIME.equals(type)) {\r
- jars = new String[] { "" };\r
- } else if (BuildType.COMPILETIME.equals(type)) {\r
- jars = new String[] { "-sources", "-javadoc" };\r
- }\r
- for (String jar : jars) {\r
- File targetFile = mo.getLocalFile("ext", jar);\r
- if (targetFile.exists()) {\r
- downloads.add(targetFile);\r
- continue;\r
- }\r
- String expectedSHA1 = mo.getSHA1(jar);\r
- if (expectedSHA1 == null) {\r
- // skip this jar\r
- continue;\r
- }\r
- float approximateLength = mo.getApproximateLength(jar);\r
- String mavenURL = mavenRoot + mo.getRepositoryPath(jar);\r
- if (!targetFile.getAbsoluteFile().getParentFile().exists()) {\r
- boolean success = targetFile.getAbsoluteFile().getParentFile().mkdirs();\r
- if (!success) {\r
- throw new RuntimeException("Failed to create destination folder structure!");\r
- }\r
- }\r
- ByteArrayOutputStream buff = new ByteArrayOutputStream();\r
- try {\r
- URL url = new URL(mavenURL);\r
- InputStream in = new BufferedInputStream(url.openStream());\r
- byte[] buffer = new byte[4096];\r
- int downloadedLen = 0;\r
- float lastProgress = 0f;\r
-\r
- updateDownload(0, targetFile);\r
- while (true) {\r
- int len = in.read(buffer);\r
- if (len < 0) {\r
- break;\r
- }\r
- downloadedLen += len;\r
- buff.write(buffer, 0, len);\r
- float progress = downloadedLen / approximateLength;\r
- if (progress - lastProgress >= 0.1f) {\r
- lastProgress = progress;\r
- updateDownload(progress, targetFile);\r
- }\r
- }\r
- in.close();\r
- updateDownload(1f, targetFile);\r
-\r
- } catch (IOException e) {\r
- throw new RuntimeException("Error downloading " + mavenURL + " to " + targetFile, e);\r
- }\r
- byte[] data = buff.toByteArray();\r
- String calculatedSHA1 = StringUtils.getSHA1(data);\r
-\r
- System.out.println();\r
-\r
- if (expectedSHA1.length() == 0) {\r
- updateProgress(0, "sha: " + calculatedSHA1);\r
- System.out.println();\r
- } else {\r
- if (!calculatedSHA1.equals(expectedSHA1)) {\r
- throw new RuntimeException("SHA1 checksum mismatch; got: " + calculatedSHA1);\r
- }\r
- }\r
- try {\r
- RandomAccessFile ra = new RandomAccessFile(targetFile, "rw");\r
- ra.write(data);\r
- ra.setLength(data.length);\r
- ra.close();\r
- } catch (IOException e) {\r
- throw new RuntimeException("Error writing to file " + targetFile, e);\r
- }\r
- downloads.add(targetFile);\r
- }\r
- return downloads;\r
- }\r
-\r
- private static void updateDownload(float progress, File file) {\r
- updateProgress(progress, "d/l: " + file.getName());\r
- }\r
-\r
- private static void updateProgress(float progress, String url) {\r
- String anim = "==========";\r
- int width = Math.round(anim.length() * progress);\r
- System.out.print("\r[");\r
- System.out.print(anim.substring(0, width));\r
- for (int i = 0; i < anim.length() - width; i++) {\r
- System.out.print(' ');\r
- }\r
- System.out.print("] " + url);\r
- }\r
-\r
- private static class MavenObject {\r
-\r
- public static final MavenObject JCOMMANDER = new MavenObject("jCommander", "com/beust",\r
- "jcommander", "1.17", 34000, 32000, 141000,\r
- "219a3540f3b27d7cc3b1d91d6ea046cd8723290e",\r
- "0bb50eec177acf0e94d58e0cf07262fe5164331d",\r
- "c7adc475ca40c288c93054e0f4fe58f3a98c0cb5");\r
-\r
- public static final MavenObject JETTY = new MavenObject("Jetty",\r
- "org/eclipse/jetty/aggregate", "jetty-webapp", "7.4.2.v20110526", 1000000, 680000,\r
- 2720000, "56331143afa22d24d9faba96e86e6371b0686c7c",\r
- "9f38230fd589e29c8be0fc3c80fb51c5093c2e1e",\r
- "0d48212889c25252c5c14bef62703e28215d80cc");\r
-\r
- public static final MavenObject SERVLET = new MavenObject("Servlet 2.5", "javax/servlet",\r
- "servlet-api", "2.5", 105000, 158000, 0,\r
- "5959582d97d8b61f4d154ca9e495aafd16726e34",\r
- "021599814ad9a605b86f3e6381571beccd861a32", null);\r
-\r
- public static final MavenObject SLF4JAPI = new MavenObject("SLF4J API", "org/slf4j",\r
- "slf4j-api", "1.6.1", 25500, 45000, 182000,\r
- "6f3b8a24bf970f17289b234284c94f43eb42f0e4",\r
- "46a386136c901748e6a3af67ebde6c22bc6b4524",\r
- "e223571d77769cdafde59040da235842f3326453");\r
-\r
- public static final MavenObject SLF4LOG4J = new MavenObject("SLF4J LOG4J", "org/slf4j",\r
- "slf4j-log4j12", "1.6.1", 9800, 9500, 52400,\r
- "bd245d6746cdd4e6203e976e21d597a46f115802",\r
- "7a26b08b265f55622fa1fed3bda68bbd37a465ba",\r
- "6e4b16bce7994e3692e82002f322a0dd2f32741e");\r
-\r
- public static final MavenObject LOG4J = new MavenObject("Apache LOG4J", "log4j", "log4j",\r
- "1.2.16", 481000, 471000, 1455000, "7999a63bfccbc7c247a9aea10d83d4272bd492c6",\r
- "bf945d1dc995be7fe64923625f842fbb6bf443be",\r
- "78aa1cbf0fa3b259abdc7d87f9f6788d785aac2a");\r
-\r
- public static final MavenObject WICKET = new MavenObject("Apache Wicket",\r
- "org/apache/wicket", "wicket", "1.4.17", 1960000, 1906000, 6818000,\r
- "39815e37a6f56465b2d2c3d3017c4f3bf17db50a",\r
- "a792ebae4123253ffd039c3be49e773f8622f94e",\r
- "f2f244ca72d10081529b017e89d6276eab62c621");\r
-\r
- public static final MavenObject WICKET_EXT = new MavenObject("Apache Wicket Extensions",\r
- "org/apache/wicket", "wicket-extensions", "1.4.17", 1180000, 1118000, 1458000,\r
- "01111d0dbffdc425581b006a43864c22797ce72a",\r
- "f194f40ea6e361bb745dfa22e2f9171eb63a9355",\r
- "bd42e5ba9444a426bb2d7cacce91c6033b663b57");\r
-\r
- public static final MavenObject WICKET_AUTH_ROLES = new MavenObject(\r
- "Apache Wicket Auth Roles", "org/apache/wicket", "wicket-auth-roles", "1.4.17",\r
- 44000, 45000, 166000, "86d20ff32f62d3026213ff11a78555da643bc676",\r
- "37e815350a2d6b97734b250a8a03d8bf3712bba7",\r
- "ac3896368bfb372d178041a4ac3ee2c44f62e21c");\r
-\r
- public static final MavenObject WICKET_GOOGLE_CHARTS = new MavenObject(\r
- "Apache Wicket Google Charts Add-On", "org/wicketstuff", "googlecharts", "1.4.17",\r
- 34000, 18750, 161000, "c567b98b0c5efe4147e77ef2d0d3c2d45c49dea5",\r
- "3d32d958b2f7aa58388af5701ea3aafc433e573f",\r
- "c37518b67ea85af485dd61fe854137eeacc50318");\r
-\r
- public static final MavenObject JUNIT = new MavenObject("JUnit", "junit", "junit", "4.8.2",\r
- 237000, 0, 0, "c94f54227b08100974c36170dcb53329435fe5ad", "", "");\r
-\r
- public static final MavenObject MARKDOWNPAPERS = new MavenObject("MarkdownPapers",\r
- "org/tautua/markdownpapers", "markdownpapers-core", "1.0.0", 87000, 58000, 278000,\r
- "feda63bd149f3315da210e397d45d02277038ad5",\r
- "a9a6c4d163af81e265a15138fcaeafa9829c6054",\r
- "f932656266a7f9593488d3f89e815d0af44d0853");\r
-\r
- public static final MavenObject BOUNCYCASTLE = new MavenObject("BouncyCastle",\r
- "org/bouncycastle", "bcprov-jdk16", "1.46", 1900000, 1400000, 4670000,\r
- "ce091790943599535cbb4de8ede84535b0c1260c",\r
- "d2b70567594225923450d7e3f80cd022c852725e",\r
- "873a6fe765f33fc27df498a5d1f5bf077e503b2f");\r
-\r
- public static final MavenObject BOUNCYCASTLE_MAIL = new MavenObject("BouncyCastle Mail",\r
- "org/bouncycastle", "bcmail-jdk16", "1.46", 502000, 420000, 482000,\r
- "08a9233bfd6ad38ea32df5e6ff91035b650584b9",\r
- "3ebd62bc56854767512dc5deec0a17795f2e671d",\r
- "3b7c5f3938f202311bdca0bf7ed46bc0118af081");\r
-\r
- public static final MavenObject JGIT = new MavenObject("JGit", "org/eclipse/jgit",\r
- "org.eclipse.jgit", "1.0.0.201106090707-r", 1318000, 1354000, 2993000,\r
- "34e70691382d67ee5c84ef207fb8d3784594ba2c",\r
- "78dbd385cf40cb266f4fb2de8651b288a72f4e2d",\r
- "dab55685bb6eee8d07cc87faf0cedaa3f9d04a0d");\r
-\r
- public static final MavenObject JGIT_HTTP = new MavenObject("JGit", "org/eclipse/jgit",\r
- "org.eclipse.jgit.http.server", "1.0.0.201106090707-r", 68000, 62000, 99000,\r
- "35e22f7000af95d0c90caaf2012071ef3734ff59",\r
- "4a2368beb1e9db4a6a0d609b7b869f218bf8e7a9",\r
- "3100ce7c40d6968481a12377c59c708cda2d17b5");\r
-\r
- public static final MavenObject JSCH = new MavenObject("JSch", "com/jcraft", "jsch",\r
- "0.1.44-1", 214000, 211000, 413000, "2e9ae08de5a71bd0e0d3ba2558598181bfa71d4e",\r
- "e528f593b19b04d500992606f58b87fcfded8883",\r
- "d0ffadd0a4ab909d94a577b5aad43c13b617ddcb");\r
-\r
- public static final MavenObject COMMONSNET = new MavenObject("commons-net", "commons-net",\r
- "commons-net", "1.4.0", 181000, 0, 0, "eb47e8cad2dd7f92fd7e77df1d1529cae87361f7",\r
- "", "");\r
-\r
- public static final MavenObject ROME = new MavenObject("rome", "rome", "rome", "0.9",\r
- 208000, 196000, 407000, "dee2705dd01e79a5a96a17225f5a1ae30470bb18",\r
- "226f851dc44fd94fe70b9c471881b71f88949cbf",\r
- "8d7d867b97eeb3a9196c3926da550ad042941c1b");\r
-\r
- public static final MavenObject JDOM = new MavenObject("jdom", "org/jdom", "jdom", "1.1",\r
- 153000, 235000, 445000, "1d04c0f321ea337f3661cf7ede8f4c6f653a8fdd",\r
- "a7ed425c4c46605b8f2bf2ee118c1609682f4f2c",\r
- "f3df91edccba2f07a0fced70887c2f7b7836cb75");\r
-\r
- public final String name;\r
- public final String group;\r
- public final String artifact;\r
- public final String version;\r
- public final int approxLibraryLen;\r
- public final int approxSourcesLen;\r
- public final int approxJavadocLen;\r
- public final String librarySHA1;\r
- public final String sourcesSHA1;\r
- public final String javadocSHA1;\r
-\r
- private MavenObject(String name, String group, String artifact, String version,\r
- int approxLibraryLen, int approxSourcesLen, int approxJavadocLen,\r
- String librarySHA1, String sourcesSHA1, String javadocSHA1) {\r
- this.name = name;\r
- this.group = group;\r
- this.artifact = artifact;\r
- this.version = version;\r
- this.approxLibraryLen = approxLibraryLen;\r
- this.approxSourcesLen = approxSourcesLen;\r
- this.approxJavadocLen = approxJavadocLen;\r
- this.librarySHA1 = librarySHA1;\r
- this.sourcesSHA1 = sourcesSHA1;\r
- this.javadocSHA1 = javadocSHA1;\r
- }\r
-\r
- private String getRepositoryPath(String jar) {\r
- return group + "/" + artifact + "/" + version + "/" + artifact + "-" + version + jar\r
- + ".jar";\r
- }\r
-\r
- private File getLocalFile(String basePath, String jar) {\r
- return new File(basePath, artifact + "-" + version + jar + ".jar");\r
- }\r
-\r
- private String getSHA1(String jar) {\r
- if (jar.equals("")) {\r
- return librarySHA1;\r
- } else if (jar.equals("-sources")) {\r
- return sourcesSHA1;\r
- } else if (jar.equals("-javadoc")) {\r
- return javadocSHA1;\r
- }\r
- return librarySHA1;\r
- }\r
-\r
- private int getApproximateLength(String jar) {\r
- if (jar.equals("")) {\r
- return approxLibraryLen;\r
- } else if (jar.equals("-sources")) {\r
- return approxSourcesLen;\r
- } else if (jar.equals("-javadoc")) {\r
- return approxJavadocLen;\r
- }\r
- return approxLibraryLen;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return name;\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.FilenameFilter;\r
-import java.io.InputStreamReader;\r
-import java.io.OutputStreamWriter;\r
-import java.nio.charset.Charset;\r
-import java.text.MessageFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import com.beust.jcommander.JCommander;\r
-import com.beust.jcommander.Parameter;\r
-import com.beust.jcommander.ParameterException;\r
-import com.beust.jcommander.Parameters;\r
-import com.gitblit.utils.MarkdownUtils;\r
-import com.gitblit.utils.StringUtils;\r
-\r
-public class BuildSite {\r
-\r
- public static void main(String... args) {\r
- Params params = new Params();\r
- JCommander jc = new JCommander(params);\r
- try {\r
- jc.parse(args);\r
- } catch (ParameterException t) {\r
- usage(jc, t);\r
- }\r
-\r
- File sourceFolder = new File(params.sourceFolder);\r
- File destinationFolder = new File(params.outputFolder);\r
- File[] markdownFiles = sourceFolder.listFiles(new FilenameFilter() {\r
-\r
- @Override\r
- public boolean accept(File dir, String name) {\r
- return name.toLowerCase().endsWith(".mkd");\r
- }\r
- });\r
- Arrays.sort(markdownFiles);\r
-\r
- Map<String, String> aliasMap = new HashMap<String, String>();\r
- for (String alias : params.aliases) {\r
- String[] values = alias.split("=");\r
- aliasMap.put(values[0], values[1]);\r
- }\r
-\r
- System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ",\r
- markdownFiles.length, sourceFolder.getAbsolutePath()));\r
- String linkPattern = "<a href=''{0}''>{1}</a>";\r
- StringBuilder sb = new StringBuilder();\r
- for (File file : markdownFiles) {\r
- String documentName = getDocumentName(file);\r
- if (!params.skips.contains(documentName)) {\r
- String displayName = documentName;\r
- if (aliasMap.containsKey(documentName)) {\r
- displayName = aliasMap.get(documentName);\r
- }\r
- String fileName = documentName + ".html";\r
- sb.append(MessageFormat.format(linkPattern, fileName, displayName));\r
- sb.append(" | ");\r
- }\r
- }\r
- sb.setLength(sb.length() - 3);\r
- sb.trimToSize();\r
-\r
- String htmlHeader = readContent(new File(params.pageHeader), "\n");\r
- String htmlFooter = readContent(new File(params.pageFooter), "\n");\r
- final String links = sb.toString();\r
- final String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links);\r
- final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());\r
- final String footer = MessageFormat.format(htmlFooter, "generated " + date);\r
- for (File file : markdownFiles) {\r
- try {\r
- String documentName = getDocumentName(file);\r
- if (!params.skips.contains(documentName)) {\r
- String fileName = documentName + ".html";\r
- System.out.println(MessageFormat.format(" {0} => {1}", file.getName(),\r
- fileName));\r
- InputStreamReader reader = new InputStreamReader(new FileInputStream(file),\r
- Charset.forName("UTF-8"));\r
- String content = MarkdownUtils.transformMarkdown(reader);\r
- for (String token : params.substitutions) {\r
- String[] kv = token.split("=");\r
- content = content.replace(kv[0], kv[1]);\r
- }\r
- for (String alias : params.loads) {\r
- String[] kv = alias.split("=");\r
- String loadedContent = readContent(new File(kv[1]), "\n");\r
- loadedContent = StringUtils.escapeForHtml(loadedContent, false);\r
- loadedContent = StringUtils.breakLinesForHtml(loadedContent);\r
- content = content.replace(kv[0], loadedContent);\r
- }\r
- OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(\r
- new File(destinationFolder, fileName)), Charset.forName("UTF-8"));\r
- writer.write(header);\r
- writer.write(content);\r
- writer.write(footer);\r
- reader.close();\r
- writer.close();\r
- }\r
- } catch (Throwable t) {\r
- System.err.println("Failed to transform " + file.getName());\r
- t.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- private static String readContent(File file, String lineEnding) {\r
- StringBuilder sb = new StringBuilder();\r
- try {\r
- InputStreamReader is = new InputStreamReader(new FileInputStream(file),\r
- Charset.forName("UTF-8"));\r
- BufferedReader reader = new BufferedReader(is);\r
- String line = null;\r
- while ((line = reader.readLine()) != null) {\r
- sb.append(line);\r
- if (lineEnding != null) {\r
- sb.append(lineEnding);\r
- }\r
- }\r
- reader.close();\r
- } catch (Throwable t) {\r
- System.err.println("Failed to read content of " + file.getAbsolutePath());\r
- t.printStackTrace();\r
- }\r
- return sb.toString();\r
- }\r
-\r
- private static String getDocumentName(File file) {\r
- String displayName = file.getName().substring(0, file.getName().lastIndexOf('.'))\r
- .toLowerCase();\r
- // trim leading ##_ which is to control display order\r
- return displayName.substring(3);\r
- }\r
-\r
- private static void usage(JCommander jc, ParameterException t) {\r
- System.out.println(Constants.getGitBlitVersion());\r
- System.out.println();\r
- if (t != null) {\r
- System.out.println(t.getMessage());\r
- System.out.println();\r
- }\r
- if (jc != null) {\r
- jc.usage();\r
- }\r
- System.exit(0);\r
- }\r
-\r
- @Parameters(separators = " ")\r
- private static class Params {\r
-\r
- @Parameter(names = { "--sourceFolder" }, description = "Markdown Source Folder", required = true)\r
- public String sourceFolder;\r
-\r
- @Parameter(names = { "--outputFolder" }, description = "HTML Ouptut Folder", required = true)\r
- public String outputFolder;\r
-\r
- @Parameter(names = { "--pageHeader" }, description = "Page Header HTML Snippet", required = true)\r
- public String pageHeader;\r
-\r
- @Parameter(names = { "--pageFooter" }, description = "Page Footer HTML Snippet", required = true)\r
- public String pageFooter;\r
-\r
- @Parameter(names = { "--skip" }, description = "Filename to skip", required = false)\r
- public List<String> skips = new ArrayList<String>();\r
-\r
- @Parameter(names = { "--alias" }, description = "Filename=Linkname aliases", required = false)\r
- public List<String> aliases = new ArrayList<String>();\r
-\r
- @Parameter(names = { "--substitute" }, description = "%TOKEN%=value", required = false)\r
- public List<String> substitutions = new ArrayList<String>();\r
-\r
- @Parameter(names = { "--load" }, description = "%TOKEN%=filename", required = false)\r
- public List<String> loads = new ArrayList<String>();\r
-\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit;\r
-\r
-import java.awt.Dimension;\r
-import java.awt.Image;\r
-import java.awt.image.BufferedImage;\r
-import java.io.File;\r
-import java.io.FileOutputStream;\r
-import java.io.FilenameFilter;\r
-import java.io.IOException;\r
-import java.util.Iterator;\r
-\r
-import javax.imageio.ImageIO;\r
-import javax.imageio.ImageReader;\r
-import javax.imageio.stream.ImageInputStream;\r
-\r
-import com.beust.jcommander.JCommander;\r
-import com.beust.jcommander.Parameter;\r
-import com.beust.jcommander.ParameterException;\r
-import com.beust.jcommander.Parameters;\r
-\r
-public class BuildThumbnails {\r
-\r
- public static void main(String[] args) {\r
- Params params = new Params();\r
- JCommander jc = new JCommander(params);\r
- try {\r
- jc.parse(args);\r
- } catch (ParameterException t) {\r
- System.err.println(t.getMessage());\r
- jc.usage();\r
- }\r
- createImageThumbnail(params.sourceFolder, params.destinationFolder, params.maximumDimension);\r
- }\r
-\r
- public static void createImageThumbnail(String sourceFolder, String destinationFolder,\r
- int maxDimension) {\r
- if (maxDimension <= 0)\r
- return;\r
- File source = new File(sourceFolder);\r
- File destination = new File(destinationFolder);\r
- destination.mkdirs();\r
- File[] sourceFiles = source.listFiles(new FilenameFilter() {\r
- @Override\r
- public boolean accept(File dir, String name) {\r
- return name.toLowerCase().endsWith(".png");\r
- }\r
- });\r
-\r
- for (File sourceFile : sourceFiles) {\r
- File destinationFile = new File(destination, sourceFile.getName());\r
- try {\r
- Dimension sz = getImageDimensions(sourceFile);\r
- int w = 0;\r
- int h = 0;\r
- if (sz.width > maxDimension) {\r
- // Scale to Width\r
- w = maxDimension;\r
- float f = maxDimension;\r
- h = (int) ((f / sz.width) * sz.height); // normalize height\r
- } else if (sz.height > maxDimension) {\r
- // Scale to Height\r
- h = maxDimension;\r
- float f = maxDimension;\r
- w = (int) ((f / sz.height) * sz.width); // normalize width\r
- } else {\r
- // No thumbnail\r
- return;\r
- }\r
- System.out.println("Generating thumbnail for " + sourceFile.getName() + " as (" + w\r
- + "," + h + ")");\r
- BufferedImage image = ImageIO.read(sourceFile);\r
- Image scaledImage = image.getScaledInstance(w, h, BufferedImage.SCALE_SMOOTH);\r
- BufferedImage destImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);\r
- destImage.createGraphics().drawImage(scaledImage, 0, 0, null);\r
- FileOutputStream fos = new FileOutputStream(destinationFile);\r
- ImageIO.write(destImage, "png", fos);\r
- fos.flush();\r
- fos.getFD().sync();\r
- fos.close();\r
- } catch (Throwable t) {\r
- t.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- public static Dimension getImageDimensions(File file) throws IOException {\r
- ImageInputStream in = ImageIO.createImageInputStream(file);\r
- try {\r
- final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);\r
- if (readers.hasNext()) {\r
- ImageReader reader = readers.next();\r
- try {\r
- reader.setInput(in);\r
- return new Dimension(reader.getWidth(0), reader.getHeight(0));\r
- } finally {\r
- reader.dispose();\r
- }\r
- }\r
- } finally {\r
- if (in != null)\r
- in.close();\r
- }\r
- return null;\r
- }\r
-\r
- @Parameters(separators = " ")\r
- private static class Params {\r
-\r
- @Parameter(names = { "--sourceFolder" }, description = "Source folder for raw images", required = true)\r
- public String sourceFolder;\r
-\r
- @Parameter(names = { "--destinationFolder" }, description = "Destination folder for thumbnails", required = true)\r
- public String destinationFolder;\r
-\r
- @Parameter(names = { "--maximumDimension" }, description = "Maximum width or height for thumbnail", required = true)\r
- public int maximumDimension;\r
-\r
- }\r
-}\r
+++ /dev/null
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileOutputStream;\r
-import java.io.FileReader;\r
-import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Vector;\r
-\r
-import com.beust.jcommander.JCommander;\r
-import com.beust.jcommander.Parameter;\r
-import com.beust.jcommander.ParameterException;\r
-import com.beust.jcommander.Parameters;\r
-import com.gitblit.utils.StringUtils;\r
-\r
-public class BuildWebXml {\r
- private static final String PARAMS = "<!-- PARAMS -->";\r
-\r
- private static final String[] STRIP_TOKENS = { "<!-- STRIP", "STRIP -->" };\r
-\r
- private static final String COMMENT_PATTERN = "\n\t<!-- {0} -->";\r
-\r
- 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";\r
-\r
- public static void main(String[] args) throws Exception {\r
- Params params = new Params();\r
- JCommander jc = new JCommander(params);\r
- try {\r
- jc.parse(args);\r
- } catch (ParameterException t) {\r
- System.err.println(t.getMessage());\r
- jc.usage();\r
- }\r
- generateWebXml(params);\r
- }\r
-\r
- private static void generateWebXml(Params params) throws Exception {\r
- // Read the current Gitblit properties\r
- BufferedReader propertiesReader = new BufferedReader(new FileReader(new File(\r
- params.propertiesFile)));\r
-\r
- Vector<Setting> settings = new Vector<Setting>();\r
- List<String> comments = new ArrayList<String>();\r
- String line = null;\r
- while ((line = propertiesReader.readLine()) != null) {\r
- if (line.length() == 0) {\r
- comments.clear();\r
- } else {\r
- if (line.charAt(0) == '#') {\r
- if (line.length() > 1) {\r
- comments.add(line.substring(1).trim());\r
- }\r
- } else {\r
- String[] kvp = line.split("=", 2);\r
- String key = kvp[0].trim();\r
- if (!skipKey(key)) {\r
- Setting s = new Setting(key, kvp[1].trim(), comments);\r
- settings.add(s);\r
- }\r
- comments.clear();\r
- }\r
- }\r
- }\r
- propertiesReader.close();\r
-\r
- StringBuilder parameters = new StringBuilder();\r
-\r
- for (Setting setting : settings) {\r
- for (String comment : setting.comments) {\r
- parameters.append(MessageFormat.format(COMMENT_PATTERN, comment));\r
- }\r
- parameters.append(MessageFormat.format(PARAM_PATTERN, setting.name, StringUtils.escapeForHtml(setting.value, false)));\r
- }\r
-\r
- // Read the prototype web.xml file\r
- File webxml = new File(params.sourceFile);\r
- char[] buffer = new char[(int) webxml.length()];\r
- FileReader webxmlReader = new FileReader(webxml);\r
- webxmlReader.read(buffer);\r
- webxmlReader.close();\r
- String webXmlContent = new String(buffer);\r
-\r
- // Insert the Gitblit properties into the prototype web.xml\r
- for (String stripToken : STRIP_TOKENS) {\r
- webXmlContent = webXmlContent.replace(stripToken, "");\r
- }\r
- int idx = webXmlContent.indexOf(PARAMS);\r
- StringBuilder sb = new StringBuilder();\r
- sb.append(webXmlContent.substring(0, idx));\r
- sb.append(parameters.toString());\r
- sb.append(webXmlContent.substring(idx + PARAMS.length()));\r
-\r
- // Save the merged web.xml to the war build folder\r
- FileOutputStream os = new FileOutputStream(new File(params.destinationFile), false);\r
- os.write(sb.toString().getBytes());\r
- os.close();\r
- }\r
-\r
- private static boolean skipKey(String key) {\r
- return key.startsWith(Keys.server._ROOT);\r
- }\r
-\r
- private static class Setting {\r
- final String name;\r
- final String value;\r
- final List<String> comments;\r
-\r
- Setting(String name, String value, List<String> comments) {\r
- this.name = name;\r
- this.value = value;\r
- this.comments = new ArrayList<String>(comments);\r
- }\r
- }\r
-\r
- @Parameters(separators = " ")\r
- private static class Params {\r
-\r
- @Parameter(names = { "--sourceFile" }, description = "Source web.xml file", required = true)\r
- public String sourceFile;\r
-\r
- @Parameter(names = { "--propertiesFile" }, description = "Properties settings file", required = true)\r
- public String propertiesFile;\r
-\r
- @Parameter(names = { "--destinationFile" }, description = "Destination web.xml file", required = true)\r
- public String destinationFile;\r
-\r
- }\r
-}\r
import java.util.Arrays;\r
import java.util.List;\r
\r
+import com.gitblit.build.Build;\r
+\r
/**\r
* Launch helper class that adds all jars found in the local "lib" folder and\r
* then calls the application main. Using this technique we do not have to\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.build;\r
+\r
+import java.io.BufferedInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileWriter;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.RandomAccessFile;\r
+import java.net.URL;\r
+import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+\r
+import com.gitblit.Constants;\r
+import com.gitblit.utils.StringUtils;\r
+\r
+public class Build {\r
+\r
+ public static enum BuildType {\r
+ RUNTIME, COMPILETIME;\r
+ }\r
+\r
+ public static void main(String... args) {\r
+ runtime();\r
+ compiletime();\r
+ buildSettingKeys();\r
+ }\r
+\r
+ public static void runtime() {\r
+ downloadFromApache(MavenObject.JCOMMANDER, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.JETTY, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.SERVLET, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.SLF4JAPI, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.SLF4LOG4J, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.LOG4J, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.WICKET, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.WICKET_EXT, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.WICKET_AUTH_ROLES, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.WICKET_GOOGLE_CHARTS, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.BOUNCYCASTLE, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.BOUNCYCASTLE_MAIL, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.JSCH, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.ROME, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.JDOM, BuildType.RUNTIME);\r
+\r
+ downloadFromEclipse(MavenObject.JGIT, BuildType.RUNTIME);\r
+ downloadFromEclipse(MavenObject.JGIT_HTTP, BuildType.RUNTIME);\r
+ }\r
+\r
+ public static void compiletime() {\r
+ downloadFromApache(MavenObject.JUNIT, BuildType.RUNTIME);\r
+ downloadFromApache(MavenObject.JCOMMANDER, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.JETTY, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.SERVLET, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.SLF4JAPI, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.SLF4LOG4J, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.LOG4J, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.WICKET, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.WICKET_EXT, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.WICKET_AUTH_ROLES, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.WICKET_GOOGLE_CHARTS, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.BOUNCYCASTLE, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.BOUNCYCASTLE_MAIL, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.JSCH, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.ROME, BuildType.COMPILETIME);\r
+ downloadFromApache(MavenObject.JDOM, BuildType.COMPILETIME);\r
+\r
+ downloadFromEclipse(MavenObject.JGIT, BuildType.COMPILETIME);\r
+ downloadFromEclipse(MavenObject.JGIT_HTTP, BuildType.COMPILETIME);\r
+\r
+ // needed for site publishing\r
+ downloadFromApache(MavenObject.COMMONSNET, BuildType.RUNTIME);\r
+ }\r
+\r
+ public static void buildSettingKeys() {\r
+ // Load all keys\r
+ Properties properties = new Properties();\r
+ FileInputStream is = null;\r
+ try {\r
+ is = new FileInputStream(Constants.PROPERTIES_FILE);\r
+ properties.load(is);\r
+ } catch (Throwable t) {\r
+ t.printStackTrace();\r
+ } finally {\r
+ if (is != null) {\r
+ try {\r
+ is.close();\r
+ } catch (Throwable t) {\r
+ // IGNORE\r
+ }\r
+ }\r
+ }\r
+ List<String> keys = new ArrayList<String>(properties.stringPropertyNames());\r
+ Collections.sort(keys);\r
+\r
+ // Determine static key group classes\r
+ Map<String, List<String>> staticClasses = new HashMap<String, List<String>>();\r
+ staticClasses.put("", new ArrayList<String>());\r
+ for (String key : keys) {\r
+ String clazz = "";\r
+ String field = key;\r
+ if (key.indexOf('.') > -1) {\r
+ clazz = key.substring(0, key.indexOf('.'));\r
+ field = key.substring(key.indexOf('.') + 1);\r
+ }\r
+ if (!staticClasses.containsKey(clazz)) {\r
+ staticClasses.put(clazz, new ArrayList<String>());\r
+ }\r
+ staticClasses.get(clazz).add(field);\r
+ }\r
+\r
+ // Assemble Keys source file\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("package com.gitblit;\n");\r
+ sb.append('\n');\r
+ sb.append("/*\n");\r
+ sb.append(" * This class is auto-generated from the properties file.\n");\r
+ sb.append(" * Do not version control!\n");\r
+ sb.append(" */\n");\r
+ sb.append("public final class Keys {\n");\r
+ sb.append('\n');\r
+ List<String> classSet = new ArrayList<String>(staticClasses.keySet());\r
+ Collections.sort(classSet);\r
+ for (String clazz : classSet) {\r
+ List<String> keySet = staticClasses.get(clazz);\r
+ if (clazz.equals("")) {\r
+ // root keys\r
+ for (String key : keySet) {\r
+ sb.append(MessageFormat.format(\r
+ "\tpublic static final String {0} = \"{1}\";\n\n",\r
+ key.replace('.', '_'), key));\r
+ }\r
+ } else {\r
+ // class keys\r
+ sb.append(MessageFormat.format("\tpublic static final class {0} '{'\n\n", clazz));\r
+ sb.append(MessageFormat.format(\r
+ "\t\tpublic static final String _ROOT = \"{0}\";\n\n", clazz));\r
+ for (String key : keySet) {\r
+ sb.append(MessageFormat.format(\r
+ "\t\tpublic static final String {0} = \"{1}\";\n\n",\r
+ key.replace('.', '_'), clazz + "." + key));\r
+ }\r
+ sb.append("\t}\n\n");\r
+ }\r
+ }\r
+ sb.append('}');\r
+\r
+ // Save Keys class definition\r
+ try {\r
+ File file = new File("src/com/gitblit/Keys.java");\r
+ FileWriter fw = new FileWriter(file, false);\r
+ fw.write(sb.toString());\r
+ fw.close();\r
+ } catch (Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Download a file from the official Apache Maven repository.\r
+ * \r
+ * @param mo\r
+ * the maven object to download.\r
+ * @return\r
+ */\r
+ private static List<File> downloadFromApache(MavenObject mo, BuildType type) {\r
+ return downloadFromMaven("http://repo1.maven.org/maven2/", mo, type);\r
+ }\r
+\r
+ /**\r
+ * Download a file from the official Eclipse Maven repository.\r
+ * \r
+ * @param mo\r
+ * the maven object to download.\r
+ * @return\r
+ */\r
+ private static List<File> downloadFromEclipse(MavenObject mo, BuildType type) {\r
+ return downloadFromMaven("http://download.eclipse.org/jgit/maven/", mo, type);\r
+ }\r
+\r
+ /**\r
+ * Download a file from a Maven repository.\r
+ * \r
+ * @param mo\r
+ * the maven object to download.\r
+ * @return\r
+ */\r
+ private static List<File> downloadFromMaven(String mavenRoot, MavenObject mo, BuildType type) {\r
+ List<File> downloads = new ArrayList<File>();\r
+ String[] jars = { "" };\r
+ if (BuildType.RUNTIME.equals(type)) {\r
+ jars = new String[] { "" };\r
+ } else if (BuildType.COMPILETIME.equals(type)) {\r
+ jars = new String[] { "-sources", "-javadoc" };\r
+ }\r
+ for (String jar : jars) {\r
+ File targetFile = mo.getLocalFile("ext", jar);\r
+ if (targetFile.exists()) {\r
+ downloads.add(targetFile);\r
+ continue;\r
+ }\r
+ String expectedSHA1 = mo.getSHA1(jar);\r
+ if (expectedSHA1 == null) {\r
+ // skip this jar\r
+ continue;\r
+ }\r
+ float approximateLength = mo.getApproximateLength(jar);\r
+ String mavenURL = mavenRoot + mo.getRepositoryPath(jar);\r
+ if (!targetFile.getAbsoluteFile().getParentFile().exists()) {\r
+ boolean success = targetFile.getAbsoluteFile().getParentFile().mkdirs();\r
+ if (!success) {\r
+ throw new RuntimeException("Failed to create destination folder structure!");\r
+ }\r
+ }\r
+ ByteArrayOutputStream buff = new ByteArrayOutputStream();\r
+ try {\r
+ URL url = new URL(mavenURL);\r
+ InputStream in = new BufferedInputStream(url.openStream());\r
+ byte[] buffer = new byte[4096];\r
+ int downloadedLen = 0;\r
+ float lastProgress = 0f;\r
+\r
+ updateDownload(0, targetFile);\r
+ while (true) {\r
+ int len = in.read(buffer);\r
+ if (len < 0) {\r
+ break;\r
+ }\r
+ downloadedLen += len;\r
+ buff.write(buffer, 0, len);\r
+ float progress = downloadedLen / approximateLength;\r
+ if (progress - lastProgress >= 0.1f) {\r
+ lastProgress = progress;\r
+ updateDownload(progress, targetFile);\r
+ }\r
+ }\r
+ in.close();\r
+ updateDownload(1f, targetFile);\r
+\r
+ } catch (IOException e) {\r
+ throw new RuntimeException("Error downloading " + mavenURL + " to " + targetFile, e);\r
+ }\r
+ byte[] data = buff.toByteArray();\r
+ String calculatedSHA1 = StringUtils.getSHA1(data);\r
+\r
+ System.out.println();\r
+\r
+ if (expectedSHA1.length() == 0) {\r
+ updateProgress(0, "sha: " + calculatedSHA1);\r
+ System.out.println();\r
+ } else {\r
+ if (!calculatedSHA1.equals(expectedSHA1)) {\r
+ throw new RuntimeException("SHA1 checksum mismatch; got: " + calculatedSHA1);\r
+ }\r
+ }\r
+ try {\r
+ RandomAccessFile ra = new RandomAccessFile(targetFile, "rw");\r
+ ra.write(data);\r
+ ra.setLength(data.length);\r
+ ra.close();\r
+ } catch (IOException e) {\r
+ throw new RuntimeException("Error writing to file " + targetFile, e);\r
+ }\r
+ downloads.add(targetFile);\r
+ }\r
+ return downloads;\r
+ }\r
+\r
+ private static void updateDownload(float progress, File file) {\r
+ updateProgress(progress, "d/l: " + file.getName());\r
+ }\r
+\r
+ private static void updateProgress(float progress, String url) {\r
+ String anim = "==========";\r
+ int width = Math.round(anim.length() * progress);\r
+ System.out.print("\r[");\r
+ System.out.print(anim.substring(0, width));\r
+ for (int i = 0; i < anim.length() - width; i++) {\r
+ System.out.print(' ');\r
+ }\r
+ System.out.print("] " + url);\r
+ }\r
+\r
+ private static class MavenObject {\r
+\r
+ public static final MavenObject JCOMMANDER = new MavenObject("jCommander", "com/beust",\r
+ "jcommander", "1.17", 34000, 32000, 141000,\r
+ "219a3540f3b27d7cc3b1d91d6ea046cd8723290e",\r
+ "0bb50eec177acf0e94d58e0cf07262fe5164331d",\r
+ "c7adc475ca40c288c93054e0f4fe58f3a98c0cb5");\r
+\r
+ public static final MavenObject JETTY = new MavenObject("Jetty",\r
+ "org/eclipse/jetty/aggregate", "jetty-webapp", "7.4.2.v20110526", 1000000, 680000,\r
+ 2720000, "56331143afa22d24d9faba96e86e6371b0686c7c",\r
+ "9f38230fd589e29c8be0fc3c80fb51c5093c2e1e",\r
+ "0d48212889c25252c5c14bef62703e28215d80cc");\r
+\r
+ public static final MavenObject SERVLET = new MavenObject("Servlet 2.5", "javax/servlet",\r
+ "servlet-api", "2.5", 105000, 158000, 0,\r
+ "5959582d97d8b61f4d154ca9e495aafd16726e34",\r
+ "021599814ad9a605b86f3e6381571beccd861a32", null);\r
+\r
+ public static final MavenObject SLF4JAPI = new MavenObject("SLF4J API", "org/slf4j",\r
+ "slf4j-api", "1.6.1", 25500, 45000, 182000,\r
+ "6f3b8a24bf970f17289b234284c94f43eb42f0e4",\r
+ "46a386136c901748e6a3af67ebde6c22bc6b4524",\r
+ "e223571d77769cdafde59040da235842f3326453");\r
+\r
+ public static final MavenObject SLF4LOG4J = new MavenObject("SLF4J LOG4J", "org/slf4j",\r
+ "slf4j-log4j12", "1.6.1", 9800, 9500, 52400,\r
+ "bd245d6746cdd4e6203e976e21d597a46f115802",\r
+ "7a26b08b265f55622fa1fed3bda68bbd37a465ba",\r
+ "6e4b16bce7994e3692e82002f322a0dd2f32741e");\r
+\r
+ public static final MavenObject LOG4J = new MavenObject("Apache LOG4J", "log4j", "log4j",\r
+ "1.2.16", 481000, 471000, 1455000, "7999a63bfccbc7c247a9aea10d83d4272bd492c6",\r
+ "bf945d1dc995be7fe64923625f842fbb6bf443be",\r
+ "78aa1cbf0fa3b259abdc7d87f9f6788d785aac2a");\r
+\r
+ public static final MavenObject WICKET = new MavenObject("Apache Wicket",\r
+ "org/apache/wicket", "wicket", "1.4.17", 1960000, 1906000, 6818000,\r
+ "39815e37a6f56465b2d2c3d3017c4f3bf17db50a",\r
+ "a792ebae4123253ffd039c3be49e773f8622f94e",\r
+ "f2f244ca72d10081529b017e89d6276eab62c621");\r
+\r
+ public static final MavenObject WICKET_EXT = new MavenObject("Apache Wicket Extensions",\r
+ "org/apache/wicket", "wicket-extensions", "1.4.17", 1180000, 1118000, 1458000,\r
+ "01111d0dbffdc425581b006a43864c22797ce72a",\r
+ "f194f40ea6e361bb745dfa22e2f9171eb63a9355",\r
+ "bd42e5ba9444a426bb2d7cacce91c6033b663b57");\r
+\r
+ public static final MavenObject WICKET_AUTH_ROLES = new MavenObject(\r
+ "Apache Wicket Auth Roles", "org/apache/wicket", "wicket-auth-roles", "1.4.17",\r
+ 44000, 45000, 166000, "86d20ff32f62d3026213ff11a78555da643bc676",\r
+ "37e815350a2d6b97734b250a8a03d8bf3712bba7",\r
+ "ac3896368bfb372d178041a4ac3ee2c44f62e21c");\r
+\r
+ public static final MavenObject WICKET_GOOGLE_CHARTS = new MavenObject(\r
+ "Apache Wicket Google Charts Add-On", "org/wicketstuff", "googlecharts", "1.4.17",\r
+ 34000, 18750, 161000, "c567b98b0c5efe4147e77ef2d0d3c2d45c49dea5",\r
+ "3d32d958b2f7aa58388af5701ea3aafc433e573f",\r
+ "c37518b67ea85af485dd61fe854137eeacc50318");\r
+\r
+ public static final MavenObject JUNIT = new MavenObject("JUnit", "junit", "junit", "4.8.2",\r
+ 237000, 0, 0, "c94f54227b08100974c36170dcb53329435fe5ad", "", "");\r
+\r
+ public static final MavenObject MARKDOWNPAPERS = new MavenObject("MarkdownPapers",\r
+ "org/tautua/markdownpapers", "markdownpapers-core", "1.0.0", 87000, 58000, 278000,\r
+ "feda63bd149f3315da210e397d45d02277038ad5",\r
+ "a9a6c4d163af81e265a15138fcaeafa9829c6054",\r
+ "f932656266a7f9593488d3f89e815d0af44d0853");\r
+\r
+ public static final MavenObject BOUNCYCASTLE = new MavenObject("BouncyCastle",\r
+ "org/bouncycastle", "bcprov-jdk16", "1.46", 1900000, 1400000, 4670000,\r
+ "ce091790943599535cbb4de8ede84535b0c1260c",\r
+ "d2b70567594225923450d7e3f80cd022c852725e",\r
+ "873a6fe765f33fc27df498a5d1f5bf077e503b2f");\r
+\r
+ public static final MavenObject BOUNCYCASTLE_MAIL = new MavenObject("BouncyCastle Mail",\r
+ "org/bouncycastle", "bcmail-jdk16", "1.46", 502000, 420000, 482000,\r
+ "08a9233bfd6ad38ea32df5e6ff91035b650584b9",\r
+ "3ebd62bc56854767512dc5deec0a17795f2e671d",\r
+ "3b7c5f3938f202311bdca0bf7ed46bc0118af081");\r
+\r
+ public static final MavenObject JGIT = new MavenObject("JGit", "org/eclipse/jgit",\r
+ "org.eclipse.jgit", "1.0.0.201106090707-r", 1318000, 1354000, 2993000,\r
+ "34e70691382d67ee5c84ef207fb8d3784594ba2c",\r
+ "78dbd385cf40cb266f4fb2de8651b288a72f4e2d",\r
+ "dab55685bb6eee8d07cc87faf0cedaa3f9d04a0d");\r
+\r
+ public static final MavenObject JGIT_HTTP = new MavenObject("JGit", "org/eclipse/jgit",\r
+ "org.eclipse.jgit.http.server", "1.0.0.201106090707-r", 68000, 62000, 99000,\r
+ "35e22f7000af95d0c90caaf2012071ef3734ff59",\r
+ "4a2368beb1e9db4a6a0d609b7b869f218bf8e7a9",\r
+ "3100ce7c40d6968481a12377c59c708cda2d17b5");\r
+\r
+ public static final MavenObject JSCH = new MavenObject("JSch", "com/jcraft", "jsch",\r
+ "0.1.44-1", 214000, 211000, 413000, "2e9ae08de5a71bd0e0d3ba2558598181bfa71d4e",\r
+ "e528f593b19b04d500992606f58b87fcfded8883",\r
+ "d0ffadd0a4ab909d94a577b5aad43c13b617ddcb");\r
+\r
+ public static final MavenObject COMMONSNET = new MavenObject("commons-net", "commons-net",\r
+ "commons-net", "1.4.0", 181000, 0, 0, "eb47e8cad2dd7f92fd7e77df1d1529cae87361f7",\r
+ "", "");\r
+\r
+ public static final MavenObject ROME = new MavenObject("rome", "rome", "rome", "0.9",\r
+ 208000, 196000, 407000, "dee2705dd01e79a5a96a17225f5a1ae30470bb18",\r
+ "226f851dc44fd94fe70b9c471881b71f88949cbf",\r
+ "8d7d867b97eeb3a9196c3926da550ad042941c1b");\r
+\r
+ public static final MavenObject JDOM = new MavenObject("jdom", "org/jdom", "jdom", "1.1",\r
+ 153000, 235000, 445000, "1d04c0f321ea337f3661cf7ede8f4c6f653a8fdd",\r
+ "a7ed425c4c46605b8f2bf2ee118c1609682f4f2c",\r
+ "f3df91edccba2f07a0fced70887c2f7b7836cb75");\r
+\r
+ public final String name;\r
+ public final String group;\r
+ public final String artifact;\r
+ public final String version;\r
+ public final int approxLibraryLen;\r
+ public final int approxSourcesLen;\r
+ public final int approxJavadocLen;\r
+ public final String librarySHA1;\r
+ public final String sourcesSHA1;\r
+ public final String javadocSHA1;\r
+\r
+ private MavenObject(String name, String group, String artifact, String version,\r
+ int approxLibraryLen, int approxSourcesLen, int approxJavadocLen,\r
+ String librarySHA1, String sourcesSHA1, String javadocSHA1) {\r
+ this.name = name;\r
+ this.group = group;\r
+ this.artifact = artifact;\r
+ this.version = version;\r
+ this.approxLibraryLen = approxLibraryLen;\r
+ this.approxSourcesLen = approxSourcesLen;\r
+ this.approxJavadocLen = approxJavadocLen;\r
+ this.librarySHA1 = librarySHA1;\r
+ this.sourcesSHA1 = sourcesSHA1;\r
+ this.javadocSHA1 = javadocSHA1;\r
+ }\r
+\r
+ private String getRepositoryPath(String jar) {\r
+ return group + "/" + artifact + "/" + version + "/" + artifact + "-" + version + jar\r
+ + ".jar";\r
+ }\r
+\r
+ private File getLocalFile(String basePath, String jar) {\r
+ return new File(basePath, artifact + "-" + version + jar + ".jar");\r
+ }\r
+\r
+ private String getSHA1(String jar) {\r
+ if (jar.equals("")) {\r
+ return librarySHA1;\r
+ } else if (jar.equals("-sources")) {\r
+ return sourcesSHA1;\r
+ } else if (jar.equals("-javadoc")) {\r
+ return javadocSHA1;\r
+ }\r
+ return librarySHA1;\r
+ }\r
+\r
+ private int getApproximateLength(String jar) {\r
+ if (jar.equals("")) {\r
+ return approxLibraryLen;\r
+ } else if (jar.equals("-sources")) {\r
+ return approxSourcesLen;\r
+ } else if (jar.equals("-javadoc")) {\r
+ return approxJavadocLen;\r
+ }\r
+ return approxLibraryLen;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return name;\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.build;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
+import java.io.FilenameFilter;\r
+import java.io.InputStreamReader;\r
+import java.io.OutputStreamWriter;\r
+import java.nio.charset.Charset;\r
+import java.text.MessageFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Date;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import com.beust.jcommander.JCommander;\r
+import com.beust.jcommander.Parameter;\r
+import com.beust.jcommander.ParameterException;\r
+import com.beust.jcommander.Parameters;\r
+import com.gitblit.Constants;\r
+import com.gitblit.utils.MarkdownUtils;\r
+import com.gitblit.utils.StringUtils;\r
+\r
+public class BuildSite {\r
+\r
+ public static void main(String... args) {\r
+ Params params = new Params();\r
+ JCommander jc = new JCommander(params);\r
+ try {\r
+ jc.parse(args);\r
+ } catch (ParameterException t) {\r
+ usage(jc, t);\r
+ }\r
+\r
+ File sourceFolder = new File(params.sourceFolder);\r
+ File destinationFolder = new File(params.outputFolder);\r
+ File[] markdownFiles = sourceFolder.listFiles(new FilenameFilter() {\r
+\r
+ @Override\r
+ public boolean accept(File dir, String name) {\r
+ return name.toLowerCase().endsWith(".mkd");\r
+ }\r
+ });\r
+ Arrays.sort(markdownFiles);\r
+\r
+ Map<String, String> aliasMap = new HashMap<String, String>();\r
+ for (String alias : params.aliases) {\r
+ String[] values = alias.split("=");\r
+ aliasMap.put(values[0], values[1]);\r
+ }\r
+\r
+ System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ",\r
+ markdownFiles.length, sourceFolder.getAbsolutePath()));\r
+ String linkPattern = "<a href=''{0}''>{1}</a>";\r
+ StringBuilder sb = new StringBuilder();\r
+ for (File file : markdownFiles) {\r
+ String documentName = getDocumentName(file);\r
+ if (!params.skips.contains(documentName)) {\r
+ String displayName = documentName;\r
+ if (aliasMap.containsKey(documentName)) {\r
+ displayName = aliasMap.get(documentName);\r
+ }\r
+ String fileName = documentName + ".html";\r
+ sb.append(MessageFormat.format(linkPattern, fileName, displayName));\r
+ sb.append(" | ");\r
+ }\r
+ }\r
+ sb.setLength(sb.length() - 3);\r
+ sb.trimToSize();\r
+\r
+ String htmlHeader = readContent(new File(params.pageHeader), "\n");\r
+ String htmlFooter = readContent(new File(params.pageFooter), "\n");\r
+ final String links = sb.toString();\r
+ final String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links);\r
+ final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());\r
+ final String footer = MessageFormat.format(htmlFooter, "generated " + date);\r
+ for (File file : markdownFiles) {\r
+ try {\r
+ String documentName = getDocumentName(file);\r
+ if (!params.skips.contains(documentName)) {\r
+ String fileName = documentName + ".html";\r
+ System.out.println(MessageFormat.format(" {0} => {1}", file.getName(),\r
+ fileName));\r
+ InputStreamReader reader = new InputStreamReader(new FileInputStream(file),\r
+ Charset.forName("UTF-8"));\r
+ String content = MarkdownUtils.transformMarkdown(reader);\r
+ for (String token : params.substitutions) {\r
+ String[] kv = token.split("=");\r
+ content = content.replace(kv[0], kv[1]);\r
+ }\r
+ for (String alias : params.loads) {\r
+ String[] kv = alias.split("=");\r
+ String loadedContent = readContent(new File(kv[1]), "\n");\r
+ loadedContent = StringUtils.escapeForHtml(loadedContent, false);\r
+ loadedContent = StringUtils.breakLinesForHtml(loadedContent);\r
+ content = content.replace(kv[0], loadedContent);\r
+ }\r
+ OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(\r
+ new File(destinationFolder, fileName)), Charset.forName("UTF-8"));\r
+ writer.write(header);\r
+ writer.write(content);\r
+ writer.write(footer);\r
+ reader.close();\r
+ writer.close();\r
+ }\r
+ } catch (Throwable t) {\r
+ System.err.println("Failed to transform " + file.getName());\r
+ t.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+\r
+ private static String readContent(File file, String lineEnding) {\r
+ StringBuilder sb = new StringBuilder();\r
+ try {\r
+ InputStreamReader is = new InputStreamReader(new FileInputStream(file),\r
+ Charset.forName("UTF-8"));\r
+ BufferedReader reader = new BufferedReader(is);\r
+ String line = null;\r
+ while ((line = reader.readLine()) != null) {\r
+ sb.append(line);\r
+ if (lineEnding != null) {\r
+ sb.append(lineEnding);\r
+ }\r
+ }\r
+ reader.close();\r
+ } catch (Throwable t) {\r
+ System.err.println("Failed to read content of " + file.getAbsolutePath());\r
+ t.printStackTrace();\r
+ }\r
+ return sb.toString();\r
+ }\r
+\r
+ private static String getDocumentName(File file) {\r
+ String displayName = file.getName().substring(0, file.getName().lastIndexOf('.'))\r
+ .toLowerCase();\r
+ // trim leading ##_ which is to control display order\r
+ return displayName.substring(3);\r
+ }\r
+\r
+ private static void usage(JCommander jc, ParameterException t) {\r
+ System.out.println(Constants.getGitBlitVersion());\r
+ System.out.println();\r
+ if (t != null) {\r
+ System.out.println(t.getMessage());\r
+ System.out.println();\r
+ }\r
+ if (jc != null) {\r
+ jc.usage();\r
+ }\r
+ System.exit(0);\r
+ }\r
+\r
+ @Parameters(separators = " ")\r
+ private static class Params {\r
+\r
+ @Parameter(names = { "--sourceFolder" }, description = "Markdown Source Folder", required = true)\r
+ public String sourceFolder;\r
+\r
+ @Parameter(names = { "--outputFolder" }, description = "HTML Ouptut Folder", required = true)\r
+ public String outputFolder;\r
+\r
+ @Parameter(names = { "--pageHeader" }, description = "Page Header HTML Snippet", required = true)\r
+ public String pageHeader;\r
+\r
+ @Parameter(names = { "--pageFooter" }, description = "Page Footer HTML Snippet", required = true)\r
+ public String pageFooter;\r
+\r
+ @Parameter(names = { "--skip" }, description = "Filename to skip", required = false)\r
+ public List<String> skips = new ArrayList<String>();\r
+\r
+ @Parameter(names = { "--alias" }, description = "Filename=Linkname aliases", required = false)\r
+ public List<String> aliases = new ArrayList<String>();\r
+\r
+ @Parameter(names = { "--substitute" }, description = "%TOKEN%=value", required = false)\r
+ public List<String> substitutions = new ArrayList<String>();\r
+\r
+ @Parameter(names = { "--load" }, description = "%TOKEN%=filename", required = false)\r
+ public List<String> loads = new ArrayList<String>();\r
+\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.build;\r
+\r
+import java.awt.Dimension;\r
+import java.awt.Image;\r
+import java.awt.image.BufferedImage;\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.FilenameFilter;\r
+import java.io.IOException;\r
+import java.util.Iterator;\r
+\r
+import javax.imageio.ImageIO;\r
+import javax.imageio.ImageReader;\r
+import javax.imageio.stream.ImageInputStream;\r
+\r
+import com.beust.jcommander.JCommander;\r
+import com.beust.jcommander.Parameter;\r
+import com.beust.jcommander.ParameterException;\r
+import com.beust.jcommander.Parameters;\r
+\r
+public class BuildThumbnails {\r
+\r
+ public static void main(String[] args) {\r
+ Params params = new Params();\r
+ JCommander jc = new JCommander(params);\r
+ try {\r
+ jc.parse(args);\r
+ } catch (ParameterException t) {\r
+ System.err.println(t.getMessage());\r
+ jc.usage();\r
+ }\r
+ createImageThumbnail(params.sourceFolder, params.destinationFolder, params.maximumDimension);\r
+ }\r
+\r
+ public static void createImageThumbnail(String sourceFolder, String destinationFolder,\r
+ int maxDimension) {\r
+ if (maxDimension <= 0)\r
+ return;\r
+ File source = new File(sourceFolder);\r
+ File destination = new File(destinationFolder);\r
+ destination.mkdirs();\r
+ File[] sourceFiles = source.listFiles(new FilenameFilter() {\r
+ @Override\r
+ public boolean accept(File dir, String name) {\r
+ return name.toLowerCase().endsWith(".png");\r
+ }\r
+ });\r
+\r
+ for (File sourceFile : sourceFiles) {\r
+ File destinationFile = new File(destination, sourceFile.getName());\r
+ try {\r
+ Dimension sz = getImageDimensions(sourceFile);\r
+ int w = 0;\r
+ int h = 0;\r
+ if (sz.width > maxDimension) {\r
+ // Scale to Width\r
+ w = maxDimension;\r
+ float f = maxDimension;\r
+ h = (int) ((f / sz.width) * sz.height); // normalize height\r
+ } else if (sz.height > maxDimension) {\r
+ // Scale to Height\r
+ h = maxDimension;\r
+ float f = maxDimension;\r
+ w = (int) ((f / sz.height) * sz.width); // normalize width\r
+ } else {\r
+ // No thumbnail\r
+ return;\r
+ }\r
+ System.out.println("Generating thumbnail for " + sourceFile.getName() + " as (" + w\r
+ + "," + h + ")");\r
+ BufferedImage image = ImageIO.read(sourceFile);\r
+ Image scaledImage = image.getScaledInstance(w, h, BufferedImage.SCALE_SMOOTH);\r
+ BufferedImage destImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);\r
+ destImage.createGraphics().drawImage(scaledImage, 0, 0, null);\r
+ FileOutputStream fos = new FileOutputStream(destinationFile);\r
+ ImageIO.write(destImage, "png", fos);\r
+ fos.flush();\r
+ fos.getFD().sync();\r
+ fos.close();\r
+ } catch (Throwable t) {\r
+ t.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+\r
+ public static Dimension getImageDimensions(File file) throws IOException {\r
+ ImageInputStream in = ImageIO.createImageInputStream(file);\r
+ try {\r
+ final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);\r
+ if (readers.hasNext()) {\r
+ ImageReader reader = readers.next();\r
+ try {\r
+ reader.setInput(in);\r
+ return new Dimension(reader.getWidth(0), reader.getHeight(0));\r
+ } finally {\r
+ reader.dispose();\r
+ }\r
+ }\r
+ } finally {\r
+ if (in != null)\r
+ in.close();\r
+ }\r
+ return null;\r
+ }\r
+\r
+ @Parameters(separators = " ")\r
+ private static class Params {\r
+\r
+ @Parameter(names = { "--sourceFolder" }, description = "Source folder for raw images", required = true)\r
+ public String sourceFolder;\r
+\r
+ @Parameter(names = { "--destinationFolder" }, description = "Destination folder for thumbnails", required = true)\r
+ public String destinationFolder;\r
+\r
+ @Parameter(names = { "--maximumDimension" }, description = "Maximum width or height for thumbnail", required = true)\r
+ public int maximumDimension;\r
+\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.build;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.FileReader;\r
+import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+import com.beust.jcommander.JCommander;\r
+import com.beust.jcommander.Parameter;\r
+import com.beust.jcommander.ParameterException;\r
+import com.beust.jcommander.Parameters;\r
+import com.gitblit.Keys;\r
+import com.gitblit.Keys.server;\r
+import com.gitblit.utils.StringUtils;\r
+\r
+public class BuildWebXml {\r
+ private static final String PARAMS = "<!-- PARAMS -->";\r
+\r
+ private static final String[] STRIP_TOKENS = { "<!-- STRIP", "STRIP -->" };\r
+\r
+ private static final String COMMENT_PATTERN = "\n\t<!-- {0} -->";\r
+\r
+ 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";\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ Params params = new Params();\r
+ JCommander jc = new JCommander(params);\r
+ try {\r
+ jc.parse(args);\r
+ } catch (ParameterException t) {\r
+ System.err.println(t.getMessage());\r
+ jc.usage();\r
+ }\r
+ generateWebXml(params);\r
+ }\r
+\r
+ private static void generateWebXml(Params params) throws Exception {\r
+ // Read the current Gitblit properties\r
+ BufferedReader propertiesReader = new BufferedReader(new FileReader(new File(\r
+ params.propertiesFile)));\r
+\r
+ Vector<Setting> settings = new Vector<Setting>();\r
+ List<String> comments = new ArrayList<String>();\r
+ String line = null;\r
+ while ((line = propertiesReader.readLine()) != null) {\r
+ if (line.length() == 0) {\r
+ comments.clear();\r
+ } else {\r
+ if (line.charAt(0) == '#') {\r
+ if (line.length() > 1) {\r
+ comments.add(line.substring(1).trim());\r
+ }\r
+ } else {\r
+ String[] kvp = line.split("=", 2);\r
+ String key = kvp[0].trim();\r
+ if (!skipKey(key)) {\r
+ Setting s = new Setting(key, kvp[1].trim(), comments);\r
+ settings.add(s);\r
+ }\r
+ comments.clear();\r
+ }\r
+ }\r
+ }\r
+ propertiesReader.close();\r
+\r
+ StringBuilder parameters = new StringBuilder();\r
+\r
+ for (Setting setting : settings) {\r
+ for (String comment : setting.comments) {\r
+ parameters.append(MessageFormat.format(COMMENT_PATTERN, comment));\r
+ }\r
+ parameters.append(MessageFormat.format(PARAM_PATTERN, setting.name, StringUtils.escapeForHtml(setting.value, false)));\r
+ }\r
+\r
+ // Read the prototype web.xml file\r
+ File webxml = new File(params.sourceFile);\r
+ char[] buffer = new char[(int) webxml.length()];\r
+ FileReader webxmlReader = new FileReader(webxml);\r
+ webxmlReader.read(buffer);\r
+ webxmlReader.close();\r
+ String webXmlContent = new String(buffer);\r
+\r
+ // Insert the Gitblit properties into the prototype web.xml\r
+ for (String stripToken : STRIP_TOKENS) {\r
+ webXmlContent = webXmlContent.replace(stripToken, "");\r
+ }\r
+ int idx = webXmlContent.indexOf(PARAMS);\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(webXmlContent.substring(0, idx));\r
+ sb.append(parameters.toString());\r
+ sb.append(webXmlContent.substring(idx + PARAMS.length()));\r
+\r
+ // Save the merged web.xml to the war build folder\r
+ FileOutputStream os = new FileOutputStream(new File(params.destinationFile), false);\r
+ os.write(sb.toString().getBytes());\r
+ os.close();\r
+ }\r
+\r
+ private static boolean skipKey(String key) {\r
+ return key.startsWith(Keys.server._ROOT);\r
+ }\r
+\r
+ private static class Setting {\r
+ final String name;\r
+ final String value;\r
+ final List<String> comments;\r
+\r
+ Setting(String name, String value, List<String> comments) {\r
+ this.name = name;\r
+ this.value = value;\r
+ this.comments = new ArrayList<String>(comments);\r
+ }\r
+ }\r
+\r
+ @Parameters(separators = " ")\r
+ private static class Params {\r
+\r
+ @Parameter(names = { "--sourceFile" }, description = "Source web.xml file", required = true)\r
+ public String sourceFile;\r
+\r
+ @Parameter(names = { "--propertiesFile" }, description = "Properties settings file", required = true)\r
+ public String propertiesFile;\r
+\r
+ @Parameter(names = { "--destinationFile" }, description = "Destination web.xml file", required = true)\r
+ public String destinationFile;\r
+\r
+ }\r
+}\r