Skip to content

Commit

Permalink
Merge branch 'master' into feature/jcasc-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Jun 24, 2019
2 parents 9c9a98c + 26b99d5 commit 396c4be
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 73 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public static boolean shouldScan(Run build) {
*/
public static boolean isSizeInLimit(Run build) {
return getInstance().getMaxLogSize() == 0
|| getInstance().getMaxLogSize() > (build.getLogFile().length() / BYTES_IN_MEGABYTE);
|| getInstance().getMaxLogSize() > (build.getLogText().length() / BYTES_IN_MEGABYTE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.sonyericsson.jenkins.plugins.bfa;

import hudson.model.Run;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nonnull;
import jenkins.model.RunAction2;
import org.apache.commons.io.FileUtils;

/**
* The Action for adding a link to the analysis for each run.
*/
public class ScanLogAction implements RunAction2 {

/**
* Log file name.
*/
public static final String FILE_NAME = "com.sonyericsson.jenkins.plugins.bfa.ScanLogAction.log";

private transient Run run;

/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getIconFileName() {
return PluginImpl.getDefaultIcon();
}

/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getDisplayName() {
return Messages.ScanLogAction_DisplayName();
}

/**
* The run associated with this action, called by jelly.
* @return the run
*/
public Run getRun() {
return run;
}

/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getUrlName() {
return "failure-cause-scan-log";
}

/**
* Log text for the analysis.
* @return the log text, lines are separated by \n
* @throws IOException if the log can't be found
*/
public String getLogText() throws IOException {
return FileUtils.readFileToString(new File(run.getRootDir(), FILE_NAME), StandardCharsets.UTF_8);
}

/**
* {@inheritDoc}
*/
@Override
public void onAttached(Run<?, ?> r) {
this.run = r;
}

/**
* {@inheritDoc}
*/
@Override
public void onLoad(Run<?, ?> r) {
this.run = r;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public BuildLogFailureReader(BuildLogIndication indication) {
*/
@Override
public FoundIndication scan(Run build) throws IOException {
String currentFile = build.getLogFile().getName();
BufferedReader reader = null;
try {
reader = new BufferedReader(build.getLogReader());
Expand All @@ -74,7 +73,7 @@ public FoundIndication scan(Run build) throws IOException {
List<FoundFailureCause> foundFailureCauses = FailureReader.scanSingleLinePatterns(causes,
build,
reader,
currentFile);
"log");
if (foundFailureCauses.isEmpty()) {
return null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ public MultilineBuildLogFailureReader(MultilineBuildLogIndication indication) {
*/
@Override
public FoundIndication scan(Run build) throws IOException {
String currentfile = build.getLogFile().getName();
BufferedReader reader = null;
try {
reader = new BufferedReader(build.getLogReader());
return scanMultiLineOneFile(build, reader, currentfile);
return scanMultiLineOneFile(build, reader, "log");
} finally {
if (reader != null) {
try {
Expand All @@ -89,12 +88,11 @@ public FoundIndication scan(Run build) throws IOException {
*/
public FoundIndication scan(Run build, PrintStream buildLog) {
FoundIndication foundIndication = null;
String currentFile = build.getLogFile().getName();
BufferedReader reader = null;
long start = System.currentTimeMillis();
try {
reader = new BufferedReader(build.getLogReader());
foundIndication = scanMultiLineOneFile(build, reader, currentFile);
foundIndication = scanMultiLineOneFile(build, reader, "log");
} catch (IOException ioe) {
logger.log(Level.SEVERE, "[BFA] I/O problems during indication analysis: ", ioe);
buildLog.println("[BFA] I/O problems during indication analysis.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.sonyericsson.jenkins.plugins.bfa.sod;

import com.sonyericsson.jenkins.plugins.bfa.ScanLogAction;
import com.sonyericsson.jenkins.plugins.bfa.model.FailureCauseBuildAction;
import com.sonyericsson.jenkins.plugins.bfa.model.FailureCauseMatrixBuildAction;
import com.sonyericsson.jenkins.plugins.bfa.BuildFailureScanner;
Expand All @@ -31,6 +32,7 @@
import hudson.matrix.MatrixRun;
import hudson.model.Run;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand Down Expand Up @@ -105,23 +107,16 @@ public void endMatrixBuildScan() throws IOException {
* @param run the non-scanned/scanned build to scan/rescan.
*/
public void scanBuild(Run run) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(run.getLogFile(), true);
PrintStream buildLog = new PrintStream(fos, true, "UTF8");
File file = new File(run.getRootDir(), ScanLogAction.FILE_NAME);
try (
FileOutputStream fos = new FileOutputStream(file, true);
PrintStream buildLog = new PrintStream(fos, true, "UTF8")
) {
PluginImpl.getInstance().getKnowledgeBase().removeBuildfailurecause(run);
BuildFailureScanner.scanIfNotScanned(run, buildLog);
run.save();
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not get the causes from the knowledge base", e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
logger.log(Level.WARNING, "Failed to close the build log file " + run.getLogFile(), e);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PermissionRemove_Description=Remove Failure causes.
BuildLogIndication_DisplayName=Build Log Indication
MultilineBuildLogIndication_DisplayName=Multi-Line Build Log Indication
CauseManagement_DisplayName=Failure Cause Management
ScanLogAction_DisplayName=Failure Scan Log
CauseList_DisplayName=Failure Causes
ScannerJobProperty_DisplayName=Do not Scan failed builds
LocalFileKnowledgeBase_DisplayName=Jenkins Local
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<l:layout title="Failure Cause Scan Log">
<st:include page="sidepanel.jelly" it="${it.run}"/>
<l:main-panel>
<h1>
${%Failure Cause Scan Log}
</h1>
<pre>${it.getLogText()}</pre>
</l:main-panel>
</l:layout>
</j:jelly>

0 comments on commit 396c4be

Please sign in to comment.