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, outputScope, sort ) );
162 }
163
164 if ( this.skippedDependencies != null && !this.skippedDependencies.isEmpty() )
165 {
166 sb.append( "\n" );
167 sb.append( "The following files were skipped:\n" );
168 Set<Artifact> skippedDependencies = new LinkedHashSet<Artifact>();
169 skippedDependencies.addAll( this.skippedDependencies );
170 sb.append( buildArtifactListOutput( skippedDependencies, outputAbsoluteArtifactFilename, outputScope, sort ) );
171 }
172
173 if ( this.unResolvedDependencies != null && !this.unResolvedDependencies.isEmpty() )
174 {
175 sb.append( "\n" );
176 sb.append( "The following files have NOT been resolved:\n" );
177 Set<Artifact> unResolvedDependencies = new LinkedHashSet<Artifact>();
178 unResolvedDependencies.addAll( this.unResolvedDependencies );
179 sb.append( buildArtifactListOutput( unResolvedDependencies, outputAbsoluteArtifactFilename, outputScope, sort ) );
180 }
181 sb.append( "\n" );
182
183 return sb.toString();
184 }
185
186 private StringBuilder buildArtifactListOutput(Set<Artifact> artifacts, boolean outputAbsoluteArtifactFilename, boolean outputScope, boolean sort )
187 {
188 StringBuilder sb = new StringBuilder();
189 List<String> artifactStringList = new ArrayList<String>();
190 for ( Artifact artifact : artifacts )
191 {
192 String artifactFilename = null;
193 if ( outputAbsoluteArtifactFilename )
194 {
195 try
196 {
197
198 artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
199 }
200 catch ( NullPointerException e )
201 {
202
203 artifactFilename = null;
204 }
205 }
206
207 String id = outputScope ? artifact.toString() : artifact.getId();
208
209 artifactStringList.add( " " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) + "\n" );
210 }
211 if ( sort )
212 {
213 Collections.sort( artifactStringList );
214 }
215 for (String artifactString : artifactStringList)
216 {
217 sb.append( artifactString );
218 }
219 return sb;
220 }
221 }