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 public class DefaultMavenRuntime implements MavenRuntime
36 {
37
38
39
40
41
42 public MavenProjectProperties getProjectProperties( URL url ) throws MavenRuntimeException
43 {
44 PropertiesMavenRuntimeVisitor visitor = new PropertiesMavenRuntimeVisitor();
45
46 MavenRuntimeVisitorUtils.accept( url, visitor );
47
48 return first( visitor.getProjects() );
49 }
50
51
52
53
54 public MavenProjectProperties getProjectProperties( Class<?> klass ) throws MavenRuntimeException
55 {
56 PropertiesMavenRuntimeVisitor visitor = new PropertiesMavenRuntimeVisitor();
57
58 MavenRuntimeVisitorUtils.accept( klass, visitor );
59
60 return first( visitor.getProjects() );
61 }
62
63
64
65
66 public List<MavenProjectProperties> getProjectsProperties( ClassLoader classLoader ) throws MavenRuntimeException
67 {
68 PropertiesMavenRuntimeVisitor visitor = new PropertiesMavenRuntimeVisitor();
69
70 MavenRuntimeVisitorUtils.accept( classLoader, visitor );
71
72 return visitor.getProjects();
73 }
74
75
76
77
78 public MavenProject getProject( URL url ) throws MavenRuntimeException
79 {
80 XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor();
81
82 MavenRuntimeVisitorUtils.accept( url, visitor );
83
84 return first( visitor.getProjects() );
85 }
86
87
88
89
90 public MavenProject getProject( Class<?> klass ) throws MavenRuntimeException
91 {
92 XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor();
93
94 MavenRuntimeVisitorUtils.accept( klass, visitor );
95
96 return first( visitor.getProjects() );
97 }
98
99
100
101
102 public List<MavenProject> getProjects( ClassLoader classLoader ) throws MavenRuntimeException
103 {
104 XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor();
105
106 MavenRuntimeVisitorUtils.accept( classLoader, visitor );
107
108 return visitor.getProjects();
109 }
110
111
112
113
114 public List<MavenProject> getSortedProjects( ClassLoader classLoader ) throws MavenRuntimeException
115 {
116 XMLMavenRuntimeVisitor visitor = new XMLMavenRuntimeVisitor();
117
118 MavenRuntimeVisitorUtils.accept( classLoader, visitor );
119
120 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 return !list.isEmpty() ? list.get( 0 ) : null;
137 }
138 }