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