Skip to content

Commit

Permalink
Merge pull request #78 from daniel-beck/JENKINS-22778
Browse files Browse the repository at this point in the history
[FIXED JENKINS-22778] Revert JENKINS-18574 related changes
  • Loading branch information
kutzi committed May 1, 2014
2 parents a923c50 + cdbb905 commit 929864e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 129 deletions.
38 changes: 2 additions & 36 deletions src/main/java/hudson/scm/DirAwareSVNXMLLogHandler.java
Expand Up @@ -11,11 +11,8 @@
*/
package hudson.scm;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;

import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNErrorCode;
Expand Down Expand Up @@ -47,11 +44,7 @@ public class DirAwareSVNXMLLogHandler extends SVNXMLLogHandler implements ISVNLo

private SVNLogFilter filter = new NullSVNLogFilter();

/** Relative path to repository root */
private String relativePath;
private String relativeUrl;

public DirAwareSVNXMLLogHandler(ContentHandler contentHandler, SVNLogFilter filter) {
public DirAwareSVNXMLLogHandler(ContentHandler contentHandler, SVNLogFilter filter) {
super(contentHandler);
this.filter = filter;
}
Expand Down Expand Up @@ -81,23 +74,6 @@ public void setOmitLogMessage(boolean omitLogMessage) {
* @throws SVNException
*/
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {

if (logEntry.getChangedPaths() != null && relativePath != null) {
// convert external path reference to local relative path
Map<String, SVNLogEntryPath> changedPaths = new HashMap<String, SVNLogEntryPath>();
for (SVNLogEntryPath entry : logEntry.getChangedPaths().values()) {
String localPath = entry.getPath().substring(1); // path in svn log start with a '/'
if(localPath.startsWith(relativeUrl))
{
localPath = relativePath + localPath.substring(relativeUrl.length());
}
// can't use entry.setPath(localPath) as FSPathChange duplicate myPath attribute then setPath().getPath() don't return same value
changedPaths.put(localPath, new SVNLogEntryPath(localPath, entry.getType(), entry.getCopyPath(), entry.getCopyRevision()));
}
logEntry.getChangedPaths().clear();
logEntry.getChangedPaths().putAll(changedPaths);
}

try {
if (filter == null || !filter.hasExclusionRule() || filter.isIncluded(logEntry)) {
sendToHandler(logEntry);
Expand Down Expand Up @@ -171,17 +147,7 @@ protected void sendToHandler(SVNLogEntry logEntry) throws SAXException {
closeTag(LOGENTRY_TAG);
}
}

public void setRelativePath(String relativePath) {
this.relativePath = relativePath;
}

public void setRelativeUrl(String relativeUrl) {
this.relativeUrl = relativeUrl.startsWith("/") ? relativeUrl.substring(1) : relativeUrl;
}


private class MergeFrame {
private class MergeFrame {
private long myNumberOfChildrenRemaining;
}

Expand Down
33 changes: 9 additions & 24 deletions src/main/java/hudson/scm/SubversionChangeLogBuilder.java
Expand Up @@ -53,7 +53,6 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.File;
import java.io.Serializable;
import java.util.Map;
import java.util.Collection;

Expand Down Expand Up @@ -125,11 +124,9 @@ public boolean run(Collection<SubversionSCM.External> externals, Result changeLo
final SVNClientManager manager = SubversionSCM.createClientManager(authProvider).getCore();
try {
SVNLogClient svnlc = manager.getLogClient();
for (SubversionSCM.External ext : externals) {
ExternalPath e = getUrlForPath(build.getWorkspace().child(ext.path), authProvider);
logHandler.setRelativePath( ext.path.startsWith("./") ? ext.path.substring(2) : ext.path );
logHandler.setRelativeUrl(e.path);
changelogFileCreated |= buildModule(e.url, svnlc, logHandler);
for(SubversionSCM.External ext : externals) {
changelogFileCreated |= buildModule(
getUrlForPath(build.getWorkspace().child(ext.path), authProvider), svnlc, logHandler);
}
} finally {
manager.dispose();
Expand All @@ -142,7 +139,7 @@ public boolean run(Collection<SubversionSCM.External> externals, Result changeLo
return changelogFileCreated;
}

private ExternalPath getUrlForPath(FilePath path, ISVNAuthenticationProvider authProvider) throws IOException, InterruptedException {
private String getUrlForPath(FilePath path, ISVNAuthenticationProvider authProvider) throws IOException, InterruptedException {
return path.act(new GetUrlForPath(authProvider));
}

Expand Down Expand Up @@ -227,24 +224,22 @@ private static TransformerHandler createTransformerHandler() {
DUMMY_LOCATOR.setColumnNumber(-1);
}

private static class GetUrlForPath implements FileCallable<ExternalPath> {
private static class GetUrlForPath implements FileCallable<String> {
private final ISVNAuthenticationProvider authProvider;

public GetUrlForPath(ISVNAuthenticationProvider authProvider) {
this.authProvider = authProvider;
}

public ExternalPath invoke(File p, VirtualChannel channel) throws IOException {
public String invoke(File p, VirtualChannel channel) throws IOException {
final SvnClientManager manager = SubversionSCM.createClientManager(authProvider);
try {
final SVNWCClient svnwc = manager.getWCClient();

SVNInfo info;
try {
SVNInfo info = svnwc.doInfo(p, SVNRevision.WORKING);

String url = info.getURL().toDecodedString();
String relative = url.substring(info.getRepositoryRootURL().toDecodedString().length());
return new ExternalPath(relative, url);
info = svnwc.doInfo(p, SVNRevision.WORKING);
return info.getURL().toDecodedString();
} catch (SVNException e) {
e.printStackTrace();
return null;
Expand All @@ -256,14 +251,4 @@ public ExternalPath invoke(File p, VirtualChannel channel) throws IOException {

private static final long serialVersionUID = 1L;
}

private static class ExternalPath implements Serializable {
private ExternalPath(String path, String url) {
this.path = path;
this.url = url;
}
public final String url; // item repository location
public final String path; // item path relative to repository root
private static final long serialVersionUID = 1L;
}
}
69 changes: 0 additions & 69 deletions src/test/java/hudson/scm/SubversionSCMTest.java
Expand Up @@ -33,7 +33,6 @@
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;

import hudson.FilePath;
import hudson.Launcher;
import hudson.Proc;
Expand Down Expand Up @@ -82,8 +81,6 @@

import org.dom4j.Document;
import org.dom4j.io.DOMReader;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.Email;
Expand Down Expand Up @@ -122,7 +119,6 @@
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import hudson.EnvVars;
import hudson.model.EnvironmentContributor;

Expand Down Expand Up @@ -1089,71 +1085,6 @@ public void testMasterPolling() throws Exception {
assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges());
}

public void testExternalsAffectedPaths() throws Exception {
// repository set as svn:externals
File ext = new CopyExisting(getClass().getResource("two-revisions.zip")).allocate();

// create and commit a file foo/README.txt in ext
FreeStyleProject forCommit = createFreeStyleProject();
SubversionSCM scmExt = new SubversionSCM("file://" + ext.toURI().toURL().getPath());
forCommit.setScm(scmExt);
forCommit.setAssignedLabel(hudson.getSelfLabel());
// Build once to get a working copy in job workspace
FreeStyleBuild b = assertBuildStatusSuccess(forCommit.scheduleBuild2(0).get());
String folderName = "foo1234567890foo1234567890"; //long path to check substring action
FilePath foo = b.getWorkspace().child(folderName);
foo.mkdirs();
FilePath newFile = foo.child("README.txt");
newFile.touch(System.currentTimeMillis());
SvnClientManager svnm = SubversionSCM.createClientManager(forCommit);
svnm.getWCClient().doAdd(new File(foo.getRemote()),false,false,false, SVNDepth.INFINITY, false,false);
SVNCommitClient cc = svnm.getCommitClient();
cc.doCommit(new File[]{new File(foo.getRemote()), new File(newFile.getRemote())},false,"added",null,null,false,false,SVNDepth.INFINITY);


// repository used by job
File repo = new CopyExisting(getClass().getResource("two-revisions.zip")).allocate();
SubversionSCM scm = new SubversionSCM("file://" + repo.toURI().toURL().getPath());
FreeStyleProject p = createFreeStyleProject();
scm.setPollFromMaster(true);
p.setScm(scm);

// setup foo directory in ext as svn:externals on "ext",
FreeStyleBuild bb = assertBuildStatusSuccess(p.scheduleBuild2(0).get());
String externalURL = "file://" + ext.toURI().toURL().getPath();
SVNPropertyValue externals = SVNPropertyValue.create("ext " + externalURL + "/" + folderName);
SvnClientManager svnm2 = SubversionSCM.createClientManager(forCommit);
svnm2.getWCClient().doSetProperty(new File(bb.getWorkspace().getRemote()), "svn:externals", externals, true, SVNDepth.FILES, null, null);
svnm2.getCommitClient().doCommit(new File[]{new File(bb.getWorkspace().getRemote())},false,"externals",null,null,false,false,SVNDepth.INFINITY);

// foo/README.tx in ext is now => /ext/README.txt in repo

assertBuildStatusSuccess(p.scheduleBuild2(2).get());
assertFalse(p.poll(StreamTaskListener.fromStdout()).hasChanges());

// create a commit in ext
newFile = foo.child("something.txt");
newFile.touch(System.currentTimeMillis());
svnm.getWCClient().doAdd(new File(newFile.getRemote()), false, false, false, SVNDepth.INFINITY, false, false);
// create another folder with content outside the ext folder
FilePath anotherDir = foo.getParent().child("anotherDir");
anotherDir.mkdirs();
FilePath anotherFile = anotherDir.child("a.txt");
anotherFile.touch(System.currentTimeMillis());
svnm.getWCClient().doAdd(new File(anotherDir.getRemote()),false,false,false, SVNDepth.INFINITY, false,false);

cc.doCommit(new File[]{new File(newFile.getRemote()), new File(anotherDir.getRemote())},false,"added",null,null,false,false,SVNDepth.INFINITY);

FreeStyleBuild build = p.scheduleBuild2(2).get();
assertBuildStatusSuccess(build);
Collection<String> paths = new ArrayList<String>();
for (ChangeLogSet.Entry e : build.getChangeSet()) {
for (String path : e.getAffectedPaths()) {
paths.add(path);
}
}
Assert.assertThat(paths, Matchers.containsInAnyOrder("ext/something.txt", "anotherDir", "anotherDir/a.txt"));
}

public void testCompareSVNAuthentications() throws Exception {
assertFalse(compareSVNAuthentications(new SVNUserNameAuthentication("me",true),new SVNSSHAuthentication("me","me",22,true)));
Expand Down

0 comments on commit 929864e

Please sign in to comment.