001/*
002 * Copyright 2017-2026 original authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.micronaut.maven.jsonschema;
017
018import java.io.File;
019import java.util.List;
020
021/**
022 * Shared configuration for Micronaut configuration validation.
023 * <p>
024 * This type is used as a nested configuration object in multiple mojos.
025 */
026public final class ConfigurationValidationConfiguration {
027
028    /**
029     * Global enable/disable flag.
030     */
031    private Boolean enabled;
032
033    /**
034     * Suppression patterns (same as the CLI --suppress/--suppressions flags).
035     */
036    private List<String> suppressions;
037
038    /**
039     * Whether to fail on unknown / not-present properties.
040     */
041    private Boolean failOnNotPresent;
042
043    /**
044     * Whether to allow Micronaut to deduce environments.
045     */
046    private Boolean deduceEnvironments;
047
048    /**
049     * Whether to run dependency-injection validation in addition to configuration validation.
050     */
051    private Boolean validateDependencyInjection;
052
053    /**
054     * Suppression patterns for dependency-injection errors (same as CLI {@code --suppress-inject-errors}).
055     */
056    private List<String> suppressInjectErrors;
057
058    /**
059     * Report format: json|html|both.
060     */
061    private String format;
062
063    /**
064     * Base output directory for reports.
065     */
066    private File outputDirectory;
067
068    /**
069     * Enable the on-disk cache to avoid re-running validation when inputs have not changed.
070     */
071    private Boolean cacheEnabled;
072
073    /**
074     * List of resource patterns to ignore when computing cache fingerprints.
075     */
076    private List<String> cacheIgnore;
077
078    private ValidationSet dev;
079    private ValidationSet packageValidation;
080    private ValidationSet test;
081
082    /**
083     * @return Whether configuration validation is enabled. If {@code null}, validation is disabled.
084     */
085    public Boolean getEnabled() {
086        return enabled;
087    }
088
089    /**
090     * @param enabled Whether configuration validation is enabled.
091     */
092    public void setEnabled(Boolean enabled) {
093        this.enabled = enabled;
094    }
095
096    /**
097     * Suppression patterns applied to validation results.
098     *
099     * @return The suppression patterns, or {@code null} to use no suppressions.
100     */
101    public List<String> getSuppressions() {
102        return suppressions;
103    }
104
105    /**
106     * @param suppressions Suppression patterns.
107     */
108    public void setSuppressions(List<String> suppressions) {
109        this.suppressions = suppressions;
110    }
111
112    /**
113     * Controls whether validation should fail when a configuration property is not present in the schema.
114     *
115     * @return Whether to fail on not-present properties. If {@code null}, defaults to {@code true}.
116     */
117    public Boolean getFailOnNotPresent() {
118        return failOnNotPresent;
119    }
120
121    /**
122     * @param failOnNotPresent Whether to fail on not-present properties.
123     */
124    public void setFailOnNotPresent(Boolean failOnNotPresent) {
125        this.failOnNotPresent = failOnNotPresent;
126    }
127
128    /**
129     * Controls whether Micronaut may deduce environments.
130     *
131     * @return Whether to deduce environments. If {@code null}, defaults to {@code false}.
132     */
133    public Boolean getDeduceEnvironments() {
134        return deduceEnvironments;
135    }
136
137    /**
138     * @param deduceEnvironments Whether to allow Micronaut to deduce environments.
139     */
140    public void setDeduceEnvironments(Boolean deduceEnvironments) {
141        this.deduceEnvironments = deduceEnvironments;
142    }
143
144    /**
145     * Controls whether dependency-injection validation should be executed.
146     *
147     * @return Whether to validate dependency injection. If {@code null}, defaults to {@code false}.
148     */
149    public Boolean getValidateDependencyInjection() {
150        return validateDependencyInjection;
151    }
152
153    /**
154     * @param validateDependencyInjection Whether to run dependency-injection validation.
155     */
156    public void setValidateDependencyInjection(Boolean validateDependencyInjection) {
157        this.validateDependencyInjection = validateDependencyInjection;
158    }
159
160    /**
161     * Suppression patterns applied only to dependency-injection validation errors.
162     *
163     * @return Suppression patterns, or {@code null} to apply none.
164     */
165    public List<String> getSuppressInjectErrors() {
166        return suppressInjectErrors;
167    }
168
169    /**
170     * @param suppressInjectErrors Suppression patterns for dependency-injection errors.
171     */
172    public void setSuppressInjectErrors(List<String> suppressInjectErrors) {
173        this.suppressInjectErrors = suppressInjectErrors;
174    }
175
176    /**
177     * Report format.
178     *
179     * @return The report format ({@code json}, {@code html}, or {@code both}). If {@code null}, defaults to {@code both}.
180     */
181    public String getFormat() {
182        return format;
183    }
184
185    /**
186     * @param format The report format ({@code json}, {@code html}, or {@code both}).
187     */
188    public void setFormat(String format) {
189        this.format = format;
190    }
191
192    /**
193     * Base output directory for reports.
194     *
195     * @return The base output directory. If {@code null}, defaults to
196     * {@code ${project.build.directory}/micronaut/config-validation}.
197     */
198    public File getOutputDirectory() {
199        return outputDirectory;
200    }
201
202    /**
203     * @param outputDirectory The base output directory.
204     */
205    public void setOutputDirectory(File outputDirectory) {
206        this.outputDirectory = outputDirectory;
207    }
208
209    /**
210     * @return Whether caching is enabled. If {@code null}, defaults to {@code true}.
211     */
212    public Boolean getCacheEnabled() {
213        return cacheEnabled;
214    }
215
216    /**
217     * @param cacheEnabled Whether caching is enabled.
218     */
219    public void setCacheEnabled(Boolean cacheEnabled) {
220        this.cacheEnabled = cacheEnabled;
221    }
222
223    /**
224     * Resource patterns to ignore when computing cache fingerprints.
225     * <p>
226     * Patterns are evaluated using {@code glob} syntax against paths relative to each configured resource directory
227     * for the active scenario.
228     *
229     * @return Ignore patterns, or {@code null} to use defaults
230     */
231    public List<String> getCacheIgnore() {
232        return cacheIgnore;
233    }
234
235    /**
236     * @param cacheIgnore Ignore patterns
237     */
238    public void setCacheIgnore(List<String> cacheIgnore) {
239        this.cacheIgnore = cacheIgnore;
240    }
241
242    /**
243     * @return Scenario-specific configuration for {@code mn:run} validation (default environment: {@code dev}).
244     */
245    public ValidationSet getDev() {
246        return dev;
247    }
248
249    /**
250     * @param dev Scenario-specific configuration for {@code mn:run} validation.
251     */
252    public void setDev(ValidationSet dev) {
253        this.dev = dev;
254    }
255
256    /**
257     * @return Scenario-specific configuration for {@code package} validation.
258     */
259    public ValidationSet getPackageValidation() {
260        return packageValidation;
261    }
262
263    /**
264     * @param packageValidation Scenario-specific configuration for {@code package} validation.
265     */
266    public void setPackageValidation(ValidationSet packageValidation) {
267        this.packageValidation = packageValidation;
268    }
269
270    /**
271     * @return Scenario-specific configuration for {@code test} validation (default environment: {@code test}).
272     */
273    public ValidationSet getTest() {
274        return test;
275    }
276
277    /**
278     * @param test Scenario-specific configuration for {@code test} validation.
279     */
280    public void setTest(ValidationSet test) {
281        this.test = test;
282    }
283
284    /**
285     * Scenario-specific configuration.
286     */
287    public static final class ValidationSet {
288        /**
289         * Enables/disables validation for this scenario.
290         */
291        private Boolean enabled;
292
293        /**
294         * Environments to validate.
295         */
296        private List<String> environments;
297
298        /**
299         * Whether to include the scenario's default environment(s).
300         */
301        private Boolean includeDefaultEnvironment;
302
303        /**
304         * Explicit classpath elements to validate (replaces defaults).
305         */
306        private List<String> classpathElements;
307
308        /**
309         * Additional classpath entries appended to the computed defaults.
310         */
311        private List<String> additionalClasspathElements;
312
313        /**
314         * Override output directory for this scenario.
315         */
316        private File outputDirectory;
317
318        /**
319         * Resource directories used to resolve and render relative origins.
320         */
321        private List<File> resourceDirectories;
322
323        /**
324         * @return Whether this validation scenario is enabled. If {@code null}, the scenario follows the global
325         * {@link ConfigurationValidationConfiguration#getEnabled()} setting. This flag cannot force execution if
326         * global validation is disabled.
327         */
328        public Boolean getEnabled() {
329            return enabled;
330        }
331
332        /**
333         * @param enabled Whether this validation scenario is enabled.
334         */
335        public void setEnabled(Boolean enabled) {
336            this.enabled = enabled;
337        }
338
339        /**
340         * @return The environments to validate for this scenario. These environments are appended to the scenario defaults
341         * (unless {@link #getIncludeDefaultEnvironment()} is {@code false}).
342         */
343        public List<String> getEnvironments() {
344            return environments;
345        }
346
347        /**
348         * @param environments The environments to validate.
349         */
350        public void setEnvironments(List<String> environments) {
351            this.environments = environments;
352        }
353
354        /**
355         * @return Whether to include the scenario's default environments. If {@code null}, defaults to {@code true}.
356         */
357        public Boolean getIncludeDefaultEnvironment() {
358            return includeDefaultEnvironment;
359        }
360
361        /**
362         * @param includeDefaultEnvironment Whether to include the scenario's default environments.
363         */
364        public void setIncludeDefaultEnvironment(Boolean includeDefaultEnvironment) {
365            this.includeDefaultEnvironment = includeDefaultEnvironment;
366        }
367
368        /**
369         * Full classpath to validate for this scenario.
370         *
371         * @return Classpath elements that replace the plugin-computed defaults. If {@code null} or empty, the plugin
372         * computes defaults for the scenario.
373         */
374        public List<String> getClasspathElements() {
375            return classpathElements;
376        }
377
378        /**
379         * @param classpathElements Classpath elements that replace the plugin-computed defaults.
380         */
381        public void setClasspathElements(List<String> classpathElements) {
382            this.classpathElements = classpathElements;
383        }
384
385        /**
386         * @return Additional classpath elements appended to the plugin-computed defaults.
387         */
388        public List<String> getAdditionalClasspathElements() {
389            return additionalClasspathElements;
390        }
391
392        /**
393         * @param additionalClasspathElements Additional classpath elements appended to the plugin-computed defaults.
394         */
395        public void setAdditionalClasspathElements(List<String> additionalClasspathElements) {
396            this.additionalClasspathElements = additionalClasspathElements;
397        }
398
399        /**
400         * @return Scenario output directory override. If {@code null}, the plugin uses
401         * {@code <baseOutputDirectory>/<scenario>}.
402         */
403        public File getOutputDirectory() {
404            return outputDirectory;
405        }
406
407        /**
408         * @param outputDirectory Scenario output directory override.
409         */
410        public void setOutputDirectory(File outputDirectory) {
411            this.outputDirectory = outputDirectory;
412        }
413
414        /**
415         * Resource directories used to resolve and render relative origin paths in error output.
416         * <p>
417         * If not specified, defaults are:
418         * <ul>
419         *     <li>dev/package: {@code src/main/resources}</li>
420         *     <li>test: {@code src/main/resources} + {@code src/test/resources}</li>
421         * </ul>
422         *
423         * @return Resource directories, or {@code null} to use scenario defaults
424         */
425        public List<File> getResourceDirectories() {
426            return resourceDirectories;
427        }
428
429        /**
430         * @param resourceDirectories Resource directories used to resolve and render relative origin paths
431         */
432        public void setResourceDirectories(List<File> resourceDirectories) {
433            this.resourceDirectories = resourceDirectories;
434        }
435    }
436}