1 | |
package org.apache.maven.surefire.booter; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.surefire.util.UrlUtils; |
23 | |
|
24 | |
import java.io.File; |
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; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class Classpath |
37 | |
{ |
38 | |
public static Classpath join( Classpath firstClasspath, Classpath secondClasspath ) |
39 | |
{ |
40 | 0 | Classpath joinedClasspath = new Classpath(); |
41 | 0 | joinedClasspath.addElementsOfClasspath( firstClasspath ); |
42 | 0 | joinedClasspath.addElementsOfClasspath( secondClasspath ); |
43 | 0 | return joinedClasspath; |
44 | |
} |
45 | |
|
46 | 0 | private final List elements = new ArrayList(); |
47 | |
|
48 | |
public Classpath() |
49 | 0 | { |
50 | 0 | } |
51 | |
|
52 | |
public Classpath( List elements ) |
53 | |
{ |
54 | 0 | this(); |
55 | 0 | addElements( elements ); |
56 | 0 | } |
57 | |
|
58 | |
public void addClassPathElementUrl( String path ) |
59 | |
{ |
60 | 0 | if ( path == null ) |
61 | |
{ |
62 | 0 | throw new IllegalArgumentException( "Null is not a valid class path element url." ); |
63 | |
} |
64 | 0 | else if ( !elements.contains( path ) ) |
65 | |
{ |
66 | 0 | elements.add( path ); |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
private void addElements( List additionalElements ) |
71 | |
{ |
72 | 0 | for ( Iterator it = additionalElements.iterator(); it.hasNext(); ) |
73 | |
{ |
74 | 0 | String element = (String) it.next(); |
75 | 0 | addClassPathElementUrl( element ); |
76 | 0 | } |
77 | 0 | } |
78 | |
|
79 | |
private void addElementsOfClasspath( Classpath otherClasspath ) |
80 | |
{ |
81 | 0 | if ( otherClasspath != null ) |
82 | |
{ |
83 | 0 | addElements( otherClasspath.elements ); |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
public List getClassPath() |
88 | |
{ |
89 | 0 | return Collections.unmodifiableList( elements ); |
90 | |
} |
91 | |
|
92 | |
public List getAsUrlList() |
93 | |
throws MalformedURLException |
94 | |
{ |
95 | 0 | List urls = new ArrayList(); |
96 | 0 | for ( Iterator i = elements.iterator(); i.hasNext(); ) |
97 | |
{ |
98 | 0 | String url = (String) i.next(); |
99 | 0 | File f = new File( url ); |
100 | 0 | urls.add( UrlUtils.getURL( f ) ); |
101 | 0 | } |
102 | 0 | return urls; |
103 | |
} |
104 | |
|
105 | |
public void writeToSystemProperty( String propertyName ) |
106 | |
{ |
107 | 0 | StringBuffer sb = new StringBuffer(); |
108 | 0 | for ( Iterator i = elements.iterator(); i.hasNext(); ) |
109 | |
{ |
110 | 0 | sb.append( (String) i.next() ).append( File.pathSeparatorChar ); |
111 | |
} |
112 | 0 | System.setProperty( propertyName, sb.toString() ); |
113 | 0 | } |
114 | |
|
115 | |
public boolean equals( Object o ) |
116 | |
{ |
117 | 0 | if ( this == o ) |
118 | |
{ |
119 | 0 | return true; |
120 | |
} |
121 | 0 | if ( o == null || getClass() != o.getClass() ) |
122 | |
{ |
123 | 0 | return false; |
124 | |
} |
125 | |
|
126 | 0 | Classpath classpath = (Classpath) o; |
127 | |
|
128 | 0 | return !( elements != null ? !elements.equals( classpath.elements ) : classpath.elements != null ); |
129 | |
|
130 | |
} |
131 | |
|
132 | |
public int hashCode() |
133 | |
{ |
134 | 0 | return elements != null ? elements.hashCode() : 0; |
135 | |
} |
136 | |
} |