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  import java.util.Optional;
24  
25  import org.apache.maven.api.RemoteRepository;
26  import org.apache.maven.api.Session;
27  import org.apache.maven.api.annotations.Experimental;
28  import org.apache.maven.api.annotations.Immutable;
29  import org.apache.maven.api.annotations.Nonnull;
30  import org.apache.maven.api.annotations.NotThreadSafe;
31  import org.apache.maven.api.annotations.Nullable;
32  
33  import static org.apache.maven.api.services.BaseRequest.nonNull;
34  
35  /**
36   * Request used to build a {@link org.apache.maven.api.Project} using
37   * the {@link ProjectBuilder} service.
38   *
39   * TODO: add validationLevel, activeProfileIds, inactiveProfileIds, resolveDependencies
40   *
41   * @since 4.0.0
42   */
43  @Experimental
44  @Immutable
45  public interface ProjectBuilderRequest {
46  
47      @Nonnull
48      Session getSession();
49  
50      @Nonnull
51      Optional<Path> getPath();
52  
53      @Nonnull
54      Optional<Source> getSource();
55  
56      boolean isAllowStubModel();
57  
58      boolean isRecursive();
59  
60      boolean isProcessPlugins();
61  
62      @Nullable
63      List<RemoteRepository> getRepositories();
64  
65      @Nonnull
66      static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Source source) {
67          return builder()
68                  .session(nonNull(session, "session cannot be null"))
69                  .source(nonNull(source, "source cannot be null"))
70                  .build();
71      }
72  
73      @Nonnull
74      static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Path path) {
75          return builder()
76                  .session(nonNull(session, "session cannot be null"))
77                  .path(nonNull(path, "path cannot be null"))
78                  .build();
79      }
80  
81      @Nonnull
82      static ProjectBuilderRequestBuilder builder() {
83          return new ProjectBuilderRequestBuilder();
84      }
85  
86      @NotThreadSafe
87      class ProjectBuilderRequestBuilder {
88          Session session;
89          Path path;
90          Source source;
91          boolean allowStubModel;
92          boolean recursive;
93          boolean processPlugins = true;
94          List<RemoteRepository> repositories;
95  
96          ProjectBuilderRequestBuilder() {}
97  
98          public ProjectBuilderRequestBuilder session(Session session) {
99              this.session = session;
100             return this;
101         }
102 
103         public ProjectBuilderRequestBuilder path(Path path) {
104             this.path = path;
105             return this;
106         }
107 
108         public ProjectBuilderRequestBuilder source(Source source) {
109             this.source = source;
110             return this;
111         }
112 
113         public ProjectBuilderRequestBuilder processPlugins(boolean processPlugins) {
114             this.processPlugins = processPlugins;
115             return this;
116         }
117 
118         public ProjectBuilderRequestBuilder repositories(List<RemoteRepository> repositories) {
119             this.repositories = repositories;
120             return this;
121         }
122 
123         public ProjectBuilderRequest build() {
124             return new DefaultProjectBuilderRequest(
125                     session, path, source, allowStubModel, recursive, processPlugins, repositories);
126         }
127 
128         private static class DefaultProjectBuilderRequest extends BaseRequest<Session>
129                 implements ProjectBuilderRequest {
130             private final Path path;
131             private final Source source;
132             private final boolean allowStubModel;
133             private final boolean recursive;
134             private final boolean processPlugins;
135             private final List<RemoteRepository> repositories;
136 
137             @SuppressWarnings("checkstyle:ParameterNumber")
138             DefaultProjectBuilderRequest(
139                     @Nonnull Session session,
140                     @Nullable Path path,
141                     @Nullable Source source,
142                     boolean allowStubModel,
143                     boolean recursive,
144                     boolean processPlugins,
145                     @Nullable List<RemoteRepository> repositories) {
146                 super(session);
147                 this.path = path;
148                 this.source = source;
149                 this.allowStubModel = allowStubModel;
150                 this.recursive = recursive;
151                 this.processPlugins = processPlugins;
152                 this.repositories = repositories;
153             }
154 
155             @Nonnull
156             @Override
157             public Optional<Path> getPath() {
158                 return Optional.ofNullable(path);
159             }
160 
161             @Nonnull
162             @Override
163             public Optional<Source> getSource() {
164                 return Optional.ofNullable(source);
165             }
166 
167             @Override
168             public boolean isAllowStubModel() {
169                 return allowStubModel;
170             }
171 
172             @Override
173             public boolean isRecursive() {
174                 return recursive;
175             }
176 
177             @Override
178             public boolean isProcessPlugins() {
179                 return processPlugins;
180             }
181 
182             @Override
183             public List<RemoteRepository> getRepositories() {
184                 return repositories;
185             }
186         }
187     }
188 }