View Javadoc
1   package org.apache.maven.surefire.booter;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.annotation.Nonnull;
23  
24  import java.util.Collection;
25  
26  import static org.apache.maven.surefire.booter.Classpath.join;
27  
28  /**
29   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
30   * @since 2.21.0.Jigsaw
31   */
32  public class ModularClasspathConfiguration extends AbstractPathConfiguration
33  {
34      private final ModularClasspath modularClasspath;
35      private final Classpath testClasspathUrls;
36  
37      /**
38       * The surefire classpath to use when invoking in-process with the plugin
39       */
40      private final Classpath inprocClasspath;
41  
42      public ModularClasspathConfiguration( @Nonnull ModularClasspath modularClasspath,
43                                            @Nonnull Classpath testClasspathUrls,
44                                            @Nonnull Classpath surefireClasspathUrls,
45                                            @Nonnull Classpath inprocClasspath,
46                                            boolean enableAssertions,
47                                            boolean childDelegation )
48      {
49          super( surefireClasspathUrls, enableAssertions, childDelegation );
50          this.modularClasspath = modularClasspath;
51          this.testClasspathUrls = testClasspathUrls;
52          this.inprocClasspath = inprocClasspath;
53      }
54  
55      @Override
56      public Classpath getTestClasspath()
57      {
58          return testClasspathUrls;
59      }
60  
61      @Override
62      public final boolean isModularPathConfig()
63      {
64          return true;
65      }
66  
67      @Override
68      public final boolean isClassPathConfig()
69      {
70          return !isModularPathConfig();
71      }
72  
73      public ModularClasspath getModularClasspath()
74      {
75          return modularClasspath;
76      }
77  
78      public ClassLoader createMergedClassLoader()
79              throws SurefireExecutionException
80      {
81          Collection<String> modulePath = getModularClasspath().getModulePath();
82          return createMergedClassLoader( join( getInprocTestClasspath(), new Classpath( modulePath ) ) );
83      }
84  
85      @Override
86      protected Classpath getInprocClasspath()
87      {
88          return inprocClasspath;
89      }
90  }