Skip to content

Commit 171d89f

Browse files
Merge pull request #147 from Praqma/java8_lambdas
Java8 lambdas
2 parents fd37e91 + 4a6891f commit 171d89f

File tree

5 files changed

+32
-47
lines changed

5 files changed

+32
-47
lines changed

src/main/java/hudson/plugins/promoted_builds/JobPropertyImpl.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,13 @@ private JobPropertyImpl(StaplerRequest req, JSONObject json) throws Descriptor.F
141141
}
142142

143143
private void loadAllProcesses(File rootDir) throws IOException {
144-
File[] subdirs = rootDir.listFiles(new FileFilter() {
145-
public boolean accept(File child) {
146-
return child.isDirectory();
147-
}
148-
});
144+
File[] subdirs = rootDir.listFiles(File::isDirectory);
149145

150146
loadProcesses(subdirs);
151147
}
152148
private void init() throws IOException {
153149
// load inactive processes
154-
File[] subdirs = getRootDir().listFiles(new FileFilter() {
155-
public boolean accept(File child) {
156-
return child.isDirectory() && !isActiveProcessNameIgnoreCase(child.getName());
157-
}
158-
});
150+
File[] subdirs = getRootDir().listFiles(child -> child.isDirectory() && !isActiveProcessNameIgnoreCase(child.getName()));
159151
loadProcesses(subdirs);
160152
}
161153
private void loadProcesses(File[] subdirs) throws IOException {

src/main/java/hudson/plugins/promoted_builds/PromotionCause.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import hudson.model.TaskListener;
66
import hudson.console.HyperlinkNote;
77

8+
import java.util.Objects;
9+
810
/**
911
* Cause used to indicate that a build was triggered by a promotion. Extends
1012
* UpstreamCause so that existing build steps can use "the upstream build that
@@ -76,10 +78,10 @@ public boolean equals(Object obj) {
7678
return false;
7779
}
7880
final PromotionCause other = (PromotionCause) obj;
79-
if ((this.promotionProcessName == null) ? (other.promotionProcessName != null) : !this.promotionProcessName.equals(other.promotionProcessName)) {
81+
if (!Objects.equals(this.promotionProcessName, other.promotionProcessName)) {
8082
return false;
8183
}
82-
if ((this.promotionBuildUrl == null) ? (other.promotionBuildUrl != null) : !this.promotionBuildUrl.equals(other.promotionBuildUrl)) {
84+
if (!Objects.equals(this.promotionBuildUrl, other.promotionBuildUrl)) {
8385
return false;
8486
}
8587
if (this.promotionBuildNumber != other.promotionBuildNumber) {

src/main/java/hudson/plugins/promoted_builds/PromotionProcess.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,7 @@ public boolean isVisible(){
309309
if (expandedIsVisible == null){
310310
return true;
311311
}
312-
if (expandedIsVisible.toLowerCase().equals("false")){
313-
return false;
314-
}
315-
return true;
312+
return !expandedIsVisible.toLowerCase().equals("false");
316313
}
317314
private static EnvVars getDefaultParameterValuesAsEnvVars(AbstractProject owner) {
318315
EnvVars envVars = null;

src/test/java/hudson/plugins/promoted_builds/KeepBuildForeverActionTest.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,19 @@ public void testDoesNotMarkBuildIfBuildNotPromotion() throws Exception {
111111
}
112112

113113
private void waitForBuild(final Job job, final int buildNumber) throws Exception {
114-
waitFor(new WaitCondition() {
115-
public boolean isMet() {
116-
return (job.getBuildByNumber(buildNumber) != null) && !job.getBuildByNumber(buildNumber).isBuilding();
117-
}
114+
waitFor(() -> {
115+
return (job.getBuildByNumber(buildNumber) != null) && !job.getBuildByNumber(buildNumber).isBuilding();
118116
}, 2000);
119117
}
120118

121119
private void waitFor(final WaitCondition condition, long timeout) throws Exception {
122-
Thread waiter = new Thread() {
123-
public void run() {
124-
try {
125-
while (!condition.isMet()) {
126-
Thread.sleep(100);
127-
}
128-
} catch (InterruptedException ie) { }
129-
}
130-
};
120+
Thread waiter = new Thread(() -> {
121+
try {
122+
while (!condition.isMet()) {
123+
Thread.sleep(100);
124+
}
125+
} catch (InterruptedException ie) { }
126+
});
131127
waiter.start();
132128
waiter.join(timeout);
133129
if (waiter.isAlive()) {

src/test/java/hudson/plugins/promoted_builds/PromotionProcessTest.java

+16-18
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,22 @@ private void waitForCompletion(FreeStyleProject down, int n) throws Exception {
150150

151151
@Test
152152
public void testCaptureXml() throws Exception {
153-
j.executeOnServer(new Callable<Object>() {
154-
public Object call() throws Exception {
155-
JSONObject o = new JSONObject()
156-
.accumulate("name", "foo")
157-
.accumulate("isVisible", "")
158-
.accumulate("icon", "star-gold")
159-
.accumulate("conditions",new JSONObject()
160-
.accumulate("hudson-plugins-promoted_builds-conditions-SelfPromotionCondition",
161-
new JSONObject().accumulate("evenIfUnstable", false)));
162-
PromotionProcess p = PromotionProcess.fromJson(Stapler.getCurrentRequest(), o);
163-
assertEquals("foo", p.getName());
164-
assertEquals("star-gold", p.getIcon());
165-
assertEquals(1, p.conditions.size());
166-
assertEquals(0, p.getBuildWrappers().size());
167-
assertNotNull(p.conditions.get(SelfPromotionCondition.class));
168-
System.out.println(Items.XSTREAM2.toXML(p));
169-
return null;
170-
}
153+
j.executeOnServer(() -> {
154+
JSONObject o = new JSONObject()
155+
.accumulate("name", "foo")
156+
.accumulate("isVisible", "")
157+
.accumulate("icon", "star-gold")
158+
.accumulate("conditions",new JSONObject()
159+
.accumulate("hudson-plugins-promoted_builds-conditions-SelfPromotionCondition",
160+
new JSONObject().accumulate("evenIfUnstable", false)));
161+
PromotionProcess p = PromotionProcess.fromJson(Stapler.getCurrentRequest(), o);
162+
assertEquals("foo", p.getName());
163+
assertEquals("star-gold", p.getIcon());
164+
assertEquals(1, p.conditions.size());
165+
assertEquals(0, p.getBuildWrappers().size());
166+
assertNotNull(p.conditions.get(SelfPromotionCondition.class));
167+
System.out.println(Items.XSTREAM2.toXML(p));
168+
return null;
171169
});
172170
}
173171

0 commit comments

Comments
 (0)