Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'JENKINS-30891'
  • Loading branch information
Thierry Lacour committed Oct 30, 2015
2 parents a591ac5 + 9f1778a commit 3d221bd
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.580</version>
</parent>

<url>http://wiki.jenkins-ci.org/display/JENKINS/Pretested+Integration+Plugin</url>
Expand Down Expand Up @@ -456,7 +456,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.2.0</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -31,7 +31,6 @@ public abstract class AbstractSCMBridge implements Describable<AbstractSCMBridge

final static String LOG_PREFIX = "[PREINT] ";

@DataBoundConstructor
public AbstractSCMBridge(IntegrationStrategy integrationStrategy) {
this.integrationStrategy = integrationStrategy;
}
Expand Down
Expand Up @@ -18,16 +18,12 @@
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException;
import org.kohsuke.stapler.DataBoundConstructor;

public abstract class IntegrationStrategy implements Describable<IntegrationStrategy>, ExtensionPoint {
private final static Logger logger = Logger.getLogger(IntegrationStrategy.class.getName());

public abstract void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener, AbstractSCMBridge bridge) throws IntegationFailedExeception, NothingToDoException, UnsupportedConfigurationException;

@DataBoundConstructor
public IntegrationStrategy() { }

public Descriptor<IntegrationStrategy> getDescriptor() {
logger.entering("IntegrationStrategy", "getDescriptor");// Generated code DONT TOUCH! Bookmark: 24cc4de9955cf69f2428d18f247547c0
logger.exiting("IntegrationStrategy", "getDescriptor");// Generated code DONT TOUCH! Bookmark: ecd722247263f21a17188169745720f1´
Expand Down
Expand Up @@ -30,7 +30,7 @@
*
* @author Mads
*/
public class AccumulatedCommitStrategy extends IntegrationStrategy {
public class AccumulatedCommitStrategy extends GitIntegrationStrategy {

private static final String B_NAME = "Accumulated commit";
private static final Logger logger = Logger.getLogger(AccumulatedCommitStrategy.class.getName());
Expand All @@ -45,11 +45,10 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
logger.entering("AccumulatedCommitStrategy", "integrate", new Object[] { build, listener, bridge, launcher });// Generated code DONT TOUCH! Bookmark: ee74dbf7df6fa51582ccc15f5fee72da
int exitCodeMerge = unLikelyExitCode;
int exitCodeCommit = unLikelyExitCode;

GitClient client;

GitBridge gitbridge = (GitBridge)bridge;

if(tryFastForward(build, launcher, listener, gitbridge)) return;

ByteArrayOutputStream out = new ByteArrayOutputStream();
BuildData gitBuildData = gitbridge.checkAndDetermineRelevantBuildData(build, listener);
String commit = gitBuildData.lastBuild.revision.getSha1String();
Expand All @@ -60,7 +59,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
Branch gitDataBranch = gitBuildData.lastBuild.revision.getBranches().iterator().next();
boolean found = false;


GitClient client;
try {
logger.log(Level.INFO, String.format("Preparing to merge changes in commit %s on development branch %s to integration branch %s", commit, gitDataBranch.getName(), gitbridge.getExpandedBranch(build.getEnvironment(listener))));
listener.getLogger().println(String.format(LOG_PREFIX + "Preparing to merge changes in commit %s on development branch %s to integration branch %s", commit, gitDataBranch.getName(), gitbridge.getExpandedBranch(build.getEnvironment(listener))));
Expand Down
@@ -0,0 +1,63 @@
package org.jenkinsci.plugins.pretestedintegration.scm.git;

import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.plugins.git.GitException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jgit.lib.ObjectId;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.MergeCommand;
import org.jenkinsci.plugins.pretestedintegration.AbstractSCMBridge;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy;
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegationFailedExeception;
import org.jenkinsci.plugins.pretestedintegration.exceptions.NothingToDoException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException;

public class GitIntegrationStrategy extends IntegrationStrategy {

private static final Logger logger = Logger.getLogger(GitIntegrationStrategy.class.getName());
private static final String LOG_PREFIX = "[PREINT] ";

@Override
public void integrate(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, AbstractSCMBridge bridge) throws IntegationFailedExeception, NothingToDoException, UnsupportedConfigurationException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

public boolean tryFastForward(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, GitBridge bridge) throws IntegationFailedExeception{
logger.log(Level.INFO, String.format(LOG_PREFIX + "Entering tryFastForward"));

//Get the commit count
int commitCount;
try {
commitCount = bridge.countCommits(build, listener);
logger.log(Level.INFO, String.format(LOG_PREFIX + "Branch commit count: " + commitCount));
} catch (IOException | InterruptedException ex) {
throw new IntegationFailedExeception("Failed to count commits.", ex);
}

//Only fast forward if it's a single commit
if (commitCount != 1) {
listener.getLogger().println(String.format(LOG_PREFIX + "Not attempting fast forward. Exiting tryFastForward."));
return false;
}

//FF merge the commit
try {
logger.log(Level.INFO, String.format(LOG_PREFIX + "Attempting rebase."));
GitClient client = Git.with(listener, build.getEnvironment(listener)).in(bridge.resolveWorkspace(build, listener)).getClient();
ObjectId commitId = bridge.getCommitId(build, listener);
client.merge().setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.FF_ONLY).setRevisionToMerge(commitId).execute();
listener.getLogger().println(String.format(LOG_PREFIX + "FF merge successful."));
logger.log(Level.INFO, LOG_PREFIX + " Exiting tryFastForward.");
return true;
} catch (GitException | IOException | InterruptedException ex) {
listener.getLogger().println(String.format(LOG_PREFIX + "FF merge failed."));
logger.log(Level.INFO, LOG_PREFIX + " Exiting tryFastForward.");
return false;
}
}
}
Expand Up @@ -25,20 +25,20 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jgit.lib.ObjectId;
import org.jenkinsci.plugins.gitclient.MergeCommand;
import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException;

/**
*
* @author Mads
*/
public class SquashCommitStrategy extends IntegrationStrategy {
public class SquashCommitStrategy extends GitIntegrationStrategy {

private static final String B_NAME = "Squashed commit";
private static final Logger logger = Logger.getLogger(SquashCommitStrategy.class.getName());
private static final String LOG_PREFIX = "[PREINT] ";
private static final int unLikelyExitCode = -999; // An very unlikely exit code, that we use as default


@DataBoundConstructor
public SquashCommitStrategy() { }

Expand All @@ -49,6 +49,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
int exitCodeCommit = unLikelyExitCode;
GitBridge gitbridge = (GitBridge) bridge;

if(tryFastForward(build, launcher, listener, gitbridge)) return;
if(tryRebase(build, launcher, listener, gitbridge)) return;

ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand All @@ -58,17 +59,8 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
BuildData gitBuildData = gitbridge.checkAndDetermineRelevantBuildData(build, listener);

Branch gitDataBranch = gitBuildData.lastBuild.revision.getBranches().iterator().next();

GitClient client;

// String integrationSHA = "Not specified";
// try {
// logger.fine("Getting current integration SHA");
// 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);
// }

boolean found = false;
try {
logger.log(Level.INFO, String.format("Preparing to merge changes in commit %s on development branch %s to integration branch %s", gitDataBranch.getSHA1String(), gitDataBranch.getName(), gitbridge.getExpandedBranch(build.getEnvironment(listener))));
Expand Down Expand Up @@ -266,7 +258,7 @@ private boolean tryRebase(AbstractBuild<?, ?> build, Launcher launcher, BuildLis
ObjectId rebasedCommit = client.revParse("HEAD");
logger.log(Level.INFO, String.format(LOG_PREFIX + "Rebase successful. Attempting fast-forward merge."));
client.checkout().ref(expandedBranch).execute();
client.merge().setRevisionToMerge(rebasedCommit).execute();
client.merge().setRevisionToMerge(rebasedCommit).setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.FF_ONLY).execute();
logger.log(Level.INFO, String.format(LOG_PREFIX + "Fast-forward merge successful. Exiting tryRebase."));
return true;
} catch (GitException | IOException | InterruptedException ex) {
Expand Down
Expand Up @@ -4,26 +4,18 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.util.RunList;

import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;


import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.File;

import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import org.eclipse.jgit.api.CreateBranchCommand;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.lib.Ref;
import static org.jenkinsci.plugins.pretestedintegration.integration.scm.git.TestUtilsFactory.STRATEGY_TYPE;
import org.junit.Ignore;

/**
* <h3>Set of tests that test that we react correctly to merge conflicts</h3>
Expand Down
Expand Up @@ -4,14 +4,11 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.util.RunList;
import java.io.File;
import java.util.Iterator;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNotNull;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
Expand Down Expand Up @@ -460,6 +457,7 @@ public void commitMessagesWithDoubleQuotesSingleQuotesMadeWindowsSquashed() thro
*
* @throws Exception
*/
@Ignore("Wait for Bue's input on changing double quotes to single quotes during FF merges.")
@Test
public void commitMessagesWithDoubleQuotesSingleQuotesMadeWindowsAccumulated_customerSuppliedRepo() throws Exception {

Expand Down

0 comments on commit 3d221bd

Please sign in to comment.