diff --git a/api/src/main/java/com/technophobia/substeps/execution/AbstractExecutionNodeVisitor.java b/api/src/main/java/com/technophobia/substeps/execution/AbstractExecutionNodeVisitor.java index 9858d6c4..e5bdc48a 100644 --- a/api/src/main/java/com/technophobia/substeps/execution/AbstractExecutionNodeVisitor.java +++ b/api/src/main/java/com/technophobia/substeps/execution/AbstractExecutionNodeVisitor.java @@ -34,49 +34,64 @@ * nodes which have tags, if not overridden these nodes will call * visit(NodeWithChildren) or visit(IExecutionNode) depending on type. * + * @param the type of class this visitor returns * @author rbarefield */ public abstract class AbstractExecutionNodeVisitor implements ExecutionNodeVisitor { + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(RootNode rootNode) { - return visit((NodeWithChildren) rootNode); } + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(FeatureNode featureNode) { - return visit((TaggedNode) featureNode); } + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(BasicScenarioNode basicScenarioNode) { - return visit((TaggedNode) basicScenarioNode); } + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(OutlineScenarioNode outlineNode) { - return visit((TaggedNode) outlineNode); } + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(OutlineScenarioRowNode outlineScenarioRowNode) { - return visit((TaggedNode) outlineScenarioRowNode); } + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(SubstepNode substepNode) { - return visit((TaggedNode) substepNode); } + /** + * {@inheritDoc} + */ @Override public RETURN_TYPE visit(StepImplementationNode stepImplementationNode) { - return visit((TaggedNode) stepImplementationNode); } diff --git a/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeResult.java b/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeResult.java index a2d07acd..92f5d54d 100644 --- a/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeResult.java +++ b/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeResult.java @@ -115,7 +115,7 @@ public void setScreenshot(byte[] screenshot) { this.screenshot = screenshot; } - public void setChildFailure(SubstepExecutionFailure substepExecutionFailure) { + public void setChildFailure() { recordComplete(); // this is to prevent a failure from overwriting a parse or setup / tear down failure diff --git a/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeVisitor.java b/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeVisitor.java index d5c7b4ed..33c630fc 100644 --- a/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeVisitor.java +++ b/api/src/main/java/com/technophobia/substeps/execution/ExecutionNodeVisitor.java @@ -20,20 +20,69 @@ import com.technophobia.substeps.execution.node.*; +/** + * Interface of visitor pattern for traversing the tree of ExecutionNodes, extend the AbstractExecutionNodeVisitor + * to then just implement the interesting nodes + * + * @param the type returned by the visitor implementation + */ public interface ExecutionNodeVisitor { + + /** + * Visit the root node + * + * @param rootNode the root node + * @return the return type + */ RETURN_TYPE visit(RootNode rootNode); + /** + * Visit a feature node + * + * @param featureNode the feature node + * @return the return type + */ RETURN_TYPE visit(FeatureNode featureNode); + /** + * Visit a basic scenario node + * + * @param basicScenarioNode the basic scenario node + * @return the return type + */ RETURN_TYPE visit(BasicScenarioNode basicScenarioNode); + /** + * Visit an outline scenario node. + * + * @param outlineNode the outline node + * @return the return type + */ RETURN_TYPE visit(OutlineScenarioNode outlineNode); + /** + * Visit an outline scenario row node + * + * @param outlineScenarioRowNode the outline scenario row node + * @return the return type + */ RETURN_TYPE visit(OutlineScenarioRowNode outlineScenarioRowNode); + /** + * Visit a substep node + * + * @param substepNode the substep node + * @return the return type + */ RETURN_TYPE visit(SubstepNode substepNode); + /** + * Visit a step implementation node + * + * @param stepImplementationNode the step implementation node + * @return the return type + */ RETURN_TYPE visit(StepImplementationNode stepImplementationNode); } diff --git a/api/src/main/java/com/technophobia/substeps/execution/node/RootNode.java b/api/src/main/java/com/technophobia/substeps/execution/node/RootNode.java index db9014f9..ba33f51a 100644 --- a/api/src/main/java/com/technophobia/substeps/execution/node/RootNode.java +++ b/api/src/main/java/com/technophobia/substeps/execution/node/RootNode.java @@ -46,11 +46,6 @@ public RootNode(String featureSetDescription, List features, String this.nonFatalTags = nonFatalTags; } - @Override - public ExecutionNodeResult getResult() { - return super.getResult(); - } - @Override public RETURN_TYPE dispatch(ExecutionNodeVisitor executionNodeVisitor) { diff --git a/api/src/main/java/com/technophobia/substeps/model/Configuration.java b/api/src/main/java/com/technophobia/substeps/model/Configuration.java index a5d77cf2..1afaf0ca 100644 --- a/api/src/main/java/com/technophobia/substeps/model/Configuration.java +++ b/api/src/main/java/com/technophobia/substeps/model/Configuration.java @@ -19,13 +19,9 @@ package com.technophobia.substeps.model; -import com.typesafe.config.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.typesafe.config.Config; import org.substeps.runner.NewSubstepsExecutionConfig; -import java.net.URL; - /** * @author ian */ @@ -41,20 +37,6 @@ public Config getConfig(){ return NewSubstepsExecutionConfig.threadLocalConfig(); } - - /** - * Implementors of substep libraries should call this with default - * properties for their library - * - * @param url to a properties file containing default values - * @param name to name of the properties file that is being added - */ - @Deprecated - public void addDefaultProperties(final URL url, final String name) { - throw new IllegalArgumentException("method no longer supported, rename default substep library properties to reference.conf and they will be loaded by Typesafe config"); - } - - public String getString(final String key) { return getConfig().getString(key); } diff --git a/api/src/main/java/com/technophobia/substeps/model/SubSteps.java b/api/src/main/java/com/technophobia/substeps/model/SubSteps.java index 81a40db4..8f8ecd3e 100644 --- a/api/src/main/java/com/technophobia/substeps/model/SubSteps.java +++ b/api/src/main/java/com/technophobia/substeps/model/SubSteps.java @@ -40,7 +40,7 @@ private SubSteps(){ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) - public static @interface StepImplementations { + public @interface StepImplementations { // no op Class[] requiredInitialisationClasses() default {}; } @@ -51,7 +51,7 @@ private SubSteps(){ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) - public static @interface AdditionalStepImplementations { + public @interface AdditionalStepImplementations { Class[] value(); } @@ -60,13 +60,13 @@ private SubSteps(){ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - public static @interface Step { + public @interface Step { String value(); } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) - public static @interface StepParameter { + public @interface StepParameter { Class> converter(); } } diff --git a/api/src/main/java/com/technophobia/substeps/runner/BuildFailureManager.java b/api/src/main/java/com/technophobia/substeps/runner/BuildFailureManager.java index 9dec3a31..a988ad25 100644 --- a/api/src/main/java/com/technophobia/substeps/runner/BuildFailureManager.java +++ b/api/src/main/java/com/technophobia/substeps/runner/BuildFailureManager.java @@ -65,7 +65,7 @@ public void addExecutionResult(RootNode rootNode) { } - private String getBuildInfoString(final String msg, final List> failures) { + private static String getBuildInfoString(final String msg, final List> failures) { final StringBuilder buf = new StringBuilder(); diff --git a/api/src/main/java/com/technophobia/substeps/runner/ExecutionContext.java b/api/src/main/java/com/technophobia/substeps/runner/ExecutionContext.java index d3bdf235..e1a78912 100644 --- a/api/src/main/java/com/technophobia/substeps/runner/ExecutionContext.java +++ b/api/src/main/java/com/technophobia/substeps/runner/ExecutionContext.java @@ -42,15 +42,14 @@ public final class ExecutionContext { protected ExecutionContext initialValue() { return new ExecutionContext(); } - - ; }; + private Map> scopedData = null; + private ExecutionContext() { scopedData = new EnumMap<>(Scope.class); } - private Map> scopedData = null; public static void put(final Scope scope, final String key, final Object value) { executionContextThreadLocal.get().putInternal(scope, key, value); @@ -65,7 +64,7 @@ private void putInternal(final Scope scope, final String key, final Object value Map map = scopedData.get(scope); if (map == null) { - map = new HashMap(); + map = new HashMap<>(); scopedData.put(scope, map); } map.put(key, value); diff --git a/api/src/main/java/com/technophobia/substeps/runner/SubstepExecutionFailure.java b/api/src/main/java/com/technophobia/substeps/runner/SubstepExecutionFailure.java index 59429f31..105d62c3 100644 --- a/api/src/main/java/com/technophobia/substeps/runner/SubstepExecutionFailure.java +++ b/api/src/main/java/com/technophobia/substeps/runner/SubstepExecutionFailure.java @@ -32,15 +32,6 @@ */ public class SubstepExecutionFailure implements Serializable { - public static final Function GET_NODE_ID = new Function() { - - @Override - public Long apply(final SubstepExecutionFailure failure) { - return failure == null || failure.getExeccutionNode() == null ? null : failure.getExeccutionNode().getId(); - } - - }; - private static final long serialVersionUID = 4981517213059529046L; private IExecutionNode executionNode; @@ -60,30 +51,7 @@ private SubstepExecutionFailure(Throwable cause, IExecutionNode executionNode, b } - - - public static SubstepExecutionFailure criticalFailure(Throwable cause, IExecutionNode node, byte[] screenshotBytes) { - SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, false, screenshotBytes); - - node.getResult().setFailure(sef); - - return sef; - - } - - - public static SubstepExecutionFailure nonCriticalFailure(final Throwable cause, final IExecutionNode node, byte[] screenshotBytes) { - - SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, true, screenshotBytes); - - node.getResult().setFailure(sef); - - return sef; - } - - public SubstepExecutionFailure(final Throwable cause) { - this.throwableInfo = new ThrowableInfo(cause); } @@ -122,6 +90,25 @@ public SubstepExecutionFailure(final Throwable cause, final IExecutionNode node, node.getResult().setResult(result); } + public static SubstepExecutionFailure criticalFailure(Throwable cause, IExecutionNode node, byte[] screenshotBytes) { + SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, false, screenshotBytes); + + node.getResult().setFailure(sef); + + return sef; + + } + + + public static SubstepExecutionFailure nonCriticalFailure(final Throwable cause, final IExecutionNode node, byte[] screenshotBytes) { + + SubstepExecutionFailure sef = new SubstepExecutionFailure(cause, node, false, true, screenshotBytes); + + node.getResult().setFailure(sef); + + return sef; + } + public static void setResult(final Throwable cause, final IExecutionNode node, final ExecutionResult result) { @@ -203,4 +190,13 @@ public void setScreenshot(final byte[] screenshot) { this.screenshot = screenshot; } + public static final Function GET_NODE_ID = new Function() { + + @Override + public Long apply(final SubstepExecutionFailure failure) { + return failure == null || failure.getExeccutionNode() == null ? null : failure.getExeccutionNode().getId(); + } + + }; + } diff --git a/core/src/main/java/com/technophobia/substeps/execution/ImplementationCache.java b/core/src/main/java/com/technophobia/substeps/execution/ImplementationCache.java index 7753855c..860a848f 100644 --- a/core/src/main/java/com/technophobia/substeps/execution/ImplementationCache.java +++ b/core/src/main/java/com/technophobia/substeps/execution/ImplementationCache.java @@ -77,7 +77,7 @@ public void addImplementationClasses(final Class... implementationClasses) { * @throws InstantiationException * @throws InvocationTargetException */ - private Object instantiateClass(final Class clazz) throws IllegalAccessException, InstantiationException, InvocationTargetException { + private static Object instantiateClass(final Class clazz) throws IllegalAccessException, InstantiationException, InvocationTargetException { Class enclosingClass = clazz.getEnclosingClass(); diff --git a/core/src/main/java/com/technophobia/substeps/execution/node/RootNodeExecutionContext.java b/core/src/main/java/com/technophobia/substeps/execution/node/RootNodeExecutionContext.java index 376a2ebd..2c2ea773 100644 --- a/core/src/main/java/com/technophobia/substeps/execution/node/RootNodeExecutionContext.java +++ b/core/src/main/java/com/technophobia/substeps/execution/node/RootNodeExecutionContext.java @@ -86,7 +86,7 @@ public void addFailure(final SubstepExecutionFailure failure) { /** * @param failure */ - private void logFailure(final SubstepExecutionFailure failure) { + private static void logFailure(final SubstepExecutionFailure failure) { final Throwable here = new Throwable(); diff --git a/core/src/main/java/com/technophobia/substeps/model/Arguments.java b/core/src/main/java/com/technophobia/substeps/model/Arguments.java index cc5d8e8e..ade7c342 100644 --- a/core/src/main/java/com/technophobia/substeps/model/Arguments.java +++ b/core/src/main/java/com/technophobia/substeps/model/Arguments.java @@ -81,7 +81,7 @@ public static Object evaluateExpression(String expressionWithDelimiters){ } } - public static String substituteValues(String src) { + public static String substituteValues(String src, Config cfg) { ParameterSubstitution parameterSubstituionConfig = NewSubstepsExecutionConfig.getParameterSubstituionConfig(); @@ -92,8 +92,8 @@ public static String substituteValues(String src) { String normalizedValue = src; - if (Configuration.INSTANCE.getConfig().hasPath(key)){ - String substitute = Configuration.INSTANCE.getString(key); + if (cfg.hasPath(key)){ + String substitute = cfg.getString(key); if (substitute == null){ throw new SubstepsRuntimeException("Failed to resolve property " + src + " to be substituted "); @@ -128,7 +128,7 @@ public static String[] getArgs(final String patternString, final String sourceSt ArrayList argsList = null; - String patternCopy = new String(patternString); + String patternCopy = patternString; if (keywordPrecedence != null && StringUtils.startsWithAny(patternString, keywordPrecedence)) { // for (String s : keywordPrecedence) { @@ -150,7 +150,7 @@ public static String[] getArgs(final String patternString, final String sourceSt if (matcher.find()) { for (int i = 1; i <= groupCount; i++) { - final String arg = substituteValues(matcher.group(i)); + final String arg = substituteValues(matcher.group(i), cfg); if (arg != null) { if (argsList == null) { @@ -184,7 +184,7 @@ public static String[] getArgs(final String patternString, final String sourceSt public static List getArgs(final String patternString, final String sourceString, - final Class[] parameterTypes, final Class>[] converterTypes) { + final Class[] parameterTypes, final Class>[] converterTypes, Config cfg) { log.debug("Arguments getArgs List with pattern: " + patternString + " and sourceStr: " + sourceString); @@ -207,7 +207,7 @@ public static List getArgs(final String patternString, final String sour if (argsList == null) { argsList = new ArrayList<>(); } - String substituted = substituteValues(arg); + String substituted = substituteValues(arg, cfg); argsList.add(getObjectArg(substituted, parameterTypes[argIdx], converterTypes[argIdx])); } diff --git a/core/src/main/java/com/technophobia/substeps/model/Background.java b/core/src/main/java/com/technophobia/substeps/model/Background.java index cde19716..f5b7de19 100644 --- a/core/src/main/java/com/technophobia/substeps/model/Background.java +++ b/core/src/main/java/com/technophobia/substeps/model/Background.java @@ -38,7 +38,7 @@ public Background(final int lineNumber, final String rawText, final File sourceF this.steps = stepsFrom(lineNumber, rawText, sourceFile); } - private List stepsFrom(final int backgroundLineNumber, final String backgroundText, final File sourceFile) { + private static List stepsFrom(final int backgroundLineNumber, final String backgroundText, final File sourceFile) { final List backgroundSteps = new ArrayList(); final String[] bLines = backgroundText.split("\n"); for (int i = 1; i < bLines.length; i++) { @@ -64,7 +64,7 @@ public List getSteps() { return this.steps; } - private String descriptionFor(final String text) { + private static String descriptionFor(final String text) { final int startIndex = text.indexOf(":") + 1; final int endIndex = text.indexOf("\n"); diff --git a/core/src/main/java/com/technophobia/substeps/model/ParentStep.java b/core/src/main/java/com/technophobia/substeps/model/ParentStep.java index e62259ca..353ef00c 100644 --- a/core/src/main/java/com/technophobia/substeps/model/ParentStep.java +++ b/core/src/main/java/com/technophobia/substeps/model/ParentStep.java @@ -35,22 +35,19 @@ public class ParentStep { private static final Logger log = LoggerFactory.getLogger(ParentStep.class); + public static final ParentStepNameComparator PARENT_STEP_COMPARATOR = new ParentStepNameComparator(); + private final Step parent; private List substeps; private ExampleParameter paramValueMap; - public static final ParentStepNameComparator PARENT_STEP_COMPARATOR = new ParentStepNameComparator(); - - - public int getSourceLineNumber() { - return this.parent.getSourceLineNumber(); - } - - public ParentStep(final Step parent) { this.parent = parent; } + public int getSourceLineNumber() { + return this.parent.getSourceLineNumber(); + } public void addStep(final Step step) { if (this.substeps == null) { diff --git a/core/src/main/java/com/technophobia/substeps/model/PatternMap.java b/core/src/main/java/com/technophobia/substeps/model/PatternMap.java index d931237f..4d63aff0 100755 --- a/core/src/main/java/com/technophobia/substeps/model/PatternMap.java +++ b/core/src/main/java/com/technophobia/substeps/model/PatternMap.java @@ -53,7 +53,7 @@ public V getNullVale() { * @param value the value * @throws IllegalStateException - if the map already contains the specified patter. */ - public void put(final String pattern, final V value) throws IllegalStateException { + public void put(final String pattern, final V value) { if (pattern != null) { if (keys.containsKey(pattern)) { diff --git a/core/src/main/java/com/technophobia/substeps/model/Scenario.java b/core/src/main/java/com/technophobia/substeps/model/Scenario.java index 20588f64..cd6bbf1a 100755 --- a/core/src/main/java/com/technophobia/substeps/model/Scenario.java +++ b/core/src/main/java/com/technophobia/substeps/model/Scenario.java @@ -25,12 +25,6 @@ public class Scenario extends RootFeature { - @Override - public String toString() { - return "Scenario: " + this.description; - } - - private String description; private Background background = null; private List steps; @@ -44,6 +38,10 @@ public String toString() { private int sourceStartOffset = -1; private int sourceStartLineNumber = -1; + @Override + public String toString() { + return "Scenario: " + this.description; + } /** * @return the background diff --git a/core/src/main/java/com/technophobia/substeps/model/Step.java b/core/src/main/java/com/technophobia/substeps/model/Step.java index 0a2c819c..2020c456 100755 --- a/core/src/main/java/com/technophobia/substeps/model/Step.java +++ b/core/src/main/java/com/technophobia/substeps/model/Step.java @@ -60,27 +60,6 @@ public class Step { private boolean isSubstep; - /** - * @return the sourceStartOffset - */ - public int getSourceStartOffset() { - return this.sourceStartOffset; - } - - /** - * @param sourceStartOffset the sourceStartOffset to set - */ - public void setSourceStartOffset(final int sourceStartOffset) { - this.sourceStartOffset = sourceStartOffset; - } - - /** - * @return the line - */ - public String getLine() { - return this.line; - } - // tests public Step(final String line) { this(line, false, null, -1, -1); @@ -144,6 +123,27 @@ public Step(final String keyword, final String line, final boolean isSubStep) { this.sourceLineNumber = -1; } + /** + * @return the sourceStartOffset + */ + public int getSourceStartOffset() { + return this.sourceStartOffset; + } + + /** + * @param sourceStartOffset the sourceStartOffset to set + */ + public void setSourceStartOffset(final int sourceStartOffset) { + this.sourceStartOffset = sourceStartOffset; + } + + /** + * @return the line + */ + public String getLine() { + return this.line; + } + private void setParamAndParamNames() { // do we have any params in the string that we need to swap for regex // expressions? diff --git a/core/src/main/java/com/technophobia/substeps/model/Syntax.java b/core/src/main/java/com/technophobia/substeps/model/Syntax.java index 103fd97c..3f3bb476 100644 --- a/core/src/main/java/com/technophobia/substeps/model/Syntax.java +++ b/core/src/main/java/com/technophobia/substeps/model/Syntax.java @@ -64,7 +64,6 @@ public Syntax(final SyntaxErrorReporter syntaxErrorReporter) { this.syntaxErrorReporter = syntaxErrorReporter; } - public Map> getStepImplementationMap() { return this.stepImplementationMap; } diff --git a/core/src/main/java/com/technophobia/substeps/model/exception/StepImplementationException.java b/core/src/main/java/com/technophobia/substeps/model/exception/StepImplementationException.java index a80dd181..9f3e93ca 100644 --- a/core/src/main/java/com/technophobia/substeps/model/exception/StepImplementationException.java +++ b/core/src/main/java/com/technophobia/substeps/model/exception/StepImplementationException.java @@ -25,8 +25,8 @@ public class StepImplementationException extends SubstepsException { private static final long serialVersionUID = 2361658683635343317L; // class can't actually be serialized fully anyway - private transient final Class implementingClass; - private transient final Method implementingMethod; + private final transient Class implementingClass; + private final transient Method implementingMethod; public StepImplementationException(final Class implementingClass, final Method implementingMethod, final String message) { diff --git a/core/src/main/java/com/technophobia/substeps/parser/FileContents.java b/core/src/main/java/com/technophobia/substeps/parser/FileContents.java index cb55dbb7..a9732383 100644 --- a/core/src/main/java/com/technophobia/substeps/parser/FileContents.java +++ b/core/src/main/java/com/technophobia/substeps/parser/FileContents.java @@ -174,7 +174,7 @@ public int getEndOfLineOffset(final int lineNumber) { // 0-based. // This method makes this clear, rather than using undocumented +1, -1 // operations on lineNumber - private int normaliseLineNumber(final int lineNumber) { + private static int normaliseLineNumber(final int lineNumber) { return lineNumber - 1; } @@ -203,7 +203,7 @@ public String getFullContent() { } - private int firstCharacterIndex(final String line) { + private static int firstCharacterIndex(final String line) { int offset = 0; if (!line.isEmpty()) { while (Character.isWhitespace(line.charAt(offset))) { diff --git a/core/src/main/java/com/technophobia/substeps/runner/ExecutionLogger.java b/core/src/main/java/com/technophobia/substeps/runner/ExecutionLogger.java index 80ec75d9..ffb27640 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/ExecutionLogger.java +++ b/core/src/main/java/com/technophobia/substeps/runner/ExecutionLogger.java @@ -23,6 +23,8 @@ */ public abstract class ExecutionLogger implements IExecutionListener { + private static final String indentString = " "; + // TODO - buf the message, check the next one, see if its the same, don't // dupe @@ -36,8 +38,6 @@ public abstract class ExecutionLogger implements IExecutionListener { public abstract void printStarted(String msg); - private final static String indentString = " "; - private String format(final IExecutionNode node) { // TODO - no way of knowing of this is an impl or not..? diff --git a/core/src/main/java/com/technophobia/substeps/runner/ExecutionNodeRunner.java b/core/src/main/java/com/technophobia/substeps/runner/ExecutionNodeRunner.java index 14e186d5..a71b7e2f 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/ExecutionNodeRunner.java +++ b/core/src/main/java/com/technophobia/substeps/runner/ExecutionNodeRunner.java @@ -224,10 +224,11 @@ private void setupExecutionListeners( final List uncalledStepImplementations = syntax.getUncalledStepImplementations(); - if (!dataOutputDir.exists()){ - dataOutputDir.mkdir(); + if (!dataOutputDir.exists() && !dataOutputDir.mkdir()){ + log.error("failed to create directory: " + dataOutputDir.getAbsolutePath()); } + reportingUtil.writeUncalledStepImpls(uncalledStepImplementations, dataOutputDir); buildCallHierarchy(); @@ -328,12 +329,6 @@ private void addToCallHierarchy(final IExecutionNode node) { immediateParents = new ArrayList(); callerHierarchy.put(usage, immediateParents); } -// else { -// log.trace("got existing usages of node: "); -// for (final ExecutionNodeUsage u : immediateParents) { -// log.trace("already found: " + u.toString()); -// } -// } log.trace("adding used by descr: " + node.getParent().getDescription() + " line: " + node.getParent().getLine()); immediateParents.add(new ExecutionNodeUsage(node.getParent())); diff --git a/core/src/main/java/com/technophobia/substeps/runner/FeatureFileComparator.java b/core/src/main/java/com/technophobia/substeps/runner/FeatureFileComparator.java index 1a948d90..62e805bb 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/FeatureFileComparator.java +++ b/core/src/main/java/com/technophobia/substeps/runner/FeatureFileComparator.java @@ -28,11 +28,11 @@ public class FeatureFileComparator implements Comparator, Serializa private static final long serialVersionUID = -8032832302837878628L; - /* + /* * (non-Javadoc) - * - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ + * + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ @Override public int compare(final FeatureFile ff1, final FeatureFile ff2) { if (ff1 != null && ff2 != null) { diff --git a/core/src/main/java/com/technophobia/substeps/runner/FeatureFileParser.java b/core/src/main/java/com/technophobia/substeps/runner/FeatureFileParser.java index 1a7cfe1d..f89160b5 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/FeatureFileParser.java +++ b/core/src/main/java/com/technophobia/substeps/runner/FeatureFileParser.java @@ -149,7 +149,7 @@ private static boolean parseFeatureDescription(final FeatureFile ff) { /** * @param sc */ - private void buildScenario(final Scenario sc, FileContents fileContents) { + private static void buildScenario(final Scenario sc, FileContents fileContents) { final String raw = sc.getRawText(); @@ -313,7 +313,7 @@ private void processScenarioDirective(final FeatureFile ff, final Set cu } } - private int backgroundLineNumber(FileContents currentFileContents) { + private static int backgroundLineNumber(FileContents currentFileContents) { return Math.max(currentFileContents.getFirstLineNumberStartingWith("Background:"), 0); } @@ -377,7 +377,7 @@ public static String stripComments(final String line) { * @param lines * @return */ - private String stripCommentsAndBlankLines(final List lines) { + private static String stripCommentsAndBlankLines(final List lines) { final StringBuilder buf = new StringBuilder(); diff --git a/core/src/main/java/com/technophobia/substeps/runner/InitialisationClassSorter.java b/core/src/main/java/com/technophobia/substeps/runner/InitialisationClassSorter.java index bcefeb1a..290128b5 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/InitialisationClassSorter.java +++ b/core/src/main/java/com/technophobia/substeps/runner/InitialisationClassSorter.java @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.technophobia.substeps.model.exception.SubstepsConfigurationException; +import com.technophobia.substeps.model.exception.SubstepsRuntimeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -221,7 +222,7 @@ public List linearize() { if (safetyCount > 100) { String message = "Unable to resolve class initialisation order, please log this as a bug with substeps"; InitialisationClassSorter.log.error(message); - throw new RuntimeException(message); + throw new SubstepsRuntimeException(message); } } diff --git a/core/src/main/java/com/technophobia/substeps/runner/TagManager.java b/core/src/main/java/com/technophobia/substeps/runner/TagManager.java index 90475c76..3b64df2b 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/TagManager.java +++ b/core/src/main/java/com/technophobia/substeps/runner/TagManager.java @@ -43,15 +43,6 @@ public class TagManager extends AbstractExecutionNodeVisitor { private Set acceptedTags = null; private Set excludedTags = null; - public static TagManager fromTags(final String tags){ - if (tags != null){ - return new TagManager(tags); - } - else { - return null; - } - } - public TagManager(final String tagList) { acceptedTags = new HashSet(); @@ -70,6 +61,16 @@ public TagManager(final String tagList) { insertCommandLineTags(); } + public static TagManager fromTags(final String tags){ + if (tags != null){ + return new TagManager(tags); + } + else { + return null; + } + } + + public void insertTagOverlay(final String textValue) { log.debug("Inserting tag overlays " + textValue); final String[] split = toArray(textValue); @@ -124,7 +125,7 @@ public boolean acceptTaggedScenario(final Set tags) { if (acceptAll || (acceptedTags.isEmpty() && excludedTags.isEmpty())) { return true; - } else if (acceptedTags.size() > 0 && (tags == null || tags.isEmpty())) { + } else if (!acceptedTags.isEmpty() && (tags == null || tags.isEmpty())) { return false; } else if (containsAny(tags, excludedTags)) { return false; @@ -133,7 +134,7 @@ public boolean acceptTaggedScenario(final Set tags) { } } - private boolean containsAny(final Collection col1, final Collection col2) { + private static boolean containsAny(final Collection col1, final Collection col2) { if (col1 != null && col2 != null) { if (col1.size() > col2.size()) { for (final T item : col1) { @@ -152,7 +153,7 @@ private boolean containsAny(final Collection col1, final Collection co return false; } - private String[] toArray(final String annotationValue) { + private static String[] toArray(final String annotationValue) { final String[] split = annotationValue.split("[ \\s]"); final String[] results = new String[split.length]; for (int i = 0; i < split.length; i++) { @@ -165,7 +166,7 @@ public Set getAcceptedTags() { return acceptedTags; } - private String normaliseTag(final String tag) { + private static String normaliseTag(final String tag) { if (tag.startsWith(IGNORE_TAG_PREFIX)) { return tag.substring(2); } diff --git a/core/src/main/java/com/technophobia/substeps/runner/builder/ScenarioNodeBuilder.java b/core/src/main/java/com/technophobia/substeps/runner/builder/ScenarioNodeBuilder.java index bfd43fe6..1a25be81 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/builder/ScenarioNodeBuilder.java +++ b/core/src/main/java/com/technophobia/substeps/runner/builder/ScenarioNodeBuilder.java @@ -49,7 +49,7 @@ public class ScenarioNodeBuilder { } // TODO - to turn off - @SuppressWarnings("PMD.AvoidCatchingThrowable") - public ScenarioNode build(final Scenario scenario, final Set inheritedTags, int depth) { + public ScenarioNode build(final Scenario scenario, final Set inheritedTags, int depth) { if (parameters.isRunnable(scenario)) { @@ -62,7 +62,7 @@ public ScenarioNode build(final Scenario scenario, final Set inherite } } - private ScenarioNode buildRunnableScenarioNode(final Scenario scenario, Set inheritedTags, int depth) { + private ScenarioNode buildRunnableScenarioNode(final Scenario scenario, Set inheritedTags, int depth) { ScenarioNode scenarioNode = null; diff --git a/core/src/main/java/com/technophobia/substeps/runner/builder/SubstepNodeBuilder.java b/core/src/main/java/com/technophobia/substeps/runner/builder/SubstepNodeBuilder.java index f25dc590..10daa921 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/builder/SubstepNodeBuilder.java +++ b/core/src/main/java/com/technophobia/substeps/runner/builder/SubstepNodeBuilder.java @@ -321,17 +321,13 @@ private void setMethodParameters(final StepImplementation execImpl, final String paramValueMap = parent.getParamValueMap().getParameters(); } - final Object[] methodParameters = getStepMethodArguments(stepParameter, paramValueMap, execImpl.getValue(), + getStepMethodArguments(stepParameter, paramValueMap, execImpl.getValue(), inlineTable, stepImplementationMethodParameterTypes, parameterConverters, stepNode); - if (methodParameters.length != stepImplementationMethodParameterTypes.length) { - throw new IllegalArgumentException( - "Argument mismatch between what expected for step impl and what found in feature"); - } } } - private Object[] getStepMethodArguments(final String stepParameter, final Map parentArguments, + private static Object[] getStepMethodArguments(final String stepParameter, final Map parentArguments, final String stepImplementationPattern, final List> inlineTable, final Class[] parameterTypes, final Class>[] converterTypes, final StepImplementationNode stepNode) { @@ -342,7 +338,7 @@ private Object[] getStepMethodArguments(final String stepParameter, final Map argsList = Arguments.getArgs(stepImplementationPattern, substitutedStepParam, parameterTypes, - converterTypes); + converterTypes, Configuration.INSTANCE.getConfig()); if (inlineTable != null) { if (argsList == null) { @@ -356,6 +352,11 @@ private Object[] getStepMethodArguments(final String stepParameter, final Map>[] getParameterConverters(final Method method) { + private static Class>[] getParameterConverters(final Method method) { final Annotation[][] annotations = method.getParameterAnnotations(); final int size = annotations.length; diff --git a/core/src/main/java/com/technophobia/substeps/runner/logger/AnsiColourExecutionLogger.java b/core/src/main/java/com/technophobia/substeps/runner/logger/AnsiColourExecutionLogger.java index f27831bd..ed3b5b04 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/logger/AnsiColourExecutionLogger.java +++ b/core/src/main/java/com/technophobia/substeps/runner/logger/AnsiColourExecutionLogger.java @@ -27,6 +27,12 @@ public class AnsiColourExecutionLogger extends ExecutionLogger { private static final Logger log = LoggerFactory.getLogger(AnsiColourExecutionLogger.class); + public static final String PREFIX = "\033["; + + public static final String SEPARATOR = ";"; + + public static final String POSTFIX = "m"; + @Override public void printFailed(final String msg) { @@ -39,7 +45,7 @@ public void printStarted(final String msg) { print(format(msg, TextFormat.DARK, TextColour.GREEN)); } - private void print(final String formatted) { + private static void print(final String formatted) { log.info(formatted); } @@ -59,11 +65,6 @@ private static String format(final String s, final TextFormat attribute, final T return PREFIX + attribute + SEPARATOR + colour + POSTFIX + s + PREFIX + "39;0;" + POSTFIX; } - public static final String PREFIX = "\033["; - - public static final String SEPARATOR = ";"; - - public static final String POSTFIX = "m"; public enum TextColour { diff --git a/core/src/main/java/com/technophobia/substeps/runner/node/AbstractNodeRunner.java b/core/src/main/java/com/technophobia/substeps/runner/node/AbstractNodeRunner.java index 8af8edfe..5f931e8b 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/node/AbstractNodeRunner.java +++ b/core/src/main/java/com/technophobia/substeps/runner/node/AbstractNodeRunner.java @@ -143,7 +143,7 @@ protected void recordResult(final NODE_TYPE node, final boolean success, final R } else { // it's a child node that's failed - no need to copy the details - node.getResult().setChildFailure(lastFailure); + node.getResult().setChildFailure(); } } else { diff --git a/core/src/main/java/com/technophobia/substeps/runner/node/StepImplementationNodeRunner.java b/core/src/main/java/com/technophobia/substeps/runner/node/StepImplementationNodeRunner.java index d145168a..0acbac4e 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/node/StepImplementationNodeRunner.java +++ b/core/src/main/java/com/technophobia/substeps/runner/node/StepImplementationNodeRunner.java @@ -120,7 +120,7 @@ private byte[] attemptScreenshot(StepImplementationNode node, RootNodeExecut (Class) node.getTargetClass()) : null; } - private byte[] getScreenshot(RootNodeExecutionContext context, + private static byte[] getScreenshot(RootNodeExecutionContext context, Class screenshotClass) { T screenshotTakingInstance = context.getMethodExecutor().getImplementation(screenshotClass); diff --git a/core/src/main/java/com/technophobia/substeps/runner/setupteardown/BeforeAndAfterMethods.java b/core/src/main/java/com/technophobia/substeps/runner/setupteardown/BeforeAndAfterMethods.java index 5a0306d0..2ce2e133 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/setupteardown/BeforeAndAfterMethods.java +++ b/core/src/main/java/com/technophobia/substeps/runner/setupteardown/BeforeAndAfterMethods.java @@ -142,7 +142,7 @@ private void sortMethodLists(final List> classHierarchy) { } - private void sortMethodList(final List methodsList, + private static void sortMethodList(final List methodsList, final Comparator methodComparator) { Collections.sort(methodsList, methodComparator); } @@ -202,7 +202,7 @@ private List> classHierarchyFor(final Class processorClass) { } - private void appendMethodsIn(final Class processorClass, final List methods) { + private static void appendMethodsIn(final Class processorClass, final List methods) { Collections.addAll(methods, processorClass.getMethods()); } diff --git a/core/src/main/java/com/technophobia/substeps/runner/setupteardown/SetupAndTearDown.java b/core/src/main/java/com/technophobia/substeps/runner/setupteardown/SetupAndTearDown.java index 00a3771c..1ead43bc 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/setupteardown/SetupAndTearDown.java +++ b/core/src/main/java/com/technophobia/substeps/runner/setupteardown/SetupAndTearDown.java @@ -125,7 +125,7 @@ private static void removeLoggingConfig() { } - public void runSetup(final Scope currentScope, IExecutionNode node) throws Throwable { + public void runSetup(final Scope currentScope, IExecutionNode node){ this.log.trace("running setup for scope: " + currentScope); ExecutionContext.put(currentScope, "SCOPE_DESCRIPTION", node.getDescription()); diff --git a/core/src/main/java/com/technophobia/substeps/runner/syntax/ClassAnalyser.java b/core/src/main/java/com/technophobia/substeps/runner/syntax/ClassAnalyser.java index df61769d..ce11f7ff 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/syntax/ClassAnalyser.java +++ b/core/src/main/java/com/technophobia/substeps/runner/syntax/ClassAnalyser.java @@ -38,16 +38,11 @@ public void analyseClass(final Class loadedClass, final Syntax syntax) { } if (hasAdditionalStepsAnnotation(loadedClass)) { - analyseAdditionalStepImplementations(loadedClass, syntax, getAdditionalStepClasses(loadedClass)); + analyseAdditionalStepImplementations(syntax, getAdditionalStepClasses(loadedClass)); } } - /** - * @param loadedClass - * @param stepImplementationMap - * @param m - */ private void analyseMethod(final Class loadedClass, final Syntax syntax, final Method m) { // TODO - handle ignores ? @@ -110,11 +105,8 @@ protected String stepValueFrom(final Method m) { /** * Analyses all deferred step implementation classes of the loading class * - * @param loadedClass - * @param syntax - * @param syntaxErrorReporter */ - private void analyseAdditionalStepImplementations(final Class loadedClass, final Syntax syntax, + private void analyseAdditionalStepImplementations(final Syntax syntax, final Class[] additionalStepImplementationClasses) { for (final Class stepImplClass : additionalStepImplementationClasses) { analyseClass(stepImplClass, syntax); diff --git a/core/src/main/java/com/technophobia/substeps/runner/syntax/DefaultSyntaxErrorReporter.java b/core/src/main/java/com/technophobia/substeps/runner/syntax/DefaultSyntaxErrorReporter.java index 6792dccb..dc04c03b 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/syntax/DefaultSyntaxErrorReporter.java +++ b/core/src/main/java/com/technophobia/substeps/runner/syntax/DefaultSyntaxErrorReporter.java @@ -31,19 +31,11 @@ public class DefaultSyntaxErrorReporter implements SyntaxErrorReporter { @Override public void reportFeatureError(final File file, final String line, final int lineNumber, final int offset, - final String description) throws RuntimeException { + final String description) { LOG.error("Error on line " + lineNumber + " of feature file " + file.getAbsolutePath() + ": " + line + " - reason: " + description); } - @Override - public void reportFeatureError(final File file, final String line, final int lineNumber, final int offset, - final String description, final RuntimeException ex) throws RuntimeException { - LOG.error("Error on line " + lineNumber + " of feature file " + file.getAbsolutePath() + ": " + line - + " - reason: " + description); - throw ex; - } - @Override public void reportSubstepsError(final SubstepsParsingException ex) { LOG.error(ex.getMessage()); diff --git a/core/src/main/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParser.java b/core/src/main/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParser.java index bf2d791d..fd08e7a9 100755 --- a/core/src/main/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParser.java +++ b/core/src/main/java/com/technophobia/substeps/runner/syntax/SubStepDefinitionParser.java @@ -51,6 +51,8 @@ public class SubStepDefinitionParser { private final SyntaxErrorReporter syntaxErrorReporter; + private Directive currentDirective = null; + public SubStepDefinitionParser(final SyntaxErrorReporter syntaxErrorReporter) { this(true, syntaxErrorReporter); } @@ -60,6 +62,7 @@ public SubStepDefinitionParser(final boolean failOnDuplicateSubsteps, final Synt this.syntaxErrorReporter = syntaxErrorReporter; } + void parseSubStepFile(final File substepFile) { FileContents currentFileContents = FileContents.fromFile(substepFile); @@ -203,8 +206,7 @@ private void processDirective(final Directive d, final String remainder, final i } } - private void storeForPatternOrThrowException(final String newPattern, final ParentStep parentStep) - throws DuplicatePatternException { + private void storeForPatternOrThrowException(final String newPattern, final ParentStep parentStep) { if (!this.parentMap.containsPattern(newPattern)) { this.parentMap.put(newPattern, parentStep); @@ -214,7 +216,7 @@ private void storeForPatternOrThrowException(final String newPattern, final Pare } - private static enum Directive { + private enum Directive { // @formatter:off DEFINITION("Define"); @@ -227,9 +229,7 @@ private static enum Directive { private final String name; } - private Directive currentDirective = null; - - private Directive isDirective(final String word) { + private static Directive isDirective(final String word) { Directive rtn = null; diff --git a/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxBuilder.java b/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxBuilder.java index 8ed192a7..5bbce848 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxBuilder.java +++ b/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxBuilder.java @@ -20,9 +20,7 @@ import com.technophobia.substeps.model.ParentStep; import com.technophobia.substeps.model.PatternMap; -import com.technophobia.substeps.model.SubSteps; import com.technophobia.substeps.model.Syntax; -import com.technophobia.substeps.scanner.ClasspathScanner; import java.io.File; import java.util.Collections; @@ -35,17 +33,6 @@ public final class SyntaxBuilder { private SyntaxBuilder() { } - -// public static List> getStepImplementationClasses(final ClassLoader classLoader, final String[] classpath) { -// final ClasspathScanner cpScanner = new ClasspathScanner(); -// -// final List> implClassList = cpScanner.getClassesWithAnnotation(SubSteps.StepImplementations.class, -// classLoader, classpath); -// -// return implClassList; -// } - - public static Syntax buildSyntax(final List> stepImplementationClasses, final File subStepsFile) { return buildSyntax(stepImplementationClasses, subStepsFile, true, (String[])null); } diff --git a/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxErrorReporter.java b/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxErrorReporter.java index cce3d892..f137f938 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxErrorReporter.java +++ b/core/src/main/java/com/technophobia/substeps/runner/syntax/SyntaxErrorReporter.java @@ -25,16 +25,9 @@ public interface SyntaxErrorReporter { - void reportFeatureError(File file, String line, int lineNumber, int offset, String description) - throws RuntimeException; - - - void reportFeatureError(File file, String line, int lineNumber, int offset, String description, RuntimeException ex) - throws RuntimeException; - + void reportFeatureError(File file, String line, int lineNumber, int offset, String description); void reportSubstepsError(SubstepsParsingException ex); - void reportStepImplError(StepImplementationException ex); } diff --git a/core/src/main/java/com/technophobia/substeps/runner/syntax/validation/SyntaxAwareStepValidator.java b/core/src/main/java/com/technophobia/substeps/runner/syntax/validation/SyntaxAwareStepValidator.java index 9206ce50..5b15cd63 100644 --- a/core/src/main/java/com/technophobia/substeps/runner/syntax/validation/SyntaxAwareStepValidator.java +++ b/core/src/main/java/com/technophobia/substeps/runner/syntax/validation/SyntaxAwareStepValidator.java @@ -82,10 +82,7 @@ protected boolean isValid(final Step step) { } final List stepImpls = this.stepImplMap.get(step.getLine()); - if (stepImpls != null && !stepImpls.isEmpty()) { - return true; - } - return false; + return (stepImpls != null && !stepImpls.isEmpty()); } diff --git a/core/src/main/java/com/technophobia/substeps/scanner/ClasspathScanner.java b/core/src/main/java/com/technophobia/substeps/scanner/ClasspathScanner.java index e77fd5b4..0f371b3f 100644 --- a/core/src/main/java/com/technophobia/substeps/scanner/ClasspathScanner.java +++ b/core/src/main/java/com/technophobia/substeps/scanner/ClasspathScanner.java @@ -124,13 +124,13 @@ public List> getClassesWithAnnotation(final Class return getClassesWithAnnotation(desiredAnnotation, classLoader, cpElements); } - private String convertFileToClass(final File f, final File root) { + private static String convertFileToClass(final File f, final File root) { final String fqp = f.getAbsolutePath().substring(root.getAbsolutePath().length() + 1, f.getAbsolutePath().length() - 6); return fqp.replace(File.separatorChar, '.'); } - private List getAllFiles(final File root, final String extension) { + private static List getAllFiles(final File root, final String extension) { final FileFilter filter = f -> f.isDirectory() || (f.isFile() && f.getName().endsWith(extension)); final List files = new ArrayList(); diff --git a/core/src/main/java/org/substeps/report/ReportingUtil.java b/core/src/main/java/org/substeps/report/ReportingUtil.java index 08ad6943..6bb905bf 100644 --- a/core/src/main/java/org/substeps/report/ReportingUtil.java +++ b/core/src/main/java/org/substeps/report/ReportingUtil.java @@ -130,14 +130,15 @@ public void writeUncalledStepImpls(List uncalledStepImplemen } - private void write(String json, File out){ + private static void write(String json, File out){ - if (out.exists()){ - out.delete(); + if (out.exists() && !out.delete()){ + log.error("failed to delete file: " + out.getAbsolutePath()); } + try { - Files.write(json, out, Charset.forName("UTF-8")); + Files.asCharSink(out, Charset.forName("UTF-8")).write(json); } catch (IOException e) { log.error("IOException writing " + out.getName(), e); diff --git a/core/src/main/scala/org/substeps/report/ReportBuilder.scala b/core/src/main/scala/org/substeps/report/ReportBuilder.scala index c9c3e3d7..87c64d9e 100644 --- a/core/src/main/scala/org/substeps/report/ReportBuilder.scala +++ b/core/src/main/scala/org/substeps/report/ReportBuilder.scala @@ -164,7 +164,8 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr val dataFile = new File(dataDir, "uncalled.stepdefs.js") if (dataFile.exists()) { - val rawUncalledStepDefs = Files.toString(dataFile, Charset.forName("UTF-8")) + + val rawUncalledStepDefs = Files.asCharSource(dataFile, Charset.forName("UTF-8")).read() parse(rawUncalledStepDefs).extract[List[UncalledStepDef]] } @@ -179,7 +180,7 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr val dataFile = new File(dataDir, "uncalled.stepimpls.js") if (dataFile.exists()) { - val rawUncalledStepImpls = Files.toString(dataFile, Charset.forName("UTF-8")) + val rawUncalledStepImpls = Files.asCharSource(dataFile, Charset.forName("UTF-8")).read() parse(rawUncalledStepImpls).extract[List[UncalledStepImpl]] } @@ -205,7 +206,9 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr implicit val rDir : File = repDir val dataDir = new File(repDir, "data") - dataDir.mkdir() + if (!dataDir.mkdir()){ + log.error("failed to create dir: " + dataDir.getAbsolutePath) + } FileUtils.copyDirectory(new File(sourceDataDir.getPath), dataDir) @@ -671,7 +674,9 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr def createFile(name : String)(implicit reportDir : File): File = { val f = new File(reportDir, name) - f.createNewFile() + if (!f.createNewFile()){ + log.error("failed to create file: " + f.getAbsolutePath) + } f } @@ -720,7 +725,8 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr val files = srcDir.listFiles().toList files.find(f => f.getName == "results.json").map(resultsFile => { - read[RootNodeSummary](Files.toString(resultsFile, Charset.defaultCharset())) + + read[RootNodeSummary](Files.asCharSource(resultsFile, Charset.defaultCharset()).read()) }) } val featureSummaries = @@ -742,7 +748,8 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr val scenarioResultsFile = new File(featureFileResultsDir, scenarioSummary.filename) - read[NodeDetail](Files.toString(scenarioResultsFile, Charset.defaultCharset())) + + read[NodeDetail](Files.asCharSource(scenarioResultsFile, Charset.defaultCharset()).read()) }) @@ -768,7 +775,8 @@ class ReportBuilder extends IReportBuilder with ReportFrameTemplate with UsageTr implicit val formats = Serialization.formats(NoTypeHints) srcDir.listFiles().toList.find(f => f.getName == srcDir.getName + ".json").map(featureResultsFile =>{ - read[FeatureSummary](Files.toString(featureResultsFile, Charset.defaultCharset())) + + read[FeatureSummary](Files.asCharSource(featureResultsFile, Charset.defaultCharset()).read()) }) } diff --git a/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java b/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java index 98406070..d21c33f1 100644 --- a/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java +++ b/core/src/test/java/com/technophobia/substeps/runner/ExecutionNodeRunnerTest.java @@ -732,6 +732,7 @@ public void testArgSubstituion() { final String patternString = "Given a substep that takes one parameter \"([^\"]*)\""; final String[] keywordPrecedence = new String[]{"Given", "And"}; + String[] args1 = Arguments.getArgs(patternString, srcString1, keywordPrecedence, cfg); diff --git a/core/src/test/java/com/technophobia/substeps/runner/syntax/validation/fake/FakeSyntaxErrorReporter.java b/core/src/test/java/com/technophobia/substeps/runner/syntax/validation/fake/FakeSyntaxErrorReporter.java index d1f102da..30b2a545 100644 --- a/core/src/test/java/com/technophobia/substeps/runner/syntax/validation/fake/FakeSyntaxErrorReporter.java +++ b/core/src/test/java/com/technophobia/substeps/runner/syntax/validation/fake/FakeSyntaxErrorReporter.java @@ -45,12 +45,6 @@ public void reportFeatureError(final File file, final String line, final int lin } - public void reportFeatureError(final File file, final String line, final int lineNumber, final int offset, - final String description, final RuntimeException ex) throws RuntimeException { - syntaxErrors.add(new SyntaxErrorData(true, file, line, lineNumber, description)); - } - - public void reportSubstepsError(final SubstepsParsingException ex) { syntaxErrors.add(new SyntaxErrorData(false, ex.getFile(), ex.getLine(), ex.getLineNumber(), ex.getMessage())); } diff --git a/core/src/test/scala/org/substeps/report/ReportBuilderTest.scala b/core/src/test/scala/org/substeps/report/ReportBuilderTest.scala index 741300e3..ff34a24d 100644 --- a/core/src/test/scala/org/substeps/report/ReportBuilderTest.scala +++ b/core/src/test/scala/org/substeps/report/ReportBuilderTest.scala @@ -42,7 +42,8 @@ class ReportBuilderTest extends FlatSpec with Matchers{ Option(uri) shouldBe defined println("uri get file: " + uri.getFile) - val rawUncalledStepDefs = Files.toString(new File( uri.getFile), Charset.forName("UTF-8")) + + val rawUncalledStepDefs = Files.asCharSource( new File( uri.getFile), Charset.forName("UTF-8")).read() val uncalledStepDefs: List[UncalledStepDef] = parse(rawUncalledStepDefs).extract[List[UncalledStepDef]] diff --git a/core/src/test/scala/org/substeps/runner/ParsingFromSourceTests.scala b/core/src/test/scala/org/substeps/runner/ParsingFromSourceTests.scala index 782bfcaa..f7d97c86 100644 --- a/core/src/test/scala/org/substeps/runner/ParsingFromSourceTests.scala +++ b/core/src/test/scala/org/substeps/runner/ParsingFromSourceTests.scala @@ -746,7 +746,8 @@ Scenario: inline table implicit val formats = Serialization.formats(NoTypeHints) - val passingScenarioContent = read[NodeDetail](Files.toString(passingScenario.get, UTF8)) + + val passingScenarioContent = read[NodeDetail](Files.asCharSource( passingScenario.get, UTF8).read()) passingScenarioContent.children.size should be (3) @@ -763,7 +764,8 @@ Scenario: inline table failingScenario shouldBe defined - val failingScenarioContent = read[NodeDetail](Files.toString(failingScenario.get, UTF8)) + + val failingScenarioContent = read[NodeDetail](Files.asCharSource( failingScenario.get, UTF8).read()) failingScenarioContent.children.size should be (4) @@ -1172,7 +1174,9 @@ Scenario: another failing scenario // tests should pass - no errors val paths1 = checkNumberOfFiles(dataDirPath1, 12) - val results1 = Files.toString(paths1.find(p => p.endsWith("results.json")).get.toFile, Charset.defaultCharset()) + + val results1 = + Files.asCharSource( paths1.find(p => p.endsWith("results.json")).get.toFile, Charset.defaultCharset()).read() val jval: JValue = parse(results1) @@ -1201,7 +1205,8 @@ Scenario: another failing scenario val allResults2 = resultsPaths2.flatMap(p => { - val resultsContents = Files.toString(p.toFile, Charset.defaultCharset()) + + val resultsContents = Files.asCharSource( p.toFile, Charset.defaultCharset()).read() val resultsFields = parse(resultsContents) filterField { @@ -1238,7 +1243,7 @@ Scenario: another failing scenario val resultsPaths3 = paths3.find(p => p.toString.endsWith("feature.results.json")) - val feaatureResultsContents3 = Files.toString(resultsPaths3.get.toFile, Charset.defaultCharset()) + val feaatureResultsContents3 = Files.asCharSource( resultsPaths3.get.toFile, Charset.defaultCharset()).read() val jresults3 = parse(feaatureResultsContents3) @@ -1271,7 +1276,7 @@ Scenario: another failing scenario val paths4 = checkNumberOfFiles(dataDirPath4, 10) - val results4 = Files.toString(paths4.find(p => p.endsWith("results.json")).get.toFile, Charset.defaultCharset()) + val results4 = Files.asCharSource( paths4.find(p => p.endsWith("results.json")).get.toFile, Charset.defaultCharset()).read() val jresults4: JValue = parse(results4) diff --git a/pom.xml b/pom.xml index f1d65cad..f110eff4 100644 --- a/pom.xml +++ b/pom.xml @@ -549,7 +549,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.0.1 + 3.3.0.603 org.apache.maven.plugins diff --git a/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java b/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java index 6df13726..28e42113 100644 --- a/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java +++ b/runner/Ant/src/main/java/com/technophobia/substeps/ant/SubStepsTask.java @@ -25,7 +25,7 @@ public class SubStepsTask extends Task { private static final String REPORT_DIR_DEFAULT = "."; @Override - public void execute() throws BuildException { + public void execute() { final BuildFailureManager buildFailureManager = new BuildFailureManager(); List substepConfigs = new ArrayList(); @@ -81,7 +81,7 @@ private void executeInternal(final BuildFailureManager buildFailureManager, } - private RootNode runExecutionConfig(final SubstepsExecutionConfig theConfig, + private static RootNode runExecutionConfig(final SubstepsExecutionConfig theConfig, final List failures) { final SubstepsRunner runner = ExecutionNodeRunnerFactory.createRunner(); diff --git a/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitFeatureRunner.java b/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitFeatureRunner.java index 207900a4..4af89396 100644 --- a/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitFeatureRunner.java +++ b/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitFeatureRunner.java @@ -142,7 +142,7 @@ public final void init(final Class reportedClass, final List> stepIm classContainingTheTests = reportedClass; - Config config = buildConfig(stepImplementationClasses, featureFile, tags, subStepsFileName, strict, nonStrictKeywordPrecedence, beforeAndAfterImplementations, classContainingTheTests.getSimpleName());//SubstepsConfigLoader.splitMasterConfig(masterConfig).get(0); + Config config = buildConfig(stepImplementationClasses, featureFile, tags, subStepsFileName, strict, nonStrictKeywordPrecedence, beforeAndAfterImplementations, classContainingTheTests.getSimpleName()); NewSubstepsExecutionConfig.setThreadLocalConfig(config); @@ -257,7 +257,7 @@ public void run(final RunNotifier junitNotifier) { runner.run(); } - private String printDescription(final Description desc, final int depth) { + private static String printDescription(final Description desc, final int depth) { final StringBuilder buf = new StringBuilder(); buf.append(Strings.repeat("\t", depth)); diff --git a/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitNotifier.java b/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitNotifier.java index 18595c43..bfc95596 100644 --- a/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitNotifier.java +++ b/runner/Junit/src/main/java/com/technophobia/substeps/runner/JunitNotifier.java @@ -40,9 +40,6 @@ public class JunitNotifier implements IJunitNotifier { private Map descriptionMap; - /** - * {@inheritDoc} - */ private void notifyTestStarted(final Description junitDescription) { if (junitRunNotifier != null && junitDescription != null) { @@ -53,9 +50,6 @@ private void notifyTestStarted(final Description junitDescription) { } - /** - * {@inheritDoc} - */ private void notifyTestFinished(final Description junitDescription) { if (junitRunNotifier != null && junitDescription != null) { log.debug(junitDescription.getDisplayName() + " notifyTestFinished"); @@ -65,9 +59,6 @@ private void notifyTestFinished(final Description junitDescription) { } - /** - * {@inheritDoc} - */ private void notifyTestIgnored(final Description junitDescription) { if (junitRunNotifier != null && junitDescription != null) { junitRunNotifier.fireTestIgnored(junitDescription); @@ -75,9 +66,6 @@ private void notifyTestIgnored(final Description junitDescription) { } - /** - * {@inheritDoc} - */ private void notifyTestFailed(final Description junitDescription, final Throwable cause) { if (junitRunNotifier != null && junitDescription != null) { log.debug(junitDescription.getDisplayName() + " notify running TestFailed"); @@ -86,7 +74,6 @@ private void notifyTestFailed(final Description junitDescription, final Throwabl junitRunNotifier.fireTestFailure(new Failure(junitDescription, cause)); } - } /** diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/glossary/CustomDoclet.java b/runner/Maven/src/main/java/com/technophobia/substeps/glossary/CustomDoclet.java index 6b8b557f..6a3da264 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/glossary/CustomDoclet.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/glossary/CustomDoclet.java @@ -162,7 +162,7 @@ private static String getSingleJavadocTagValue(final MethodDoc md, final String final Tag[] tags = md.tags(tagName); if (tags != null && tags.length > 0) { rtn = tags[0].text().replace("@" + tagName, ""); - rtn.replaceAll("\n", " "); + rtn = rtn.replaceAll("\n", " "); } return rtn != null ? rtn : ""; diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/glossary/FileBasedGlossaryPublisher.java b/runner/Maven/src/main/java/com/technophobia/substeps/glossary/FileBasedGlossaryPublisher.java index 9fccb414..772057be 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/glossary/FileBasedGlossaryPublisher.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/glossary/FileBasedGlossaryPublisher.java @@ -27,6 +27,7 @@ public abstract class FileBasedGlossaryPublisher implements GlossaryPublisher { */ private File outputFile; + private Comparator expressionComparator = (s1, s2) -> s1.getExpression().compareTo(s2.getExpression()); @Override public void publish(final List stepimplementationDescriptors) { @@ -43,9 +44,7 @@ public void publish(final List stepimplementation public abstract String getDefaultFileName(); - private Comparator expressionComparator = (s1, s2) -> s1.getExpression().compareTo(s2.getExpression()); - - private String getSection(StepDescriptor stepTag) { + private static String getSection(StepDescriptor stepTag) { boolean noTag = stepTag.getSection() == null || stepTag.getSection().isEmpty(); return noTag ? "Miscellaneous" : stepTag.getSection(); } @@ -65,7 +64,7 @@ private Map> sortStepDescriptions(List%s"; + + private static final String TABLE_ROW_FORMAT = "%s%s%s"; + @Override public String getDefaultFileName() { return "stepimplementations.html"; @@ -61,7 +65,7 @@ public String buildFileContents(final Map> se } - private void buildStepTagRows(final StringBuilder buf, final Collection infos) { + private static void buildStepTagRows(final StringBuilder buf, final Collection infos) { for (final StepDescriptor info : infos) { @@ -77,8 +81,5 @@ private void buildStepTagRows(final StringBuilder buf, final Collection%s"; - - private static final String TABLE_ROW_FORMAT = "%s%s%s"; } diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/glossary/MarkdownSubstepsPublisher.java b/runner/Maven/src/main/java/com/technophobia/substeps/glossary/MarkdownSubstepsPublisher.java index a0532825..78ebdbbe 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/glossary/MarkdownSubstepsPublisher.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/glossary/MarkdownSubstepsPublisher.java @@ -34,6 +34,14 @@ public class MarkdownSubstepsPublisher extends FileBasedGlossaryPublisher implem private static final Logger log = LoggerFactory.getLogger(MarkdownSubstepsPublisher.class); + private static final String TABLE_ROW_SECTION_FORMAT = "%s\n" + + "==========\n" + + "| **Keyword** | **Example** | **Description** |\n" + + "| :------------ |:---------------| :-----|"; + + private static final String TABLE_ROW_FORMAT = "| %s | %s | %s |"; + + @Override public String getDefaultFileName() { return "stepimplementations.md"; @@ -60,7 +68,7 @@ public String buildFileContents(final Map> se } - private void buildStepTagRows(final StringBuilder buf, final Collection infos) { + private static void buildStepTagRows(final StringBuilder buf, final Collection infos) { for (final StepDescriptor info : infos) { @@ -77,11 +85,5 @@ private void buildStepTagRows(final StringBuilder buf, final Collection runJavaDoclet(final String classToDocument) { @@ -102,7 +102,8 @@ private List runJavaDoclet(final String classToDo path }; - // Main.execute(args); + // the custom doclet generates quite a lot of noise around things missing from the classpath etc - + // not important in this context, so consume and discard apart from the errors.. StringWriter esw = new StringWriter(); PrintWriter err = new PrintWriter(esw); @@ -149,17 +150,17 @@ private String resolveClassToPath(final String classToDocument, final String dir @Override - public void executeConfig(Config cfg) throws MojoExecutionException, MojoFailureException { + public void executeConfig(Config cfg) { // no op } @Override - public void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException{ + public void executeBeforeAllConfigs(Config masterConfig) { // no op } @Override - public void executeAfterAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException{ + public void executeAfterAllConfigs(Config masterConfig) { setupBuildEnvironmentInfo(); @@ -301,7 +302,9 @@ private void writeOutputFile(String xml, String filename) { } try { - Files.write(xml, output, Charset.forName("UTF-8")); + + Files.asCharSink(output, Charset.forName("UTF-8")).write(xml); + } catch (final IOException e) { log.error("error writing file", e); } @@ -348,7 +351,7 @@ private void loadStepTagsFromJar(final JarFile jarFileForClass, } - private String convertClassNameToPath(final String className) { + private static String convertClassNameToPath(final String className) { return className.replace('.', '/') + ".class"; } @@ -360,8 +363,9 @@ private JarFile getJarFileForClass(final String className) { if (artifacts != null) { for (final Artifact a : artifacts) { // does this jar contain this class? + JarFile tempJarFile = null; try { - final JarFile tempJarFile = new JarFile(a.getFile()); + tempJarFile = new JarFile(a.getFile()); final JarEntry jarEntry = tempJarFile .getJarEntry(convertClassNameToPath(className)); @@ -373,6 +377,15 @@ private JarFile getJarFileForClass(final String className) { } catch (final IOException e) { log.error("IO Exception opening jar file", e); } + finally { + if (tempJarFile != null){ + try { + tempJarFile.close(); + } catch (IOException e) { + log.debug("ioexcception closing jar file", e); + } + } + } } } return jarFile; diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/BaseSubstepsMojo.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/BaseSubstepsMojo.java index 481866c3..88640043 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/BaseSubstepsMojo.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/BaseSubstepsMojo.java @@ -39,6 +39,7 @@ public abstract class BaseSubstepsMojo extends AbstractMojo { /** * will be removed in a later release, use .conf files instead + * @deprecated use .config files for runtime configuration instead */ @Deprecated @Parameter @@ -86,6 +87,7 @@ public abstract class BaseSubstepsMojo extends AbstractMojo { /** * if true a jvm will be spawned to run substeps otherwise substeps will * execute within the same jvm as maven + * @deprecated use .config files for runtime configuration instead */ @Deprecated @Parameter(property = "runTestsInForkedVM", defaultValue = "false") @@ -95,6 +97,7 @@ public abstract class BaseSubstepsMojo extends AbstractMojo { /** * When running in forked mode, a port is required to communicate between * maven and substeps, to set explicitly use -DjmxPort=9999 + * @deprecated use .config files for runtime configuration instead */ @Parameter(defaultValue = "9999") @Deprecated @@ -102,6 +105,7 @@ public abstract class BaseSubstepsMojo extends AbstractMojo { /** * A space delimited string of vm arguments to pass to the forked jvm + * @deprecated use .config files for runtime configuration instead */ @Deprecated @Parameter @@ -251,11 +255,11 @@ private void executeNewConfigs(List configs) throws MojoExecutionExcepti } } - public abstract void executeConfig(Config cfg) throws MojoExecutionException, MojoFailureException; + public abstract void executeConfig(Config cfg) throws MojoExecutionException; - public abstract void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException; + public abstract void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionException; - public abstract void executeAfterAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException; + public abstract void executeAfterAllConfigs(Config masterConfig) throws MojoFailureException; private void ensureValidConfiguration() throws MojoExecutionException { @@ -303,7 +307,8 @@ protected void checkPomSettings() throws MojoExecutionException{ File out = new File(resourcesDir, "migrated-application.conf"); - Files.write(configSrc, out , Charset.defaultCharset()); + Files.asCharSink(out, Charset.defaultCharset()).write(configSrc); + throw new MojoExecutionException(this, "Substeps execution config has changed and moved to a config file", "A new config file has been written to: " + out.getAbsolutePath() + ",\n this will need checking and renaming to application.conf"); diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedProcessCloser.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedProcessCloser.java index 6517e69c..5603dacb 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedProcessCloser.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedProcessCloser.java @@ -22,12 +22,20 @@ public class ForkedProcessCloser implements Runnable { + private static final long GRACEFULL_SHUTDOWN_TIMEOUT_MILLIS = 2 * 1000L; + private SubstepsJMXClient client; private Process forkedJvm; private Thread thread; private Log log; - private static final long GRACEFULL_SHUTDOWN_TIMEOUT_MILLIS = 2 * 1000L; + private ForkedProcessCloser(SubstepsJMXClient client, Process forkedJvm, Log log) { + + this.client = client; + this.forkedJvm = forkedJvm; + this.log = log; + this.thread = new Thread(this); + } public static ForkedProcessCloser addHook(SubstepsJMXClient client, Process forkedJvm, Log log) { @@ -36,19 +44,12 @@ public static ForkedProcessCloser addHook(SubstepsJMXClient client, Process fork return hook; } + public void notifyShutdownSuccessful() { Runtime.getRuntime().removeShutdownHook(getThread()); } - private ForkedProcessCloser(SubstepsJMXClient client, Process forkedJvm, Log log) { - - this.client = client; - this.forkedJvm = forkedJvm; - this.log = log; - this.thread = new Thread(this); - } - private Thread getThread() { return this.thread; diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedRunner.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedRunner.java index 6e977571..56538b58 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedRunner.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/ForkedRunner.java @@ -434,7 +434,7 @@ else if (resultNotification.getResult() == ExecutionResult.RUNNING){ } - private List flattenTree(final IExecutionNode node) { + private static List flattenTree(final IExecutionNode node) { return node.accept(new AbstractExecutionNodeVisitor() { diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/IncludeProjectDependenciesComponentConfigurator.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/IncludeProjectDependenciesComponentConfigurator.java index ff9153f8..5c1a5ba2 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/IncludeProjectDependenciesComponentConfigurator.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/IncludeProjectDependenciesComponentConfigurator.java @@ -102,7 +102,7 @@ private void addProjectDependenciesToClassRealm( } - private URL[] buildURLs(final List runtimeClasspathElements) + private static URL[] buildURLs(final List runtimeClasspathElements) throws ComponentConfigurationException { // Add the projects classes and dependencies final List urls = new ArrayList( diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsJMXClient.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsJMXClient.java index 2ecb60ea..8506622f 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsJMXClient.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsJMXClient.java @@ -52,12 +52,12 @@ public class SubstepsJMXClient implements SubstepsRunner, NotificationListener { private JMXConnector cntor = null; private MBeanServerConnection mbsc = null; + private ExecutionNodeResultNotificationHandler notificiationHandler = null; + public void setNotificiationHandler(ExecutionNodeResultNotificationHandler notificiationHandler) { this.notificiationHandler = notificiationHandler; } - private ExecutionNodeResultNotificationHandler notificiationHandler = null; - public byte[] runAsBytes() { return this.mbean.runAsBytes(); @@ -89,7 +89,7 @@ public void init(final int portNumber) throws MojoExecutionException { addNotificationListener(objectName); - } + } } catch (final IOException e) { @@ -164,7 +164,7 @@ public byte[] prepareExecutionConfigAsBytes(final String theConfig) { return this.mbean.prepareExecutionConfigAsBytes(theConfig); } catch (SubstepsConfigurationException ex){ - log.error("Failed to init tests: " + ex.getMessage()); + log.error("Failed to init tests", ex); return null; } } @@ -186,7 +186,7 @@ public RootNode prepareExecutionConfig(Config theConfig) { return null; } - @Override + @Override public List getFailures() { return this.mbean.getFailures(); @@ -233,7 +233,7 @@ public void handleNotification(Notification notification, Object handback) { ExecutionNodeResult result = getFromBytes(rawBytes); log.trace("received a JMX event msg: " + notification.getMessage() + - " seq: " + notification.getSequenceNumber() + " exec result node id: " + result.getExecutionNodeId()); + " seq: " + notification.getSequenceNumber() + " exec result node id: " + (result != null ? result.getExecutionNodeId() : "no result")); notificiationHandler.handleNotification(result); } else if (notification.getType().compareTo("ExecConfigComplete") == 0) { diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsReportBuilderMojo.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsReportBuilderMojo.java index 775b14e6..52746908 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsReportBuilderMojo.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsReportBuilderMojo.java @@ -42,17 +42,17 @@ public class SubstepsReportBuilderMojo extends BaseSubstepsMojo { @Override - public void executeConfig(Config cfg) throws MojoExecutionException, MojoFailureException { - + public void executeConfig(Config cfg) { + // no op } @Override - public void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException{ - + public void executeBeforeAllConfigs(Config masterConfig) { + // no op } @Override - public void executeAfterAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException{ + public void executeAfterAllConfigs(Config masterConfig) throws MojoFailureException{ setupBuildEnvironmentInfo(); diff --git a/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsRunnerMojo.java b/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsRunnerMojo.java index 4f3b838a..78526e71 100644 --- a/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsRunnerMojo.java +++ b/runner/Maven/src/main/java/com/technophobia/substeps/runner/SubstepsRunnerMojo.java @@ -103,12 +103,12 @@ public class SubstepsRunnerMojo extends BaseSubstepsMojo { @Override - public void executeAfterAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException{ + public void executeAfterAllConfigs(Config masterConfig) throws MojoFailureException{ processBuildData(); } @Override - public void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionException, MojoFailureException{ + public void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionException{ // write out the master config to the root data dir File rootDataDir = NewSubstepsExecutionConfig.getRootDataDir(masterConfig); @@ -121,21 +121,17 @@ public void executeBeforeAllConfigs(Config masterConfig) throws MojoExecutionExc String renderedConfig = SubstepsConfigLoader.render(masterConfig); this.getLog().info("\n\n *** USING COMBINED CONFIG:\n\n" + renderedConfig + "\n\n"); - Files.write(renderedConfig, outFile, Charset.forName("UTF-8")); + Files.asCharSink(outFile, Charset.forName("UTF-8")).write(renderedConfig); } catch (IOException e){ throw new MojoExecutionException(e.getMessage(), e); } } - private void mkdirOrException(File dir) { - if (!dir.exists()){ - - if (!dir.mkdirs()){ - throw new SubstepsRuntimeException("Failed to create dir: " + dir.getAbsolutePath()); - } + private static void mkdirOrException(File dir) { + if (!dir.exists() && !dir.mkdirs()){ + throw new SubstepsRuntimeException("Failed to create dir: " + dir.getAbsolutePath()); } - }