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     * Report format: json|html|both.
050     */
051    private String format;
052
053    /**
054     * Base output directory for reports.
055     */
056    private File outputDirectory;
057
058    /**
059     * Enable the on-disk cache to avoid re-running validation when inputs have not changed.
060     */
061    private Boolean cacheEnabled;
062
063    /**
064     * List of resource patterns to ignore when computing cache fingerprints.
065     */
066    private List<String> cacheIgnore;
067
068    private ValidationSet dev;
069    private ValidationSet packageValidation;
070    private ValidationSet test;
071
072    /**
073     * @return Whether configuration validation is enabled. If {@code null}, validation is enabled.
074     */
075    public Boolean getEnabled() {
076        return enabled;
077    }
078
079    /**
080     * @param enabled Whether configuration validation is enabled.
081     */
082    public void setEnabled(Boolean enabled) {
083        this.enabled = enabled;
084    }
085
086    /**
087     * Suppression patterns applied to validation results.
088     *
089     * @return The suppression patterns, or {@code null} to use no suppressions.
090     */
091    public List<String> getSuppressions() {
092        return suppressions;
093    }
094
095    /**
096     * @param suppressions Suppression patterns.
097     */
098    public void setSuppressions(List<String> suppressions) {
099        this.suppressions = suppressions;
100    }
101
102    /**
103     * Controls whether validation should fail when a configuration property is not present in the schema.
104     *
105     * @return Whether to fail on not-present properties. If {@code null}, defaults to {@code true}.
106     */
107    public Boolean getFailOnNotPresent() {
108        return failOnNotPresent;
109    }
110
111    /**
112     * @param failOnNotPresent Whether to fail on not-present properties.
113     */
114    public void setFailOnNotPresent(Boolean failOnNotPresent) {
115        this.failOnNotPresent = failOnNotPresent;
116    }
117
118    /**
119     * Controls whether Micronaut may deduce environments.
120     *
121     * @return Whether to deduce environments. If {@code null}, defaults to {@code false}.
122     */
123    public Boolean getDeduceEnvironments() {
124        return deduceEnvironments;
125    }
126
127    /**
128     * @param deduceEnvironments Whether to allow Micronaut to deduce environments.
129     */
130    public void setDeduceEnvironments(Boolean deduceEnvironments) {
131        this.deduceEnvironments = deduceEnvironments;
132    }
133
134    /**
135     * Report format.
136     *
137     * @return The report format ({@code json}, {@code html}, or {@code both}). If {@code null}, defaults to {@code both}.
138     */
139    public String getFormat() {
140        return format;
141    }
142
143    /**
144     * @param format The report format ({@code json}, {@code html}, or {@code both}).
145     */
146    public void setFormat(String format) {
147        this.format = format;
148    }
149
150    /**
151     * Base output directory for reports.
152     *
153     * @return The base output directory. If {@code null}, defaults to
154     * {@code ${project.build.directory}/micronaut/config-validation}.
155     */
156    public File getOutputDirectory() {
157        return outputDirectory;
158    }
159
160    /**
161     * @param outputDirectory The base output directory.
162     */
163    public void setOutputDirectory(File outputDirectory) {
164        this.outputDirectory = outputDirectory;
165    }
166
167    /**
168     * @return Whether caching is enabled. If {@code null}, defaults to {@code true}.
169     */
170    public Boolean getCacheEnabled() {
171        return cacheEnabled;
172    }
173
174    /**
175     * @param cacheEnabled Whether caching is enabled.
176     */
177    public void setCacheEnabled(Boolean cacheEnabled) {
178        this.cacheEnabled = cacheEnabled;
179    }
180
181    /**
182     * Resource patterns to ignore when computing cache fingerprints.
183     * <p>
184     * Patterns are evaluated using {@code glob} syntax against paths relative to each configured resource directory
185     * for the active scenario.
186     *
187     * @return Ignore patterns, or {@code null} to use defaults
188     */
189    public List<String> getCacheIgnore() {
190        return cacheIgnore;
191    }
192
193    /**
194     * @param cacheIgnore Ignore patterns
195     */
196    public void setCacheIgnore(List<String> cacheIgnore) {
197        this.cacheIgnore = cacheIgnore;
198    }
199
200    /**
201     * @return Scenario-specific configuration for {@code mn:run} validation (default environment: {@code dev}).
202     */
203    public ValidationSet getDev() {
204        return dev;
205    }
206
207    /**
208     * @param dev Scenario-specific configuration for {@code mn:run} validation.
209     */
210    public void setDev(ValidationSet dev) {
211        this.dev = dev;
212    }
213
214    /**
215     * @return Scenario-specific configuration for {@code package} validation.
216     */
217    public ValidationSet getPackageValidation() {
218        return packageValidation;
219    }
220
221    /**
222     * @param packageValidation Scenario-specific configuration for {@code package} validation.
223     */
224    public void setPackageValidation(ValidationSet packageValidation) {
225        this.packageValidation = packageValidation;
226    }
227
228    /**
229     * @return Scenario-specific configuration for {@code test} validation (default environment: {@code test}).
230     */
231    public ValidationSet getTest() {
232        return test;
233    }
234
235    /**
236     * @param test Scenario-specific configuration for {@code test} validation.
237     */
238    public void setTest(ValidationSet test) {
239        this.test = test;
240    }
241
242    /**
243     * Scenario-specific configuration.
244     */
245    public static final class ValidationSet {
246        /**
247         * Enables/disables validation for this scenario.
248         */
249        private Boolean enabled;
250
251        /**
252         * Environments to validate.
253         */
254        private List<String> environments;
255
256        /**
257         * Whether to include the scenario's default environment(s).
258         */
259        private Boolean includeDefaultEnvironment;
260
261        /**
262         * Explicit classpath elements to validate (replaces defaults).
263         */
264        private List<String> classpathElements;
265
266        /**
267         * Additional classpath entries appended to the computed defaults.
268         */
269        private List<String> additionalClasspathElements;
270
271        /**
272         * Override output directory for this scenario.
273         */
274        private File outputDirectory;
275
276        /**
277         * Resource directories used to resolve and render relative origins.
278         */
279        private List<File> resourceDirectories;
280
281        /**
282         * @return Whether this validation scenario is enabled. If {@code null}, the scenario is enabled.
283         */
284        public Boolean getEnabled() {
285            return enabled;
286        }
287
288        /**
289         * @param enabled Whether this validation scenario is enabled.
290         */
291        public void setEnabled(Boolean enabled) {
292            this.enabled = enabled;
293        }
294
295        /**
296         * @return The environments to validate for this scenario. These environments are appended to the scenario defaults
297         * (unless {@link #getIncludeDefaultEnvironment()} is {@code false}).
298         */
299        public List<String> getEnvironments() {
300            return environments;
301        }
302
303        /**
304         * @param environments The environments to validate.
305         */
306        public void setEnvironments(List<String> environments) {
307            this.environments = environments;
308        }
309
310        /**
311         * @return Whether to include the scenario's default environments. If {@code null}, defaults to {@code true}.
312         */
313        public Boolean getIncludeDefaultEnvironment() {
314            return includeDefaultEnvironment;
315        }
316
317        /**
318         * @param includeDefaultEnvironment Whether to include the scenario's default environments.
319         */
320        public void setIncludeDefaultEnvironment(Boolean includeDefaultEnvironment) {
321            this.includeDefaultEnvironment = includeDefaultEnvironment;
322        }
323
324        /**
325         * Full classpath to validate for this scenario.
326         *
327         * @return Classpath elements that replace the plugin-computed defaults. If {@code null} or empty, the plugin
328         * computes defaults for the scenario.
329         */
330        public List<String> getClasspathElements() {
331            return classpathElements;
332        }
333
334        /**
335         * @param classpathElements Classpath elements that replace the plugin-computed defaults.
336         */
337        public void setClasspathElements(List<String> classpathElements) {
338            this.classpathElements = classpathElements;
339        }
340
341        /**
342         * @return Additional classpath elements appended to the plugin-computed defaults.
343         */
344        public List<String> getAdditionalClasspathElements() {
345            return additionalClasspathElements;
346        }
347
348        /**
349         * @param additionalClasspathElements Additional classpath elements appended to the plugin-computed defaults.
350         */
351        public void setAdditionalClasspathElements(List<String> additionalClasspathElements) {
352            this.additionalClasspathElements = additionalClasspathElements;
353        }
354
355        /**
356         * @return Scenario output directory override. If {@code null}, the plugin uses
357         * {@code <baseOutputDirectory>/<scenario>}.
358         */
359        public File getOutputDirectory() {
360            return outputDirectory;
361        }
362
363        /**
364         * @param outputDirectory Scenario output directory override.
365         */
366        public void setOutputDirectory(File outputDirectory) {
367            this.outputDirectory = outputDirectory;
368        }
369
370        /**
371         * Resource directories used to resolve and render relative origin paths in error output.
372         * <p>
373         * If not specified, defaults are:
374         * <ul>
375         *     <li>dev/package: {@code src/main/resources}</li>
376         *     <li>test: {@code src/main/resources} + {@code src/test/resources}</li>
377         * </ul>
378         *
379         * @return Resource directories, or {@code null} to use scenario defaults
380         */
381        public List<File> getResourceDirectories() {
382            return resourceDirectories;
383        }
384
385        /**
386         * @param resourceDirectories Resource directories used to resolve and render relative origin paths
387         */
388        public void setResourceDirectories(List<File> resourceDirectories) {
389            this.resourceDirectories = resourceDirectories;
390        }
391    }
392}