1 12 package org.eclipse.pde.internal.build.fetch; 13 14 import java.util.Map ; 15 import java.util.Properties ; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.pde.build.IAntScript; 19 import org.eclipse.pde.build.IFetchFactory; 20 import org.eclipse.pde.internal.build.*; 21 22 43 public class COPYFetchTasksFactory implements IFetchFactory, IPDEBuildConstants { 44 public static final String ID = "COPY"; 46 private static final String SEPARATOR = ","; private static final String OVERRIDE_TAG = ID; 48 49 private static final String KEY_PATH = "path"; private static final String KEY_ROOT = "root"; 53 public void generateRetrieveElementCall(Map entryInfos, IPath destination, IAntScript script) { 54 String element = (String ) entryInfos.get(KEY_ELEMENT_NAME); 55 56 String root = (String ) entryInfos.get(KEY_ROOT); 58 String path = (String ) entryInfos.get(KEY_PATH); 59 IPath sourcePath = new Path(root); 60 if (path != null) { 61 sourcePath = sourcePath.append(path); 62 } else { 63 sourcePath = sourcePath.append(element); 64 } 65 66 printCopyTask(null, destination.toString(), new String [] {sourcePath.toString()}, false, true, script); 67 } 68 69 public void generateRetrieveFilesCall(final Map entryInfos, IPath destination, final String [] files, IAntScript script) { 70 String root = (String ) entryInfos.get(KEY_ROOT); 71 String path = (String ) entryInfos.get(KEY_PATH); 72 73 for (int i = 0; i < files.length; i++) { 74 String file = files[i]; 75 IPath filePath = new Path(root); 76 if (path != null) { 77 filePath = filePath.append(path).append(file); 78 } else { 79 filePath = filePath.append((String ) entryInfos.get(KEY_ELEMENT_NAME)).append(file); 80 } 81 printCopyTask(filePath.toString(), destination.toString(), null, true, true, script); 82 } 83 } 84 85 public void addTargets(IAntScript script) { 86 } 88 89 public void parseMapFileEntry(String repoSpecificentry, Properties overrideTags, Map entryInfos) throws CoreException { 90 String [] arguments = Utils.getArrayFromStringWithBlank(repoSpecificentry, SEPARATOR); 91 if (arguments.length < 1) { 92 String message = NLS.bind(Messages.error_incorrectDirectoryEntry, entryInfos.get(KEY_ELEMENT_NAME)); 93 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null)); 94 } 95 96 String overrideTag = overrideTags != null ? overrideTags.getProperty(OVERRIDE_TAG) : null; 97 entryInfos.put(KEY_ROOT, (null == overrideTag || overrideTag.trim().length() == 0) ? arguments[0] : overrideTag); 98 entryInfos.put(KEY_PATH, (arguments.length > 1 && arguments[1].trim().length() > 0) ? arguments[1] : null); 99 } 100 101 111 private void printCopyTask(String file, String todir, String [] dirs, boolean failOnError, boolean overwrite, IAntScript script) { 112 script.printTabs(); 113 script.print("<copy"); script.printAttribute("file", file, false); script.printAttribute("todir", todir, false); script.printAttribute("failonerror", failOnError ? "true" : "false", true); script.printAttribute("overwrite", overwrite ? "true" : "false", true); 119 if (dirs == null) 120 script.println("/>"); else { 122 script.println(">"); for (int i = 0; i < dirs.length; i++) { 124 script.printTabs(); 125 script.print("\t<fileset"); script.printAttribute("dir", dirs[i], true); script.println("/>"); } 129 script.println("</copy>"); } 131 } 132 } 133 | Popular Tags |