24
24
import org .springframework .aot .hint .RuntimeHints ;
25
25
import org .springframework .aot .nativex .FileNativeConfigurationWriter ;
26
26
import org .springframework .lang .Nullable ;
27
+ import org .springframework .util .Assert ;
27
28
import org .springframework .util .FileSystemUtils ;
28
29
29
30
/**
@@ -49,6 +50,7 @@ public abstract class AbstractAotProcessor {
49
50
50
51
/**
51
52
* Create a new processor instance with the supplied {@linkplain Settings settings}.
53
+ * @see Settings#builder()
52
54
*/
53
55
protected AbstractAotProcessor (Settings settings ) {
54
56
this .settings = settings ;
@@ -102,114 +104,163 @@ protected void writeHints(RuntimeHints hints) {
102
104
/**
103
105
* Common settings for AOT processors.
104
106
*/
105
- public static class Settings {
107
+ public static final class Settings {
106
108
107
- @ Nullable
108
- private Path sourceOutput ;
109
+ private final Path sourceOutput ;
109
110
110
- @ Nullable
111
- private Path resourceOutput ;
111
+ private final Path resourceOutput ;
112
112
113
- @ Nullable
114
- private Path classOutput ;
113
+ private final Path classOutput ;
115
114
116
- @ Nullable
117
- private String groupId ;
115
+ private final String groupId ;
118
116
119
- @ Nullable
120
- private String artifactId ;
117
+ private final String artifactId ;
121
118
122
119
123
- /**
124
- * Set the output directory for generated sources.
125
- * @param sourceOutput the location of generated sources
126
- * @return this settings object for method chaining
127
- */
128
- public Settings setSourceOutput (Path sourceOutput ) {
120
+ private Settings (Path sourceOutput , Path resourceOutput , Path classOutput , String groupId , String artifactId ) {
129
121
this .sourceOutput = sourceOutput ;
130
- return this ;
122
+ this .resourceOutput = resourceOutput ;
123
+ this .classOutput = classOutput ;
124
+ this .groupId = groupId ;
125
+ this .artifactId = artifactId ;
131
126
}
132
127
128
+
133
129
/**
134
- * Get the output directory for generated sources .
130
+ * Create a new {@link Builder} for {@link Settings} .
135
131
*/
136
- @ Nullable
137
- public Path getSourceOutput () {
138
- return this .sourceOutput ;
132
+ public static Builder builder () {
133
+ return new Builder ();
139
134
}
140
135
136
+
141
137
/**
142
- * Set the output directory for generated resources.
143
- * @param resourceOutput the location of generated resources
144
- * @return this settings object for method chaining
138
+ * Get the output directory for generated sources.
145
139
*/
146
- public Settings setResourceOutput (Path resourceOutput ) {
147
- this .resourceOutput = resourceOutput ;
148
- return this ;
140
+ public Path getSourceOutput () {
141
+ return this .sourceOutput ;
149
142
}
150
143
151
144
/**
152
145
* Get the output directory for generated resources.
153
146
*/
154
- @ Nullable
155
147
public Path getResourceOutput () {
156
148
return this .resourceOutput ;
157
149
}
158
150
159
- /**
160
- * Set the output directory for generated classes.
161
- * @param classOutput the location of generated classes
162
- * @return this settings object for method chaining
163
- */
164
- public Settings setClassOutput (Path classOutput ) {
165
- this .classOutput = classOutput ;
166
- return this ;
167
- }
168
-
169
151
/**
170
152
* Get the output directory for generated classes.
171
153
*/
172
- @ Nullable
173
154
public Path getClassOutput () {
174
155
return this .classOutput ;
175
156
}
176
157
177
- /**
178
- * Set the group ID of the application.
179
- * @param groupId the group ID of the application, used to locate
180
- * {@code native-image.properties}
181
- * @return this settings object for method chaining
182
- */
183
- public Settings setGroupId (String groupId ) {
184
- this .groupId = groupId ;
185
- return this ;
186
- }
187
-
188
158
/**
189
159
* Get the group ID of the application.
190
160
*/
191
- @ Nullable
192
161
public String getGroupId () {
193
162
return this .groupId ;
194
163
}
195
164
196
165
/**
197
- * Set the artifact ID of the application.
198
- * @param artifactId the artifact ID of the application, used to locate
199
- * {@code native-image.properties}
200
- * @return this settings object for method chaining
166
+ * Get the artifact ID of the application.
201
167
*/
202
- public Settings setArtifactId (String artifactId ) {
203
- this .artifactId = artifactId ;
204
- return this ;
168
+ public String getArtifactId () {
169
+ return this .artifactId ;
205
170
}
206
171
172
+
207
173
/**
208
- * Get the artifact ID of the application .
174
+ * Fluent builder API for {@link Settings} .
209
175
*/
210
- @ Nullable
211
- public String getArtifactId () {
212
- return this .artifactId ;
176
+ public static final class Builder {
177
+
178
+ @ Nullable
179
+ private Path sourceOutput ;
180
+
181
+ @ Nullable
182
+ private Path resourceOutput ;
183
+
184
+ @ Nullable
185
+ private Path classOutput ;
186
+
187
+ @ Nullable
188
+ private String groupId ;
189
+
190
+ @ Nullable
191
+ private String artifactId ;
192
+
193
+
194
+ private Builder () {
195
+ // internal constructor
196
+ }
197
+
198
+
199
+ /**
200
+ * Set the output directory for generated sources.
201
+ * @param sourceOutput the location of generated sources
202
+ * @return this builder for method chaining
203
+ */
204
+ public Builder sourceOutput (Path sourceOutput ) {
205
+ this .sourceOutput = sourceOutput ;
206
+ return this ;
207
+ }
208
+
209
+ /**
210
+ * Set the output directory for generated resources.
211
+ * @param resourceOutput the location of generated resources
212
+ * @return this builder for method chaining
213
+ */
214
+ public Builder resourceOutput (Path resourceOutput ) {
215
+ this .resourceOutput = resourceOutput ;
216
+ return this ;
217
+ }
218
+
219
+ /**
220
+ * Set the output directory for generated classes.
221
+ * @param classOutput the location of generated classes
222
+ * @return this builder for method chaining
223
+ */
224
+ public Builder classOutput (Path classOutput ) {
225
+ this .classOutput = classOutput ;
226
+ return this ;
227
+ }
228
+
229
+ /**
230
+ * Set the group ID of the application.
231
+ * @param groupId the group ID of the application, used to locate
232
+ * {@code native-image.properties}
233
+ * @return this builder for method chaining
234
+ */
235
+ public Builder groupId (String groupId ) {
236
+ this .groupId = groupId ;
237
+ return this ;
238
+ }
239
+
240
+ /**
241
+ * Set the artifact ID of the application.
242
+ * @param artifactId the artifact ID of the application, used to locate
243
+ * {@code native-image.properties}
244
+ * @return this builder for method chaining
245
+ */
246
+ public Builder artifactId (String artifactId ) {
247
+ this .artifactId = artifactId ;
248
+ return this ;
249
+ }
250
+
251
+ /**
252
+ * Build the {@link Settings} configured in this {@code Builder}.
253
+ */
254
+ public Settings build () {
255
+ Assert .notNull (this .sourceOutput , "'sourceOutput' must not be null" );
256
+ Assert .notNull (this .resourceOutput , "'resourceOutput' must not be null" );
257
+ Assert .notNull (this .classOutput , "'classOutput' must not be null" );
258
+ Assert .hasText (this .groupId , "'groupId' must not be null or empty" );
259
+ Assert .hasText (this .artifactId , "'artifactId' must not be null or empty" );
260
+ return new Settings (this .sourceOutput , this .resourceOutput , this .classOutput ,
261
+ this .groupId , this .artifactId );
262
+ }
263
+
213
264
}
214
265
215
266
}
0 commit comments