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