1 12 package org.eclipse.pde.internal.build.fetch; 13 14 import java.util.*; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.pde.build.*; 18 import org.eclipse.pde.internal.build.*; 19 20 38 public class CVSFetchTaskFactory implements IFetchFactory { 39 public static final String ID = "CVS"; 41 private static final String TARGET_GET_FROM_CVS = "FetchFromCVS"; private static final String SEPARATOR = ","; public static final String OVERRIDE_TAG = ID; 44 45 private static final String KEY_CVSROOT = "cvsRoot"; private static final String KEY_CVSPASSFILE = "cvsPassFile"; private static final String KEY_PASSWORD = "password"; private static final String KEY_PATH = "path"; private static final String KEY_PREBUILT = "prebuilt"; 52 private static final String PROP_DESTINATIONFOLDER = "destinationFolder"; private static final String PROP_CVSROOT = "cvsRoot"; private static final String PROP_MODULE = "module"; private static final String PROP_TAG = "tag"; private static final String PROP_QUIET = "quiet"; private static final String PROP_FILETOCHECK = "fileToCheck"; private static final String PROP_ELEMENTNAME = "elementName"; 61 private void generateAuthentificationAntTask(Map entryInfos, IAntScript script) { 62 String password = (String ) entryInfos.get(KEY_PASSWORD); 63 String cvsPassFileLocation = (String ) entryInfos.get(KEY_CVSPASSFILE); 64 if (password != null) 65 printCVSPassTask((String ) entryInfos.get(KEY_CVSROOT), password, cvsPassFileLocation, script); 66 } 67 68 public void generateRetrieveElementCall(Map entryInfos, IPath destination, IAntScript script) { 69 String type = (String ) entryInfos.get(KEY_ELEMENT_TYPE); 70 String element = (String ) entryInfos.get(KEY_ELEMENT_NAME); 71 boolean prebuilt = "true".equalsIgnoreCase((String ) entryInfos.get(KEY_PREBUILT)); 72 73 Map params = new HashMap(5); 74 int remove = prebuilt ? 2 : 1; 78 String suggestedPath = destination.lastSegment(); 79 params.put(PROP_DESTINATIONFOLDER, destination.removeLastSegments(remove).toString()); 80 params.put(PROP_TAG, entryInfos.get(IFetchFactory.KEY_ELEMENT_TAG)); 81 params.put(PROP_CVSROOT, entryInfos.get(KEY_CVSROOT)); 82 params.put(PROP_QUIET, "${cvs.quiet}"); if (prebuilt) { 86 if (type.equals(ELEMENT_TYPE_PLUGIN)) 87 element = IPDEBuildConstants.DEFAULT_PLUGIN_LOCATION; 88 else if (type.equals(ELEMENT_TYPE_FEATURE)) 89 element = IPDEBuildConstants.DEFAULT_FEATURE_LOCATION; 90 } else { 91 if (suggestedPath != null) 92 element = suggestedPath; 93 } 94 params.put(PROP_ELEMENTNAME, element); 95 String module = entryInfos.get(KEY_PATH) == null ? element : (String ) entryInfos.get(KEY_PATH); 96 params.put(PROP_MODULE, module); 97 98 IPath locationToCheck = (IPath) destination.clone(); 99 if (prebuilt) { 102 locationToCheck = locationToCheck.removeLastSegments(1); 103 locationToCheck = locationToCheck.append(new Path(module).lastSegment()); 104 } else { 105 if (type.equals(ELEMENT_TYPE_FEATURE)) { 106 locationToCheck = locationToCheck.append(Constants.FEATURE_FILENAME_DESCRIPTOR); 107 } else if (type.equals(ELEMENT_TYPE_PLUGIN)) { 108 locationToCheck = locationToCheck.append(Constants.PLUGIN_FILENAME_DESCRIPTOR); 109 } else if (type.equals(ELEMENT_TYPE_FRAGMENT)) { 110 locationToCheck = locationToCheck.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR); 111 } else if (type.equals(ELEMENT_TYPE_BUNDLE)) { 112 locationToCheck = locationToCheck.append(Constants.BUNDLE_FILENAME_DESCRIPTOR); 113 } 114 } 115 params.put(PROP_FILETOCHECK, locationToCheck.toString()); 116 117 printAvailableTask(locationToCheck.toString(), locationToCheck.toString(), script); 118 if (!prebuilt&& (type.equals(IFetchFactory.ELEMENT_TYPE_PLUGIN) || type.equals(IFetchFactory.ELEMENT_TYPE_FRAGMENT))) { 119 printAvailableTask(locationToCheck.toString(), locationToCheck.removeLastSegments(1).append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toString(), script); 120 } 121 122 generateAuthentificationAntTask(entryInfos, script); 123 script.printAntCallTask(TARGET_GET_FROM_CVS, true, params); 124 } 125 126 public void generateRetrieveFilesCall(final Map entryInfos, IPath destination, final String [] files, IAntScript script) { 127 generateAuthentificationAntTask(entryInfos, script); 128 String path = (String ) entryInfos.get(KEY_PATH); 129 for (int i = 0; i < files.length; i++) { 130 String file = files[i]; 131 IPath filePath; 132 if (path != null) { 133 filePath = new Path(path).append(file); 134 } else { 135 filePath = new Path((String ) entryInfos.get(KEY_ELEMENT_NAME)).append(file); 136 } 137 String tag = (String ) entryInfos.get(IFetchFactory.KEY_ELEMENT_TAG); 138 String cvsRoot = (String ) entryInfos.get(KEY_CVSROOT); 139 String dest = "true".equalsIgnoreCase((String ) entryInfos.get(KEY_PREBUILT)) ? destination.removeLastSegments(1).toString() : destination.toString(); printCVSTask("export -r " + tag + ' ' + filePath.toString(), cvsRoot, dest, null, null, "true", null, null, "${fetch.failonerror}", script); script.println("<move file=\"" + destination + '/' + filePath + "\"" + " tofile=\"" + destination.append(file) + "\" failonerror=\"false\" />"); } 143 } 144 145 public void addTargets(IAntScript script) { 146 script.printTargetDeclaration(TARGET_GET_FROM_CVS, null, null, "${fileToCheck}", null); printCVSTask("export -d ${" + PROP_ELEMENTNAME + "}", "${" + PROP_CVSROOT + "}", "${" + PROP_DESTINATIONFOLDER + "}", "${" + PROP_MODULE + "}", "${" + PROP_TAG + "}", "${" + PROP_QUIET + "}", null, "CVS - ${" + PROP_MODULE + "}", script); script.printTargetEnd(); 149 } 150 151 156 private void legacyParseMapFileEntry(String [] arguments, Properties overrideTags, Map entryInfos) { 157 String overrideTag = overrideTags != null ? overrideTags.getProperty(OVERRIDE_TAG) : null; 158 entryInfos.put(KEY_CVSPASSFILE, (arguments.length > 4 && !arguments[4].equals("")) ? arguments[4] : null); entryInfos.put(IFetchFactory.KEY_ELEMENT_TAG, (overrideTag != null && overrideTag.trim().length() != 0 ? overrideTag : arguments[0])); 160 entryInfos.put(KEY_CVSROOT, arguments[1]); 161 entryInfos.put(KEY_PASSWORD, (arguments.length > 2 && !arguments[2].equals("")) ? arguments[2] : null); entryInfos.put(KEY_PATH, (arguments.length > 3 && !arguments[3].equals("")) ? arguments[3] : null); } 164 165 public void parseMapFileEntry(String repoSpecificentry, Properties overrideTags, Map entryInfos) throws CoreException { 166 String [] arguments = Utils.getArrayFromStringWithBlank(repoSpecificentry, SEPARATOR); 167 if (arguments.length < 2) { 168 String message = NLS.bind(Messages.error_incorrectDirectoryEntry, entryInfos.get(KEY_ELEMENT_NAME)); 169 throw new CoreException(new Status(IStatus.ERROR, IPDEBuildConstants.PI_PDEBUILD, 1, message, null)); } 171 172 Map table = new HashMap(); 174 for (int i=0; i<arguments.length; i++) { 175 String arg = arguments[i]; 176 int index = arg.indexOf('='); 179 if (index == -1) { 180 legacyParseMapFileEntry(arguments, overrideTags, entryInfos); 181 return; 182 } 183 String key = arg.substring(0, index); 184 String value = arg.substring(index+1); 185 table.put(key, value); 186 } 187 188 entryInfos.put(KEY_CVSPASSFILE, table.get(KEY_CVSPASSFILE)); 192 String overrideTag = overrideTags != null ? overrideTags.getProperty(OVERRIDE_TAG) : null; 193 entryInfos.put(IFetchFactory.KEY_ELEMENT_TAG, (overrideTag != null && overrideTag.trim().length() != 0 ? overrideTag : table.get(IFetchFactory.KEY_ELEMENT_TAG))); 194 entryInfos.put(KEY_CVSROOT, table.get(KEY_CVSROOT)); 195 entryInfos.put(KEY_PASSWORD, table.get(KEY_PASSWORD)); 196 entryInfos.put(KEY_PATH, table.get(KEY_PATH)); 197 entryInfos.put(KEY_PREBUILT, table.get(KEY_PREBUILT)); 198 } 199 200 211 private void printCVSTask(String command, String cvsRoot, String dest, String module, String tag, String quiet, String passFile, String taskname, IAntScript script) { 212 printCVSTask(command, cvsRoot, dest, module, tag, quiet, passFile, taskname, null, script); 213 } 214 215 227 private void printCVSTask(String command, String cvsRoot, String dest, String module, String tag, String quiet, String passFile, String taskname, String failOnError, IAntScript script) { 228 script.printTabs(); 229 script.print("<cvs"); script.printAttribute("command", command, false); script.printAttribute("cvsRoot", cvsRoot, false); script.printAttribute("dest", dest, false); script.printAttribute("package", module, false); script.printAttribute("tag", tag, false); script.printAttribute("quiet", quiet, false); script.printAttribute("passfile", passFile, false); script.printAttribute("taskname", taskname, false); script.printAttribute("failonerror", failOnError, false); script.println("/>"); } 241 242 249 private void printCVSPassTask(String cvsRoot, String password, String passFile, IAntScript script) { 250 script.printTabs(); 251 script.print("<cvspass"); script.printAttribute("cvsRoot", cvsRoot, true); script.printAttribute("password", password, true); script.printAttribute("passfile", passFile, false); script.println("/>"); } 257 258 265 private void printAvailableTask(String property, String file, IAntScript script) { 266 script.printTabs(); 267 script.print("<available"); script.printAttribute("property", property, true); script.printAttribute("file", file, false); script.println("/>"); } 272 } 273 | Popular Tags |