1
package org.apache.maven.surefire.booter;
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
12
* http://www.apache.org/licenses/LICENSE-2.0
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
22
import org.apache.maven.surefire.util.UrlUtils;
25
import java.net.MalformedURLException;
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.Iterator;
29
import java.util.List;
32
* An ordered list of classpath elements with set behaviour
34
* @author Kristian Rosenvold
36
public class Classpath
38
public static Classpath join( Classpath firstClasspath, Classpath secondClasspath )
40
Classpath joinedClasspath = new Classpath();
41
joinedClasspath.addElementsOfClasspath( firstClasspath );
42
joinedClasspath.addElementsOfClasspath( secondClasspath );
43
return joinedClasspath;
46
private final List elements = new ArrayList();
52
public Classpath( List elements )
55
addElements( elements );
58
public void addClassPathElementUrl( String path )
62
throw new IllegalArgumentException( "Null is not a valid class path element url." );
64
else if ( !elements.contains( path ) )
70
private void addElements( List additionalElements )
72
for ( Iterator it = additionalElements.iterator(); it.hasNext(); )
74
String element = (String) it.next();
75
addClassPathElementUrl( element );
79
private void addElementsOfClasspath( Classpath otherClasspath )
81
if ( otherClasspath != null )
83
addElements( otherClasspath.elements );
87
public List getClassPath()
89
return Collections.unmodifiableList( elements );
92
public List getAsUrlList()
93
throws MalformedURLException
95
List urls = new ArrayList();
96
for ( Iterator i = elements.iterator(); i.hasNext(); )
98
String url = (String) i.next();
99
File f = new File( url );
100
urls.add( UrlUtils.getURL( f ) );
105
public void writeToSystemProperty( String propertyName )
107
StringBuffer sb = new StringBuffer();
108
for ( Iterator i = elements.iterator(); i.hasNext(); )
110
sb.append( (String) i.next() ).append( File.pathSeparatorChar );
112
System.setProperty( propertyName, sb.toString() );
115
public boolean equals( Object o )
121
if ( o == null || getClass() != o.getClass() )
126
Classpath classpath = (Classpath) o;
128
return !( elements != null ? !elements.equals( classpath.elements ) : classpath.elements != null );
132
public int hashCode()
134
return elements != null ? elements.hashCode() : 0;