Skip to content

Commit

Permalink
[JENKINS-27208] Initial source code modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
recena committed Sep 27, 2015
1 parent 398c0ef commit 7847264
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 38 deletions.
16 changes: 15 additions & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/hudson/plugins/logparser/LogParserAction.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

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

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

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

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

while (true) {

Expand Down
25 changes: 18 additions & 7 deletions src/main/java/hudson/plugins/logparser/LogParserParser.java
Expand Up @@ -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;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class LogParserParser {

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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
52 changes: 29 additions & 23 deletions src/main/java/hudson/plugins/logparser/LogParserPublisher.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +44,7 @@ private HashMap<String, String> computeStatusMatches(
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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/logparser/LogParserUtils.java
Expand Up @@ -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");
}

Expand Down

0 comments on commit 7847264

Please sign in to comment.