Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
PROC-960: NOBUG style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygoodwin committed Jul 18, 2023
1 parent f35cd31 commit 9c443f0
Show file tree
Hide file tree
Showing 393 changed files with 17,650 additions and 13,468 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import java.io.PrintWriter;

/**
* Executes the LocalProctorBuilder
* destdir - The output directory to write the matrix json file.
* If set to '-', output is written to STDOUT
* destfile - The name of the generated test-matrix JSON file.
* srcdir - The source directory containing the test-definitions directory
* ${srcdir}/test-definitions
* author - Optional author string to be used for the test-matrix audit.author
* version - Optional version to be used for the test-matrix audit.version
* Executes the LocalProctorBuilder destdir - The output directory to write the matrix json file. If
* set to '-', output is written to STDOUT destfile - The name of the generated test-matrix JSON
* file. srcdir - The source directory containing the test-definitions directory
* ${srcdir}/test-definitions author - Optional author string to be used for the test-matrix
* audit.author version - Optional version to be used for the test-matrix audit.version
*
* @author parker
*/
public class LocalProctorBuilderTask extends Task {
Expand Down Expand Up @@ -78,18 +76,18 @@ public void execute() throws BuildException {
throw new BuildException("destdir is required");
}
new LocalProctorBuilder(
new File(srcdir),
"-".equals(destdir) ?
new PrintWriter(System.out) :
new FileWriter(new File(destdir, destfile)),
author,
version).execute();
new File(srcdir),
"-".equals(destdir)
? new PrintWriter(System.out)
: new FileWriter(new File(destdir, destfile)),
author,
version)
.execute();
} catch (final Exception e) {
if (e instanceof BuildException) {
throw (BuildException) e;
}
throw new BuildException("Failed to create test matrix: " + e.getMessage(), e);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,38 @@
public abstract class TestGroupsGeneratorTask extends Task {
protected static final Logger LOGGER = LogManager.getLogger(TestGroupsGeneratorTask.class);

/**
* A period of sleep to display warning messages to users
*/
/** A period of sleep to display warning messages to users */
private static final int SLEEP_TIME_FOR_WARNING = 3;

/**
* URL to the page for the dynamic filters migration
*/
private static final String DYNAMIC_FILTERS_MIGRATION_URL = "https://github.com/indeedeng/proctor/issues/47";
/** URL to the page for the dynamic filters migration */
private static final String DYNAMIC_FILTERS_MIGRATION_URL =
"https://github.com/indeedeng/proctor/issues/47";

/**
* Paths to input specification files separated by ","
* It allows two types of inputs
* Paths to input specification files separated by "," It allows two types of inputs
*
* 1. A single path to json file that is not named
* providedcontext.json or dynamicfilters.json
* The json file holds all tests specifications (total specification).
* <p>1. A single path to json file that is not named providedcontext.json or
* dynamicfilters.json The json file holds all tests specifications (total specification).
*
* 2. All other cases. one or more paths to json file
* or directory including json files, separated by comma.
* each json file is a single test specification
* or providedcontext.json or dynamicfilters.json.
* <p>2. All other cases. one or more paths to json file or directory including json files,
* separated by comma. each json file is a single test specification or providedcontext.json or
* dynamicfilters.json.
*
* FIXME: current implementation is not strictly following this at this moment.
* Current limitations are
* * single path to "providedcontext.json" is handled as Type 1.
* * single path to "dynamicfilters.json" is handled as Type 1.
* * multiple paths to json files is handled as Type 1 and fails to parse.
* <p>FIXME: current implementation is not strictly following this at this moment. Current
* limitations are * single path to "providedcontext.json" is handled as Type 1. * single path
* to "dynamicfilters.json" is handled as Type 1. * multiple paths to json files is handled as
* Type 1 and fails to parse.
*/
protected String input;
/**
* Target base directory to generate files
*/
/** Target base directory to generate files */
protected String target;
/**
* Package of generated source files
*/
/** Package of generated source files */
protected String packageName;
/**
* Name of generated group class
*/
/** Name of generated group class */
protected String groupsClass;
/**
* Paths to generate a total specification json file.
* This is ignored when `input` specifies total specification json file.
* Paths to generate a total specification json file. This is ignored when `input` specifies
* total specification json file.
*/
protected String specificationOutput;

Expand Down Expand Up @@ -113,10 +100,11 @@ public void setSpecificationOutput(final String specificationOutput) {
}

/**
* Generates total specifications from any partial specifications found
* Output generate total specification to `specificationOutput`
* Generates total specifications from any partial specifications found Output generate total
* specification to `specificationOutput`
*/
protected ProctorSpecification mergePartialSpecifications(final List<File> files) throws CodeGenException {
protected ProctorSpecification mergePartialSpecifications(final List<File> files)
throws CodeGenException {
if (files == null || files.size() == 0) {
throw new CodeGenException("No specifications file input");
}
Expand All @@ -125,22 +113,22 @@ protected ProctorSpecification mergePartialSpecifications(final List<File> files
}

// make directory if it doesn't exist
new File(specificationOutput.substring(0, specificationOutput.lastIndexOf(File.separator))).mkdirs();
new File(specificationOutput.substring(0, specificationOutput.lastIndexOf(File.separator)))
.mkdirs();
final File specificationOutputFile = new File(specificationOutput);
return TestGroupsGenerator.makeTotalSpecification(
files,
specificationOutputFile.getParent(),
specificationOutputFile.getName()
);
files, specificationOutputFile.getParent(), specificationOutputFile.getName());
}

@Override
public void execute() throws BuildException {
if (input == null) {
throw new BuildException("Undefined input files for code generation from specification");
throw new BuildException(
"Undefined input files for code generation from specification");
}
if (target == null) {
throw new BuildException("Undefined target directory for code generation from specification");
throw new BuildException(
"Undefined target directory for code generation from specification");
}

final String[] inputs = input.split(",");
Expand Down Expand Up @@ -173,7 +161,12 @@ public void execute() throws BuildException {
try {
specification = mergePartialSpecifications(files);
} catch (final CodeGenException e) {
throw new BuildException("Unable to generate total specification for inputs " + Arrays.asList(inputs) + " : " + e.getMessage(), e);
throw new BuildException(
"Unable to generate total specification for inputs "
+ Arrays.asList(inputs)
+ " : "
+ e.getMessage(),
e);
}
}

Expand All @@ -187,26 +180,25 @@ public void execute() throws BuildException {
}
}

/**
* Validate input specification and log messages
*/
/** Validate input specification and log messages */
private void validateSpecification(final ProctorSpecification specification) {
final boolean hasDuplicatedFilters = specification.getDynamicFilters()
.asCollection()
.stream()
.anyMatch(filter -> filter.getClass().isAnnotationPresent(Deprecated.class));
final boolean hasDuplicatedFilters =
specification.getDynamicFilters().asCollection().stream()
.anyMatch(
filter -> filter.getClass().isAnnotationPresent(Deprecated.class));

if (hasDuplicatedFilters) {
log(String.join("\n",
"=================================================================================",
"Warning: Proctor detected this application is using deprecated dynamic filters.",
"Please migrate to meta tags based filters.",
"See " + DYNAMIC_FILTERS_MIGRATION_URL + " for details.",
"",
"Sleeping " + SLEEP_TIME_FOR_WARNING + " seconds",
"================================================================================="
), LogLevel.WARN.getLevel()
);
log(
String.join(
"\n",
"=================================================================================",
"Warning: Proctor detected this application is using deprecated dynamic filters.",
"Please migrate to meta tags based filters.",
"See " + DYNAMIC_FILTERS_MIGRATION_URL + " for details.",
"",
"Sleeping " + SLEEP_TIME_FOR_WARNING + " seconds",
"================================================================================="),
LogLevel.WARN.getLevel());
}
}

Expand All @@ -215,5 +207,6 @@ private void validateSpecification(final ProctorSpecification specification) {
*
* @param specification a input specification for source code generation
*/
protected abstract void generateSourceFiles(final ProctorSpecification specification) throws CodeGenException;
protected abstract void generateSourceFiles(final ProctorSpecification specification)
throws CodeGenException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ public void setContextClass(final String contextClass) {
}

@Override
protected void generateSourceFiles(final ProctorSpecification specification) throws CodeGenException {
protected void generateSourceFiles(final ProctorSpecification specification)
throws CodeGenException {
gen.generate(
specification,
target,
packageName,
groupsClass,
groupsManagerClass,
contextClass
);
specification, target, packageName, groupsClass, groupsManagerClass, contextClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* @author andrewk
*/
public class TestGroupsJavascriptGeneratorTask extends TestGroupsGeneratorTask {
private static final Logger LOGGER = LogManager.getLogger(TestGroupsJavascriptGeneratorTask.class);
private static final Logger LOGGER =
LogManager.getLogger(TestGroupsJavascriptGeneratorTask.class);
private final TestGroupsJavascriptGenerator gen = new TestGroupsJavascriptGenerator();

private boolean useClosure;
Expand All @@ -26,13 +27,8 @@ public void setUseClosure(final boolean useClosure) {
}

@Override
protected void generateSourceFiles(final ProctorSpecification specification) throws CodeGenException {
gen.generate(
specification,
target,
packageName,
groupsClass,
useClosure
);
protected void generateSourceFiles(final ProctorSpecification specification)
throws CodeGenException {
gen.generate(specification, target, packageName, groupsClass, useClosure);
}
}
Loading

0 comments on commit 9c443f0

Please sign in to comment.