### Eclipse Workspace Patch 1.0 #P subversion Index: src/main/java/hudson/scm/SubversionChangeLogSet.java =================================================================== --- src/main/java/hudson/scm/SubversionChangeLogSet.java (revision 39626) +++ src/main/java/hudson/scm/SubversionChangeLogSet.java (working copy) @@ -23,6 +23,7 @@ */ package hudson.scm; +import hudson.Util; import hudson.model.AbstractBuild; import hudson.model.User; import hudson.scm.SubversionChangeLogSet.LogEntry; @@ -253,6 +254,17 @@ public Collection getAffectedFiles() { return paths; } + + void finish() { + Collections.sort(paths, new Comparator() { + @Override + public int compare(Path o1, Path o2) { + String path1 = Util.fixNull(o1.getValue()); + String path2 = Util.fixNull(o2.getValue()); + return path1.compareTo(path2); + } + }); + } } /** Index: src/test/resources/hudson/scm/changelog_unsorted.xml =================================================================== --- src/test/resources/hudson/scm/changelog_unsorted.xml (revision 0) +++ src/test/resources/hudson/scm/changelog_unsorted.xml (revision 0) @@ -0,0 +1,19 @@ + + + + user + 2011-07-14T15:25:09.982854Z + + /module-a/trunk/test-impl/src/main/java/org/test/Test1.java + + /integration-tests/trunk/src/test/java/org/test/testing/impl/TestService.java + + /module-b/trunk/src/main/java/org/test/a/Test2.java + + /module-a/trunk/test-impl/src/main/java/org/test/ITest.java + + + A commit + message + + \ No newline at end of file Index: src/main/java/hudson/scm/SubversionChangeLogParser.java =================================================================== --- src/main/java/hudson/scm/SubversionChangeLogParser.java (revision 39626) +++ src/main/java/hudson/scm/SubversionChangeLogParser.java (working copy) @@ -44,7 +44,7 @@ */ public class SubversionChangeLogParser extends ChangeLogParser { public SubversionChangeLogSet parse(AbstractBuild build, File changelogFile) throws IOException, SAXException { - // http://svn.collab.net/repos/svn/trunk/subversion/svn/schema/ + // http://svn.apache.org/repos/asf/subversion/trunk/subversion/svn/schema/log.rnc Digester digester = new Digester2(); ArrayList r = new ArrayList(); @@ -70,6 +70,9 @@ throw new IOException2("Failed to parse "+changelogFile,e); } + for (LogEntry e : r) { + e.finish(); + } return new SubversionChangeLogSet(build,r); } Index: src/test/java/hudson/scm/SubversionChangeLogParserTest.java =================================================================== --- src/test/java/hudson/scm/SubversionChangeLogParserTest.java (revision 0) +++ src/test/java/hudson/scm/SubversionChangeLogParserTest.java (revision 0) @@ -0,0 +1,52 @@ +package hudson.scm; + +import hudson.scm.SubversionChangeLogSet.LogEntry; +import hudson.scm.SubversionChangeLogSet.Path; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.junit.Assert; +import org.junit.Test; +import org.jvnet.hudson.test.Bug; +import org.xml.sax.SAXException; + +/** + * Tests for {@link SubversionChangeLogParser}. + * + * @author kutzi + */ +public class SubversionChangeLogParserTest extends AbstractSubversionTest { + + private File changelogFile; + private SubversionChangeLogSet changeLogSet; + + @Test + @Bug(10324) + public void testPathsSortedAlphabetically() throws URISyntaxException, IOException, SAXException { + givenAChangelogFileWithUnsortedPaths(); + whenChangelogFileIsParsed(); + thenAffectedPathsMustBeSortedAlphabetically(); + } + + private void givenAChangelogFileWithUnsortedPaths() throws URISyntaxException { + URL url = SubversionChangeLogParserTest.class.getResource("changelog_unsorted.xml"); + this.changelogFile = new File(url.toURI().getSchemeSpecificPart()); + } + + private void whenChangelogFileIsParsed() throws IOException, SAXException { + this.changeLogSet = new SubversionChangeLogParser().parse(null, this.changelogFile); + } + + private void thenAffectedPathsMustBeSortedAlphabetically() { + for(LogEntry entry : changeLogSet.getLogs()) { + String previous = ""; + for(Path path : entry.getPaths()) { + Assert.assertTrue(previous.compareTo(path.getPath()) <= 0); + previous = path.getPath(); + } + } + } +}