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  /**
23   * Represents the classpaths for the BooterConfiguration.
24   * <p/>
25   *
26   * @author Jason van Zyl
27   * @author Emmanuel Venisse
28   * @author Kristian Rosenvold
29   */
30  public class ClasspathConfiguration
31  {
32      public static final String CHILD_DELEGATION = "childDelegation";
33  
34      public static final String ENABLE_ASSERTIONS = "enableAssertions";
35  
36      public static final String CLASSPATH = "classPathUrl.";
37  
38      public static final String SUREFIRE_CLASSPATH = "surefireClassPathUrl.";
39  
40      private final Classpath classpathUrls;
41  
42      private final Classpath surefireClasspathUrls;
43  
44      /**
45       * The surefire classpath to use when invoking in-process with the plugin
46       */
47      private final Classpath inprocClasspath;
48  
49      /**
50       * Whether to enable assertions or not (can be affected by the fork arguments, and the ability to do so based on the
51       * JVM).
52       */
53      private final boolean enableAssertions;
54  
55      // todo: @deprecated because the IsolatedClassLoader is really isolated - no parent.
56      private final boolean childDelegation;
57  
58      public ClasspathConfiguration( boolean enableAssertions, boolean childDelegation )
59      {
60          this( Classpath.emptyClasspath(), Classpath.emptyClasspath(), Classpath.emptyClasspath(), enableAssertions,
61                childDelegation );
62      }
63  
64      ClasspathConfiguration( PropertiesWrapper properties )
65      {
66          this( properties.getClasspath( CLASSPATH ), properties.getClasspath( SUREFIRE_CLASSPATH ),
67                Classpath.emptyClasspath(),
68                properties.getBooleanProperty( ENABLE_ASSERTIONS ), properties.getBooleanProperty( CHILD_DELEGATION ) );
69      }
70  
71      public ClasspathConfiguration( Classpath testClasspath, Classpath surefireClassPathUrls, Classpath inprocClasspath,
72                                     boolean enableAssertions, boolean childDelegation )
73      {
74          this.enableAssertions = enableAssertions;
75          this.childDelegation = childDelegation;
76          this.inprocClasspath = inprocClasspath;
77          this.classpathUrls = testClasspath;
78          this.surefireClasspathUrls = surefireClassPathUrls;
79      }
80  
81      public ClassLoader createMergedClassLoader()
82          throws SurefireExecutionException
83      {
84          return Classpath.join( inprocClasspath, classpathUrls )
85              .createClassLoader( null, this.childDelegation, enableAssertions, "test" );
86      }
87  
88      public Classpath getProviderClasspath()
89      {
90          return surefireClasspathUrls;
91      }
92  
93  
94          public Classpath getTestClasspath()
95      {
96          return classpathUrls;
97      }
98  
99      public void trickClassPathWhenManifestOnlyClasspath()
100         throws SurefireExecutionException
101     {
102             System.setProperty( "surefire.real.class.path", System.getProperty( "java.class.path" ) );
103             getTestClasspath().writeToSystemProperty( "java.class.path" );
104     }
105 
106     public boolean isEnableAssertions()
107     {
108         return enableAssertions;
109     }
110 
111     public boolean isChildDelegation()
112     {
113         return childDelegation;
114     }
115 }