Skip to content
Permalink
Browse files

[JENKINS-27208] Initial source code modifications

  • Loading branch information
recena committed Sep 27, 2015
1 parent 398c0ef commit 7847264fcf1605a4f1405ec8f7d53969d9430772
16 pom.xml
@@ -7,12 +7,17 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.455</version>
<version>1.596.1</version>
</parent>
<artifactId>log-parser</artifactId>
<packaging>hpi</packaging>
<version>1.1-SNAPSHOT</version>
<name>Log Parser Plugin</name>

<properties>
<workflow-jenkins-plugin.version>1.4</workflow-jenkins-plugin.version>
</properties>

<reporting>
<plugins>
<plugin>
@@ -47,6 +52,15 @@
<email>jborghi@java.net</email>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- see http://groups.google.com/group/hudson-dev/browse_thread/thread/83e34c639eec470a
for the rationale behind this -->
<build>
@@ -3,6 +3,7 @@
import hudson.Functions;
import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.util.Area;
import hudson.util.ChartUtil;
import hudson.util.ColorPalette;
@@ -31,13 +32,17 @@

public class LogParserAction implements Action {

final private AbstractBuild<?, ?> build;
final private Run<?, ?> build;
final private LogParserResult result;

private static String urlName = "parsed_console";

public LogParserAction(final AbstractBuild<?, ?> build,
final LogParserResult result) {
@Deprecated
public LogParserAction(final AbstractBuild<?, ?> build, final LogParserResult result) {
this((Run<?, ?>) build, result);
}

public LogParserAction(final Run<?, ?> build, final LogParserResult result) {
this.build = build;
this.result = result;

@@ -59,7 +64,7 @@ public static String getUrlNameStat() {
return urlName;
}

public AbstractBuild<?, ?> getOwner() {
public Run<?, ?> getOwner() {
return build;
}

@@ -70,7 +75,7 @@ public LogParserResult getResult() {
}

public LogParserAction getPreviousAction() {
AbstractBuild<?, ?> build = this.getOwner();
Run<?, ?> build = this.getOwner();

while (true) {

@@ -3,6 +3,7 @@
import hudson.FilePath;
import hudson.console.ConsoleNote;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.remoting.VirtualChannel;

import java.io.BufferedReader;
@@ -40,7 +41,7 @@

public LogParserParser(final FilePath parsingRulesFile,
final boolean preformattedHtml, final VirtualChannel channel)
throws IOException {
throws IOException, InterruptedException {

// init logger
final Logger logger = Logger.getLogger(getClass().getName());
@@ -69,8 +70,12 @@ public LogParserParser(final FilePath parsingRulesFile,
* lists of links to these errors/warnings/info messages respectively :
* errorLinks.html, warningLinks.html, infoLinks.html
*/
public LogParserResult parseLog(final AbstractBuild build)
throws IOException, InterruptedException {
@Deprecated
public LogParserResult parseLog(final AbstractBuild build) throws IOException, InterruptedException {
return this.parseLog((Run<?, ?>) build);
}

public LogParserResult parseLog(final Run<?, ?> build) throws IOException, InterruptedException {

// init logger
final Logger logger = Logger.getLogger(getClass().getName());
@@ -292,10 +297,16 @@ private String addMarkerAndLink(final String line,
return markedLine.toString();
}

private void parseLogBody(final AbstractBuild build,
final BufferedWriter writer, final FilePath filePath,
final String logFileLocation, final int linesInLog,
final Logger logger) throws IOException, InterruptedException {
@Deprecated
private void parseLogBody(final AbstractBuild build, final BufferedWriter writer, final FilePath filePath, final
String logFileLocation, final int linesInLog, final Logger logger) throws IOException, InterruptedException {

this.parseLogBody((Run<?, ?>) build, writer, filePath, logFileLocation, linesInLog, logger);
}

private void parseLogBody(final Run<?, ?> build, final BufferedWriter writer, final FilePath filePath, final
String logFileLocation, final int linesInLog, final Logger logger) throws IOException, InterruptedException {

// Logging information - start
final String signature = build.getParent().getName() + "_build_"
+ build.getNumber();
@@ -7,6 +7,8 @@
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.logparser.action.LogParserProjectAction;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
@@ -19,11 +21,12 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.StaplerRequest;

public class LogParserPublisher extends Recorder implements Serializable {
public class LogParserPublisher extends Recorder implements SimpleBuildStep, Serializable {
private static final long serialVersionUID = 1L;
public final boolean unstableOnWarning;
public final boolean failBuildOnError;
@@ -67,58 +70,61 @@ public boolean prebuild(final AbstractBuild<?, ?> build,
return true;
}

@Deprecated
@Override
public boolean perform(final AbstractBuild<?, ?> build,
final Launcher launcher, final BuildListener listener)
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
throws InterruptedException, IOException {

this.perform((Run<?, ?>) build, build.getWorkspace(), launcher, listener);
return true;
}

@Override
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws
InterruptedException, IOException {

final Logger logger = Logger.getLogger(getClass().getName());
LogParserResult result = new LogParserResult();
try {
// Create a parser with the parsing rules as configured : colors,
// regular expressions, etc.
boolean preformattedHtml = !((DescriptorImpl) getDescriptor())
.getLegacyFormatting();
// Create a parser with the parsing rules as configured : colors, regular expressions, etc.
boolean preformattedHtml = !((DescriptorImpl) getDescriptor()).getLegacyFormatting();
final FilePath parsingRulesFile;
if (useProjectRule) {
parsingRulesFile = new FilePath(build.getWorkspace(),
projectRulePath);
parsingRulesFile = new FilePath(workspace, projectRulePath);
} else {
parsingRulesFile = new FilePath(new File(parsingRulesPath));
}
final LogParserParser parser = new LogParserParser(
parsingRulesFile, preformattedHtml, launcher.getChannel());
final LogParserParser parser = new LogParserParser(parsingRulesFile, preformattedHtml, launcher.getChannel());
// Parse the build's log according to these rules and get the result
result = parser.parseLog(build);
result = parser.parseLog(run);

// Mark build as failed/unstable if necessary
if (this.failBuildOnError && result.getTotalErrors() > 0) {
build.setResult(Result.FAILURE);
run.setResult(Result.FAILURE);
} else if (this.unstableOnWarning && result.getTotalWarnings() > 0) {
build.setResult(Result.UNSTABLE);
run.setResult(Result.UNSTABLE);
}
} catch (IOException e) {
// Failure to parse should not fail the build - but should be
// handled as a serious error.
// This should catch all process problems during parsing, including
// parser file not found..
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + build, e);
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + run, e);
result.setFailedToParseError(e.toString());
} catch (NullPointerException e) {
// in case the rules path is null
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + build, e);
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + run, e);
result.setFailedToParseError(e.toString());
build.setResult(Result.ABORTED);
run.setResult(Result.ABORTED);
} catch (InterruptedException e) {
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + build, e);
logger.log(Level.SEVERE, LogParserConsts.CANNOT_PARSE + run, e);
result.setFailedToParseError(e.toString());
build.setResult(Result.ABORTED);
run.setResult(Result.ABORTED);
}

// Add an action created with the above results
final LogParserAction action = new LogParserAction(build, result);
build.getActions().add(0, action);

return true;
final LogParserAction action = new LogParserAction(run, result);
run.addAction(action);
}

@Override
@@ -3,6 +3,7 @@
import hudson.FilePath;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import jenkins.security.MasterToSlaveCallable;

import java.io.BufferedReader;
import java.io.File;
@@ -43,7 +44,7 @@ public LogParserStatusComputer(final VirtualChannel channel,
HashMap<String, String> result = null;

result = channel
.call(new Callable<HashMap<String, String>, RuntimeException>() {
.call(new MasterToSlaveCallable<HashMap<String, String>, RuntimeException>() {

private static final long serialVersionUID = 1L;

@@ -14,7 +14,7 @@
public final class LogParserUtils {

public static String[] readParsingRules(final FilePath parsingRulesFile)
throws IOException {
throws IOException, InterruptedException {
return parsingRulesFile.readToString().split("\n");
}

0 comments on commit 7847264

Please sign in to comment.