Split GATKDoclet from ResourceBundleDoclet. Refactored GaTKDocWorkUnit
This commit is contained in:
parent
7b84347047
commit
9f06f6c493
|
|
@ -28,7 +28,6 @@ import com.sun.javadoc.ClassDoc;
|
|||
import com.sun.javadoc.RootDoc;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
|
@ -52,5 +51,5 @@ public abstract class DocumentedGATKFeatureHandler {
|
|||
}
|
||||
|
||||
public abstract String getTemplateName(ClassDoc doc) throws IOException;
|
||||
public abstract void processOne(RootDoc rootDoc, GATKDoclet.DocWorkUnit toProcess, Set<GATKDoclet.DocWorkUnit> all);
|
||||
public abstract void processOne(RootDoc rootDoc, GATKDocWorkUnit toProcess, Set<GATKDocWorkUnit> all);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2011, The Broad Institute
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.sting.utils.help;
|
||||
|
||||
import com.sun.javadoc.ClassDoc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: depristo
|
||||
* Date: 7/24/11
|
||||
* Time: 7:59 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class GATKDocWorkUnit implements Comparable<GATKDocWorkUnit> {
|
||||
// known at the start
|
||||
final String name, filename, group;
|
||||
final DocumentedGATKFeatureHandler handler;
|
||||
final ClassDoc classDoc;
|
||||
final Class clazz;
|
||||
final DocumentedGATKFeature annotation;
|
||||
final String buildTimestamp, absoluteVersion;
|
||||
|
||||
// set by the handler
|
||||
String summary;
|
||||
Map<String, Object> forTemplate;
|
||||
|
||||
public GATKDocWorkUnit(String name, String filename, String group,
|
||||
DocumentedGATKFeature annotation, DocumentedGATKFeatureHandler handler,
|
||||
ClassDoc classDoc, Class clazz,
|
||||
String buildTimestamp, String absoluteVersion) {
|
||||
this.annotation = annotation;
|
||||
this.name = name;
|
||||
this.filename = filename;
|
||||
this.group = group;
|
||||
this.handler = handler;
|
||||
this.classDoc = classDoc;
|
||||
this.clazz = clazz;
|
||||
this.buildTimestamp = buildTimestamp;
|
||||
this.absoluteVersion = absoluteVersion;
|
||||
}
|
||||
|
||||
public void setHandlerContent(String summary, Map<String, Object> forTemplate) {
|
||||
this.summary = summary;
|
||||
this.forTemplate = forTemplate;
|
||||
}
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> data = new HashMap<String, String>();
|
||||
data.put("name", name);
|
||||
data.put("summary", summary);
|
||||
data.put("filename", filename);
|
||||
data.put("group", group);
|
||||
return data;
|
||||
}
|
||||
|
||||
public int compareTo(GATKDocWorkUnit other) {
|
||||
return this.name.compareTo(other.name);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ import freemarker.template.TemplateException;
|
|||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||
import sun.misc.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
|
@ -41,57 +40,11 @@ import java.util.*;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
||||
public class GATKDoclet {
|
||||
final protected static File SETTINGS_DIR = new File("settings/helpTemplates");
|
||||
final protected static File DESTINATION_DIR = new File("gatkdocs");
|
||||
final protected static Logger logger = Logger.getLogger(GATKDoclet.class);
|
||||
|
||||
public static class DocWorkUnit implements Comparable<DocWorkUnit> {
|
||||
// known at the start
|
||||
final String name, filename, group;
|
||||
final DocumentedGATKFeatureHandler handler;
|
||||
final ClassDoc classDoc;
|
||||
final Class clazz;
|
||||
final DocumentedGATKFeature annotation;
|
||||
final String buildTimestamp, absoluteVersion;
|
||||
|
||||
// set by the handler
|
||||
String summary;
|
||||
Map<String, Object> forTemplate;
|
||||
|
||||
public DocWorkUnit(String name, String filename, String group,
|
||||
DocumentedGATKFeature annotation, DocumentedGATKFeatureHandler handler,
|
||||
ClassDoc classDoc, Class clazz,
|
||||
String buildTimestamp, String absoluteVersion) {
|
||||
this.annotation = annotation;
|
||||
this.name = name;
|
||||
this.filename = filename;
|
||||
this.group = group;
|
||||
this.handler = handler;
|
||||
this.classDoc = classDoc;
|
||||
this.clazz = clazz;
|
||||
this.buildTimestamp = buildTimestamp;
|
||||
this.absoluteVersion = absoluteVersion;
|
||||
}
|
||||
|
||||
public void setHandlerContent(String summary, Map<String, Object> forTemplate) {
|
||||
this.summary = summary;
|
||||
this.forTemplate = forTemplate;
|
||||
}
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> data = new HashMap<String, String>();
|
||||
data.put("name", name);
|
||||
data.put("summary", summary);
|
||||
data.put("filename", filename);
|
||||
data.put("group", group);
|
||||
return data;
|
||||
}
|
||||
|
||||
public int compareTo(DocWorkUnit other) {
|
||||
return this.name.compareTo(other.name);
|
||||
}
|
||||
}
|
||||
protected static String buildTimestamp = null, absoluteVersion = null;
|
||||
|
||||
RootDoc rootDoc;
|
||||
|
||||
|
|
@ -102,17 +55,33 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
* @throws java.io.IOException if output can't be written.
|
||||
*/
|
||||
public static boolean start(RootDoc rootDoc) throws IOException {
|
||||
// load arguments
|
||||
for(String[] options: rootDoc.options()) {
|
||||
if(options[0].equals("-build-timestamp"))
|
||||
buildTimestamp = options[1];
|
||||
if (options[0].equals("-absolute-version"))
|
||||
absoluteVersion = options[1];
|
||||
}
|
||||
|
||||
GATKDoclet doclet = new GATKDoclet();
|
||||
doclet.processDocs(rootDoc, null);
|
||||
doclet.processDocs(rootDoc);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the given options against options supported by this doclet.
|
||||
* @param option Option to validate.
|
||||
* @return Number of potential parameters; 0 if not supported.
|
||||
*/
|
||||
public static int optionLength(String option) {
|
||||
return ResourceBundleExtractorDoclet.optionLength(option);
|
||||
if(option.equals("-build-timestamp") || option.equals("-absolute-version") ) {
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Set<DocWorkUnit> workUnits() {
|
||||
TreeSet<DocWorkUnit> m = new TreeSet<DocWorkUnit>();
|
||||
public Set<GATKDocWorkUnit> workUnits() {
|
||||
TreeSet<GATKDocWorkUnit> m = new TreeSet<GATKDocWorkUnit>();
|
||||
|
||||
for ( ClassDoc doc : rootDoc.classes() ) {
|
||||
System.out.printf("Considering %s%n", doc);
|
||||
|
|
@ -121,7 +90,7 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
DocumentedGATKFeatureHandler handler = createHandler(doc, feature);
|
||||
if ( handler != null && handler.shouldBeProcessed(doc) ) {
|
||||
String filename = handler.getDestinationFilename(doc);
|
||||
DocWorkUnit unit = new DocWorkUnit(doc.name(),
|
||||
GATKDocWorkUnit unit = new GATKDocWorkUnit(doc.name(),
|
||||
filename, feature.groupName(),
|
||||
feature, handler, doc, clazz,
|
||||
buildTimestamp, absoluteVersion);
|
||||
|
|
@ -133,7 +102,7 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void processDocs(RootDoc rootDoc, PrintStream ignore) {
|
||||
protected void processDocs(RootDoc rootDoc) {
|
||||
// setup the global access to the root
|
||||
this.rootDoc = rootDoc;
|
||||
super.loadData(rootDoc, false);
|
||||
|
|
@ -152,12 +121,12 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
// Specify how templates will see the data-model. This is an advanced topic...
|
||||
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
|
||||
Set<DocWorkUnit> myWorkUnits = workUnits();
|
||||
for ( DocWorkUnit workUnit : myWorkUnits ) {
|
||||
Set<GATKDocWorkUnit> myWorkUnits = workUnits();
|
||||
for ( GATKDocWorkUnit workUnit : myWorkUnits ) {
|
||||
processDocWorkUnit(cfg, workUnit, myWorkUnits);
|
||||
}
|
||||
|
||||
processIndex(cfg, new ArrayList<DocWorkUnit>(myWorkUnits));
|
||||
processIndex(cfg, new ArrayList<GATKDocWorkUnit>(myWorkUnits));
|
||||
} catch ( FileNotFoundException e ) {
|
||||
throw new RuntimeException(e);
|
||||
} catch ( IOException e ) {
|
||||
|
|
@ -214,7 +183,7 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
return rootDoc.classNamed(clazz.getName());
|
||||
}
|
||||
|
||||
private void processIndex(Configuration cfg, List<DocWorkUnit> indexData) throws IOException {
|
||||
private void processIndex(Configuration cfg, List<GATKDocWorkUnit> indexData) throws IOException {
|
||||
/* Get or create a template */
|
||||
Template temp = cfg.getTemplate("generic.index.template.html");
|
||||
|
||||
|
|
@ -228,7 +197,7 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> groupIndexData(List<DocWorkUnit> indexData) {
|
||||
private Map<String, Object> groupIndexData(List<GATKDocWorkUnit> indexData) {
|
||||
//
|
||||
// root -> data -> { summary -> y, filename -> z }, etc
|
||||
// -> groups -> group1, group2, etc.
|
||||
|
|
@ -238,7 +207,7 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
|
||||
Set<DocumentedGATKFeature> docFeatures = new HashSet<DocumentedGATKFeature>();
|
||||
List<Map<String, String>> data = new ArrayList<Map<String, String>>();
|
||||
for ( DocWorkUnit workUnit : indexData ) {
|
||||
for ( GATKDocWorkUnit workUnit : indexData ) {
|
||||
data.add(workUnit.toMap());
|
||||
docFeatures.add(workUnit.annotation);
|
||||
}
|
||||
|
|
@ -263,14 +232,14 @@ public class GATKDoclet extends ResourceBundleExtractorDoclet {
|
|||
return root;
|
||||
}
|
||||
|
||||
public final static DocWorkUnit findWorkUnitForClass(Class c, Set<DocWorkUnit> all) {
|
||||
for ( final DocWorkUnit unit : all )
|
||||
public final static GATKDocWorkUnit findWorkUnitForClass(Class c, Set<GATKDocWorkUnit> all) {
|
||||
for ( final GATKDocWorkUnit unit : all )
|
||||
if ( unit.clazz.equals(c) )
|
||||
return unit;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processDocWorkUnit(Configuration cfg, DocWorkUnit unit, Set<DocWorkUnit> all)
|
||||
private void processDocWorkUnit(Configuration cfg, GATKDocWorkUnit unit, Set<GATKDocWorkUnit> all)
|
||||
throws IOException {
|
||||
System.out.printf("Processing documentation for class %s%n", unit.classDoc);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import com.sun.javadoc.Tag;
|
|||
import org.broadinstitute.sting.commandline.*;
|
||||
import org.broadinstitute.sting.gatk.CommandLineGATK;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
import org.broadinstitute.sting.utils.classloader.JVMUtils;
|
||||
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||
|
||||
import java.io.*;
|
||||
|
|
@ -43,9 +42,9 @@ import java.util.*;
|
|||
*
|
||||
*/
|
||||
public class GenericDocumentationHandler extends DocumentedGATKFeatureHandler {
|
||||
GATKDoclet.DocWorkUnit toProcess;
|
||||
GATKDocWorkUnit toProcess;
|
||||
ClassDoc classdoc;
|
||||
Set<GATKDoclet.DocWorkUnit> all;
|
||||
Set<GATKDocWorkUnit> all;
|
||||
RootDoc rootDoc;
|
||||
|
||||
@Override
|
||||
|
|
@ -66,7 +65,7 @@ public class GenericDocumentationHandler extends DocumentedGATKFeatureHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void processOne(RootDoc rootDoc, GATKDoclet.DocWorkUnit toProcessArg, Set<GATKDoclet.DocWorkUnit> allArg) {
|
||||
public void processOne(RootDoc rootDoc, GATKDocWorkUnit toProcessArg, Set<GATKDocWorkUnit> allArg) {
|
||||
this.rootDoc = rootDoc;
|
||||
this.toProcess = toProcessArg;
|
||||
this.all = allArg;
|
||||
|
|
@ -132,7 +131,7 @@ public class GenericDocumentationHandler extends DocumentedGATKFeatureHandler {
|
|||
|
||||
// add in all of the explicitly related items
|
||||
for ( final Class extraDocClass : toProcess.annotation.extraDocs() ) {
|
||||
final GATKDoclet.DocWorkUnit otherUnit = GATKDoclet.findWorkUnitForClass(extraDocClass, all);
|
||||
final GATKDocWorkUnit otherUnit = GATKDoclet.findWorkUnitForClass(extraDocClass, all);
|
||||
if ( otherUnit == null )
|
||||
throw new ReviewedStingException("Requested extraDocs for class without any documentation: " + extraDocClass);
|
||||
extraDocsData.add(
|
||||
|
|
@ -143,7 +142,7 @@ public class GenericDocumentationHandler extends DocumentedGATKFeatureHandler {
|
|||
}
|
||||
|
||||
List<Map<String, Object>> hierarchyDocs = new ArrayList<Map<String, Object>>();
|
||||
for (final GATKDoclet.DocWorkUnit other : all ) {
|
||||
for (final GATKDocWorkUnit other : all ) {
|
||||
final String relation = classRelationship(toProcess.clazz, other.clazz);
|
||||
if ( relation != null )
|
||||
hierarchyDocs.add(
|
||||
|
|
|
|||
Loading…
Reference in New Issue