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