Skip to content
Permalink
Browse files

[JENKINS-27690],[JENKINS-27662],[JENKINS-27697]: checkstyle fixes

Fixed some checkstyle warnings to pass thressholds.
  • Loading branch information...
buep committed Apr 5, 2015
1 parent c032c71 commit bba993008f51195ebf913d760d405d7b28aa5ad6
@@ -52,28 +52,30 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
BuildData gitBuildData = gitbridge.checkAndDetermineRelevantBuildData(build.getActions(BuildData.class));
String commit = gitBuildData.lastBuild.revision.getSha1String();

//TODO: Implement robustness, in which situations does this one contain multiple revisons, when two branches point to the same commit? (JENKINS-24909). Check branch spec before doing anything
Branch gitDataBranch = gitBuildData.lastBuild.revision.getBranches().iterator().next();
//TODO: Implement robustness, in which situations does this one contain
// multiple revisons, when two branches point to the same commit?
// (JENKINS-24909). Check branch spec before doing anything
Branch gitDataBranch = gitBuildData.lastBuild.revision.getBranches().iterator().next();
boolean found = false;

try {
logger.fine("Resolving and getting git client from workspace:");
client = Git.with(listener, build.getEnvironment(listener)).in(gitbridge.resolveWorkspace(build, listener)).getClient();
client = Git.with(listener, build.getEnvironment(listener)).in(gitbridge.resolveWorkspace(build, listener)).getClient();
logger.fine("Finding remote branches:");
for(Branch b : client.getRemoteBranches()) {
for (Branch b : client.getRemoteBranches()) {
logger.fine(String.format("Found remote branch %s", b.getName()));
if(b.getName().equals(gitDataBranch.getName())) {
if (b.getName().equals(gitDataBranch.getName())) {
found = true;
break;
}
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "GitClient error", ex);
logger.exiting("AccumulatedCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: 26b6ce59c6edbad7afa29f96febc6fd7
throw new IntegationFailedExeception("GitClient error, unspecified", ex);
throw new IntegationFailedExeception("GitClient error, unspecified", ex);
}
if(!found) {

if (!found) {
logger.fine("Found no remote branches.");
try {
logger.fine("Setting build description 'Nothing to do':");
@@ -85,19 +87,23 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
String msg = GitMessages.NoRelevantSCMchange(gitDataBranch != null ? gitDataBranch.getName() : "null");
logger.log(Level.WARNING, msg);
logger.exiting("AccumulatedCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: 26b6ce59c6edbad7afa29f96febc6fd7
throw new NothingToDoException(msg);
throw new NothingToDoException(msg);
}

listener.getLogger().println( String.format(LOG_PREFIX + "Preparing to merge changes in commit %s to integration branch %s", commit, gitbridge.getBranch() ) );
listener.getLogger().println(String.format(LOG_PREFIX + "Preparing to merge changes in commit %s to integration branch %s", commit, gitbridge.getBranch()));
try {
// FIXME I don't like this call back design, where we collect data for commit message based on a series of commits
// 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.
// FIXME I don't like this call back design, where we collect data
// for commit message based on a series of commits 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");

} catch (Exception ex) {
logger.log(Level.SEVERE, "Exception while merging, logging exception", ex);
logger.exiting("AccumulatedCommitStrategy ", "integrate-mergeFailure"); // Generated code DONT TOUCH! Bookmark: 26b6ce59c6edbad7afa29f96febc6fd7
@@ -48,7 +48,8 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener

ByteArrayOutputStream out = new ByteArrayOutputStream();

//TODO: How can you add more than 1 action, MultiSCM plugin with two seperate gits?
//TODO: How can you add more than 1 action, MultiSCM plugin with two
// seperate gits?
BuildData gitBuildData = gitbridge.checkAndDetermineRelevantBuildData(build.getActions(BuildData.class));

Branch gitDataBranch = gitBuildData.lastBuild.revision.getBranches().iterator().next();
@@ -57,33 +58,33 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
String integrationSHA = "Not specified";
try {
logger.fine("Getting current integration SHA");
integrationSHA = (String)build.getAction(PretestedIntegrationAction.class).getCurrentIntegrationTip().getId();
integrationSHA = (String) build.getAction(PretestedIntegrationAction.class).getCurrentIntegrationTip().getId();
logger.fine("Found integration SHA");
} catch (Exception ex) {
logger.log(Level.SEVERE, "Integrate() error, integration SHA not found", ex);
}

listener.getLogger().println( String.format(LOG_PREFIX + "Preparing to merge changes in commit %s to integration branch %s(%s)", gitDataBranch.getSHA1String(), bridge.getBranch(), integrationSHA) );
listener.getLogger().println(String.format(LOG_PREFIX + "Preparing to merge changes in commit %s to integration branch %s(%s)", gitDataBranch.getSHA1String(), bridge.getBranch(), integrationSHA));
boolean found = false;
try {
logger.fine("Resolving and getting git client from workspace:");
client = Git.with(listener, build.getEnvironment(listener)).in(gitbridge.resolveWorkspace(build, listener)).getClient();

logger.fine("Finding remote branches:");
for(Branch b : client.getRemoteBranches()) {
for (Branch b : client.getRemoteBranches()) {
logger.fine(String.format("Found remote branch %s", b.getName()));
if(b.getName().equals(gitDataBranch.getName())) {
if (b.getName().equals(gitDataBranch.getName())) {
found = true;
break;
}
}
} catch (Exception ex) {
logger.log(Level.SEVERE, "GitClient error", ex);
logger.exiting("SquashCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: c9b422ba65a6a142f9cc7f27faeea6e9
throw new IntegationFailedExeception("Unspecified GitClient error", ex);
throw new IntegationFailedExeception("Unspecified GitClient error", ex);
}

if(!found) {
if (!found) {
logger.fine("Found no remote branches.");
try {
logger.fine("Setting build description 'Nothing to do':");
@@ -95,10 +96,10 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
String msg = GitMessages.NoRelevantSCMchange(gitDataBranch != null ? gitDataBranch.getName() : "null");
logger.log(Level.WARNING, msg);
logger.exiting("SquashCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: c9b422ba65a6a142f9cc7f27faeea6e9
throw new NothingToDoException(msg);
throw new NothingToDoException(msg);
}

listener.getLogger().println( String.format(LOG_PREFIX + "Preparing to merge changes from branch %s", gitbridge.getBranch() ) );
listener.getLogger().println(String.format(LOG_PREFIX + "Preparing to merge changes from branch %s", gitbridge.getBranch()));
try {
logger.fine("Collecting and gathering commit message for debug out put after commit:");
String commitMessage = client.withRepository(new FindCommitMessageCallback(listener, gitDataBranch.getSHA1()));
@@ -111,9 +112,9 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
exitCodeCommit = gitbridge.git(build, launcher, listener, out, "commit", "--no-edit");
logger.fine("Commit of squashed merge done.");

listener.getLogger().println( String.format(LOG_PREFIX + "Commit message:%n%s", commitMessage));
} catch (Exception ex) {
/*Handled below */
listener.getLogger().println(String.format(LOG_PREFIX + "Commit message:%n%s", commitMessage));
} catch (Exception ex) {
/*Handled below */
logger.log(Level.SEVERE, "Exception while merging, logging exception", ex);
}

@@ -124,7 +125,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
listener.getLogger().println(LOG_PREFIX + "Failed to merge changes.");
listener.getLogger().println(String.format(LOG_PREFIX + "Git command failed with exit code '%d' and error message:", exitCode));
listener.getLogger().println(LOG_PREFIX + out.toString());

try {
logger.fine("Setting build description 'Merge conflict':");
build.setDescription(String.format("Merge conflict"));
@@ -136,7 +137,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
// throw new IntegationFailedExeception(ex);
}
logger.exiting("SquashCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: c9b422ba65a6a142f9cc7f27faeea6e9
throw new IntegationFailedExeception();
throw new IntegationFailedExeception();
}

if (exitCodeCommit != 0 && exitCodeCommit != -999 ) {
@@ -148,7 +149,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
listener.getLogger().println(LOG_PREFIX + out.toString());

try {
if(out.toString().contains("nothing to commit")) {
if (out.toString().contains("nothing to commit")) {
logger.fine("Git says nothing to commit.");
logger.fine("Setting build description 'Nothing to do':");
build.setDescription(String.format("Nothing to do"));
@@ -166,13 +167,13 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
//throw new IntegationFailedExeception(ex);
}

if(out.toString().contains("nothing to commit")) {
if (out.toString().contains("nothing to commit")) {
logger.exiting("SquashCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: c9b422ba65a6a142f9cc7f27faeea6e9
throw new NothingToDoException();
throw new NothingToDoException();
}

logger.exiting("SquashCommitStrategy", "integrate");// Generated code DONT TOUCH! Bookmark: c9b422ba65a6a142f9cc7f27faeea6e9
throw new IntegationFailedExeception("Could not commit merges. Git output: " + out.toString());
throw new IntegationFailedExeception("Could not commit merges. Git output: " + out.toString());
}
}

0 comments on commit bba9930

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