Skip to content

Commit

Permalink
Merge pull request #1283 from Bertk/fixes
Browse files Browse the repository at this point in the history
suppress error message (input file is not available)
  • Loading branch information
guwirth authored Nov 6, 2017
2 parents d6bab96 + 0476d7f commit 423222a
Showing 1 changed file with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @author jorge costa, stefan weiser
*/
public class CxxOtherSensor extends CxxReportSensor {
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 @@ -118,7 +119,7 @@ protected String getSensorKey() {

public void transformFiles(final File baseDir, SensorContext context) {
boolean goOn = true;
for (int i = 1; (i < 10) && goOn; i++) {
for (int i = 1; (i < MAX_STYLESHEETS) && goOn; i++) {
String stylesheetKey = this.language.getPluginProperty(OTHER_XSLT_KEY + i + STYLESHEET_KEY);
String inputKey = this.language.getPluginProperty(OTHER_XSLT_KEY + i + INPUT_KEY);
String outputKey = this.language.getPluginProperty(OTHER_XSLT_KEY + i + OUTPUT_KEY);
Expand All @@ -134,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 @@ -155,21 +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())) {
LOG.error(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 423222a

Please sign in to comment.