1 | |
package org.apache.maven.plugin.dependency.utils; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
import java.util.Iterator; |
27 | |
import java.util.Set; |
28 | |
import java.util.SortedSet; |
29 | |
import java.util.TreeSet; |
30 | |
|
31 | |
import org.apache.maven.artifact.Artifact; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class DependencyStatusSets |
38 | |
{ |
39 | |
|
40 | 132 | TreeSet resolvedDependencies = null; |
41 | |
|
42 | 132 | TreeSet unResolvedDependencies = null; |
43 | |
|
44 | 132 | TreeSet skippedDependencies = null; |
45 | |
|
46 | |
public DependencyStatusSets() |
47 | 11 | { |
48 | |
|
49 | 11 | } |
50 | |
|
51 | |
public DependencyStatusSets( Set resolved, Set unResolved, Set skipped ) |
52 | 121 | { |
53 | 121 | if ( resolved != null ) |
54 | |
{ |
55 | 112 | this.resolvedDependencies = new TreeSet( resolved ); |
56 | |
} |
57 | 121 | if ( unResolved != null ) |
58 | |
{ |
59 | 12 | this.unResolvedDependencies = new TreeSet( unResolved ); |
60 | |
} |
61 | 121 | if ( skipped != null ) |
62 | |
{ |
63 | 112 | this.skippedDependencies = new TreeSet( skipped ); |
64 | |
} |
65 | 121 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public Set getResolvedDependencies() |
71 | |
{ |
72 | 104 | return this.resolvedDependencies; |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public void setResolvedDependencies( Set resolvedDependencies ) |
80 | |
{ |
81 | 4 | if ( resolvedDependencies != null ) |
82 | |
{ |
83 | 4 | this.resolvedDependencies = new TreeSet( resolvedDependencies ); |
84 | |
} |
85 | |
else |
86 | |
{ |
87 | 0 | this.resolvedDependencies = null; |
88 | |
} |
89 | 4 | } |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public Set getSkippedDependencies() |
95 | |
{ |
96 | 89 | return this.skippedDependencies; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public void setSkippedDependencies( Set skippedDependencies ) |
104 | |
{ |
105 | 0 | if ( skippedDependencies != null ) |
106 | |
{ |
107 | 0 | this.skippedDependencies = new TreeSet( skippedDependencies ); |
108 | |
} |
109 | |
else |
110 | |
{ |
111 | 0 | this.skippedDependencies = null; |
112 | |
} |
113 | 0 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
public Set getUnResolvedDependencies() |
119 | |
{ |
120 | 0 | return this.unResolvedDependencies; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public void setUnResolvedDependencies( Set unResolvedDependencies ) |
128 | |
{ |
129 | 4 | if ( unResolvedDependencies != null ) |
130 | |
{ |
131 | 4 | this.unResolvedDependencies = new TreeSet( unResolvedDependencies ); |
132 | |
} |
133 | |
else |
134 | |
{ |
135 | 0 | this.unResolvedDependencies = null; |
136 | |
} |
137 | 4 | } |
138 | |
|
139 | |
public String getOutput(boolean outputAbsoluteArtifactFilename ) |
140 | |
{ |
141 | 48 | return getOutput(outputAbsoluteArtifactFilename, true ); |
142 | |
} |
143 | |
|
144 | |
public String getOutput(boolean outputAbsoluteArtifactFilename, boolean outputScope ) |
145 | |
{ |
146 | 62 | StringBuffer sb = new StringBuffer(); |
147 | 62 | sb.append( "\n" ); |
148 | 62 | sb.append( "The following files have been resolved:\n" ); |
149 | 62 | if ( this.resolvedDependencies == null || this.resolvedDependencies.isEmpty() ) |
150 | |
{ |
151 | 36 | sb.append( " none\n" ); |
152 | |
} |
153 | |
else |
154 | |
{ |
155 | 26 | for ( Iterator i = resolvedDependencies.iterator(); i.hasNext(); ) |
156 | |
{ |
157 | 297 | Artifact artifact = (Artifact) i.next(); |
158 | 297 | String artifactFilename = null; |
159 | 297 | if ( outputAbsoluteArtifactFilename ) |
160 | |
{ |
161 | |
try |
162 | |
{ |
163 | |
|
164 | 144 | artifactFilename = artifact.getFile().getAbsoluteFile().getPath(); |
165 | |
} |
166 | 72 | catch ( NullPointerException e ) |
167 | |
{ |
168 | |
|
169 | 72 | artifactFilename = null; |
170 | 72 | } |
171 | |
} |
172 | |
|
173 | 297 | String id = outputScope ? artifact.toString() : artifact.getId(); |
174 | |
|
175 | 297 | sb.append( " " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) +"\n"); |
176 | 297 | } |
177 | |
} |
178 | |
|
179 | 62 | if ( this.skippedDependencies != null && !this.skippedDependencies.isEmpty() ) |
180 | |
{ |
181 | 24 | sb.append( "\n" ); |
182 | 24 | sb.append( "The following files were skipped:\n" ); |
183 | 24 | SortedSet sortedSkippedDependencies = new TreeSet(); |
184 | 24 | sortedSkippedDependencies.addAll( this.skippedDependencies ); |
185 | 24 | for ( Iterator i = sortedSkippedDependencies.iterator(); i.hasNext(); ) |
186 | |
{ |
187 | 288 | sb.append( " " + ( (Artifact) i.next() ).getId()+"\n" ); |
188 | |
} |
189 | |
} |
190 | |
|
191 | 62 | if ( this.unResolvedDependencies != null && !this.unResolvedDependencies.isEmpty() ) |
192 | |
{ |
193 | 24 | sb.append( "\n" ); |
194 | 24 | sb.append( "The following files have NOT been resolved:\n" ); |
195 | 24 | SortedSet sortedUnResolvedDependencies = new TreeSet(); |
196 | 24 | sortedUnResolvedDependencies.addAll( this.unResolvedDependencies ); |
197 | 24 | for ( Iterator i = sortedUnResolvedDependencies.iterator(); i.hasNext(); ) |
198 | |
{ |
199 | 288 | sb.append( " " + ( (Artifact) i.next() ).getId()+"\n" ); |
200 | |
} |
201 | |
} |
202 | 62 | sb.append("\n"); |
203 | |
|
204 | 62 | return sb.toString(); |
205 | |
} |
206 | |
} |