Funzionante ma non sono gestiti gli errori
This commit is contained in:
@@ -2,12 +2,11 @@ package io.jenkins.plugins.sample;
|
||||
|
||||
import hudson.console.LineTransformationOutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -19,12 +18,12 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
private final boolean verboseLogging;
|
||||
private final String workspace;
|
||||
|
||||
private List<String> warnings = new ArrayList<>();
|
||||
private List<String> errors = new ArrayList<>();
|
||||
|
||||
private final PBAutoBuildErrorNote errorNote = new PBAutoBuildErrorNote();
|
||||
private final PBAutoBuildWarningNote warningNote = new PBAutoBuildWarningNote();
|
||||
|
||||
private int numberOfWarnings = 0;
|
||||
private int numberOfErrors = 0;
|
||||
|
||||
// Pattern per Versione e Runtime
|
||||
private Pattern versionPattern = Pattern.compile("PBAutoBuild Version: ([\\d\\.]+)");
|
||||
private Pattern runtimePattern = Pattern.compile("Runtime Version: ([\\d\\.]+)");
|
||||
@@ -41,9 +40,11 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
|
||||
// Pattern per Stage1, Stage2 e Regenerating
|
||||
private Pattern stagePattern = Pattern.compile("(Normal|Stage1|Stage2|Regenerating) for ([a-zA-Z]:\\\\.*?\\\\([^\\\\]+\\.\\w+))");
|
||||
private Pattern errorPattern = Pattern.compile("\\[\\s*Error\\s*\\](.*)");
|
||||
private Pattern warningPattern = Pattern.compile("\\[\\s*Warning\\s*\\](.*)");
|
||||
|
||||
|
||||
private final Queue<byte[]> queueLog = new ConcurrentLinkedQueue<>();
|
||||
private final Queue<String> queueLog = new ConcurrentLinkedQueue<>();
|
||||
private Thread consumerThread;
|
||||
private boolean consumerThreadRunning;
|
||||
|
||||
@@ -57,17 +58,12 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
startQueueConsumer();
|
||||
}
|
||||
|
||||
public int getNumberOfWarnings() {
|
||||
return numberOfWarnings;
|
||||
}
|
||||
|
||||
public int getNumberOfErrors() {
|
||||
return numberOfErrors;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void eol(byte[] b, int len) throws IOException {
|
||||
queueLog.add(b);
|
||||
String line = charset.decode(ByteBuffer.wrap(b, 0, len)).toString();
|
||||
line = line.replace("\0", "").trim();
|
||||
queueLog.add(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +78,7 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
consumerThread = new Thread(() -> {
|
||||
while (consumerThreadRunning) {
|
||||
if (!queueLog.isEmpty()) {
|
||||
final byte[] item = queueLog.poll();
|
||||
final String item = queueLog.poll();
|
||||
|
||||
if (item != null) {
|
||||
try {
|
||||
@@ -93,6 +89,7 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
// queueLog.wait();
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -103,41 +100,22 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
consumerThread.start();
|
||||
}
|
||||
|
||||
private void processLine(byte[] b) throws IOException {
|
||||
String line = charset.decode(ByteBuffer.wrap(b, 0, b.length)).toString();
|
||||
byte[] bytes1 = line.getBytes(charset);
|
||||
|
||||
String lineUtf16 = StandardCharsets.UTF_16.decode(ByteBuffer.wrap(b, 0, b.length)).toString();
|
||||
|
||||
boolean isUtf16 = true;
|
||||
for (int i = 0; i < bytes1.length; i = i + 2) {
|
||||
if (bytes1[i] != 0) {
|
||||
isUtf16 = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isUtf16) {
|
||||
line = lineUtf16;
|
||||
}
|
||||
|
||||
// trim off CR/LF from the end
|
||||
line = trimEOL(line);
|
||||
|
||||
private void processLine(String line) throws IOException {
|
||||
if (line.isEmpty()) return;
|
||||
|
||||
// Error messages handler
|
||||
Matcher m = PBAutoBuildErrorNote.PATTERN.matcher(line);
|
||||
if (m.matches()) { // Match the number of warnings
|
||||
final String errorMessage = extractData(line, errorPattern);
|
||||
|
||||
if (errorMessage != null) { // Match the number of warnings
|
||||
errorNote.encodeTo(out);
|
||||
this.numberOfErrors++;
|
||||
errors.add(errorMessage);
|
||||
}
|
||||
|
||||
// Warning messages handler
|
||||
m = PBAutoBuildWarningNote.PATTERN.matcher(line);
|
||||
if (m.matches()) { // Match the number of warnings
|
||||
final String warningMessage = extractData(line, warningPattern);
|
||||
if (warningMessage != null) { // Match the number of warnings
|
||||
warningNote.encodeTo(out);
|
||||
this.numberOfWarnings++;
|
||||
warnings.add(warningMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,13 +125,7 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
out.write(b1, 0, b1.length);
|
||||
} else {
|
||||
// Estrarre i dati
|
||||
// String version = extractData(line, versionPattern);
|
||||
// String runtimePath = extractData(line, runtimePattern);
|
||||
// String workPath = extractData(line, workPathPattern);
|
||||
// String project = extractData(line, projectPattern);
|
||||
String timestamp = extractData(line, timestampPattern);
|
||||
// String filename = extractFileNames(line, fileNamePattern);
|
||||
// String stage = extractStages(line, stagePattern);
|
||||
|
||||
line = line.replace(workspace, "")
|
||||
.replace("\t", " ");
|
||||
@@ -163,9 +135,8 @@ public class PBAutoBuildConsoleAnnotator extends LineTransformationOutputStream
|
||||
|
||||
|
||||
line += "\r\n";
|
||||
byte[] bytesToWrite = line.getBytes(charset);
|
||||
byte[] bytesToWrite = line.getBytes();
|
||||
out.write(bytesToWrite, 0, bytesToWrite.length);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user