Skip to content

Commit

Permalink
TEZ-4387: reformat code before touching it
Browse files Browse the repository at this point in the history
  • Loading branch information
LA-Toth committed Feb 28, 2022
1 parent 5241f58 commit dab5d77
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

package org.apache.tez.tools.javadoc.doclet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.sun.javadoc.*;
import com.sun.javadoc.AnnotationDesc.ElementValuePair;
import com.sun.tools.doclets.standard.Standard;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
Expand All @@ -32,202 +31,194 @@
import org.apache.tez.tools.javadoc.util.HtmlWriter;
import org.apache.tez.tools.javadoc.util.XmlWriter;

import com.sun.javadoc.AnnotationDesc;
import com.sun.javadoc.AnnotationDesc.ElementValuePair;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.DocErrorReporter;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.LanguageVersion;
import com.sun.javadoc.RootDoc;
import com.sun.tools.doclets.standard.Standard;
import java.io.IOException;
import java.util.Map;

public class ConfigStandardDoclet {

private static final String DEBUG_SWITCH = "-debug";
private static boolean debugMode = false;
private static final String DEBUG_SWITCH = "-debug";
private static boolean debugMode = false;

public static LanguageVersion languageVersion() {
return LanguageVersion.JAVA_1_5;
}

private static void logMessage(String message) {
if (!debugMode) {
return;
}
System.out.println(message);
}

public static boolean start(RootDoc root) {
//look for debug flag
for (String[] opts : root.options()) {
for (String opt : opts) {
if (opt.equals(DEBUG_SWITCH)) {
debugMode = true;
}
}
public static LanguageVersion languageVersion() {
return LanguageVersion.JAVA_1_5;
}

logMessage("Running doclet " + ConfigStandardDoclet.class.getSimpleName());
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; ++i) {
processDoc(classes[i]);
private static void logMessage(String message) {
if (!debugMode) {
return;
}
System.out.println(message);
}

return true;
}

private static void processDoc(ClassDoc doc) {
logMessage("Parsing : " + doc);
if (!doc.isClass()) {
logMessage("Ignoring non-class: " + doc);
return;
}
public static boolean start(RootDoc root) {
//look for debug flag
for (String[] opts : root.options()) {
for (String opt : opts) {
if (opt.equals(DEBUG_SWITCH)) {
debugMode = true;
}
}
}

AnnotationDesc[] annotations = doc.annotations();
boolean isConfigClass = false;
String templateName = null;
for (AnnotationDesc annotation : annotations) {
logMessage("Checking annotation: " + annotation.annotationType());
if (annotation.annotationType().qualifiedTypeName().equals(
ConfigurationClass.class.getName())) {
isConfigClass = true;
for (ElementValuePair element : annotation.elementValues()) {
if (element.element().name().equals("templateFileName")) {
templateName = stripQuotes(element.value().toString());
}
logMessage("Running doclet " + ConfigStandardDoclet.class.getSimpleName());
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; ++i) {
processDoc(classes[i]);
}
break;
}
}

if (!isConfigClass) {
logMessage("Ignoring non-config class: " + doc);
return;
return true;
}

logMessage("Processing config class: " + doc);
Config config = new Config(doc.name(), templateName);
Map<String, ConfigProperty> configProperties = config.configProperties;

FieldDoc[] fields = doc.fields();
for (FieldDoc field : fields) {
if (field.isPrivate()) {
logMessage("Skipping private field: " + field);
continue;
}
if (!field.isStatic()) {
logMessage("Skipping non-static field: " + field);
continue;
}

if (field.name().endsWith("_PREFIX")) {
logMessage("Skipping non-config prefix constant field: " + field);
continue;
}
if (field.name().equals("TEZ_SITE_XML")) {
logMessage("Skipping constant field: " + field);
continue;
}

if (field.name().endsWith("_DEFAULT")) {

String name = field.name().substring(0,
field.name().lastIndexOf("_DEFAULT"));
if (!configProperties.containsKey(name)) {
configProperties.put(name, new ConfigProperty());
private static void processDoc(ClassDoc doc) {
logMessage("Parsing : " + doc);
if (!doc.isClass()) {
logMessage("Ignoring non-class: " + doc);
return;
}
ConfigProperty configProperty = configProperties.get(name);
if (field.constantValue() == null) {
logMessage("Got null constant value"
+ ", name=" + name
+ ", field=" + field.name()
+ ", val=" + field.constantValueExpression());
configProperty.defaultValue = field.constantValueExpression();
} else {
configProperty.defaultValue = field.constantValue().toString();

AnnotationDesc[] annotations = doc.annotations();
boolean isConfigClass = false;
String templateName = null;
for (AnnotationDesc annotation : annotations) {
logMessage("Checking annotation: " + annotation.annotationType());
if (annotation.annotationType().qualifiedTypeName().equals(
ConfigurationClass.class.getName())) {
isConfigClass = true;
for (ElementValuePair element : annotation.elementValues()) {
if (element.element().name().equals("templateFileName")) {
templateName = stripQuotes(element.value().toString());
}
}
break;
}
}
configProperty.inferredType = field.type().simpleTypeName();

if (name.equals("TEZ_AM_STAGING_DIR") && configProperty.defaultValue != null) {
String defaultValue = configProperty.defaultValue;
defaultValue = defaultValue.replace(System.getProperty("user.name"), "${user.name}");
configProperty.defaultValue = defaultValue;
if (!isConfigClass) {
logMessage("Ignoring non-config class: " + doc);
return;
}

continue;
}
logMessage("Processing config class: " + doc);
Config config = new Config(doc.name(), templateName);
Map<String, ConfigProperty> configProperties = config.configProperties;

String name = field.name();
if (!configProperties.containsKey(name)) {
configProperties.put(name, new ConfigProperty());
}
ConfigProperty configProperty = configProperties.get(name);
configProperty.propertyName = field.constantValue().toString();
FieldDoc[] fields = doc.fields();
for (FieldDoc field : fields) {
if (field.isPrivate()) {
logMessage("Skipping private field: " + field);
continue;
}
if (!field.isStatic()) {
logMessage("Skipping non-static field: " + field);
continue;
}

AnnotationDesc[] annotationDescs = field.annotations();
if (field.name().endsWith("_PREFIX")) {
logMessage("Skipping non-config prefix constant field: " + field);
continue;
}
if (field.name().equals("TEZ_SITE_XML")) {
logMessage("Skipping constant field: " + field);
continue;
}

for (AnnotationDesc annotationDesc : annotationDescs) {
if (field.name().endsWith("_DEFAULT")) {

String name = field.name().substring(0,
field.name().lastIndexOf("_DEFAULT"));
if (!configProperties.containsKey(name)) {
configProperties.put(name, new ConfigProperty());
}
ConfigProperty configProperty = configProperties.get(name);
if (field.constantValue() == null) {
logMessage("Got null constant value"
+ ", name=" + name
+ ", field=" + field.name()
+ ", val=" + field.constantValueExpression());
configProperty.defaultValue = field.constantValueExpression();
} else {
configProperty.defaultValue = field.constantValue().toString();
}
configProperty.inferredType = field.type().simpleTypeName();

if (name.equals("TEZ_AM_STAGING_DIR") && configProperty.defaultValue != null) {
String defaultValue = configProperty.defaultValue;
defaultValue = defaultValue.replace(System.getProperty("user.name"), "${user.name}");
configProperty.defaultValue = defaultValue;
}

continue;
}

if (annotationDesc.annotationType().qualifiedTypeName().equals(
Private.class.getCanonicalName())) {
configProperty.isPrivate = true;
}
if (annotationDesc.annotationType().qualifiedTypeName().equals(
Unstable.class.getCanonicalName())) {
configProperty.isUnstable = true;
}
if (annotationDesc.annotationType().qualifiedTypeName().equals(
Evolving.class.getCanonicalName())) {
configProperty.isEvolving = true;
}
if (annotationDesc.annotationType().qualifiedTypeName().equals(
ConfigurationProperty.class.getCanonicalName())) {
configProperty.isValidConfigProp = true;

boolean foundType = false;
for (ElementValuePair element : annotationDesc.elementValues()) {
if (element.element().name().equals("type")) {
configProperty.type = stripQuotes(element.value().toString());
foundType = true;
} else {
logMessage("Unhandled annotation property: " + element.element().name());
String name = field.name();
if (!configProperties.containsKey(name)) {
configProperties.put(name, new ConfigProperty());
}
ConfigProperty configProperty = configProperties.get(name);
configProperty.propertyName = field.constantValue().toString();

AnnotationDesc[] annotationDescs = field.annotations();

for (AnnotationDesc annotationDesc : annotationDescs) {

if (annotationDesc.annotationType().qualifiedTypeName().equals(
Private.class.getCanonicalName())) {
configProperty.isPrivate = true;
}
if (annotationDesc.annotationType().qualifiedTypeName().equals(
Unstable.class.getCanonicalName())) {
configProperty.isUnstable = true;
}
if (annotationDesc.annotationType().qualifiedTypeName().equals(
Evolving.class.getCanonicalName())) {
configProperty.isEvolving = true;
}
if (annotationDesc.annotationType().qualifiedTypeName().equals(
ConfigurationProperty.class.getCanonicalName())) {
configProperty.isValidConfigProp = true;

boolean foundType = false;
for (ElementValuePair element : annotationDesc.elementValues()) {
if (element.element().name().equals("type")) {
configProperty.type = stripQuotes(element.value().toString());
foundType = true;
} else {
logMessage("Unhandled annotation property: " + element.element().name());
}
}
}
}
}

configProperty.description = field.commentText();
}
}

configProperty.description = field.commentText();
HtmlWriter writer = new HtmlWriter();
try {
writer.write(config);
} catch (IOException e) {
throw new RuntimeException(e);
}

XmlWriter xmlWriter = new XmlWriter();
try {
xmlWriter.write(config);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

HtmlWriter writer = new HtmlWriter();
try {
writer.write(config);
} catch (IOException e) {
throw new RuntimeException(e);
private static String stripQuotes(String s) {
if (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') {
return s.substring(1, s.length() - 1);
}
return s;
}

XmlWriter xmlWriter = new XmlWriter();
try {
xmlWriter.write(config);
} catch (IOException e) {
throw new RuntimeException(e);
public static int optionLength(String option) {
return Standard.optionLength(option);
}

}

private static String stripQuotes(String s) {
if (s.charAt(0) == '"' && s.charAt(s.length()-1) == '"') {
return s.substring(1, s.length()-1);
public static boolean validOptions(String options[][], DocErrorReporter reporter) {
return true;
}
return s;
}

public static int optionLength(String option) {
return Standard.optionLength(option);
}

public static boolean validOptions(String options[][], DocErrorReporter reporter) {
return true;
}
}
Loading

0 comments on commit dab5d77

Please sign in to comment.