Skip to content

Commit

Permalink
Less logging
Browse files Browse the repository at this point in the history
* Also creating a backup of settings.xml when running build.sh
  • Loading branch information
tomasbjerre committed May 30, 2015
1 parent 068b77e commit 17e7bc0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -50,7 +48,7 @@ public static void jvctsPerform(ViolationsToStashConfig config, AbstractBuild<?,
doLog(FINE, "Workspace: " + workspace.getAbsolutePath());
doPerform(config, workspace, listener);
} catch (Exception e) {
logger.log(SEVERE, "", e);
doLog(SEVERE, "", e);
return;
}
}
Expand All @@ -67,7 +65,7 @@ private static void commentStash(Map<String, List<Violation>> 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));
Expand All @@ -77,7 +75,7 @@ private static void commentStash(Map<String, List<Violation>> 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));
Expand All @@ -90,20 +88,18 @@ private static void commentStash(Map<String, List<Violation>> 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<Violation> getViolationsForFile(Map<String, List<Violation>> violationsPerFile,
String changedFileInStash, BuildListener listener) {
List<Violation> 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;
Expand Down

0 comments on commit 17e7bc0

Please sign in to comment.