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