You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by km...@apache.org on 2013/09/25 19:15:31 UTC
svn commit: r1526235 [3/3] - in /incubator/knox: ./ site/ site/books/
site/books/knox-incubating-0-3-0/ trunk/ trunk/books/ trunk/books/0.3.0/
trunk/books/common/ trunk/books/static/ trunk/markbook/ trunk/markbook/src/
trunk/markbook/src/main/ trunk/ma...
Added: incubator/knox/trunk/markbook/pom.xml
URL: http://svn.apache.org/viewvc/incubator/knox/trunk/markbook/pom.xml?rev=1526235&view=auto
==============================================================================
--- incubator/knox/trunk/markbook/pom.xml (added)
+++ incubator/knox/trunk/markbook/pom.xml Wed Sep 25 17:15:30 2013
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>gateway-site</artifactId>
+ <groupId>org.apache.hadoop.gateway</groupId>
+ <version>0.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>markbook</artifactId>
+ <name>markbook</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>2.1</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <outputFile>target/markbook.jar</outputFile>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>org.apache.hadoop.gateway.markbook.MarkBook</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.pegdown</groupId>
+ <artifactId>pegdown</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: incubator/knox/trunk/markbook/src/main/java/org/apache/hadoop/gateway/markbook/MarkBook.java
URL: http://svn.apache.org/viewvc/incubator/knox/trunk/markbook/src/main/java/org/apache/hadoop/gateway/markbook/MarkBook.java?rev=1526235&view=auto
==============================================================================
--- incubator/knox/trunk/markbook/src/main/java/org/apache/hadoop/gateway/markbook/MarkBook.java (added)
+++ incubator/knox/trunk/markbook/src/main/java/org/apache/hadoop/gateway/markbook/MarkBook.java Wed Sep 25 17:15:30 2013
@@ -0,0 +1,195 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.hadoop.gateway.markbook;
+
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.SystemUtils;
+import org.pegdown.Extensions;
+import org.pegdown.PegDownProcessor;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MarkBook {
+
+ public static void main( String[] args ) throws IOException, ParseException {
+// Pattern pattern = Pattern.compile( "<<(.+?)>>" );
+// Matcher matcher = pattern.matcher( "before <<first>> <<second>> after" );
+// matcher.find();
+// System.out.println( matcher.group( 1 ) );
+// System.out.println( matcher.replaceFirst( "__" + matcher.group( 1 ) + "__" ) );
+// matcher = pattern.matcher( matcher.replaceFirst( "__" + matcher.group( 1 ) + "__" ) );
+// matcher.find();
+// System.out.println( matcher.group( 1 ) );
+// System.out.println( matcher.replaceFirst( "__" + matcher.group( 1 ) + "__" ) );
+
+// Pattern pattern = Pattern.compile( "<\\!---\\s*.*\\s*--->" );
+// String text = "before <!---\nincluded\n---> after";
+// Matcher matcher = pattern.matcher( text );
+// matcher.find();
+// System.out.println( replace( matcher, text, "X" ) );
+
+// System.out.println( replaceIdentifiers( "{{text}}" ) );
+// System.out.println( removeComments( "line\r\n<!--- \r\n comment \r\n comment \r\n---> \r\nline" ) );
+
+ CommandLine command = parseCommandLine( args );
+ String markdown = loadMarkdown( command );
+ storeHtml( command, markdown );
+ }
+
+ private static void storeHtml( CommandLine command, String markdown ) throws IOException {
+ PegDownProcessor processor = new PegDownProcessor(
+ Extensions.AUTOLINKS | Extensions.FENCED_CODE_BLOCKS | Extensions.QUOTES +
+ Extensions.SMARTS | Extensions.TABLES | Extensions.WIKILINKS );
+ log( "Converting markdown (" + markdown.length() + " bytes) to HTML" );
+ String html = processor.markdownToHtml( markdown.toString() );
+ File outputFile = new File( command.getOptionValue( "o" ) );
+ log( "Storing HTML to " + outputFile.getAbsolutePath() );
+ FileUtils.write( outputFile, html );
+ }
+
+ private static String loadMarkdown( CommandLine command ) throws IOException {
+ StringBuilder markdown = new StringBuilder();
+ for( String inputFileName : command.getOptionValues( "i" ) ) {
+ File inputFile = new File( inputFileName );
+ log( "Loading markdown from " + inputFile.getAbsolutePath() );
+ markdown.append( loadMarkdown( inputFile ) );
+ markdown.append( SystemUtils.LINE_SEPARATOR );
+ }
+ return markdown.toString();
+ }
+
+ private static String loadMarkdown( File file ) throws IOException {
+ String text = FileUtils.readFileToString( file );
+ text = removeComments( text );
+ text = replaceIdentifiers( text );
+ text = replaceIncludes( file, text );
+ return text;
+ }
+
+ private static String replaceIncludes( File file, String text ) throws IOException {
+ Pattern pattern = Pattern.compile( "<<\\s*(.+?)\\s*>>" );
+ Matcher matcher = pattern.matcher( text );
+ while( matcher.find() ) {
+ String includeFileName = matcher.group( 1 );
+ File includeFile = new File( file.getParent(), includeFileName );
+ if( includeFile.exists() && includeFile.canRead() ) {
+ String includeString = loadMarkdown( includeFile );
+ text = replace( matcher, text, includeString );
+ } else {
+ text = replace( matcher, text, includeFileName );
+ }
+ matcher = pattern.matcher( text );
+ }
+ return text;
+ }
+
+ private static String replaceIdentifiers( String text ) throws IOException {
+ Pattern pattern = Pattern.compile( "\\{\\{(.+?)\\}\\}" );
+ Matcher matcher = pattern.matcher( text );
+ while( matcher.find() ) {
+ String name = matcher.group( 1 ).trim();
+ String id = name.replaceAll( "\\s", "+" );
+ text = replace( matcher, text, String.format( "<a id=\"%s\"></a>%s", id, name ) );
+ matcher = pattern.matcher( text );
+ }
+ return text;
+ }
+
+ private static String removeComments( String text ) {
+ Pattern pattern = Pattern.compile( "<!---.*--->", Pattern.DOTALL );
+ Matcher matcher = pattern.matcher( text );
+ while( matcher.find() ) {
+ text = replace( matcher, text, "" );
+ matcher = pattern.matcher( text );
+ }
+ return text;
+ }
+
+ private static String replace( Matcher matcher, String original, String replace ) {
+ return original.substring( 0, matcher.start() ) + replace + original.substring( matcher.end(), matcher.regionEnd() );
+ }
+
+ private static Options createOptions() {
+ Options options = new Options();
+
+ Option help = OptionBuilder
+ .withArgName( "help" )
+ .withLongOpt( "help" )
+ .withDescription( "Prints this help." )
+ .create( "h" );
+
+ Option input = OptionBuilder
+ .withArgName( "input" )
+ .withLongOpt( "input" )
+ .hasArg()
+ .withDescription( "Repeat for each Markdown input file name." )
+ .create( "i" );
+
+ Option output = OptionBuilder
+ .withArgName( "output" )
+ .withLongOpt( "output" )
+ .hasArgs( 1 )
+ //.isRequired()
+ .withDescription( "A single output HTML file name." )
+ .create( "o" );
+
+ options.addOption( input );
+ options.addOption( output );
+ options.addOption( help );
+
+ return options;
+ }
+
+ private static CommandLine parseCommandLine( String[] args ) throws ParseException {
+ Options options = createOptions();
+ CommandLineParser parser = new BasicParser();
+ CommandLine command = parser.parse( options, args );
+ if( command.hasOption( "help" ) ) {
+ printHelp( options );
+ }
+ if( !command.hasOption( "input" ) || command.getOptionValues( "input" ).length == 0 ) {
+ printHelp( options );
+ }
+ if( !command.hasOption( "output" ) || command.getOptionValues( "output" ).length != 1 ) {
+ printHelp( options );
+ }
+ return command;
+ }
+
+ private static void printHelp( Options options ) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "java -jar pegdown.jar", options );
+ System.exit( -1 );
+ }
+
+ private static void log( String message ) {
+ System.out.println( message );
+ }
+
+}
Modified: incubator/knox/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/knox/trunk/pom.xml?rev=1526235&r1=1526234&r2=1526235&view=diff
==============================================================================
--- incubator/knox/trunk/pom.xml (original)
+++ incubator/knox/trunk/pom.xml Wed Sep 25 17:15:30 2013
@@ -20,10 +20,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
<modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.hadoop</groupId>
+ <groupId>org.apache.hadoop.gateway</groupId>
<artifactId>gateway-site</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <version>0.0.0-SNAPSHOT</version>
+
+ <modules>
+ <module>markbook</module>
+ </modules>
<name>Apache Knox Gateway</name>
<description>Knox is a gateway for Hadoop clusters.</description>
@@ -34,7 +40,6 @@
<HHH>###</HHH>
<HHHH>####</HHHH>
<HHHHH>#####</HHHHH>
- <gateway-version>0.2.0-SNAPSHOT</gateway-version>
</properties>
<licenses>
@@ -192,7 +197,7 @@
<configuration>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
- <outputDirectory>../site</outputDirectory>
+ <outputDirectory>../../site</outputDirectory>
</configuration>
</plugin>
</plugins>