/* * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jetbrains.buildServer.xmlReportPlugin; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import static jetbrains.buildServer.xmlReportPlugin.XmlReportPluginConstants.*; public class XmlReportPluginUtil { public static final Map SUPPORTED_REPORT_TYPES = new HashMap(); public static final List INSPECTIONS_TYPES = new LinkedList(); public static final List DUPLICATES_TYPES = new LinkedList(); static { SUPPORTED_REPORT_TYPES.put("junit", "Ant JUnit"); SUPPORTED_REPORT_TYPES.put("nunit", "NUnit"); SUPPORTED_REPORT_TYPES.put("surefire", "Surefire"); SUPPORTED_REPORT_TYPES.put("findBugs", "FindBugs"); SUPPORTED_REPORT_TYPES.put("pmd", "PMD"); SUPPORTED_REPORT_TYPES.put("checkstyle", "Checkstyle"); SUPPORTED_REPORT_TYPES.put("pmdCpd", "PMD CPD"); INSPECTIONS_TYPES.add("findBugs"); INSPECTIONS_TYPES.add("pmd"); INSPECTIONS_TYPES.add("checkstyle"); DUPLICATES_TYPES.add("pmdCpd"); } public static boolean isParsingEnabled(@NotNull final Map params) { return params.containsKey(REPORT_TYPE) && !"".equals(params.get(REPORT_TYPE)); } public static boolean isOutputVerbose(@NotNull final Map params) { return params.containsKey(VERBOSE_OUTPUT) && Boolean.parseBoolean(params.get(VERBOSE_OUTPUT)); } public static boolean isParseOutOfDateReports(@NotNull final Map params) { return params.containsKey(PARSE_OUT_OF_DATE) && Boolean.parseBoolean(params.get(PARSE_OUT_OF_DATE)); } public static void enableXmlReportParsing(@NotNull final Map params, String reportType) { if (reportType.equals("")) { params.remove(REPORT_TYPE); params.remove(REPORT_DIRS); params.remove(VERBOSE_OUTPUT); params.remove(PARSE_OUT_OF_DATE); } else { params.put(REPORT_TYPE, reportType); } } public static void setVerboseOutput(@NotNull final Map params, boolean verboseOutput) { if (isParsingEnabled(params)) { if (verboseOutput) { params.put(VERBOSE_OUTPUT, "true"); } else { params.remove(VERBOSE_OUTPUT); } } } public static void setParseOutOfDateReports(@NotNull final Map systemProperties, boolean shouldParse) { if (shouldParse) { systemProperties.put(PARSE_OUT_OF_DATE, "true"); } else { systemProperties.remove(PARSE_OUT_OF_DATE); } } public static void setWhenNoDataPublished(@NotNull final Map systemProperties, String value) { systemProperties.put(WHEN_NO_DATA_PUBLISHED, value); } public static void setXmlReportPaths(@NotNull final Map params, String reportDirs) { if (isParsingEnabled(params)) { params.put(REPORT_DIRS, reportDirs); } } public static String getXmlReportPaths(@NotNull final Map params) { return params.get(REPORT_DIRS); } public static String getReportType(@NotNull final Map params) { return params.get(REPORT_TYPE); } public static int getMaxErrors(@NotNull final Map params) { return getMaxErrorsOrWarnings(params, MAX_ERRORS); } public static void setMaxErrors(@NotNull final Map params, int maxErrors) { if (isParsingEnabled(params)) { params.put(MAX_ERRORS, "" + maxErrors); } } public static int getMaxWarnings(@NotNull final Map params) { return getMaxErrorsOrWarnings(params, MAX_WARNINGS); } public static void setMaxWarnings(@NotNull final Map params, int maxWarnings) { if (isParsingEnabled(params)) { params.put(MAX_WARNINGS, "" + maxWarnings); } } private static int getMaxErrorsOrWarnings(@NotNull final Map params, String what) { if (params.containsKey(what)) { try { return Integer.parseInt(params.get(what)); } catch (NumberFormatException e) { return -1; } } return -1; } public static boolean isInspection(String type) { return INSPECTIONS_TYPES.contains(type); } public static String getFindBugsHomePath(@NotNull final Map params) { return params.get(FINDBUGS_HOME); } public static boolean isDuplication(String type) { return DUPLICATES_TYPES.contains(type); } public static String getCheckoutDirPath(@NotNull final Map params) { return params.get(CHECKOUT_DIR); } public static long getBuildStart(@NotNull final Map params) { try { return params.containsKey(BUILD_START) ? Long.parseLong(params.get(BUILD_START)) : 0L; } catch (NumberFormatException e) { return 0L; } } public static String getTempFolder(@NotNull final Map params) { return params.containsKey(TMP_DIR) ? params.get(TMP_DIR) : System.getProperty("java.io.tmpdir"); } public static String getNUnitSchemaPath(@NotNull final Map params) { return "false".equalsIgnoreCase(params.get(TREAT_DLL_AS_SUITE)) ? NUNIT_TO_JUNIT_OLD_XSL : NUNIT_TO_JUNIT_XSL; } public static boolean isCheckReportComplete(@NotNull final Map params) { return !"false".equalsIgnoreCase(params.get(CHECK_REPORT_COMPLETE)); } public static boolean isCheckReportGrows(@NotNull final Map params) { return !"false".equalsIgnoreCase(params.get(CHECK_REPORT_GROWS)); } @NotNull public static String whenNoDataPublished(@NotNull final Map params) { return params.containsKey(WHEN_NO_DATA_PUBLISHED) ? params.get(WHEN_NO_DATA_PUBLISHED) : "error"; } public static boolean isLogIsInternal(@NotNull final Map params) { return params.containsKey(LOG_AS_INTERNAL) && params.get(LOG_AS_INTERNAL) != null ? Boolean.parseBoolean(params.get(LOG_AS_INTERNAL)) : !isOutputVerbose(params); } }