View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.api.services;
20  
21  import java.nio.file.Path;
22  
23  import org.apache.maven.api.Service;
24  import org.apache.maven.api.Session;
25  import org.apache.maven.api.annotations.Experimental;
26  import org.apache.maven.api.annotations.Nonnull;
27  import org.apache.maven.api.settings.Settings;
28  
29  /**
30   * Builds the effective settings from a user settings file and/or an installation settings file.
31   *
32   * @since 4.0.0
33   */
34  @Experimental
35  public interface SettingsBuilder extends Service {
36  
37      /**
38       * Builds the effective settings of the specified settings files.
39       *
40       * @param request the settings building request that holds the parameters, must not be {@code null}
41       * @return the result of the settings building, never {@code null}
42       * @throws SettingsBuilderException if the effective settings could not be built
43       */
44      @Nonnull
45      SettingsBuilderResult build(@Nonnull SettingsBuilderRequest request);
46  
47      /**
48       * Builds the effective settings of the specified settings sources.
49       *
50       * @return the result of the settings building, never {@code null}
51       * @throws SettingsBuilderException if the effective settings could not be built
52       */
53      @Nonnull
54      default SettingsBuilderResult build(
55              @Nonnull Session session, @Nonnull Source installationSettingsSource, @Nonnull Source userSettingsSource) {
56          return build(session, installationSettingsSource, null, userSettingsSource);
57      }
58  
59      /**
60       * Builds the effective settings of the specified settings paths.
61       *
62       * @return the result of the settings building, never {@code null}
63       * @throws SettingsBuilderException if the effective settings could not be built
64       */
65      @Nonnull
66      default SettingsBuilderResult build(
67              @Nonnull Session session, @Nonnull Path installationSettingsPath, @Nonnull Path userSettingsPath) {
68          return build(session, installationSettingsPath, null, userSettingsPath);
69      }
70  
71      /**
72       * Builds the effective settings of the specified settings sources.
73       *
74       * @return the result of the settings building, never {@code null}
75       * @throws SettingsBuilderException if the effective settings could not be built
76       */
77      @Nonnull
78      default SettingsBuilderResult build(
79              @Nonnull Session session,
80              @Nonnull Source installationSettingsSource,
81              @Nonnull Source projectSettingsSource,
82              @Nonnull Source userSettingsSource) {
83          return build(SettingsBuilderRequest.build(
84                  session, installationSettingsSource, projectSettingsSource, userSettingsSource));
85      }
86  
87      /**
88       * Builds the effective settings of the specified settings paths.
89       *
90       * @return the result of the settings building, never {@code null}
91       * @throws SettingsBuilderException if the effective settings could not be built
92       */
93      @Nonnull
94      default SettingsBuilderResult build(
95              @Nonnull Session session,
96              @Nonnull Path installationSettingsPath,
97              @Nonnull Path projectSettingsPath,
98              @Nonnull Path userSettingsPath) {
99          return build(
100                 SettingsBuilderRequest.build(session, installationSettingsPath, projectSettingsPath, userSettingsPath));
101     }
102 
103     /**
104      * Validate the specified settings.
105      *
106      * @param settings The settings to validate, must not be {@code null}.
107      * @return The list of problems that were encountered, must not be {@code null}.
108      */
109     @Nonnull
110     default ProblemCollector<BuilderProblem> validate(@Nonnull Settings settings) {
111         return validate(settings, false);
112     }
113 
114     /**
115      * Validate the specified settings.
116      *
117      * @param settings The settings to validate, must not be {@code null}.
118      * @param isProjectSettings Boolean indicating if the validation is for project settings or user / installation settings.
119      * @return The list of problems that were encountered, must not be {@code null}.
120      */
121     @Nonnull
122     ProblemCollector<BuilderProblem> validate(@Nonnull Settings settings, boolean isProjectSettings);
123 
124     /**
125      * Convert a model profile to a settings profile.
126      */
127     @Nonnull
128     org.apache.maven.api.settings.Profile convert(@Nonnull org.apache.maven.api.model.Profile profile);
129 
130     /**
131      * Convert a settings profile to a model profile.
132      */
133     @Nonnull
134     org.apache.maven.api.model.Profile convert(@Nonnull org.apache.maven.api.settings.Profile profile);
135 }