1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
37
38
39
40
41
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 }