Runnable: replace anonymous class with lambda
In Java 8 Runnable is functional interface and can be replaced with lambda expressions or method references. Change-Id: I2896b39c27b2e5a91a60149155a8c00a8eb48e39
This commit is contained in:

committed by
Shawn Pearce

parent
8f0528f3b5
commit
8785d73fa5
@@ -133,17 +133,14 @@ public class GerritServer {
|
|||||||
static GerritServer start(Description desc, Config baseConfig) throws Exception {
|
static GerritServer start(Description desc, Config baseConfig) throws Exception {
|
||||||
Config cfg = desc.buildConfig(baseConfig);
|
Config cfg = desc.buildConfig(baseConfig);
|
||||||
Logger.getLogger("com.google.gerrit").setLevel(Level.DEBUG);
|
Logger.getLogger("com.google.gerrit").setLevel(Level.DEBUG);
|
||||||
final CyclicBarrier serverStarted = new CyclicBarrier(2);
|
CyclicBarrier serverStarted = new CyclicBarrier(2);
|
||||||
final Daemon daemon =
|
Daemon daemon =
|
||||||
new Daemon(
|
new Daemon(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
serverStarted.await();
|
||||||
try {
|
} catch (InterruptedException | BrokenBarrierException e) {
|
||||||
serverStarted.await();
|
throw new RuntimeException(e);
|
||||||
} catch (InterruptedException | BrokenBarrierException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Paths.get(baseConfig.getString("gerrit", null, "tempSiteDir")));
|
Paths.get(baseConfig.getString("gerrit", null, "tempSiteDir")));
|
||||||
|
@@ -79,12 +79,9 @@ abstract class ChunkManager {
|
|||||||
cm.addLineClass(line, where, className);
|
cm.addLineClass(line, where, className);
|
||||||
}
|
}
|
||||||
undo.add(
|
undo.add(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
for (int line = start; line < end; line++) {
|
||||||
public void run() {
|
cm.removeLineClass(line, where, className);
|
||||||
for (int line = start; line < end; line++) {
|
|
||||||
cm.removeLineClass(line, where, className);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -203,32 +203,26 @@ abstract class CommentManager {
|
|||||||
|
|
||||||
abstract String getTokenSuffixForActiveLine(CodeMirror cm);
|
abstract String getTokenSuffixForActiveLine(CodeMirror cm);
|
||||||
|
|
||||||
Runnable signInCallback(final CodeMirror cm) {
|
Runnable signInCallback(CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
String token = host.getToken();
|
||||||
public void run() {
|
if (cm.extras().hasActiveLine()) {
|
||||||
String token = host.getToken();
|
token += "@" + getTokenSuffixForActiveLine(cm);
|
||||||
if (cm.extras().hasActiveLine()) {
|
|
||||||
token += "@" + getTokenSuffixForActiveLine(cm);
|
|
||||||
}
|
|
||||||
Gerrit.doSignIn(token);
|
|
||||||
}
|
}
|
||||||
|
Gerrit.doSignIn(token);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void newDraft(CodeMirror cm);
|
abstract void newDraft(CodeMirror cm);
|
||||||
|
|
||||||
Runnable newDraftCallback(final CodeMirror cm) {
|
Runnable newDraftCallback(CodeMirror cm) {
|
||||||
if (!Gerrit.isSignedIn()) {
|
if (!Gerrit.isSignedIn()) {
|
||||||
return signInCallback(cm);
|
return signInCallback(cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
if (cm.extras().hasActiveLine()) {
|
||||||
public void run() {
|
newDraft(cm);
|
||||||
if (cm.extras().hasActiveLine()) {
|
|
||||||
newDraft(cm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -268,51 +262,48 @@ abstract class CommentManager {
|
|||||||
abstract SortedMap<Integer, CommentGroup> getMapForNav(DisplaySide side);
|
abstract SortedMap<Integer, CommentGroup> getMapForNav(DisplaySide side);
|
||||||
|
|
||||||
Runnable commentNav(final CodeMirror src, final Direction dir) {
|
Runnable commentNav(final CodeMirror src, final Direction dir) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
// Every comment appears in both side maps as a linked pair.
|
||||||
public void run() {
|
// It is only necessary to search one side to find a comment
|
||||||
// Every comment appears in both side maps as a linked pair.
|
// on either side of the editor pair.
|
||||||
// It is only necessary to search one side to find a comment
|
SortedMap<Integer, CommentGroup> map = getMapForNav(src.side());
|
||||||
// on either side of the editor pair.
|
int line =
|
||||||
SortedMap<Integer, CommentGroup> map = getMapForNav(src.side());
|
src.extras().hasActiveLine() ? src.getLineNumber(src.extras().activeLine()) + 1 : 0;
|
||||||
int line =
|
|
||||||
src.extras().hasActiveLine() ? src.getLineNumber(src.extras().activeLine()) + 1 : 0;
|
|
||||||
|
|
||||||
CommentGroup g;
|
CommentGroup g;
|
||||||
if (dir == Direction.NEXT) {
|
if (dir == Direction.NEXT) {
|
||||||
map = map.tailMap(line + 1);
|
map = map.tailMap(line + 1);
|
||||||
|
if (map.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g = map.get(map.firstKey());
|
||||||
|
while (g.getBoxCount() == 0) {
|
||||||
|
map = map.tailMap(map.firstKey() + 1);
|
||||||
if (map.isEmpty()) {
|
if (map.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g = map.get(map.firstKey());
|
g = map.get(map.firstKey());
|
||||||
while (g.getBoxCount() == 0) {
|
}
|
||||||
map = map.tailMap(map.firstKey() + 1);
|
} else {
|
||||||
if (map.isEmpty()) {
|
map = map.headMap(line);
|
||||||
return;
|
if (map.isEmpty()) {
|
||||||
}
|
return;
|
||||||
g = map.get(map.firstKey());
|
}
|
||||||
}
|
g = map.get(map.lastKey());
|
||||||
} else {
|
while (g.getBoxCount() == 0) {
|
||||||
map = map.headMap(line);
|
map = map.headMap(map.lastKey());
|
||||||
if (map.isEmpty()) {
|
if (map.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g = map.get(map.lastKey());
|
g = map.get(map.lastKey());
|
||||||
while (g.getBoxCount() == 0) {
|
|
||||||
map = map.headMap(map.lastKey());
|
|
||||||
if (map.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g = map.get(map.lastKey());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeMirror cm = g.getCm();
|
|
||||||
double y = cm.heightAtLine(g.getLine() - 1, "local");
|
|
||||||
cm.setCursor(Pos.create(g.getLine() - 1));
|
|
||||||
cm.scrollToY(y - 0.5 * cm.scrollbarV().getClientHeight());
|
|
||||||
cm.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CodeMirror cm = g.getCm();
|
||||||
|
double y = cm.heightAtLine(g.getLine() - 1, "local");
|
||||||
|
cm.setCursor(Pos.create(g.getLine() - 1));
|
||||||
|
cm.scrollToY(y - 0.5 * cm.scrollbarV().getClientHeight());
|
||||||
|
cm.focus();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,26 +416,20 @@ abstract class CommentManager {
|
|||||||
|
|
||||||
abstract CommentGroup getCommentGroupOnActiveLine(CodeMirror cm);
|
abstract CommentGroup getCommentGroupOnActiveLine(CodeMirror cm);
|
||||||
|
|
||||||
Runnable toggleOpenBox(final CodeMirror cm) {
|
Runnable toggleOpenBox(CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
||||||
public void run() {
|
if (group != null) {
|
||||||
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
group.openCloseLast();
|
||||||
if (group != null) {
|
|
||||||
group.openCloseLast();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable openCloseAll(final CodeMirror cm) {
|
Runnable openCloseAll(CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
||||||
public void run() {
|
if (group != null) {
|
||||||
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
group.openCloseAll();
|
||||||
if (group != null) {
|
|
||||||
group.openCloseAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -336,7 +336,7 @@ abstract class DiffScreen extends Screen {
|
|||||||
handlers.clear();
|
handlers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerCmEvents(final CodeMirror cm) {
|
void registerCmEvents(CodeMirror cm) {
|
||||||
cm.on("cursorActivity", updateActiveLine(cm));
|
cm.on("cursorActivity", updateActiveLine(cm));
|
||||||
cm.on("focus", updateActiveLine(cm));
|
cm.on("focus", updateActiveLine(cm));
|
||||||
KeyMap keyMap =
|
KeyMap keyMap =
|
||||||
@@ -356,169 +356,108 @@ abstract class DiffScreen extends Screen {
|
|||||||
.on("Shift-O", getCommentManager().openCloseAll(cm))
|
.on("Shift-O", getCommentManager().openCloseAll(cm))
|
||||||
.on(
|
.on(
|
||||||
"I",
|
"I",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
switch (getIntraLineStatus()) {
|
||||||
public void run() {
|
case OFF:
|
||||||
switch (getIntraLineStatus()) {
|
case OK:
|
||||||
case OFF:
|
toggleShowIntraline();
|
||||||
case OK:
|
break;
|
||||||
toggleShowIntraline();
|
case FAILURE:
|
||||||
break;
|
case TIMEOUT:
|
||||||
case FAILURE:
|
default:
|
||||||
case TIMEOUT:
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on(
|
|
||||||
"','",
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
prefsAction.show();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.on("','", prefsAction::show)
|
||||||
.on(
|
.on(
|
||||||
"Shift-/",
|
"Shift-/",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
new ShowHelpCommand().onKeyPress(null);
|
||||||
public void run() {
|
|
||||||
new ShowHelpCommand().onKeyPress(null);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Space",
|
"Space",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.vim().handleKey("<C-d>");
|
||||||
public void run() {
|
|
||||||
cm.vim().handleKey("<C-d>");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Shift-Space",
|
"Shift-Space",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.vim().handleKey("<C-u>");
|
||||||
public void run() {
|
|
||||||
cm.vim().handleKey("<C-u>");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Ctrl-F",
|
"Ctrl-F",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.execCommand("find");
|
||||||
public void run() {
|
|
||||||
cm.execCommand("find");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Ctrl-G",
|
"Ctrl-G",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.execCommand("findNext");
|
||||||
public void run() {
|
|
||||||
cm.execCommand("findNext");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on("Enter", maybeNextCmSearch(cm))
|
.on("Enter", maybeNextCmSearch(cm))
|
||||||
.on(
|
.on(
|
||||||
"Shift-Ctrl-G",
|
"Shift-Ctrl-G",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.execCommand("findPrev");
|
||||||
public void run() {
|
|
||||||
cm.execCommand("findPrev");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Shift-Enter",
|
"Shift-Enter",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.execCommand("findPrev");
|
||||||
public void run() {
|
|
||||||
cm.execCommand("findPrev");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Esc",
|
"Esc",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.setCursor(cm.getCursor());
|
||||||
public void run() {
|
cm.execCommand("clearSearch");
|
||||||
cm.setCursor(cm.getCursor());
|
cm.vim().handleEx("nohlsearch");
|
||||||
cm.execCommand("clearSearch");
|
|
||||||
cm.vim().handleEx("nohlsearch");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"Ctrl-A",
|
"Ctrl-A",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cm.execCommand("selectAll");
|
||||||
public void run() {
|
|
||||||
cm.execCommand("selectAll");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G O",
|
"G O",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("status:open"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("status:open"));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G M",
|
"G M",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("status:merged"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("status:merged"));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G A",
|
"G A",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("status:abandoned"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("status:abandoned"));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (Gerrit.isSignedIn()) {
|
if (Gerrit.isSignedIn()) {
|
||||||
keyMap
|
keyMap
|
||||||
.on(
|
.on(
|
||||||
"G I",
|
"G I",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.MINE);
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.MINE);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G D",
|
"G D",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("owner:self is:draft"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("owner:self is:draft"));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G C",
|
"G C",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("has:draft"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("has:draft"));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G W",
|
"G W",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("is:watched status:open"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("is:watched status:open"));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on(
|
.on(
|
||||||
"G S",
|
"G S",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
Gerrit.display(PageLinks.toChangeQuery("is:starred"));
|
||||||
public void run() {
|
|
||||||
Gerrit.display(PageLinks.toChangeQuery("is:starred"));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,13 +639,10 @@ abstract class DiffScreen extends Screen {
|
|||||||
|
|
||||||
void setContext(final int context) {
|
void setContext(final int context) {
|
||||||
operation(
|
operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
skipManager.removeAll();
|
||||||
public void run() {
|
skipManager.render(context, diff);
|
||||||
skipManager.removeAll();
|
updateRenderEntireFile();
|
||||||
skipManager.render(context, diff);
|
|
||||||
updateRenderEntireFile();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -753,21 +689,18 @@ abstract class DiffScreen extends Screen {
|
|||||||
return line - offset;
|
return line - offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable openEditScreen(final CodeMirror cm) {
|
private Runnable openEditScreen(CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
LineHandle handle = cm.extras().activeLine();
|
||||||
public void run() {
|
int line = cm.getLineNumber(handle) + 1;
|
||||||
LineHandle handle = cm.extras().activeLine();
|
if (Patch.COMMIT_MSG.equals(path)) {
|
||||||
int line = cm.getLineNumber(handle) + 1;
|
line = adjustCommitMessageLine(line);
|
||||||
if (Patch.COMMIT_MSG.equals(path)) {
|
}
|
||||||
line = adjustCommitMessageLine(line);
|
String token = Dispatcher.toEditScreen(revision, path, line);
|
||||||
}
|
if (!Gerrit.isSignedIn()) {
|
||||||
String token = Dispatcher.toEditScreen(revision, path, line);
|
Gerrit.doSignIn(token);
|
||||||
if (!Gerrit.isSignedIn()) {
|
} else {
|
||||||
Gerrit.doSignIn(token);
|
Gerrit.display(token);
|
||||||
} else {
|
|
||||||
Gerrit.display(token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -832,63 +765,51 @@ abstract class DiffScreen extends Screen {
|
|||||||
|
|
||||||
abstract void operation(Runnable apply);
|
abstract void operation(Runnable apply);
|
||||||
|
|
||||||
private Runnable upToChange(final boolean openReplyBox) {
|
private Runnable upToChange(boolean openReplyBox) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
CallbackGroup group = new CallbackGroup();
|
||||||
public void run() {
|
getCommentManager().saveAllDrafts(group);
|
||||||
CallbackGroup group = new CallbackGroup();
|
group.done();
|
||||||
getCommentManager().saveAllDrafts(group);
|
group.addListener(
|
||||||
group.done();
|
new GerritCallback<Void>() {
|
||||||
group.addListener(
|
@Override
|
||||||
new GerritCallback<Void>() {
|
public void onSuccess(Void result) {
|
||||||
@Override
|
String rev = String.valueOf(revision.get());
|
||||||
public void onSuccess(Void result) {
|
Gerrit.display(
|
||||||
String rev = String.valueOf(revision.get());
|
PageLinks.toChange(changeId, base.asString(), rev),
|
||||||
Gerrit.display(
|
new ChangeScreen(changeId, base, rev, openReplyBox, FileTable.Mode.REVIEW));
|
||||||
PageLinks.toChange(changeId, base.asString(), rev),
|
}
|
||||||
new ChangeScreen(changeId, base, rev, openReplyBox, FileTable.Mode.REVIEW));
|
});
|
||||||
}
|
};
|
||||||
});
|
}
|
||||||
|
|
||||||
|
private Runnable maybePrevVimSearch(CodeMirror cm) {
|
||||||
|
return () -> {
|
||||||
|
if (cm.vim().hasSearchHighlight()) {
|
||||||
|
cm.vim().handleKey("N");
|
||||||
|
} else {
|
||||||
|
getCommentManager().commentNav(cm, Direction.NEXT).run();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable maybePrevVimSearch(final CodeMirror cm) {
|
private Runnable maybeNextVimSearch(CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
if (cm.vim().hasSearchHighlight()) {
|
||||||
public void run() {
|
cm.vim().handleKey("n");
|
||||||
if (cm.vim().hasSearchHighlight()) {
|
} else {
|
||||||
cm.vim().handleKey("N");
|
getChunkManager().diffChunkNav(cm, Direction.NEXT).run();
|
||||||
} else {
|
|
||||||
getCommentManager().commentNav(cm, Direction.NEXT).run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable maybeNextVimSearch(final CodeMirror cm) {
|
Runnable maybeNextCmSearch(CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
if (cm.hasSearchHighlight()) {
|
||||||
public void run() {
|
cm.execCommand("findNext");
|
||||||
if (cm.vim().hasSearchHighlight()) {
|
} else {
|
||||||
cm.vim().handleKey("n");
|
cm.execCommand("clearSearch");
|
||||||
} else {
|
getCommentManager().toggleOpenBox(cm).run();
|
||||||
getChunkManager().diffChunkNav(cm, Direction.NEXT).run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable maybeNextCmSearch(final CodeMirror cm) {
|
|
||||||
return new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (cm.hasSearchHighlight()) {
|
|
||||||
cm.execCommand("findNext");
|
|
||||||
} else {
|
|
||||||
cm.execCommand("clearSearch");
|
|
||||||
getCommentManager().toggleOpenBox(cm).run();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -973,7 +894,7 @@ abstract class DiffScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reloadDiffInfo() {
|
void reloadDiffInfo() {
|
||||||
final int id = ++reloadVersionId;
|
int id = ++reloadVersionId;
|
||||||
DiffApi.diff(revision, path)
|
DiffApi.diff(revision, path)
|
||||||
.base(base.asPatchSetId())
|
.base(base.asPatchSetId())
|
||||||
.wholeFile()
|
.wholeFile()
|
||||||
@@ -986,16 +907,13 @@ abstract class DiffScreen extends Screen {
|
|||||||
if (id == reloadVersionId && isAttached()) {
|
if (id == reloadVersionId && isAttached()) {
|
||||||
diff = diffInfo;
|
diff = diffInfo;
|
||||||
operation(
|
operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
skipManager.removeAll();
|
||||||
public void run() {
|
getChunkManager().reset();
|
||||||
skipManager.removeAll();
|
getDiffTable().scrollbar.removeDiffAnnotations();
|
||||||
getChunkManager().reset();
|
setShowIntraline(prefs.intralineDifference());
|
||||||
getDiffTable().scrollbar.removeDiffAnnotations();
|
render(diff);
|
||||||
setShowIntraline(prefs.intralineDifference());
|
skipManager.render(prefs.context(), diff);
|
||||||
render(diff);
|
|
||||||
skipManager.render(prefs.context(), diff);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -318,47 +318,32 @@ public class Header extends Composite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Runnable toggleReviewed() {
|
Runnable toggleReviewed() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
reviewed.setValue(!reviewed.getValue(), true);
|
||||||
public void run() {
|
|
||||||
reviewed.setValue(!reviewed.getValue(), true);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable navigate(Direction dir) {
|
Runnable navigate(Direction dir) {
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case PREV:
|
case PREV:
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
(hasPrev ? prev : up).go();
|
||||||
public void run() {
|
|
||||||
(hasPrev ? prev : up).go();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
case NEXT:
|
case NEXT:
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
(hasNext ? next : up).go();
|
||||||
public void run() {
|
|
||||||
(hasNext ? next : up).go();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return new Runnable() {
|
return () -> {};
|
||||||
@Override
|
|
||||||
public void run() {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable reviewedAndNext() {
|
Runnable reviewedAndNext() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
if (Gerrit.isSignedIn()) {
|
||||||
public void run() {
|
reviewed.setValue(true, true);
|
||||||
if (Gerrit.isSignedIn()) {
|
|
||||||
reviewed.setValue(true, true);
|
|
||||||
}
|
|
||||||
navigate(Direction.NEXT).run();
|
|
||||||
}
|
}
|
||||||
|
navigate(Direction.NEXT).run();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -322,13 +322,10 @@ public class PreferencesBox extends Composite {
|
|||||||
prefs.tabSize(Math.max(1, Integer.parseInt(v)));
|
prefs.tabSize(Math.max(1, Integer.parseInt(v)));
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.operation(
|
view.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
int size = prefs.tabSize();
|
||||||
public void run() {
|
for (CodeMirror cm : view.getCms()) {
|
||||||
int v = prefs.tabSize();
|
cm.setOption("tabSize", size);
|
||||||
for (CodeMirror cm : view.getCms()) {
|
|
||||||
cm.setOption("tabSize", v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -342,11 +339,8 @@ public class PreferencesBox extends Composite {
|
|||||||
prefs.lineLength(Math.max(1, Integer.parseInt(v)));
|
prefs.lineLength(Math.max(1, Integer.parseInt(v)));
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.operation(
|
view.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
view.setLineLength(prefs.lineLength());
|
||||||
public void run() {
|
|
||||||
view.setLineLength(prefs.lineLength());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,12 +455,9 @@ public class PreferencesBox extends Composite {
|
|||||||
&& Objects.equals(mode, getSelectedMode())
|
&& Objects.equals(mode, getSelectedMode())
|
||||||
&& view.isAttached()) {
|
&& view.isAttached()) {
|
||||||
view.operation(
|
view.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
view.getCmFromSide(DisplaySide.A).setOption("mode", mode);
|
||||||
public void run() {
|
view.getCmFromSide(DisplaySide.B).setOption("mode", mode);
|
||||||
view.getCmFromSide(DisplaySide.A).setOption("mode", mode);
|
|
||||||
view.getCmFromSide(DisplaySide.B).setOption("mode", mode);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,13 +474,10 @@ public class PreferencesBox extends Composite {
|
|||||||
prefs.showWhitespaceErrors(e.getValue());
|
prefs.showWhitespaceErrors(e.getValue());
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.operation(
|
view.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
boolean s = prefs.showWhitespaceErrors();
|
||||||
public void run() {
|
for (CodeMirror cm : view.getCms()) {
|
||||||
boolean s = prefs.showWhitespaceErrors();
|
cm.setOption("showTrailingSpace", s);
|
||||||
for (CodeMirror cm : view.getCms()) {
|
|
||||||
cm.setOption("showTrailingSpace", s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -546,15 +534,12 @@ public class PreferencesBox extends Composite {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(Void result) {
|
public void onSuccess(Void result) {
|
||||||
view.operation(
|
view.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
if (getSelectedTheme() == newTheme && isAttached()) {
|
||||||
public void run() {
|
String t = newTheme.name().toLowerCase();
|
||||||
if (getSelectedTheme() == newTheme && isAttached()) {
|
view.getCmFromSide(DisplaySide.A).setOption("theme", t);
|
||||||
String t = newTheme.name().toLowerCase();
|
view.getCmFromSide(DisplaySide.B).setOption("theme", t);
|
||||||
view.getCmFromSide(DisplaySide.A).setOption("theme", t);
|
view.setThemeStyles(newTheme.isDark());
|
||||||
view.getCmFromSide(DisplaySide.B).setOption("theme", t);
|
|
||||||
view.setThemeStyles(newTheme.isDark());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -64,12 +64,9 @@ class ScrollbarAnnotation extends Widget implements ClickHandler {
|
|||||||
refresh =
|
refresh =
|
||||||
cmB.on(
|
cmB.on(
|
||||||
"refresh",
|
"refresh",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
if (updateScale()) {
|
||||||
public void run() {
|
updatePosition();
|
||||||
if (updateScale()) {
|
|
||||||
updatePosition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateScale();
|
updateScale();
|
||||||
|
@@ -102,14 +102,11 @@ public class SideBySide extends DiffScreen {
|
|||||||
super.onShowView();
|
super.onShowView();
|
||||||
|
|
||||||
operation(
|
operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
resizeCodeMirror();
|
||||||
public void run() {
|
chunkManager.adjustPadding();
|
||||||
resizeCodeMirror();
|
cmA.refresh();
|
||||||
chunkManager.adjustPadding();
|
cmB.refresh();
|
||||||
cmA.refresh();
|
|
||||||
cmB.refresh();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
|
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
|
||||||
diffTable.refresh();
|
diffTable.refresh();
|
||||||
@@ -209,18 +206,15 @@ public class SideBySide extends DiffScreen {
|
|||||||
chunkManager = new SideBySideChunkManager(this, cmA, cmB, diffTable.scrollbar);
|
chunkManager = new SideBySideChunkManager(this, cmA, cmB, diffTable.scrollbar);
|
||||||
|
|
||||||
operation(
|
operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
// Estimate initial CodeMirror height, fixed up in onShowView.
|
||||||
public void run() {
|
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
||||||
// Estimate initial CodeMirror height, fixed up in onShowView.
|
cmA.setHeight(height);
|
||||||
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
cmB.setHeight(height);
|
||||||
cmA.setHeight(height);
|
|
||||||
cmB.setHeight(height);
|
|
||||||
|
|
||||||
render(diff);
|
render(diff);
|
||||||
commentManager.render(comments, prefs.expandAllComments());
|
commentManager.render(comments, prefs.expandAllComments());
|
||||||
skipManager.render(prefs.context(), diff);
|
skipManager.render(prefs.context(), diff);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerCmEvents(cmA);
|
registerCmEvents(cmA);
|
||||||
@@ -321,64 +315,50 @@ public class SideBySide extends DiffScreen {
|
|||||||
@Override
|
@Override
|
||||||
Runnable updateActiveLine(final CodeMirror cm) {
|
Runnable updateActiveLine(final CodeMirror cm) {
|
||||||
final CodeMirror other = otherCm(cm);
|
final CodeMirror other = otherCm(cm);
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
// The rendering of active lines has to be deferred. Reflow
|
||||||
public void run() {
|
// caused by adding and removing styles chokes Firefox when arrow
|
||||||
// The rendering of active lines has to be deferred. Reflow
|
// key (or j/k) is held down. Performance on Chrome is fine
|
||||||
// caused by adding and removing styles chokes Firefox when arrow
|
// without the deferral.
|
||||||
// key (or j/k) is held down. Performance on Chrome is fine
|
//
|
||||||
// without the deferral.
|
Scheduler.get()
|
||||||
//
|
.scheduleDeferred(
|
||||||
Scheduler.get()
|
new ScheduledCommand() {
|
||||||
.scheduleDeferred(
|
@Override
|
||||||
new ScheduledCommand() {
|
public void execute() {
|
||||||
@Override
|
operation(
|
||||||
public void execute() {
|
() -> {
|
||||||
operation(
|
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
||||||
new Runnable() {
|
if (!cm.extras().activeLine(handle)) {
|
||||||
@Override
|
return;
|
||||||
public void run() {
|
}
|
||||||
LineHandle handle =
|
|
||||||
cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
|
||||||
if (!cm.extras().activeLine(handle)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LineOnOtherInfo info = lineOnOther(cm.side(), cm.getLineNumber(handle));
|
LineOnOtherInfo info = lineOnOther(cm.side(), cm.getLineNumber(handle));
|
||||||
if (info.isAligned()) {
|
if (info.isAligned()) {
|
||||||
other.extras().activeLine(other.getLineHandle(info.getLine()));
|
other.extras().activeLine(other.getLineHandle(info.getLine()));
|
||||||
} else {
|
} else {
|
||||||
other.extras().clearActiveLine();
|
other.extras().clearActiveLine();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable moveCursorToSide(final CodeMirror cmSrc, DisplaySide sideDst) {
|
private Runnable moveCursorToSide(final CodeMirror cmSrc, DisplaySide sideDst) {
|
||||||
final CodeMirror cmDst = getCmFromSide(sideDst);
|
final CodeMirror cmDst = getCmFromSide(sideDst);
|
||||||
if (cmDst == cmSrc) {
|
if (cmDst == cmSrc) {
|
||||||
return new Runnable() {
|
return () -> {};
|
||||||
@Override
|
|
||||||
public void run() {}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final DisplaySide sideSrc = cmSrc.side();
|
final DisplaySide sideSrc = cmSrc.side();
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
if (cmSrc.extras().hasActiveLine()) {
|
||||||
public void run() {
|
cmDst.setCursor(
|
||||||
if (cmSrc.extras().hasActiveLine()) {
|
Pos.create(
|
||||||
cmDst.setCursor(
|
lineOnOther(sideSrc, cmSrc.getLineNumber(cmSrc.extras().activeLine())).getLine()));
|
||||||
Pos.create(
|
|
||||||
lineOnOther(sideSrc, cmSrc.getLineNumber(cmSrc.extras().activeLine()))
|
|
||||||
.getLine()));
|
|
||||||
}
|
|
||||||
cmDst.focus();
|
|
||||||
}
|
}
|
||||||
|
cmDst.focus();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,19 +369,10 @@ public class SideBySide extends DiffScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void operation(final Runnable apply) {
|
void operation(Runnable apply) {
|
||||||
cmA.operation(
|
cmA.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cmB.operation(apply::run);
|
||||||
public void run() {
|
|
||||||
cmB.operation(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
apply.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -246,15 +246,12 @@ class SideBySideChunkManager extends ChunkManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Runnable diffChunkNav(final CodeMirror cm, final Direction dir) {
|
Runnable diffChunkNav(final CodeMirror cm, final Direction dir) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
||||||
public void run() {
|
int res =
|
||||||
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
Collections.binarySearch(
|
||||||
int res =
|
chunks, new DiffChunkInfo(cm.side(), line, 0, false), getDiffChunkComparator());
|
||||||
Collections.binarySearch(
|
diffChunkNavHelper(chunks, host, res, dir);
|
||||||
chunks, new DiffChunkInfo(cm.side(), line, 0, false), getDiffChunkComparator());
|
|
||||||
diffChunkNavHelper(chunks, host, res, dir);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -88,29 +88,26 @@ class SideBySideCommentGroup extends CommentGroup implements Comparable<SideBySi
|
|||||||
void handleRedraw() {
|
void handleRedraw() {
|
||||||
getLineWidget()
|
getLineWidget()
|
||||||
.onRedraw(
|
.onRedraw(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
||||||
public void run() {
|
if (getResizeTimer() != null) {
|
||||||
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
getResizeTimer().cancel();
|
||||||
if (getResizeTimer() != null) {
|
setResizeTimer(null);
|
||||||
getResizeTimer().cancel();
|
|
||||||
setResizeTimer(null);
|
|
||||||
}
|
|
||||||
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
|
||||||
} else if (getResizeTimer() == null) {
|
|
||||||
setResizeTimer(
|
|
||||||
new Timer() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
|
||||||
cancel();
|
|
||||||
setResizeTimer(null);
|
|
||||||
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getResizeTimer().scheduleRepeating(5);
|
|
||||||
}
|
}
|
||||||
|
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
||||||
|
} else if (getResizeTimer() == null) {
|
||||||
|
setResizeTimer(
|
||||||
|
new Timer() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
||||||
|
cancel();
|
||||||
|
setResizeTimer(null);
|
||||||
|
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getResizeTimer().scheduleRepeating(5);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -75,11 +75,8 @@ class SideBySideTable extends DiffTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Runnable toggleA() {
|
Runnable toggleA() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
setVisibleA(!isVisibleA());
|
||||||
public void run() {
|
|
||||||
setVisibleA(!isVisibleA());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -91,12 +91,9 @@ class SkipBar extends Composite {
|
|||||||
}
|
}
|
||||||
if (isNew) {
|
if (isNew) {
|
||||||
lineWidget.onFirstRedraw(
|
lineWidget.onFirstRedraw(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
int w = cm.getGutterElement().getOffsetWidth();
|
||||||
public void run() {
|
getElement().getStyle().setPaddingLeft(w, Unit.PX);
|
||||||
int w = cm.getGutterElement().getOffsetWidth();
|
|
||||||
getElement().getStyle().setPaddingLeft(w, Unit.PX);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,14 +107,7 @@ class SkipBar extends Composite {
|
|||||||
.set("inclusiveLeft", true)
|
.set("inclusiveLeft", true)
|
||||||
.set("inclusiveRight", true));
|
.set("inclusiveRight", true));
|
||||||
|
|
||||||
textMarker.on(
|
textMarker.on("beforeCursorEnter", this::expandAll);
|
||||||
"beforeCursorEnter",
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
expandAll();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
int skipped = end - start + 1;
|
int skipped = end - start + 1;
|
||||||
if (skipped <= UP_DOWN_THRESHOLD) {
|
if (skipped <= UP_DOWN_THRESHOLD) {
|
||||||
|
@@ -30,7 +30,6 @@ import com.google.gwt.core.client.GWT;
|
|||||||
import com.google.gwt.core.client.JavaScriptObject;
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
import com.google.gwt.core.client.JsArrayString;
|
import com.google.gwt.core.client.JsArrayString;
|
||||||
import com.google.gwt.core.client.Scheduler;
|
import com.google.gwt.core.client.Scheduler;
|
||||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
|
||||||
import com.google.gwt.dom.client.Element;
|
import com.google.gwt.dom.client.Element;
|
||||||
import com.google.gwt.event.dom.client.FocusEvent;
|
import com.google.gwt.event.dom.client.FocusEvent;
|
||||||
import com.google.gwt.event.dom.client.FocusHandler;
|
import com.google.gwt.event.dom.client.FocusHandler;
|
||||||
@@ -102,12 +101,9 @@ public class Unified extends DiffScreen {
|
|||||||
super.onShowView();
|
super.onShowView();
|
||||||
|
|
||||||
operation(
|
operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
resizeCodeMirror();
|
||||||
public void run() {
|
cm.refresh();
|
||||||
resizeCodeMirror();
|
|
||||||
cm.refresh();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
|
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
|
||||||
diffTable.refresh();
|
diffTable.refresh();
|
||||||
@@ -142,13 +138,10 @@ public class Unified extends DiffScreen {
|
|||||||
|
|
||||||
cm.on(
|
cm.on(
|
||||||
"scroll",
|
"scroll",
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
ScrollInfo si = cm.getScrollInfo();
|
||||||
public void run() {
|
if (autoHideDiffTableHeader) {
|
||||||
ScrollInfo si = cm.getScrollInfo();
|
updateDiffTableHeader(si);
|
||||||
if (autoHideDiffTableHeader) {
|
|
||||||
updateDiffTableHeader(si);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
maybeRegisterRenderEntireFileKeyMap(cm);
|
maybeRegisterRenderEntireFileKeyMap(cm);
|
||||||
@@ -186,17 +179,14 @@ public class Unified extends DiffScreen {
|
|||||||
chunkManager = new UnifiedChunkManager(this, cm, diffTable.scrollbar);
|
chunkManager = new UnifiedChunkManager(this, cm, diffTable.scrollbar);
|
||||||
|
|
||||||
operation(
|
operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
// Estimate initial CodeMirror height, fixed up in onShowView.
|
||||||
public void run() {
|
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
||||||
// Estimate initial CodeMirror height, fixed up in onShowView.
|
cm.setHeight(height);
|
||||||
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
|
||||||
cm.setHeight(height);
|
|
||||||
|
|
||||||
render(diff);
|
render(diff);
|
||||||
commentManager.render(comments, prefs.expandAllComments());
|
commentManager.render(comments, prefs.expandAllComments());
|
||||||
skipManager.render(prefs.context(), diff);
|
skipManager.render(prefs.context(), diff);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerCmEvents(cm);
|
registerCmEvents(cm);
|
||||||
@@ -318,24 +308,18 @@ public class Unified extends DiffScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Runnable updateActiveLine(final CodeMirror cm) {
|
Runnable updateActiveLine(final CodeMirror cm) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
// The rendering of active lines has to be deferred. Reflow
|
||||||
public void run() {
|
// caused by adding and removing styles chokes Firefox when arrow
|
||||||
// The rendering of active lines has to be deferred. Reflow
|
// key (or j/k) is held down. Performance on Chrome is fine
|
||||||
// caused by adding and removing styles chokes Firefox when arrow
|
// without the deferral.
|
||||||
// key (or j/k) is held down. Performance on Chrome is fine
|
//
|
||||||
// without the deferral.
|
Scheduler.get()
|
||||||
//
|
.scheduleDeferred(
|
||||||
Scheduler.get()
|
() -> {
|
||||||
.scheduleDeferred(
|
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
||||||
new ScheduledCommand() {
|
cm.extras().activeLine(handle);
|
||||||
@Override
|
});
|
||||||
public void execute() {
|
|
||||||
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
|
||||||
cm.extras().activeLine(handle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,14 +338,8 @@ public class Unified extends DiffScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void operation(final Runnable apply) {
|
void operation(Runnable apply) {
|
||||||
cm.operation(
|
cm.operation(apply::run);
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
apply.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -214,17 +214,14 @@ class UnifiedChunkManager extends ChunkManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Runnable diffChunkNav(final CodeMirror cm, final Direction dir) {
|
Runnable diffChunkNav(final CodeMirror cm, final Direction dir) {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
||||||
public void run() {
|
int res =
|
||||||
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
Collections.binarySearch(
|
||||||
int res =
|
chunks,
|
||||||
Collections.binarySearch(
|
new UnifiedDiffChunkInfo(cm.side(), 0, 0, line, false),
|
||||||
chunks,
|
getDiffChunkComparatorCmLine());
|
||||||
new UnifiedDiffChunkInfo(cm.side(), 0, 0, line, false),
|
diffChunkNavHelper(chunks, host, res, dir);
|
||||||
getDiffChunkComparatorCmLine());
|
|
||||||
diffChunkNavHelper(chunks, host, res, dir);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,29 +50,26 @@ class UnifiedCommentGroup extends CommentGroup {
|
|||||||
void handleRedraw() {
|
void handleRedraw() {
|
||||||
getLineWidget()
|
getLineWidget()
|
||||||
.onRedraw(
|
.onRedraw(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
if (canComputeHeight()) {
|
||||||
public void run() {
|
if (getResizeTimer() != null) {
|
||||||
if (canComputeHeight()) {
|
getResizeTimer().cancel();
|
||||||
if (getResizeTimer() != null) {
|
setResizeTimer(null);
|
||||||
getResizeTimer().cancel();
|
|
||||||
setResizeTimer(null);
|
|
||||||
}
|
|
||||||
reportHeightChange();
|
|
||||||
} else if (getResizeTimer() == null) {
|
|
||||||
setResizeTimer(
|
|
||||||
new Timer() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (canComputeHeight()) {
|
|
||||||
cancel();
|
|
||||||
setResizeTimer(null);
|
|
||||||
reportHeightChange();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
getResizeTimer().scheduleRepeating(5);
|
|
||||||
}
|
}
|
||||||
|
reportHeightChange();
|
||||||
|
} else if (getResizeTimer() == null) {
|
||||||
|
setResizeTimer(
|
||||||
|
new Timer() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (canComputeHeight()) {
|
||||||
|
cancel();
|
||||||
|
setResizeTimer(null);
|
||||||
|
reportHeightChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getResizeTimer().scheduleRepeating(5);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -49,7 +49,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
|||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.core.client.JsArray;
|
import com.google.gwt.core.client.JsArray;
|
||||||
import com.google.gwt.core.client.Scheduler;
|
import com.google.gwt.core.client.Scheduler;
|
||||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
|
||||||
import com.google.gwt.dom.client.Element;
|
import com.google.gwt.dom.client.Element;
|
||||||
import com.google.gwt.dom.client.Style.Unit;
|
import com.google.gwt.dom.client.Style.Unit;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
@@ -318,11 +317,8 @@ public class EditScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Runnable gotoLine() {
|
private Runnable gotoLine() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
cmEdit.execCommand("jumpToLine");
|
||||||
public void run() {
|
|
||||||
cmEdit.execCommand("jumpToLine");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,18 +470,12 @@ public class EditScreen extends Screen {
|
|||||||
|
|
||||||
void setTheme(final Theme newTheme) {
|
void setTheme(final Theme newTheme) {
|
||||||
cmBase.operation(
|
cmBase.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cmBase.setOption("theme", newTheme.name().toLowerCase());
|
||||||
public void run() {
|
|
||||||
cmBase.setOption("theme", newTheme.name().toLowerCase());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
cmEdit.operation(
|
cmEdit.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cmEdit.setOption("theme", newTheme.name().toLowerCase());
|
||||||
public void run() {
|
|
||||||
cmEdit.setOption("theme", newTheme.name().toLowerCase());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,18 +496,12 @@ public class EditScreen extends Screen {
|
|||||||
|
|
||||||
void setShowWhitespaceErrors(final boolean show) {
|
void setShowWhitespaceErrors(final boolean show) {
|
||||||
cmBase.operation(
|
cmBase.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cmBase.setOption("showTrailingSpace", show);
|
||||||
public void run() {
|
|
||||||
cmBase.setOption("showTrailingSpace", show);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
cmEdit.operation(
|
cmEdit.operation(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
cmEdit.setOption("showTrailingSpace", show);
|
||||||
public void run() {
|
|
||||||
cmEdit.setOption("showTrailingSpace", show);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,29 +627,17 @@ public class EditScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Runnable updateCursorPosition() {
|
private Runnable updateCursorPosition() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
// The rendering of active lines has to be deferred. Reflow
|
||||||
public void run() {
|
// caused by adding and removing styles chokes Firefox when arrow
|
||||||
// The rendering of active lines has to be deferred. Reflow
|
// key (or j/k) is held down. Performance on Chrome is fine
|
||||||
// caused by adding and removing styles chokes Firefox when arrow
|
// without the deferral.
|
||||||
// key (or j/k) is held down. Performance on Chrome is fine
|
//
|
||||||
// without the deferral.
|
Scheduler.get()
|
||||||
//
|
.scheduleDeferred(
|
||||||
Scheduler.get()
|
() -> {
|
||||||
.scheduleDeferred(
|
cmEdit.operation(this::updateActiveLine);
|
||||||
new ScheduledCommand() {
|
});
|
||||||
@Override
|
|
||||||
public void execute() {
|
|
||||||
cmEdit.operation(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateActiveLine();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,37 +655,34 @@ public class EditScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Runnable save() {
|
private Runnable save() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
if (!cmEdit.isClean(generation)) {
|
||||||
public void run() {
|
close.setEnabled(false);
|
||||||
if (!cmEdit.isClean(generation)) {
|
String text = cmEdit.getValue();
|
||||||
close.setEnabled(false);
|
if (Patch.COMMIT_MSG.equals(path)) {
|
||||||
String text = cmEdit.getValue();
|
String trimmed = text.trim() + "\r";
|
||||||
if (Patch.COMMIT_MSG.equals(path)) {
|
if (!trimmed.equals(text)) {
|
||||||
String trimmed = text.trim() + "\r";
|
text = trimmed;
|
||||||
if (!trimmed.equals(text)) {
|
cmEdit.setValue(text);
|
||||||
text = trimmed;
|
|
||||||
cmEdit.setValue(text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
final int g = cmEdit.changeGeneration(false);
|
|
||||||
ChangeEditApi.put(
|
|
||||||
revision.getParentKey().get(),
|
|
||||||
path,
|
|
||||||
text,
|
|
||||||
new GerritCallback<VoidResult>() {
|
|
||||||
@Override
|
|
||||||
public void onSuccess(VoidResult result) {
|
|
||||||
generation = g;
|
|
||||||
setClean(cmEdit.isClean(g));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(final Throwable caught) {
|
|
||||||
close.setEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
final int g = cmEdit.changeGeneration(false);
|
||||||
|
ChangeEditApi.put(
|
||||||
|
revision.getParentKey().get(),
|
||||||
|
path,
|
||||||
|
text,
|
||||||
|
new GerritCallback<VoidResult>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(VoidResult result) {
|
||||||
|
generation = g;
|
||||||
|
setClean(cmEdit.isClean(g));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(final Throwable caught) {
|
||||||
|
close.setEnabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -121,28 +121,25 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
|
|||||||
@SuppressWarnings("unused") // Error handling within Runnable.
|
@SuppressWarnings("unused") // Error handling within Runnable.
|
||||||
Future<?> possiblyIgnoredError =
|
Future<?> possiblyIgnoredError =
|
||||||
autoCommitExecutor.scheduleAtFixedRate(
|
autoCommitExecutor.scheduleAtFixedRate(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
if (autoCommitWriter.hasUncommittedChanges()) {
|
||||||
|
autoCommitWriter.manualFlush();
|
||||||
|
autoCommitWriter.commit();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error committing " + index + " Lucene index", e);
|
||||||
|
} catch (OutOfMemoryError e) {
|
||||||
|
log.error("Error committing " + index + " Lucene index", e);
|
||||||
try {
|
try {
|
||||||
if (autoCommitWriter.hasUncommittedChanges()) {
|
autoCommitWriter.close();
|
||||||
autoCommitWriter.manualFlush();
|
} catch (IOException e2) {
|
||||||
autoCommitWriter.commit();
|
log.error(
|
||||||
}
|
"SEVERE: Error closing "
|
||||||
} catch (IOException e) {
|
+ index
|
||||||
log.error("Error committing " + index + " Lucene index", e);
|
+ " Lucene index after OOM;"
|
||||||
} catch (OutOfMemoryError e) {
|
+ " index may be corrupted.",
|
||||||
log.error("Error committing " + index + " Lucene index", e);
|
e);
|
||||||
try {
|
|
||||||
autoCommitWriter.close();
|
|
||||||
} catch (IOException e2) {
|
|
||||||
log.error(
|
|
||||||
"SEVERE: Error closing "
|
|
||||||
+ index
|
|
||||||
+ " Lucene index after OOM;"
|
|
||||||
+ " index may be corrupted.",
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -228,12 +228,9 @@ public class Daemon extends SiteProgram {
|
|||||||
try {
|
try {
|
||||||
start();
|
start();
|
||||||
RuntimeShutdown.add(
|
RuntimeShutdown.add(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
log.info("caught shutdown, cleaning up");
|
||||||
public void run() {
|
stop();
|
||||||
log.info("caught shutdown, cleaning up");
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("Gerrit Code Review " + myVersion() + " ready");
|
log.info("Gerrit Code Review " + myVersion() + " ready");
|
||||||
|
@@ -45,16 +45,13 @@ public class Gsql extends SiteProgram {
|
|||||||
manager.add(dbInjector);
|
manager.add(dbInjector);
|
||||||
manager.start();
|
manager.start();
|
||||||
RuntimeShutdown.add(
|
RuntimeShutdown.add(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
System.in.close();
|
||||||
try {
|
} catch (IOException e) {
|
||||||
System.in.close();
|
// Ignored
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
manager.stop();
|
|
||||||
}
|
}
|
||||||
|
manager.stop();
|
||||||
});
|
});
|
||||||
final QueryShell shell = shellFactory().create(System.in, System.out);
|
final QueryShell shell = shellFactory().create(System.in, System.out);
|
||||||
shell.setOutputFormat(format);
|
shell.setOutputFormat(format);
|
||||||
|
@@ -85,13 +85,7 @@ public class ProtobufImport extends SiteProgram {
|
|||||||
Injector dbInjector = createDbInjector(SINGLE_USER);
|
Injector dbInjector = createDbInjector(SINGLE_USER);
|
||||||
manager.add(dbInjector);
|
manager.add(dbInjector);
|
||||||
manager.start();
|
manager.start();
|
||||||
RuntimeShutdown.add(
|
RuntimeShutdown.add(manager::stop);
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
manager.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dbInjector.injectMembers(this);
|
dbInjector.injectMembers(this);
|
||||||
|
|
||||||
ProgressMonitor progress = new TextProgressMonitor();
|
ProgressMonitor progress = new TextProgressMonitor();
|
||||||
|
@@ -79,19 +79,16 @@ public abstract class MetricMaker {
|
|||||||
* @param value only value of the metric.
|
* @param value only value of the metric.
|
||||||
* @param desc description of the metric.
|
* @param desc description of the metric.
|
||||||
*/
|
*/
|
||||||
public <V> void newConstantMetric(String name, final V value, Description desc) {
|
public <V> void newConstantMetric(String name, V value, Description desc) {
|
||||||
desc.setConstant();
|
desc.setConstant();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Class<V> type = (Class<V>) value.getClass();
|
Class<V> type = (Class<V>) value.getClass();
|
||||||
final CallbackMetric0<V> metric = newCallbackMetric(name, type, desc);
|
CallbackMetric0<V> metric = newCallbackMetric(name, type, desc);
|
||||||
newTrigger(
|
newTrigger(
|
||||||
metric,
|
metric,
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
metric.set(value);
|
||||||
public void run() {
|
|
||||||
metric.set(value);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,15 +113,12 @@ public abstract class MetricMaker {
|
|||||||
* @param trigger function to compute the value of the metric.
|
* @param trigger function to compute the value of the metric.
|
||||||
*/
|
*/
|
||||||
public <V> void newCallbackMetric(
|
public <V> void newCallbackMetric(
|
||||||
String name, Class<V> valueClass, Description desc, final Supplier<V> trigger) {
|
String name, Class<V> valueClass, Description desc, Supplier<V> trigger) {
|
||||||
final CallbackMetric0<V> metric = newCallbackMetric(name, valueClass, desc);
|
CallbackMetric0<V> metric = newCallbackMetric(name, valueClass, desc);
|
||||||
newTrigger(
|
newTrigger(
|
||||||
metric,
|
metric,
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
metric.set(trigger.get());
|
||||||
public void run() {
|
|
||||||
metric.set(trigger.get());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -147,23 +147,20 @@ public class ProcMetricModule extends MetricModule {
|
|||||||
metrics.newTrigger(
|
metrics.newTrigger(
|
||||||
ImmutableSet.<CallbackMetric<?>>of(
|
ImmutableSet.<CallbackMetric<?>>of(
|
||||||
heapCommitted, heapUsed, nonHeapCommitted, nonHeapUsed, objectPendingFinalizationCount),
|
heapCommitted, heapUsed, nonHeapCommitted, nonHeapUsed, objectPendingFinalizationCount),
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
MemoryUsage stats = memory.getHeapMemoryUsage();
|
||||||
try {
|
heapCommitted.set(stats.getCommitted());
|
||||||
MemoryUsage stats = memory.getHeapMemoryUsage();
|
heapUsed.set(stats.getUsed());
|
||||||
heapCommitted.set(stats.getCommitted());
|
} catch (IllegalArgumentException e) {
|
||||||
heapUsed.set(stats.getUsed());
|
// MXBean may throw due to a bug in Java 7; ignore.
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
// MXBean may throw due to a bug in Java 7; ignore.
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryUsage stats = memory.getNonHeapMemoryUsage();
|
|
||||||
nonHeapCommitted.set(stats.getCommitted());
|
|
||||||
nonHeapUsed.set(stats.getUsed());
|
|
||||||
|
|
||||||
objectPendingFinalizationCount.set(memory.getObjectPendingFinalizationCount());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryUsage stats = memory.getNonHeapMemoryUsage();
|
||||||
|
nonHeapCommitted.set(stats.getCommitted());
|
||||||
|
nonHeapUsed.set(stats.getUsed());
|
||||||
|
|
||||||
|
objectPendingFinalizationCount.set(memory.getObjectPendingFinalizationCount());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,18 +184,15 @@ public class ProcMetricModule extends MetricModule {
|
|||||||
metrics.newTrigger(
|
metrics.newTrigger(
|
||||||
gcCount,
|
gcCount,
|
||||||
gcTime,
|
gcTime,
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
|
||||||
public void run() {
|
long count = gc.getCollectionCount();
|
||||||
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
|
if (count != -1) {
|
||||||
long count = gc.getCollectionCount();
|
gcCount.set(gc.getName(), count);
|
||||||
if (count != -1) {
|
}
|
||||||
gcCount.set(gc.getName(), count);
|
long time = gc.getCollectionTime();
|
||||||
}
|
if (time != -1) {
|
||||||
long time = gc.getCollectionTime();
|
gcTime.set(gc.getName(), time);
|
||||||
if (time != -1) {
|
|
||||||
gcTime.set(gc.getName(), time);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -119,19 +119,13 @@ public final class StoredValues {
|
|||||||
GitRepositoryManager gitMgr = env.getArgs().getGitRepositoryManager();
|
GitRepositoryManager gitMgr = env.getArgs().getGitRepositoryManager();
|
||||||
Change change = getChange(engine);
|
Change change = getChange(engine);
|
||||||
Project.NameKey projectKey = change.getProject();
|
Project.NameKey projectKey = change.getProject();
|
||||||
final Repository repo;
|
Repository repo;
|
||||||
try {
|
try {
|
||||||
repo = gitMgr.openRepository(projectKey);
|
repo = gitMgr.openRepository(projectKey);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SystemException(e.getMessage());
|
throw new SystemException(e.getMessage());
|
||||||
}
|
}
|
||||||
env.addToCleanup(
|
env.addToCleanup(repo::close);
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
repo.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -69,26 +69,23 @@ public class CacheMetrics {
|
|||||||
|
|
||||||
metrics.newTrigger(
|
metrics.newTrigger(
|
||||||
cacheMetrics,
|
cacheMetrics,
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
|
||||||
public void run() {
|
Cache<?, ?> c = e.getProvider().get();
|
||||||
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
|
String name = metricNameOf(e);
|
||||||
Cache<?, ?> c = e.getProvider().get();
|
CacheStats cstats = c.stats();
|
||||||
String name = metricNameOf(e);
|
memEnt.set(name, c.size());
|
||||||
CacheStats cstats = c.stats();
|
memHit.set(name, cstats.hitRate() * 100);
|
||||||
memEnt.set(name, c.size());
|
memEvict.set(name, cstats.evictionCount());
|
||||||
memHit.set(name, cstats.hitRate() * 100);
|
if (c instanceof PersistentCache) {
|
||||||
memEvict.set(name, cstats.evictionCount());
|
PersistentCache.DiskStats d = ((PersistentCache) c).diskStats();
|
||||||
if (c instanceof PersistentCache) {
|
perDiskEnt.set(name, d.size());
|
||||||
PersistentCache.DiskStats d = ((PersistentCache) c).diskStats();
|
perDiskHit.set(name, hitRatio(d));
|
||||||
perDiskEnt.set(name, d.size());
|
|
||||||
perDiskHit.set(name, hitRatio(d));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (CallbackMetric<?> cbm : cacheMetrics) {
|
|
||||||
cbm.prune();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (CallbackMetric<?> cbm : cacheMetrics) {
|
||||||
|
cbm.prune();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,12 +51,9 @@ public class RequestScopedReviewDbProvider implements Provider<ReviewDb> {
|
|||||||
cleanup
|
cleanup
|
||||||
.get()
|
.get()
|
||||||
.add(
|
.add(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
c.close();
|
||||||
public void run() {
|
db = null;
|
||||||
c.close();
|
|
||||||
db = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
c.close();
|
c.close();
|
||||||
|
@@ -54,25 +54,19 @@ public class ProjectCacheWarmer implements LifecycleListener {
|
|||||||
|
|
||||||
log.info("Loading project cache");
|
log.info("Loading project cache");
|
||||||
scheduler.execute(
|
scheduler.execute(
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
for (final Project.NameKey name : cache.all()) {
|
||||||
public void run() {
|
pool.execute(
|
||||||
for (final Project.NameKey name : cache.all()) {
|
() -> {
|
||||||
pool.execute(
|
cache.get(name);
|
||||||
new Runnable() {
|
});
|
||||||
@Override
|
}
|
||||||
public void run() {
|
pool.shutdown();
|
||||||
cache.get(name);
|
try {
|
||||||
}
|
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||||
});
|
log.info("Finished loading project cache");
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
pool.shutdown();
|
log.warn("Interrupted while waiting for project cache to load");
|
||||||
try {
|
|
||||||
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
|
||||||
log.info("Finished loading project cache");
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted while waiting for project cache to load");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -161,8 +161,8 @@ public class DataSourceProvider implements Provider<DataSource>, LifecycleListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportPoolMetrics(final BasicDataSource pool) {
|
private void exportPoolMetrics(BasicDataSource pool) {
|
||||||
final CallbackMetric1<Boolean, Integer> cnt =
|
CallbackMetric1<Boolean, Integer> cnt =
|
||||||
metrics.newCallbackMetric(
|
metrics.newCallbackMetric(
|
||||||
"sql/connection_pool/connections",
|
"sql/connection_pool/connections",
|
||||||
Integer.class,
|
Integer.class,
|
||||||
@@ -170,13 +170,10 @@ public class DataSourceProvider implements Provider<DataSource>, LifecycleListen
|
|||||||
Field.ofBoolean("active"));
|
Field.ofBoolean("active"));
|
||||||
metrics.newTrigger(
|
metrics.newTrigger(
|
||||||
cnt,
|
cnt,
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
synchronized (pool) {
|
||||||
public void run() {
|
cnt.set(true, pool.getNumActive());
|
||||||
synchronized (pool) {
|
cnt.set(false, pool.getNumIdle());
|
||||||
cnt.set(true, pool.getNumActive());
|
|
||||||
cnt.set(false, pool.getNumIdle());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -133,12 +133,9 @@ public class ProcMetricModuleTest {
|
|||||||
final AtomicInteger invocations = new AtomicInteger(0);
|
final AtomicInteger invocations = new AtomicInteger(0);
|
||||||
metrics.newTrigger(
|
metrics.newTrigger(
|
||||||
cntr,
|
cntr,
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
invocations.getAndIncrement();
|
||||||
public void run() {
|
cntr.set(42L);
|
||||||
invocations.getAndIncrement();
|
|
||||||
cntr.set(42L);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Triggers run immediately with DropWizard binding.
|
// Triggers run immediately with DropWizard binding.
|
||||||
|
@@ -159,14 +159,11 @@ public class RepoSequenceTest {
|
|||||||
// Seed existing ref value.
|
// Seed existing ref value.
|
||||||
writeBlob("id", "1");
|
writeBlob("id", "1");
|
||||||
|
|
||||||
final AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
|
AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
|
||||||
Runnable bgUpdate =
|
Runnable bgUpdate =
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
if (!doneBgUpdate.getAndSet(true)) {
|
||||||
public void run() {
|
writeBlob("id", "1234");
|
||||||
if (!doneBgUpdate.getAndSet(true)) {
|
|
||||||
writeBlob("id", "1234");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -203,13 +200,10 @@ public class RepoSequenceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failAfterRetryerGivesUp() throws Exception {
|
public void failAfterRetryerGivesUp() throws Exception {
|
||||||
final AtomicInteger bgCounter = new AtomicInteger(1234);
|
AtomicInteger bgCounter = new AtomicInteger(1234);
|
||||||
Runnable bgUpdate =
|
Runnable bgUpdate =
|
||||||
new Runnable() {
|
() -> {
|
||||||
@Override
|
writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000)));
|
||||||
public void run() {
|
|
||||||
writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000)));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
RepoSequence s =
|
RepoSequence s =
|
||||||
newSequence(
|
newSequence(
|
||||||
|
@@ -230,13 +230,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
|||||||
Future<?> future = task.getAndSet(null);
|
Future<?> future = task.getAndSet(null);
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.cancel(true);
|
future.cancel(true);
|
||||||
destroyExecutor.execute(
|
destroyExecutor.execute(this::onDestroy);
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
onDestroy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user