Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions core/src/main/java/hudson/cli/CLIAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
}
Authentication authentication = Jenkins.getAuthentication2();
return WebSockets.upgrade(new WebSocketSession() {
ServerSideImpl connection;
volatile ServerSideImpl connection;
long sentBytes, sentCount, receivedBytes, receivedCount;
class OutputImpl implements PlainCLIProtocol.Output {
@Override
Expand All @@ -202,6 +202,11 @@
connection = new ServerSideImpl(new OutputImpl(), authentication);
} catch (IOException x) {
error(x);
try {
doClose();
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to close websocket on initialization error", e);
}

Check warning on line 209 in core/src/main/java/hudson/cli/CLIAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 206-209 are not covered by tests
return;
}
new Thread(() -> {
Expand All @@ -219,6 +224,7 @@

@Override
protected void binary(byte[] payload, int offset, int len) {
if (connection == null) return;

Check warning on line 227 in core/src/main/java/hudson/cli/CLIAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 227 is only partially covered, one branch is missing
try {
connection.handle(new DataInputStream(new ByteArrayInputStream(payload, offset, len)));
receivedBytes += len;
Expand All @@ -237,7 +243,9 @@
protected void closed(int statusCode, String reason) {
LOGGER.fine(() -> "closed: " + statusCode + ": " + reason);
LOGGER.fine(() -> "received " + receivedCount + " packets of " + receivedBytes + " bytes; sent " + sentCount + " packets of " + sentBytes + " bytes");
connection.handleClose();
if (connection != null) {

Check warning on line 246 in core/src/main/java/hudson/cli/CLIAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 246 is only partially covered, one branch is missing
connection.handleClose();
}
}
});
}
Expand Down Expand Up @@ -268,6 +276,14 @@
private final PipedOutputStream stdinMatch = new PipedOutputStream();
private final Authentication authentication;

private static final Map<String, Locale> AVAILABLE_LOCALES = new ConcurrentHashMap<>();

static {
for (Locale l : Locale.getAvailableLocales()) {
AVAILABLE_LOCALES.put(l.toString(), l);
Comment thread
Piyush0049 marked this conversation as resolved.
}
}

ServerSideImpl(PlainCLIProtocol.Output out, Authentication authentication) throws IOException {
super(out);
stdinMatch.connect(stdin);
Expand All @@ -281,11 +297,10 @@

@Override
protected void onLocale(String text) {
for (Locale _locale : Locale.getAvailableLocales()) {
if (_locale.toString().equals(text)) {
locale = _locale;
return;
}
Locale parsed = AVAILABLE_LOCALES.get(text);
if (parsed != null) {

Check warning on line 301 in core/src/main/java/hudson/cli/CLIAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 301 is only partially covered, one branch is missing
locale = parsed;
return;
}
LOGGER.log(Level.WARNING, "unknown client locale {0}", text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ConsoleAnnotationOutputStream<T> extends LineTransformationOutputSt
* {@link OutputStream} that writes to {@link #line}.
*/
private final WriterOutputStream lineOut;
private final Charset charset;

/**
*
Expand All @@ -70,6 +71,7 @@ public ConsoleAnnotationOutputStream(Writer out, ConsoleAnnotator<? super T> ann
this.out = out;
this.ann = ConsoleAnnotator.cast(ann);
this.context = context;
this.charset = charset;
this.lineOut = new WriterOutputStream(line, charset);
}

Expand Down Expand Up @@ -122,7 +124,7 @@ public ConsoleAnnotator<T> annotate(T context, MarkupText text) {
}
} catch (IOException | ClassNotFoundException e) {
// if we failed to resurrect an annotation, ignore it.
LOGGER.log(Level.FINE, "Failed to resurrect annotation from \"" + SourceCodeEscapers.javaCharEscaper().escape(new String(in, next, rest, Charset.defaultCharset())) + "\"", e);
LOGGER.log(Level.FINE, "Failed to resurrect annotation from \"" + SourceCodeEscapers.javaCharEscaper().escape(new String(in, next, rest, charset)) + "\"", e);
}

int bytesUsed = rest - b.available(); // bytes consumed by annotations
Expand Down
Loading