Skip to content

Commit

Permalink
Merge pull request #10 from recena/JENKINS-27208
Browse files Browse the repository at this point in the history
[JENKINS-27208] Compatible with Workflow
  • Loading branch information
recena committed Oct 13, 2015
2 parents 398c0ef + 4fcb6fb commit 7cce021
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 70 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.7</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
16 changes: 10 additions & 6 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 @@ -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,9 @@ 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 {
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
110 changes: 58 additions & 52 deletions src/main/java/hudson/plugins/logparser/LogParserPublisher.java
Expand Up @@ -2,11 +2,14 @@

import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.Action;
import hudson.model.BuildListener;
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,18 +22,21 @@
import java.util.logging.Level;
import java.util.logging.Logger;

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

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
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;
public final boolean showGraphs;
public final String parsingRulesPath;
public final boolean useProjectRule;
public final String projectRulePath;
public boolean unstableOnWarning;
public boolean failBuildOnError;
public boolean showGraphs;
public String parsingRulesPath = null;
public boolean useProjectRule;
public String projectRulePath = null;

/**
* Create new LogParserPublisher.
Expand All @@ -48,6 +54,7 @@ public class LogParserPublisher extends Recorder implements Serializable {
* @param projectRulePath
* path to project specific rules relative to workspace root.
*/
@Deprecated
private LogParserPublisher(final boolean unstableOnWarning,
final boolean failBuildOnError, final boolean showGraphs,
final String parsingRulesPath, final boolean useProjectRule,
Expand All @@ -61,32 +68,65 @@ private LogParserPublisher(final boolean unstableOnWarning,
this.projectRulePath = projectRulePath;
}

@DataBoundConstructor
public LogParserPublisher(boolean useProjectRule, String projectRulePath, String parsingRulesPath) {
super();
if (useProjectRule) {
this.projectRulePath = Util.fixEmpty(projectRulePath);
this.parsingRulesPath = null;
} else {
this.parsingRulesPath = Util.fixEmpty(parsingRulesPath);
this.projectRulePath = null;
}
this.useProjectRule = useProjectRule;
}

@DataBoundSetter
public void setUnstableOnWarning(boolean unstableOnWarning) {
this.unstableOnWarning = unstableOnWarning;
}

@DataBoundSetter
public void setFailBuildOnError(boolean failBuildOnError) {
this.failBuildOnError = failBuildOnError;
}

@DataBoundSetter
public void setShowGraphs(boolean showGraphs) {
this.showGraphs = showGraphs;
}

@Override
public boolean prebuild(final AbstractBuild<?, ?> build,
final BuildListener listener) {
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<?, ?> build, 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);

Expand Down Expand Up @@ -116,9 +156,7 @@ public boolean perform(final AbstractBuild<?, ?> build,

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

return true;
build.addAction(action);
}

@Override
Expand Down Expand Up @@ -171,38 +209,6 @@ public boolean configure(final StaplerRequest req, final JSONObject json)
save();
return true;
}

/**
* Cannot use simple DataBoundConstructor due to radioBlock usage where
* a JSON object is returned holding the selected value of the block.
*
* {@inheritDoc}
*/
@Override
public LogParserPublisher newInstance(StaplerRequest req,
JSONObject json) throws FormException {

String configuredParsingRulesPath = null;
String configuredProjectRulePath = null;
boolean configuredUseProjectRule = false;
final JSONObject useProjectRuleJSON = json.getJSONObject("useProjectRule");

if (useProjectRuleJSON != null) {
configuredUseProjectRule = useProjectRuleJSON.getBoolean("value");

if (!configuredUseProjectRule && useProjectRuleJSON.containsKey("parsingRulesPath")) {
configuredParsingRulesPath = useProjectRuleJSON.getString("parsingRulesPath");
} else if (configuredUseProjectRule && useProjectRuleJSON.containsKey("projectRulePath")) {
configuredProjectRulePath = useProjectRuleJSON.getString("projectRulePath");
}
}
return new LogParserPublisher(json.getBoolean("unstableOnWarning"),
json.getBoolean("failBuildOnError"),
json.getBoolean("showGraphs"),
configuredParsingRulesPath,
configuredUseProjectRule,
configuredProjectRulePath);
}
}

public BuildStepMonitor getRequiredMonitorService() {
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
9 changes: 6 additions & 3 deletions src/main/java/hudson/plugins/logparser/LogParserUtils.java
Expand Up @@ -13,9 +13,12 @@

public final class LogParserUtils {

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

public static boolean skipParsingRule(final String parsingRule) {
Expand Down
Expand Up @@ -9,7 +9,7 @@
<f:entry title="Show log parser graphs" help="/plugin/log-parser/parser_graphs.html">
<f:checkbox name="log-parser.showGraphs" checked="${instance.showGraphs}"/>
</f:entry>
<f:radioBlock title="Use global rule" name="log-parser.useProjectRule" value="false" checked="${instance.useProjectRule!=true}">
<f:radioBlock title="Use global rule" name="log-parser.useProjectRule" value="false" checked="${instance.useProjectRule!=true}" inline="true">
<f:entry title="Select Parsing Rules" field="currentRulePath" help="/plugin/log-parser/parse_rule_choice.html">
<select name="log-parser.parsingRulesPath">
<j:forEach var="i" items="${descriptor.parsingRulesGlobal}">
Expand All @@ -18,7 +18,7 @@
</select>
</f:entry>
</f:radioBlock>
<f:radioBlock title="Use project rule" name="log-parser.useProjectRule" value="true" checked="${instance.useProjectRule==true}">
<f:radioBlock title="Use project rule" name="log-parser.useProjectRule" value="true" checked="${instance.useProjectRule==true}" inline="true">
<f:entry title="Path to rule file in workspace" field="projectRulePath">
<f:textbox/>
</f:entry>
Expand Down

0 comments on commit 7cce021

Please sign in to comment.