Skip to content

Commit cf11669

Browse files
committed
Document several classes
1 parent 5213373 commit cf11669

File tree

6 files changed

+541
-20
lines changed

6 files changed

+541
-20
lines changed

src/main/java/dev/erichaag/develocity/processing/BuildListener.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,92 @@
1111

1212
import static java.util.Collections.emptySet;
1313

14+
/**
15+
* A listener interface for receiving notifications about builds encountered
16+
* during processing.
17+
*
18+
* <p>Implement this interface to receive callbacks when builds are encountered
19+
* by a {@link BuildProcessor}. A {@link BuildListenerBuilder} provides a
20+
* convenient way to create custom listeners without needing to write a
21+
* dedicated class that implements this interface.
22+
*
23+
* <p>Note that it can sometimes be useful for an implementation to also
24+
* implement {@link ProcessListener} if it needs to be notified about a specific
25+
* processing stage. For example, when all processing has finished so that the
26+
* listener can perform a final action.
27+
*
28+
* <p>By default, all methods have empty implementations. Implement only the
29+
* methods relevant to your use case.
30+
*
31+
* @see BuildListenerBuilder
32+
* @see ProcessListener
33+
*/
1434
public interface BuildListener {
1535

36+
/**
37+
* Creates a new {@link BuildListenerBuilder} to construct a
38+
* {@link BuildListener} instance.
39+
*
40+
* <p>This can be convenient to quickly construct listeners without needing
41+
* to write a dedicated class that implements this interface.
42+
*
43+
* @return a new builder instance
44+
*/
1645
static BuildListenerBuilder builder() {
1746
return new BuildListenerBuilder();
1847
}
1948

49+
/**
50+
* Returns the set of {@link BuildModel}s required by this listener.
51+
* This information is used by a {@link BuildProcessor} to know which build
52+
* models to request.
53+
*
54+
* <p>By default, this method returns an empty set, indicating that no
55+
* additional build models are required by this listener.
56+
*
57+
* @return the set of required build models
58+
*/
2059
default Set<BuildModel> getRequiredBuildModels() {
2160
return emptySet();
2261
}
2362

63+
/**
64+
* Callback method invoked when any build is encountered.
65+
*
66+
* @param build the build that was encountered
67+
*/
2468
default void onBuild(Build build) {
2569
}
2670

71+
/**
72+
* Callback method invoked when a Gradle build is encountered.
73+
*
74+
* @param build the Gradle build that was encountered
75+
*/
2776
default void onGradleBuild(GradleBuild build) {
2877
}
2978

79+
/**
80+
* Callback method invoked when a Maven build is encountered.
81+
*
82+
* @param build the Maven build that was encountered
83+
*/
3084
default void onMavenBuild(MavenBuild build) {
3185
}
3286

87+
/**
88+
* Callback method invoked when a Bazel build is encountered.
89+
*
90+
* @param build the Bazel build that was encountered
91+
*/
3392
default void onBazelBuild(BazelBuild build) {
3493
}
3594

95+
/**
96+
* Callback method invoked when an sbt build is encountered.
97+
*
98+
* @param build the Sbt build that was encountered
99+
*/
36100
default void onSbtBuild(SbtBuild build) {
37101
}
38102

src/main/java/dev/erichaag/develocity/processing/BuildListenerBuilder.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515

1616
import static java.util.Set.copyOf;
1717

18+
/**
19+
* A builder class for constructing a {@link BuildListener} instance.
20+
*
21+
* <p>An instance of this builder can be obtained by calling
22+
* {@link BuildListener#builder()}.
23+
*
24+
* <p>This builder allows you to create a {@link BuildListener} by specifying
25+
* the desired callback methods and the required build models. This builder can
26+
* be convenient to quickly construct listeners without needing to write a
27+
* dedicated class that implements {@link BuildListener}.
28+
*
29+
* <p>This builder provides a fluent interface, allowing method calls to be
30+
* chained together to register multiple callbacks for different builds.
31+
*
32+
* @see BuildListener
33+
*/
1834
public final class BuildListenerBuilder {
1935

2036
private final List<BuildListener> listeners = new ArrayList<>();
@@ -23,6 +39,15 @@ public final class BuildListenerBuilder {
2339
BuildListenerBuilder() {
2440
}
2541

42+
/**
43+
* Constructs a new {@link BuildListener} instance with the configured
44+
* callbacks and required build models.
45+
*
46+
* <p>The returned listener will invoke all registered listener methods
47+
* when builds are encountered.
48+
*
49+
* @return a new {@link BuildListener} instance
50+
*/
2651
public BuildListener build() {
2752
return new BuildListener() {
2853

@@ -59,11 +84,28 @@ public void onSbtBuild(SbtBuild build) {
5984
};
6085
}
6186

87+
/**
88+
* Adds the specified build models required by the constructed
89+
* {@link BuildListener}. This information is used by a
90+
* {@link BuildProcessor} to know which build models to request.
91+
*
92+
* <p>Calling this method more than once will add the supplied build models
93+
* to the set of required build models. Duplicate build models are ignored.
94+
*
95+
* @param buildModels the build models required by the constructed listener
96+
* @return this builder instance for fluent configuration
97+
*/
6298
public BuildListenerBuilder requiredBuildModels(BuildModel... buildModels) {
6399
requiredBuildModels.addAll(Set.of(buildModels));
64100
return this;
65101
}
66102

103+
/**
104+
* Registers a callback function to be invoked when any build is encountered.
105+
*
106+
* @param onBuild the callback function to execute
107+
* @return this builder instance for fluent configuration
108+
*/
67109
public BuildListenerBuilder onBuild(Consumer<Build> onBuild) {
68110
listeners.add(new BuildListener() {
69111
@Override
@@ -74,6 +116,13 @@ public void onBuild(Build build) {
74116
return this;
75117
}
76118

119+
/**
120+
* Registers a callback function to be invoked when a Gradle build is
121+
* encountered.
122+
*
123+
* @param onGradleBuild the callback function to execute
124+
* @return this builder instance for fluent configuration
125+
*/
77126
public BuildListenerBuilder onGradleBuild(Consumer<GradleBuild> onGradleBuild) {
78127
listeners.add(new BuildListener() {
79128
@Override
@@ -84,6 +133,13 @@ public void onGradleBuild(GradleBuild build) {
84133
return this;
85134
}
86135

136+
/**
137+
* Registers a callback function to be invoked when a Maven build is
138+
* encountered.
139+
*
140+
* @param onMavenBuild the callback function to execute
141+
* @return this builder instance for fluent configuration
142+
*/
87143
public BuildListenerBuilder onMavenBuild(Consumer<MavenBuild> onMavenBuild) {
88144
listeners.add(new BuildListener() {
89145
@Override
@@ -94,6 +150,13 @@ public void onMavenBuild(MavenBuild build) {
94150
return this;
95151
}
96152

153+
/**
154+
* Registers a callback function to be invoked when a Bazel build is
155+
* encountered.
156+
*
157+
* @param onBazelBuild the callback function to execute
158+
* @return this builder instance for fluent configuration
159+
*/
97160
public BuildListenerBuilder onBazelBuild(Consumer<BazelBuild> onBazelBuild) {
98161
listeners.add(new BuildListener() {
99162
@Override
@@ -104,6 +167,13 @@ public void onBazelBuild(BazelBuild build) {
104167
return this;
105168
}
106169

170+
/**
171+
* Registers a callback function to be invoked when an sbt build is
172+
* encountered.
173+
*
174+
* @param onSbtBuild the callback function to execute
175+
* @return this builder instance for fluent configuration
176+
*/
107177
public BuildListenerBuilder onSbtBuild(Consumer<SbtBuild> onSbtBuild) {
108178
listeners.add(new BuildListener() {
109179
@Override

src/main/java/dev/erichaag/develocity/processing/BuildProcessor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static java.util.Objects.requireNonNullElseGet;
2121
import static java.util.Optional.empty;
2222
import static java.util.stream.Collectors.toUnmodifiableSet;
23-
import static java.util.stream.Stream.concat;
2423

2524
public final class BuildProcessor {
2625

@@ -46,8 +45,7 @@ public final class BuildProcessor {
4645
Integer retryLimit,
4746
Double retryFactor,
4847
List<BuildListener> buildListeners,
49-
List<ProcessListener> processListeners,
50-
Set<BuildModel> requiredBuildModels
48+
List<ProcessListener> processListeners
5149
) {
5250
this.develocity = develocity;
5351
this.processorCache = requireNonNullElseGet(processorCache, NoopCache::new);
@@ -58,7 +56,8 @@ public final class BuildProcessor {
5856
this.retryFactor = requireNonNullElse(retryFactor, 1.5);
5957
this.buildListeners = buildListeners;
6058
this.processListeners = processListeners;
61-
this.requiredBuildModels = concat(requiredBuildModels.stream(), buildListeners.stream().flatMap(it -> it.getRequiredBuildModels().stream()))
59+
this.requiredBuildModels = buildListeners.stream()
60+
.flatMap(it -> it.getRequiredBuildModels().stream())
6261
.collect(toUnmodifiableSet());
6362
validate();
6463
}

0 commit comments

Comments
 (0)