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.Files;
22 import java.nio.file.Path;
23 import java.util.Optional;
24
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.annotations.NotThreadSafe;
29 import org.apache.maven.api.annotations.Nullable;
30
31 import static org.apache.maven.api.services.BaseRequest.nonNull;
32
33
34
35
36
37 @Experimental
38 public interface ToolchainsBuilderRequest {
39 @Nonnull
40 Session getSession();
41
42
43
44
45
46
47 @Nonnull
48 Optional<Source> getInstallationToolchainsSource();
49
50
51
52
53
54
55 @Nonnull
56 Optional<Source> getUserToolchainsSource();
57
58 @Nonnull
59 static ToolchainsBuilderRequest build(
60 @Nonnull Session session,
61 @Nullable Source installationToolchainsFile,
62 @Nullable Source userToolchainsSource) {
63 return builder()
64 .session(nonNull(session, "session cannot be null"))
65 .installationToolchainsSource(installationToolchainsFile)
66 .userToolchainsSource(userToolchainsSource)
67 .build();
68 }
69
70 @Nonnull
71 static ToolchainsBuilderRequest build(
72 @Nonnull Session session, @Nullable Path installationToolchainsFile, @Nullable Path userToolchainsPath) {
73 return builder()
74 .session(nonNull(session, "session cannot be null"))
75 .installationToolchainsSource(
76 installationToolchainsFile != null && Files.exists(installationToolchainsFile)
77 ? Source.fromPath(installationToolchainsFile)
78 : null)
79 .userToolchainsSource(
80 userToolchainsPath != null && Files.exists(userToolchainsPath)
81 ? Source.fromPath(userToolchainsPath)
82 : null)
83 .build();
84 }
85
86 @Nonnull
87 static ToolchainsBuilderRequestBuilder builder() {
88 return new ToolchainsBuilderRequestBuilder();
89 }
90
91 @NotThreadSafe
92 class ToolchainsBuilderRequestBuilder {
93 Session session;
94 Source installationToolchainsSource;
95 Source userToolchainsSource;
96
97 public ToolchainsBuilderRequestBuilder session(Session session) {
98 this.session = session;
99 return this;
100 }
101
102 public ToolchainsBuilderRequestBuilder installationToolchainsSource(Source installationToolchainsSource) {
103 this.installationToolchainsSource = installationToolchainsSource;
104 return this;
105 }
106
107 public ToolchainsBuilderRequestBuilder userToolchainsSource(Source userToolchainsSource) {
108 this.userToolchainsSource = userToolchainsSource;
109 return this;
110 }
111
112 public ToolchainsBuilderRequest build() {
113 return new ToolchainsBuilderRequestBuilder.DefaultToolchainsBuilderRequest(
114 session, installationToolchainsSource, userToolchainsSource);
115 }
116
117 private static class DefaultToolchainsBuilderRequest extends BaseRequest implements ToolchainsBuilderRequest {
118 private final Source installationToolchainsSource;
119 private final Source userToolchainsSource;
120
121 @SuppressWarnings("checkstyle:ParameterNumber")
122 DefaultToolchainsBuilderRequest(
123 @Nonnull Session session,
124 @Nullable Source installationToolchainsSource,
125 @Nullable Source userToolchainsSource) {
126 super(session);
127 this.installationToolchainsSource = installationToolchainsSource;
128 this.userToolchainsSource = userToolchainsSource;
129 }
130
131 @Nonnull
132 @Override
133 public Optional<Source> getInstallationToolchainsSource() {
134 return Optional.ofNullable(installationToolchainsSource);
135 }
136
137 @Nonnull
138 @Override
139 public Optional<Source> getUserToolchainsSource() {
140 return Optional.ofNullable(userToolchainsSource);
141 }
142 }
143 }
144 }