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

(-).cvsignore (-1 / +4 lines)
Lines 1-2 Link Here
1
bin
1
bin
2
lib
2
lib
3
temp*
4
build.xml
5
pdebuild.jar
(-)plugin.properties (+3 lines)
Lines 1-2 Link Here
1
pluginName = Plug-in Development Environment Build Support
1
pluginName = Plug-in Development Environment Build Support
2
providerName = Eclipse.org
2
providerName = Eclipse.org
3
4
5
fetchScriptBuilder.name = Fetch Script Builder
(-)plugin.xml (+10 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="fetchScriptBuilder" name="%fetchScriptBuilder.name" schema="schema/fetchScriptBuilder.exsd"/>
4
<!-- Tasks -->
5
<!-- Tasks -->
5
   <extension
6
   <extension
6
         point="org.eclipse.ant.core.antTasks">
7
         point="org.eclipse.ant.core.antTasks">
Lines 84-89 Link Here
84
      <feature-factory
85
      <feature-factory
85
            class="org.eclipse.pde.internal.build.site.BuildTimeFeatureFactory">
86
            class="org.eclipse.pde.internal.build.site.BuildTimeFeatureFactory">
86
      </feature-factory>
87
      </feature-factory>
88
   </extension>
89
   <extension
90
         point="org.eclipse.pde.build.fetchScriptBuilder">
91
      <builder
92
            class="org.eclipse.pde.internal.build.PATHFetchScriptBuilder"
93
            id="PATH"/>
94
      <builder
95
            class="org.eclipse.pde.internal.build.CVSFetchScriptBuilder"
96
            id="CVS"/>
87
   </extension>
97
   </extension>
88
98
89
</plugin>
99
</plugin>
(-)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
        FetchScriptBuilderRegistry.shutdown();
23
	}
24
	}
24
}
25
}
(-)src/org/eclipse/pde/internal/build/FetchScriptGenerator.java (-82 / +119 lines)
Lines 10-21 Link Here
10
 **********************************************************************/
10
 **********************************************************************/
11
package org.eclipse.pde.internal.build;
11
package org.eclipse.pde.internal.build;
12
12
13
import java.io.*;
13
import java.io.BufferedInputStream;
14
import java.util.*;
14
import java.io.BufferedOutputStream;
15
import java.io.File;
16
import java.io.FileInputStream;
17
import java.io.FileOutputStream;
18
import java.io.IOException;
19
import java.io.InputStream;
20
import java.io.OutputStream;
21
import java.util.ArrayList;
22
import java.util.HashMap;
23
import java.util.List;
24
import java.util.Map;
25
import java.util.Properties;
26
15
import org.eclipse.ant.core.AntRunner;
27
import org.eclipse.ant.core.AntRunner;
16
import org.eclipse.core.runtime.*;
28
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.Path;
32
import org.eclipse.core.runtime.Status;
17
import org.eclipse.pde.internal.build.ant.AntScript;
33
import org.eclipse.pde.internal.build.ant.AntScript;
18
import org.eclipse.update.core.*;
34
import org.eclipse.pde.internal.build.ant.ITask;
35
import org.eclipse.update.core.Feature;
36
import org.eclipse.update.core.IFeature;
37
import org.eclipse.update.core.IIncludedFeatureReference;
38
import org.eclipse.update.core.IPluginEntry;
19
import org.eclipse.update.internal.core.FeatureExecutableFactory;
39
import org.eclipse.update.internal.core.FeatureExecutableFactory;
20
40
21
/**
41
/**
Lines 25-34 Link Here
25
public class FetchScriptGenerator extends AbstractScriptGenerator {
45
public class FetchScriptGenerator extends AbstractScriptGenerator {
26
	private static final String ELEMENT = "element"; //$NON-NLS-1$
46
	private static final String ELEMENT = "element"; //$NON-NLS-1$
27
	private static final String TYPE = "type"; //$NON-NLS-1$
47
	private static final String TYPE = "type"; //$NON-NLS-1$
28
	private static final String PATH = "path"; //$NON-NLS-1$
48
    private static final String BUILDER = "builder"; //$NON-NLS-1$
29
	private static final String PASSWORD = "password"; //$NON-NLS-1$
30
	private static final String CVSROOT = "cvsRoot"; //$NON-NLS-1$
31
	private static final String TAG = "tag"; //$NON-NLS-1$
32
49
33
	// flag saying if we want to recursively generate the scripts	
50
	// flag saying if we want to recursively generate the scripts	
34
	protected boolean recursiveGeneration = true;
51
	protected boolean recursiveGeneration = true;
Lines 37-45 Link Here
37
	protected String directoryLocation;
54
	protected String directoryLocation;
38
	protected static Properties directory;	//TODO Should be passed around
55
	protected static Properties directory;	//TODO Should be passed around
39
56
40
	// The location of the CVS password file.
41
	protected String cvsPassFileLocation;
42
43
	protected boolean fetchChildren = true;
57
	protected boolean fetchChildren = true;
44
58
45
	protected String fetchTag = ""; //$NON-NLS-1$
59
	protected String fetchTag = ""; //$NON-NLS-1$
Lines 145-151 Link Here
145
			FetchScriptGenerator generator = new FetchScriptGenerator("feature@" + featureId); //$NON-NLS-1$
159
			FetchScriptGenerator generator = new FetchScriptGenerator("feature@" + featureId); //$NON-NLS-1$
146
			generator.setDirectoryLocation(directoryLocation);
160
			generator.setDirectoryLocation(directoryLocation);
147
			generator.setFetchChildren(fetchChildren);
161
			generator.setFetchChildren(fetchChildren);
148
			generator.setCvsPassFileLocation(cvsPassFileLocation);
149
			generator.setRecursiveGeneration(recursiveGeneration);
162
			generator.setRecursiveGeneration(recursiveGeneration);
150
			generator.setFetchTag(fetchTag);
163
			generator.setFetchTag(fetchTag);
151
			generator.repositoryPluginVersions = repositoryPluginVersions;
164
			generator.repositoryPluginVersions = repositoryPluginVersions;
Lines 197-203 Link Here
197
210
198
	protected void generateFetchPluginsTarget() throws CoreException {
211
	protected void generateFetchPluginsTarget() throws CoreException {
199
		script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null);
212
		script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null);
200
		retrieveFeature((String) mapInfos.get(ELEMENT), (String) mapInfos.get(CVSROOT), (String) mapInfos.get(TAG), (String) mapInfos.get(PASSWORD), (String) mapInfos.get(PATH)); //$NON-NLS-1$ 	//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-1$ //$NON-NLS-5$
213
		retrieveFeature((String) mapInfos.get(ELEMENT), (String) mapInfos.get(TYPE), mapInfos);
201
		generateChildrenFetchScript();
214
		generateChildrenFetchScript();
202
		script.printTargetEnd();
215
		script.printTargetEnd();
203
	}
216
	}
Lines 212-243 Link Here
212
	private Map processMapFileEntry(String entry) throws CoreException {
225
	private Map processMapFileEntry(String entry) throws CoreException {
213
		Map entryInfos = new HashMap(5);
226
		Map entryInfos = new HashMap(5);
214
227
215
		String cvsInfo = getCVSInfo(entry);
228
        // extract type and element from entry
216
		if (cvsInfo == null) {
229
        int index = entry.indexOf('@'); //$NON-NLS-1$
230
        String type =  entry.substring(0, index);
231
        String element = entry.substring(index + 1);
232
        
233
        // read and validate the repository info
234
		String repositoryInfo = getRepositoryInfo(entry);
235
		if (repositoryInfo == null) {
217
			String message = Policy.bind("error.missingDirectoryEntry", entry); //$NON-NLS-1$
236
			String message = Policy.bind("error.missingDirectoryEntry", entry); //$NON-NLS-1$
218
			BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
237
			BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
219
			return null;
238
			return null;
220
		}
239
		}
221
240
222
		String[] cvsFields = Utils.getArrayFromStringWithBlank(cvsInfo, ","); //$NON-NLS-1$
241
        // collect and validate the repository info
223
		if (cvsFields.length < 2) {
242
		String[] repositoryFields = Utils.getArrayFromStringWithBlank(repositoryInfo, ","); //$NON-NLS-1$
243
		if (repositoryFields.length < 2) {
224
			String message = Policy.bind("error.incorrectDirectoryEntry", element); //$NON-NLS-1$
244
			String message = Policy.bind("error.incorrectDirectoryEntry", element); //$NON-NLS-1$
225
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
245
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
226
		}
246
		}
227
247
228
		entryInfos.put(TAG, fetchTag.length() == 0 ? cvsFields[0] : fetchTag); //$NON-NLS-1$
248
        // determine fetch script builder
229
		entryInfos.put(CVSROOT, cvsFields[1]); //$NON-NLS-1$
249
        IFetchScriptBuilder fetchScriptBuilder = null;
230
		entryInfos.put(PASSWORD, (cvsFields.length > 2 && !cvsFields[2].equals("")) ? cvsFields[2] : null); //$NON-NLS-1$ //$NON-NLS-2$
250
        String[] arguments = null;
231
251
        
232
		entryInfos.put(PATH, (cvsFields.length > 3 && !cvsFields[3].equals("")) ? cvsFields[3] : null); //$NON-NLS-1$ //$NON-NLS-2$
252
        // check if first repository field matches a builder id
233
253
        if(FetchScriptBuilderRegistry.getRegistry().getBuilderIds().contains(repositoryFields[0])) 
234
		int index = entry.indexOf('@'); //$NON-NLS-1$
254
        {
235
		entryInfos.put(TYPE, entry.substring(0, index)); //$NON-NLS-1$
255
            fetchScriptBuilder = FetchScriptBuilderRegistry.getRegistry().getBuilder(repositoryFields[0]);
236
		entryInfos.put(ELEMENT, entry.substring(index + 1)); //$NON-NLS-1$
256
            
257
            // construct arguments array for registered builder
258
            arguments = new String[repositoryFields.length-1];
259
            System.arraycopy(repositoryFields, 1, arguments, 0, repositoryFields.length-1);
260
        }
261
        
262
        // check builder not nuöl
263
        if( null == fetchScriptBuilder) 
264
        {
265
            // fall back to CVS
266
            fetchScriptBuilder = new CVSFetchScriptBuilder();
267
268
            // construct arguments array for CVS builder
269
            arguments = repositoryFields;
270
        }
271
        
272
        // add infos from registered builder
273
        fetchScriptBuilder.processMapFileEntry(element, type, arguments, fetchTag, entryInfos);
274
        
275
        // store builde
276
        entryInfos.put(BUILDER, fetchScriptBuilder);
277
        
278
        // add general infos (will override builder specific infos)
279
		entryInfos.put(TYPE, type);
280
		entryInfos.put(ELEMENT, element);
237
		return entryInfos;
281
		return entryInfos;
238
	}
282
	}
239
283
240
	protected void generateFetchRecusivelyTarget() throws CoreException {
284
    protected void generateFetchRecusivelyTarget() throws CoreException {
241
		script.printTargetDeclaration(TARGET_FETCH_RECURSIVELY, null, FEATURES_RECURSIVELY, null, null);
285
		script.printTargetDeclaration(TARGET_FETCH_RECURSIVELY, null, FEATURES_RECURSIVELY, null, null);
242
286
243
		IIncludedFeatureReference[] compiledFeatures = ((Feature) feature).getFeatureIncluded();
287
		IIncludedFeatureReference[] compiledFeatures = ((Feature) feature).getFeatureIncluded();
Lines 264-312 Link Here
264
				return;
308
				return;
265
		}
309
		}
266
310
267
		String password = (String) mapFileEntry.get(PASSWORD);
311
        IFetchScriptBuilder builder = (IFetchScriptBuilder) mapFileEntry.get(BUILDER);
268
		if (password != null)
312
        String element = (String) mapFileEntry.get(ELEMENT);
269
			script.printCVSPassTask((String) mapFileEntry.get(CVSROOT), password, cvsPassFileLocation); //$NON-NLS-1$
313
        String type = (String) mapFileEntry.get(TYPE);
270
314
        
271
		String type = (String) mapFileEntry.get(TYPE);
315
        // print authentification task if one is provided
316
        ITask authTask = builder.generateAuthentificationTask(element,type,mapFileEntry);
317
        if(null != authTask) script.print(authTask);
318
        
319
        // the location
272
		String location = getElementLocation(type);
320
		String location = getElementLocation(type);
273
		Map params = new HashMap(5);
321
        
274
322
        // the destination
275
		//We directly export the CVS content into the correct directory 
323
        // we directly export the content into the correct directory 
276
		params.put("destination", mapFileEntry.get(ELEMENT)); //$NON-NLS-1$ //$NON-NLS-2$
324
        String destination = element;
277
		params.put(TAG, mapFileEntry.get(TAG)); //$NON-NLS-1$ //$NON-NLS-2$
325
        
278
		params.put(CVSROOT, mapFileEntry.get(CVSROOT)); //$NON-NLS-1$ //$NON-NLS-2$
326
        // get params from builder
279
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
327
		Map params = new HashMap(builder.generatePropertiesForFetchTask(element, type, mapFileEntry, destination, xmlFileOnly));
280
328
281
		String cvsPackage = ((String) mapFileEntry.get(PATH) == null ? (String) mapFileEntry.get(ELEMENT) : (String) mapFileEntry.get(PATH)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
282
		String fullLocation = null;
329
		String fullLocation = null;
283
		if (type.equals("feature")) { //$NON-NLS-1$
330
		if (type.equals("feature")) { //$NON-NLS-1$
284
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
331
			fullLocation = location + '/' + element + '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
285
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
332
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
286
			cvsPackage += xmlFileOnly ? '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$ //$NON-NLS-2$
333
			repositoryFeatureVersions.put(element, builder.getVersionToFetch(element,type,mapFileEntry));
287
			repositoryFeatureVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
288
		} else if (type.equals("plugin")) { //$NON-NLS-1$
334
		} else if (type.equals("plugin")) { //$NON-NLS-1$
289
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
335
			fullLocation = location + '/' + element + '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
290
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
336
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
291
			cvsPackage += xmlFileOnly ? '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$ //$NON-NLS-2$
337
			repositoryPluginVersions.put(element, builder.getVersionToFetch(element,type,mapFileEntry));
292
			repositoryPluginVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
293
		} else if (type.equals("fragment")) { //$NON-NLS-1$
338
		} else if (type.equals("fragment")) { //$NON-NLS-1$
294
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
339
			fullLocation = location + '/' + element + '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
295
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
340
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
296
			cvsPackage += xmlFileOnly ? '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$ //$NON-NLS-2$
341
			repositoryPluginVersions.put(element, builder.getVersionToFetch(element,type,mapFileEntry));
297
			repositoryPluginVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
298
		}
342
		}
299
		params.put("package", cvsPackage); //$NON-NLS-1$
300
343
301
		// This call create a new property for every feature, plugins or fragments that we must check the existence of 
344
		// This call create a new property for every feature, plugins or fragments that we must check the existence of 
302
		script.printAvailableTask(fullLocation, fullLocation);
345
		script.printAvailableTask(fullLocation, fullLocation);
303
		script.printAntTask("../" + scriptName, getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + (type.equals("feature") ? DEFAULT_FEATURE_LOCATION : DEFAULT_PLUGIN_LOCATION), TARGET_GET_FROM_CVS, null, null, params); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
346
		script.printAntTask("../" + scriptName, getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + (type.equals("feature") ? DEFAULT_FEATURE_LOCATION : DEFAULT_PLUGIN_LOCATION), TARGET_FETCH_FROM_REPOSITORY, null, null, params); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
304
347
305
	}
348
	}
306
349
307
	protected void generateGetFromCVSTarget() {
350
	protected void generateGetFromCVSTarget() {
308
		script.printTargetDeclaration(TARGET_GET_FROM_CVS, null, null, "${fileToCheck}", null); //$NON-NLS-1$
351
		script.printTargetDeclaration(TARGET_FETCH_FROM_REPOSITORY, null, null, "${fileToCheck}", null); //$NON-NLS-1$
309
		script.printCVSTask("export -d ${destination} -r ${tag} ${package}", "${cvsRoot}", null, null, null, "${quiet}", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
352
        if(null != mapInfos) {
353
            IFetchScriptBuilder builder = (IFetchScriptBuilder) mapInfos.get(BUILDER);
354
            if(null != builder) {
355
                ITask getTask = builder.getFetchTask();
356
                if(null != getTask) {
357
                    script.print(getTask);
358
                }
359
            }
360
        }
310
		script.printTargetEnd();
361
		script.printTargetEnd();
311
	}
362
	}
312
363
Lines 360-366 Link Here
360
	 * @param password the CVS password
411
	 * @param password the CVS password
361
	 * @throws CoreException
412
	 * @throws CoreException
362
	 */
413
	 */
363
	protected void retrieveFeature(String elementName, String cvsRoot, String tag, String password, String path) throws CoreException {
414
	protected void retrieveFeature(String elementName, String elementType, Map elementInfos) throws CoreException {
364
		// Generate a temporary Ant script which retrieves the feature.xml for this
415
		// Generate a temporary Ant script which retrieves the feature.xml for this
365
		// feature from CVS
416
		// feature from CVS
366
		File root = new File(workingDirectory);
417
		File root = new File(workingDirectory);
Lines 371-392 Link Here
371
				retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
422
				retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
372
				retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null); //$NON-NLS-1$
423
				retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null); //$NON-NLS-1$
373
424
374
				IPath moduleFeatureFile;
425
                String destination = elementName;
375
				IPath moduleFeatureProperties;
426
                String[] files = new String[] {DEFAULT_FEATURE_FILENAME_DESCRIPTOR, PROPERTIES_FILE};
376
				if (path != null) {
427
                IFetchScriptBuilder builder = (IFetchScriptBuilder) elementInfos.get(BUILDER);
377
					moduleFeatureFile = new Path(path).append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
428
                ITask retrieveFeatureTask = builder.generateRetrieveFilesTask(elementName, elementType, elementInfos, destination, files);
378
					moduleFeatureProperties = new Path(path).append(PROPERTIES_FILE);
429
                if(null == retrieveFeatureTask) {
379
				} else {
430
                    String message = Policy.bind("error.noRetrieveFeatureTask", elementName); //$NON-NLS-1$
380
					moduleFeatureFile = new Path(elementName).append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
431
                    throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
381
					moduleFeatureProperties = new Path(elementName).append(PROPERTIES_FILE);
432
                }
382
				}
433
                retrieve.print(retrieveFeatureTask);
383
434
                
384
				if (password != null)
385
					retrieve.printCVSPassTask(cvsRoot, password, cvsPassFileLocation);
386
387
				retrieve.printCVSTask("export -r " + tag + " " + moduleFeatureFile.toString(), cvsRoot, null, null, null, "true", null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
388
				retrieve.printCVSTask("export -r " + tag + " " + moduleFeatureProperties.toString(), cvsRoot, null, null, null, "true", null); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
389
390
				retrieve.printTargetEnd();
435
				retrieve.printTargetEnd();
391
				retrieve.printProjectEnd();
436
				retrieve.printProjectEnd();
392
			} finally {
437
			} finally {
Lines 403-416 Link Here
403
			AntRunner runner = new AntRunner();
448
			AntRunner runner = new AntRunner();
404
			runner.setBuildFileLocation(target.getAbsolutePath());
449
			runner.setBuildFileLocation(target.getAbsolutePath());
405
			runner.run();
450
			runner.run();
451
            String destination = elementName;
406
			FeatureExecutableFactory factory = new FeatureExecutableFactory();
452
			FeatureExecutableFactory factory = new FeatureExecutableFactory();
407
			File featureFolder = new File(root, (path == null ? elementName : path));
453
			File featureFolder = new File(root, destination);
408
			feature = (Feature) factory.createFeature(featureFolder.toURL(), null, null);
454
			feature = (Feature) factory.createFeature(featureFolder.toURL(), null, null);
409
455
410
			//We only delete here, so if an exception is thrown the user can still see the retrieve.xml 
456
			//We only delete here, so if an exception is thrown the user can still see the retrieve.xml 
411
			target.delete();
457
			target.delete();
412
			featureProperties = new Properties();
458
			featureProperties = new Properties();
413
			InputStream featureStream = new FileInputStream(new File(root, (path == null ? elementName : path) + '/' + PROPERTIES_FILE));
459
			InputStream featureStream = new FileInputStream(new File(root, destination + '/' + PROPERTIES_FILE));
414
			featureProperties.load(featureStream);
460
			featureProperties.load(featureStream);
415
			featureStream.close();
461
			featureStream.close();
416
			clear(featureFolder);
462
			clear(featureFolder);
Lines 474-480 Link Here
474
	 * @return String
520
	 * @return String
475
	 * @throws CoreException
521
	 * @throws CoreException
476
	 */
522
	 */
477
	protected String getCVSInfo(String elementName) throws CoreException {
523
	protected String getRepositoryInfo(String elementName) throws CoreException {
478
		if (directory == null)
524
		if (directory == null)
479
			directory = readProperties(directoryLocation, "", IStatus.ERROR); //$NON-NLS-1$
525
			directory = readProperties(directoryLocation, "", IStatus.ERROR); //$NON-NLS-1$
480
		return directory.getProperty(elementName);
526
		return directory.getProperty(elementName);
Lines 526-540 Link Here
526
	 */
572
	 */
527
	public void setFetchTag(String value) {
573
	public void setFetchTag(String value) {
528
		fetchTag = value;
574
		fetchTag = value;
529
	}
530
531
	/**
532
	 * Sets the CVS password file location to be the given value.
533
	 * 
534
	 * @param cvsPassFileLocation the CVS password file location
535
	 */
536
	public void setCvsPassFileLocation(String cvsPassFileLocation) {
537
		this.cvsPassFileLocation = cvsPassFileLocation;
538
	}
575
	}
539
576
540
	public void setRecursiveGeneration(boolean recursiveGeneration) {
577
	public void setRecursiveGeneration(boolean recursiveGeneration) {
(-)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_ant/org/eclipse/pde/internal/build/tasks/FetchTask.java (-9 lines)
Lines 45-59 Link Here
45
	}
45
	}
46
46
47
	/**
47
	/**
48
	 * Set the location for the CVS password file.
49
	 * 
50
	 * @param cvsPassFileLocation the location of the password file
51
	 */
52
	public void setCvsPassFile(String cvsPassFileLocation) {
53
		generator.setCvsPassFileLocation(cvsPassFileLocation);
54
	}
55
56
	/**
57
	 * 
48
	 * 
58
	 * @param directoryLocation
49
	 * @param directoryLocation
59
	 */
50
	 */
(-)schema/fetchScriptBuilder.exsd (+117 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="fetchScriptBuilder" name="Fetch Script Builder"/>
7
      </appInfo>
8
      <documentation>
9
         Provides builders for constructing fetch scripts during the build process.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence>
16
            <element ref="builder" 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="builder">
43
      <annotation>
44
         <appInfo>
45
            <meta.element labelAttribute="id"/>
46
         </appInfo>
47
         <documentation>
48
            The builder.
49
         </documentation>
50
      </annotation>
51
      <complexType>
52
         <attribute name="id" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  The builder id (must be unique).
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="class" type="string" use="required">
60
            <annotation>
61
               <documentation>
62
                  The builder implementation (must implement &lt;code&gt;org.eclipse.pde.internal.build.IFetchScriptBuilder&lt;/code&gt; and must provide a parameter less, public constructor).
63
               </documentation>
64
               <appInfo>
65
                  <meta.attribute kind="java" basedOn="org.eclipse.pde.internal.build.IFetchScriptBuilder"/>
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
         [Enter the first release in which this extension point appears.]
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         [Enter extension point usage example here.]
87
      </documentation>
88
   </annotation>
89
90
   <annotation>
91
      <appInfo>
92
         <meta.section type="apiInfo"/>
93
      </appInfo>
94
      <documentation>
95
         [Enter API information here.]
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="implementation"/>
102
      </appInfo>
103
      <documentation>
104
         [Enter information about supplied implementation of this extension point.]
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="copyright"/>
111
      </appInfo>
112
      <documentation>
113
         
114
      </documentation>
115
   </annotation>
116
117
</schema>
(-)src/org/eclipse/pde/internal/build/CVSFetchScriptBuilder.java (+217 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors: 
9
 *     IBM Corporation - initial API and implementation
10
 *     Gunnar Wagenknecht - adaption to new builder API
11
 **********************************************************************/
12
package org.eclipse.pde.internal.build;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Status;
22
import org.eclipse.pde.internal.build.ant.AntScript;
23
import org.eclipse.pde.internal.build.ant.ITask;
24
25
/**
26
 * An <code>IFetchScriptBuilder</code> for building fetch scripts that will
27
 * fetch content from a CVS repository (id: <code>CVS</code>).
28
 * <p>
29
 * Map file arguments:
30
 * <code>&lt;TAG&gt;,&lt;CVSROOT&gt;[,&lt;PASSWORD&gt;[,&lt;PATH&gt;[,&lt;CVSPASSFILE&gt;]]]</code>
31
 * </p>
32
 */
33
public class CVSFetchScriptBuilder implements IFetchScriptBuilder,
34
        IPDEBuildConstants {
35
36
    private static final String CVSPASSFILE = "cvsPassFile"; //$NON-NLS-1$
37
38
    private static final String CVSROOT = "cvsRoot"; //$NON-NLS-1$
39
40
    private static final ITask GET_FROM_CVS_TASK = new ITask() {
41
42
        /*
43
         * (non-Javadoc)
44
         * 
45
         * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
46
         */
47
        public void print(AntScript script) {
48
            script
49
                    .printCVSTask(
50
                            "export -d ${destination} -r ${tag} ${package}", "${cvsRoot}", null, null, null, "${quiet}", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
51
        }
52
    };
53
54
    public static final String ID = "CVS"; //$NON-NLS-1$
55
56
    private static final String PASSWORD = "password"; //$NON-NLS-1$
57
58
    private static final String PATH = "path"; //$NON-NLS-1$
59
60
    private static final String TAG = "tag"; //$NON-NLS-1$
61
62
    /*
63
     * (non-Javadoc)
64
     * 
65
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateAuthentificationTask(java.lang.String,
66
     *      java.lang.String, java.util.Map)
67
     */
68
    public ITask generateAuthentificationTask(final String element,
69
            final String type, final Map entryInfos) {
70
71
        return new ITask() {
72
73
            /*
74
             * (non-Javadoc)
75
             * 
76
             * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
77
             */
78
            public void print(AntScript script) {
79
                String password = (String) entryInfos.get(PASSWORD);
80
                String cvsPassFileLocation = (String) entryInfos
81
                        .get(CVSPASSFILE);
82
                if (password != null)
83
                        script.printCVSPassTask((String) entryInfos
84
                                .get(CVSROOT), password, cvsPassFileLocation);
85
            }
86
        };
87
    }
88
89
    /*
90
     * (non-Javadoc)
91
     * 
92
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generatePropertiesForFetchTask(java.lang.String,
93
     *      java.lang.String, java.util.Map, java.lang.String, boolean)
94
     */
95
    public Map generatePropertiesForFetchTask(String element, String type,
96
            Map entryInfos, String destination, boolean xmlFileOnly)
97
            throws CoreException {
98
        Map params = new HashMap(5);
99
100
        // we directly export the CVS content into the destination
101
        params.put("destination", destination); //$NON-NLS-1$
102
        params.put(TAG, entryInfos.get(TAG));
103
        params.put(CVSROOT, entryInfos.get(CVSROOT));
104
        params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
105
106
        String cvsPackage = ((String) entryInfos.get(PATH) == null ? element
107
                : (String) entryInfos.get(PATH));
108
        if (type.equals("feature")) { //$NON-NLS-1$
109
            cvsPackage += xmlFileOnly ? '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR
110
                    : ""; //$NON-NLS-1$ //$NON-NLS-2$
111
        } else if (type.equals("plugin")) { //$NON-NLS-1$
112
            cvsPackage += xmlFileOnly ? '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR
113
                    : ""; //$NON-NLS-1$ //$NON-NLS-2$
114
        } else if (type.equals("fragment")) { //$NON-NLS-1$
115
            cvsPackage += xmlFileOnly ? '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR
116
                    : ""; //$NON-NLS-1$ //$NON-NLS-2$
117
        }
118
        params.put("package", cvsPackage); //$NON-NLS-1$
119
120
        return params;
121
    }
122
123
    /*
124
     * (non-Javadoc)
125
     * 
126
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateRetrieveFilesTask(java.lang.String,
127
     *      java.lang.String, java.util.Map, java.lang.String,
128
     *      java.lang.String[])
129
     */
130
    public ITask generateRetrieveFilesTask(final String element,
131
            final String type, final Map entryInfos, final String destination,
132
            final String[] files) {
133
        return new ITask() {
134
135
            /*
136
             * (non-Javadoc)
137
             * 
138
             * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
139
             */
140
            public void print(AntScript script) {
141
                String cvsRoot = (String) entryInfos.get(CVSROOT);
142
                String tag = (String) entryInfos.get(TAG);
143
                String path = (String) entryInfos.get(PATH);
144
                String password = (String) entryInfos.get(PASSWORD);
145
                String cvsPassFileLocation = (String) entryInfos
146
                        .get(CVSPASSFILE);
147
148
                if (password != null)
149
                        script.printCVSPassTask(cvsRoot, password,
150
                                cvsPassFileLocation);
151
152
                for (int i = 0; i < files.length; i++) {
153
                    String file = files[i];
154
                    IPath filePath;
155
                    if (path != null) {
156
                        filePath = new Path(path).append(file);
157
                    } else {
158
                        filePath = new Path(element).append(file);
159
                    }
160
161
                    script
162
                            .printCVSTask(
163
                                    "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$
164
                }
165
            }
166
        };
167
    }
168
169
    /*
170
     * (non-Javadoc)
171
     * 
172
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getFetchTask()
173
     */
174
    public ITask getFetchTask() {
175
        return GET_FROM_CVS_TASK;
176
    }
177
178
    /*
179
     * (non-Javadoc)
180
     * 
181
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getVersionToFetch(java.lang.String,
182
     *      java.lang.String, java.util.Map)
183
     */
184
    public String getVersionToFetch(String element, String type, Map entryInfos) {
185
        return (String) entryInfos.get(TAG);
186
    }
187
188
    /*
189
     * (non-Javadoc)
190
     * 
191
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#processMapFileEntry(java.lang.String,
192
     *      java.lang.String, java.lang.String[], java.lang.String,
193
     *      java.util.Map)
194
     */
195
    public void processMapFileEntry(String element, String type,
196
            String[] arguments, String fetchTag, Map entryInfos)
197
            throws CoreException {
198
199
        if (arguments.length < 2) {
200
            String message = Policy.bind(
201
                    "error.incorrectDirectoryEntry", element); //$NON-NLS-1$
202
            throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD,
203
                    EXCEPTION_ENTRY_MISSING, message, null));
204
        }
205
206
        entryInfos.put(TAG, (null == fetchTag || fetchTag.trim().length() == 0 ) ? arguments[0] : fetchTag);
207
        entryInfos.put(CVSROOT, arguments[1]);
208
        entryInfos.put(PASSWORD, (arguments.length > 2 && !arguments[2]
209
                .equals("")) ? arguments[2] : null); //$NON-NLS-1$
210
        entryInfos
211
                .put(
212
                        PATH,
213
                        (arguments.length > 3 && !arguments[3].equals("")) ? arguments[3] : null); //$NON-NLS-1$ 
214
        entryInfos.put(CVSPASSFILE, (arguments.length > 4 && !arguments[4]
215
                .equals("")) ? arguments[4] : null); //$NON-NLS-1$
216
    }
217
}
(-)src/org/eclipse/pde/internal/build/FetchScriptBuilderRegistry.java (+163 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.Collection;
14
import java.util.Collections;
15
import java.util.HashMap;
16
import java.util.Map;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.IRegistryChangeEvent;
21
import org.eclipse.core.runtime.IRegistryChangeListener;
22
import org.eclipse.core.runtime.Platform;
23
24
/**
25
 * A registry for acessing fetch script builders.
26
 */
27
public class FetchScriptBuilderRegistry implements IRegistryChangeListener {
28
29
    /** the extension point */
30
    public static final String EXT_FETCH_SCRIPT_BUILDER = "org.eclipse.pde.build.fetchScriptBuilder"; //$NON-NLS-1$
31
32
    /** attribute <code>id</code> */
33
    public static final String ATTR_ID = "id"; //$NON-NLS-1$
34
35
    /** attribute <code>class</code> */
36
    public static final String ATTR_CLASS = "class"; //$NON-NLS-1$
37
38
    /** element <code>builder</code> */
39
    public static final String ELEM_BUILDER = "builder"; //$NON-NLS-1$
40
41
    /** the shared instance */
42
    private static FetchScriptBuilderRegistry instance;
43
44
    /**
45
     * Returns the singleton registry instance.
46
     * 
47
     * @return the registry instance
48
     */
49
    public static FetchScriptBuilderRegistry getRegistry() {
50
        if (null == instance) {
51
            createRegistry();
52
        }
53
        return instance;
54
    }
55
56
    /**
57
     * Creates the singleton registry instance.
58
     */
59
    private static synchronized void createRegistry() {
60
61
        if (null != instance) return;
62
63
        instance = new FetchScriptBuilderRegistry();
64
        Platform.getExtensionRegistry().addRegistryChangeListener(instance,
65
                "org.eclipse.pde.build"); //$NON-NLS-1$
66
    }
67
68
    /**
69
     * Shuts down the registry.
70
     */
71
    static void shutdown() {
72
        if (null != instance) {
73
            Platform.getExtensionRegistry().removeRegistryChangeListener(
74
                    instance);
75
        }
76
    }
77
78
    /** a map of registered builders */
79
    private Map builders;
80
81
    /**
82
     * Hidden constructor.
83
     */
84
    private FetchScriptBuilderRegistry() {
85
        // hidden constructor
86
    }
87
88
    /*
89
     * (non-Javadoc)
90
     * 
91
     * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
92
     */
93
    public void registryChanged(IRegistryChangeEvent event) {
94
95
        // reset list of known builders
96
        if (null != builders) builders = null;
97
    }
98
99
    /**
100
     * Returns a collection of registered builder ids.
101
     * 
102
     * @return a collection of registered builder ids
103
     */
104
    public Collection getBuilderIds() {
105
106
        // ensure initialized
107
        initializeRegistry();
108
109
        return null != builders ? builders.keySet() : Collections.EMPTY_SET;
110
    }
111
112
    /**
113
     * Initializes the registry
114
     */
115
    private void initializeRegistry() {
116
        
117
        // don't initialize twice
118
        if (null != builders) return;
119
        
120
        synchronized (builders = new HashMap()) {
121
            IConfigurationElement[] extensions = Platform
122
                    .getExtensionRegistry().getConfigurationElementsFor(
123
                            EXT_FETCH_SCRIPT_BUILDER);
124
            for (int i = 0; i < extensions.length; i++) {
125
                IConfigurationElement extension = extensions[i];
126
                if(ELEM_BUILDER.equals(extension.getName())) {
127
                    String id = extension.getAttribute(ATTR_ID);
128
                    if (null != id && id.trim().length() > 0) {
129
                        builders.put(id, extension);
130
                    }
131
                }
132
            }
133
        }
134
    }
135
136
    /**
137
     * Returns the builder instance with the specified id.
138
     * <p>
139
     * The instance is not cached. Each time this method is called, a new
140
     * instance is created.
141
     * </p>
142
     * 
143
     * @param id
144
     * @return the builder instance (maybe <code>null</code>)
145
     */
146
    public IFetchScriptBuilder getBuilder(String id) {
147
148
        // ensure initialized
149
        initializeRegistry();
150
151
        IConfigurationElement extension = (IConfigurationElement) builders
152
                .get(id);
153
        if (null != extension) {
154
            try {
155
                return (IFetchScriptBuilder) extension
156
                        .createExecutableExtension(ATTR_CLASS);
157
            } catch (CoreException e) {
158
                BundleHelper.getDefault().getLog().log(e.getStatus());
159
            }
160
        }
161
        return null;
162
    }
163
}
(-)src/org/eclipse/pde/internal/build/IFetchScriptBuilder.java (+150 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.Map;
14
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.pde.internal.build.ant.ITask;
17
18
/**
19
 * A <code>IFetchScriptBuilder</code> constructs a repository specific. fetch
20
 * script.
21
 * 
22
 * <p>
23
 * It is registered via the
24
 * <code>org.eclipse.pde.build.fetchScriptBuilder</code> extension point.
25
 * </p>
26
 * <p>
27
 * <strong>EXPERIMENTAL</strong> This API is subject to change.
28
 * </p>
29
 */
30
public interface IFetchScriptBuilder {
31
32
    /**
33
     * Generates a task that is necessary for authentificate against the
34
     * repository.
35
     * 
36
     * @param element
37
     *            the element name
38
     * @param type
39
     *            the element type
40
     * @param entryInfos
41
     *            the map with detailed information collected in
42
     *            {@link #processMapFileEntry(String, String, String[], String, Map)}
43
     * @return the authentification task (maybe <code>null</code> if not
44
     *         necessary)
45
     */
46
    ITask generateAuthentificationTask(String element, String type,
47
            Map entryInfos);
48
49
    /**
50
     * Generates a properties for fetching the specified element via the fetch
51
     * task.
52
     * 
53
     * @param element
54
     *            the element name
55
     * @param type
56
     *            the element type
57
     * @param entryInfos
58
     *            the map with detailed information collected in
59
     *            {@link #processMapFileEntry(String, String, String[], String, Map)}
60
     * @param destination
61
     *            the destination where the files should be fetched to
62
     * @param xmlFileOnly
63
     *            if <code>true</code> only the element's XML descriptor
64
     *            should be fetched, otherwise the complete element must be
65
     *            fetched
66
     * @return the map with properties (must be <code>String</code> keys and
67
     *         <code>String</code> values)
68
     * @throws CoreException
69
     */
70
    Map generatePropertiesForFetchTask(String element, String type,
71
            Map entryInfos, String destination, boolean xmlFileOnly)
72
            throws CoreException;
73
74
    /**
75
     * Generates a task for retrieving the specified files only.
76
     * 
77
     * @param element
78
     *            the element name
79
     * @param type
80
     *            the element type
81
     * @param entryInfos
82
     *            the map with detailed information collected in
83
     *            {@link #processMapFileEntry(String, String, String[], String, Map)}
84
     * @param destination
85
     *            the destination where the files should be fetched to
86
     * @param files
87
     *            the list of files to fetch
88
     * @return the task for fetching the files
89
     */
90
    ITask generateRetrieveFilesTask(String element, String type,
91
            Map entryInfos, String destination, String[] files);
92
93
    /**
94
     * Returns the common task that is used to fetch elements specified via Ant
95
     * properties.
96
     * <p>
97
     * This task is called from within the element specific generated fetch
98
     * tasks to fetch an elements.
99
     * </p>
100
     * 
101
     * @return the common fetch task
102
     * @see #generatePropertiesForFetchTask(String, String, Map, boolean)
103
     */
104
    ITask getFetchTask();
105
106
    /**
107
     * Returns a version identifyer (eg. TAG name) of the element that will be
108
     * fetched.
109
     * 
110
     * @param element
111
     *            the element name
112
     * @param type
113
     *            the element type
114
     * @param entryInfos
115
     *            the map with detailed information collected in
116
     *            {@link #processMapFileEntry(String, String, String[], String, Map)}
117
     * @return a version identifyer
118
     */
119
    String getVersionToFetch(String element, String type, Map entryInfos);
120
121
    /**
122
     * Processes the specified element with the specified type.
123
     * <p>
124
     * The arguments specified in the map file are provided. The map with entry
125
     * infos should be filled with provider specific information that is
126
     * required in later processing to sucessfully generate the fetch script.
127
     * </p>
128
     * 
129
     * @param element
130
     *            the element name (eg. <code>com.my.plugin</code>) (may not
131
     *            be <code>null</code>)
132
     * @param type
133
     *            the element type (one of <code>feature</code>,
134
     *            <code>plugin</code> or <code>fragment</code>) (may not be
135
     *            <code>null</code>)
136
     * @param arguments
137
     *            the arguments specified in the build script (may not be
138
     *            <code>null</code>)
139
     * @param fetchTag
140
     *            the fetch tag that will overwrite all tags specified in the
141
     *            repository if set (maybe <code>null</code> or empty)
142
     * @param entryInfos
143
     *            the map to store repository specific information (may not be
144
     *            <code>null</code>)
145
     * @throws CoreException
146
     *             if the arguments are invalid
147
     */
148
    void processMapFileEntry(String element, String type, String[] arguments,
149
            String fetchTag, Map entryInfos) throws CoreException;
150
}
(-)src/org/eclipse/pde/internal/build/PATHFetchScriptBuilder.java (+203 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.pde.internal.build.ant.AntScript;
22
import org.eclipse.pde.internal.build.ant.FileSet;
23
import org.eclipse.pde.internal.build.ant.ITask;
24
25
/**
26
 * An <code>IFetchScriptBuilder</code> that fetches features and plugins from
27
 * a specific path (id: <code>PATH</code>).
28
 * <p>
29
 * Map file arguments: <code>&lt;ROOT&gt;[,&lt;PATH&gt;]</code>
30
 * <dl>
31
 * <dt>ROOT</dt>
32
 * <dd>The ROOT (eg. <code>/source/eclipse</code>) is used as root path to
33
 * determine the location and the specific version to fetch. It can be
34
 * overwritten via the <code>fetchTag</code> to fetch another version from
35
 * another location (for nightly builds for example).</dd>
36
 * </dl>
37
 * <dt>PATH</dt>
38
 * <dd>A custom path withing the ROOT (eg.
39
 * <code>org.eclipse.sdk-feature/features/org.eclipse.rcp</code>) to retrive
40
 * the element from if it is not within the root. If this is not provided the
41
 * default path will be used which simply maps to the element name.</dd>
42
 * </dl>
43
 * </p>
44
 */
45
public class PATHFetchScriptBuilder implements IFetchScriptBuilder,
46
        IPDEBuildConstants {
47
48
    public static final String ID = "PATH"; //$NON-NLS-1$
49
50
    private static final String PATH = "path"; //$NON-NLS-1$
51
52
    private static final String ROOT = "root"; //$NON-NLS-1$
53
54
    private static final ITask GET_FROM_PATH_TASK = new ITask() {
55
56
        /*
57
         * (non-Javadoc)
58
         * 
59
         * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
60
         */
61
        public void print(AntScript script) {
62
            FileSet dir = new FileSet(
63
                    "${sourcePath}",null,null,null,null,null,null); //$NON-NLS-1$
64
            script.printCopyTask(
65
                    null, "${destination}", new FileSet[] {dir}, false); //$NON-NLS-1$ 
66
        }
67
    };
68
69
    /*
70
     * (non-Javadoc)
71
     * 
72
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateAuthentificationTask(java.lang.String,
73
     *      java.lang.String, java.util.Map)
74
     */
75
    public ITask generateAuthentificationTask(String element, String type,
76
            Map entryInfos) {
77
        // not necessary
78
        return null;
79
    }
80
81
    /*
82
     * (non-Javadoc)
83
     * 
84
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generatePropertiesForFetchTask(java.lang.String,
85
     *      java.lang.String, java.util.Map, java.lang.String, boolean)
86
     */
87
    public Map generatePropertiesForFetchTask(String element, String type,
88
            Map entryInfos, String destination, boolean xmlFileOnly)
89
            throws CoreException {
90
        Map params = new HashMap(2);
91
92
        // we directly export the CVS content into the destination
93
        params.put("destination", destination); //$NON-NLS-1$
94
        params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
95
96
        String root = (String) entryInfos.get(ROOT);
97
        String path = (String) entryInfos.get(PATH);
98
        IPath sourcePath = new Path(root);
99
        if (path != null) {
100
            sourcePath = sourcePath.append(path);
101
        } else {
102
            sourcePath = sourcePath.append(element);
103
        }
104
105
        if (xmlFileOnly) {
106
            if (type.equals("feature")) { //$NON-NLS-1$
107
                sourcePath.append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
108
            } else if (type.equals("plugin")) { //$NON-NLS-1$
109
                sourcePath.append(DEFAULT_PLUGIN_FILENAME_DESCRIPTOR);
110
            } else if (type.equals("fragment")) { //$NON-NLS-1$
111
                sourcePath.append(DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR);
112
            }
113
        }
114
        params.put("sourcePath", sourcePath.toString()); //$NON-NLS-1$
115
116
        return params;
117
    }
118
119
    /*
120
     * (non-Javadoc)
121
     * 
122
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateRetrieveFilesTask(java.lang.String,
123
     *      java.lang.String, java.util.Map, java.lang.String,
124
     *      java.lang.String[])
125
     */
126
    public ITask generateRetrieveFilesTask(final String element,
127
            final String type, final Map entryInfos, final String destination,
128
            final String[] files) {
129
130
        return new ITask() {
131
132
            /*
133
             * (non-Javadoc)
134
             * 
135
             * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
136
             */
137
            public void print(AntScript script) {
138
                String root = (String) entryInfos.get(ROOT);
139
                String path = (String) entryInfos.get(PATH);
140
141
                for (int i = 0; i < files.length; i++) {
142
                    String file = files[i];
143
                    IPath filePath = new Path(root);
144
                    if (path != null) {
145
                        filePath = filePath.append(path).append(file);
146
                    } else {
147
                        filePath = filePath.append(element).append(file);
148
                    }
149
150
                    script.printCopyTask(filePath.toString(), destination,
151
                            null, false);
152
                }
153
            }
154
        };
155
    }
156
157
    /*
158
     * (non-Javadoc)
159
     * 
160
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getFetchTask()
161
     */
162
    public ITask getFetchTask() {
163
        return GET_FROM_PATH_TASK;
164
    }
165
166
    /*
167
     * (non-Javadoc)
168
     * 
169
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getVersionToFetch(java.lang.String,
170
     *      java.lang.String, java.util.Map)
171
     */
172
    public String getVersionToFetch(String element, String type, Map entryInfos) {
173
        return (String) entryInfos.get(ROOT);
174
    }
175
176
    /*
177
     * (non-Javadoc)
178
     * 
179
     * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#processMapFileEntry(java.lang.String,
180
     *      java.lang.String, java.lang.String[], java.lang.String,
181
     *      java.util.Map)
182
     */
183
    public void processMapFileEntry(String element, String type,
184
            String[] arguments, String fetchTag, Map entryInfos)
185
            throws CoreException {
186
187
        if (arguments.length < 1) {
188
            String message = Policy.bind(
189
                    "error.incorrectDirectoryEntry", element); //$NON-NLS-1$
190
            throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD,
191
                    EXCEPTION_ENTRY_MISSING, message, null));
192
        }
193
194
        entryInfos
195
                .put(
196
                        ROOT,
197
                        (null == fetchTag || fetchTag.trim().length() == 0) ? arguments[0]
198
                                : fetchTag);
199
        entryInfos.put(PATH, (arguments.length > 1 && arguments[1].trim()
200
                .length() > 0) ? arguments[1] : null);
201
    }
202
203
}

Return to bug 34757