Skip to content
Permalink
Browse files

JENKINS-26568: Static analysis code fixes

Fixed some warnings from our build pipeline around our statis analysis
of the code.
  • Loading branch information...
buep committed Mar 6, 2015
1 parent 6050417 commit b3bfd2d5ec32945c22ff48a54e06d2d6eacfe413
@@ -7,7 +7,6 @@
package org.jenkinsci.plugins.pretestedintegration.scm.git;

import hudson.Extension;
import hudson.Functions;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
@@ -20,7 +19,6 @@
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.pretestedintegration.AbstractSCMBridge;
import org.jenkinsci.plugins.pretestedintegration.Commit;
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegationFailedExeception;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategyDescriptor;
@@ -91,13 +89,13 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
// which aren't really ensure to match what the 'git merge' command ends up merging.
// The method that get all commits from a branch walk the git tree using JGit, so it is complete independent from the following
// merge operation. Worst case is that the merge commit message is based on other commits than the actual merge commit consist of.
String commits = client.withRepository(new GetAllCommitsFromBranchCallback(listener, gitDataBranch.getSHA1(), gitbridge.getBranch()));
String headerLine = String.format("Accumulated commit of the following from branch '%s':\n", gitDataBranch.getName());
exitCode = gitbridge.git(build, launcher, listener, out, "merge","-m", String.format("%s\n%s", headerLine, commits), commit, "--no-ff");
String commits = client.withRepository(new GetAllCommitsFromBranchCallback(listener, gitDataBranch.getSHA1(), gitbridge.getBranch()));
String headerLine = String.format("Accumulated commit of the following from branch '%s':%n", gitDataBranch.getName());
exitCode = gitbridge.git(build, launcher, listener, out, "merge", "-m", String.format("%s%n%s", headerLine, commits), commit, "--no-ff");

} catch (Exception ex) {
logger.exiting("AccumulatedCommitStrategy ", "integrate-mergeFailure");// Generated code DONT TOUCH! Bookmark: 26b6ce59c6edbad7afa29f96febc6fd7
logger.log(Level.WARNING, "Exception while merging, logging exception",ex);
logger.exiting("AccumulatedCommitStrategy ", "integrate-mergeFailure"); // Generated code DONT TOUCH! Bookmark: 26b6ce59c6edbad7afa29f96febc6fd7
logger.log(Level.WARNING, "Exception while merging, logging exception", ex);
throw new IntegationFailedExeception(ex);
}

@@ -11,9 +11,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -52,14 +50,6 @@ public String invoke(Repository repo, VirtualChannel channel) throws IOException
// iterating over the commits that will be integrated
for (RevCommit rev : walk) {


// Using spaces in git commit message formatting, to avoid inconsistent
// results based on tab with, and to mimic normal recommendations
// on writing commit message (indented bullet lists with space)
// following (same) examples:
// http://chris.beams.io/posts/git-commit/
// http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
// 4 spaces are used, as this is how the squashed commit message looks like
sb.append(String.format("commit %s",rev.getName()));
sb.append(String.format("%n"));
// In the commit message overview, the author is right one to give credit (author wrote the code)
@@ -68,15 +58,22 @@ public String invoke(Repository repo, VirtualChannel channel) throws IOException

Integer secondsSinceUnixEpoch = rev.getCommitTime();
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy ZZZZ"); //yyyy-MM-dd'T'hh:mm:ssZZZZ");
Date commitTime = new Date(secondsSinceUnixEpoch * 1000L);
Date commitTime = new Date(secondsSinceUnixEpoch * 1000L); // seconds to milis
String asString = formatter.format(commitTime);
sb.append(String.format("Date: %s", asString ));
sb.append(String.format("%n"));
sb.append(String.format("%n"));

String newlinechar = System.getProperty("line.separator");
String indentation = String.format("%" + 4 + "s", "");

// Using spaces in git commit message formatting, to avoid inconsistent
// results based on tab with, and to mimic normal recommendations
// on writing commit message (indented bullet lists with space)
// following (same) examples:
// http://chris.beams.io/posts/git-commit/
// http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
// 4 spaces are used, as this is how the squashed commit message looks like
Integer numberOfSpaces = 4;
String indentation = String.format("%" + numberOfSpaces + "s", "");
String fullMessage = rev.getFullMessage();
Pattern myregexp = Pattern.compile(newlinechar, Pattern.MULTILINE);

0 comments on commit b3bfd2d

Please sign in to comment.
You can’t perform that action at this time.