-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a main method for executing log-parser as a commandline tool (#…
…155) * Added unit tests for issue #10 * Finished integration of commandline execution of the log-parser * Included the main tests, and corrected issue with misplaced tests
- Loading branch information
Showing
11 changed files
with
729 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/com/adobe/campaign/tests/logparser/RunLogParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2022 Adobe | ||
* All Rights Reserved. | ||
* | ||
* NOTICE: Adobe permits you to use, modify, and distribute this file in | ||
* accordance with the terms of the Adobe license agreement accompanying | ||
* it. | ||
*/ | ||
package com.adobe.campaign.tests.logparser; | ||
|
||
import com.adobe.campaign.tests.logparser.core.LogData; | ||
import com.adobe.campaign.tests.logparser.core.LogDataFactory; | ||
import com.adobe.campaign.tests.logparser.core.ParseDefinition; | ||
import com.adobe.campaign.tests.logparser.core.ParseDefinitionFactory; | ||
import com.adobe.campaign.tests.logparser.exceptions.StringParseException; | ||
import com.adobe.campaign.tests.logparser.utils.RunArguments; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
public class RunLogParser { | ||
/** | ||
* @param in_args | ||
* @throws Exception | ||
*/ | ||
public static void main(String[] in_args) throws StringParseException { | ||
//Print help if requested | ||
if (Arrays.stream(in_args).anyMatch(arg -> RunArguments.HELP.correspondsTo(arg))) { | ||
RunArguments.printHelp(); | ||
return; | ||
} | ||
|
||
StringBuilder l_mandatories = new StringBuilder(); | ||
//Check if the mandatory values are there | ||
RunArguments.getMandatoryCommands().stream().forEach(mc -> { | ||
if (mc.fetchValue(in_args, null) == null) { | ||
l_mandatories.append("Mandatory argument ").append(mc.buildTag()).append(" is missing").append("\n"); | ||
} | ||
}); | ||
|
||
if (l_mandatories.length() > 0) { | ||
System.err.println(l_mandatories.toString()); | ||
RunArguments.printHelp(); | ||
return; | ||
} | ||
|
||
//Fetch parse definition | ||
ParseDefinition l_parseDefinition = ParseDefinitionFactory.importParseDefinition( | ||
RunArguments.PARSE_DEFINITIONS_FILE.fetchValue(in_args)); | ||
|
||
//Extract the target SDK class | ||
Class l_targetSDKClass; | ||
try { | ||
l_targetSDKClass = Class.forName(RunArguments.TARGET_SDK_CLASS.fetchValue(in_args)); | ||
} catch (ClassNotFoundException e) { | ||
System.err.println("The target SDK class " + RunArguments.TARGET_SDK_CLASS.fetchValue(in_args) | ||
+ " could not be found"); | ||
return; | ||
} | ||
|
||
//Generate Log data | ||
LogData l_logData = LogDataFactory.generateLogData(RunArguments.START_DIR.fetchValue(in_args), | ||
RunArguments.FILTER_LOG_FILES.fetchValue(in_args), l_parseDefinition, | ||
l_targetSDKClass); | ||
|
||
//Generate Report | ||
if (RunArguments.REPORT_FORMAT.fetchValue(in_args).equalsIgnoreCase("CSV")) { | ||
File x = l_logData.exportLogDataToCSV(RunArguments.REPORT_FILENAME.fetchValue(in_args, | ||
l_parseDefinition.fetchEscapedTitle() + "-export.csv")); | ||
} else if (RunArguments.REPORT_FORMAT.fetchValue(in_args).equalsIgnoreCase("HTML")) { | ||
File x = l_logData.exportLogDataToHTML( | ||
RunArguments.REPORT_NAME.fetchValue(in_args, l_parseDefinition.getTitle()), | ||
RunArguments.REPORT_FILENAME.fetchValue(in_args, | ||
l_parseDefinition.fetchEscapedTitle() + "-export")); | ||
} else { | ||
System.err.println("The report format " + RunArguments.REPORT_FORMAT.fetchValue(in_args) | ||
+ " is not supported."); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.