Skip to content

Commit

Permalink
[FIXED JENKINS-13790] Use the native SVNKit ISVNExternalsHandler to p…
Browse files Browse the repository at this point in the history
…ick up the svn:externals URLs.
  • Loading branch information
Tom Palmer authored and ndeloof committed Jan 4, 2013
1 parent ee2d28e commit 1e685c2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 57 deletions.
15 changes: 4 additions & 11 deletions src/main/java/hudson/scm/SubversionSCM.java 100644 → 100755
Expand Up @@ -151,7 +151,6 @@
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.internal.wc.SVNExternal;
import org.tmatesoft.svn.core.internal.wc.admin.SVNAdminAreaFactory;
import org.tmatesoft.svn.core.io.SVNCapability;
import org.tmatesoft.svn.core.io.SVNRepository;
Expand Down Expand Up @@ -1093,16 +1092,10 @@ public static final class External implements Serializable {
*/
public final long revision;

/**
* @param modulePath
* The root of the current module that svn was checking out when it hits 'ext'.
* Since we call svnkit multiple times in general case to check out from multiple locations,
* we use this to make the path relative to the entire workspace, not just the particular module.
*/
public External(String modulePath,SVNExternal ext) {
this.path = modulePath+'/'+ext.getPath();
this.url = ext.getResolvedURL().toDecodedString();
this.revision = ext.getRevision().getNumber();
public External(String path, SVNURL url, long revision) {
this.path = path;
this.url = url.toDecodedString();
this.revision = revision;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/hudson/scm/subversion/CheckoutUpdater.java 100644 → 100755
Expand Up @@ -91,8 +91,10 @@ public List<External> perform() throws IOException, InterruptedException {
" to depth " + location.getDepthOption() + " and ignoring externals: " + location.isIgnoreExternalsOption());

File local = new File(ws, location.getLocalDir());
SubversionUpdateEventHandler eventHandler = new SubversionUpdateEventHandler(new PrintStream(pos), externals, local, location.getLocalDir());
svnuc.setEventHandler(eventHandler);
svnuc.setExternalsHandler(eventHandler);
svnuc.setIgnoreExternals(location.isIgnoreExternalsOption());
svnuc.setEventHandler(new SubversionUpdateEventHandler(new PrintStream(pos), externals, local, location.getLocalDir()));

SVNDepth svnDepth = getSvnDepth(location.getDepthOption());
svnuc.doCheckout(location.getSVNURL(), local.getCanonicalFile(), SVNRevision.HEAD, r, svnDepth, true);
Expand Down
94 changes: 50 additions & 44 deletions src/main/java/hudson/scm/subversion/SubversionUpdateEventHandler.java 100644 → 100755
Expand Up @@ -23,22 +23,23 @@
*/
package hudson.scm.subversion;

import hudson.remoting.Which;
import hudson.scm.SubversionEventHandlerImpl;
import hudson.scm.SubversionSCM.External;
import java.util.HashMap;
import java.util.Map;
import org.tmatesoft.svn.core.SVNCancelException;
import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.internal.wc.SVNExternal;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNExternalsHandler;
import org.tmatesoft.svn.core.wc.SVNEvent;
import org.tmatesoft.svn.core.wc.SVNEventAction;
import org.tmatesoft.svn.core.wc.SVNRevision;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.List;

/**
Expand All @@ -47,8 +48,11 @@
*
* This code also records all the referenced external locations.
*/
final class SubversionUpdateEventHandler extends SubversionEventHandlerImpl {

final class SubversionUpdateEventHandler extends SubversionEventHandlerImpl implements ISVNExternalsHandler {
/**
* Staged map of svn:externals details.
*/
private final Map<File, SVNExternalDetails> externalDetails = new HashMap<File, SVNExternalDetails>();
/**
* External urls that are fetched through svn:externals.
* We add to this collection as we find them.
Expand All @@ -65,56 +69,58 @@ public SubversionUpdateEventHandler(PrintStream out, List<External> externals, F
this.modulePath = modulePath;
}

public void handleEvent(SVNEvent event, double progress) throws SVNException {
File file = event.getFile();
String path = null;
if (file != null) {
try {
path = getRelativePath(file);
} catch (IOException e) {
throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, e));
}
path = getLocalPath(path);
}
public SVNRevision[] handleExternal(File externalPath, SVNURL externalURL, SVNRevision externalRevision,
SVNRevision externalPegRevision, String externalsDefinition,
SVNRevision externalsWorkingRevision) {
long revisionNumber = SVNRevision.isValidRevisionNumber(externalPegRevision.getNumber()) ? externalPegRevision.getNumber() : -1;
SVNExternalDetails details = new SVNExternalDetails(externalURL, revisionNumber);

externalDetails.put(externalPath, details);
return new SVNRevision[] {externalRevision, externalPegRevision};
}

/*
* Gets the current action. An action is represented by SVNEventAction.
* In case of an update an action can be determined via comparing
* SVNEvent.getAction() and SVNEventAction.UPDATE_-like constants.
*/
@Override
public void handleEvent(SVNEvent event, double progress) throws SVNException {
SVNEventAction action = event.getAction();
if (action == SVNEventAction.UPDATE_EXTERNAL) {
// for externals definitions
SVNExternal ext = event.getExternalInfo();
if(ext==null) {
// prepare for the situation where the user created their own svnkit
URL jarFile = null;
if (action == SVNEventAction.UPDATE_COMPLETED) {
File file = event.getFile();
SVNExternalDetails details = externalDetails.remove(file);
if (details != null) {
String path;
try {
jarFile = Which.jarURL(SVNEvent.class);
path = getLocalPath(getRelativePath(file));
} catch (IOException e) {
// ignore this failure
throw new SVNException(SVNErrorMessage.create(SVNErrorCode.FS_GENERAL, e));
}
out.println("AssertionError: appears to be using unpatched svnkit at "+ jarFile);
} else {
out.println(Messages.SubversionUpdateEventHandler_FetchExternal(
ext.getResolvedURL(), ext.getRevision().getNumber(), event.getFile()));
//#1539 - an external inside an external needs to have the path appended
externals.add(new External(modulePath + "/" + path.substring(0
,path.length() - ext.getPath().length())
,ext));

out.println(Messages.SubversionUpdateEventHandler_FetchExternal(details, event.getRevision(), file));
externals.add(new External(modulePath + '/' + path, details.getUrl(), details.getRevision()));
}
return;
}
if (action==SVNEventAction.SKIP && event.getExpectedAction()==SVNEventAction.UPDATE_EXTERNAL && event.getNodeKind()== SVNNodeKind.FILE) {
// svn:externals file support requires 1.6 workspace
out.println("svn:externals to a file requires Subversion 1.6 workspace support. Use the system configuration to enable that.");
}

super.handleEvent(event,progress);
super.handleEvent(event, progress);
}

public void checkCancelled() throws SVNCancelException {
if(Thread.interrupted())
throw new SVNCancelException();
}

private static class SVNExternalDetails {
private final SVNURL url;
private final long revision;

private SVNExternalDetails(SVNURL url, long revision) {
this.url = url;
this.revision = revision;
}

public SVNURL getUrl() {
return url;
}

public long getRevision() {
return revision;
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/hudson/scm/subversion/UpdateUpdater.java 100644 → 100755
Expand Up @@ -127,7 +127,9 @@ public List<External> perform() throws IOException, InterruptedException {

try {
File local = new File(ws, location.getLocalDir());
svnuc.setEventHandler(new SubversionUpdateEventHandler(listener.getLogger(), externals, local, location.getLocalDir()));
SubversionUpdateEventHandler eventHandler = new SubversionUpdateEventHandler(listener.getLogger(), externals, local, location.getLocalDir());
svnuc.setEventHandler(eventHandler);
svnuc.setExternalsHandler(eventHandler);

SVNRevision r = getRevision(location);

Expand Down

1 comment on commit 1e685c2

@kutzi
Copy link
Member

@kutzi kutzi commented on 1e685c2 Apr 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.