1515
1616import 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+ */
1834public 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
0 commit comments