1 | |
package org.apache.maven.shared.runtime; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.net.URL; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import org.apache.maven.project.MavenProject; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 160 | public class DefaultMavenRuntime implements MavenRuntime |
36 | |
{ |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public MavenProjectProperties getProjectProperties( URL url ) throws MavenRuntimeException |
43 | |
{ |
44 | 12 | PropertiesMavenRuntimeVisitor visitor = new PropertiesMavenRuntimeVisitor(); |
45 | |
|
46 | 12 | MavenRuntimeVisitorUtils.accept( url, visitor ); |
47 | |
|
48 | 12 | return first( visitor.getProjects() ); |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public MavenProjectProperties getProjectProperties( Class<?> klass ) throws MavenRuntimeException |
55 | |
{ |
56 | 28 | PropertiesMavenRuntimeVisitor visitor = new PropertiesMavenRuntimeVisitor(); |
57 | |
|
58 | 28 | MavenRuntimeVisitorUtils.accept( klass, visitor ); |
59 | |
|
60 | 28 | return first( visitor.getProjects() ); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public List<MavenProjectProperties> getProjectsProperties( ClassLoader classLoader ) throws MavenRuntimeException |
67 | |
{ |
68 | 24 | PropertiesMavenRuntimeVisitor visitor = new PropertiesMavenRuntimeVisitor(); |
69 | |
|
70 | 24 | MavenRuntimeVisitorUtils.accept( classLoader, visitor ); |
71 | |
|
72 | 24 | return visitor.getProjects(); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public MavenProject getProject( URL url ) throws MavenRuntimeException |
79 | |
{ |
80 | 12 | XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor(); |
81 | |
|
82 | 12 | MavenRuntimeVisitorUtils.accept( url, visitor ); |
83 | |
|
84 | 12 | return first( visitor.getProjects() ); |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public MavenProject getProject( Class<?> klass ) throws MavenRuntimeException |
91 | |
{ |
92 | 28 | XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor(); |
93 | |
|
94 | 28 | MavenRuntimeVisitorUtils.accept( klass, visitor ); |
95 | |
|
96 | 28 | return first( visitor.getProjects() ); |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public List<MavenProject> getProjects( ClassLoader classLoader ) throws MavenRuntimeException |
103 | |
{ |
104 | 24 | XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor(); |
105 | |
|
106 | 24 | MavenRuntimeVisitorUtils.accept( classLoader, visitor ); |
107 | |
|
108 | 24 | return visitor.getProjects(); |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public List<MavenProject> getSortedProjects( ClassLoader classLoader ) throws MavenRuntimeException |
115 | |
{ |
116 | 32 | XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor(); |
117 | |
|
118 | 32 | MavenRuntimeVisitorUtils.accept( classLoader, visitor ); |
119 | |
|
120 | 32 | return visitor.getSortedProjects(); |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
private static <T> T first( List<T> list ) |
135 | |
{ |
136 | 80 | return !list.isEmpty() ? list.get( 0 ) : null; |
137 | |
} |
138 | |
} |