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