summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2013-03-08 19:19:48 -0500
committerJames Moger <james.moger@gmail.com>2013-03-08 19:20:14 -0500
commit926634baaccf8f19f30fa179298ca7edebfeb58d (patch)
tree9f50715e2d9cb3d0732c2321ec154add48f701f0 /src
parent69be7ea90171acfba352ebb5d0f05c72dc63e72a (diff)
downloadiciql-926634baaccf8f19f30fa179298ca7edebfeb58d.tar.gz
iciql-926634baaccf8f19f30fa179298ca7edebfeb58d.zip
Mostly complete migration of build script to Moxie
Diffstat (limited to 'src')
-rw-r--r--src/com/iciql/build/Build.java262
-rw-r--r--src/com/iciql/build/BuildSite.java338
2 files changed, 0 insertions, 600 deletions
diff --git a/src/com/iciql/build/Build.java b/src/com/iciql/build/Build.java
deleted file mode 100644
index 7ce229c..0000000
--- a/src/com/iciql/build/Build.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright 2011 James Moger.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.iciql.build;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.iciql.util.StringUtils;
-
-/**
- * The Build class downloads runtime and compile-time jar files from the Apache
- * Maven repositories.
- *
- * Its important that this class have minimal compile dependencies since its
- * called very early in the build script.
- *
- */
-public class Build {
-
- /**
- * BuildTypes
- */
- public static enum BuildType {
- RUNTIME, COMPILETIME;
- }
-
- public static void main(String... args) {
- runtime();
- compiletime();
- }
-
- public static void runtime() {
- }
-
- public static void compiletime() {
- downloadFromApache(MavenObject.H2, BuildType.RUNTIME);
- downloadFromApache(MavenObject.H2, BuildType.COMPILETIME);
- downloadFromApache(MavenObject.HSQLDB, BuildType.RUNTIME);
- downloadFromApache(MavenObject.DERBY, BuildType.RUNTIME);
- downloadFromApache(MavenObject.MYSQL, BuildType.RUNTIME);
- downloadFromApache(MavenObject.POSTGRESQL, BuildType.RUNTIME);
- downloadFromApache(MavenObject.JCOMMANDER, BuildType.RUNTIME);
- downloadFromApache(MavenObject.JCOMMANDER, BuildType.COMPILETIME);
- downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.RUNTIME);
- downloadFromApache(MavenObject.MARKDOWNPAPERS, BuildType.COMPILETIME);
- downloadFromApache(MavenObject.JUNIT, BuildType.RUNTIME);
- downloadFromApache(MavenObject.DOCLAVA, BuildType.RUNTIME);
- downloadFromApache(MavenObject.DOCLAVA, BuildType.COMPILETIME);
- downloadFromApache(MavenObject.SLF4JAPI, BuildType.RUNTIME);
- downloadFromApache(MavenObject.SLF4JAPI, BuildType.COMPILETIME);
- downloadFromApache(MavenObject.COMMONSPOOL, BuildType.RUNTIME);
- downloadFromApache(MavenObject.COMMONSPOOL, BuildType.COMPILETIME);
- downloadFromApache(MavenObject.COMMONSDBCP, BuildType.RUNTIME);
- downloadFromApache(MavenObject.COMMONSDBCP, BuildType.COMPILETIME);
-
- // needed for site publishing
- downloadFromApache(MavenObject.COMMONSNET, BuildType.RUNTIME);
- }
-
- /**
- * Download a file from the official Apache Maven repository.
- *
- * @param mo
- * the maven object to download.
- * @return
- */
- private static List<File> downloadFromApache(MavenObject mo, BuildType type) {
- return downloadFromMaven("http://repo1.maven.org/maven2/", mo, type);
- }
-
- /**
- * Download a file from a Maven repository.
- *
- * @param mo
- * the maven object to download.
- * @return
- */
- private static List<File> downloadFromMaven(String mavenRoot, MavenObject mo, BuildType type) {
- List<File> downloads = new ArrayList<File>();
- String[] jars = { "" };
- if (BuildType.RUNTIME.equals(type)) {
- jars = new String[] { "" };
- } else if (BuildType.COMPILETIME.equals(type)) {
- jars = new String[] { "-sources", "-javadoc" };
- }
- for (String jar : jars) {
- File targetFile = mo.getLocalFile("ext", jar);
- if (targetFile.exists()) {
- downloads.add(targetFile);
- continue;
- }
- String expectedSHA1 = mo.getSHA1(jar);
- if (expectedSHA1 == null) {
- // skip this jar
- continue;
- }
- String mavenURL = mavenRoot + mo.getRepositoryPath(jar);
- if (!targetFile.getAbsoluteFile().getParentFile().exists()) {
- boolean success = targetFile.getAbsoluteFile().getParentFile().mkdirs();
- if (!success) {
- throw new RuntimeException("Failed to create destination folder structure!");
- }
- }
- ByteArrayOutputStream buff = new ByteArrayOutputStream();
- try {
- URL url = new URL(mavenURL);
- InputStream in = new BufferedInputStream(url.openStream());
- byte[] buffer = new byte[4096];
-
- System.out.println("d/l: " + targetFile.getName());
- while (true) {
- int len = in.read(buffer);
- if (len < 0) {
- break;
- }
- buff.write(buffer, 0, len);
- }
- in.close();
-
- } catch (IOException e) {
- throw new RuntimeException("Error downloading " + mavenURL + " to " + targetFile, e);
- }
- byte[] data = buff.toByteArray();
- String calculatedSHA1 = StringUtils.calculateSHA1(data);
-
- System.out.println();
-
- if (expectedSHA1.length() == 0) {
- System.out.println("sha: " + calculatedSHA1);
- System.out.println();
- } else {
- if (!calculatedSHA1.equals(expectedSHA1)) {
- throw new RuntimeException("SHA1 checksum mismatch; got: " + calculatedSHA1);
- }
- }
- try {
- RandomAccessFile ra = new RandomAccessFile(targetFile, "rw");
- ra.write(data);
- ra.setLength(data.length);
- ra.close();
- } catch (IOException e) {
- throw new RuntimeException("Error writing to file " + targetFile, e);
- }
- downloads.add(targetFile);
- }
- return downloads;
- }
-
- /**
- * Class that describes a retrievable Maven object.
- */
- private static class MavenObject {
-
- public static final MavenObject JCOMMANDER = new MavenObject("com/beust", "jcommander", "1.17",
- "219a3540f3b27d7cc3b1d91d6ea046cd8723290e", "0bb50eec177acf0e94d58e0cf07262fe5164331d",
- "c7adc475ca40c288c93054e0f4fe58f3a98c0cb5");
-
- public static final MavenObject H2 = new MavenObject("com/h2database", "h2", "1.3.168",
- "eb32936a239d95220f5b2d2973a7b17372f98b54", "61da28f8c48d07c099fc78d72c6152b84d89b4ca",
- "724ff8347553919e703a369a856713a8e7ef4fac");
-
- public static final MavenObject HSQLDB = new MavenObject("org/hsqldb", "hsqldb", "2.2.8",
- "8231a3ff71ba5889f9e2d01ce13503cbdd4038e9", "", "");
-
- public static final MavenObject DERBY = new MavenObject("org/apache/derby", "derby", "10.9.1.0",
- "4538cf5564ab3c262eec65c55fdb13965625589c", "", "");
-
- public static final MavenObject MYSQL = new MavenObject("mysql", "mysql-connector-java", "5.1.15",
- "0fbc80454d27cc65f3addfa516707e9f8e60c3eb", "", "");
-
- public static final MavenObject POSTGRESQL = new MavenObject("postgresql", "postgresql", "9.0-801.jdbc4",
- "153f2f92a786f12fc111d0111f709012df87c808", "", "");
-
- public static final MavenObject JUNIT = new MavenObject("junit", "junit", "4.8.2",
- "c94f54227b08100974c36170dcb53329435fe5ad", "", "");
-
- public static final MavenObject MARKDOWNPAPERS = new MavenObject("org/tautua/markdownpapers",
- "markdownpapers-core", "1.1.0", "b879b4720fa642d3c490ab559af132daaa16dbb4",
- "d98c53939815be2777d5a56dcdc3bbc9ddb468fa", "4c09d2d3073e85b973572292af00bd69681df76b");
-
- public static final MavenObject COMMONSNET = new MavenObject("commons-net", "commons-net", "1.4.0",
- "eb47e8cad2dd7f92fd7e77df1d1529cae87361f7", "", "");
-
- public static final MavenObject DOCLAVA = new MavenObject("com/google/doclava", "doclava", "1.0.3",
- "5a1e05977fd36480b0cf314410440f88e3a0049e", "6e314df1733455d66b98b56014363172773d0905",
- "1c1aa631b235439356e6e5803319caca80aaaa88");
-
- public static final MavenObject SLF4JAPI = new MavenObject("org/slf4j", "slf4j-api", "1.6.1",
- "6f3b8a24bf970f17289b234284c94f43eb42f0e4", "46a386136c901748e6a3af67ebde6c22bc6b4524",
- "e223571d77769cdafde59040da235842f3326453");
-
- public static final MavenObject COMMONSPOOL = new MavenObject("commons-pool", "commons-pool", "1.5.6",
- "16390e2d74df4ab08c06a85d42a74a951dc93ad7", "bbfb73ed3c341d9738c64da8157910b967f878d6",
- "d72204023b30cd9fecb64829586472f3c6806005");
-
- public static final MavenObject COMMONSDBCP = new MavenObject("commons-dbcp", "commons-dbcp", "1.4",
- "30be73c965cc990b153a100aaaaafcf239f82d39", "9b076ff231434d5403be6599a1347019b12c0def",
- "098bf7c8d5b026f6e3969259a36e813ac37432b3");
-
- public final String group;
- public final String artifact;
- public final String version;
- public final String librarySHA1;
- public final String sourcesSHA1;
- public final String javadocSHA1;
-
- private MavenObject(String group, String artifact, String version, String librarySHA1,
- String sourcesSHA1, String javadocSHA1) {
- this.group = group;
- this.artifact = artifact;
- this.version = version;
- this.librarySHA1 = librarySHA1;
- this.sourcesSHA1 = sourcesSHA1;
- this.javadocSHA1 = javadocSHA1;
- }
-
- private String getRepositoryPath(String jar) {
- return group + "/" + artifact + "/" + version + "/" + artifact + "-" + version + jar + ".jar";
- }
-
- private File getLocalFile(String basePath, String jar) {
- return new File(basePath, artifact + "-" + version + jar + ".jar");
- }
-
- private String getSHA1(String jar) {
- if (jar.equals("")) {
- return librarySHA1;
- } else if (jar.equals("-sources")) {
- return sourcesSHA1;
- } else if (jar.equals("-javadoc")) {
- return javadocSHA1;
- }
- return librarySHA1;
- }
-
- @Override
- public String toString() {
- return group;
- }
- }
-}
diff --git a/src/com/iciql/build/BuildSite.java b/src/com/iciql/build/BuildSite.java
deleted file mode 100644
index 81863ee..0000000
--- a/src/com/iciql/build/BuildSite.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * Copyright 2011 James Moger.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.iciql.build;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-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;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
-import org.tautua.markdownpapers.Markdown;
-
-import com.beust.jcommander.JCommander;
-import com.beust.jcommander.Parameter;
-import com.beust.jcommander.ParameterException;
-import com.beust.jcommander.Parameters;
-import com.iciql.Constants;
-import com.iciql.util.StringUtils;
-
-/**
- * Builds the web site or deployment documentation from Markdown source files.
- *
- * All Markdown source files must have the .mkd extension.
- *
- * Natural string sort order of the Markdown source filenames is the order of
- * page links. "##_" prefixes are used to control the sort order.
- *
- * @author James Moger
- *
- */
-public class BuildSite {
-
- public static void main(String... args) {
- Params params = new Params();
- JCommander jc = new JCommander(params);
- try {
- jc.parse(args);
- } catch (ParameterException t) {
- usage(jc, t);
- }
-
- File sourceFolder = new File(params.sourceFolder);
- File destinationFolder = new File(params.outputFolder);
- File[] markdownFiles = sourceFolder.listFiles(new FilenameFilter() {
-
- @Override
- public boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".mkd");
- }
- });
- Arrays.sort(markdownFiles);
-
- Map<String, String> aliasMap = new HashMap<String, String>();
- for (String alias : params.aliases) {
- String[] values = alias.split("=");
- aliasMap.put(values[0], values[1]);
- }
-
- System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ",
- markdownFiles.length, sourceFolder.getAbsolutePath()));
- String linkPattern = "<a href=''{0}''>{1}</a>";
- StringBuilder sb = new StringBuilder();
- for (File file : markdownFiles) {
- String documentName = getDocumentName(file);
- if (!params.skips.contains(documentName)) {
- String displayName = documentName;
- if (aliasMap.containsKey(documentName)) {
- displayName = aliasMap.get(documentName);
- } else {
- displayName = displayName.replace('_', ' ');
- }
- String fileName = documentName + ".html";
- sb.append(MessageFormat.format(linkPattern, fileName, displayName));
- sb.append(" | ");
- }
- }
- sb.setLength(sb.length() - 3);
- sb.trimToSize();
-
- String htmlHeader = readContent(new File(params.pageHeader), "\n");
-
- String htmlAdSnippet = null;
- if (!StringUtils.isNullOrEmpty(params.adSnippet)) {
- File snippet = new File(params.adSnippet);
- if (snippet.exists()) {
- htmlAdSnippet = readContent(snippet, "\n");
- }
- }
- String htmlFooter = readContent(new File(params.pageFooter), "\n");
- String links = sb.toString();
- String header = MessageFormat.format(htmlHeader, Constants.NAME, links);
- if (!StringUtils.isNullOrEmpty(params.analyticsSnippet)) {
- File snippet = new File(params.analyticsSnippet);
- if (snippet.exists()) {
- String htmlSnippet = 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) {
- try {
- String documentName = getDocumentName(file);
- if (!params.skips.contains(documentName)) {
- String fileName = documentName + ".html";
- System.out.println(MessageFormat.format(" {0} => {1}", file.getName(), fileName));
- String rawContent = readContent(file, "\n");
- String markdownContent = rawContent;
-
- Map<String, List<String>> nomarkdownMap = new HashMap<String, List<String>>();
-
- // extract sections marked as no-markdown
- int nmd = 0;
- for (String token : params.nomarkdown) {
- StringBuilder strippedContent = new StringBuilder();
-
- String nomarkdownKey = "%NOMARKDOWN" + nmd + "%";
- String[] kv = token.split(":", 2);
- String beginToken = kv[0];
- String endToken = kv[1];
-
- // strip nomarkdown chunks from markdown and cache them
- List<String> chunks = new Vector<String>();
- int beginCode = 0;
- int endCode = 0;
- while ((beginCode = markdownContent.indexOf(beginToken, endCode)) > -1) {
- if (endCode == 0) {
- strippedContent.append(markdownContent.substring(0, beginCode));
- } else {
- strippedContent.append(markdownContent.substring(endCode, beginCode));
- }
- strippedContent.append(nomarkdownKey);
- endCode = markdownContent.indexOf(endToken, beginCode);
- chunks.add(markdownContent.substring(beginCode, endCode));
- nomarkdownMap.put(nomarkdownKey, chunks);
- }
-
- // get remainder of text
- if (endCode < markdownContent.length()) {
- strippedContent.append(markdownContent.substring(endCode,
- markdownContent.length()));
- }
- markdownContent = strippedContent.toString();
- nmd++;
- }
-
- // transform markdown to html
- String content = transformMarkdown(new StringReader(markdownContent.toString()));
-
- // reinsert nomarkdown chunks
- for (Map.Entry<String, List<String>> nomarkdown : nomarkdownMap.entrySet()) {
- for (String chunk : nomarkdown.getValue()) {
- content = content.replaceFirst(nomarkdown.getKey(), chunk);
- }
- }
-
- // perform specified substitutions
- for (String token : params.substitutions) {
- String[] kv = token.split("=", 2);
- content = content.replace(kv[0], kv[1]);
- }
- for (String token : params.regex) {
- String[] kv = token.split("!!!", 2);
- content = content.replaceAll(kv[0], kv[1]);
- }
- for (String alias : params.loads) {
- String[] kv = alias.split("=", 2);
- String loadedContent = StringUtils.readContent(new File(kv[1]), "\n");
- loadedContent = StringUtils.escapeForHtml(loadedContent, false);
- loadedContent = StringUtils.breakLinesForHtml(loadedContent);
- content = content.replace(kv[0], loadedContent);
- }
-
- OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(
- destinationFolder, fileName)), Charset.forName("UTF-8"));
- writer.write(header);
- if (!StringUtils.isNullOrEmpty(htmlAdSnippet)) {
- writer.write(htmlAdSnippet);
- }
- writer.write(content);
- writer.write(footer);
- writer.close();
- }
- } catch (Throwable t) {
- System.err.println("Failed to transform " + file.getName());
- t.printStackTrace();
- }
- }
- }
-
- private static String getDocumentName(File file) {
- String displayName = file.getName().substring(0, file.getName().lastIndexOf('.')).toLowerCase();
- int underscore = displayName.indexOf('_') + 1;
- if (underscore > -1) {
- // trim leading ##_ which is to control display order
- return displayName.substring(underscore);
- }
- return displayName;
- }
-
- /**
- * Returns the string content of the specified file.
- *
- * @param file
- * @param lineEnding
- * @return the string content of the file
- */
- private static String readContent(File file, String lineEnding) {
- StringBuilder sb = new StringBuilder();
- try {
- InputStreamReader is = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
- BufferedReader reader = new BufferedReader(is);
- String line = null;
- while ((line = reader.readLine()) != null) {
- sb.append(line);
- if (lineEnding != null) {
- sb.append(lineEnding);
- }
- }
- reader.close();
- } catch (Throwable t) {
- System.err.println("Failed to read content of " + file.getAbsolutePath());
- t.printStackTrace();
- }
- return sb.toString();
- }
-
- private static String transformMarkdown(Reader markdownReader) throws ParseException {
- // Read raw markdown content and transform it to html
- StringWriter writer = new StringWriter();
- try {
- Markdown md = new Markdown();
- md.transform(markdownReader, writer);
- return writer.toString().trim();
- } catch (org.tautua.markdownpapers.parser.ParseException p) {
- throw new java.text.ParseException(p.getMessage(), 0);
- } finally {
- try {
- markdownReader.close();
- } catch (IOException e) {
- // IGNORE
- }
- try {
- writer.close();
- } catch (IOException e) {
- // IGNORE
- }
- }
- }
-
- private static void usage(JCommander jc, ParameterException t) {
- System.out.println(Constants.NAME + " v" + Constants.VERSION);
- System.out.println();
- if (t != null) {
- System.out.println(t.getMessage());
- System.out.println();
- }
- if (jc != null) {
- jc.usage();
- }
- System.exit(0);
- }
-
- /**
- * Command-line parameters for BuildSite utility.
- */
- @Parameters(separators = " ")
- private static class Params {
-
- @Parameter(names = { "--sourceFolder" }, description = "Markdown Source Folder", required = true)
- public String sourceFolder;
-
- @Parameter(names = { "--outputFolder" }, description = "HTML Ouptut Folder", required = true)
- public String outputFolder;
-
- @Parameter(names = { "--pageHeader" }, description = "Page Header HTML Snippet", required = true)
- public String pageHeader;
-
- @Parameter(names = { "--pageFooter" }, description = "Page Footer HTML Snippet", required = true)
- public String pageFooter;
-
- @Parameter(names = { "--adSnippet" }, description = "Ad HTML Snippet", required = false)
- public String adSnippet;
-
- @Parameter(names = { "--analyticsSnippet" }, description = "Analytics HTML Snippet", required = false)
- public String analyticsSnippet;
-
- @Parameter(names = { "--skip" }, description = "Filename to skip", required = false)
- public List<String> skips = new ArrayList<String>();
-
- @Parameter(names = { "--alias" }, description = "Filename=Linkname aliases", required = false)
- public List<String> aliases = new ArrayList<String>();
-
- @Parameter(names = { "--substitute" }, description = "%TOKEN%=value", required = false)
- public List<String> substitutions = new ArrayList<String>();
-
- @Parameter(names = { "--load" }, description = "%TOKEN%=filename", required = false)
- public List<String> loads = new ArrayList<String>();
-
- @Parameter(names = { "--nomarkdown" }, description = "%STARTTOKEN%:%ENDTOKEN%", required = false)
- public List<String> nomarkdown = new ArrayList<String>();
-
- @Parameter(names = { "--regex" }, description = "searchPattern!!!replacePattern", required = false)
- public List<String> regex = new ArrayList<String>();
-
- }
-}