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