KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > ant > IvyCacheTask


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.ant;
7
8 import java.io.IOException JavaDoc;
9 import java.text.ParseException JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import java.util.Arrays JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.LinkedHashSet JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Set JavaDoc;
17
18 import org.apache.tools.ant.BuildException;
19
20 import fr.jayasoft.ivy.Artifact;
21 import fr.jayasoft.ivy.ModuleRevisionId;
22 import fr.jayasoft.ivy.report.ArtifactDownloadReport;
23 import fr.jayasoft.ivy.report.ConfigurationResolveReport;
24 import fr.jayasoft.ivy.report.ResolveReport;
25 import fr.jayasoft.ivy.util.Message;
26 import fr.jayasoft.ivy.xml.XmlReportParser;
27
28 /**
29  * Base class for the cache path related classes: cachepath and cachefileset.
30  *
31  * Most of the behviour is common to the two, since only the produced element differs.
32  *
33  * @author Xavier Hanin
34  */

35 public abstract class IvyCacheTask extends IvyPostResolveTask {
36
37     protected List JavaDoc getArtifacts() throws BuildException, ParseException JavaDoc, IOException JavaDoc {
38         Collection JavaDoc artifacts = getAllArtifacts();
39         List JavaDoc ret = new ArrayList JavaDoc();
40         for (Iterator JavaDoc iter = artifacts.iterator(); iter.hasNext();) {
41             Artifact artifact = (Artifact)iter.next();
42             if (getArtifactFilter().accept(artifact)) {
43                 ret.add(artifact);
44             }
45         }
46         
47         return ret;
48     }
49
50     private Collection JavaDoc getAllArtifacts() throws ParseException JavaDoc, IOException JavaDoc {
51         String JavaDoc[] confs = splitConfs(getConf());
52         Collection JavaDoc all = new LinkedHashSet JavaDoc();
53
54         ResolveReport report = getResolvedReport();
55         if (report != null) {
56             Message.debug("using internal report instance to get artifacts list");
57             for (int i = 0; i < confs.length; i++) {
58                 ConfigurationResolveReport configurationReport = report.getConfigurationReport(confs[i]);
59                 if (configurationReport == null) {
60                     throw new BuildException("bad confs provided: "+confs[i]+" not found among "+Arrays.asList(report.getConfigurations()));
61                 }
62                 Set JavaDoc revisions = configurationReport.getModuleRevisionIds();
63                 for (Iterator JavaDoc it = revisions.iterator(); it.hasNext(); ) {
64                     ModuleRevisionId revId = (ModuleRevisionId) it.next();
65                     ArtifactDownloadReport[] aReps = configurationReport.getDownloadReports(revId);
66                     for (int j = 0; j < aReps.length; j++) {
67                         all.add(aReps[j].getArtifact());
68                     }
69                 }
70             }
71         } else {
72             Message.debug("using stored report to get artifacts list");
73             XmlReportParser parser = new XmlReportParser();
74             
75             for (int i = 0; i < confs.length; i++) {
76                 Artifact[] artifacts = parser.getArtifacts(getResolvedModuleId(), confs[i], getCache());
77                 all.addAll(Arrays.asList(artifacts));
78             }
79         }
80         return all;
81     }
82 }
83
Popular Tags