Funzionante ma non sono gestiti gli errori
This commit is contained in:
12
pom.xml
12
pom.xml
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>plugin</artifactId>
|
||||
<version>4.85</version>
|
||||
<version>4.88</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<revision>1.0.7</revision>
|
||||
<revision>1.0.20</revision>
|
||||
<changelist>-SNAPSHOT</changelist>
|
||||
|
||||
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
|
||||
@@ -47,14 +47,18 @@
|
||||
<dependency>
|
||||
<!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
|
||||
<groupId>io.jenkins.tools.bom</groupId>
|
||||
<artifactId>bom-2.440.x</artifactId>
|
||||
<version>3193.v330d8248d39e</version>
|
||||
<artifactId>bom-2.462.x</artifactId>
|
||||
<version>3696.vb_b_4e2d1a_0542</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins.workflow</groupId>
|
||||
<artifactId>workflow-step-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jenkins-ci.plugins</groupId>
|
||||
<artifactId>structs</artifactId>
|
||||
|
||||
@@ -24,30 +24,19 @@ public class PBAutoBuildBuilder extends Builder implements SimpleBuildStep {
|
||||
*/
|
||||
private String pbAutoBuildName;
|
||||
private String cmdLineArgs;
|
||||
private boolean continueOnBuildFailure;
|
||||
private boolean unstableIfWarnings;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* When this builder is created in the project configuration step, the
|
||||
* builder object will be created from the strings below.
|
||||
*
|
||||
* @param pbAutoBuildName
|
||||
* The PowerBuilder logical name
|
||||
* @param cmdLineArgs
|
||||
* Whitespace separated list of command line arguments for pb autobuild utility
|
||||
* @param continueOnBuildFailure
|
||||
* If true, job will continue despite pb autobuild build failure
|
||||
* @param unstableIfWarnings
|
||||
* If true, job will be unstable if there are warnings
|
||||
* @param pbAutoBuildName The PowerBuilder logical name
|
||||
* @param cmdLineArgs Whitespace separated list of command line arguments for pb autobuild utility
|
||||
*/
|
||||
@DataBoundConstructor
|
||||
public PBAutoBuildBuilder(String pbAutoBuildName, String cmdLineArgs, boolean continueOnBuildFailure, boolean unstableIfWarnings) {
|
||||
public PBAutoBuildBuilder(String pbAutoBuildName, String cmdLineArgs) {
|
||||
this.pbAutoBuildName = pbAutoBuildName;
|
||||
this.cmdLineArgs = cmdLineArgs;
|
||||
this.continueOnBuildFailure = continueOnBuildFailure;
|
||||
this.unstableIfWarnings = unstableIfWarnings;
|
||||
}
|
||||
|
||||
public String getPbAutoBuildName() {
|
||||
@@ -68,127 +57,124 @@ public class PBAutoBuildBuilder extends Builder implements SimpleBuildStep {
|
||||
this.cmdLineArgs = cmdLineArgs;
|
||||
}
|
||||
|
||||
public boolean isContinueOnBuildFailure() {
|
||||
return continueOnBuildFailure;
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setContinueOnBuildFailure(boolean continueOnBuildFailure) {
|
||||
this.continueOnBuildFailure = continueOnBuildFailure;
|
||||
}
|
||||
|
||||
public boolean isUnstableIfWarnings() {
|
||||
return unstableIfWarnings;
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setUnstableIfWarnings(boolean unstableIfWarnings) {
|
||||
this.unstableIfWarnings = unstableIfWarnings;
|
||||
}
|
||||
|
||||
public PBAutoBuildInstallation getPBAutoBuild() {
|
||||
DescriptorImpl descriptor = (DescriptorImpl) getDescriptor();
|
||||
for (PBAutoBuildInstallation i : descriptor.getInstallations()) {
|
||||
if (pbAutoBuildName != null && i.getName().equals(pbAutoBuildName))
|
||||
return i;
|
||||
}
|
||||
if ( descriptor.getInstallations().length == 1 ) {
|
||||
if (descriptor.getInstallations().length == 1) {
|
||||
return descriptor.getInstallations()[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
|
||||
throws InterruptedException, IOException {
|
||||
return runPBAutoBuild(build, Objects.requireNonNull(build.getWorkspace()), launcher, listener);
|
||||
public boolean requiresWorkspace() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull EnvVars env, @NonNull Launcher launcher, @NonNull TaskListener listener) throws InterruptedException, IOException {
|
||||
public void perform(@NonNull Run<?, ?> run,
|
||||
@NonNull FilePath workspace,
|
||||
@NonNull EnvVars env,
|
||||
@NonNull Launcher launcher,
|
||||
@NonNull TaskListener listener
|
||||
) throws InterruptedException, IOException {
|
||||
runPBAutoBuild(run, workspace, launcher, listener);
|
||||
}
|
||||
|
||||
public boolean runPBAutoBuild(Run<?, ?> build, @NonNull FilePath workspace, Launcher launcher, TaskListener listener)
|
||||
throws InterruptedException, IOException {
|
||||
ArgumentListBuilder args = new ArgumentListBuilder();
|
||||
PBAutoBuildInstallation ai = getPBAutoBuild();
|
||||
String execName = "pbautobuild220.exe";
|
||||
|
||||
if (ai == null) {
|
||||
listener.fatalError("Unable to find a valid installation");
|
||||
} else {
|
||||
EnvVars env = build.getEnvironment(listener);
|
||||
//Node node = Computer.currentComputer().getNode();
|
||||
//if (node != null) {
|
||||
//ai = ai.forNode(node, listener);
|
||||
ai = ai.forEnvironment(env);
|
||||
String pathToPBAutoBuild = getToolFullPath(launcher, ai.getHome(), execName);
|
||||
FilePath exec = new FilePath(launcher.getChannel(), pathToPBAutoBuild);
|
||||
|
||||
try {
|
||||
if (!exec.exists()) {
|
||||
listener.fatalError(pathToPBAutoBuild + " doesn't exist");
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
listener.fatalError("Failed checking for existence of " + pathToPBAutoBuild);
|
||||
return false;
|
||||
}
|
||||
|
||||
listener.getLogger().println("Path to PB AutoBuild utility: " + pathToPBAutoBuild);
|
||||
args.add(pathToPBAutoBuild);
|
||||
|
||||
if (ai.getDefaultArgs() != null) {
|
||||
args.add(tokenizeArgs(ai.getDefaultArgs()));
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
EnvVars env = build.getEnvironment(listener);
|
||||
String normalizedArgs = cmdLineArgs.replaceAll("[\t\r\n]+", " ");
|
||||
normalizedArgs = Util.replaceMacro(normalizedArgs, env);
|
||||
//normalizedArgs = Util.replaceMacro(normalizedArgs, build.getBuildVariables());
|
||||
|
||||
if (!normalizedArgs.trim().isEmpty())
|
||||
args.add(tokenizeArgs(normalizedArgs));
|
||||
|
||||
|
||||
if (!launcher.isUnix()) {
|
||||
// final int cpi = getCodePageIdentifier(build.getCharset());
|
||||
// if (cpi != 0)
|
||||
// args.prepend("cmd.exe", "/C", "\"", "chcp", String.valueOf(cpi), "&&");
|
||||
// else
|
||||
args.prepend("cmd.exe", "/C", "\"");
|
||||
args.add("\"", "&&", "exit", "%%ERRORLEVEL%%");
|
||||
}
|
||||
|
||||
try {
|
||||
listener.getLogger()
|
||||
.println(String.format("Executing the command %s from %s", args.toStringWithQuote(), workspace));
|
||||
// Parser to find the number of Warnings/Errors
|
||||
PBAutoBuildConsoleParser mbcp = new PBAutoBuildConsoleParser(listener.getLogger(), build.getCharset(), false);
|
||||
PBAutoBuildConsoleAnnotator annotator = new PBAutoBuildConsoleAnnotator(listener.getLogger(),
|
||||
build.getCharset(), false, workspace.getRemote());
|
||||
|
||||
// Launch the pbautobuild utility
|
||||
int r = launcher.launch().cmds(args).envs(env).stdout(mbcp).stdout(annotator).pwd(workspace).join();
|
||||
|
||||
// Check the number of warnings
|
||||
if (unstableIfWarnings && mbcp.getNumberOfWarnings() > 0) {
|
||||
listener.getLogger().println("> Set build UNSTABLE because there are warnings.");
|
||||
build.setResult(Result.UNSTABLE);
|
||||
}
|
||||
// Return the result of the compilation
|
||||
return continueOnBuildFailure || (r == 0);
|
||||
|
||||
} catch (IOException e) {
|
||||
Util.displayIOException(e, listener);
|
||||
build.setResult(Result.FAILURE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ottieni l'ambiente della build
|
||||
EnvVars env = build.getEnvironment(listener);
|
||||
ai = ai.forEnvironment(env); // Configura l'installazione per l'ambiente corrente
|
||||
String execName = "pbautobuild220.exe";
|
||||
String pathToPBAutoBuild = getToolFullPath(launcher, ai.getHome(), execName);
|
||||
FilePath exec = new FilePath(launcher.getChannel(), pathToPBAutoBuild);
|
||||
|
||||
// Verifica se l'eseguibile esiste
|
||||
if (!exec.exists()) {
|
||||
return handleError(pathToPBAutoBuild + " doesn't exist", build, listener);
|
||||
}
|
||||
|
||||
listener.getLogger().println("Path to PB AutoBuild utility: " + pathToPBAutoBuild);
|
||||
|
||||
// Costruisci i parametri di comando
|
||||
ArgumentListBuilder args = new ArgumentListBuilder();
|
||||
args.add(pathToPBAutoBuild);
|
||||
|
||||
if (ai.getDefaultArgs() != null) {
|
||||
args.add(tokenizeArgs(ai.getDefaultArgs()));
|
||||
}
|
||||
|
||||
// Aggiungi gli argomenti personalizzati (se presenti)
|
||||
String normalizedArgs = cmdLineArgs.replaceAll("[\t\r\n]+", " ");
|
||||
normalizedArgs = Util.replaceMacro(normalizedArgs, env);
|
||||
if (!normalizedArgs.trim().isEmpty()) {
|
||||
args.add(tokenizeArgs(normalizedArgs));
|
||||
}
|
||||
|
||||
// Aggiungi il comando per Windows
|
||||
if (!launcher.isUnix()) {
|
||||
args.prepend("cmd.exe", "/C", "\"");
|
||||
args.add("\"", "&&", "exit", "%%ERRORLEVEL%%");
|
||||
}
|
||||
|
||||
// Esegui il comando
|
||||
return executeBuildCommand(args, build, workspace, launcher, listener);
|
||||
}
|
||||
|
||||
private boolean handleError(String message, Run<?, ?> build, TaskListener listener) throws AbortException {
|
||||
listener.fatalError(message);
|
||||
build.setResult(Result.FAILURE);
|
||||
throw new AbortException(message);
|
||||
// return false;
|
||||
}
|
||||
|
||||
private boolean executeBuildCommand(ArgumentListBuilder args, Run<?, ?> build, FilePath workspace,
|
||||
Launcher launcher, TaskListener listener) throws IOException, InterruptedException {
|
||||
listener.getLogger().println(String.format("Executing the command %s from %s", args.toStringWithQuote(), workspace));
|
||||
|
||||
// Parser per il numero di Warnings/Errors
|
||||
PBAutoBuildConsoleParser mbcp = new PBAutoBuildConsoleParser(listener.getLogger(),
|
||||
build.getCharset(), false, workspace.getRemote());
|
||||
PBAutoBuildConsoleAnnotator annotator = new PBAutoBuildConsoleAnnotator(listener.getLogger(),
|
||||
build.getCharset(), false, workspace.getRemote());
|
||||
|
||||
// Lancia il comando
|
||||
int r = launcher.launch()
|
||||
.cmds(args)
|
||||
.envs(build.getEnvironment(listener))
|
||||
.stdout(mbcp)
|
||||
.stdout(annotator)
|
||||
.pwd(workspace)
|
||||
.join();
|
||||
|
||||
// Gestione degli errori
|
||||
if (!mbcp.getErrors().isEmpty()) {
|
||||
return handleError(mbcp.getErrors().get(0), build, listener);
|
||||
}
|
||||
|
||||
// Se ci sono warning, possiamo decidere se segnalarli come build UNSTABLE
|
||||
// Se necessario, decommentare la parte per segnalarli come UNSTABLE
|
||||
// if (unstableIfWarnings && !mbcp.getWarnings().isEmpty()) {
|
||||
// listener.getLogger().println("> Set build UNSTABLE because there are warnings.");
|
||||
// build.setResult(Result.UNSTABLE);
|
||||
//}
|
||||
|
||||
return r == 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the full path of the tool to run. If given path is a directory, this
|
||||
* will append the executable name.
|
||||
@@ -235,6 +221,7 @@ public class PBAutoBuildBuilder extends Builder implements SimpleBuildStep {
|
||||
@Extension
|
||||
@Symbol("pbautobuild")
|
||||
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
|
||||
|
||||
@CopyOnWrite
|
||||
private volatile PBAutoBuildInstallation[] installations = new PBAutoBuildInstallation[0];
|
||||
|
||||
@@ -248,7 +235,6 @@ public class PBAutoBuildBuilder extends Builder implements SimpleBuildStep {
|
||||
return Messages.PBAutoBuildBuilder_DisplayName();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
|
||||
return true;
|
||||
@@ -268,156 +254,4 @@ public class PBAutoBuildBuilder extends Builder implements SimpleBuildStep {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getCodePageIdentifier(Charset charset) {
|
||||
final String s_charset = charset.name();
|
||||
if (s_charset.equalsIgnoreCase("utf-8")) // Unicode
|
||||
return 65001;
|
||||
else if (s_charset.equalsIgnoreCase("ibm437")) // US
|
||||
return 437;
|
||||
else if (s_charset.equalsIgnoreCase("ibm850")) // OEM Multilingual Latin
|
||||
// 1
|
||||
return 850;
|
||||
else if (s_charset.equalsIgnoreCase("ibm852")) // OEM Latin2
|
||||
return 852;
|
||||
else if (s_charset.equalsIgnoreCase("shift_jis") || s_charset.equalsIgnoreCase("windows-31j")) // Japanese
|
||||
return 932;
|
||||
else if (s_charset.equalsIgnoreCase("us-ascii")) // US-ASCII
|
||||
return 20127;
|
||||
else if (s_charset.equalsIgnoreCase("euc-jp")) // Japanese
|
||||
return 20932;
|
||||
else if (s_charset.equalsIgnoreCase("iso-8859-1")) // Latin 1
|
||||
return 28591;
|
||||
else if (s_charset.equalsIgnoreCase("iso-8859-2")) // Latin 2
|
||||
return 28592;
|
||||
else if (s_charset.equalsIgnoreCase("IBM00858"))
|
||||
return 858;
|
||||
else if (s_charset.equalsIgnoreCase("IBM775"))
|
||||
return 775;
|
||||
else if (s_charset.equalsIgnoreCase("IBM855"))
|
||||
return 855;
|
||||
else if (s_charset.equalsIgnoreCase("IBM857"))
|
||||
return 857;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-4"))
|
||||
return 28594;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-5"))
|
||||
return 28595;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-7"))
|
||||
return 28597;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-9"))
|
||||
return 28599;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-13"))
|
||||
return 28603;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-15"))
|
||||
return 28605;
|
||||
else if (s_charset.equalsIgnoreCase("KOI8-R"))
|
||||
return 20866;
|
||||
else if (s_charset.equalsIgnoreCase("KOI8-U"))
|
||||
return 21866;
|
||||
else if (s_charset.equalsIgnoreCase("UTF-16"))
|
||||
return 1200;
|
||||
else if (s_charset.equalsIgnoreCase("UTF-32"))
|
||||
return 12000;
|
||||
else if (s_charset.equalsIgnoreCase("UTF-32BE"))
|
||||
return 12001;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1250"))
|
||||
return 1250;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1251"))
|
||||
return 1251;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1252"))
|
||||
return 1252;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1253"))
|
||||
return 1253;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1254"))
|
||||
return 1254;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1257"))
|
||||
return 1257;
|
||||
else if (s_charset.equalsIgnoreCase("Big5"))
|
||||
return 950;
|
||||
else if (s_charset.equalsIgnoreCase("EUC-KR"))
|
||||
return 51949;
|
||||
else if (s_charset.equalsIgnoreCase("GB18030"))
|
||||
return 54936;
|
||||
else if (s_charset.equalsIgnoreCase("GB2312"))
|
||||
return 936;
|
||||
else if (s_charset.equalsIgnoreCase("IBM-Thai"))
|
||||
return 20838;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01140"))
|
||||
return 1140;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01141"))
|
||||
return 1141;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01142"))
|
||||
return 1142;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01143"))
|
||||
return 1143;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01144"))
|
||||
return 1144;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01145"))
|
||||
return 1145;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01146"))
|
||||
return 1146;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01147"))
|
||||
return 1147;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01148"))
|
||||
return 1148;
|
||||
else if (s_charset.equalsIgnoreCase("IBM01149"))
|
||||
return 1149;
|
||||
else if (s_charset.equalsIgnoreCase("IBM037"))
|
||||
return 37;
|
||||
else if (s_charset.equalsIgnoreCase("IBM1026"))
|
||||
return 1026;
|
||||
else if (s_charset.equalsIgnoreCase("IBM273"))
|
||||
return 20273;
|
||||
else if (s_charset.equalsIgnoreCase("IBM277"))
|
||||
return 20277;
|
||||
else if (s_charset.equalsIgnoreCase("IBM278"))
|
||||
return 20278;
|
||||
else if (s_charset.equalsIgnoreCase("IBM280"))
|
||||
return 20280;
|
||||
else if (s_charset.equalsIgnoreCase("IBM284"))
|
||||
return 20284;
|
||||
else if (s_charset.equalsIgnoreCase("IBM285"))
|
||||
return 20285;
|
||||
else if (s_charset.equalsIgnoreCase("IBM297"))
|
||||
return 20297;
|
||||
else if (s_charset.equalsIgnoreCase("IBM420"))
|
||||
return 20420;
|
||||
else if (s_charset.equalsIgnoreCase("IBM424"))
|
||||
return 20424;
|
||||
else if (s_charset.equalsIgnoreCase("IBM500"))
|
||||
return 500;
|
||||
else if (s_charset.equalsIgnoreCase("IBM860"))
|
||||
return 860;
|
||||
else if (s_charset.equalsIgnoreCase("IBM861"))
|
||||
return 861;
|
||||
else if (s_charset.equalsIgnoreCase("IBM863"))
|
||||
return 863;
|
||||
else if (s_charset.equalsIgnoreCase("IBM864"))
|
||||
return 864;
|
||||
else if (s_charset.equalsIgnoreCase("IBM865"))
|
||||
return 865;
|
||||
else if (s_charset.equalsIgnoreCase("IBM869"))
|
||||
return 869;
|
||||
else if (s_charset.equalsIgnoreCase("IBM870"))
|
||||
return 870;
|
||||
else if (s_charset.equalsIgnoreCase("IBM871"))
|
||||
return 20871;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-2022-JP"))
|
||||
return 50220;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-2022-KR"))
|
||||
return 50225;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-3"))
|
||||
return 28593;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-6"))
|
||||
return 28596;
|
||||
else if (s_charset.equalsIgnoreCase("ISO-8859-8"))
|
||||
return 28598;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1255"))
|
||||
return 1255;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1256"))
|
||||
return 1256;
|
||||
else if (s_charset.equalsIgnoreCase("windows-1258"))
|
||||
return 1258;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,17 @@ package io.jenkins.plugins.sample;
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import hudson.console.LineTransformationOutputStream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
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.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -40,11 +44,11 @@ import java.util.regex.Pattern;
|
||||
public class PBAutoBuildConsoleParser extends LineTransformationOutputStream {
|
||||
private final OutputStream out;
|
||||
private final Charset charset;
|
||||
|
||||
private int numberOfWarnings = -1;
|
||||
private int numberOfErrors = -1;
|
||||
|
||||
private boolean verboseLogging = false;
|
||||
private final String workspace;
|
||||
|
||||
private List<String> warnings = new ArrayList<>();
|
||||
private List<String> errors = new ArrayList<>();
|
||||
|
||||
private final Pattern patternWarnings = Pattern.compile(".*\\d+\\sWarning\\(s\\).*");
|
||||
private final Pattern patternErrors = Pattern.compile(".*\\d+\\sError\\(s\\).*");
|
||||
@@ -61,87 +65,67 @@ public class PBAutoBuildConsoleParser extends LineTransformationOutputStream {
|
||||
|
||||
// Pattern per i file (solo nome, escludendo il percorso)
|
||||
private Pattern fileNamePattern = Pattern.compile("([^\\\\]+\\.\\w+)$");
|
||||
private Pattern timestampPattern = Pattern.compile("(^\\d{2}:\\d{2}:\\d{2})");
|
||||
|
||||
// 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*\\](.*)");
|
||||
|
||||
|
||||
public PBAutoBuildConsoleParser(OutputStream out, Charset charset, boolean verboseLogging) {
|
||||
public PBAutoBuildConsoleParser(OutputStream out, Charset charset, boolean verboseLogging, String workspace) {
|
||||
this.out = out;
|
||||
this.charset = charset;
|
||||
this.verboseLogging = verboseLogging;
|
||||
this.workspace = workspace + File.separator;
|
||||
}
|
||||
|
||||
public int getNumberOfWarnings() {
|
||||
return numberOfWarnings;
|
||||
public List<String> getWarnings() {
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public int getNumberOfErrors() {
|
||||
return numberOfErrors;
|
||||
public List<String> getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void eol(byte[] b, int len) throws IOException {
|
||||
String line = charset.decode(ByteBuffer.wrap(b, 0, len)).toString();
|
||||
byte[] bytes1 = line.getBytes(charset);
|
||||
line = line.replace("\0", "").trim();
|
||||
|
||||
String lineUtf16 = StandardCharsets.UTF_16.decode(ByteBuffer.wrap(b, 0, len)).toString();
|
||||
if (line.isEmpty()) return;
|
||||
|
||||
boolean isUtf16 = true;
|
||||
for(int i = 0; i < bytes1.length; i = i+2) {
|
||||
if(bytes1[i] != 0) {
|
||||
isUtf16 = false;
|
||||
break;
|
||||
}
|
||||
final String errorMessage = extractData(line, errorPattern);
|
||||
|
||||
if (errorMessage != null) { // Match the number of warnings
|
||||
errors.add(errorMessage);
|
||||
}
|
||||
|
||||
if(isUtf16) {
|
||||
line = lineUtf16;
|
||||
}
|
||||
|
||||
// trim off CR/LF from the end
|
||||
line = trimEOL(line);
|
||||
|
||||
if(line.isEmpty()) return;
|
||||
|
||||
Matcher mWarnings = patternWarnings.matcher(line);
|
||||
Matcher mErrors = patternErrors.matcher(line);
|
||||
|
||||
if (mWarnings.matches()) { // Match the number of warnings
|
||||
String[] part = line.split(" ");
|
||||
try {
|
||||
numberOfWarnings = Integer.parseInt(part[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
} else if (mErrors.matches()) { // Match the number of errors
|
||||
String[] part = line.split(" ");
|
||||
try {
|
||||
numberOfErrors = Integer.parseInt(part[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
// Warning messages handler
|
||||
final String warningMessage = extractData(line, warningPattern);
|
||||
if (warningMessage != null) { // Match the number of warnings
|
||||
warnings.add(warningMessage);
|
||||
}
|
||||
|
||||
// Write to output
|
||||
if(verboseLogging)
|
||||
out.write(b, 0, len);
|
||||
else {
|
||||
if (verboseLogging) {
|
||||
line += "\r\n";
|
||||
byte[] b1 = line.getBytes(charset);
|
||||
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 filename = extractFileNames(line, fileNamePattern);
|
||||
String stage = extractStages(line, stagePattern);
|
||||
String timestamp = extractData(line, timestampPattern);
|
||||
|
||||
if(line.contains("[Normal]")) {
|
||||
//if(line.contains("\\"))
|
||||
// line = line.substring(line.lastIndexOf("\\"));
|
||||
line = line.replace(workspace, "")
|
||||
.replace("\t", " ");
|
||||
|
||||
byte[] bytesToWrite = line.getBytes(charset);
|
||||
out.write(bytesToWrite, 0, bytesToWrite.length);
|
||||
}
|
||||
if (timestamp != null && !timestamp.isEmpty())
|
||||
line = line.replace(timestamp, "").trim();
|
||||
|
||||
|
||||
line += "\r\n";
|
||||
byte[] bytesToWrite = line.getBytes();
|
||||
out.write(bytesToWrite, 0, bytesToWrite.length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +136,6 @@ public class PBAutoBuildConsoleParser extends LineTransformationOutputStream {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String extractData(String log, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(log);
|
||||
if (matcher.matches()) {
|
||||
|
||||
@@ -19,8 +19,6 @@ public class PBAutoBuildErrorNote extends ConsoleNote {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3278523238642788774L;
|
||||
/** Pattern to identify error messages */
|
||||
public final static Pattern PATTERN = Pattern.compile("(.*)[Ee]rror\\s(([A-Z]*)\\d+){0,1}:\\s(.*)");
|
||||
|
||||
public PBAutoBuildErrorNote() {
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ public class PBAutoBuildWarningNote extends ConsoleNote {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 5058082724408336863L;
|
||||
/** Pattern to identify warning messages */
|
||||
public final static Pattern PATTERN = Pattern.compile("(.*)\\(\\d+(,\\d+){0,1}\\):\\s[Ww]arning\\s(([A-Z]*)\\d+){0,1}:\\s(.*)");
|
||||
|
||||
public PBAutoBuildWarningNote() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user