diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8991f..e92ef38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Changelog of Violation Comments to Stash Plugin +# 1.5 +* Less logging in build log + # 1.4 * Finding all violations for files. Even if same file is reported twice (with absolute and relative path). diff --git a/build.sh b/build.sh index 40049c3..8392707 100755 --- a/build.sh +++ b/build.sh @@ -12,6 +12,7 @@ function build_clean { ## echo Setting up Maven mkdir -p ~/.m2 +[ -f ~/.m2/settings.xml.backup ] || cp ~/.m2/settings.xml ~/.m2/settings.xml.backup cp sandbox/settings.xml ~/.m2/settings.xml ## diff --git a/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java b/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java index 1ad446d..0213fc9 100644 --- a/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java +++ b/plugin-test/src/test/java/org/jenkinsci/plugins/jvcts/test/ConfigurationWebTest.java @@ -4,6 +4,7 @@ import static com.google.common.base.MoreObjects.firstNonNull; import static java.lang.System.getProperty; import static java.lang.Thread.sleep; +import static java.util.logging.Level.OFF; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.openqa.selenium.By.id; @@ -12,6 +13,7 @@ import java.util.logging.Logger; +import org.apache.commons.logging.LogFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -52,6 +54,12 @@ public class ConfigurationWebTest { private static final String TEST_JOB_NAME = "testJobb"; private WebDriver webDriver; + static { + LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); + java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(OFF); + java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(OFF); + } + private String getJenkinsBaseUrl() { return firstNonNull(getProperty(PROP_JENKINS_URL), "http://localhost:8080/jenkins"); } diff --git a/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java b/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java index 16aef21..4ccd83c 100644 --- a/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java +++ b/src/main/java/org/jenkinsci/plugins/jvcts/perform/JvctsPerformer.java @@ -22,7 +22,6 @@ import java.net.MalformedURLException; import java.util.List; import java.util.Map; -import java.util.logging.Logger; import org.jenkinsci.plugins.jvcts.JvctsLogger; import org.jenkinsci.plugins.jvcts.config.ParserConfig; @@ -32,7 +31,6 @@ import com.google.common.annotations.VisibleForTesting; public class JvctsPerformer { - private static final Logger logger = Logger.getLogger(JvctsPerformer.class.getName()); public static void jvctsPerform(ViolationsToStashConfig config, AbstractBuild build, BuildListener listener) { try { @@ -50,7 +48,7 @@ public static void jvctsPerform(ViolationsToStashConfig config, AbstractBuild> violationsPerFile, if (!isNullOrEmpty(config.getStashPullRequestId())) { doLog(FINE, "Commenting pull request \"" + config.getStashPullRequestId() + "\""); for (String changedFileInStash : jvctsStashClient.getChangedFileInPullRequest()) { - logger.log(FINE, "Changed file in pull request: \"" + changedFileInStash + "\""); + doLog(FINE, "Changed file in pull request: \"" + changedFileInStash + "\""); jvctsStashClient.removeCommentsFromPullRequest(changedFileInStash); for (Violation violation : getViolationsForFile(violationsPerFile, changedFileInStash, listener)) { jvctsStashClient.commentPullRequest(changedFileInStash, violation.getLine(), constructCommentMessage(violation)); @@ -77,7 +75,7 @@ private static void commentStash(Map> violationsPerFile, if (!isNullOrEmpty(config.getCommitHash())) { doLog(FINE, "Commenting commit \"" + config.getCommitHash() + "\""); for (String changedFileInStash : jvctsStashClient.getChangedFileInCommit()) { - logger.log(FINE, "Changed file in commit: \"" + changedFileInStash + "\""); + doLog(FINE, "Changed file in commit: \"" + changedFileInStash + "\""); jvctsStashClient.removeCommentsCommit(changedFileInStash); for (Violation violation : getViolationsForFile(violationsPerFile, changedFileInStash, listener)) { jvctsStashClient.commentCommit(changedFileInStash, violation.getLine(), constructCommentMessage(violation)); @@ -90,20 +88,18 @@ private static void commentStash(Map> violationsPerFile, * Get list of violations that has files ending with changed file in Stash. * Violation instances may have absolute or relative paths, we can not trust * that. - * - * @param listener */ private static List getViolationsForFile(Map> violationsPerFile, String changedFileInStash, BuildListener listener) { List found = newArrayList(); for (String reportedFile : violationsPerFile.keySet()) { if (reportedFile.endsWith(changedFileInStash) || changedFileInStash.endsWith(reportedFile)) { - JvctsLogger.doLog(listener, FINE, "Changed file and reported file matches. Stash: \"" + changedFileInStash - + "\" Reported: \"" + reportedFile + "\""); + JvctsLogger.doLog(listener, FINE, "Found comments for \"" + changedFileInStash + "\" (reported as \"" + + reportedFile + "\")"); found.addAll(violationsPerFile.get(reportedFile)); } else { - doLog(listener, FINE, "Changed file and reported file not matching. Stash: \"" + changedFileInStash - + "\" Reported: \"" + reportedFile + "\""); + doLog(FINE, "Changed file and reported file not matching. Stash: \"" + changedFileInStash + "\" Reported: \"" + + reportedFile + "\""); } } return found;