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  import java.util.List;
23  
24  import org.apache.maven.api.Service;
25  import org.apache.maven.api.Session;
26  import org.apache.maven.api.annotations.Experimental;
27  import org.apache.maven.api.annotations.Nonnull;
28  import org.apache.maven.api.settings.Settings;
29  
30  /**
31   * Builds the effective settings from a user settings file and/or a global settings file.
32   *
33   * @since 4.0.0
34   */
35  @Experimental
36  public interface SettingsBuilder extends Service {
37  
38      /**
39       * Builds the effective settings of the specified settings files.
40       *
41       * @param request the settings building request that holds the parameters, must not be {@code null}
42       * @return the result of the settings building, never {@code null}
43       * @throws SettingsBuilderException if the effective settings could not be built
44       */
45      @Nonnull
46      SettingsBuilderResult build(@Nonnull SettingsBuilderRequest request);
47  
48      /**
49       * Builds the effective settings of the specified settings sources.
50       *
51       * @return the result of the settings building, never {@code null}
52       * @throws SettingsBuilderException if the effective settings could not be built
53       */
54      @Nonnull
55      default SettingsBuilderResult build(
56              @Nonnull Session session, @Nonnull Source globalSettingsSource, @Nonnull Source userSettingsSource) {
57          return build(session, globalSettingsSource, null, userSettingsSource);
58      }
59  
60      /**
61       * Builds the effective settings of the specified settings paths.
62       *
63       * @return the result of the settings building, never {@code null}
64       * @throws SettingsBuilderException if the effective settings could not be built
65       */
66      @Nonnull
67      default SettingsBuilderResult build(
68              @Nonnull Session session, @Nonnull Path globalSettingsPath, @Nonnull Path userSettingsPath) {
69          return build(session, globalSettingsPath, null, userSettingsPath);
70      }
71  
72      /**
73       * Builds the effective settings of the specified settings sources.
74       *
75       * @return the result of the settings building, never {@code null}
76       * @throws SettingsBuilderException if the effective settings could not be built
77       */
78      @Nonnull
79      default SettingsBuilderResult build(
80              @Nonnull Session session,
81              @Nonnull Source globalSettingsSource,
82              @Nonnull Source projectSettingsSource,
83              @Nonnull Source userSettingsSource) {
84          return build(
85                  SettingsBuilderRequest.build(session, globalSettingsSource, projectSettingsSource, userSettingsSource));
86      }
87  
88      /**
89       * Builds the effective settings of the specified settings paths.
90       *
91       * @return the result of the settings building, never {@code null}
92       * @throws SettingsBuilderException if the effective settings could not be built
93       */
94      @Nonnull
95      default SettingsBuilderResult build(
96              @Nonnull Session session,
97              @Nonnull Path globalSettingsPath,
98              @Nonnull Path projectSettingsPath,
99              @Nonnull Path userSettingsPath) {
100         return build(SettingsBuilderRequest.build(session, globalSettingsPath, 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 List<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 / global settings.
119      * @return The list of problems that were encountered, must not be {@code null}.
120      */
121     @Nonnull
122     List<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 }