Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 34757 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/build/IXMLConstants.java (-1 / +1 lines)
Lines 53-59 Link Here
53
	public static final String TARGET_FETCH_ELEMENT = "fetch.element"; //$NON-NLS-1$
53
	public static final String TARGET_FETCH_ELEMENT = "fetch.element"; //$NON-NLS-1$
54
	public static final String TARGET_FETCH_PLUGINS = "fetch.plugins"; //$NON-NLS-1$
54
	public static final String TARGET_FETCH_PLUGINS = "fetch.plugins"; //$NON-NLS-1$
55
	public static final String TARGET_FETCH_RECURSIVELY = "fetch.recursively"; //$NON-NLS-1$
55
	public static final String TARGET_FETCH_RECURSIVELY = "fetch.recursively"; //$NON-NLS-1$
56
	public static final String TARGET_GET_FROM_CVS = "getFromCVS"; //$NON-NLS-1$
56
	public static final String TARGET_FETCH_FROM_REPOSITORY = "fetchFromRepository"; //$NON-NLS-1$
57
	public static final String TARGET_EFFECTIVE_FETCH = "effectiveFetch"; //$NON-NLS-1$
57
	public static final String TARGET_EFFECTIVE_FETCH = "effectiveFetch"; //$NON-NLS-1$
58
	public static final String TARGET_JARUP = "jarUp"; //$NON-NLS-1$
58
	public static final String TARGET_JARUP = "jarUp"; //$NON-NLS-1$
59
	public static final String TARGET_JARING = "jarIng"; //$NON-NLS-1$
59
	public static final String TARGET_JARING = "jarIng"; //$NON-NLS-1$
(-)src/org/eclipse/pde/internal/build/BuildActivator.java (+1 lines)
Lines 20-24 Link Here
20
20
21
	public void stop(BundleContext ctx) throws Exception {
21
	public void stop(BundleContext ctx) throws Exception {
22
		BundleHelper.close();
22
		BundleHelper.close();
23
        FetchTaskFactoriesRegistry.shutdown();
23
	}
24
	}
24
}
25
}
(-)src/org/eclipse/pde/internal/build/FetchScriptGenerator.java (-298 / +324 lines)
Lines 15-54 Link Here
15
import org.eclipse.ant.core.AntRunner;
15
import org.eclipse.ant.core.AntRunner;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.pde.build.FetchTaskFactory;
18
import org.eclipse.pde.internal.build.ant.AntScript;
19
import org.eclipse.pde.internal.build.ant.AntScript;
20
import org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory;
19
import org.eclipse.update.core.*;
21
import org.eclipse.update.core.*;
20
import org.eclipse.update.internal.core.FeatureExecutableFactory;
22
import org.eclipse.update.internal.core.FeatureExecutableFactory;
21
23
22
/**
24
/**
23
 * Generates Ant scripts which will use the CVS "fetch" element
25
 * Generates Ant scripts with a repository specific factory
24
 * to retrieve plug-ins and features from the CVS repository.
26
 * to retrieve plug-ins and features from a repository.
25
 */
27
 */
26
public class FetchScriptGenerator extends AbstractScriptGenerator {
28
public class FetchScriptGenerator extends AbstractScriptGenerator {
27
	private static final String BUNDLE = "bundle"; //$NON-NLS-1$
29
	private static final String BUNDLE = FetchTaskFactory.ELEMENT_TYPE_BUNDLE;
28
	private static final String FRAGMENT = "fragment"; //$NON-NLS-1$
30
	private static final String FRAGMENT = FetchTaskFactory.ELEMENT_TYPE_FRAGMENT;
29
	private static final String PLUGIN = "plugin"; //$NON-NLS-1$
31
	private static final String PLUGIN = FetchTaskFactory.ELEMENT_TYPE_PLUGIN;
30
	private static final String FEATURE = "feature"; //$NON-NLS-1$
32
	private static final String FEATURE = FetchTaskFactory.ELEMENT_TYPE_FEATURE;
31
	private static final String ELEMENT = "element"; //$NON-NLS-1$
33
	private static final String ELEMENT = FetchTaskFactory.KEY_ELEMENT_NAME;
32
	private static final String TYPE = "type"; //$NON-NLS-1$
34
	private static final String TYPE = FetchTaskFactory.KEY_ELEMENT_TYPE;
33
	private static final String PATH = "path"; //$NON-NLS-1$
35
	private static final String FETCH_TASK_FACTORY = FetchTaskFactory.KEY_FACTORY;
34
	private static final String PASSWORD = "password"; //$NON-NLS-1$
36
35
	private static final String CVSROOT = "cvsRoot"; //$NON-NLS-1$
37
	public static final String FEATURE_ONLY = "featureOnly"; //$NON-NLS-1$
36
	private static final String TAG = "tag"; //$NON-NLS-1$
38
39
	public static final String FEATURE_AND_PLUGINS = "featureAndPlugins"; //$NON-NLS-1$
40
	public static final String FEATURES_RECURSIVELY = "featuresRecursively"; //$NON-NLS-1$
41
42
	public static final String FETCH_FILE_PREFIX = "fetch_"; //$NON-NLS-1$
43
44
	/**
45
	 * Deletes all the files and directories from the given root down (inclusive).
46
	 * Returns false if we could not delete some file or an exception occurred
47
	 * at any point in the deletion.
48
	 * Even if an exception occurs, a best effort is made to continue deleting.
49
	 * 
50
	 * @param root
51
	 * @return boolean
52
	 */
53
	public static boolean clear(File root) {
54
		boolean result = true;
55
		if (root.isDirectory()) {
56
			String[] list = root.list();
57
			// for some unknown reason, list() can return null.  
58
			// Just skip the children If it does.
59
			if (list != null)
60
				for (int i = 0; i < list.length; i++)
61
					result &= clear(new java.io.File(root, list[i]));
62
		}
63
		try {
64
			if (root.exists())
65
				result &= root.delete();
66
		} catch (Exception e) {
67
			// ignore any exceptions
68
			result = false;
69
		}
70
		return result;
71
	}
37
72
38
	// flag saying if we want to recursively generate the scripts	
73
	// flag saying if we want to recursively generate the scripts	
39
	protected boolean recursiveGeneration = true;
74
	protected boolean recursiveGeneration = true;
40
75
	// Points to the map files containing references to repository
41
	// Points to the map files containing references to cvs repository
42
	protected String directoryLocation;
76
	protected String directoryLocation;
43
	protected Properties directory;
77
	protected Properties directory;
44
45
	// The location of the CVS password file.
78
	// The location of the CVS password file.
46
	protected String cvsPassFileLocation;
79
	protected String cvsPassFileLocation;
47
48
	protected boolean fetchChildren = true;
80
	protected boolean fetchChildren = true;
49
50
	protected String fetchTag = ""; //$NON-NLS-1$
81
	protected String fetchTag = ""; //$NON-NLS-1$
51
52
	// The element (an entry of the map file) for which we create the script 
82
	// The element (an entry of the map file) for which we create the script 
53
	protected String element;
83
	protected String element;
54
	// The feature object representing the element
84
	// The feature object representing the element
Lines 63-73 Link Here
63
	protected Properties repositoryPluginTags = new Properties();
93
	protected Properties repositoryPluginTags = new Properties();
64
	protected Properties repositoryFeatureTags = new Properties();
94
	protected Properties repositoryFeatureTags = new Properties();
65
95
66
	public static final String FEATURE_ONLY = "featureOnly"; //$NON-NLS-1$
67
	public static final String FEATURE_AND_PLUGINS = "featureAndPlugins"; //$NON-NLS-1$
68
	public static final String FEATURES_RECURSIVELY = "featuresRecursively"; //$NON-NLS-1$
69
	public static final String FETCH_FILE_PREFIX = "fetch_"; //$NON-NLS-1$
70
71
	private String scriptName;
96
	private String scriptName;
72
97
73
	public FetchScriptGenerator() {
98
	public FetchScriptGenerator() {
Lines 78-87 Link Here
78
		setElement(element);
103
		setElement(element);
79
	}
104
	}
80
105
81
	public void setElement(String element) {
82
		this.element = element;
83
	}
84
85
	/**
106
	/**
86
	 * @see AbstractScriptGenerator#generate()
107
	 * @see AbstractScriptGenerator#generate()
87
	 */
108
	 */
Lines 101-140 Link Here
101
			closeScript();
122
			closeScript();
102
		}
123
		}
103
124
104
		if (recursiveGeneration && mapInfos.get(TYPE).equals(FEATURE)) 
125
		if (recursiveGeneration && mapInfos.get(TYPE).equals(FEATURE))
105
			generateFetchFilesForIncludedFeatures();
126
			generateFetchFilesForIncludedFeatures();
106
127
107
		saveRepositoryTags();
128
		saveRepositoryTags();
108
	}
129
	}
109
130
110
	private void saveRepositoryTags(Properties properties, String fileName) throws CoreException {
131
	/**
111
		try {
132
	 * 
112
			InputStream input = new BufferedInputStream(new FileInputStream(workingDirectory + '/' + fileName)); 
133
	 * @throws CoreException
113
			try {
134
	 */
114
				properties.load(input);
135
	protected void generateChildrenFetchScript() throws CoreException {
115
			} finally {
136
		IPluginEntry[] allChildren = feature.getRawPluginEntries();
116
				input.close();
137
		IPluginEntry[] compiledChildren = feature.getPluginEntries();
138
139
		for (int i = 0; i < allChildren.length; i++) {
140
			String elementId = allChildren[i].getVersionedIdentifier().getIdentifier();
141
			// We are not fetching the elements that are said to be generated, but we are fetching some elements that can be associated
142
			if (featureProperties.containsKey(GENERATION_SOURCE_PLUGIN_PREFIX + elementId)) {
143
				String[] extraElementsToFetch = Utils.getArrayFromString(featureProperties.getProperty(GENERATION_SOURCE_PLUGIN_PREFIX + elementId), ","); //$NON-NLS-1$
144
				for (int j = 1; j < extraElementsToFetch.length; j++) {
145
					generateFetchEntry(extraElementsToFetch[j], false);
146
				}
147
				continue;
117
			}
148
			}
118
		} catch (IOException e) {
149
119
			//ignore the exception, the same may not exist
150
			boolean generated = true;
151
			if (allChildren[i].isFragment())
152
				generated = generateFetchEntry(FRAGMENT + '@' + elementId, !Utils.isIn(compiledChildren, allChildren[i]));
153
			else
154
				generated = generateFetchEntry(PLUGIN + '@' + elementId, !Utils.isIn(compiledChildren, allChildren[i]));
155
			if (generated == false)
156
				generateFetchEntry(BUNDLE + '@' + elementId, !Utils.isIn(compiledChildren, allChildren[i]));
120
		}
157
		}
158
	}
121
159
160
	/**
161
	 * Just ends the script.
162
	 */
163
	protected void generateEpilogue() {
164
		script.println();
165
		script.printProjectEnd();
166
	}
167
168
	protected void generateFetchElementTarget() {
169
		script.printTargetDeclaration(TARGET_FETCH_ELEMENT, null, FEATURE_ONLY, null, null);
122
		try {
170
		try {
123
			OutputStream os = new BufferedOutputStream(new FileOutputStream(workingDirectory + '/' + fileName));
171
			generateFetchEntry(element, false);
124
			try {
172
		} catch (CoreException e) {
125
				properties.store(os, null);
173
			IStatus status = new Status(IStatus.ERROR, PI_PDEBUILD, WARNING_ELEMENT_NOT_FETCHED, NLS.bind(Messages.error_fetchingFailed, element), null);
126
			} finally {
174
			BundleHelper.getDefault().getLog().log(status);
127
				os.close();
128
			}
129
		} catch (IOException e) {
130
			String message = NLS.bind(Messages.exception_writingFile, workingDirectory + '/' + fileName);
131
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, null));
132
		}
175
		}
176
		script.printTargetEnd();
133
	}
177
	}
134
	
178
135
	private void saveRepositoryTags() throws CoreException {
179
	protected boolean generateFetchEntry(String entry, boolean manifestFileOnly) throws CoreException {
136
		saveRepositoryTags(repositoryPluginTags, DEFAULT_PLUGIN_REPOTAG_FILENAME_DESCRIPTOR);
180
		Map mapFileEntry = mapInfos;
137
		saveRepositoryTags(repositoryFeatureTags, DEFAULT_FEATURE_REPOTAG_FILENAME_DESCRIPTOR);
181
		if (!entry.equals(element)) {
182
			mapFileEntry = processMapFileEntry(entry);
183
			if (mapFileEntry == null)
184
				return false;
185
		}
186
187
		FetchTaskFactory factory = (FetchTaskFactory) mapFileEntry.get(FETCH_TASK_FACTORY);
188
		String elementToFetch = (String) mapFileEntry.get(ELEMENT);
189
		String type = (String) mapFileEntry.get(TYPE);
190
191
		// print authentification task if one is provided
192
		CharSequence authTask = factory.generateAuthentificationTask(elementToFetch, type, mapFileEntry);
193
		if (null != authTask)
194
			script.print(authTask);
195
196
		// the location
197
		String location = getElementLocation(type);
198
199
		// the destination
200
		// we directly export the content into the correct directory 
201
		String destination = elementToFetch;
202
203
		// get params from builder
204
		Map params = new HashMap(factory.generatePropertiesForFetchTask(elementToFetch, type, mapFileEntry, destination, manifestFileOnly));
205
206
		String fullLocation = null;
207
		if (type.equals(FEATURE)) {
208
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR;
209
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
210
			repositoryFeatureTags.put(elementToFetch, factory.getTagToFetch(elementToFetch, type, mapFileEntry));
211
		} else if (type.equals(PLUGIN)) {
212
			fullLocation = location + '/' + elementToFetch + '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR;
213
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
214
			repositoryPluginTags.put(elementToFetch, factory.getTagToFetch(elementToFetch, type, mapFileEntry));
215
		} else if (type.equals(FRAGMENT)) {
216
			fullLocation = location + '/' + elementToFetch + '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR;
217
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
218
			repositoryPluginTags.put(elementToFetch, factory.getTagToFetch(elementToFetch, type, mapFileEntry));
219
		} else if (type.equals(BUNDLE)) {
220
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR;
221
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
222
			repositoryPluginTags.put(elementToFetch, factory.getTagToFetch(elementToFetch, type, mapFileEntry));
223
		}
224
225
		// This call create a new property for every feature, plugins or fragments that we must check the existence of 
226
		script.printAvailableTask(fullLocation, fullLocation);
227
		if (type.equals(PLUGIN) || type.equals(FRAGMENT)) {
228
			script.printAvailableTask(fullLocation, location + '/' + elementToFetch + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR);
229
		}
230
		script.printAntTask("../" + scriptName, Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + (type.equals(FEATURE) ? DEFAULT_FEATURE_LOCATION : DEFAULT_PLUGIN_LOCATION), TARGET_FETCH_FROM_REPOSITORY, null, null, params); //$NON-NLS-1$ 
231
		return true;
138
	}
232
	}
139
233
140
	/**
234
	/**
Lines 160-165 Link Here
160
		}
254
		}
161
	}
255
	}
162
256
257
	protected void generateFetchPluginsTarget() throws CoreException {
258
		script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null);
259
		retrieveFeature((String) mapInfos.get(ELEMENT), (String) mapInfos.get(TYPE), mapInfos);
260
		generateChildrenFetchScript();
261
		script.printTargetEnd();
262
	}
263
264
	protected void generateFetchRecusivelyTarget() throws CoreException {
265
		script.printTargetDeclaration(TARGET_FETCH_RECURSIVELY, null, FEATURES_RECURSIVELY, null, null);
266
267
		IIncludedFeatureReference[] compiledFeatures = ((Feature) feature).getFeatureIncluded();
268
		for (int i = 0; i < compiledFeatures.length; i++) {
269
			String featureId = compiledFeatures[i].getVersionedIdentifier().getIdentifier();
270
			if (featureProperties.containsKey(GENERATION_SOURCE_FEATURE_PREFIX + featureId)) {
271
				String[] extraElementsToFetch = Utils.getArrayFromString(featureProperties.getProperty(GENERATION_SOURCE_FEATURE_PREFIX + featureId), ","); //$NON-NLS-1$
272
				for (int j = 1; j < extraElementsToFetch.length; j++) {
273
					generateFetchEntry(extraElementsToFetch[j], false);
274
				}
275
				continue;
276
			}
277
278
			//Included features can be available in the baseLocation.
279
			if (getRepositoryInfo(FEATURE + '@' + featureId) != null)
280
				script.printAntTask(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + FETCH_FILE_PREFIX + featureId + ".xml", null, TARGET_FETCH, null, null, null); //$NON-NLS-1$
281
			else if (getSite(false).findFeature(featureId, null, false) == null) {
282
				String message = NLS.bind(Messages.error_cannotFetchNorFindFeature, featureId);
283
				throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null));
284
			}
285
		}
286
		script.printTargetEnd();
287
	}
288
163
	/**
289
	/**
164
	 * Main call for generating the script.
290
	 * Main call for generating the script.
165
	 * 
291
	 * 
Lines 169-179 Link Here
169
		generatePrologue();
295
		generatePrologue();
170
		generateFetchTarget();
296
		generateFetchTarget();
171
		generateFetchElementTarget();
297
		generateFetchElementTarget();
172
		if (mapInfos.get(TYPE).equals(FEATURE)) { 
298
		if (mapInfos.get(TYPE).equals(FEATURE)) {
173
			generateFetchPluginsTarget();
299
			generateFetchPluginsTarget();
174
			generateFetchRecusivelyTarget();
300
			generateFetchRecusivelyTarget();
175
		}
301
		}
176
		generateGetFromCVSTarget();
302
		generateGetFromRepositoryTarget();
177
		generateEpilogue();
303
		generateEpilogue();
178
	}
304
	}
179
305
Lines 184-212 Link Here
184
		script.println();
310
		script.println();
185
		script.printTargetDeclaration(TARGET_FETCH, null, null, null, null);
311
		script.printTargetDeclaration(TARGET_FETCH, null, null, null, null);
186
		script.printAntCallTask(TARGET_FETCH_ELEMENT, null, null);
312
		script.printAntCallTask(TARGET_FETCH_ELEMENT, null, null);
187
		if (mapInfos.get(TYPE).equals(FEATURE)) { 
313
		if (mapInfos.get(TYPE).equals(FEATURE)) {
188
			script.printAntCallTask(TARGET_FETCH_PLUGINS, null, null);
314
			script.printAntCallTask(TARGET_FETCH_PLUGINS, null, null);
189
			script.printAntCallTask(TARGET_FETCH_RECURSIVELY, null, null);
315
			script.printAntCallTask(TARGET_FETCH_RECURSIVELY, null, null);
190
		}
316
		}
191
		script.printTargetEnd();
317
		script.printTargetEnd();
192
	}
318
	}
193
319
194
	protected void generateFetchElementTarget() {
320
	protected void generateGetFromRepositoryTarget() throws CoreException {
195
		script.printTargetDeclaration(TARGET_FETCH_ELEMENT, null, FEATURE_ONLY, null, null);
321
		script.printTargetDeclaration(TARGET_FETCH_FROM_REPOSITORY, null, null, "${fileToCheck}", null); //$NON-NLS-1$
196
		try {
322
		if (null != mapInfos) {
197
			generateFetchEntry(element, false);
323
			FetchTaskFactory factory = (FetchTaskFactory) mapInfos.get(FETCH_TASK_FACTORY);
198
		} catch (CoreException e) {
324
			if (null != factory) {
199
			IStatus status = new Status(IStatus.ERROR, PI_PDEBUILD, WARNING_ELEMENT_NOT_FETCHED, NLS.bind(Messages.error_fetchingFailed, element), null);
325
				CharSequence getTask = factory.getFetchTask();
200
			BundleHelper.getDefault().getLog().log(status);
326
				if (null != getTask) {
327
					script.print(getTask);
328
				}
329
			}
201
		}
330
		}
202
		script.printTargetEnd();
331
		script.printTargetEnd();
203
	}
332
	}
204
333
205
	protected void generateFetchPluginsTarget() throws CoreException {
334
	/**
206
		script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null);
335
	 * Helper method to control for what locations a mkdir Ant task was already
207
		retrieveFeature((String) mapInfos.get(ELEMENT), (String) mapInfos.get(CVSROOT), (String) mapInfos.get(TAG), (String) mapInfos.get(PASSWORD), (String) mapInfos.get(PATH)); 
336
	 * generated so we can reduce replication.
208
		generateChildrenFetchScript();
337
	 * 
209
		script.printTargetEnd();
338
	 * @param location
339
	 */
340
	protected void generateMkdirs(String location) {
341
		if (mkdirLocations.contains(location))
342
			return;
343
		mkdirLocations.add(location);
344
		script.printMkdirTask(location);
345
	}
346
347
	/**
348
	 * Defines, the XML declaration and Ant project.
349
	 */
350
	protected void generatePrologue() {
351
		script.println();
352
		script.printComment("Fetch script for " + element); //$NON-NLS-1$
353
		script.println();
354
		script.printProjectDeclaration("FetchScript", TARGET_FETCH, null); //$NON-NLS-1$ 
355
		script.printProperty(PROPERTY_QUIET, "true"); //$NON-NLS-1$
356
	}
357
358
	/**
359
	 * 
360
	 * @param type
361
	 * @return String
362
	 */
363
	protected String getElementLocation(String type) {
364
		IPath location = new Path(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY));
365
		if (type.equals(FEATURE))
366
			location = location.append(DEFAULT_FEATURE_LOCATION);
367
		else
368
			location = location.append(DEFAULT_PLUGIN_LOCATION);
369
		return location.toString();
370
	}
371
372
	/**
373
	 * Get information stored in the directory file.
374
	 * 
375
	 * @param elementName
376
	 * @return String
377
	 * @throws CoreException
378
	 */
379
	protected String getRepositoryInfo(String elementName) throws CoreException {
380
		if (directory == null)
381
			directory = readProperties(directoryLocation, "", IStatus.ERROR); //$NON-NLS-1$
382
		return directory.getProperty(elementName);
210
	}
383
	}
211
384
212
	/**
385
	/**
Lines 219-376 Link Here
219
	private Map processMapFileEntry(String entry) throws CoreException {
392
	private Map processMapFileEntry(String entry) throws CoreException {
220
		Map entryInfos = new HashMap(5);
393
		Map entryInfos = new HashMap(5);
221
394
222
		String cvsInfo = getCVSInfo(entry);
395
		// extract type and element from entry
223
		if (cvsInfo == null) {
396
		int index = entry.indexOf('@');
397
		String type = entry.substring(0, index);
398
		String currentElement = entry.substring(index + 1);
399
400
		// read and validate the repository info
401
		String repositoryInfo = getRepositoryInfo(entry);
402
		if (repositoryInfo == null) {
224
			String message = NLS.bind(Messages.error_missingDirectoryEntry, entry);
403
			String message = NLS.bind(Messages.error_missingDirectoryEntry, entry);
225
			BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
404
			BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
226
			return null;
405
			return null;
227
		}
406
		}
228
407
229
		String[] cvsFields = Utils.getArrayFromStringWithBlank(cvsInfo, ","); //$NON-NLS-1$
408
		// collect and validate the repository info
230
		if (cvsFields.length < 2) {
409
		String[] repositoryFields = Utils.getArrayFromStringWithBlank(repositoryInfo, ","); //$NON-NLS-1$
231
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, element);
410
		if (repositoryFields.length < 2) {
411
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, currentElement);
232
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
412
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
233
		}
413
		}
234
414
235
		entryInfos.put(TAG, fetchTag.length() == 0 ? cvsFields[0] : fetchTag); 
415
		// determine fetch script builder
236
		entryInfos.put(CVSROOT, cvsFields[1]); 
416
		FetchTaskFactory fetchTaskFactory = null;
237
		entryInfos.put(PASSWORD, (cvsFields.length > 2 && !cvsFields[2].equals("")) ? cvsFields[2] : null); //$NON-NLS-1$ 
417
		String[] arguments = null;
238
239
		entryInfos.put(PATH, (cvsFields.length > 3 && !cvsFields[3].equals("")) ? cvsFields[3] : null); //$NON-NLS-1$ 
240
241
		int index = entry.indexOf('@'); 
242
		entryInfos.put(TYPE, entry.substring(0, index)); 
243
		entryInfos.put(ELEMENT, entry.substring(index + 1)); 
244
		return entryInfos;
245
	}
246
418
247
	protected void generateFetchRecusivelyTarget() throws CoreException {
419
		// check if first repository field matches a builder id
248
		script.printTargetDeclaration(TARGET_FETCH_RECURSIVELY, null, FEATURES_RECURSIVELY, null, null);
420
		if (FetchTaskFactoriesRegistry.getRegistry().getFactoryIds().contains(repositoryFields[0])) {
249
421
			fetchTaskFactory = FetchTaskFactoriesRegistry.getRegistry().getFactory(repositoryFields[0]);
250
		IIncludedFeatureReference[] compiledFeatures = ((Feature) feature).getFeatureIncluded();
251
		for (int i = 0; i < compiledFeatures.length; i++) {
252
			String featureId = compiledFeatures[i].getVersionedIdentifier().getIdentifier();
253
			if (featureProperties.containsKey(GENERATION_SOURCE_FEATURE_PREFIX + featureId)) {
254
				String[] extraElementsToFetch = Utils.getArrayFromString(featureProperties.getProperty(GENERATION_SOURCE_FEATURE_PREFIX + featureId), ","); //$NON-NLS-1$
255
				for (int j = 1; j < extraElementsToFetch.length; j++) {
256
					generateFetchEntry(extraElementsToFetch[j], false);
257
				}
258
				continue;
259
			}
260
			
261
			//Included features can be available in the baseLocation.
262
			if (getCVSInfo(FEATURE + '@' + featureId) != null)
263
				script.printAntTask(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + FETCH_FILE_PREFIX + featureId + ".xml", null, TARGET_FETCH, null, null, null); //$NON-NLS-1$
264
			else if (getSite(false).findFeature(featureId, null, false) == null) {
265
				String message = NLS.bind(Messages.error_cannotFetchNorFindFeature, featureId);
266
				throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null));
267
			}
268
		}
269
		script.printTargetEnd();
270
	}
271
422
272
	protected boolean generateFetchEntry(String entry, boolean manifestFileOnly) throws CoreException {
423
			// construct arguments array for registered builder
273
		Map mapFileEntry = mapInfos;
424
			arguments = new String[repositoryFields.length - 1];
274
		if (!entry.equals(element)) {
425
			System.arraycopy(repositoryFields, 1, arguments, 0, repositoryFields.length - 1);
275
			mapFileEntry = processMapFileEntry(entry);
276
			if (mapFileEntry == null)
277
				return false;
278
		}
426
		}
279
427
280
		String password = (String) mapFileEntry.get(PASSWORD);
428
		// default to CVS builder (to be compatible)
281
		if (password != null)
429
		if (null == fetchTaskFactory) {
282
			script.printCVSPassTask((String) mapFileEntry.get(CVSROOT), password, cvsPassFileLocation); 
430
			// fall back to CVS
283
431
			fetchTaskFactory = new CVSFetchTaskFactory();
284
		String type = (String) mapFileEntry.get(TYPE);
285
		String location = getElementLocation(type);
286
		Map params = new HashMap(5);
287
288
		//We directly export the CVS content into the correct directory 
289
		params.put("destination", mapFileEntry.get(ELEMENT)); //$NON-NLS-1$ 
290
		params.put(TAG, mapFileEntry.get(TAG)); 
291
		params.put(CVSROOT, mapFileEntry.get(CVSROOT)); 
292
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
293
294
		String cvsPackage = ((String) mapFileEntry.get(PATH) == null ? (String) mapFileEntry.get(ELEMENT) : (String) mapFileEntry.get(PATH)); 
295
		String fullLocation = null;
296
		if (type.equals(FEATURE)) {
297
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR; 
298
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
299
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
300
			repositoryFeatureTags.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
301
		} else if (type.equals(PLUGIN)) {
302
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR; 
303
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
304
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
305
			repositoryPluginTags.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
306
		} else if (type.equals(FRAGMENT)) {
307
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR; 
308
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
309
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
310
			repositoryPluginTags.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
311
		} else if (type.equals(BUNDLE)) {
312
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR;
313
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
314
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR : "";//$NON-NLS-1$ 
315
			repositoryPluginTags.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));   
316
		}
317
		params.put("package", cvsPackage); //$NON-NLS-1$
318
432
319
		// This call create a new property for every feature, plugins or fragments that we must check the existence of 
433
			// construct arguments array for CVS builder
320
		script.printAvailableTask(fullLocation, fullLocation);
434
			arguments = repositoryFields;
321
		if (type.equals(PLUGIN) || type.equals(FRAGMENT)) {
322
			script.printAvailableTask(fullLocation, location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR);
323
		}
435
		}
324
		script.printAntTask("../" + scriptName, Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + (type.equals(FEATURE) ? DEFAULT_FEATURE_LOCATION : DEFAULT_PLUGIN_LOCATION), TARGET_GET_FROM_CVS, null, null, params); //$NON-NLS-1$ 
325
		return true;
326
	}
327
328
	protected void generateGetFromCVSTarget() {
329
		script.printTargetDeclaration(TARGET_GET_FROM_CVS, null, null, "${fileToCheck}", "{destination}"); //$NON-NLS-1$ //$NON-NLS-2$
330
		script.printCVSTask("export -d ${destination} -r ${tag} ${package}", "${cvsRoot}", null, null, null, "${quiet}", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
331
		script.printTargetEnd();
332
	}
333
334
	/**
335
	 * Helper method to control for what locations a mkdir Ant task was already
336
	 * generated so we can reduce replication.
337
	 * 
338
	 * @param location
339
	 */
340
	protected void generateMkdirs(String location) {
341
		if (mkdirLocations.contains(location))
342
			return;
343
		mkdirLocations.add(location);
344
		script.printMkdirTask(location);
345
	}
346
436
347
	/**
437
		// add infos from registered builder
348
	 * 
438
		fetchTaskFactory.processMapFileEntry(currentElement, type, arguments, fetchTag, entryInfos);
349
	 * @throws CoreException
350
	 */
351
	protected void generateChildrenFetchScript() throws CoreException {
352
		IPluginEntry[] allChildren = feature.getRawPluginEntries();
353
		IPluginEntry[] compiledChildren = feature.getPluginEntries();
354
439
355
		for (int i = 0; i < allChildren.length; i++) {
440
		// store builder
356
			String elementId = allChildren[i].getVersionedIdentifier().getIdentifier();
441
		entryInfos.put(FETCH_TASK_FACTORY, fetchTaskFactory);
357
			// We are not fetching the elements that are said to be generated, but we are fetching some elements that can be associated
358
			if (featureProperties.containsKey(GENERATION_SOURCE_PLUGIN_PREFIX + elementId)) {
359
				String[] extraElementsToFetch = Utils.getArrayFromString(featureProperties.getProperty(GENERATION_SOURCE_PLUGIN_PREFIX + elementId), ","); //$NON-NLS-1$
360
				for (int j = 1; j < extraElementsToFetch.length; j++) {
361
					generateFetchEntry(extraElementsToFetch[j], false);
362
				}
363
				continue;
364
			}
365
442
366
			boolean generated = true;
443
		// add general infos (will override builder specific infos)
367
			if (allChildren[i].isFragment())
444
		entryInfos.put(TYPE, type);
368
				generated = generateFetchEntry(FRAGMENT + '@' + elementId, !Utils.isIn(compiledChildren, allChildren[i])); 
445
		entryInfos.put(ELEMENT, currentElement);
369
			else
446
		return entryInfos;
370
				generated = generateFetchEntry(PLUGIN + '@' + elementId, !Utils.isIn(compiledChildren, allChildren[i])); 
371
			if (generated == false)
372
				generateFetchEntry(BUNDLE + '@' + elementId, !Utils.isIn(compiledChildren, allChildren[i])); 
373
		}
374
	}
447
	}
375
448
376
	/**
449
	/**
Lines 379-415 Link Here
379
	 * constructor from Update.
452
	 * constructor from Update.
380
	 * 
453
	 * 
381
	 * @param elementName the feature to retrieve
454
	 * @param elementName the feature to retrieve
382
	 * @param cvsRoot the root in CVS
455
	 * @param elementType the element type
383
	 * @param tag the CVS tag
456
	 * @param elementInfos the element information
384
	 * @param password the CVS password
385
	 * @throws CoreException
457
	 * @throws CoreException
386
	 */
458
	 */
387
	protected void retrieveFeature(String elementName, String cvsRoot, String tag, String password, String path) throws CoreException {
459
	protected void retrieveFeature(String elementName, String elementType, Map elementInfos) throws CoreException {
388
		// Generate a temporary Ant script which retrieves the feature.xml for this
460
		// Generate a temporary Ant script which retrieves the feature.xml for this
389
		// feature from CVS
461
		// feature from CVS
390
		File root = new File(workingDirectory);
462
		File root = new File(workingDirectory);
391
		File target = new File(root, DEFAULT_RETRIEVE_FILENAME_DESCRIPTOR); 
463
		File target = new File(root, DEFAULT_RETRIEVE_FILENAME_DESCRIPTOR);
392
		try {
464
		try {
393
			AntScript retrieve = new AntScript(new FileOutputStream(target));
465
			AntScript retrieve = new AntScript(new FileOutputStream(target));
394
			try {
466
			try {
395
				retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
467
				retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
396
				retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null); 
468
				retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null);
397
469
398
				IPath moduleFeatureFile;
470
				String destination = elementName;
399
				IPath moduleFeatureProperties;
471
				String[] files = new String[] {DEFAULT_FEATURE_FILENAME_DESCRIPTOR, PROPERTIES_FILE};
400
				if (path != null) {
472
				FetchTaskFactory factory = (FetchTaskFactory) elementInfos.get(FETCH_TASK_FACTORY);
401
					moduleFeatureFile = new Path(path).append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
473
				CharSequence retrieveFeatureTask = factory.generateRetrieveFilesTask(elementName, elementType, elementInfos, destination, files);
402
					moduleFeatureProperties = new Path(path).append(PROPERTIES_FILE);
474
				if (null == retrieveFeatureTask) {
403
				} else {
475
					String message = NLS.bind(Messages.error_noRetrieveFeatureTask, elementName);
404
					moduleFeatureFile = new Path(elementName).append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
476
					throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
405
					moduleFeatureProperties = new Path(elementName).append(PROPERTIES_FILE);
406
				}
477
				}
407
478
				retrieve.print(retrieveFeatureTask);
408
				if (password != null)
409
					retrieve.printCVSPassTask(cvsRoot, password, cvsPassFileLocation);
410
411
				retrieve.printCVSTask("export -r " + tag + " " + moduleFeatureFile.toString(), cvsRoot, null, null, null, "true", null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
412
				retrieve.printCVSTask("export -r " + tag + " " + moduleFeatureProperties.toString(), cvsRoot, null, null, null, "true", null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
413
479
414
				retrieve.printTargetEnd();
480
				retrieve.printTargetEnd();
415
				retrieve.printProjectEnd();
481
				retrieve.printProjectEnd();
Lines 427-440 Link Here
427
			AntRunner runner = new AntRunner();
493
			AntRunner runner = new AntRunner();
428
			runner.setBuildFileLocation(target.getAbsolutePath());
494
			runner.setBuildFileLocation(target.getAbsolutePath());
429
			runner.run();
495
			runner.run();
496
			String destination = elementName;
430
			FeatureExecutableFactory factory = new FeatureExecutableFactory();
497
			FeatureExecutableFactory factory = new FeatureExecutableFactory();
431
			File featureFolder = new File(root, (path == null ? elementName : path));
498
			File featureFolder = new File(root, destination);
432
			feature = factory.createFeature(featureFolder.toURL(), null, null);
499
			feature = factory.createFeature(featureFolder.toURL(), null, null);
433
500
434
			//We only delete here, so if an exception is thrown the user can still see the retrieve.xml 
501
			//We only delete here, so if an exception is thrown the user can still see the retrieve.xml 
435
			target.delete();
502
			target.delete();
436
			featureProperties = new Properties();
503
			featureProperties = new Properties();
437
			InputStream featureStream = new FileInputStream(new File(root, (path == null ? elementName : path) + '/' + PROPERTIES_FILE));
504
			InputStream featureStream = new FileInputStream(new File(root, destination + '/' + PROPERTIES_FILE));
438
			featureProperties.load(featureStream);
505
			featureProperties.load(featureStream);
439
			featureStream.close();
506
			featureStream.close();
440
			clear(featureFolder);
507
			clear(featureFolder);
Lines 448-526 Link Here
448
		}
515
		}
449
	}
516
	}
450
517
451
	/**
518
	private void saveRepositoryTags() throws CoreException {
452
	 * Deletes all the files and directories from the given root down (inclusive).
519
		saveRepositoryTags(repositoryPluginTags, DEFAULT_PLUGIN_REPOTAG_FILENAME_DESCRIPTOR);
453
	 * Returns false if we could not delete some file or an exception occurred
520
		saveRepositoryTags(repositoryFeatureTags, DEFAULT_FEATURE_REPOTAG_FILENAME_DESCRIPTOR);
454
	 * at any point in the deletion.
521
	}
455
	 * Even if an exception occurs, a best effort is made to continue deleting.
522
456
	 * 
523
	private void saveRepositoryTags(Properties properties, String fileName) throws CoreException {
457
	 * @param root
458
	 * @return boolean
459
	 */
460
	public static boolean clear(File root) {
461
		boolean result = true;
462
		if (root.isDirectory()) {
463
			String[] list = root.list();
464
			// for some unknown reason, list() can return null.  
465
			// Just skip the children If it does.
466
			if (list != null)
467
				for (int i = 0; i < list.length; i++)
468
					result &= clear(new java.io.File(root, list[i]));
469
		}
470
		try {
524
		try {
471
			if (root.exists())
525
			InputStream input = new BufferedInputStream(new FileInputStream(workingDirectory + '/' + fileName));
472
				result &= root.delete();
526
			try {
473
		} catch (Exception e) {
527
				properties.load(input);
474
			// ignore any exceptions
528
			} finally {
475
			result = false;
529
				input.close();
530
			}
531
		} catch (IOException e) {
532
			//ignore the exception, the same may not exist
476
		}
533
		}
477
		return result;
478
	}
479
534
480
	/**
535
		try {
481
	 * 
536
			OutputStream os = new BufferedOutputStream(new FileOutputStream(workingDirectory + '/' + fileName));
482
	 * @param type
537
			try {
483
	 * @return String
538
				properties.store(os, null);
484
	 */
539
			} finally {
485
	protected String getElementLocation(String type) {
540
				os.close();
486
		IPath location = new Path(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY));
541
			}
487
		if (type.equals(FEATURE)) 
542
		} catch (IOException e) {
488
			location = location.append(DEFAULT_FEATURE_LOCATION);
543
			String message = NLS.bind(Messages.exception_writingFile, workingDirectory + '/' + fileName);
489
		else
544
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, null));
490
			location = location.append(DEFAULT_PLUGIN_LOCATION);
545
		}
491
		return location.toString();
492
	}
546
	}
493
547
494
	/**
548
	/**
495
	 * Get information stored in the directory file.
549
	 * Sets the CVS password file location to be the given value.
496
	 * 
550
	 * 
497
	 * @param elementName
551
	 * @param cvsPassFileLocation the CVS password file location
498
	 * @return String
499
	 * @throws CoreException
500
	 */
501
	protected String getCVSInfo(String elementName) throws CoreException {
502
		if (directory == null)
503
			directory = readProperties(directoryLocation, "", IStatus.ERROR); //$NON-NLS-1$
504
		return directory.getProperty(elementName);
505
	}
506
507
	/**
508
	 * Defines, the XML declaration and Ant project.
509
	 */
552
	 */
510
	protected void generatePrologue() {
553
	public void setCvsPassFileLocation(String cvsPassFileLocation) {
511
		script.println();
554
		this.cvsPassFileLocation = cvsPassFileLocation;
512
		script.printComment("Fetch script for " + element); //$NON-NLS-1$
513
		script.println();
514
		script.printProjectDeclaration("FetchScript", TARGET_FETCH, null); //$NON-NLS-1$ 
515
		script.printProperty(PROPERTY_QUIET, "true"); //$NON-NLS-1$
516
	}
555
	}
517
556
518
	/**
557
	public void setDirectory(Properties dir) {
519
	 * Just ends the script.
558
		directory = dir;
520
	 */
521
	protected void generateEpilogue() {
522
		script.println();
523
		script.printProjectEnd();
524
	}
559
	}
525
560
526
	/**
561
	/**
Lines 532-537 Link Here
532
		this.directoryLocation = directoryLocation;
567
		this.directoryLocation = directoryLocation;
533
	}
568
	}
534
569
570
	public void setElement(String element) {
571
		this.element = element;
572
	}
573
535
	/**
574
	/**
536
	 * Sets whether children of the current element should be fetched.
575
	 * Sets whether children of the current element should be fetched.
537
	 * 
576
	 * 
Lines 552-571 Link Here
552
		fetchTag = value;
591
		fetchTag = value;
553
	}
592
	}
554
593
555
	/**
556
	 * Sets the CVS password file location to be the given value.
557
	 * 
558
	 * @param cvsPassFileLocation the CVS password file location
559
	 */
560
	public void setCvsPassFileLocation(String cvsPassFileLocation) {
561
		this.cvsPassFileLocation = cvsPassFileLocation;
562
	}
563
564
	public void setRecursiveGeneration(boolean recursiveGeneration) {
594
	public void setRecursiveGeneration(boolean recursiveGeneration) {
565
		this.recursiveGeneration = recursiveGeneration;
595
		this.recursiveGeneration = recursiveGeneration;
566
	}
596
	}
567
568
	public void setDirectory(Properties dir) {
569
		directory = dir;
570
	}
571
}
597
}
(-)src/org/eclipse/pde/internal/build/Messages.java (-1 / +2 lines)
Lines 33-39 Link Here
33
	public static String error_configWrongFormat;
33
	public static String error_configWrongFormat;
34
	public static String error_missingCustomBuildFile;
34
	public static String error_missingCustomBuildFile;
35
	public static String error_missingSourceFolder;
35
	public static String error_missingSourceFolder;
36
	
36
	public static String error_noRetrieveFeatureTask;
37
37
	// exception
38
	// exception
38
	public static String exception_missingElement;
39
	public static String exception_missingElement;
39
	public static String exception_missingFeature;
40
	public static String exception_missingFeature;
(-)src/org/eclipse/pde/internal/build/messages.properties (-1 / +2 lines)
Lines 29-35 Link Here
29
error_configWrongFormat = {0} is not a valid configuration.
29
error_configWrongFormat = {0} is not a valid configuration.
30
error_missingCustomBuildFile = No custom build file found in {0}.
30
error_missingCustomBuildFile = No custom build file found in {0}.
31
error_missingSourceFolder = In plugin {0}, the value for property {1} is not set.
31
error_missingSourceFolder = In plugin {0}, the value for property {1} is not set.
32
32
error_noRetrieveFeatureTask = No fetch task available for element {0}, check your map files.
33
  
33
### exception
34
### exception
34
exception_missingElement = Unable to find element: {0}.
35
exception_missingElement = Unable to find element: {0}.
35
exception_missingFeature = Unable to find feature: {0}.
36
exception_missingFeature = Unable to find feature: {0}.
(-)src/org/eclipse/pde/internal/build/ant/AntScript.java (-379 / +424 lines)
Lines 12-17 Link Here
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.util.*;
14
import java.util.*;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.pde.internal.build.IPDEBuildConstants;
15
17
16
/**
18
/**
17
 * Class for producing Ant scripts. Contains convenience methods for creating the
19
 * Class for producing Ant scripts. Contains convenience methods for creating the
Lines 20-40 Link Here
20
 */
22
 */
21
public class AntScript {
23
public class AntScript {
22
24
25
	/**
26
	 * Converts the specified task to a String.
27
	 * @param task
28
	 * @return a String reprecentation of an ITask.
29
	 */
30
	public static String taskAsString(ITask task) throws CoreException {
31
		if (null == task)
32
			return null;
33
	
34
		ByteArrayOutputStream out = new ByteArrayOutputStream();
35
		try {
36
			AntScript script = new AntScript(out, false);
37
			task.print(script);
38
			script.close();
39
			return out.toString("UTF8"); //$NON-NLS-1$
40
		} catch (IOException e) {
41
			String message = e.getMessage();
42
			throw new CoreException(new Status(IStatus.ERROR, IPDEBuildConstants.PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_WRITING_SCRIPT, message, null));
43
		}
44
	}
45
	
23
	protected OutputStream out;
46
	protected OutputStream out;
24
	protected PrintWriter output;
47
	protected PrintWriter output;
25
	protected final String XML_PROLOG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
48
	protected final String XML_PROLOG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
49
26
	protected int indent = 0;
50
	protected int indent = 0;
27
51
28
	/**
52
	/**
29
	 * Constructor for the class.
53
	 * Creates a new Ant script including the XML prolog <code>&lt;?xml ... ?&gt;</code>.
30
	 * 
54
	 * 
31
	 * @param out the output stream to write the script to
55
	 * @param out the output stream to write the script to
32
	 * @throws IOException
56
	 * @throws IOException
33
	 */
57
	 */
34
	public AntScript(OutputStream out) throws IOException {
58
	public AntScript(OutputStream out) throws IOException {
59
		this(out, true);
60
	}
61
62
	/**
63
	 * Constructor for the class.
64
	 * 
65
	 * @param out the output stream to write the script to
66
	 * @param writeXMLProlog indicates if the XML prolog should be written
67
	 * @throws IOException
68
	 */
69
	public AntScript(OutputStream out, boolean writeXMLProlog) throws IOException {
35
		this.out = out;
70
		this.out = out;
36
		output = new PrintWriter(new OutputStreamWriter(out, "UTF8")); //$NON-NLS-1$
71
		output = new PrintWriter(new OutputStreamWriter(out, "UTF8")); //$NON-NLS-1$
37
		output.println(XML_PROLOG);
72
		if(writeXMLProlog)
73
			output.println(XML_PROLOG);
38
	}
74
	}
39
75
40
	/**
76
	/**
Lines 53-58 Link Here
53
	}
89
	}
54
90
55
	/**
91
	/**
92
	 * Print the given char sequence to the Ant script.
93
	 * 
94
	 * @param charSequence the char sequence to print
95
	 */
96
	public void print(CharSequence charSequence) {
97
		output.print(charSequence.toString());
98
	}
99
100
	/**
101
	 * Print the given task to the Ant script.
102
	 * 
103
	 * @param task the task to print
104
	 */
105
	public void print(ITask task) {
106
		task.print(this);
107
	}
108
109
	/**
110
	 * Print the given string to the Ant script.
111
	 * 
112
	 * @param message
113
	 */
114
	public void print(String message) {
115
		output.print(message);
116
	}
117
	
118
	/**
56
	 * Print an <code>antcall</code> task to the script. This calls Ant on the given 
119
	 * Print an <code>antcall</code> task to the script. This calls Ant on the given 
57
	 * target which is located within the same build file. 
120
	 * target which is located within the same build file. 
58
	 * 
121
	 * 
Lines 81-133 Link Here
81
			output.println("</antcall>"); //$NON-NLS-1$
144
			output.println("</antcall>"); //$NON-NLS-1$
82
		}
145
		}
83
	}
146
	}
84
85
	/**
86
	 * Print a <code>jar</code> Ant task to this script. This jars together a group of 
87
	 * files into a single file.
88
	 * 
89
	 * @param jarFile the destination file name
90
	 * @param basedir the base directory
91
	 */
92
	public void printJarTask(String jarFile, String basedir, String manifestAttribute) {
93
		printTab();
94
		output.print("<jar"); //$NON-NLS-1$
95
		printAttribute("destfile", jarFile, true); //$NON-NLS-1$
96
		printAttribute("basedir", basedir, false); //$NON-NLS-1$
97
		printAttribute("manifest", manifestAttribute, false); //$NON-NLS-1$
98
		output.println("/>"); //$NON-NLS-1$
99
	}
100
101
	/**
102
	 * Print the <code>available</code> Ant task to this script. This task sets a property
103
	 * value if the given file exists at runtime.
104
	 * 
105
	 * @param property the property to set
106
	 * @param file the file to look for
107
	 */
108
	public void printAvailableTask(String property, String file) {
109
		printTab();
110
		output.print("<available"); //$NON-NLS-1$
111
		printAttribute("property", property, true); //$NON-NLS-1$
112
		printAttribute("file", file, false); //$NON-NLS-1$
113
		output.println("/>"); //$NON-NLS-1$
114
	}
115
116
	/**
117
	 * Print the <code>available</code> Ant task to this script. This task sets a property
118
	 * to the given value if the given file exists at runtime.
119
	 * 
120
	 * @param property the property to set
121
	 * @param file the file to look for
122
	 */
123
	public void printAvailableTask(String property, String file, String value){
124
		printTab();
125
		output.print("<available"); //$NON-NLS-1$
126
		printAttribute("property", property, true); //$NON-NLS-1$
127
		printAttribute("file", file, false); //$NON-NLS-1$
128
		printAttribute("value", value, false); //$NON-NLS-1$
129
		output.println("/>"); //$NON-NLS-1$
130
	}
131
	
147
	
132
	/**
148
	/**
133
	 * Print an <code>ant</code> task to this script. This calls Ant on the specified 
149
	 * Print an <code>ant</code> task to this script. This calls Ant on the specified 
Lines 144-150 Link Here
144
	public void printAntTask(String antfile, String dir, String target, String outputParam, String inheritAll, Map properties ) {
160
	public void printAntTask(String antfile, String dir, String target, String outputParam, String inheritAll, Map properties ) {
145
		printAntTask(antfile, dir, target, outputParam, inheritAll, properties, null );
161
		printAntTask(antfile, dir, target, outputParam, inheritAll, properties, null );
146
	}
162
	}
147
	
163
148
	/**
164
	/**
149
	 * Print an <code>ant</code> task to this script. This calls Ant on the specified 
165
	 * Print an <code>ant</code> task to this script. This calls Ant on the specified 
150
	 * target contained in the specified Ant file with the given parameters.
166
	 * target contained in the specified Ant file with the given parameters.
Lines 196-290 Link Here
196
			output.println("</ant>"); //$NON-NLS-1$
212
			output.println("</ant>"); //$NON-NLS-1$
197
		}
213
		}
198
	}
214
	}
199
200
	public void printSubantTask(String antfile, String target, String buildpath, String failOnError, Map properties, Map references) {
201
		printTab();
202
		output.print("<subant"); //$NON-NLS-1$
203
		printAttribute("antfile", antfile, false); //$NON-NLS-1$
204
		printAttribute("target", target, false); //$NON-NLS-1$
205
		printAttribute("failonerror", failOnError, false);   //$NON-NLS-1$
206
		printAttribute("buildpath", buildpath, false);  //$NON-NLS-1$
207
		if (properties == null && references == null)
208
			output.println("/>"); //$NON-NLS-1$
209
		else {
210
			output.println(">"); //$NON-NLS-1$
211
			indent++;
212
			if( properties != null ) {
213
				Set entries = properties.entrySet();
214
				for (Iterator iter = entries.iterator(); iter.hasNext();) {
215
					Map.Entry entry = (Map.Entry) iter.next();
216
					printProperty((String) entry.getKey(), (String) entry.getValue());
217
				}
218
			}
219
			if( references != null ){
220
				Set entries = references.entrySet();
221
				for (Iterator iter = entries.iterator(); iter.hasNext();) {
222
					Map.Entry entry = (Map.Entry) iter.next();
223
					printTab();
224
					print("<reference refid=\"" + (String)entry.getKey() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
225
					if( entry.getValue() != null ){
226
						print(" torefid=\"" + (String) entry.getValue() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
227
					}
228
					print("/>"); //$NON-NLS-1$
229
					println();
230
				}
231
			}
232
			indent--;
233
			printTab();
234
			output.println("</subant>"); //$NON-NLS-1$
235
		}
236
	}
237
	/**
238
	 * Print a <code>zip</code> task to this script.
239
	 * 
240
	 * @param zipfile the destination file name
241
	 * @param basedir the source directory to start the zip
242
	 * @param filesOnly <code>true</code> if the resulting zip file should contain only files and not directories
243
	 * @param update ndicates whether to update or overwrite the destination file if it already exists
244
	 * @param fileSets the inclusion/exclusion rules to use when zipping
245
	 */
246
	public void printZipTask(String zipfile, String basedir, boolean filesOnly, boolean update, FileSet[] fileSets) {
247
		printTab();
248
		output.print("<zip"); //$NON-NLS-1$
249
		printAttribute("destfile", zipfile, true); //$NON-NLS-1$
250
		printAttribute("basedir", basedir, false); //$NON-NLS-1$
251
		printAttribute("filesonly", filesOnly ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
252
		printAttribute("whenempty", "skip", true); //$NON-NLS-1$//$NON-NLS-2$
253
		printAttribute("update", update ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
254
		if (fileSets == null)
255
			output.println("/>"); //$NON-NLS-1$
256
		else {
257
			output.println(">"); //$NON-NLS-1$
258
			indent++;
259
			for (int i = 0; i < fileSets.length; i++)
260
				if (fileSets[i] != null)
261
					fileSets[i].print(this);
262
			indent--;
263
			printTab();
264
			output.println("</zip>"); //$NON-NLS-1$
265
		}
266
	}
267
268
	public void printTarTask(String zipfile, String basedir, boolean filesOnly, boolean update, FileSet[] fileSets) {
269
		printTab();
270
		output.print("<tar"); //$NON-NLS-1$
271
		printAttribute("destfile", zipfile, true); //$NON-NLS-1$
272
		printAttribute("basedir", basedir, false); //$NON-NLS-1$
273
		printAttribute("compression", "gzip", true); //$NON-NLS-1$//$NON-NLS-2$
274
		if (fileSets == null)
275
			output.println("/>"); //$NON-NLS-1$
276
		else {
277
			output.println(">"); //$NON-NLS-1$
278
			indent++;
279
			for (int i = 0; i < fileSets.length; i++)
280
				if (fileSets[i] != null)
281
					fileSets[i].print(this);
282
			indent--;
283
			printTab();
284
			output.println("</tar>"); //$NON-NLS-1$
285
		}
286
	}
287
288
	/**
215
	/**
289
	 * Print an <code>arg</code> element to the Ant file.
216
	 * Print an <code>arg</code> element to the Ant file.
290
	 * 
217
	 * 
Lines 298-325 Link Here
298
	}
225
	}
299
226
300
	/**
227
	/**
301
	 * Print the given string to the Ant script.
302
	 * 
303
	 * @param string the string to write to the file
304
	 */
305
	public void printString(String string) {
306
		printTab();
307
		output.println(string);
308
	}
309
310
	/**
311
	 * Print the given comment to the Ant script.
312
	 * 
313
	 * @param comment the comment to write out
314
	 */
315
	public void printComment(String comment) {
316
		printTab();
317
		output.print("<!-- "); //$NON-NLS-1$
318
		output.print(comment);
319
		output.println(" -->"); //$NON-NLS-1$
320
	}
321
322
	/**
323
	 * Add the given name/value attribute pair to the script. Do not write the attribute
228
	 * Add the given name/value attribute pair to the script. Do not write the attribute
324
	 * if the value is <code>null</code> unless a <code>true</code> is specified
229
	 * if the value is <code>null</code> unless a <code>true</code> is specified
325
	 * indicating that it is mandatory.
230
	 * indicating that it is mandatory.
Lines 341-386 Link Here
341
	}
246
	}
342
247
343
	/**
248
	/**
344
	 * Print a <code>copy</code> task to the script. The source file is specified 
249
	 * Print the <code>available</code> Ant task to this script. This task sets a property
345
	 * by the <code>file</code> parameter. The destination directory is specified by 
250
	 * value if the given file exists at runtime.
346
	 * the <code>todir</code> parameter. 
251
	 * 
347
	 * @param file the source file
252
	 * @param property the property to set
348
	 * @param todir the destination directory
253
	 * @param file the file to look for
349
	 * @param fileSets the inclusion/exclusion rules to use when copying
350
	 * @param overwrite TODO
351
	 */
254
	 */
352
	public void printCopyTask(String file, String todir, FileSet[] fileSets, boolean failOnError, boolean overwrite) {
255
	public void printAvailableTask(String property, String file) {
353
		printTab();
256
		printTab();
354
		output.print("<copy"); //$NON-NLS-1$
257
		output.print("<available"); //$NON-NLS-1$
258
		printAttribute("property", property, true); //$NON-NLS-1$
355
		printAttribute("file", file, false); //$NON-NLS-1$
259
		printAttribute("file", file, false); //$NON-NLS-1$
356
		printAttribute("todir", todir, false); //$NON-NLS-1$
260
		output.println("/>"); //$NON-NLS-1$
357
		printAttribute("failonerror", failOnError ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
358
		printAttribute("overwrite", overwrite ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
359
		if (fileSets == null)
360
			output.println("/>"); //$NON-NLS-1$
361
		else {
362
			output.println(">"); //$NON-NLS-1$
363
			indent++;
364
			for (int i = 0; i < fileSets.length; i++)
365
				fileSets[i].print(this);
366
			indent--;
367
			printTab();
368
			output.println("</copy>"); //$NON-NLS-1$
369
		}
370
	}
261
	}
371
262
372
	public void printMoveTask(String todir, FileSet[] fileSets, boolean failOnError) {
263
	/**
373
		printTab();
264
	 * Print the <code>available</code> Ant task to this script. This task sets a property
374
		output.print("<move"); //$NON-NLS-1$
265
	 * to the given value if the given file exists at runtime.
375
		printAttribute("todir", todir, false); //$NON-NLS-1$
266
	 * 
376
		printAttribute("failonerror", failOnError ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
267
	 * @param property the property to set
377
		output.println(">"); //$NON-NLS-1$
268
	 * @param file the file to look for
378
		indent++;
269
	 */
379
		for (int i = 0; i < fileSets.length; i++)
270
	public void printAvailableTask(String property, String file, String value){
380
			fileSets[i].print(this);
381
		indent--;
382
		printTab();
271
		printTab();
383
		output.println("</move>"); //$NON-NLS-1$
272
		output.print("<available"); //$NON-NLS-1$
273
		printAttribute("property", property, true); //$NON-NLS-1$
274
		printAttribute("file", file, false); //$NON-NLS-1$
275
		printAttribute("value", value, false); //$NON-NLS-1$
276
		output.println("/>"); //$NON-NLS-1$
277
	}
278
279
	/**
280
	 * Print a <code>brand</code> task to the Ant script.
281
	 * 
282
	 * @param root the location of the launcher to brand.
283
	 * @param icons the list of icons to use in the branding
284
	 * @param name the name of the resultant launcher
285
	 */
286
	public void printBrandTask(String root, String icons, String name, String os) {
287
		printTab();
288
		print("<eclipse.brand"); //$NON-NLS-1$
289
		printAttribute("root", root, true); //$NON-NLS-1$
290
		if (icons != null)
291
			printAttribute("icons", icons, true); //$NON-NLS-1$
292
		printAttribute("name", name, true); //$NON-NLS-1$
293
		printAttribute("os", os, true); //$NON-NLS-1$
294
		println("/>"); //$NON-NLS-1$
295
	}
296
297
	public void printChmod(String dir, String rights, String files) {
298
		printTab();
299
		output.print("<chmod perm=\"" + rights + "\" "); //$NON-NLS-1$//$NON-NLS-2$
300
		output.print("dir=\"" + dir + "\" "); //$NON-NLS-1$//$NON-NLS-2$
301
		output.print("includes=\"" + files + "\" /> "); //$NON-NLS-1$ //$NON-NLS-2$
302
		output.println();
303
	}
304
305
	/**
306
	 * Print the given comment to the Ant script.
307
	 * 
308
	 * @param comment the comment to write out
309
	 */
310
	public void printComment(String comment) {
311
		printTab();
312
		output.print("<!-- "); //$NON-NLS-1$
313
		output.print(comment);
314
		output.println(" -->"); //$NON-NLS-1$
315
	}
316
317
	/**
318
	 * Print a <code>Condition</code> task with isset test to the script
319
	 * @param property		name of the property to set	
320
	 * @param value			value to set the property to
321
	 * @param testProperty	name of the property for the isset test
322
	 */
323
	public void printConditionIsSet(String property, String value, String testProperty) {
324
		println("<condition property=\"" + property + "\" value=\"" + value + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
325
		indent++;
326
		println("<isset property=\"" + testProperty + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
327
		indent--;
328
		printEndTag("condition"); //$NON-NLS-1$
329
	}
330
331
	/**
332
	 * Print a <code> eclipse.convertTask</code> task to the script. This task convert a file path to 
333
	 * an Eclipse resource or vice-versa. 
334
	 *
335
	 * @param toConvert the entry to convert 
336
	 * @param propertyName the property where to store the result of the convertion
337
	 * @param isEclipseResource true if toConvert refers to an eclipse resource. 
338
	 */
339
	public void printConvertPathTask(String toConvert, String propertyName, boolean isEclipseResource) {
340
		printTab();
341
		output.print("<eclipse.convertPath"); //$NON-NLS-1$
342
		if (isEclipseResource == false)
343
			printAttribute("fileSystemPath", toConvert, true); //$NON-NLS-1$
344
		else
345
			printAttribute("resourcePath", toConvert, true); //$NON-NLS-1$
346
		printAttribute("property", propertyName, true); //$NON-NLS-1$
347
		output.println("/>"); //$NON-NLS-1$
384
	}
348
	}
385
349
386
	/**
350
	/**
Lines 400-405 Link Here
400
	}
364
	}
401
365
402
	/**
366
	/**
367
	 * Print a <code>copy</code> task to the script. The source file is specified 
368
	 * by the <code>file</code> parameter. The destination directory is specified by 
369
	 * the <code>todir</code> parameter. 
370
	 * @param file the source file
371
	 * @param todir the destination directory
372
	 * @param fileSets the inclusion/exclusion rules to use when copying
373
	 * @param overwrite TODO
374
	 */
375
	public void printCopyTask(String file, String todir, FileSet[] fileSets, boolean failOnError, boolean overwrite) {
376
		printTab();
377
		output.print("<copy"); //$NON-NLS-1$
378
		printAttribute("file", file, false); //$NON-NLS-1$
379
		printAttribute("todir", todir, false); //$NON-NLS-1$
380
		printAttribute("failonerror", failOnError ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
381
		printAttribute("overwrite", overwrite ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
382
		if (fileSets == null)
383
			output.println("/>"); //$NON-NLS-1$
384
		else {
385
			output.println(">"); //$NON-NLS-1$
386
			indent++;
387
			for (int i = 0; i < fileSets.length; i++)
388
				fileSets[i].print(this);
389
			indent--;
390
			printTab();
391
			output.println("</copy>"); //$NON-NLS-1$
392
		}
393
	}
394
395
	/**
396
	 * Print a <code>cvspass</code> task to the Ant script.
397
	 * 
398
	 * @param cvsRoot the name of the repository
399
	 * @param password the password
400
	 * @param passFile the name of the password file
401
	 */
402
	public void printCVSPassTask(String cvsRoot, String password, String passFile) {
403
		printTab();
404
		output.print("<cvspass"); //$NON-NLS-1$
405
		printAttribute("cvsRoot", cvsRoot, true); //$NON-NLS-1$
406
		printAttribute("password", password, true); //$NON-NLS-1$
407
		printAttribute("passfile", passFile, false); //$NON-NLS-1$
408
		output.println("/>"); //$NON-NLS-1$
409
	}
410
411
	/**
412
	 * Print a <code>cvs</code> task to the Ant script.
413
	 * 
414
	 * @param command the CVS command to run
415
	 * @param cvsRoot value for the CVSROOT variable
416
	 * @param dest the destination directory for the checked out resources
417
	 * @param module the module name to check out
418
	 * @param tag the tag of the module to check out
419
	 * @param quiet whether or not to print informational messages to the output
420
	 * @param passFile the name of the password file
421
	 */
422
	public void printCVSTask(String command, String cvsRoot, String dest, String module, String tag, String quiet, String passFile) {
423
		printTab();
424
		output.print("<cvs"); //$NON-NLS-1$
425
		printAttribute("command", command, false); //$NON-NLS-1$
426
		printAttribute("cvsRoot", cvsRoot, false); //$NON-NLS-1$
427
		printAttribute("dest", dest, false); //$NON-NLS-1$
428
		printAttribute("package", module, false); //$NON-NLS-1$
429
		printAttribute("tag", tag, false); //$NON-NLS-1$
430
		printAttribute("quiet", quiet, false); //$NON-NLS-1$
431
		printAttribute("passfile", passFile, false); //$NON-NLS-1$
432
		output.println("/>"); //$NON-NLS-1$
433
	}
434
435
	/**
403
	 * Print a <code>delete</code> task to the Ant script. At least one of <code>dir</code>
436
	 * Print a <code>delete</code> task to the Ant script. At least one of <code>dir</code>
404
	 * or <code>file</code> is required unless some <code>fileSets</code> are
437
	 * or <code>file</code> is required unless some <code>fileSets</code> are
405
	 * present.
438
	 * present.
Lines 427-432 Link Here
427
	}
460
	}
428
461
429
	/**
462
	/**
463
	 * Print a <code> dirname </code> task to the script.
464
	 * @param property
465
	 * @param file
466
	 */
467
	public void printDirName(String property, String file) {
468
		printTab();
469
		output.print("<dirname"); //$NON-NLS-1$
470
		printAttribute("property", property, true); //$NON-NLS-1$
471
		printAttribute("file", file, true); //$NON-NLS-1$
472
		output.println("/>"); //$NON-NLS-1$
473
	}
474
475
	/**
476
	 * Print an <code>echo</code> task to the Ant script.
477
	 * 
478
	 * @param message the message to echo to the output
479
	 */
480
	public void printEchoTask(String message) {
481
		printTab();
482
		output.print("<echo"); //$NON-NLS-1$
483
		printAttribute("message", message, true); //$NON-NLS-1$
484
		output.println("/>"); //$NON-NLS-1$
485
	}
486
487
	/**
488
	 * Print an end tag in the Ant script for the given element name.
489
	 * 
490
	 * @param tag the name of the element
491
	 */
492
	public void printEndTag(String tag) {
493
		printTab();
494
		output.print("</"); //$NON-NLS-1$
495
		output.print(tag);
496
		output.println(">"); //$NON-NLS-1$
497
	}
498
	
499
	/**
430
	 * Print an <code>exec</code> task to the Ant script.
500
	 * Print an <code>exec</code> task to the Ant script.
431
	 * 
501
	 * 
432
	 * @param executable the program to execute
502
	 * @param executable the program to execute
Lines 452-536 Link Here
452
		}
522
		}
453
	}
523
	}
454
524
525
	public void printGet(String source, String destination, String login, String password, boolean usetimestamp) {
526
		printTab();
527
		output.print("<get "); //$NON-NLS-1$
528
		printAttribute("username", login, false); //$NON-NLS-1$
529
		printAttribute("password", password, false); //$NON-NLS-1$
530
		printAttribute("src", source, true); //$NON-NLS-1$
531
		printAttribute("dest", destination, true); //$NON-NLS-1$
532
		printAttribute("usetimestamp", usetimestamp ? "true" : null, false); //$NON-NLS-1$ //$NON-NLS-2$
533
		output.println("/>"); //$NON-NLS-1$
534
	}
535
536
	public void printGZip(String source, String destination) {
537
		printTab();
538
		output.println("<gzip src=\"" + source + "\" zipfile=\"" + destination + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
539
	}
540
455
	/**
541
	/**
456
	 * Print a <code>mkdir</code> task to the Ant script.
542
	 * Print a <code>jar</code> Ant task to this script. This jars together a group of 
543
	 * files into a single file.
457
	 * 
544
	 * 
458
	 * @param dir the name of the directory to create.
545
	 * @param jarFile the destination file name
546
	 * @param basedir the base directory
459
	 */
547
	 */
460
	public void printMkdirTask(String dir) {
548
	public void printJarTask(String jarFile, String basedir, String manifestAttribute) {
461
		printTab();
549
		printTab();
462
		output.print("<mkdir"); //$NON-NLS-1$
550
		output.print("<jar"); //$NON-NLS-1$
463
		printAttribute("dir", dir, false); //$NON-NLS-1$
551
		printAttribute("destfile", jarFile, true); //$NON-NLS-1$
552
		printAttribute("basedir", basedir, false); //$NON-NLS-1$
553
		printAttribute("manifest", manifestAttribute, false); //$NON-NLS-1$
464
		output.println("/>"); //$NON-NLS-1$
554
		output.println("/>"); //$NON-NLS-1$
465
	}
555
	}
466
556
467
	/**
557
	/**
468
	 * Print a <code>brand</code> task to the Ant script.
558
	 * Print a carriage-return to the Ant script.
469
	 * 
470
	 * @param root the location of the launcher to brand.
471
	 * @param icons the list of icons to use in the branding
472
	 * @param name the name of the resultant launcher
473
	 */
559
	 */
474
	public void printBrandTask(String root, String icons, String name, String os) {
560
	public void println() {
475
		printTab();
561
		output.println();
476
		print("<eclipse.brand"); //$NON-NLS-1$
477
		printAttribute("root", root, true); //$NON-NLS-1$
478
		if (icons != null)
479
			printAttribute("icons", icons, true); //$NON-NLS-1$
480
		printAttribute("name", name, true); //$NON-NLS-1$
481
		printAttribute("os", os, true); //$NON-NLS-1$
482
		println("/>"); //$NON-NLS-1$
483
	}
562
	}
484
563
485
	/**
564
	/**
486
	 * Print an <code>echo</code> task to the Ant script.
565
	 * Print the given string to the Ant script followed by a carriage-return.
487
	 * 
566
	 * 
488
	 * @param message the message to echo to the output
567
	 * @param message the string to print
489
	 */
568
	 */
490
	public void printEchoTask(String message) {
569
	public void println(String message) {
491
		printTab();
570
		printTab();
492
		output.print("<echo"); //$NON-NLS-1$
571
		output.println(message);
493
		printAttribute("message", message, true); //$NON-NLS-1$
494
		output.println("/>"); //$NON-NLS-1$
495
	}
572
	}
496
573
497
	/**
574
	/**
498
	 * Print a <code>cvs</code> task to the Ant script.
575
	 * Print a <code>mkdir</code> task to the Ant script.
499
	 * 
576
	 * 
500
	 * @param command the CVS command to run
577
	 * @param dir the name of the directory to create.
501
	 * @param cvsRoot value for the CVSROOT variable
502
	 * @param dest the destination directory for the checked out resources
503
	 * @param module the module name to check out
504
	 * @param tag the tag of the module to check out
505
	 * @param quiet whether or not to print informational messages to the output
506
	 * @param passFile the name of the password file
507
	 */
578
	 */
508
	public void printCVSTask(String command, String cvsRoot, String dest, String module, String tag, String quiet, String passFile) {
579
	public void printMkdirTask(String dir) {
509
		printTab();
580
		printTab();
510
		output.print("<cvs"); //$NON-NLS-1$
581
		output.print("<mkdir"); //$NON-NLS-1$
511
		printAttribute("command", command, false); //$NON-NLS-1$
582
		printAttribute("dir", dir, false); //$NON-NLS-1$
512
		printAttribute("cvsRoot", cvsRoot, false); //$NON-NLS-1$
513
		printAttribute("dest", dest, false); //$NON-NLS-1$
514
		printAttribute("package", module, false); //$NON-NLS-1$
515
		printAttribute("tag", tag, false); //$NON-NLS-1$
516
		printAttribute("quiet", quiet, false); //$NON-NLS-1$
517
		printAttribute("passfile", passFile, false); //$NON-NLS-1$
518
		output.println("/>"); //$NON-NLS-1$
583
		output.println("/>"); //$NON-NLS-1$
519
	}
584
	}
520
585
586
	public void printMoveTask(String todir, FileSet[] fileSets, boolean failOnError) {
587
		printTab();
588
		output.print("<move"); //$NON-NLS-1$
589
		printAttribute("todir", todir, false); //$NON-NLS-1$
590
		printAttribute("failonerror", failOnError ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
591
		output.println(">"); //$NON-NLS-1$
592
		indent++;
593
		for (int i = 0; i < fileSets.length; i++)
594
			fileSets[i].print(this);
595
		indent--;
596
		printTab();
597
		output.println("</move>"); //$NON-NLS-1$
598
	}
599
521
	/**
600
	/**
522
	 * Print a <code>cvspass</code> task to the Ant script.
601
	 * Print a <code>param</code> tag to the Ant script.
523
	 * 
602
	 * 
524
	 * @param cvsRoot the name of the repository
603
	 * @param name the parameter name
525
	 * @param password the password
604
	 * @param value the parameter value
526
	 * @param passFile the name of the password file
527
	 */
605
	 */
528
	public void printCVSPassTask(String cvsRoot, String password, String passFile) {
606
	protected void printParam(String name, String value) {
529
		printTab();
607
		printTab();
530
		output.print("<cvspass"); //$NON-NLS-1$
608
		output.print("<param"); //$NON-NLS-1$
531
		printAttribute("cvsRoot", cvsRoot, true); //$NON-NLS-1$
609
		printAttribute("name", name, true); //$NON-NLS-1$
532
		printAttribute("password", password, true); //$NON-NLS-1$
610
		printAttribute("value", value, true); //$NON-NLS-1$
533
		printAttribute("passfile", passFile, false); //$NON-NLS-1$
534
		output.println("/>"); //$NON-NLS-1$
611
		output.println("/>"); //$NON-NLS-1$
535
	}
612
	}
536
613
Lines 564-583 Link Here
564
		}
641
		}
565
		printEndTag(tag);
642
		printEndTag(tag);
566
	}
643
	}
567
	
568
	/**
569
	 * Print a <code>param</code> tag to the Ant script.
570
	 * 
571
	 * @param name the parameter name
572
	 * @param value the parameter value
573
	 */
574
	protected void printParam(String name, String value) {
575
		printTab();
576
		output.print("<param"); //$NON-NLS-1$
577
		printAttribute("name", name, true); //$NON-NLS-1$
578
		printAttribute("value", value, true); //$NON-NLS-1$
579
		output.println("/>"); //$NON-NLS-1$
580
	}
581
644
582
	/**
645
	/**
583
	 * Print a <code>project</code> tag to the Ant script.
646
	 * Print a <code>project</code> tag to the Ant script.
Lines 637-706 Link Here
637
	}
700
	}
638
701
639
	/**
702
	/**
640
	 * Print a start tag in the Ant script for the given element name.
703
	 * Print a <code>eclipse.refreshLocal</code> task to the script. This task refreshes
704
	 * the specified resource in the workspace, to the specified depth. 
641
	 * 
705
	 * 
642
	 * @param tag the name of the element
706
	 * @param resource the resource to refresh
707
	 * @param depth one of <code>IResource.DEPTH_ZERO</code>,
708
	 *   <code>IResource.DEPTH_ONE</code>, or <code>IResource.DEPTH_INFINITY</code>
643
	 */
709
	 */
644
	public void printStartTag(String tag) {
710
	public void printRefreshLocalTask(String resource, String depth) {
645
		printTab();
711
		printTab();
646
		output.print("<"); //$NON-NLS-1$
712
		output.print("<eclipse.refreshLocal"); //$NON-NLS-1$
647
		output.print(tag);
713
		printAttribute("resource", resource, true); //$NON-NLS-1$
648
		output.println(">"); //$NON-NLS-1$
714
		printAttribute("depth", depth, false); //$NON-NLS-1$
715
		output.println("/>"); //$NON-NLS-1$
649
	}
716
	}
650
717
651
	/**
718
	/**
652
	 * Print an end tag in the Ant script for the given element name.
719
	 * Print a start tag in the Ant script for the given element name.
653
	 * 
720
	 * 
654
	 * @param tag the name of the element
721
	 * @param tag the name of the element
655
	 */
722
	 */
656
	public void printEndTag(String tag) {
723
	public void printStartTag(String tag) {
657
		printTab();
724
		printTab();
658
		output.print("</"); //$NON-NLS-1$
725
		output.print("<"); //$NON-NLS-1$
659
		output.print(tag);
726
		output.print(tag);
660
		output.println(">"); //$NON-NLS-1$
727
		output.println(">"); //$NON-NLS-1$
661
	}
728
	}
662
729
663
	/**
730
	/**
664
	 * Print the given number of tabs to the Ant script.
665
	 */
666
	protected void printTab() {
667
		for (int i = 0; i < indent; i++)
668
			output.print("\t"); //$NON-NLS-1$
669
	}
670
671
	/**
672
	 * Print the given string to the Ant script followed by a carriage-return.
673
	 * 
674
	 * @param message the string to print
675
	 */
676
	public void println(String message) {
677
		printTab();
678
		output.println(message);
679
	}
680
681
	/**
682
	 * Print the given string to the Ant script.
731
	 * Print the given string to the Ant script.
683
	 * 
732
	 * 
684
	 * @param message
733
	 * @param string the string to write to the file
685
	 */
734
	 */
686
	public void print(String message) {
735
	public void printString(String string) {
687
		output.print(message);
736
		printTab();
737
		output.println(string);
688
	}
738
	}
689
739
690
	/**
740
	public void printSubantTask(String antfile, String target, String buildpath, String failOnError, Map properties, Map references) {
691
	 * Print a carriage-return to the Ant script.
741
		printTab();
692
	 */
742
		output.print("<subant"); //$NON-NLS-1$
693
	public void println() {
743
		printAttribute("antfile", antfile, false); //$NON-NLS-1$
694
		output.println();
744
		printAttribute("target", target, false); //$NON-NLS-1$
745
		printAttribute("failonerror", failOnError, false);   //$NON-NLS-1$
746
		printAttribute("buildpath", buildpath, false);  //$NON-NLS-1$
747
		if (properties == null && references == null)
748
			output.println("/>"); //$NON-NLS-1$
749
		else {
750
			output.println(">"); //$NON-NLS-1$
751
			indent++;
752
			if( properties != null ) {
753
				Set entries = properties.entrySet();
754
				for (Iterator iter = entries.iterator(); iter.hasNext();) {
755
					Map.Entry entry = (Map.Entry) iter.next();
756
					printProperty((String) entry.getKey(), (String) entry.getValue());
757
				}
758
			}
759
			if( references != null ){
760
				Set entries = references.entrySet();
761
				for (Iterator iter = entries.iterator(); iter.hasNext();) {
762
					Map.Entry entry = (Map.Entry) iter.next();
763
					printTab();
764
					print("<reference refid=\"" + (String)entry.getKey() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
765
					if( entry.getValue() != null ){
766
						print(" torefid=\"" + (String) entry.getValue() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
767
					}
768
					print("/>"); //$NON-NLS-1$
769
					println();
770
				}
771
			}
772
			indent--;
773
			printTab();
774
			output.println("</subant>"); //$NON-NLS-1$
775
		}
695
	}
776
	}
696
777
697
	/**
778
	/**
698
	 * Print the given task to the Ant script.
779
	 * Print the given number of tabs to the Ant script.
699
	 * 
700
	 * @param task the task to print
701
	 */
780
	 */
702
	public void print(ITask task) {
781
	protected void printTab() {
703
		task.print(this);
782
		for (int i = 0; i < indent; i++)
783
			output.print("\t"); //$NON-NLS-1$
704
	}
784
	}
705
785
706
	/**
786
	/**
Lines 732-821 Link Here
732
		indent--;
812
		indent--;
733
		printEndTag("target"); //$NON-NLS-1$
813
		printEndTag("target"); //$NON-NLS-1$
734
	}
814
	}
735
815
	
736
	/**
816
	public void printTarTask(String zipfile, String basedir, boolean filesOnly, boolean update, FileSet[] fileSets) {
737
	 * Print a <code>eclipse.refreshLocal</code> task to the script. This task refreshes
738
	 * the specified resource in the workspace, to the specified depth. 
739
	 * 
740
	 * @param resource the resource to refresh
741
	 * @param depth one of <code>IResource.DEPTH_ZERO</code>,
742
	 *   <code>IResource.DEPTH_ONE</code>, or <code>IResource.DEPTH_INFINITY</code>
743
	 */
744
	public void printRefreshLocalTask(String resource, String depth) {
745
		printTab();
746
		output.print("<eclipse.refreshLocal"); //$NON-NLS-1$
747
		printAttribute("resource", resource, true); //$NON-NLS-1$
748
		printAttribute("depth", depth, false); //$NON-NLS-1$
749
		output.println("/>"); //$NON-NLS-1$
750
	}
751
752
	public void printChmod(String dir, String rights, String files) {
753
		printTab();
754
		output.print("<chmod perm=\"" + rights + "\" "); //$NON-NLS-1$//$NON-NLS-2$
755
		output.print("dir=\"" + dir + "\" "); //$NON-NLS-1$//$NON-NLS-2$
756
		output.print("includes=\"" + files + "\" /> "); //$NON-NLS-1$ //$NON-NLS-2$
757
		output.println();
758
	}
759
760
	public void printGet(String source, String destination, String login, String password, boolean usetimestamp) {
761
		printTab();
762
		output.print("<get "); //$NON-NLS-1$
763
		printAttribute("username", login, false); //$NON-NLS-1$
764
		printAttribute("password", password, false); //$NON-NLS-1$
765
		printAttribute("src", source, true); //$NON-NLS-1$
766
		printAttribute("dest", destination, true); //$NON-NLS-1$
767
		printAttribute("usetimestamp", usetimestamp ? "true" : null, false); //$NON-NLS-1$ //$NON-NLS-2$
768
		output.println("/>"); //$NON-NLS-1$
769
	}
770
771
	public void printGZip(String source, String destination) {
772
		printTab();
773
		output.println("<gzip src=\"" + source + "\" zipfile=\"" + destination + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
774
	}
775
776
	/**
777
	 * Print a <code> eclipse.convertTask</code> task to the script. This task convert a file path to 
778
	 * an Eclipse resource or vice-versa. 
779
	 *
780
	 * @param toConvert the entry to convert 
781
	 * @param propertyName the property where to store the result of the convertion
782
	 * @param isEclipseResource true if toConvert refers to an eclipse resource. 
783
	 */
784
	public void printConvertPathTask(String toConvert, String propertyName, boolean isEclipseResource) {
785
		printTab();
817
		printTab();
786
		output.print("<eclipse.convertPath"); //$NON-NLS-1$
818
		output.print("<tar"); //$NON-NLS-1$
787
		if (isEclipseResource == false)
819
		printAttribute("destfile", zipfile, true); //$NON-NLS-1$
788
			printAttribute("fileSystemPath", toConvert, true); //$NON-NLS-1$
820
		printAttribute("basedir", basedir, false); //$NON-NLS-1$
789
		else
821
		printAttribute("compression", "gzip", true); //$NON-NLS-1$//$NON-NLS-2$
790
			printAttribute("resourcePath", toConvert, true); //$NON-NLS-1$
822
		if (fileSets == null)
791
		printAttribute("property", propertyName, true); //$NON-NLS-1$
823
			output.println("/>"); //$NON-NLS-1$
792
		output.println("/>"); //$NON-NLS-1$
824
		else {
825
			output.println(">"); //$NON-NLS-1$
826
			indent++;
827
			for (int i = 0; i < fileSets.length; i++)
828
				if (fileSets[i] != null)
829
					fileSets[i].print(this);
830
			indent--;
831
			printTab();
832
			output.println("</tar>"); //$NON-NLS-1$
833
		}
793
	}
834
	}
794
835
795
	/**
836
	/**
796
	 * Print a <code> dirname </code> task to the script.
837
	 * Print a <code>zip</code> task to this script.
797
	 * @param property
838
	 * 
798
	 * @param file
839
	 * @param zipfile the destination file name
840
	 * @param basedir the source directory to start the zip
841
	 * @param filesOnly <code>true</code> if the resulting zip file should contain only files and not directories
842
	 * @param update ndicates whether to update or overwrite the destination file if it already exists
843
	 * @param fileSets the inclusion/exclusion rules to use when zipping
799
	 */
844
	 */
800
	public void printDirName(String property, String file) {
845
	public void printZipTask(String zipfile, String basedir, boolean filesOnly, boolean update, FileSet[] fileSets) {
801
		printTab();
846
		printTab();
802
		output.print("<dirname"); //$NON-NLS-1$
847
		output.print("<zip"); //$NON-NLS-1$
803
		printAttribute("property", property, true); //$NON-NLS-1$
848
		printAttribute("destfile", zipfile, true); //$NON-NLS-1$
804
		printAttribute("file", file, true); //$NON-NLS-1$
849
		printAttribute("basedir", basedir, false); //$NON-NLS-1$
805
		output.println("/>"); //$NON-NLS-1$
850
		printAttribute("filesonly", filesOnly ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
806
	}
851
		printAttribute("whenempty", "skip", true); //$NON-NLS-1$//$NON-NLS-2$
807
	
852
		printAttribute("update", update ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
808
	/**
853
		if (fileSets == null)
809
	 * Print a <code>Condition</code> task with isset test to the script
854
			output.println("/>"); //$NON-NLS-1$
810
	 * @param property		name of the property to set	
855
		else {
811
	 * @param value			value to set the property to
856
			output.println(">"); //$NON-NLS-1$
812
	 * @param testProperty	name of the property for the isset test
857
			indent++;
813
	 */
858
			for (int i = 0; i < fileSets.length; i++)
814
	public void printConditionIsSet(String property, String value, String testProperty) {
859
				if (fileSets[i] != null)
815
		println("<condition property=\"" + property + "\" value=\"" + value + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
860
					fileSets[i].print(this);
816
		indent++;
861
			indent--;
817
		println("<isset property=\"" + testProperty + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
862
			printTab();
818
		indent--;
863
			output.println("</zip>"); //$NON-NLS-1$
819
		printEndTag("condition"); //$NON-NLS-1$
864
		}
820
	}
865
	}
821
}
866
}
(-)plugin.properties (+3 lines)
Lines 10-12 Link Here
10
###############################################################################
10
###############################################################################
11
pluginName = Plug-in Development Environment Build Support
11
pluginName = Plug-in Development Environment Build Support
12
providerName = Eclipse.org
12
providerName = Eclipse.org
13
14
15
fetchTaskFactories.name = Fetch Script Task Factories
(-).cvsignore (-1 / +7 lines)
Lines 1-2 Link Here
1
bin
1
bin
2
lib
2
lib
3
temp*
4
build.xml
5
pdebuild.jar
6
org.eclipse.pde.build_*.zip
7
pdebuildsrc.zip
8
javaCompiler.pdebuild.jar.args
(-)build.properties (-1 / +2 lines)
Lines 22-26 Link Here
22
jars.compile.order = pdebuild.jar,\
22
jars.compile.order = pdebuild.jar,\
23
                     lib/pdebuild-ant.jar
23
                     lib/pdebuild-ant.jar
24
source.pdebuild.jar = src/
24
source.pdebuild.jar = src/
25
src.includes = about.html
25
src.includes = about.html,\
26
               schema/
26
source.lib/pdebuild-ant.jar = src_ant/
27
source.lib/pdebuild-ant.jar = src_ant/
(-)plugin.xml (+11 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<plugin>
3
<plugin>
4
   <extension-point id="fetchTaskFactories" name="%fetchTaskFactories.name" schema="schema/fetchTaskFactories.exsd"/>
4
<!-- Tasks -->
5
<!-- Tasks -->
5
   <extension
6
   <extension
6
         point="org.eclipse.ant.core.antTasks">
7
         point="org.eclipse.ant.core.antTasks">
Lines 85-88 Link Here
85
      </application>
86
      </application>
86
   </extension>
87
   </extension>
87
88
89
   <extension
90
         point="org.eclipse.pde.build.fetchTaskFactories">
91
      <factory
92
            class="org.eclipse.pde.internal.build.fetch.COPYFetchTasksFactory"
93
            id="COPY"/>
94
      <factory
95
            class="org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory"
96
            id="CVS"/>
97
   </extension>
98
88
</plugin>
99
</plugin>
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 12-18 Link Here
12
 org.eclipse.update.core,
12
 org.eclipse.update.core,
13
 org.apache.ant,
13
 org.apache.ant,
14
 org.eclipse.core.runtime.compatibility;resolution:=optional
14
 org.eclipse.core.runtime.compatibility;resolution:=optional
15
Export-Package: org.eclipse.pde.internal.build;x-friends:="org.eclipse.pde.ui",
15
Export-Package: org.eclipse.pde.build,
16
 org.eclipse.pde.internal.build;x-friends:="org.eclipse.pde.ui",
16
 org.eclipse.pde.internal.build.ant;x-friends:="org.eclipse.pde.ui",
17
 org.eclipse.pde.internal.build.ant;x-friends:="org.eclipse.pde.ui",
17
 org.eclipse.pde.internal.build.builder;x-friends:="org.eclipse.pde.ui",
18
 org.eclipse.pde.internal.build.builder;x-friends:="org.eclipse.pde.ui",
18
 org.eclipse.pde.internal.build.packager;x-friends:="org.eclipse.pde.ui",
19
 org.eclipse.pde.internal.build.packager;x-friends:="org.eclipse.pde.ui",
(-)src/org/eclipse/pde/internal/build/fetch/CVSFetchTaskFactory.java (+130 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors: 
9
 *     IBM Corporation - initial API and implementation
10
 *     Gunnar Wagenknecht - adaption to new fetch script builder API
11
 **********************************************************************/
12
package org.eclipse.pde.internal.build.fetch;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.pde.build.FetchTaskFactory;
19
import org.eclipse.pde.internal.build.IPDEBuildConstants;
20
import org.eclipse.pde.internal.build.Messages;
21
import org.eclipse.pde.internal.build.ant.AntScript;
22
import org.eclipse.pde.internal.build.ant.ITask;
23
24
/**
25
 * An <code>FetchTaskFactory</code> for building fetch scripts that will
26
 * fetch content from a CVS repository (id: <code>CVS</code>).
27
 * <p>
28
 * Map file arguments:
29
 * <code>&lt;TAG&gt;,&lt;CVSROOT&gt;[,&lt;PASSWORD&gt;[,&lt;PATH&gt;[,&lt;CVSPASSFILE&gt;]]]</code>
30
 * </p>
31
 */
32
public class CVSFetchTaskFactory extends FetchTaskFactory implements IPDEBuildConstants {
33
	public static final String ID = "CVS"; //$NON-NLS-1$
34
	
35
	private static final String CVSPASSFILE = "cvsPassFile"; //$NON-NLS-1$
36
	private static final String CVSROOT = "cvsRoot"; //$NON-NLS-1$
37
	private static final String PASSWORD = "password"; //$NON-NLS-1$
38
	private static final String PATH = "path"; //$NON-NLS-1$
39
	private static final String TAG = "tag"; //$NON-NLS-1$
40
41
	private static final ITask GET_FROM_CVS_TASK = new ITask() {
42
		public void print(AntScript script) {
43
			script.printCVSTask("export -d ${destination} -r ${tag} ${package}", "${cvsRoot}", null, null, null, "${quiet}", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
44
		}
45
	};
46
47
	public CharSequence generateAuthentificationTask(final String element, final String type, final Map entryInfos) throws CoreException {
48
		return AntScript.taskAsString(new ITask() {
49
			public void print(AntScript script) {
50
				String password = (String) entryInfos.get(PASSWORD);
51
				String cvsPassFileLocation = (String) entryInfos.get(CVSPASSFILE);
52
				if (password != null)
53
					script.printCVSPassTask((String) entryInfos.get(CVSROOT), password, cvsPassFileLocation);
54
			}
55
		});
56
	}
57
58
	public Map generatePropertiesForFetchTask(String element, String type, Map entryInfos, String destination, boolean manifestFileOnly) {
59
		Map params = new HashMap(5);
60
61
		// we directly export the CVS content into the destination
62
		params.put("destination", destination); //$NON-NLS-1$
63
		params.put(TAG, entryInfos.get(TAG));
64
		params.put(CVSROOT, entryInfos.get(CVSROOT));
65
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
66
67
		String cvsPackage = ((String) entryInfos.get(PATH) == null ? element : (String) entryInfos.get(PATH));
68
		if (type.equals(ELEMENT_TYPE_FEATURE)) {
69
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
70
		} else if (type.equals(ELEMENT_TYPE_PLUGIN)) {
71
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
72
		} else if (type.equals(ELEMENT_TYPE_FRAGMENT)) {
73
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
74
		} else if (type.equals(ELEMENT_TYPE_BUNDLE)) {
75
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR : "";//$NON-NLS-1$ 
76
		}
77
		params.put("package", cvsPackage); //$NON-NLS-1$
78
79
		return params;
80
	}
81
82
	public CharSequence generateRetrieveFilesTask(final String element, final String type, final Map entryInfos, final String destination, final String[] files) throws CoreException {
83
		return AntScript.taskAsString(new ITask() {
84
			public void print(AntScript script) {
85
				String cvsRoot = (String) entryInfos.get(CVSROOT);
86
				String tag = (String) entryInfos.get(TAG);
87
				String path = (String) entryInfos.get(PATH);
88
				String password = (String) entryInfos.get(PASSWORD);
89
				String cvsPassFileLocation = (String) entryInfos.get(CVSPASSFILE);
90
91
				if (password != null)
92
					script.printCVSPassTask(cvsRoot, password, cvsPassFileLocation);
93
94
				for (int i = 0; i < files.length; i++) {
95
					String file = files[i];
96
					IPath filePath;
97
					if (path != null) {
98
						filePath = new Path(path).append(file);
99
					} else {
100
						filePath = new Path(element).append(file);
101
					}
102
103
					script.printCVSTask("export -d " + destination + " -r " + tag + " " + filePath.toString(), cvsRoot, null, null, null, "true", null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
104
				}
105
			}
106
		});
107
	}
108
109
	public CharSequence getFetchTask() throws CoreException {
110
		return AntScript.taskAsString(GET_FROM_CVS_TASK);
111
	}
112
113
	public String getTagToFetch(String element, String type, Map entryInfos) {
114
		return (String) entryInfos.get(TAG);
115
	}
116
117
	public void processMapFileEntry(String element, String type, String[] arguments, String fetchTag, Map entryInfos) throws CoreException {
118
		if (arguments.length < 2) {
119
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, element);
120
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
121
		}
122
123
		entryInfos.put(CVSPASSFILE, (arguments.length > 4 && !arguments[4].equals("")) ? arguments[4] : null); //$NON-NLS-1$
124
		entryInfos.put(TAG, (null == fetchTag || fetchTag.trim().length() == 0) ? arguments[0] : fetchTag);
125
		entryInfos.put(CVSROOT, arguments[1]);
126
		entryInfos.put(PASSWORD, (arguments.length > 2 && !arguments[2].equals("")) ? arguments[2] : null); //$NON-NLS-1$
127
128
		entryInfos.put(PATH, (arguments.length > 3 && !arguments[3].equals("")) ? arguments[3] : null); //$NON-NLS-1$ 
129
	}
130
}
(-)src/org/eclipse/pde/internal/build/fetch/COPYFetchTasksFactory.java (+132 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2006 Eclipse Foundation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Gunnar Wagenknecht - Initial API and implementation
10
 **********************************************************************/
11
package org.eclipse.pde.internal.build.fetch;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.pde.build.FetchTaskFactory;
18
import org.eclipse.pde.internal.build.IPDEBuildConstants;
19
import org.eclipse.pde.internal.build.Messages;
20
import org.eclipse.pde.internal.build.ant.*;
21
22
/**
23
 * An <code>FetchTaskFactory</code> that fetches features and plugins by
24
 * copying from a specific location (id: <code>COPY</code>).
25
 * <p>
26
 * Map file arguments:
27
 * <code>&lt;ROOT_LOCATION&gt;[,&lt;ELEMENT_LOCATION&gt;]</code>
28
 * <dl>
29
 * <dt>ROOT_LOCATION</dt>
30
 * <dd>The ROOT_LOCATION (eg. <code>/source/eclipse</code>, or
31
 * <code>D:/dev/myproduct</code>) is used as root path to determine the
32
 * location to fetch. It can be overwritten via the
33
 * <code>fetchTag</code> to fetch from another location (for example, on a different machine).</dd>
34
 * </dl>
35
 * <dt>ELEMENT_LOCATION</dt>
36
 * <dd>A path withing the ROOT_LOCATION (eg.
37
 * <code>org.eclipse.sdk-feature/features/org.eclipse.rcp</code>) to retrive
38
 * the element from if it is not within the root. If this is not provided the
39
 * default path will be used which simply maps to the element name.</dd>
40
 * </dl>
41
 * </p>
42
 */
43
public class COPYFetchTasksFactory extends FetchTaskFactory implements IPDEBuildConstants {
44
45
	public static final String ID = "COPY"; //$NON-NLS-1$
46
47
	private static final String PATH = "path"; //$NON-NLS-1$
48
	private static final String ROOT = "root"; //$NON-NLS-1$
49
50
	private static final ITask GET_FROM_PATH_TASK = new ITask() {
51
		public void print(AntScript script) {
52
			FileSet dir = new FileSet("${sourcePath}", null, null, null, null, null, null); //$NON-NLS-1$
53
			script.printCopyTask(null, "${destination}", new FileSet[] {dir}, false, true); //$NON-NLS-1$ 
54
		}
55
	};
56
57
	public CharSequence generateAuthentificationTask(String element, String type, Map entryInfos) {
58
		// not necessary
59
		return null;
60
	}
61
62
	public Map generatePropertiesForFetchTask(String element, String type, Map entryInfos, String destination, boolean xmlFileOnly) {
63
		Map params = new HashMap(2);
64
65
		// we directly export the CVS content into the destination
66
		params.put("destination", destination); //$NON-NLS-1$
67
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
68
69
		String root = (String) entryInfos.get(ROOT);
70
		String path = (String) entryInfos.get(PATH);
71
		IPath sourcePath = new Path(root);
72
		if (path != null) {
73
			sourcePath = sourcePath.append(path);
74
		} else {
75
			sourcePath = sourcePath.append(element);
76
		}
77
78
		if (xmlFileOnly) {
79
			if (type.equals("feature")) { //$NON-NLS-1$
80
				sourcePath.append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
81
			} else if (type.equals("plugin")) { //$NON-NLS-1$
82
				sourcePath.append(DEFAULT_PLUGIN_FILENAME_DESCRIPTOR);
83
			} else if (type.equals("fragment")) { //$NON-NLS-1$
84
				sourcePath.append(DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR);
85
			}
86
		}
87
		params.put("sourcePath", sourcePath.toString()); //$NON-NLS-1$
88
89
		return params;
90
	}
91
92
	public CharSequence generateRetrieveFilesTask(final String element, final String type, final Map entryInfos, final String destination, final String[] files) throws CoreException {
93
		return AntScript.taskAsString(new ITask() {
94
			public void print(AntScript script) {
95
				String root = (String) entryInfos.get(ROOT);
96
				String path = (String) entryInfos.get(PATH);
97
98
				for (int i = 0; i < files.length; i++) {
99
					String file = files[i];
100
					IPath filePath = new Path(root);
101
					if (path != null) {
102
						filePath = filePath.append(path).append(file);
103
					} else {
104
						filePath = filePath.append(element).append(file);
105
					}
106
107
					script.printCopyTask(filePath.toString(), destination, null, false, true);
108
				}
109
			}
110
		});
111
	}
112
113
	public CharSequence getFetchTask() throws CoreException {
114
		return AntScript.taskAsString(GET_FROM_PATH_TASK);
115
	}
116
117
	public String getTagToFetch(String element, String type, Map entryInfos) {
118
		return (String) entryInfos.get(ROOT);
119
	}
120
121
	public void processMapFileEntry(String element, String type, String[] arguments, String fetchTag, Map entryInfos) throws CoreException {
122
123
		if (arguments.length < 1) {
124
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, element);
125
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
126
		}
127
128
		entryInfos.put(ROOT, (null == fetchTag || fetchTag.trim().length() == 0) ? arguments[0] : fetchTag);
129
		entryInfos.put(PATH, (arguments.length > 1 && arguments[1].trim().length() > 0) ? arguments[1] : null);
130
	}
131
132
}
(-)schema/fetchTaskFactories.exsd (+130 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.pde.build">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.pde.build" id="fetchScriptBuilders" name="Fetch Script Builder"/>
7
      </appInfo>
8
      <documentation>
9
         This extension point provides factories for constructing repository specific fetch script tasks during the PDE Build fetch process.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence>
16
            <element ref="factory" minOccurs="1" maxOccurs="unbounded"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
            </annotation>
38
         </attribute>
39
      </complexType>
40
   </element>
41
42
   <element name="factory">
43
      <annotation>
44
         <appInfo>
45
            <meta.element labelAttribute="id"/>
46
         </appInfo>
47
         <documentation>
48
            Defines a fetch task factory.
49
         </documentation>
50
      </annotation>
51
      <complexType>
52
         <attribute name="id" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  The factory id (must be unique).
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="class" type="string" use="required">
60
            <annotation>
61
               <documentation>
62
                  The factory implementation (must extend &lt;code&gt;org.eclipse.pde.build.FetchTaskFactory&lt;/code&gt; and must provide a parameter less, public constructor).
63
               </documentation>
64
               <appInfo>
65
                  <meta.attribute kind="java" basedOn="org.eclipse.pde.build.FetchTaskFactory"/>
66
               </appInfo>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
72
   <annotation>
73
      <appInfo>
74
         <meta.section type="since"/>
75
      </appInfo>
76
      <documentation>
77
         3.2
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         &lt;pre&gt;
87
&lt;extension point=&quot;org.eclipse.pde.build.fetchTaskFactories&quot;&gt;
88
    &lt;factory
89
        class=&quot;org.eclipse.pde.internal.build.fetch.COPYFetchTasksFactory&quot;
90
        id=&quot;COPY&quot;/&gt;
91
    &lt;factory
92
        class=&quot;org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory&quot;
93
        id=&quot;CVS&quot;/&gt;
94
&lt;/extension&gt;
95
&lt;/pre&gt;
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="apiInfo"/>
102
      </appInfo>
103
      <documentation>
104
         A fetch task factory must extend &lt;code&gt;org.eclipse.pde.build.FetchTaskFactory&lt;/code&gt; and must provide a parameter less, public constructor.
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="implementation"/>
111
      </appInfo>
112
      <documentation>
113
         The following fetch task factories are provided by PDE Build.
114
&lt;ul&gt;
115
&lt;li&gt;a CVS fetch task factroy for fetching features and plug-ins from CVS repositories&lt;/li&gt;
116
&lt;li&gt;a COPY fetch task factory for copying features and plug-ins from arbitrary file system locations&lt;/li&gt;
117
&lt;/ul&gt;
118
      </documentation>
119
   </annotation>
120
121
   <annotation>
122
      <appInfo>
123
         <meta.section type="copyright"/>
124
      </appInfo>
125
      <documentation>
126
         
127
      </documentation>
128
   </annotation>
129
130
</schema>
(-)src/org/eclipse/pde/build/FetchTaskFactory.java (+206 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2006 Eclipse Foundation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Gunnar Wagenknecht - Initial API and implementation
10
 **********************************************************************/
11
package org.eclipse.pde.build;
12
13
import java.util.Map;
14
import org.eclipse.core.runtime.CoreException;
15
16
/**
17
 * A <code>FetchTaskFactory</code> constructs a repository specific fetch
18
 * script for the PDE build process.
19
 * <p>
20
 * It is registered via the
21
 * <code>org.eclipse.pde.build.fetchScriptBuilder</code> extension point.
22
 * </p>
23
 * @since 3.2
24
 */
25
public abstract class FetchTaskFactory {
26
27
	/** element type <code>bundle</code> */
28
	public static final String ELEMENT_TYPE_BUNDLE = "bundle"; //$NON-NLS-1$
29
30
	/** element type <code>feature</code> */
31
	public static final String ELEMENT_TYPE_FEATURE = "feature"; //$NON-NLS-1$
32
33
	/** element type <code>fragment</code> */
34
	public static final String ELEMENT_TYPE_FRAGMENT = "fragment"; //$NON-NLS-1$
35
36
	/** element type <code>plugin</code> */
37
	public static final String ELEMENT_TYPE_PLUGIN = "plugin"; //$NON-NLS-1$
38
39
	/** map key of the element type (value <code>type</code>) */
40
	public static final String KEY_ELEMENT_TYPE = "type"; //$NON-NLS-1$
41
42
	/** map key of the element name (value <code>element</code>) */
43
	public static final String KEY_ELEMENT_NAME = "element"; //$NON-NLS-1$
44
45
	/** map key of the fetch task factory (value <code>factory</code>) */
46
	public static final String KEY_FACTORY = "factory"; //$NON-NLS-1$
47
48
	/**
49
	 * Generates an ANT task that is necessary for authentificate against the
50
	 * repository.
51
	 * 
52
	 * @param element
53
	 *            the element name
54
	 * @param type
55
	 *            the element type (one of
56
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
57
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
58
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
59
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
60
	 *            <code>null</code>)
61
	 * @param entryInfos
62
	 *            the map with detailed information collected in
63
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)},
64
	 *            additional keys that are set by PDE Build are:
65
	 *            {@link #KEY_ELEMENT_NAME}, 
66
	 *            {@link #KEY_ELEMENT_TYPE} and
67
	 *            {@link #KEY_FACTORY}
68
	 * @return the authentification task (maybe <code>null</code> if not
69
	 *         necessary)
70
	 */
71
	public abstract CharSequence generateAuthentificationTask(String element, String type, Map entryInfos) throws CoreException;
72
73
	/**
74
	 * Generates a properties for fetching the specified element via the fetch
75
	 * task.
76
	 * 
77
	 * @param element
78
	 *            the element name
79
	 * @param type
80
	 *            the element type (one of
81
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
82
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
83
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
84
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
85
	 *            <code>null</code>)
86
	 * @param entryInfos
87
	 *            the map with detailed information collected in
88
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)},
89
	 *            additional keys that are set by PDE Build are:
90
	 *            {@link #KEY_ELEMENT_NAME}, 
91
	 *            {@link #KEY_ELEMENT_TYPE} and
92
	 *            {@link #KEY_FACTORY}
93
	 * @param destination
94
	 *            the destination where the files should be fetched to
95
	 * @param xmlFileOnly
96
	 *            if <code>true</code> only the element's XML descriptor
97
	 *            should be fetched, otherwise the complete element must be
98
	 *            fetched
99
	 * @return the map with properties (must be <code>String</code> keys and
100
	 *         <code>String</code> values)
101
	 * @throws CoreException
102
	 */
103
	public abstract Map generatePropertiesForFetchTask(String element, String type, Map entryInfos, String destination, boolean xmlFileOnly) throws CoreException;
104
105
	/**
106
	 * Generates a task for retrieving the specified files only.
107
	 * 
108
	 * @param element
109
	 *            the element name
110
	 * @param type
111
	 *            the element type (one of
112
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
113
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
114
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
115
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
116
	 *            <code>null</code>)
117
	 * @param entryInfos
118
	 *            the map with detailed information collected in
119
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)},
120
	 *            additional keys that are set by PDE Build are:
121
	 *            {@link #KEY_ELEMENT_NAME}, 
122
	 *            {@link #KEY_ELEMENT_TYPE} and
123
	 *            {@link #KEY_FACTORY}
124
	 * @param destination
125
	 *            the destination where the files should be fetched to
126
	 * @param files
127
	 *            the list of files to fetch
128
	 * @return the task for fetching the files
129
	 */
130
	public abstract CharSequence generateRetrieveFilesTask(String element, String type, Map entryInfos, String destination, String[] files) throws CoreException;
131
132
	/**
133
	 * Returns the common task that is used to fetch elements specified via Ant
134
	 * properties.
135
	 * <p>
136
	 * This task is called from within the element specific generated fetch
137
	 * tasks to fetch an elements.
138
	 * </p>
139
	 * 
140
	 * @return the common fetch task
141
	 * @see #generatePropertiesForFetchTask(String, String, Map, String,
142
	 *      boolean)
143
	 */
144
	public abstract CharSequence getFetchTask() throws CoreException;
145
146
	/**
147
	 * Returns a version identifyer (eg. TAG name) of the element that will be
148
	 * fetched.
149
	 * 
150
	 * @param element
151
	 *            the element name
152
	 * @param type
153
	 *            the element type (one of
154
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
155
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
156
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
157
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
158
	 *            <code>null</code>)
159
	 * @param entryInfos
160
	 *            the map with detailed information collected in
161
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)},
162
	 *            additional keys that are set by PDE Build are:
163
	 *            {@link #KEY_ELEMENT_NAME}, 
164
	 *            {@link #KEY_ELEMENT_TYPE} and
165
	 *            {@link #KEY_FACTORY}
166
	 * @return a version identifyer
167
	 */
168
	public abstract String getTagToFetch(String element, String type, Map entryInfos) throws CoreException;
169
170
	/**
171
	 * Processes the specified element with the specified type.
172
	 * <p>
173
	 * The arguments specified in the map file are provided. The map with entry
174
	 * infos should be filled with provider specific information that is
175
	 * required in later processing to sucessfully generate the fetch script.
176
	 * </p>
177
	 * 
178
	 * @param element
179
	 *            the element name (eg. <code>com.my.plugin</code>) (may not
180
	 *            be <code>null</code>)
181
	 * @param type
182
	 *            the element type (one of
183
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
184
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
185
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
186
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
187
	 *            <code>null</code>)
188
	 * @param arguments
189
	 *            the arguments specified in the build script (may not be
190
	 *            <code>null</code>)
191
	 * @param fetchTag
192
	 *            the fetch tag that will overwrite all tags specified in the
193
	 *            repository if set (maybe <code>null</code> or empty)
194
	 * @param entryInfos
195
	 *            the map to store repository specific information 
196
	 *            (eg., label/tag/authentification informationen)
197
	 *            (may not be <code>null</code>);
198
	 *            reserved keys that must not be used are 
199
	 *            {@link #KEY_ELEMENT_NAME}, 
200
	 *            {@link #KEY_ELEMENT_TYPE} and
201
	 *            {@link #KEY_FACTORY}
202
	 * @throws CoreException
203
	 *             if the arguments are invalid
204
	 */
205
	public abstract void processMapFileEntry(String element, String type, String[] arguments, String fetchTag, Map entryInfos) throws CoreException;
206
}
(-)src/org/eclipse/pde/internal/build/FetchTaskFactoriesRegistry.java (+153 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2006 Eclipse Foundation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Gunnar Wagenknecht - Initial API and implementation
10
 **********************************************************************/
11
package org.eclipse.pde.internal.build;
12
13
import java.util.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.pde.build.FetchTaskFactory;
16
17
/**
18
 * A registry for acessing fetch script builders.
19
 * @since 3.2
20
 */
21
public class FetchTaskFactoriesRegistry implements IRegistryChangeListener {
22
23
	/** the extension point */
24
	private static final String EXT_FETCH_TASK_FACTORIES = "org.eclipse.pde.build.fetchTaskFactories"; //$NON-NLS-1$
25
26
	/** attribute <code>id</code> */
27
	private static final String ATTR_ID = "id"; //$NON-NLS-1$
28
29
	/** attribute <code>class</code> */
30
	private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
31
32
	/** element <code>builder</code> */
33
	private static final String ELEM_FACTORY = "factory"; //$NON-NLS-1$
34
35
	/** the shared instance */
36
	private static FetchTaskFactoriesRegistry instance;
37
38
	/**
39
	 * Creates the singleton registry instance.
40
	 */
41
	private static synchronized void createRegistry() {
42
		if (null != instance)
43
			return;
44
45
		instance = new FetchTaskFactoriesRegistry();
46
		Platform.getExtensionRegistry().addRegistryChangeListener(instance, "org.eclipse.pde.build"); //$NON-NLS-1$
47
	}
48
49
	/**
50
	 * Returns the singleton registry instance.
51
	 * 
52
	 * @return the registry instance
53
	 */
54
	public static FetchTaskFactoriesRegistry getRegistry() {
55
		if (null == instance) {
56
			createRegistry();
57
		}
58
		return instance;
59
	}
60
61
	/**
62
	 * Shuts down the registry.
63
	 */
64
	static void shutdown() {
65
		if (null != instance) {
66
			Platform.getExtensionRegistry().removeRegistryChangeListener(instance);
67
		}
68
	}
69
70
	/** a map of registered builders */
71
	private Map factories;
72
73
	/**
74
	 * Hidden constructor.
75
	 */
76
	private FetchTaskFactoriesRegistry() {
77
		// hidden constructor
78
	}
79
80
	/**
81
	 * Returns the builder instance with the specified id.
82
	 * <p>
83
	 * The instance is not cached. Each time this method is called, a new
84
	 * instance is created.
85
	 * </p>
86
	 * 
87
	 * @param id
88
	 * @return the builder instance (maybe <code>null</code>)
89
	 */
90
	public FetchTaskFactory getFactory(String id) {
91
92
		// ensure initialized
93
		initializeRegistry();
94
95
		IConfigurationElement extension = (IConfigurationElement) factories.get(id);
96
		if (null != extension) {
97
			try {
98
				return (FetchTaskFactory) extension.createExecutableExtension(ATTR_CLASS);
99
			} catch (CoreException e) {
100
				BundleHelper.getDefault().getLog().log(e.getStatus());
101
			}
102
		}
103
		return null;
104
	}
105
106
	/**
107
	 * Returns a collection of registered builder ids.
108
	 * 
109
	 * @return a collection of registered builder ids
110
	 */
111
	public Collection getFactoryIds() {
112
113
		// ensure initialized
114
		initializeRegistry();
115
116
		return null != factories ? factories.keySet() : Collections.EMPTY_SET;
117
	}
118
119
	/**
120
	 * Initializes the registry
121
	 */
122
	private void initializeRegistry() {
123
124
		// don't initialize twice
125
		if (null != factories)
126
			return;
127
128
		synchronized (factories = new HashMap()) {
129
			IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(EXT_FETCH_TASK_FACTORIES);
130
			for (int i = 0; i < extensions.length; i++) {
131
				IConfigurationElement extension = extensions[i];
132
				if (ELEM_FACTORY.equals(extension.getName())) {
133
					String id = extension.getAttribute(ATTR_ID);
134
					if (null != id && id.trim().length() > 0) {
135
						factories.put(id, extension);
136
					}
137
				}
138
			}
139
		}
140
	}
141
142
	/*
143
	 * (non-Javadoc)
144
	 * 
145
	 * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
146
	 */
147
	public void registryChanged(IRegistryChangeEvent event) {
148
149
		// reset list of known builders
150
		if (null != factories)
151
			factories = null;
152
	}
153
}

Return to bug 34757