Skip to content

Commit

Permalink
[FIXED JENKINS-10227] Applied patch provided by grahamparks through G…
Browse files Browse the repository at this point in the history
…itHub
  • Loading branch information
rseguy committed Jan 16, 2012
1 parent 3f188fa commit a7b2cfa
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
@@ -1,8 +1,8 @@
/*
* The MIT License
*
* Copyright (c) 2010-2011, Manufacture Francaise des Pneumatiques Michelin,
* Romain Seguy
* Copyright (c) 2010-2012, Manufacture Francaise des Pneumatiques Michelin,
* Romain Seguy, id:kutzi, id:grahamparks
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -29,10 +29,8 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Comparator;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.regex.Pattern;

import org.tmatesoft.svn.core.ISVNDirEntryHandler;
Expand All @@ -47,7 +45,7 @@
*/
public class SimpleSVNDirEntryHandler implements ISVNDirEntryHandler {

private final SortedMap<Date, String> dirs = new TreeMap<Date, String>(Collections.reverseOrder());
private final List<SVNDirEntry> dirs = new ArrayList<SVNDirEntry>();
private final Pattern filterPattern;

public SimpleSVNDirEntryHandler(String filter) {
Expand All @@ -63,22 +61,38 @@ public List<String> getDirs() {
}

public List<String> getDirs(boolean reverseByDate, boolean reverseByName) {
List<String> sortedDirs = new ArrayList<String>(dirs.values());
if(reverseByDate) {
// dirs are already sorted reversely by date because of the SortedMap
Collections.sort(dirs, new Comparator<SVNDirEntry>() {
public int compare(SVNDirEntry dir1, SVNDirEntry dir2){
return dir2.getDate().compareTo(dir1.getDate());
}
});
} else if(reverseByName) {
Collections.sort(sortedDirs, Collections.reverseOrder());
Collections.sort(dirs, new Comparator<SVNDirEntry>() {
public int compare(SVNDirEntry dir1, SVNDirEntry dir2){
return dir2.getName().compareTo(dir1.getName());
}
});
} else {
Collections.sort(sortedDirs);
Collections.sort(dirs, new Comparator<SVNDirEntry>() {
public int compare(SVNDirEntry dir1, SVNDirEntry dir2){
return dir1.getName().compareTo(dir2.getName());
}
});
}

List<String> sortedDirs = new ArrayList<String>();
for (SVNDirEntry dirEntry : dirs) {
sortedDirs.add(dirEntry.getName());
}

return sortedDirs;
}

@Override
public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
if(filterPattern == null || filterPattern.matcher(dirEntry.getName()).matches()) {
dirs.put(dirEntry.getDate(), Util.removeTrailingSlash(dirEntry.getName()));
dirs.add(dirEntry);
}
}

Expand Down
@@ -1,3 +1,27 @@
/*
* The MIT License
*
* Copyright (c) 2011-2012, id:kutzi, id:grahamparks
*
* 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.listtagsparameter;

import java.text.ParseException;
Expand Down Expand Up @@ -25,10 +49,11 @@ public void testSortByName() {

List<String> dirs = handler.getDirs(false, false);

Assert.assertEquals(3, dirs.size());
Assert.assertEquals(4, dirs.size());
Assert.assertEquals("trunk/a", dirs.get(0));
Assert.assertEquals("trunk/c", dirs.get(1));
Assert.assertEquals("trunk/x", dirs.get(2));
Assert.assertEquals("trunk/b", dirs.get(1));
Assert.assertEquals("trunk/c", dirs.get(2));
Assert.assertEquals("trunk/x", dirs.get(3));
}

@Test
Expand All @@ -37,10 +62,11 @@ public void testReverseSortByDate() {
addEntries(handler);
List<String> dirs = handler.getDirs(true, false);

Assert.assertEquals(3, dirs.size());
Assert.assertEquals(4, dirs.size());
Assert.assertEquals("trunk/a", dirs.get(0));
Assert.assertEquals("trunk/x", dirs.get(1));
Assert.assertEquals("trunk/c", dirs.get(2));
Assert.assertEquals("trunk/b", dirs.get(1));
Assert.assertEquals("trunk/x", dirs.get(2));
Assert.assertEquals("trunk/c", dirs.get(3));
}

@Test
Expand All @@ -49,10 +75,11 @@ public void testReverseSortByName() {
addEntries(handler);
List<String> dirs = handler.getDirs(false, true);

Assert.assertEquals(3, dirs.size());
Assert.assertEquals(4, dirs.size());
Assert.assertEquals("trunk/x", dirs.get(0));
Assert.assertEquals("trunk/c", dirs.get(1));
Assert.assertEquals("trunk/a", dirs.get(2));
Assert.assertEquals("trunk/b", dirs.get(2));
Assert.assertEquals("trunk/a", dirs.get(3));
}

@Test
Expand All @@ -68,6 +95,7 @@ public void testFilter() {
private void addEntries(SimpleSVNDirEntryHandler handler) {
try {
handler.handleDirEntry(getEntry("2011-11-01", "trunk/a"));
handler.handleDirEntry(getEntry("2011-11-01", "trunk/b"));
handler.handleDirEntry(getEntry("2011-10-01", "trunk/x"));
handler.handleDirEntry(getEntry("2011-09-01", "trunk/c"));
} catch (ParseException e) {
Expand Down

0 comments on commit a7b2cfa

Please sign in to comment.