| // Copyright (C) 2014 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package com.googlesource.gerrit.plugins.xdocs.client; |
| |
| import com.google.gerrit.client.rpc.Natives; |
| import com.google.gwt.core.client.JavaScriptObject; |
| import com.google.gwt.core.client.JsArray; |
| |
| import java.util.Collections; |
| import java.util.Comparator; |
| |
| public class FileInfo extends JavaScriptObject { |
| public static final String COMMIT_MSG = "/COMMIT_MSG"; |
| public final native String path() /*-{ return this.path; }-*/; |
| public final native boolean binary() /*-{ return this.binary || false; }-*/; |
| |
| public static void sortFileInfoByPath(JsArray<FileInfo> list) { |
| Collections.sort(Natives.asList(list), new Comparator<FileInfo>() { |
| @Override |
| public int compare(FileInfo a, FileInfo b) { |
| if (COMMIT_MSG.equals(a.path())) { |
| return -1; |
| } else if (COMMIT_MSG.equals(b.path())) { |
| return 1; |
| } |
| return a.path().compareTo(b.path()); |
| } |
| }); |
| } |
| |
| public static String getFileName(String path) { |
| String fileName = COMMIT_MSG.equals(path) |
| ? "Commit Message" |
| : path; |
| int s = fileName.lastIndexOf('/'); |
| return s >= 0 ? fileName.substring(s + 1) : fileName; |
| } |
| |
| protected FileInfo() { |
| } |
| } |