1 11 package org.eclipse.pde.internal.build.fetch; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.*; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.pde.build.IAntScript; 18 import org.eclipse.pde.build.IFetchFactory; 19 import org.eclipse.pde.internal.build.*; 20 21 39 public class GETFetchFactory implements IFetchFactory { 40 41 private static final String UNPACK = "unpack"; private static final String SEPARATOR = ","; private static final String TASK_GET = "get"; private static final String TASK_DELETE = "delete"; private static final String TASK_UNZIP = "unzip"; private static final String ATTRIBUTE_SRC = "src"; private static final String ATTRIBUTE_DEST = "dest"; private static final String ATTRIBUTE_FILE = "file"; private static final String ATTRIBUTE_VERBOSE = "verbose"; private static final String ATTRIBUTE_IGNORE_ERRORS = "ignoreerrors"; private static final String ATTRIBUTE_USE_TIMESTAMP = "usetimestamp"; private static final String ATTRIBUTE_USERNAME = "username"; private static final String ATTRIBUTE_PASSWORD = "password"; private static final String TAG_OPEN = "<"; private static final String TAG_CLOSE = "/>"; 57 60 public void addTargets(IAntScript script) { 61 } 63 64 67 public void generateRetrieveElementCall(Map entryInfos, IPath destination, IAntScript script) { 68 printGetTask(destination, script, entryInfos); 69 } 70 71 74 public void generateRetrieveFilesCall(Map entryInfos, IPath destination, String [] files, IAntScript script) { 75 } 77 78 81 public void parseMapFileEntry(String rawEntry, Properties overrideTags, Map entryInfos) throws CoreException { 82 String url = rawEntry; 83 if (rawEntry.indexOf(',') != -1) { 84 StringTokenizer tokenizer = new StringTokenizer(rawEntry, SEPARATOR); 85 if (tokenizer.hasMoreTokens()) 86 url = tokenizer.nextToken(); 87 while (tokenizer.hasMoreTokens()) { 88 String token = tokenizer.nextToken(); 89 int index = token.indexOf('='); 90 if (index == -1) { 91 IStatus status = new Status(IStatus.WARNING, IPDEBuildConstants.PI_PDEBUILD, "Problems parsing map file entry: " + rawEntry); 93 BundleHelper.getDefault().getLog().log(status); 94 } else { 95 String key = token.substring(0, index).trim(); 96 String value = token.substring(index + 1).trim(); 97 entryInfos.put(key, value); 98 } 99 } 100 } 101 try { 102 new URL (url); 103 } catch (MalformedURLException e) { 104 throw new CoreException(new Status(IStatus.ERROR, IPDEBuildConstants.PI_PDEBUILD, "Invalid URL in map file entry: " + rawEntry)); 105 } 106 entryInfos.put(ATTRIBUTE_SRC, url); 107 } 108 109 112 private void printGetTask(IPath destination, IAntScript script, Map entryInfos) { 113 String src = (String ) entryInfos.get(ATTRIBUTE_SRC); 114 int index = src.lastIndexOf('/'); 115 String filename = index == -1 ? src : src.substring(index); 116 117 script.printTabs(); 119 script.print(TAG_OPEN + TASK_GET); 120 script.printAttribute(ATTRIBUTE_SRC, src, true); 121 122 String dest = (String ) entryInfos.get(ATTRIBUTE_DEST); 124 if (dest == null) 125 dest = destination.removeLastSegments(1).append(filename).toOSString(); 126 script.printAttribute(ATTRIBUTE_DEST, dest, true); 127 128 String ignoreErrors = (String ) entryInfos.get(ATTRIBUTE_IGNORE_ERRORS); 130 if (ignoreErrors != null) 131 script.printAttribute(ATTRIBUTE_IGNORE_ERRORS, ignoreErrors, false); 132 133 String useTimestamp = (String ) entryInfos.get(ATTRIBUTE_USE_TIMESTAMP); 134 if (useTimestamp != null) 135 script.printAttribute(ATTRIBUTE_USE_TIMESTAMP, useTimestamp, false); 136 137 String verbose = (String ) entryInfos.get(ATTRIBUTE_VERBOSE); 138 if (verbose != null) 139 script.printAttribute(ATTRIBUTE_VERBOSE, verbose, false); 140 141 String username = (String ) entryInfos.get(ATTRIBUTE_USERNAME); 142 String password = (String ) entryInfos.get(ATTRIBUTE_PASSWORD); 143 if (username != null) 144 script.printAttribute(ATTRIBUTE_USERNAME, username, password != null); 145 if (password != null) 146 script.printAttribute(ATTRIBUTE_PASSWORD, password, username != null); 147 148 script.print(TAG_CLOSE); 149 150 boolean unpack = Boolean.valueOf((String ) entryInfos.get(UNPACK)).booleanValue(); 152 if (unpack || ELEMENT_TYPE_FEATURE.equals(entryInfos.get(KEY_ELEMENT_TYPE))) { 153 script.printTabs(); 154 script.print(TAG_OPEN + TASK_UNZIP); 155 script.printAttribute(ATTRIBUTE_SRC, dest, true); 156 script.printAttribute(ATTRIBUTE_DEST, new Path(dest).removeLastSegments(1).toOSString(), true); 157 script.print(TAG_CLOSE); 158 159 script.printTabs(); 160 script.print(TAG_OPEN + TASK_DELETE); 161 script.printAttribute(ATTRIBUTE_FILE, dest, true); 162 script.print(TAG_CLOSE); 163 } 164 script.println(); 165 } 166 167 } 168 | Popular Tags |