Skip to content

Commit 9da32b2

Browse files
committed
Fix release tasks
Rework the task hierarchy to not have unnecessary properties in the Snap release task. Signed-off-by: thc202 <[email protected]>
1 parent 3f0f3a6 commit 9da32b2

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.zaproxy.gradle.GitHubRepo
1313
import org.zaproxy.gradle.GitHubUser
1414
import org.zaproxy.gradle.HandleMainRelease
1515
import org.zaproxy.gradle.HandleWeeklyRelease
16+
import org.zaproxy.gradle.MainReleaseRepositoryDispatch
1617
import org.zaproxy.gradle.UpdateAddOnZapVersionsEntries
1718
import org.zaproxy.gradle.UpdateAndCreatePullRequestAddOnRelease
1819
import org.zaproxy.gradle.UpdateDailyZapVersionsEntries
@@ -443,7 +444,7 @@ val updateZapMgmtScripts by tasks.registering(CreatePullRequest::class) {
443444
mustRunAfter(handleMainRelease)
444445
}
445446

446-
val handleSnapRelease by tasks.registering(HandleMainRelease::class) {
447+
val handleSnapRelease by tasks.registering(MainReleaseRepositoryDispatch::class) {
447448
releaseState.set(releaseStateData)
448449

449450
gitHubUser.set(ghUser)

buildSrc/src/main/java/org/zaproxy/gradle/HandleMainRelease.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,22 @@
2020
package org.zaproxy.gradle;
2121

2222
import java.util.Map;
23-
import org.gradle.api.file.RegularFileProperty;
2423
import org.gradle.api.provider.Property;
2524
import org.gradle.api.tasks.Input;
26-
import org.gradle.api.tasks.InputFile;
27-
import org.zaproxy.gradle.ReleaseState.VersionChange;
2825

2926
/**
3027
* Task that handles a main release, if any.
3128
*
3229
* <p>Sends a repository dispatch to release the main and nightly Docker images.
3330
*/
34-
public abstract class HandleMainRelease extends SendRepositoryDispatch {
35-
36-
@InputFile
37-
public abstract RegularFileProperty getReleaseState();
31+
public abstract class HandleMainRelease extends MainReleaseRepositoryDispatch {
3832

3933
@Input
4034
public abstract Property<String> getEventTypeNightly();
4135

4236
@Override
43-
void send() {
44-
ReleaseState releaseState = ReleaseState.read(getReleaseState().getAsFile().get());
45-
if (isNewMainRelease(releaseState)) {
46-
super.send();
47-
sendRepositoryDispatch(getEventTypeNightly().get(), Map.of());
48-
}
49-
}
50-
51-
private static boolean isNewMainRelease(ReleaseState releaseState) {
52-
VersionChange mainRelease = releaseState.getMainRelease();
53-
return mainRelease != null && mainRelease.isNewVersion();
37+
protected void sendDispatch() {
38+
super.sendDispatch();
39+
sendRepositoryDispatch(getEventTypeNightly().get(), Map.of());
5440
}
5541
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Zed Attack Proxy (ZAP) and its related class files.
3+
*
4+
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
5+
*
6+
* Copyright 2020 The ZAP Development Team
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.zaproxy.gradle;
21+
22+
import java.util.Map;
23+
import org.gradle.api.file.RegularFileProperty;
24+
import org.gradle.api.provider.Property;
25+
import org.gradle.api.tasks.Input;
26+
import org.gradle.api.tasks.InputFile;
27+
import org.zaproxy.gradle.ReleaseState.VersionChange;
28+
29+
/**
30+
* A {@link SendRepositoryDispatch} that only runs on a main release.
31+
*/
32+
public abstract class MainReleaseRepositoryDispatch extends SendRepositoryDispatch {
33+
34+
@InputFile
35+
public abstract RegularFileProperty getReleaseState();
36+
37+
@Override
38+
void send() {
39+
ReleaseState releaseState = ReleaseState.read(getReleaseState().getAsFile().get());
40+
if (isNewMainRelease(releaseState)) {
41+
sendDispatch();
42+
}
43+
}
44+
45+
protected void sendDispatch() {
46+
super.send();
47+
}
48+
49+
private static boolean isNewMainRelease(ReleaseState releaseState) {
50+
VersionChange mainRelease = releaseState.getMainRelease();
51+
return mainRelease != null && mainRelease.isNewVersion();
52+
}
53+
}

0 commit comments

Comments
 (0)