1 package net.sf.invicta.handler; 2 import java.util.ArrayList ; 3 import java.util.Iterator ; 4 import java.util.List ; 5 import java.util.Map ; 6 import java.util.StringTokenizer ; 7 8 import net.sf.invicta.InvictaConstants; 9 import net.sf.invicta.InvictaException; 10 import net.sf.invicta.api.DefinedProperty; 11 import net.sf.invicta.api.Product; 12 13 22 public class DistCopyCommandsHandler extends InvictaBasicHandler { 23 private final static boolean DEFAULT_ADD_COMPONENT_NAME = false; 24 private final static boolean DEFAULT_IS_SRC_PROPERTY = true; 25 private final static boolean DEFAULT_FLATTEN = false; 26 private final static String DIST_LIST_SEPARATOR = ","; 27 28 protected boolean flatten; 29 protected boolean addComponentName; 30 protected String projectDistDir; 31 protected String srcDir; 32 protected List srcList; 33 34 37 public String getName() { 38 return "distCopyCommands"; 39 } 40 41 44 public String handle(Map paramsMap) throws InvictaException { 45 46 String projectDistDirProperty = getRequiredParameter("distDirProperty"); 48 this.projectDistDir = 49 getPropertyReference(projectDistDirProperty); 50 this.addComponentName = getBooleanParameter("addComponentName", DEFAULT_ADD_COMPONENT_NAME); 51 this.flatten = getBooleanParameter("flatten", DEFAULT_FLATTEN); 52 String srcDirProperty = getParameter("srcDirProperty"); 53 String srcListProperty = getParameter("srcListProperty"); 54 55 if ((srcListProperty == null) && (srcDirProperty == null)) { 58 return getProductsCopyCommands(); 59 } 60 61 if (srcDirProperty != null) { 62 this.srcDir = getPropertyReference(srcDirProperty); 63 } else { 64 this.srcDir = getComponent().getDir(); 65 getPropertyReference(srcListProperty); 66 String srcDirListStr = getComponent().getPropertyValue(srcListProperty); 67 this.srcList = new ArrayList (); 68 StringTokenizer st = new StringTokenizer (srcDirListStr, DIST_LIST_SEPARATOR); 69 while (st.hasMoreTokens()) 70 this.srcList.add(st.nextToken().trim()); 71 72 } 73 74 return getFilesetCopyCommand(); 75 } 76 77 78 83 private String getProductsCopyCommands() { 84 String result = ""; 85 86 String localDistDir = getComponent().getDir(); 88 String distDir = this.projectDistDir + InvictaConstants.FILE_SEPARATOR + localDistDir; 89 90 for (Iterator prodIter = getComponent().getSelfProducts().iterator(); prodIter.hasNext();) { 92 Product product = (Product) prodIter.next(); 93 94 if (product.getFile() != null) { 95 96 String productDir = product.getRelativeDir(); 97 if (product.getFile().charAt(0) != InvictaConstants.FILE_SEPARATOR_CHAR) 98 productDir = InvictaConstants.FILE_SEPARATOR + productDir; 99 result += getCopyCommand(product.getPath(), distDir + productDir); 100 } 101 } 102 return result; 103 } 104 105 113 private String getCopyCommand(String srcFile, String distDir) { 114 return "<mkdir dir=\"" + this.projectDistDir + "\"/>\n" 115 + "<copy file=\"" + srcFile + "\" " 116 + "flatten=\"" + String.valueOf(flatten) + "\" " 117 + "todir=\"" + distDir 118 + "\" preservelastmodified=\"true\"" 119 + " includeemptydirs=\"false\"" + "/>\n"; 120 } 121 122 129 private String getFilesetCopyCommand() { 130 String fullDistDir; 131 if (addComponentName) 132 fullDistDir = this.projectDistDir + InvictaConstants.FILE_SEPARATOR + getComponent().getDir(); 133 else 134 fullDistDir = this.projectDistDir; 135 136 String command = "<mkdir dir=\"" 137 + fullDistDir 138 + "\"/>\n" 139 + "<copy todir=\"" 140 + fullDistDir 141 + "\" preservelastmodified=\"true\"" 142 + " includeemptydirs=\"false\"" 143 + " flatten=\"" + String.valueOf(flatten) + "\"" 144 + ">\n" 145 + "<fileset dir=\"" + srcDir + "\">\n"; 146 147 if (this.srcList != null) { 148 for (Iterator iter = this.srcList.iterator(); iter.hasNext();) { 149 String include = (String ) iter.next(); 150 command += "<include name=\"" + include + "/**/*\"/>\n"; 151 command += "<include name=\"" + include + "\"/>\n"; 152 } 153 } 154 155 command += "</fileset>\n"; 156 command += "</copy>\n"; 157 return command; 158 } 159 160 161 164 protected String getPropertyReference(String propertyName) throws InvictaHandlerException { 165 DefinedProperty property = getComponent().getDefinedProperty(propertyName); 166 if (property == null) { 167 throw new InvictaHandlerException(this, 168 "Property not defined: " + propertyName 169 + " for component '" + getComponent().getName() 170 + "' (type '" + getComponent().getTypeName() + "')"); 171 } 172 return property.getReferenceValue(); 173 } 174 } 175 | Popular Tags |