1 7 package com.inversoft.savant.ant.taskdefs; 8 9 10 import java.io.File ; 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 import org.apache.tools.ant.BuildException; 15 import org.apache.tools.ant.taskdefs.Copy; 16 import org.apache.tools.ant.types.FileSet; 17 import org.apache.tools.ant.types.PatternSet; 18 19 import com.inversoft.savant.Artifact; 20 import com.inversoft.savant.ArtifactGroup; 21 import com.inversoft.savant.LocalCacheStore; 22 import com.inversoft.savant.SavantException; 23 import com.inversoft.savant.ant.types.ArtifactGroupType; 24 import com.inversoft.savant.ant.types.ArtifactType; 25 26 27 37 public class ArtifactCopyTask extends Copy { 38 39 private File localCache; 40 private final List artifacts = new ArrayList (); 41 private final List groups = new ArrayList (); 42 43 44 50 public void setLocalcache(File localCache) { 51 this.localCache = localCache; 52 } 53 54 59 public void addArtifact(ArtifactType artifact) { 60 artifacts.add(artifact.getProxy()); 61 } 62 63 68 public void addArtifactgroup(ArtifactGroupType group) { 69 groups.add(group.getProxy()); 70 } 71 72 75 public void execute() { 76 LocalCacheStore lcs; 77 try { 78 lcs = new LocalCacheStore(localCache); 79 } catch (SavantException se) { 80 log("Invalid local cache location [" + localCache.getAbsolutePath() + "]"); 81 throw new BuildException(se); 82 } 83 84 FileSet fs = new FileSet(); 85 fs.setProject(getProject()); 86 fs.setDir(lcs.getLocation()); 87 addIncludes(fs, artifacts); 88 89 for (int i = 0; i < groups.size(); i++) { 90 ArtifactGroup artifactGroup = (ArtifactGroup) groups.get(i); 91 addIncludes(fs, artifactGroup.getArtifacts()); 92 } 93 94 super.addFileset(fs); 95 super.execute(); 96 } 97 98 102 private void addIncludes(FileSet fs, List artifacts) { 103 for (int i = 0; i < artifacts.size(); i++) { 104 Artifact artifact = (Artifact) artifacts.get(i); 105 PatternSet.NameEntry ne = fs.createInclude(); 106 ne.setName(artifact.getArtifactFile()); 107 } 108 } 109 } | Popular Tags |