Skip to content

Commit

Permalink
[FIXED JENKINS-12139] Sort workspace file list based on request locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzi committed Dec 27, 2011
1 parent f4966f7 commit f37dcab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -64,6 +64,9 @@
<li class='rfe'>
Add option to disable mailnotifications for each failed maven module.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-5695">issue 5695</a>)
<li class='rfe'>
Sort workspace file list based on request locale.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-12139">issue 12139</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
20 changes: 17 additions & 3 deletions core/src/main/java/hudson/model/DirectoryBrowserSupport.java
Expand Up @@ -43,11 +43,13 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import java.util.logging.Level;
Expand Down Expand Up @@ -227,7 +229,7 @@ public void serveFile(StaplerRequest req, StaplerResponse rsp, FilePath root, St
} else
if(serveDirIndex) {
// serve directory index
glob = new ChildPathBuilder();
glob = new ChildPathBuilder(req.getLocale());
}

if(glob!=null) {
Expand Down Expand Up @@ -392,12 +394,18 @@ public long getSize() {


private static final class FileComparator implements Comparator<File> {
private Collator collator;

public FileComparator(Locale locale) {
this.collator = Collator.getInstance(locale);
}

public int compare(File lhs, File rhs) {
// directories first, files next
int r = dirRank(lhs)-dirRank(rhs);
if(r!=0) return r;
// otherwise alphabetical
return lhs.getName().compareTo(rhs.getName());
return this.collator.compare(lhs.getName(), rhs.getName());
}

private int dirRank(File f) {
Expand Down Expand Up @@ -432,12 +440,18 @@ public List<String> invoke(File f, VirtualChannel channel) throws IOException {
* (this mechanism is used to skip empty intermediate directory.)
*/
private static final class ChildPathBuilder implements FileCallable<List<List<Path>>> {
private Locale locale;

public ChildPathBuilder(Locale locale) {
this.locale = locale;
}

public List<List<Path>> invoke(File cur, VirtualChannel channel) throws IOException {
List<List<Path>> r = new ArrayList<List<Path>>();

File[] files = cur.listFiles();
if (files != null) {
Arrays.sort(files,new FileComparator());
Arrays.sort(files,new FileComparator(this.locale));

for( File f : files ) {
Path p = new Path(Util.rawEncode(f.getName()),f.getName(),f.isDirectory(),f.length(), f.canRead());
Expand Down

0 comments on commit f37dcab

Please sign in to comment.