com.exadatum.xsuite.xmaven.bash.doc.DoxiaDocPageGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bash-maven-plugin Show documentation
Show all versions of bash-maven-plugin Show documentation
Bash Maven Plugin is used to generate documentation as well as to run unit test for bash scripts.
The newest version!
package com.exadatum.xsuite.xmaven.bash.doc;
/*-
* #%L
* Bash Plugin
* %%
* Copyright (C) 2016 - 2018 Exadatum Software Services Pvt. Ltd.
* %%
* 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.
* #L%
*/
import java.util.List;
import org.apache.maven.doxia.sink.Sink;
/**
* Report generator using Doxia.
*/
public class DoxiaDocPageGenerator implements DocGenerator {
/**
* Maven Doxia API to produce a resultant output format.
*/
private Sink sink;
/**
* Constructor to initialize sink.
*
* @param sink
*/
public DoxiaDocPageGenerator(final Sink sink) {
this.sink = sink;
}
/**
* Default Constructor.
*/
public DoxiaDocPageGenerator() {
}
/**
* Getter for Sink.
*
* @return sink
*/
public Sink getSink() {
return sink;
}
/**
* Setter for Sink.
*
* @param sink
*/
public void setSink(final Sink sink) {
this.sink = sink;
}
/**
*
* @param context
* {@link DocGeneratorContext} contains information about the
* template file, output file and the parsed document block objects
* to be used in generation.
*/
@Override
public void generate(final DocGeneratorContext context) {
List docBlocks = context.getDocBlocks();
Sink sink = context.getSink();
sink.body();
sink.lineBreak();
sink.horizontalRule();
sink.bold();
sink.text(context.getFileName() + ".sh");
sink.bold_();
for (DocBlock docBlock : docBlocks) {
if (docBlock.getTarget() == "Description") {
sink.lineBreak();
sink.italic();
sink.text(docBlock.getDescription());
sink.italic_();
}
}
sink.horizontalRule();
sink.lineBreak();
sink.text("Description of Constants");
sink.table();
sink.tableRow();
sink.tableHeaderCell();
sink.text("Constant");
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text("Description");
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text("Annotations");
sink.tableHeaderCell_();
sink.tableRow_();
for (int i = 0; i < docBlocks.size(); i++) {
sink.tableRow();
if (docBlocks.get(i).getTarget().indexOf("=") != -1) {
sinkCell(sink, docBlocks.get(i).getTarget());
sinkCell(sink, docBlocks.get(i).getDescription());
sinkCell(sink, docBlocks.get(i).getAnnotations().toString());
}
sink.tableRow_();
}
sink.table_();
sink.lineBreak();
sink.text("Description of Functions");
sink.table();
sink.tableRow();
sink.tableHeaderCell();
sink.text("Function");
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text("Description");
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text("Annotations");
sink.tableHeaderCell_();
sink.tableRow_();
for (int i = 0; i < docBlocks.size(); i++) {
sink.tableRow();
if (docBlocks.get(i).getTarget().indexOf("=") == -1
&& !docBlocks.get(i).getTarget().equals("Description")) {
sinkCell(sink, docBlocks.get(i).getTarget());
sinkCell(sink, docBlocks.get(i).getDescription());
getLineSeperatedAnnotations(sink, docBlocks.get(i).getAnnotations());
}
sink.tableRow_();
}
sink.table_();
sink.horizontalRule();
sink.body_();
}
/**
*
* @param annotations
* List of annotations
* @param sink
* sink
*/
private void getLineSeperatedAnnotations(final Sink sink,
final List annotations) {
sink.tableCell();
for (DocBlock.Annotation annotation : annotations) {
sink.bold();
sink.text(annotation.getKey() + " : ");
sink.bold_();
sink.text(annotation.getValue() + " ");
sink.bold();
if (!annotation.getDescription().isEmpty())
sink.text("Description : ");
sink.bold_();
sink.text(annotation.getDescription());
sink.lineBreak();
}
sink.tableCell_();
}
/**
* Create a table cell.
*
* @param sink
* @param text
*/
private void sinkCell(final Sink sink, final String text) {
sink.tableCell();
sink.text(text);
sink.tableCell_();
}
}