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 implements ProjectBuilderRequest {
129             private final Path path;
130             private final Source source;
131             private final boolean allowStubModel;
132             private final boolean recursive;
133             private final boolean processPlugins;
134             private final List<RemoteRepository> repositories;
135 
136             @SuppressWarnings("checkstyle:ParameterNumber")
137             DefaultProjectBuilderRequest(
138                     @Nonnull Session session,
139                     @Nullable Path path,
140                     @Nullable Source source,
141                     boolean allowStubModel,
142                     boolean recursive,
143                     boolean processPlugins,
144                     @Nullable List<RemoteRepository> repositories) {
145                 super(session);
146                 this.path = path;
147                 this.source = source;
148                 this.allowStubModel = allowStubModel;
149                 this.recursive = recursive;
150                 this.processPlugins = processPlugins;
151                 this.repositories = repositories;
152             }
153 
154             @Nonnull
155             @Override
156             public Optional<Path> getPath() {
157                 return Optional.ofNullable(path);
158             }
159 
160             @Nonnull
161             @Override
162             public Optional<Source> getSource() {
163                 return Optional.ofNullable(source);
164             }
165 
166             @Override
167             public boolean isAllowStubModel() {
168                 return allowStubModel;
169             }
170 
171             @Override
172             public boolean isRecursive() {
173                 return recursive;
174             }
175 
176             @Override
177             public boolean isProcessPlugins() {
178                 return processPlugins;
179             }
180 
181             @Override
182             public List<RemoteRepository> getRepositories() {
183                 return repositories;
184             }
185         }
186     }
187 }