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.cling.invoker;
20  
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.nio.file.Path;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Optional;
27  
28  import org.apache.maven.api.annotations.Nonnull;
29  import org.apache.maven.api.annotations.Nullable;
30  import org.apache.maven.api.cli.InvokerRequest;
31  import org.apache.maven.api.cli.ParserRequest;
32  import org.apache.maven.api.cli.extensions.CoreExtension;
33  
34  import static java.util.Objects.requireNonNull;
35  
36  public abstract class BaseInvokerRequest implements InvokerRequest {
37      private final ParserRequest parserRequest;
38      private final Path cwd;
39      private final Path installationDirectory;
40      private final Path userHomeDirectory;
41      private final List<String> jvmArguments;
42      private final Map<String, String> userProperties;
43      private final Map<String, String> systemProperties;
44      private final Path topDirectory;
45      private final Path rootDirectory;
46      private final List<CoreExtension> coreExtensions;
47      private final InputStream in;
48      private final OutputStream out;
49      private final OutputStream err;
50  
51      @SuppressWarnings("ParameterNumber")
52      public BaseInvokerRequest(
53              @Nonnull ParserRequest parserRequest,
54              @Nonnull Path cwd,
55              @Nonnull Path installationDirectory,
56              @Nonnull Path userHomeDirectory,
57              @Nonnull Map<String, String> userProperties,
58              @Nonnull Map<String, String> systemProperties,
59              @Nonnull Path topDirectory,
60              @Nullable Path rootDirectory,
61              @Nullable InputStream in,
62              @Nullable OutputStream out,
63              @Nullable OutputStream err,
64              @Nullable List<CoreExtension> coreExtensions,
65              @Nullable List<String> jvmArguments) {
66          this.parserRequest = requireNonNull(parserRequest);
67          this.cwd = requireNonNull(cwd);
68          this.installationDirectory = requireNonNull(installationDirectory);
69          this.userHomeDirectory = requireNonNull(userHomeDirectory);
70          this.jvmArguments = jvmArguments;
71  
72          this.userProperties = requireNonNull(userProperties);
73          this.systemProperties = requireNonNull(systemProperties);
74          this.topDirectory = requireNonNull(topDirectory);
75          this.rootDirectory = rootDirectory;
76          this.coreExtensions = coreExtensions;
77  
78          this.in = in;
79          this.out = out;
80          this.err = err;
81      }
82  
83      @Override
84      public ParserRequest parserRequest() {
85          return parserRequest;
86      }
87  
88      @Override
89      public Path cwd() {
90          return cwd;
91      }
92  
93      @Override
94      public Path installationDirectory() {
95          return installationDirectory;
96      }
97  
98      @Override
99      public Path userHomeDirectory() {
100         return userHomeDirectory;
101     }
102 
103     @Override
104     public Optional<List<String>> jvmArguments() {
105         return Optional.ofNullable(jvmArguments);
106     }
107 
108     @Override
109     public Map<String, String> userProperties() {
110         return userProperties;
111     }
112 
113     @Override
114     public Map<String, String> systemProperties() {
115         return systemProperties;
116     }
117 
118     @Override
119     public Path topDirectory() {
120         return topDirectory;
121     }
122 
123     @Override
124     public Optional<Path> rootDirectory() {
125         return Optional.ofNullable(rootDirectory);
126     }
127 
128     @Override
129     public Optional<InputStream> in() {
130         return Optional.ofNullable(in);
131     }
132 
133     @Override
134     public Optional<OutputStream> out() {
135         return Optional.ofNullable(out);
136     }
137 
138     @Override
139     public Optional<OutputStream> err() {
140         return Optional.ofNullable(err);
141     }
142 
143     @Override
144     public Optional<List<CoreExtension>> coreExtensions() {
145         return Optional.ofNullable(coreExtensions);
146     }
147 }