Skip to content

Commit

Permalink
Merge pull request #103 from christ66/JENKINS-18935
Browse files Browse the repository at this point in the history
[JENKINS-18935] Add support for subversion 1.8 format
  • Loading branch information
christ66 committed Nov 13, 2014
2 parents 38af370 + bc601a8 commit 4a88de9
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -91,7 +91,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.7.10</version>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci</groupId>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/hudson/scm/SubversionWorkspaceSelector.java
Expand Up @@ -30,6 +30,7 @@
import org.tmatesoft.svn.core.internal.wc.admin.ISVNAdminAreaFactorySelector;
import org.tmatesoft.svn.core.internal.wc.admin.SVNAdminArea14;
import org.tmatesoft.svn.core.internal.wc.admin.SVNAdminAreaFactory;
import org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb;
import org.tmatesoft.svn.core.internal.wc2.SvnWcGeneration;

import java.io.File;
Expand Down Expand Up @@ -125,8 +126,10 @@ public Integer call() {

/**
* Constant for {@link #workspaceFormat} that indicates we opt for 1.7 working copy.
*
* @deprecated Use {@link org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb#WC_FORMAT_17}
*/
public static final int WC_FORMAT_17 = 100;
public static final int WC_FORMAT_17 = ISVNWCDb.WC_FORMAT_17;

private static final Logger LOGGER = Logger.getLogger(SubversionWorkspaceSelector.class.getName());
}
4 changes: 3 additions & 1 deletion src/main/java/hudson/scm/SvnClientManager.java
Expand Up @@ -2,6 +2,7 @@

import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb;
import org.tmatesoft.svn.core.internal.wc2.SvnWcGeneration;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.wc.SVNBasicClient;
Expand All @@ -12,6 +13,7 @@
import org.tmatesoft.svn.core.wc.SVNStatusClient;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc2.SvnSetWCDbVersion;

/**
* {@link SVNClientManager} makes it rather error prone to specify the proper expected version
Expand All @@ -27,7 +29,7 @@ public class SvnClientManager {
public SvnClientManager(SVNClientManager core) {
this.core = core;
SubversionWorkspaceSelector.syncWorkspaceFormatFromMaster();
wcgen = SubversionWorkspaceSelector.workspaceFormat>=SubversionWorkspaceSelector.WC_FORMAT_17 ? SvnWcGeneration.V17 : SvnWcGeneration.V16;
wcgen = SubversionWorkspaceSelector.workspaceFormat>= ISVNWCDb.WC_FORMAT_18 ? SvnWcGeneration.V17 : SvnWcGeneration.V16;
}

public SVNClientManager getCore() {
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/hudson/scm/subversion/CheckoutUpdater.java
Expand Up @@ -29,6 +29,7 @@
import hudson.Extension;
import hudson.Util;
import hudson.scm.SubversionSCM.External;
import hudson.scm.SubversionWorkspaceSelector;
import hudson.util.IOException2;
import hudson.util.StreamCopyThread;

Expand All @@ -37,8 +38,12 @@
import org.tmatesoft.svn.core.SVNCancelException;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.internal.util.DefaultSVNDebugLogger;
import org.tmatesoft.svn.core.internal.wc2.compat.SvnCodec;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc2.SvnCheckout;
import org.tmatesoft.svn.core.wc2.SvnTarget;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -94,9 +99,20 @@ public List<External> perform() throws IOException, InterruptedException {
svnuc.setEventHandler(eventHandler);
svnuc.setExternalsHandler(eventHandler);
svnuc.setIgnoreExternals(location.isIgnoreExternalsOption());

SVNDepth svnDepth = getSvnDepth(location.getDepthOption());
svnuc.doCheckout(location.getSVNURL(), local.getCanonicalFile(), SVNRevision.HEAD, r, svnDepth, true);
SvnCheckout checkout = svnuc.getOperationsFactory().createCheckout();
checkout.setSource(SvnTarget.fromURL(location.getSVNURL(), SVNRevision.HEAD));
checkout.setSingleTarget(SvnTarget.fromFile(local.getCanonicalFile()));
checkout.setDepth(svnDepth);
checkout.setRevision(r);
checkout.setAllowUnversionedObstructions(true);
checkout.setIgnoreExternals(location.isIgnoreExternalsOption());
checkout.setExternalsHandler(SvnCodec.externalsHandler(svnuc.getExternalsHandler()));

// Workaround for SVNKIT-430 is to set the working copy format when
// a checkout is performed.
checkout.setTargetWorkingCopyFormat(SubversionWorkspaceSelector.workspaceFormat);
checkout.run();
} catch (SVNCancelException e) {
if (isAuthenticationFailedError(e)) {
e.printStackTrace(listener.error("Failed to check out " + location.remote));
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/hudson/scm/SubversionSCM/global.jelly
Expand Up @@ -30,7 +30,8 @@ THE SOFTWARE.
<f:option value="8" selected="${descriptor.workspaceFormat==8}" >1.4</f:option>
<f:option value="9" selected="${descriptor.workspaceFormat==9}" >1.5</f:option>
<f:option value="10" selected="${descriptor.workspaceFormat==10}" >1.6 (svn:externals to file)</f:option>
<f:option value="100" selected="${descriptor.workspaceFormat==100}">1.7</f:option>
<f:option value="29" selected="${descriptor.workspaceFormat==100||descriptor.workspaceFormat==29}">1.7</f:option>
<f:option value="31" selected="${descriptor.workspaceFormat==31}" >1.8</f:option>
</select>
</f:entry>
<f:entry title="${%Exclusion revprop name}" help="/descriptor/hudson.scm.SubversionSCM/help/excludedRevprop">
Expand Down
91 changes: 91 additions & 0 deletions src/test/java/hudson/scm/SVNWorkingCopyTest.java
@@ -0,0 +1,91 @@
/*
* The MIT License
*
* Copyright (c) 2014 schristou88
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.scm;

import hudson.model.AbstractProject;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.queue.QueueTaskFuture;
import hudson.scm.subversion.WorkspaceUpdater;
import hudson.scm.subversion.WorkspaceUpdaterDescriptor;
import org.tmatesoft.svn.core.internal.wc.SVNStatusUtil;
import org.tmatesoft.svn.core.internal.wc.admin.*;
import org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNStatus;
import org.tmatesoft.svn.core.wc.SVNStatusClient;
import org.tmatesoft.svn.core.wc2.SvnGetStatus;

import java.io.File;

/**
* @author schristou88
*/
public class SVNWorkingCopyTest extends AbstractSubversionTest {
public void testCheckoutWorkingCopyFormat14() throws Exception {
checkoutAndVerifyWithFormat(SVNAdminArea14.WC_FORMAT);
}

public void testCheckoutWorkingCopyFormat15() throws Exception {
checkoutAndVerifyWithFormat(SVNAdminArea15.WC_FORMAT);
}

public void testCheckoutWorkingCopyFormat16() throws Exception {
checkoutAndVerifyWithFormat(SVNAdminArea16.WC_FORMAT);
}

/**
* SVN 1.7 in jenkins uses a WC format of {@link SubversionWorkspaceSelector#WC_FORMAT_17}.
* However we still need to check against the actual working copy format of {@link ISVNWCDb#WC_FORMAT_17}
*/
public void testCheckoutWorkingCopyFormat17() throws Exception {
int checkoutFormat = checkoutWithFormat(SubversionWorkspaceSelector.WC_FORMAT_17);
assertEquals(ISVNWCDb.WC_FORMAT_17, checkoutFormat);
}

public void testCheckoutWorkingCopyFormat18() throws Exception {
checkoutAndVerifyWithFormat(ISVNWCDb.WC_FORMAT_18);
}

private void checkoutAndVerifyWithFormat(int format) throws Exception {
assertEquals("Checkout and workspace format do not match", format, checkoutWithFormat(format));
}

private int checkoutWithFormat(int format) throws Exception {
super.configureSvnWorkspaceFormat(format);

FreeStyleProject project = jenkins.createProject(FreeStyleProject.class, "svntest" + format);
SubversionSCM subversionSCM = new SubversionSCM("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant");

project.setScm(subversionSCM);
assertBuildStatusSuccess(project.scheduleBuild2(0));

// Create a status client and get the working copy format.
SVNClientManager testWCVerseion = SVNClientManager.newInstance(null, "testWCVerseion", null);
File path = new File(project.getWorkspace().getRemote());
return testWCVerseion.getStatusClient().doStatus(path,
true).getWorkingCopyFormat();
}
}

0 comments on commit 4a88de9

Please sign in to comment.