Skip to content

Commit

Permalink
improve input check
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertk committed Nov 5, 2017
1 parent dbe5473 commit 0476d7f
Showing 1 changed file with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @author jorge costa, stefan weiser
*/
public class CxxOtherSensor extends CxxReportSensor {
static final int MAX_STYLESHEETS = 10;
private static final int MAX_STYLESHEETS = 10;
private static final Logger LOG = Loggers.get(CxxOtherSensor.class);
public static final String REPORT_PATH_KEY = "other.reportPath";
public static final String KEY = "other";
Expand Down Expand Up @@ -135,11 +135,15 @@ public void transformFiles(final File baseDir, SensorContext context) {
String[] outputStrings = context.settings().getStringArray(outputKey);
List<String> outputs = Arrays.asList((outputStrings != null) ? outputStrings : new String[] {});

if (stylesheet == null) {
LOG.error(stylesheetKey + " is not defined.");
if (stylesheet == null && inputKey==null && outputKey==null) {
goOn = false;
} else {
goOn = checkInput(inputKey, outputKey, inputs, outputs);
if (stylesheet == null) {
LOG.error(stylesheetKey + " is not defined.");
goOn = false;
} else {
goOn = checkInput(inputKey, outputKey, inputs, outputs);
}
}

if (goOn) {
Expand All @@ -156,23 +160,44 @@ public void transformFiles(final File baseDir, SensorContext context) {

private static boolean checkInput(String inputKey, String outputKey, @Nullable List<File> inputs,
@Nullable List<String> outputs) {
if ((inputs == null) || (inputs.isEmpty())) {
if (LOG.isDebugEnabled()) {
LOG.debug(inputKey + " file is not defined.");
}
return isValidInput(inputKey, inputs) && isValidOutput(outputKey, outputs) && hasCorrectSize(inputs, outputs);
}

/**
* @param inputs
* @param outputs
* @return
*/
private static boolean hasCorrectSize(List<File> inputs, List<String> outputs) {
if (inputs.size() != outputs.size()) {
LOG.error("Number of source XML files is not equal to the the number of output files.");
return false;
}
}
return true;
}

/**
* @param outputKey
* @param outputs
* @return
*/
private static boolean isValidOutput(String outputKey, @Nullable List<String> outputs) {
if ((outputs == null) || (outputs.isEmpty())) {
LOG.error(outputKey + " is not defined.");
return false;
}
return true;
}

if (inputs.size() != outputs.size()) {
LOG.error("Number of source XML files is not equal to the the number of output files.");
/**
* @param inputKey
* @param inputs
*/
private static boolean isValidInput(String inputKey, @Nullable List<File> inputs) {
if ((inputs == null) || (inputs.isEmpty())) {
LOG.error(inputKey + " file is not defined.");
return false;
}

}
return true;
}

Expand Down

0 comments on commit 0476d7f

Please sign in to comment.