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.surefire.booter;
20  
21  import javax.annotation.Nonnull;
22  
23  import java.util.Collection;
24  
25  import static org.apache.maven.surefire.booter.Classpath.join;
26  
27  /**
28   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
29   * @since 2.21.0.Jigsaw
30   */
31  public class ModularClasspathConfiguration extends AbstractPathConfiguration {
32      private final ModularClasspath modularClasspath;
33      private final Classpath testClasspathUrls;
34  
35      /**
36       * The surefire classpath to use when invoking in-process with the plugin
37       */
38      private final Classpath inprocClasspath;
39  
40      public ModularClasspathConfiguration(
41              @Nonnull ModularClasspath modularClasspath,
42              @Nonnull Classpath testClasspathUrls,
43              @Nonnull Classpath surefireClasspathUrls,
44              @Nonnull Classpath inprocClasspath,
45              boolean enableAssertions,
46              boolean childDelegation) {
47          super(surefireClasspathUrls, enableAssertions, childDelegation);
48          this.modularClasspath = modularClasspath;
49          this.testClasspathUrls = testClasspathUrls;
50          this.inprocClasspath = inprocClasspath;
51      }
52  
53      @Override
54      public Classpath getTestClasspath() {
55          return testClasspathUrls;
56      }
57  
58      @Override
59      public final boolean isModularPathConfig() {
60          return true;
61      }
62  
63      @Override
64      public final boolean isClassPathConfig() {
65          return !isModularPathConfig();
66      }
67  
68      public ModularClasspath getModularClasspath() {
69          return modularClasspath;
70      }
71  
72      public ClassLoader createMergedClassLoader() throws SurefireExecutionException {
73          Collection<String> modulePath = getModularClasspath().getModulePath();
74          return createMergedClassLoader(join(getInprocTestClasspath(), new Classpath(modulePath)));
75      }
76  
77      @Override
78      protected Classpath getInprocClasspath() {
79          return inprocClasspath;
80      }
81  }