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 installation 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 installationSettingsSource, @Nonnull Source userSettingsSource) {
57          return build(session, installationSettingsSource, 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 installationSettingsPath, @Nonnull Path userSettingsPath) {
69          return build(session, installationSettingsPath, 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 installationSettingsSource,
82              @Nonnull Source projectSettingsSource,
83              @Nonnull Source userSettingsSource) {
84          return build(SettingsBuilderRequest.build(
85                  session, installationSettingsSource, 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 installationSettingsPath,
98              @Nonnull Path projectSettingsPath,
99              @Nonnull Path userSettingsPath) {
100         return build(
101                 SettingsBuilderRequest.build(session, installationSettingsPath, projectSettingsPath, userSettingsPath));
102     }
103 
104     /**
105      * Validate the specified settings.
106      *
107      * @param settings The settings to validate, must not be {@code null}.
108      * @return The list of problems that were encountered, must not be {@code null}.
109      */
110     @Nonnull
111     default List<BuilderProblem> validate(@Nonnull Settings settings) {
112         return validate(settings, false);
113     }
114 
115     /**
116      * Validate the specified settings.
117      *
118      * @param settings The settings to validate, must not be {@code null}.
119      * @param isProjectSettings Boolean indicating if the validation is for project settings or user / installation settings.
120      * @return The list of problems that were encountered, must not be {@code null}.
121      */
122     @Nonnull
123     List<BuilderProblem> validate(@Nonnull Settings settings, boolean isProjectSettings);
124 
125     /**
126      * Convert a model profile to a settings profile.
127      */
128     @Nonnull
129     org.apache.maven.api.settings.Profile convert(@Nonnull org.apache.maven.api.model.Profile profile);
130 
131     /**
132      * Convert a settings profile to a model profile.
133      */
134     @Nonnull
135     org.apache.maven.api.model.Profile convert(@Nonnull org.apache.maven.api.settings.Profile profile);
136 }