2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.ivy.core.report;
20
import java.io.IOException;
21
import java.util.ArrayList;
22
import java.util.Arrays;
23
import java.util.Collection;
24
import java.util.Iterator;
25
import java.util.LinkedHashMap;
26
import java.util.LinkedHashSet;
27
import java.util.List;
30
import org.apache.ivy.core.cache.ResolutionCacheManager;
31
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
32
import org.apache.ivy.core.module.id.ModuleId;
33
import org.apache.ivy.core.module.id.ModuleRevisionId;
34
import org.apache.ivy.core.resolve.IvyNode;
35
import org.apache.ivy.core.resolve.ResolveOptions;
36
import org.apache.ivy.plugins.report.ReportOutputter;
37
import org.apache.ivy.util.filter.Filter;
40
* Represents a whole resolution report for a module
42
public class ResolveReport {
43
private ModuleDescriptor md;
45
/** String conf -> ConfigurationResolveReport report */
46
private Map confReports = new LinkedHashMap();
48
private List problemMessages = new ArrayList();
51
* the list of all dependencies resolved, ordered from the more dependent to the less dependent
53
private List dependencies = new ArrayList();
55
private List artifacts = new ArrayList();
57
private long resolveTime;
59
private long downloadTime;
61
private String resolveId;
63
private long downloadSize;
65
public ResolveReport(ModuleDescriptor md) {
66
this(md, ResolveOptions.getDefaultResolveId(md));
69
public ResolveReport(ModuleDescriptor md, String resolveId) {
71
this.resolveId = resolveId;
74
public void addReport(String conf, ConfigurationResolveReport report) {
75
confReports.put(conf, report);
78
public ConfigurationResolveReport getConfigurationReport(String conf) {
79
return (ConfigurationResolveReport) confReports.get(conf);
82
public String[] getConfigurations() {
83
return (String[]) confReports.keySet().toArray(new String[confReports.size()]);
86
public boolean hasError() {
87
boolean hasError = false;
88
for (Iterator it = confReports.values().iterator(); it.hasNext() && !hasError;) {
89
ConfigurationResolveReport report = (ConfigurationResolveReport) it.next();
90
hasError |= report.hasError();
96
ReportOutputter[] outputters, ResolutionCacheManager cacheMgr, ResolveOptions options)
98
for (int i = 0; i < outputters.length; i++) {
99
outputters[i].output(this, cacheMgr, options);
103
public ModuleDescriptor getModuleDescriptor() {
107
public IvyNode[] getEvictedNodes() {
108
Collection all = new LinkedHashSet();
109
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
110
ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
111
all.addAll(Arrays.asList(report.getEvictedNodes()));
113
return (IvyNode[]) all.toArray(new IvyNode[all.size()]);
116
public IvyNode[] getUnresolvedDependencies() {
117
Collection all = new LinkedHashSet();
118
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
119
ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
120
all.addAll(Arrays.asList(report.getUnresolvedDependencies()));
122
return (IvyNode[]) all.toArray(new IvyNode[all.size()]);
126
* Get every report on the download requests.
128
* @return the list of reports, never <code>null</code>
130
public ArtifactDownloadReport[] getFailedArtifactsReports() {
131
return ConfigurationResolveReport.filterOutMergedArtifacts(
132
getArtifactsReports(DownloadStatus.FAILED, true));
136
* Get every report on the download requests.
138
* @return the list of reports, never <code>null</code>
140
public ArtifactDownloadReport[] getAllArtifactsReports() {
141
return getArtifactsReports(null, true);
145
* Get the report on the download requests. The list of download report can be restricted to a
146
* specific download status, and also remove the download report for the evicted modules.
148
* @param downloadStatus
149
* the status of download to retreive. Set it to <code>null</code> for no
150
* restriction on the download status
152
* set it to <code>true</code> if the report for the evicted modules have to be
153
* retrieved, <code>false</code> to exclude reports from modules evicted in all
155
* @return the list of reports, never <code>null</code>
156
* @see ConfigurationResolveReport#getArtifactsReports(DownloadStatus, boolean)
158
public ArtifactDownloadReport[] getArtifactsReports(
159
DownloadStatus downloadStatus, boolean withEvicted) {
160
Collection all = new LinkedHashSet();
161
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
162
ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
163
ArtifactDownloadReport[] reports =
164
report.getArtifactsReports(downloadStatus, withEvicted);
165
all.addAll(Arrays.asList(reports));
167
return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]);
170
public ArtifactDownloadReport[] getArtifactsReports(ModuleRevisionId mrid) {
171
Collection all = new LinkedHashSet();
172
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
173
ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
174
all.addAll(Arrays.asList(report.getDownloadReports(mrid)));
176
return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]);
180
public void checkIfChanged() {
181
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
182
ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
183
report.checkIfChanged();
188
/** Can only be called if checkIfChanged has been called */
189
public boolean hasChanged() {
190
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
191
ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
192
if (report.hasChanged()) {
199
public void setProblemMessages(List problems) {
200
problemMessages = problems;
203
public List getProblemMessages() {
204
return problemMessages;
207
public List getAllProblemMessages() {
208
List ret = new ArrayList(problemMessages);
209
for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
210
ConfigurationResolveReport r = (ConfigurationResolveReport) iter.next();
211
IvyNode[] unresolved = r.getUnresolvedDependencies();
212
for (int i = 0; i < unresolved.length; i++) {
213
String errMsg = unresolved[i].getProblemMessage();
214
if (errMsg.length() > 0) {
215
ret.add("unresolved dependency: " + unresolved[i].getId() + ": " + errMsg);
217
ret.add("unresolved dependency: " + unresolved[i].getId());
220
ArtifactDownloadReport[] adrs = r.getFailedArtifactsReports();
221
for (int i = 0; i < adrs.length; i++) {
222
ret.add("download failed: " + adrs[i].getArtifact());
228
public void setDependencies(List dependencies, Filter artifactFilter) {
229
this.dependencies = dependencies;
230
// collect list of artifacts
231
artifacts = new ArrayList();
232
for (Iterator iter = dependencies.iterator(); iter.hasNext();) {
233
IvyNode dependency = (IvyNode) iter.next();
234
if (!dependency.isCompletelyEvicted() && !dependency.hasProblem()) {
235
artifacts.addAll(Arrays.asList(dependency.getSelectedArtifacts(artifactFilter)));
237
// update the configurations reports with the dependencies
238
// these reports will be completed later with download information, if any
239
String[] dconfs = dependency.getRootModuleConfigurations();
240
for (int j = 0; j < dconfs.length; j++) {
241
ConfigurationResolveReport configurationReport = getConfigurationReport(dconfs[j]);
242
if (configurationReport != null) {
243
configurationReport.addDependency(dependency);
250
* Returns the list of all dependencies concerned by this report as a List of IvyNode ordered
251
* from the more dependent to the least one
253
* @return The list of all dependencies.
255
public List getDependencies() {
260
* Returns the list of all artifacts which should be downloaded per this resolve To know if the
261
* artifact have actually been downloaded use information found in ConfigurationResolveReport.
263
* @return The list of all artifacts.
265
public List getArtifacts() {
270
* gives all the modules ids concerned by this report, from the most dependent to the least one
272
* @return a list of ModuleId
274
public List getModuleIds() {
275
List ret = new ArrayList();
276
List sortedDependencies = new ArrayList(dependencies);
277
for (Iterator iter = sortedDependencies.iterator(); iter.hasNext();) {
278
IvyNode dependency = (IvyNode) iter.next();
279
ModuleId mid = dependency.getResolvedId().getModuleId();
280
if (!ret.contains(mid)) {
287
public void setResolveTime(long elapsedTime) {
288
resolveTime = elapsedTime;
291
public long getResolveTime() {
295
public void setDownloadTime(long elapsedTime) {
296
downloadTime = elapsedTime;
299
public long getDownloadTime() {
303
public void setDownloadSize(long size) {
304
this.downloadSize = size;
308
* The total size of downloaded artifacts, in bytes.
310
* This only includes artifacts actually downloaded to cache (DownloadStatus.SUCCESSFUL), and
311
* not artifacts already in cache or used at their original location.
314
* @return The total size of downloaded artifacts, in bytes.
316
public long getDownloadSize() {
320
public String getResolveId() {