~ubuntu-branches/ubuntu/karmic/ivy/karmic

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/core/report/ResolveReport.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-06 22:04:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090306220456-5v37luqiuqda8ewp
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
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.
 
16
 *
 
17
 */
 
18
package org.apache.ivy.core.report;
 
19
 
 
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;
 
28
import java.util.Map;
 
29
 
 
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;
 
38
 
 
39
/**
 
40
 * Represents a whole resolution report for a module
 
41
 */
 
42
public class ResolveReport {
 
43
    private ModuleDescriptor md;
 
44
 
 
45
    /** String conf -> ConfigurationResolveReport report */
 
46
    private Map confReports = new LinkedHashMap();
 
47
 
 
48
    private List problemMessages = new ArrayList();
 
49
 
 
50
    /**
 
51
     * the list of all dependencies resolved, ordered from the more dependent to the less dependent
 
52
     */
 
53
    private List dependencies = new ArrayList();
 
54
 
 
55
    private List artifacts = new ArrayList();
 
56
 
 
57
    private long resolveTime;
 
58
 
 
59
    private long downloadTime;
 
60
 
 
61
    private String resolveId;
 
62
 
 
63
    private long downloadSize;
 
64
 
 
65
    public ResolveReport(ModuleDescriptor md) {
 
66
        this(md, ResolveOptions.getDefaultResolveId(md));
 
67
    }
 
68
 
 
69
    public ResolveReport(ModuleDescriptor md, String resolveId) {
 
70
        this.md = md;
 
71
        this.resolveId = resolveId;
 
72
    }
 
73
 
 
74
    public void addReport(String conf, ConfigurationResolveReport report) {
 
75
        confReports.put(conf, report);
 
76
    }
 
77
 
 
78
    public ConfigurationResolveReport getConfigurationReport(String conf) {
 
79
        return (ConfigurationResolveReport) confReports.get(conf);
 
80
    }
 
81
 
 
82
    public String[] getConfigurations() {
 
83
        return (String[]) confReports.keySet().toArray(new String[confReports.size()]);
 
84
    }
 
85
 
 
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();
 
91
        }
 
92
        return hasError;
 
93
    }
 
94
 
 
95
    public void output(
 
96
            ReportOutputter[] outputters, ResolutionCacheManager cacheMgr, ResolveOptions options)
 
97
            throws IOException {
 
98
        for (int i = 0; i < outputters.length; i++) {
 
99
            outputters[i].output(this, cacheMgr, options);
 
100
        }
 
101
    }
 
102
 
 
103
    public ModuleDescriptor getModuleDescriptor() {
 
104
        return md;
 
105
    }
 
106
 
 
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()));
 
112
        }
 
113
        return (IvyNode[]) all.toArray(new IvyNode[all.size()]);
 
114
    }
 
115
 
 
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()));
 
121
        }
 
122
        return (IvyNode[]) all.toArray(new IvyNode[all.size()]);
 
123
    }
 
124
 
 
125
    /**
 
126
     * Get every report on the download requests.
 
127
     * 
 
128
     * @return the list of reports, never <code>null</code>
 
129
     */
 
130
    public ArtifactDownloadReport[] getFailedArtifactsReports() {
 
131
        return ConfigurationResolveReport.filterOutMergedArtifacts(
 
132
            getArtifactsReports(DownloadStatus.FAILED, true));
 
133
    }
 
134
 
 
135
    /**
 
136
     * Get every report on the download requests.
 
137
     * 
 
138
     * @return the list of reports, never <code>null</code>
 
139
     */
 
140
    public ArtifactDownloadReport[] getAllArtifactsReports() {
 
141
        return getArtifactsReports(null, true);
 
142
    }
 
143
 
 
144
    /**
 
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.
 
147
     * 
 
148
     * @param downloadStatus
 
149
     *            the status of download to retreive. Set it to <code>null</code> for no
 
150
     *            restriction on the download status
 
151
     * @param withEvicted
 
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
 
154
     *            configurations.
 
155
     * @return the list of reports, never <code>null</code>
 
156
     * @see ConfigurationResolveReport#getArtifactsReports(DownloadStatus, boolean)
 
157
     */
 
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));
 
166
        }
 
167
        return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]);
 
168
    }
 
169
 
 
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)));
 
175
        }
 
176
        return (ArtifactDownloadReport[]) all.toArray(new ArtifactDownloadReport[all.size()]);
 
177
    }
 
178
 
 
179
    
 
180
    public void checkIfChanged() {
 
181
        for (Iterator iter = confReports.values().iterator(); iter.hasNext();) {
 
182
            ConfigurationResolveReport report = (ConfigurationResolveReport) iter.next();
 
183
            report.checkIfChanged();
 
184
        }
 
185
    }
 
186
 
 
187
    
 
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()) {
 
193
                return true;
 
194
            }
 
195
        }
 
196
        return false;
 
197
    }
 
198
 
 
199
    public void setProblemMessages(List problems) {
 
200
        problemMessages = problems;
 
201
    }
 
202
 
 
203
    public List getProblemMessages() {
 
204
        return problemMessages;
 
205
    }
 
206
 
 
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);
 
216
                } else {
 
217
                    ret.add("unresolved dependency: " + unresolved[i].getId());
 
218
                }
 
219
            }
 
220
            ArtifactDownloadReport[] adrs = r.getFailedArtifactsReports();
 
221
            for (int i = 0; i < adrs.length; i++) {
 
222
                ret.add("download failed: " + adrs[i].getArtifact());
 
223
            }
 
224
        }
 
225
        return ret;
 
226
    }
 
227
 
 
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)));
 
236
            }
 
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);
 
244
                }
 
245
            }
 
246
        }
 
247
    }
 
248
 
 
249
    /**
 
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
 
252
     * 
 
253
     * @return The list of all dependencies.
 
254
     */
 
255
    public List getDependencies() {
 
256
        return dependencies;
 
257
    }
 
258
 
 
259
    /**
 
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.
 
262
     * 
 
263
     * @return The list of all artifacts.
 
264
     */
 
265
    public List getArtifacts() {
 
266
        return artifacts;
 
267
    }
 
268
 
 
269
    /**
 
270
     * gives all the modules ids concerned by this report, from the most dependent to the least one
 
271
     * 
 
272
     * @return a list of ModuleId
 
273
     */
 
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)) {
 
281
                ret.add(mid);
 
282
            }
 
283
        }
 
284
        return ret;
 
285
    }
 
286
 
 
287
    public void setResolveTime(long elapsedTime) {
 
288
        resolveTime = elapsedTime;
 
289
    }
 
290
 
 
291
    public long getResolveTime() {
 
292
        return resolveTime;
 
293
    }
 
294
 
 
295
    public void setDownloadTime(long elapsedTime) {
 
296
        downloadTime = elapsedTime;
 
297
    }
 
298
 
 
299
    public long getDownloadTime() {
 
300
        return downloadTime;
 
301
    }
 
302
 
 
303
    public void setDownloadSize(long size) {
 
304
        this.downloadSize = size;
 
305
    }
 
306
 
 
307
    /**
 
308
     * The total size of downloaded artifacts, in bytes.
 
309
     * <p>
 
310
     * This only includes artifacts actually downloaded to cache (DownloadStatus.SUCCESSFUL), and
 
311
     * not artifacts already in cache or used at their original location.
 
312
     * </p>
 
313
     * 
 
314
     * @return The total size of downloaded artifacts, in bytes.
 
315
     */
 
316
    public long getDownloadSize() {
 
317
        return downloadSize;
 
318
    }
 
319
 
 
320
    public String getResolveId() {
 
321
        return resolveId;
 
322
    }
 
323
 
 
324
}