Skip to content

Commit

Permalink
simplified debug.report
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 13, 2021
1 parent 813a026 commit 6e80321
Show file tree
Hide file tree
Showing 29 changed files with 44 additions and 133 deletions.
Expand Up @@ -61,6 +61,11 @@ public interface DenizenImplementation {
*/
void debugReport(Debuggable caller, String name, String message);

/**
* Output a command information report.
*/
void debugReport(Debuggable caller, String name, Object... values);

/**
* Output an 'Okay!' message.
*/
Expand Down
Expand Up @@ -78,8 +78,7 @@ public void addCustomTabCompletions(String arg, Consumer<String> addOne) {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("object")
&& arg.limitToOnlyPrefix("object")) {
if (!scriptEntry.hasObject("object")) {
if (arg.object instanceof ListTag) {
scriptEntry.addObject("object", arg.object);
}
Expand Down Expand Up @@ -192,9 +191,7 @@ public void execute(ScriptEntry scriptEntry) {
ListTag objects = scriptEntry.getObjectTag("object");
MapTag mechanismMap = scriptEntry.getObjectTag("mechanism_map");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
objects.debug()
+ (mechanismMap == null ? mechanism.debug() + (value == null ? "" : value.debug()) : mechanismMap.debug()));
Debug.report(scriptEntry, getName(), objects, value, mechanism, mechanismMap);
}
ListTag result = new ListTag();
for (ObjectTag object : objects.objectForms) {
Expand Down
Expand Up @@ -80,7 +80,7 @@ public void execute(ScriptEntry scriptEntry) {
ListTag events = scriptEntry.getObjectTag("events");
ListTag context = scriptEntry.getObjectTag("context");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), events.debug() + context.debug());
Debug.report(scriptEntry, getName(), events, context);
}
if (context.size() % 2 == 1) { // Size is uneven!
context.add("null");
Expand Down
Expand Up @@ -197,9 +197,7 @@ public void execute(ScriptEntry scriptEntry) {
TimeTag expiration = scriptEntry.getObjectTag("expiration");
DataAction flagAction = (DataAction) scriptEntry.getObject("flag_action");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), targets.debug()
+ (expiration == null ? "" : expiration.debug())
+ flagAction.debug());
Debug.report(scriptEntry, getName(), targets, expiration, flagAction.debug());
}
((FlagActionProvider) flagAction.provider).expiration = expiration;
for (ObjectTag object : targets.objectForms) {
Expand Down
Expand Up @@ -172,12 +172,7 @@ public void execute(final ScriptEntry scriptEntry) {
final ElementTag sqlID = scriptEntry.getElement("sqlid");
final ElementTag query = scriptEntry.getElement("query");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), sqlID.debug()
+ action.debug()
+ (server != null ? server.debug() : "")
+ (username != null ? username.debug() : "")
+ (password != null ? ArgumentHelper.debugObj("password", "NotLogged") : "")
+ (query != null ? query.debug() : ""));
Debug.report(scriptEntry, getName(), sqlID, action, server, username, (password != null ? ArgumentHelper.debugObj("password", "NotLogged") : null), query);
}
if (!action.asString().equalsIgnoreCase("connect") &&
(!action.asString().equalsIgnoreCase("query") || !scriptEntry.shouldWaitFor())) {
Expand Down
Expand Up @@ -164,13 +164,7 @@ public void execute(final ScriptEntry scriptEntry) {
final ElementTag saveFile = scriptEntry.getElement("savefile");
final ElementTag hideFailure = scriptEntry.getElement("hide_failure");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), url.debug()
+ (data != null ? data.debug() : "")
+ (method != null ? method.debug() : "")
+ (timeout != null ? timeout.debug() : "")
+ (saveFile != null ? saveFile.debug() : "")
+ (hideFailure != null ? hideFailure.debug() : "")
+ (headers != null ? headers.debug() : ""));
Debug.report(scriptEntry, getName(), url, data, method, timeout, saveFile, hideFailure, headers);
}
Thread thr = new Thread(() -> webGet(scriptEntry, data, method, url, timeout, headers, saveFile, hideFailure));
thr.start();
Expand Down
Expand Up @@ -85,7 +85,7 @@ public void execute(final ScriptEntry scriptEntry) {
ElementTag destination = scriptEntry.getElement("destination");
ElementTag overwrite = scriptEntry.getElement("overwrite");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), origin.debug() + destination.debug() + overwrite.debug());
Debug.report(scriptEntry, getName(), origin, destination, overwrite);
}
if (!DenizenCore.getImplementation().allowFileCopy()) {
Debug.echoError(scriptEntry.getResidingQueue(), "File copy disabled by server administrator.");
Expand Down
Expand Up @@ -78,7 +78,6 @@ public enum Type {SEVERE, INFO, WARNING, FINE, FINER, FINEST, NONE, CLEAR}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("type")
&& arg.matchesPrefix("type")
Expand All @@ -96,15 +95,12 @@ else if (!scriptEntry.hasObject("message")) {
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("message")) {
throw new InvalidArgumentsException("Must specify a message.");
}

if (!scriptEntry.hasObject("file")) {
throw new InvalidArgumentsException("Must specify a file.");
}

if (!scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", new ElementTag("INFO"));
}
Expand All @@ -119,27 +115,18 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag message = scriptEntry.getElement("message");
ElementTag fileName = scriptEntry.getElement("file");
ElementTag typeElement = scriptEntry.getElement("type");

if (scriptEntry.dbCallShouldDebug()) {

Debug.report(scriptEntry, getName(),
message.debug() + fileName.debug() + typeElement.debug());

Debug.report(scriptEntry, getName(), message, fileName, typeElement);
}

Type type = Type.valueOf(typeElement.asString().toUpperCase());

String directory = URLDecoder.decode(System.getProperty("user.dir"));
File file = new File(directory, fileName.asString());

file.getParentFile().mkdirs();
if (!DenizenCore.getImplementation().canWriteToFile(file)) {
Debug.echoError(scriptEntry.getResidingQueue(), "Cannot log into that file!");
return;
}

String output = message.asString();

file.getParentFile().mkdirs();
if (type == Type.NONE) {
try {
Expand Down Expand Up @@ -167,34 +154,26 @@ else if (type == Type.CLEAR) {
}
return;
}

DebugLog log = new DebugLog("Denizen-ScriptLog-" + fileName, file.getAbsolutePath());

switch (type) {
case SEVERE:
log.severe(output);
break;

case INFO:
log.info(output);
break;

case WARNING:
log.warning(output);
break;

case FINE:
log.fine(output);
break;

case FINER:
log.finer(output);
break;

case FINEST:
log.finest(output);
}

log.close();
}
}
Expand Up @@ -315,16 +315,8 @@ public void execute(final ScriptEntry scriptEntry) {
ElementTag toId = scriptEntry.getElement("to_id");
YamlConfiguration yamlConfiguration;
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
idElement.debug()
+ actionElement.debug()
+ (filename != null ? filename.debug() : "")
+ (yaml_action != null ? ArgumentHelper.debugObj("yaml_action", yaml_action.name()) : "")
+ (key != null ? key.debug() : "")
+ (value != null ? value.debug() : "")
+ (split != null ? split.debug() : "")
+ (rawText != null ? rawText.debug() : "")
+ (toId != null ? toId.debug() : ""));
Debug.report(scriptEntry, getName(), idElement, actionElement, filename, key, value, split, rawText, toId,
(yaml_action != null ? ArgumentHelper.debugObj("yaml_action", yaml_action.name()) : null));
}
// Do action
Action action = Action.valueOf(actionElement.asString().toUpperCase());
Expand Down
Expand Up @@ -127,7 +127,7 @@ else if (cmdName.equals("case")) {
}
ElementTag choice = scriptEntry.getElement("choice");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), choice.debug());
Debug.report(scriptEntry, getName(), choice);
}
String choice_low = CoreUtilities.toLowerCase(choice.asString());
Integer resultIndex = lookupTable.get(choice_low);
Expand Down
Expand Up @@ -2,13 +2,13 @@

import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.core.QueueTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.data.ActionableDataProvider;
import com.denizenscript.denizencore.utilities.data.DataAction;
import com.denizenscript.denizencore.utilities.data.DataActionHelper;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
Expand Down Expand Up @@ -126,11 +126,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag remove = scriptEntry.getElement("remove");
DataAction action = (DataAction) scriptEntry.getObject("action");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("queue", scriptEntry.getResidingQueue().id)
+ (definition == null ? "" : definition.debug())
+ (value == null ? "" : value.debug())
+ (action == null ? "" : action.debug())
+ (remove != null ? remove.debug() : ""));
Debug.report(scriptEntry, getName(), new QueueTag(scriptEntry.getResidingQueue()), definition, value, action == null ? null : action.debug(), remove);
}
if (action != null) {
action.execute(scriptEntry.getContext());
Expand Down
Expand Up @@ -2,9 +2,9 @@

import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.objects.core.QueueTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -86,9 +86,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag definition = scriptEntry.getElement("definition");
MapTag value = scriptEntry.getObjectTag("map");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("queue", scriptEntry.getResidingQueue().id)
+ definition.debug()
+ value.debug());
Debug.report(scriptEntry, getName(), new QueueTag(scriptEntry.getResidingQueue()), definition, value);
}
scriptEntry.getResidingQueue().addDefinition(definition.asString(), value.duplicate());
}
Expand Down
Expand Up @@ -77,7 +77,7 @@ public void execute(ScriptEntry scriptEntry) {
ObjectTag outcomeObj = scriptEntry.getObjectTag("outcome");
ElementTag passively = scriptEntry.getElement("passively");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), outcomeObj.debug() + passively.debug() + new QueueTag(scriptEntry.getResidingQueue()).debug());
Debug.report(scriptEntry, getName(), outcomeObj, passively, new QueueTag(scriptEntry.getResidingQueue()));
}
ScriptQueue queue = scriptEntry.getResidingQueue();
ListTag determines = queue.determinations;
Expand Down
Expand Up @@ -142,7 +142,7 @@ public void execute(ScriptEntry scriptEntry) {
ScriptQueue queue = scriptEntry.getResidingQueue();
if (stop != null && stop.asBoolean()) {
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), stop.debug());
Debug.report(scriptEntry, getName(), stop);
}
boolean hasnext = false;
for (int i = 0; i < queue.getQueueSize(); i++) {
Expand Down Expand Up @@ -172,7 +172,7 @@ public void execute(ScriptEntry scriptEntry) {
}
else if (next != null && next.asBoolean()) {
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), next.debug());
Debug.report(scriptEntry, getName(), next);
}
boolean hasnext = false;
for (int i = 0; i < queue.getQueueSize(); i++) {
Expand Down Expand Up @@ -236,7 +236,7 @@ else if (callback != null && callback.asBoolean()) {
}
else {
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (list == null ? map.debug() + key_as.debug() : list.debug()) + as_name.debug());
Debug.report(scriptEntry, getName(), map, map == null ? null : key_as, list, as_name);
}
int target = list == null ? map.map.size() : list.size();
if (target <= 0) {
Expand Down
Expand Up @@ -46,36 +46,26 @@ public GotoCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("m_name")) {
scriptEntry.addObject("m_name", arg.asElement());
}

else {
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("m_name")) {
throw new InvalidArgumentsException("Must have a mark name!");
}

}

@Override
public void execute(ScriptEntry scriptEntry) {

ElementTag mName = scriptEntry.getElement("m_name");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), mName.debug());
Debug.report(scriptEntry, getName(), mName);
}

String markName = mName.asString();

// Jump forth
boolean hasmark = false;
for (int i = 0; i < scriptEntry.getResidingQueue().getQueueSize(); i++) {
ScriptEntry entry = scriptEntry.getResidingQueue().getEntry(i);
Expand Down
Expand Up @@ -169,20 +169,16 @@ else if (!has_brace && in_elsecommand) {

@Override
public void execute(ScriptEntry scriptEntry) {

List<String> subcommand = (List<String>) scriptEntry.getObject("subcommand");
List<String> elsecommand = (List<String>) scriptEntry.getObject("elsecommand");
List<String> comparisons = (List<String>) scriptEntry.getObject("comparisons");
List<BracedData> braces = (List<BracedData>) scriptEntry.getObject("braces");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("use_braces", braces != null));
}

if (Debug.verbose) {
Debug.log("comparisons=" + comparisons + ", sc:" + subcommand + ", ec:" + elsecommand);
}

boolean first_set = new ArgComparer().compare(comparisons, scriptEntry);
if (first_set && subcommand != null && subcommand.size() > 0) {
executeCommandList(subcommand, scriptEntry);
Expand Down
Expand Up @@ -106,10 +106,7 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag path = scriptEntry.getElement("path");
ElementTag local = scriptEntry.getElement("local");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), script.debug()
+ (instant != null ? instant.debug() : "")
+ (path != null ? path.debug() : "")
+ (local != null ? local.debug() : ""));
Debug.report(scriptEntry, getName(), script, instant, path, local);
}
List<ScriptEntry> entries;
if (local != null && local.asBoolean()) {
Expand Down
Expand Up @@ -39,31 +39,24 @@ public MarkCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("m_name")) {
scriptEntry.addObject("m_name", arg.asElement());
}

else {
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("m_name")) {
throw new InvalidArgumentsException("Must have a mark name!");
}

}

@Override
public void execute(ScriptEntry scriptEntry) {

ElementTag mName = scriptEntry.getElement("m_name");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), mName.debug());
Debug.report(scriptEntry, getName(), mName);
}
}
}

0 comments on commit 6e80321

Please sign in to comment.