Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.

Commit 67406a1

Browse files
Added back fixed LogFileFilterStep
1 parent 2ff4b62 commit 67406a1

File tree

5 files changed

+199
-48
lines changed

5 files changed

+199
-48
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/.classpath
44
/.project
55
/pom.xml.bak
6+
/.settings/

pom.xml

+15-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<properties>
1515
<!-- Baseline Jenkins version you use to build the plugin. Users must have
1616
this version or newer to run. -->
17-
<jenkins.version>1.642.1</jenkins.version>
17+
<jenkins.version>1.642.3</jenkins.version>
1818
<!-- Java Level to use. Java 7 required when using core >= 1.612 -->
1919
<java.level>7</java.level>
2020
<!-- Jenkins Test Harness version you use to test the plugin. -->
@@ -109,4 +109,18 @@
109109
</pluginManagement>
110110
</build>
111111

112+
<dependencies>
113+
<dependency>
114+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
115+
<artifactId>workflow-step-api</artifactId>
116+
<version>2.4</version>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
120+
<artifactId>workflow-aggregator</artifactId>
121+
<version>2.5</version>
122+
<scope>test</scope>
123+
</dependency>
124+
</dependencies>
125+
112126
</project>
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
package com.tsystems.sbs;
2-
3-
import java.util.Arrays;
4-
import java.util.Collections;
5-
import java.util.LinkedHashSet;
6-
import java.util.Set;
7-
import java.util.logging.Level;
8-
import java.util.regex.Matcher;
9-
import java.util.regex.Pattern;
10-
11-
/**
12-
* The default regexes (which use is activated by the checkbox 'Default regexp') are defined in this class.
13-
*
14-
* @author ccapdevi
15-
*
16-
*/
17-
public final class DefaultRegexpPairs {
18-
19-
private final static Set<RegexpPair> DEFAULT_REGEXES
20-
= Collections.unmodifiableSet(
21-
new LinkedHashSet<RegexpPair>(Arrays.asList(
22-
new RegexpPair("(https?+://[^:\\s]++):[^@\\s]++@", "$1:********@"),//Passwd URL MASKING
23-
new RegexpPair("-password=\\S*", "-password=********") //PASSWORD MASKING
24-
)));
25-
26-
public static Set<RegexpPair> getDefaultRegexes() {
27-
return DEFAULT_REGEXES;
28-
}
29-
}
1+
package com.tsystems.sbs;
2+
3+
import java.util.Arrays;
4+
import java.util.Collections;
5+
import java.util.LinkedHashSet;
6+
import java.util.Set;
7+
8+
/**
9+
* The default regexes (which use is activated by the checkbox 'Default regexp') are defined in this class.
10+
*
11+
* @author ccapdevi
12+
*
13+
*/
14+
public final class DefaultRegexpPairs {
15+
16+
private final static Set<RegexpPair> DEFAULT_REGEXES
17+
= Collections.unmodifiableSet(
18+
new LinkedHashSet<RegexpPair>(Arrays.asList(
19+
new RegexpPair("(https?+://[^:\\s]++):[^@\\s]++@", "$1:********@"),//Passwd URL MASKING
20+
new RegexpPair("-password=\\S*", "-password=********") //PASSWORD MASKING
21+
)));
22+
23+
public static Set<RegexpPair> getDefaultRegexes() {
24+
return DEFAULT_REGEXES;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,59 @@
1-
package com.tsystems.sbs;
2-
3-
import java.io.IOException;
4-
import java.io.OutputStream;
5-
6-
import hudson.Extension;
7-
import hudson.console.ConsoleLogFilter;
8-
import hudson.model.Run;
9-
10-
@Extension
11-
public class LogFileFilterConsoleLogFilter extends ConsoleLogFilter {
12-
13-
@Override
14-
public OutputStream decorateLogger(Run build, OutputStream logger) throws IOException, InterruptedException {
15-
return new LogFileFilterOutputStream(logger, build.getCharset(), build.getFullDisplayName());
16-
}
17-
18-
}
1+
package com.tsystems.sbs;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
import java.io.Serializable;
6+
import java.nio.charset.Charset;
7+
8+
import hudson.Extension;
9+
import hudson.console.ConsoleLogFilter;
10+
import hudson.model.Run;
11+
12+
@Extension
13+
public class LogFileFilterConsoleLogFilter extends ConsoleLogFilter implements Serializable {
14+
15+
private static final long serialVersionUID = 1L;
16+
17+
@Override
18+
public OutputStream decorateLogger(Run build, OutputStream logger) throws IOException, InterruptedException {
19+
if(logger == null)
20+
return null;
21+
22+
Charset charset = null;
23+
String displayName = null;
24+
if (build != null) {
25+
charset = build.getCharset();
26+
displayName = build.getFullDisplayName();
27+
} else {
28+
charset = Charset.defaultCharset();
29+
displayName = "LogFileFilterLogger";
30+
}
31+
32+
return new LogFileFilterOutputStream(logger, charset, displayName);
33+
}
34+
35+
//Overriding this method allows filtering the logs of the slaves (master-slave communication)
36+
/*
37+
@Override
38+
public OutputStream decorateLogger(Computer computer, OutputStream logger)
39+
throws IOException, InterruptedException {
40+
if(logger == null)
41+
return null;
42+
43+
Charset charset = null;
44+
String displayName = null;
45+
if (computer != null) {
46+
charset = computer.getDefaultCharset();
47+
displayName = computer.getDisplayName();
48+
} else {
49+
charset = Charset.defaultCharset();
50+
displayName = "LogFileFilterLogger";
51+
}
52+
53+
if(charset == null)
54+
charset = put some default charset here?
55+
56+
return new LogFileFilterOutputStream(logger, charset, displayName);
57+
}*/
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.tsystems.sbs;
2+
3+
import java.io.IOException;
4+
5+
import javax.annotation.Nonnull;
6+
7+
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
8+
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
9+
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
10+
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
11+
import org.jenkinsci.plugins.workflow.steps.BodyInvoker;
12+
import org.jenkinsci.plugins.workflow.steps.StepContext;
13+
import org.kohsuke.stapler.DataBoundConstructor;
14+
15+
import com.google.inject.Inject;
16+
17+
import hudson.Extension;
18+
import hudson.console.ConsoleLogFilter;
19+
20+
/**
21+
* Custom pipeline step that can be used without a node and build wrapper.
22+
*/
23+
public class LogFileFilterStep extends AbstractStepImpl {
24+
25+
@DataBoundConstructor
26+
public LogFileFilterStep() {}
27+
28+
/**
29+
* Execution for {@link LogFileFilterStep}.
30+
*/
31+
public static class ExecutionImpl extends AbstractStepExecutionImpl {
32+
33+
private static final long serialVersionUID = 1L;
34+
35+
@Inject(optional = true)
36+
private transient LogFileFilterStep step;
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
@Override
42+
public boolean start() throws Exception {
43+
StepContext context = getContext();
44+
context.newBodyInvoker().withContext(createConsoleLogFilter(context))
45+
.withCallback(BodyExecutionCallback.wrap(context)).start();
46+
return false;
47+
}
48+
49+
private ConsoleLogFilter createConsoleLogFilter(StepContext context)
50+
throws IOException, InterruptedException {
51+
ConsoleLogFilter original = context.get(ConsoleLogFilter.class);
52+
ConsoleLogFilter subsequent = new LogFileFilterConsoleLogFilter();
53+
return BodyInvoker.mergeConsoleLogFilters(original, subsequent);
54+
}
55+
56+
/**
57+
* {@inheritDoc}
58+
*/
59+
@Override
60+
public void stop(@Nonnull Throwable cause) throws Exception {
61+
getContext().onFailure(cause);
62+
}
63+
}
64+
65+
/**
66+
* Descriptor for {@link LogFileFilterStep}.
67+
*/
68+
@Extension(optional = true)
69+
public static class StepDescriptorImpl extends AbstractStepDescriptorImpl {
70+
71+
public StepDescriptorImpl() {
72+
super(ExecutionImpl.class);
73+
}
74+
75+
@Override
76+
public String getDisplayName() {
77+
return "LogFileFilterStep";
78+
}
79+
80+
/**
81+
* {@inheritDoc}
82+
*/
83+
@Override
84+
public String getFunctionName() {
85+
return "logFileFilter";
86+
}
87+
88+
/**
89+
* {@inheritDoc}
90+
*/
91+
@Override
92+
public boolean takesImplicitBlockArgument() {
93+
return true;
94+
}
95+
96+
}
97+
98+
}

0 commit comments

Comments
 (0)