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 static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
25  
26  /**
27   * Represents the classpaths for the BooterConfiguration.
28   * <br>
29   *
30   * @author Jason van Zyl
31   * @author Emmanuel Venisse
32   * @author Kristian Rosenvold
33   */
34  public class ClasspathConfiguration extends AbstractPathConfiguration
35  {
36      private final Classpath testClasspathUrls;
37  
38      /**
39       * The surefire classpath to use when invoking in-process with the plugin
40       */
41      private final Classpath inprocClasspath;
42  
43      public ClasspathConfiguration( boolean enableAssertions, boolean childDelegation )
44      {
45          this( emptyClasspath(), emptyClasspath(), emptyClasspath(), enableAssertions, childDelegation );
46      }
47  
48      ClasspathConfiguration( @Nonnull PropertiesWrapper properties )
49      {
50          this( properties.getClasspath( CLASSPATH ), properties.getClasspath( SUREFIRE_CLASSPATH ), emptyClasspath(),
51                properties.getBooleanProperty( ENABLE_ASSERTIONS ), properties.getBooleanProperty( CHILD_DELEGATION ) );
52      }
53  
54      public ClasspathConfiguration( @Nonnull Classpath testClasspathUrls, @Nonnull Classpath surefireClassPathUrls,
55                                     @Nonnull Classpath inprocClasspath, boolean enableAssertions,
56                                     boolean childDelegation )
57      {
58          super( surefireClassPathUrls, enableAssertions, childDelegation );
59          this.testClasspathUrls = testClasspathUrls;
60          this.inprocClasspath = inprocClasspath;
61      }
62  
63      @Override
64      protected Classpath getInprocClasspath()
65      {
66          return inprocClasspath;
67      }
68  
69      public Classpath getTestClasspath()
70      {
71          return testClasspathUrls;
72      }
73  
74      @Override
75      public final boolean isModularPathConfig()
76      {
77          return !isClassPathConfig();
78      }
79  
80      @Override
81      public final boolean isClassPathConfig()
82      {
83          return true;
84      }
85  
86      public void trickClassPathWhenManifestOnlyClasspath()
87      {
88          System.setProperty( "surefire.real.class.path", System.getProperty( "java.class.path" ) );
89          getTestClasspath().writeToSystemProperty( "java.class.path" );
90      }
91  }