1 7 package com.inversoft.savant.ant.taskdefs; 8 9 10 import java.io.File ; 11 import java.util.Set ; 12 13 import org.apache.tools.ant.BuildException; 14 import org.apache.tools.ant.Task; 15 16 import com.inversoft.savant.ArtifactTools; 17 import com.inversoft.savant.LocalCacheStore; 18 import com.inversoft.savant.SavantException; 19 import com.inversoft.savant.ant.types.ArtifactType; 20 import com.inversoft.savant.ant.types.DependenciesType; 21 22 23 31 public class PublishTask extends Task { 32 33 private File from; 34 private File localcache; 35 private ArtifactType artifact; 36 private DependenciesType deps; 37 38 39 public File getFrom() { 40 return from; 41 } 42 43 public void setFrom(File from) { 44 this.from = from; 45 } 46 47 public File getLocalcache() { 48 return localcache; 49 } 50 51 public void setLocalcache(File localcache) { 52 this.localcache = localcache; 53 } 54 55 61 public void addArtifact(ArtifactType artifact) { 62 if (this.artifact != null) { 63 throw new BuildException("Only one artifact per publish tag"); 64 } 65 66 this.artifact = artifact; 67 } 68 69 76 public void addDependencies(DependenciesType deps) { 77 if (this.deps != null) { 78 throw new BuildException("Only one artifact per publish tag"); 79 } 80 81 this.deps = deps; 82 } 83 84 89 public void execute() throws BuildException { 90 validate(); 91 92 LocalCacheStore lcs; 93 try { 94 lcs = new LocalCacheStore(localcache); 95 } catch (SavantException se) { 96 log("Invalid local cache location [" + localcache.getAbsolutePath() + "]"); 97 throw new BuildException(se); 98 } 99 100 try { 101 lcs.store(artifact.getProxy(), from); 102 } catch (SavantException se) { 103 throw new BuildException(se); 104 } 105 106 log("Published artifact [" + artifact.getProxy() + "]"); 107 108 if (deps != null) { 110 Set artifacts = deps.getAllArtifacts(); 111 if (artifacts.size() > 0) { 112 File file = null; 113 try { 114 file = ArtifactTools.generateXML(artifacts); 115 lcs.storeDeps(artifact.getProxy(), file); 116 } catch (SavantException se) { 117 throw new BuildException(se); 118 } finally { 119 if (file != null) { 120 file.delete(); 121 } 122 } 123 } 124 } 125 } 126 127 130 private void validate() { 131 if (from == null) { 132 throw new BuildException("from attribute required for publish task"); 133 } 134 135 if (!from.exists() || from.isDirectory()) { 136 throw new BuildException("Invalid from file [" + from.getAbsolutePath() + 137 "]"); 138 } 139 } 140 } | Popular Tags |