1 6 package fr.jayasoft.ivy.ant; 7 8 import java.io.IOException ; 9 import java.text.ParseException ; 10 import java.util.ArrayList ; 11 import java.util.Arrays ; 12 import java.util.Collection ; 13 import java.util.Iterator ; 14 import java.util.LinkedHashSet ; 15 import java.util.List ; 16 import java.util.Set ; 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 35 public abstract class IvyCacheTask extends IvyPostResolveTask { 36 37 protected List getArtifacts() throws BuildException, ParseException , IOException { 38 Collection artifacts = getAllArtifacts(); 39 List ret = new ArrayList (); 40 for (Iterator 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 getAllArtifacts() throws ParseException , IOException { 51 String [] confs = splitConfs(getConf()); 52 Collection all = new LinkedHashSet (); 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 revisions = configurationReport.getModuleRevisionIds(); 63 for (Iterator 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 |