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 / +6 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
(-)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
fetchScriptBuilders.name = Fetch Script Builders
(-)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="fetchScriptBuilders" name="%fetchScriptBuilders.name" schema="schema/fetchScriptBuilders.exsd"/>
4
<!-- Tasks -->
5
<!-- Tasks -->
5
   <extension
6
   <extension
6
         point="org.eclipse.ant.core.antTasks">
7
         point="org.eclipse.ant.core.antTasks">
Lines 86-89 Link Here
86
      </application>
87
      </application>
87
   </extension>
88
   </extension>
88
89
90
   <extension
91
         point="org.eclipse.pde.build.fetchScriptBuilders">
92
      <builder
93
            class="org.eclipse.pde.internal.build.fetch.COPYFetchScriptBuilder"
94
            id="COPY"/>
95
      <builder
96
            class="org.eclipse.pde.internal.build.fetch.CVSFetchScriptBuilder"
97
            id="CVS"/>
98
   </extension>
99
89
</plugin>
100
</plugin>
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 10-16 Link Here
10
 org.eclipse.update.core,
10
 org.eclipse.update.core,
11
 org.apache.ant,
11
 org.apache.ant,
12
 org.eclipse.core.runtime.compatibility;optional=true
12
 org.eclipse.core.runtime.compatibility;optional=true
13
Provide-Package: org.eclipse.pde.internal.build;x-friends:="org.eclipse.pde.ui",
13
Provide-Package: org.eclipse.pde.build,
14
 org.eclipse.pde.internal.build;x-friends:="org.eclipse.pde.ui",
14
 org.eclipse.pde.internal.build.ant;x-friends:="org.eclipse.pde.ui",
15
 org.eclipse.pde.internal.build.ant;x-friends:="org.eclipse.pde.ui",
15
 org.eclipse.pde.internal.build.builder;x-friends:="org.eclipse.pde.ui",
16
 org.eclipse.pde.internal.build.builder;x-friends:="org.eclipse.pde.ui",
16
 org.eclipse.pde.internal.build.packager;x-friends:="org.eclipse.pde.ui",
17
 org.eclipse.pde.internal.build.packager;x-friends:="org.eclipse.pde.ui",
(-)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
        FetchScriptBuildersRegistry.shutdown();
23
	}
24
	}
24
}
25
}
(-)src/org/eclipse/pde/internal/build/FetchScriptGenerator.java (-80 / +130 lines)
Lines 10-22 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.osgi.util.NLS;
33
import org.eclipse.osgi.util.NLS;
34
import org.eclipse.pde.build.IFetchScriptBuilder;
18
import org.eclipse.pde.internal.build.ant.AntScript;
35
import org.eclipse.pde.internal.build.ant.AntScript;
19
import org.eclipse.update.core.*;
36
import org.eclipse.pde.internal.build.ant.ITask;
37
import org.eclipse.pde.internal.build.fetch.CVSFetchScriptBuilder;
38
import org.eclipse.update.core.Feature;
39
import org.eclipse.update.core.IFeature;
40
import org.eclipse.update.core.IIncludedFeatureReference;
41
import org.eclipse.update.core.IPluginEntry;
20
import org.eclipse.update.internal.core.FeatureExecutableFactory;
42
import org.eclipse.update.internal.core.FeatureExecutableFactory;
21
43
22
/**
44
/**
Lines 24-39 Link Here
24
 * to retrieve plug-ins and features from the CVS repository.
46
 * to retrieve plug-ins and features from the CVS repository.
25
 */
47
 */
26
public class FetchScriptGenerator extends AbstractScriptGenerator {
48
public class FetchScriptGenerator extends AbstractScriptGenerator {
27
	private static final String BUNDLE = "bundle"; //$NON-NLS-1$
49
	private static final String BUNDLE = IFetchScriptBuilder.ELEMENT_TYPE_BUNDLE;
28
	private static final String FRAGMENT = "fragment"; //$NON-NLS-1$
50
	private static final String FRAGMENT = IFetchScriptBuilder.ELEMENT_TYPE_FRAGMENT;
29
	private static final String PLUGIN = "plugin"; //$NON-NLS-1$
51
	private static final String PLUGIN = IFetchScriptBuilder.ELEMENT_TYPE_PLUGIN;
30
	private static final String FEATURE = "feature"; //$NON-NLS-1$
52
	private static final String FEATURE = IFetchScriptBuilder.ELEMENT_TYPE_FEATURE;
31
	private static final String ELEMENT = "element"; //$NON-NLS-1$
53
	private static final String ELEMENT = "element"; //$NON-NLS-1$
32
	private static final String TYPE = "type"; //$NON-NLS-1$
54
	private static final String TYPE = "type"; //$NON-NLS-1$
33
	private static final String PATH = "path"; //$NON-NLS-1$
55
    private static final String BUILDER = "builder"; //$NON-NLS-1$
34
	private static final String PASSWORD = "password"; //$NON-NLS-1$
35
	private static final String CVSROOT = "cvsRoot"; //$NON-NLS-1$
36
	private static final String TAG = "tag"; //$NON-NLS-1$
37
56
38
	// flag saying if we want to recursively generate the scripts	
57
	// flag saying if we want to recursively generate the scripts	
39
	protected boolean recursiveGeneration = true;
58
	protected boolean recursiveGeneration = true;
Lines 173-179 Link Here
173
			generateFetchPluginsTarget();
192
			generateFetchPluginsTarget();
174
			generateFetchRecusivelyTarget();
193
			generateFetchRecusivelyTarget();
175
		}
194
		}
176
		generateGetFromCVSTarget();
195
		generateGetFromRepositoryTarget();
177
		generateEpilogue();
196
		generateEpilogue();
178
	}
197
	}
179
198
Lines 204-210 Link Here
204
223
205
	protected void generateFetchPluginsTarget() throws CoreException {
224
	protected void generateFetchPluginsTarget() throws CoreException {
206
		script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null);
225
		script.printTargetDeclaration(TARGET_FETCH_PLUGINS, null, FEATURE_AND_PLUGINS, null, null);
207
		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$
226
		retrieveFeature((String) mapInfos.get(ELEMENT), (String) mapInfos.get(TYPE), mapInfos);
208
		generateChildrenFetchScript();
227
		generateChildrenFetchScript();
209
		script.printTargetEnd();
228
		script.printTargetEnd();
210
	}
229
	}
Lines 219-246 Link Here
219
	private Map processMapFileEntry(String entry) throws CoreException {
238
	private Map processMapFileEntry(String entry) throws CoreException {
220
		Map entryInfos = new HashMap(5);
239
		Map entryInfos = new HashMap(5);
221
240
222
		String cvsInfo = getCVSInfo(entry);
241
        // extract type and element from entry
223
		if (cvsInfo == null) {
242
        int index = entry.indexOf('@'); //$NON-NLS-1$
243
        String type =  entry.substring(0, index);
244
        String currentElement = entry.substring(index + 1);
245
246
        // read and validate the repository info
247
		String repositoryInfo = getRepositoryInfo(entry);
248
		if (repositoryInfo == null) {
224
			String message = NLS.bind(Messages.error_missingDirectoryEntry, entry);
249
			String message = NLS.bind(Messages.error_missingDirectoryEntry, entry);
225
			BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
250
			BundleHelper.getDefault().getLog().log(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
226
			return null;
251
			return null;
227
		}
252
		}
228
253
229
		String[] cvsFields = Utils.getArrayFromStringWithBlank(cvsInfo, ","); //$NON-NLS-1$
254
        // collect and validate the repository info
230
		if (cvsFields.length < 2) {
255
		String[] repositoryFields = Utils.getArrayFromStringWithBlank(repositoryInfo, ","); //$NON-NLS-1$
231
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, element);
256
		if (repositoryFields.length < 2) {
257
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, currentElement);
232
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
258
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
233
		}
259
		}
234
260
235
		entryInfos.put(TAG, fetchTag.length() == 0 ? cvsFields[0] : fetchTag); //$NON-NLS-1$
261
        // determine fetch script builder
236
		entryInfos.put(CVSROOT, cvsFields[1]); //$NON-NLS-1$
262
        IFetchScriptBuilder fetchScriptBuilder = null;
237
		entryInfos.put(PASSWORD, (cvsFields.length > 2 && !cvsFields[2].equals("")) ? cvsFields[2] : null); //$NON-NLS-1$ //$NON-NLS-2$
263
        String[] arguments = null;
238
264
        
239
		entryInfos.put(PATH, (cvsFields.length > 3 && !cvsFields[3].equals("")) ? cvsFields[3] : null); //$NON-NLS-1$ //$NON-NLS-2$
265
        // check if first repository field matches a builder id
240
266
        if(FetchScriptBuildersRegistry.getRegistry().getBuilderIds().contains(repositoryFields[0])) 
241
		int index = entry.indexOf('@'); //$NON-NLS-1$
267
        {
242
		entryInfos.put(TYPE, entry.substring(0, index)); //$NON-NLS-1$
268
            fetchScriptBuilder = FetchScriptBuildersRegistry.getRegistry().getBuilder(repositoryFields[0]);
243
		entryInfos.put(ELEMENT, entry.substring(index + 1)); //$NON-NLS-1$
269
            
270
            // construct arguments array for registered builder
271
            arguments = new String[repositoryFields.length-1];
272
            System.arraycopy(repositoryFields, 1, arguments, 0, repositoryFields.length-1);
273
        }
274
        
275
        // default to CVS builder (to be compatible)
276
        if( null == fetchScriptBuilder) 
277
        {
278
            // fall back to CVS
279
            fetchScriptBuilder = new CVSFetchScriptBuilder();
280
281
            // construct arguments array for CVS builder
282
            arguments = repositoryFields;
283
        }
284
        
285
        // add infos from registered builder
286
        fetchScriptBuilder.processMapFileEntry(currentElement, type, arguments, fetchTag, entryInfos);
287
288
        // store builder
289
        entryInfos.put(BUILDER, fetchScriptBuilder);
290
        
291
        // add general infos (will override builder specific infos)
292
		entryInfos.put(TYPE, type);
293
		entryInfos.put(ELEMENT, currentElement);
244
		return entryInfos;
294
		return entryInfos;
245
	}
295
	}
246
296
Lines 257-270 Link Here
257
				}
307
				}
258
				continue;
308
				continue;
259
			}
309
			}
260
			
310
261
			//Included features can be available in the baseLocation.
311
			//Included features can be available in the baseLocation.
262
			if (getCVSInfo(FEATURE + '@' + featureId) != null)
312
			if (getRepositoryInfo(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$
313
				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) {
314
			else if (getSite(false).findFeature(featureId, null, false) == null) {
265
				String message = NLS.bind(Messages.error_cannotFetchNorFindFeature, featureId);
315
				String message = NLS.bind(Messages.error_cannotFetchNorFindFeature, featureId);
266
				throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null));
316
				throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_FEATURE_MISSING, message, null));
267
			}
317
		}
268
		}
318
		}
269
		script.printTargetEnd();
319
		script.printTargetEnd();
270
	}
320
	}
Lines 277-333 Link Here
277
				return false;
327
				return false;
278
		}
328
		}
279
329
280
		String password = (String) mapFileEntry.get(PASSWORD);
330
        IFetchScriptBuilder builder = (IFetchScriptBuilder) mapFileEntry.get(BUILDER);
281
		if (password != null)
331
        String elementToFetch = (String) mapFileEntry.get(ELEMENT);
282
			script.printCVSPassTask((String) mapFileEntry.get(CVSROOT), password, cvsPassFileLocation); //$NON-NLS-1$
283
284
		String type = (String) mapFileEntry.get(TYPE);
332
		String type = (String) mapFileEntry.get(TYPE);
333
334
        // print authentification task if one is provided
335
        ITask authTask = builder.generateAuthentificationTask(elementToFetch,type,mapFileEntry);
336
        if(null != authTask) script.print(authTask);
337
        
338
        // the location
285
		String location = getElementLocation(type);
339
		String location = getElementLocation(type);
286
		Map params = new HashMap(5);
287
340
288
		//We directly export the CVS content into the correct directory 
341
        // the destination
289
		params.put("destination", mapFileEntry.get(ELEMENT)); //$NON-NLS-1$ //$NON-NLS-2$
342
        // we directly export the content into the correct directory 
290
		params.put(TAG, mapFileEntry.get(TAG)); //$NON-NLS-1$ //$NON-NLS-2$
343
        String destination = elementToFetch;
291
		params.put(CVSROOT, mapFileEntry.get(CVSROOT)); //$NON-NLS-1$ //$NON-NLS-2$
344
        
292
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
345
        // get params from builder
346
		Map params = new HashMap(builder.generatePropertiesForFetchTask(elementToFetch, type, mapFileEntry, destination, manifestFileOnly));
293
347
294
		String cvsPackage = ((String) mapFileEntry.get(PATH) == null ? (String) mapFileEntry.get(ELEMENT) : (String) mapFileEntry.get(PATH)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
295
		String fullLocation = null;
348
		String fullLocation = null;
296
		if (type.equals(FEATURE)) {
349
		if (type.equals(FEATURE)) {
297
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
350
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
298
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
351
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
299
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
352
			repositoryFeatureVersions.put(elementToFetch, builder.getVersionToFetch(elementToFetch,type,mapFileEntry));
300
			repositoryFeatureVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
301
		} else if (type.equals(PLUGIN)) {
353
		} else if (type.equals(PLUGIN)) {
302
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
354
			fullLocation = location + '/' + elementToFetch + '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
303
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
355
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
304
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
356
			repositoryPluginVersions.put(elementToFetch, builder.getVersionToFetch(elementToFetch,type,mapFileEntry));
305
			repositoryPluginVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
306
		} else if (type.equals(FRAGMENT)) {
357
		} else if (type.equals(FRAGMENT)) {
307
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
358
			fullLocation = location + '/' + elementToFetch + '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
308
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
359
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
309
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR : ""; //$NON-NLS-1$
360
			repositoryPluginVersions.put(elementToFetch, builder.getVersionToFetch(elementToFetch,type,mapFileEntry));
310
			repositoryPluginVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));
311
		} else if (type.equals(BUNDLE)) {
361
		} else if (type.equals(BUNDLE)) {
312
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR;
362
			fullLocation = location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR;
313
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
363
			params.put("fileToCheck", fullLocation); //$NON-NLS-1$
314
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR : "";//$NON-NLS-1$ 
364
			repositoryPluginVersions.put(elementToFetch, builder.getVersionToFetch(elementToFetch,type,mapFileEntry));
315
			repositoryPluginVersions.put(mapFileEntry.get(ELEMENT), mapFileEntry.get(TAG));			
316
		}
365
		}
317
		params.put("package", cvsPackage); //$NON-NLS-1$
318
366
319
		// This call create a new property for every feature, plugins or fragments that we must check the existence of 
367
		// This call create a new property for every feature, plugins or fragments that we must check the existence of 
320
		script.printAvailableTask(fullLocation, fullLocation);
368
		script.printAvailableTask(fullLocation, fullLocation);
321
		if (type.equals(PLUGIN) || type.equals(FRAGMENT)) {
369
		if (type.equals(PLUGIN) || type.equals(FRAGMENT)) {
322
			script.printAvailableTask(fullLocation, location + '/' + (String) mapFileEntry.get(ELEMENT) + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR);
370
			script.printAvailableTask(fullLocation, location + '/' + elementToFetch + '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR);
323
		}
371
		}
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$ //$NON-NLS-2$ //$NON-NLS-3$
372
		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$ //$NON-NLS-2$ //$NON-NLS-3$
325
		return true;
373
		return true;
326
	}
374
	}
327
375
328
	protected void generateGetFromCVSTarget() {
376
	protected void generateGetFromRepositoryTarget() {
329
		script.printTargetDeclaration(TARGET_GET_FROM_CVS, null, null, "${fileToCheck}", "{destination}"); //$NON-NLS-1$ //$NON-NLS-2$
377
		script.printTargetDeclaration(TARGET_FETCH_FROM_REPOSITORY, null, null, "${fileToCheck}", null); //$NON-NLS-1$
330
		script.printCVSTask("export -d ${destination} -r ${tag} ${package}", "${cvsRoot}", null, null, null, "${quiet}", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
378
        if(null != mapInfos) {
379
            IFetchScriptBuilder builder = (IFetchScriptBuilder) mapInfos.get(BUILDER);
380
            if(null != builder) {
381
                ITask getTask = builder.getFetchTask();
382
                if(null != getTask) {
383
                    script.print(getTask);
384
                }
385
            }
386
        }
331
		script.printTargetEnd();
387
		script.printTargetEnd();
332
	}
388
	}
333
389
Lines 379-390 Link Here
379
	 * constructor from Update.
435
	 * constructor from Update.
380
	 * 
436
	 * 
381
	 * @param elementName the feature to retrieve
437
	 * @param elementName the feature to retrieve
382
	 * @param cvsRoot the root in CVS
438
	 * @param elementType the element type
383
	 * @param tag the CVS tag
439
	 * @param elementInfos the element information
384
	 * @param password the CVS password
385
	 * @throws CoreException
440
	 * @throws CoreException
386
	 */
441
	 */
387
	protected void retrieveFeature(String elementName, String cvsRoot, String tag, String password, String path) throws CoreException {
442
	protected void retrieveFeature(String elementName, String elementType, Map elementInfos) throws CoreException {
388
		// Generate a temporary Ant script which retrieves the feature.xml for this
443
		// Generate a temporary Ant script which retrieves the feature.xml for this
389
		// feature from CVS
444
		// feature from CVS
390
		File root = new File(workingDirectory);
445
		File root = new File(workingDirectory);
Lines 395-415 Link Here
395
				retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
450
				retrieve.printProjectDeclaration("RetrieveFeature", "main", "."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
396
				retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null); //$NON-NLS-1$
451
				retrieve.printTargetDeclaration(TARGET_MAIN, null, null, null, null); //$NON-NLS-1$
397
452
398
				IPath moduleFeatureFile;
453
                String destination = elementName;
399
				IPath moduleFeatureProperties;
454
                String[] files = new String[] {DEFAULT_FEATURE_FILENAME_DESCRIPTOR, PROPERTIES_FILE};
400
				if (path != null) {
455
                IFetchScriptBuilder builder = (IFetchScriptBuilder) elementInfos.get(BUILDER);
401
					moduleFeatureFile = new Path(path).append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
456
                ITask retrieveFeatureTask = builder.generateRetrieveFilesTask(elementName, elementType, elementInfos, destination, files);
402
					moduleFeatureProperties = new Path(path).append(PROPERTIES_FILE);
457
                if(null == retrieveFeatureTask) {
403
				} else {
458
                    String message = NLS.bind(Messages.error_noRetrieveFeatureTask, elementName); //$NON-NLS-1$
404
					moduleFeatureFile = new Path(elementName).append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
459
                    throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
405
					moduleFeatureProperties = new Path(elementName).append(PROPERTIES_FILE);
406
				}
460
				}
407
461
                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
462
414
				retrieve.printTargetEnd();
463
				retrieve.printTargetEnd();
415
				retrieve.printProjectEnd();
464
				retrieve.printProjectEnd();
Lines 427-440 Link Here
427
			AntRunner runner = new AntRunner();
476
			AntRunner runner = new AntRunner();
428
			runner.setBuildFileLocation(target.getAbsolutePath());
477
			runner.setBuildFileLocation(target.getAbsolutePath());
429
			runner.run();
478
			runner.run();
479
            String destination = elementName;
430
			FeatureExecutableFactory factory = new FeatureExecutableFactory();
480
			FeatureExecutableFactory factory = new FeatureExecutableFactory();
431
			File featureFolder = new File(root, (path == null ? elementName : path));
481
			File featureFolder = new File(root, destination);
432
			feature = (Feature) factory.createFeature(featureFolder.toURL(), null, null);
482
			feature = (Feature) factory.createFeature(featureFolder.toURL(), null, null);
433
483
434
			//We only delete here, so if an exception is thrown the user can still see the retrieve.xml 
484
			//We only delete here, so if an exception is thrown the user can still see the retrieve.xml 
435
			target.delete();
485
			target.delete();
436
			featureProperties = new Properties();
486
			featureProperties = new Properties();
437
			InputStream featureStream = new FileInputStream(new File(root, (path == null ? elementName : path) + '/' + PROPERTIES_FILE));
487
			InputStream featureStream = new FileInputStream(new File(root, destination + '/' + PROPERTIES_FILE));
438
			featureProperties.load(featureStream);
488
			featureProperties.load(featureStream);
439
			featureStream.close();
489
			featureStream.close();
440
			clear(featureFolder);
490
			clear(featureFolder);
Lines 484-490 Link Here
484
	 */
534
	 */
485
	protected String getElementLocation(String type) {
535
	protected String getElementLocation(String type) {
486
		IPath location = new Path(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY));
536
		IPath location = new Path(Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY));
487
		if (type.equals(FEATURE)) //$NON-NLS-1$
537
		if (type.equals(FEATURE)) 
488
			location = location.append(DEFAULT_FEATURE_LOCATION);
538
			location = location.append(DEFAULT_FEATURE_LOCATION);
489
		else
539
		else
490
			location = location.append(DEFAULT_PLUGIN_LOCATION);
540
			location = location.append(DEFAULT_PLUGIN_LOCATION);
Lines 498-504 Link Here
498
	 * @return String
548
	 * @return String
499
	 * @throws CoreException
549
	 * @throws CoreException
500
	 */
550
	 */
501
	protected String getCVSInfo(String elementName) throws CoreException {
551
	protected String getRepositoryInfo(String elementName) throws CoreException {
502
		if (directory == null)
552
		if (directory == null)
503
			directory = readProperties(directoryLocation, "", IStatus.ERROR); //$NON-NLS-1$
553
			directory = readProperties(directoryLocation, "", IStatus.ERROR); //$NON-NLS-1$
504
		return directory.getProperty(elementName);
554
		return directory.getProperty(elementName);
(-)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/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}.
(-)templates/customTargets.xml (-3 / +3 lines)
Lines 6-13 Link Here
6
	<!-- ===================================================================== -->
6
	<!-- ===================================================================== -->
7
	<target name="allElements">
7
	<target name="allElements">
8
		<ant antfile="${genericTargets}" target="${target}">
8
		<ant antfile="${genericTargets}" target="${target}">
9
		<property name="type" value="<feature | plugin | fragment>" />
9
		<property name="type" value="'feature | plugin | fragment'" />
10
		<property name="id" value="<element.id>" />
10
		<property name="id" value="'element.id'" />
11
		</ant>
11
		</ant>
12
	</target>
12
	</target>
13
13
Lines 18-24 Link Here
18
	<!-- Add one target for each root element and each configuration -->
18
	<!-- Add one target for each root element and each configuration -->
19
	<!-- ===================================================================== -->
19
	<!-- ===================================================================== -->
20
20
21
	<target name="assemble.<element.id>[.config.spec]">
21
	<target name="assemble.'element.id[.config.spec]'">
22
		<ant antfile="${assembleScriptName}" dir="${buildDirectory}"/>
22
		<ant antfile="${assembleScriptName}" dir="${buildDirectory}"/>
23
	</target>
23
	</target>
24
24
(-)schema/fetchScriptBuilders.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="fetchScriptBuilders" 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.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.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/build/IFetchScriptBuilder.java (+183 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2005 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
 * $Id$
8
 *
9
 * Contributors:
10
 *     Gunnar Wagenknecht - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.pde.build;
13
14
import java.util.Map;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.pde.internal.build.ant.ITask;
18
19
/**
20
 * A <code>IFetchScriptBuilder</code> constructs a repository specific fetch
21
 * script for the PDE build process.
22
 * <p>
23
 * It is registered via the
24
 * <code>org.eclipse.pde.build.fetchScriptBuilder</code> extension point.
25
 * </p>
26
 */
27
public interface IFetchScriptBuilder {
28
29
	/** element type <code>bundle</code> */
30
	String ELEMENT_TYPE_BUNDLE = "bundle"; //$NON-NLS-1$
31
32
	/** element type <code>feature</code> */
33
	String ELEMENT_TYPE_FEATURE = "feature"; //$NON-NLS-1$
34
35
	/** element type <code>fragment</code> */
36
	String ELEMENT_TYPE_FRAGMENT = "fragment"; //$NON-NLS-1$
37
38
	/** element type <code>plugin</code> */
39
	String ELEMENT_TYPE_PLUGIN = "plugin"; //$NON-NLS-1$
40
41
	/**
42
	 * Generates a task that is necessary for authentificate against the
43
	 * repository.
44
	 * 
45
	 * @param element
46
	 *            the element name
47
	 * @param type
48
	 *            the element type (one of
49
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
50
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
51
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
52
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
53
	 *            <code>null</code>)
54
	 * @param entryInfos
55
	 *            the map with detailed information collected in
56
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)}
57
	 * @return the authentification task (maybe <code>null</code> if not
58
	 *         necessary)
59
	 */
60
	ITask generateAuthentificationTask(String element, String type,
61
			Map entryInfos);
62
63
	/**
64
	 * Generates a properties for fetching the specified element via the fetch
65
	 * task.
66
	 * 
67
	 * @param element
68
	 *            the element name
69
	 * @param type
70
	 *            the element type (one of
71
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
72
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
73
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
74
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
75
	 *            <code>null</code>)
76
	 * @param entryInfos
77
	 *            the map with detailed information collected in
78
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)}
79
	 * @param destination
80
	 *            the destination where the files should be fetched to
81
	 * @param xmlFileOnly
82
	 *            if <code>true</code> only the element's XML descriptor
83
	 *            should be fetched, otherwise the complete element must be
84
	 *            fetched
85
	 * @return the map with properties (must be <code>String</code> keys and
86
	 *         <code>String</code> values)
87
	 * @throws CoreException
88
	 */
89
	Map generatePropertiesForFetchTask(String element, String type,
90
			Map entryInfos, String destination, boolean xmlFileOnly)
91
			throws CoreException;
92
93
	/**
94
	 * Generates a task for retrieving the specified files only.
95
	 * 
96
	 * @param element
97
	 *            the element name
98
	 * @param type
99
	 *            the element type (one of
100
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
101
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
102
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
103
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
104
	 *            <code>null</code>)
105
	 * @param entryInfos
106
	 *            the map with detailed information collected in
107
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)}
108
	 * @param destination
109
	 *            the destination where the files should be fetched to
110
	 * @param files
111
	 *            the list of files to fetch
112
	 * @return the task for fetching the files
113
	 */
114
	ITask generateRetrieveFilesTask(String element, String type,
115
			Map entryInfos, String destination, String[] files);
116
117
	/**
118
	 * Returns the common task that is used to fetch elements specified via Ant
119
	 * properties.
120
	 * <p>
121
	 * This task is called from within the element specific generated fetch
122
	 * tasks to fetch an elements.
123
	 * </p>
124
	 * 
125
	 * @return the common fetch task
126
	 * @see #generatePropertiesForFetchTask(String, String, Map, String,
127
	 *      boolean)
128
	 */
129
	ITask getFetchTask();
130
131
	/**
132
	 * Returns a version identifyer (eg. TAG name) of the element that will be
133
	 * fetched.
134
	 * 
135
	 * @param element
136
	 *            the element name
137
	 * @param type
138
	 *            the element type (one of
139
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
140
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
141
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
142
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
143
	 *            <code>null</code>)
144
	 * @param entryInfos
145
	 *            the map with detailed information collected in
146
	 *            {@link #processMapFileEntry(String, String, String[], String, Map)}
147
	 * @return a version identifyer
148
	 */
149
	String getVersionToFetch(String element, String type, Map entryInfos);
150
151
	/**
152
	 * Processes the specified element with the specified type.
153
	 * <p>
154
	 * The arguments specified in the map file are provided. The map with entry
155
	 * infos should be filled with provider specific information that is
156
	 * required in later processing to sucessfully generate the fetch script.
157
	 * </p>
158
	 * 
159
	 * @param element
160
	 *            the element name (eg. <code>com.my.plugin</code>) (may not
161
	 *            be <code>null</code>)
162
	 * @param type
163
	 *            the element type (one of
164
	 *            {@link #ELEMENT_TYPE_FEATURE <code>feature</code>},
165
	 *            {@link #ELEMENT_TYPE_PLUGIN <code>plugin</code>},
166
	 *            {@link #ELEMENT_TYPE_FRAGMENT <code>fragment</code>} or
167
	 *            {@link #ELEMENT_TYPE_BUNDLE <code>bundle</code>}) (may not be
168
	 *            <code>null</code>)
169
	 * @param arguments
170
	 *            the arguments specified in the build script (may not be
171
	 *            <code>null</code>)
172
	 * @param fetchTag
173
	 *            the fetch tag that will overwrite all tags specified in the
174
	 *            repository if set (maybe <code>null</code> or empty)
175
	 * @param entryInfos
176
	 *            the map to store repository specific information (may not be
177
	 *            <code>null</code>)
178
	 * @throws CoreException
179
	 *             if the arguments are invalid
180
	 */
181
	void processMapFileEntry(String element, String type, String[] arguments,
182
			String fetchTag, Map entryInfos) throws CoreException;
183
}
(-)src/org/eclipse/pde/internal/build/FetchScriptBuildersRegistry.java (+165 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2005 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
 * $Id$
8
 *
9
 * Contributors:
10
 *     Gunnar Wagenknecht - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.pde.internal.build;
13
14
import java.util.Collection;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IRegistryChangeEvent;
22
import org.eclipse.core.runtime.IRegistryChangeListener;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.pde.build.IFetchScriptBuilder;
25
26
/**
27
 * A registry for acessing fetch script builders.
28
 */
29
public class FetchScriptBuildersRegistry implements IRegistryChangeListener {
30
31
    /** the extension point */
32
	private static final String EXT_FETCH_SCRIPT_BUILDERS = "org.eclipse.pde.build.fetchScriptBuilders"; //$NON-NLS-1$
33
34
    /** attribute <code>id</code> */
35
    private static final String ATTR_ID = "id"; //$NON-NLS-1$
36
37
    /** attribute <code>class</code> */
38
    private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
39
40
    /** element <code>builder</code> */
41
    private static final String ELEM_BUILDER = "builder"; //$NON-NLS-1$
42
43
    /** the shared instance */
44
    private static FetchScriptBuildersRegistry instance;
45
46
    /**
47
     * Returns the singleton registry instance.
48
     * 
49
     * @return the registry instance
50
     */
51
    public static FetchScriptBuildersRegistry getRegistry() {
52
        if (null == instance) {
53
            createRegistry();
54
        }
55
        return instance;
56
    }
57
58
    /**
59
     * Creates the singleton registry instance.
60
     */
61
    private static synchronized void createRegistry() {
62
63
        if (null != instance) return;
64
65
        instance = new FetchScriptBuildersRegistry();
66
        Platform.getExtensionRegistry().addRegistryChangeListener(instance,
67
                "org.eclipse.pde.build"); //$NON-NLS-1$
68
    }
69
70
    /**
71
     * Shuts down the registry.
72
     */
73
    static void shutdown() {
74
        if (null != instance) {
75
            Platform.getExtensionRegistry().removeRegistryChangeListener(
76
                    instance);
77
        }
78
    }
79
80
    /** a map of registered builders */
81
    private Map builders;
82
83
    /**
84
     * Hidden constructor.
85
     */
86
    private FetchScriptBuildersRegistry() {
87
        // hidden constructor
88
    }
89
90
    /*
91
     * (non-Javadoc)
92
     * 
93
     * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
94
     */
95
    public void registryChanged(IRegistryChangeEvent event) {
96
97
        // reset list of known builders
98
        if (null != builders) builders = null;
99
    }
100
101
    /**
102
     * Returns a collection of registered builder ids.
103
     * 
104
     * @return a collection of registered builder ids
105
     */
106
    public Collection getBuilderIds() {
107
108
        // ensure initialized
109
        initializeRegistry();
110
111
        return null != builders ? builders.keySet() : Collections.EMPTY_SET;
112
    }
113
114
    /**
115
     * Initializes the registry
116
     */
117
    private void initializeRegistry() {
118
        
119
        // don't initialize twice
120
        if (null != builders) return;
121
        
122
        synchronized (builders = new HashMap()) {
123
            IConfigurationElement[] extensions = Platform
124
                    .getExtensionRegistry().getConfigurationElementsFor(
125
                            EXT_FETCH_SCRIPT_BUILDERS);
126
            for (int i = 0; i < extensions.length; i++) {
127
                IConfigurationElement extension = extensions[i];
128
                if(ELEM_BUILDER.equals(extension.getName())) {
129
                    String id = extension.getAttribute(ATTR_ID);
130
                    if (null != id && id.trim().length() > 0) {
131
                        builders.put(id, extension);
132
                    }
133
                }
134
            }
135
        }
136
    }
137
138
    /**
139
     * Returns the builder instance with the specified id.
140
     * <p>
141
     * The instance is not cached. Each time this method is called, a new
142
     * instance is created.
143
     * </p>
144
     * 
145
     * @param id
146
     * @return the builder instance (maybe <code>null</code>)
147
     */
148
    public IFetchScriptBuilder getBuilder(String id) {
149
150
        // ensure initialized
151
        initializeRegistry();
152
153
        IConfigurationElement extension = (IConfigurationElement) builders
154
                .get(id);
155
        if (null != extension) {
156
            try {
157
                return (IFetchScriptBuilder) extension
158
                        .createExecutableExtension(ATTR_CLASS);
159
            } catch (CoreException e) {
160
                BundleHelper.getDefault().getLog().log(e.getStatus());
161
            }
162
        }
163
        return null;
164
    }
165
}
(-)src/org/eclipse/pde/internal/build/fetch/COPYFetchScriptBuilder.java (+208 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2005 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
 * $Id$
8
 *
9
 * Contributors:
10
 *     Gunnar Wagenknecht - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.pde.internal.build.fetch;
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.osgi.util.NLS;
23
import org.eclipse.pde.build.IFetchScriptBuilder;
24
import org.eclipse.pde.internal.build.IPDEBuildConstants;
25
import org.eclipse.pde.internal.build.Messages;
26
import org.eclipse.pde.internal.build.ant.AntScript;
27
import org.eclipse.pde.internal.build.ant.FileSet;
28
import org.eclipse.pde.internal.build.ant.ITask;
29
30
/**
31
 * An <code>IFetchScriptBuilder</code> that fetches features and plugins by
32
 * copying from a specific location (id: <code>COPY</code>).
33
 * <p>
34
 * Map file arguments:
35
 * <code>&lt;ROOT_LOCATION&gt;[,&lt;ELEMENT_LOCATION&gt;]</code>
36
 * <dl>
37
 * <dt>ROOT_LOCATION</dt>
38
 * <dd>The ROOT_LOCATION (eg. <code>/source/eclipse</code>, or
39
 * <code>D:/dev/myproduct</code>) is used as root path to determine the
40
 * location to fetch. It can be overwritten via the
41
 * <code>fetchTag</code> to fetch from another location (for example, on a different machine).</dd>
42
 * </dl>
43
 * <dt>ELEMENT_LOCATION</dt>
44
 * <dd>A path withing the ROOT_LOCATION (eg.
45
 * <code>org.eclipse.sdk-feature/features/org.eclipse.rcp</code>) to retrive
46
 * the element from if it is not within the root. If this is not provided the
47
 * default path will be used which simply maps to the element name.</dd>
48
 * </dl>
49
 * </p>
50
 */
51
public class COPYFetchScriptBuilder implements IFetchScriptBuilder,
52
		IPDEBuildConstants {
53
54
	public static final String ID = "COPY"; //$NON-NLS-1$
55
56
	private static final String PATH = "path"; //$NON-NLS-1$
57
58
	private static final String ROOT = "root"; //$NON-NLS-1$
59
60
	private static final ITask GET_FROM_PATH_TASK = new ITask() {
61
62
		/*
63
		 * (non-Javadoc)
64
		 * 
65
		 * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
66
		 */
67
		public void print(AntScript script) {
68
			FileSet dir = new FileSet(
69
					"${sourcePath}", null, null, null, null, null, null); //$NON-NLS-1$
70
			script.printCopyTask(null,
71
					"${destination}", new FileSet[] { dir }, false, true); //$NON-NLS-1$ 
72
		}
73
	};
74
75
	/*
76
	 * (non-Javadoc)
77
	 * 
78
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateAuthentificationTask(java.lang.String,
79
	 *      java.lang.String, java.util.Map)
80
	 */
81
	public ITask generateAuthentificationTask(String element, String type,
82
			Map entryInfos) {
83
		// not necessary
84
		return null;
85
	}
86
87
	/*
88
	 * (non-Javadoc)
89
	 * 
90
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generatePropertiesForFetchTask(java.lang.String,
91
	 *      java.lang.String, java.util.Map, java.lang.String, boolean)
92
	 */
93
	public Map generatePropertiesForFetchTask(String element, String type,
94
			Map entryInfos, String destination, boolean xmlFileOnly) {
95
		Map params = new HashMap(2);
96
97
		// we directly export the CVS content into the destination
98
		params.put("destination", destination); //$NON-NLS-1$
99
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
100
101
		String root = (String) entryInfos.get(ROOT);
102
		String path = (String) entryInfos.get(PATH);
103
		IPath sourcePath = new Path(root);
104
		if (path != null) {
105
			sourcePath = sourcePath.append(path);
106
		} else {
107
			sourcePath = sourcePath.append(element);
108
		}
109
110
		if (xmlFileOnly) {
111
			if (type.equals("feature")) { //$NON-NLS-1$
112
				sourcePath.append(DEFAULT_FEATURE_FILENAME_DESCRIPTOR);
113
			} else if (type.equals("plugin")) { //$NON-NLS-1$
114
				sourcePath.append(DEFAULT_PLUGIN_FILENAME_DESCRIPTOR);
115
			} else if (type.equals("fragment")) { //$NON-NLS-1$
116
				sourcePath.append(DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR);
117
			}
118
		}
119
		params.put("sourcePath", sourcePath.toString()); //$NON-NLS-1$
120
121
		return params;
122
	}
123
124
	/*
125
	 * (non-Javadoc)
126
	 * 
127
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateRetrieveFilesTask(java.lang.String,
128
	 *      java.lang.String, java.util.Map, java.lang.String,
129
	 *      java.lang.String[])
130
	 */
131
	public ITask generateRetrieveFilesTask(final String element,
132
			final String type, final Map entryInfos, final String destination,
133
			final String[] files) {
134
135
		return new ITask() {
136
137
			/*
138
			 * (non-Javadoc)
139
			 * 
140
			 * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
141
			 */
142
			public void print(AntScript script) {
143
				String root = (String) entryInfos.get(ROOT);
144
				String path = (String) entryInfos.get(PATH);
145
146
				for (int i = 0; i < files.length; i++) {
147
					String file = files[i];
148
					IPath filePath = new Path(root);
149
					if (path != null) {
150
						filePath = filePath.append(path).append(file);
151
					} else {
152
						filePath = filePath.append(element).append(file);
153
					}
154
155
					script.printCopyTask(filePath.toString(), destination,
156
							null, false, true);
157
				}
158
			}
159
		};
160
	}
161
162
	/*
163
	 * (non-Javadoc)
164
	 * 
165
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getFetchTask()
166
	 */
167
	public ITask getFetchTask() {
168
		return GET_FROM_PATH_TASK;
169
	}
170
171
	/*
172
	 * (non-Javadoc)
173
	 * 
174
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getVersionToFetch(java.lang.String,
175
	 *      java.lang.String, java.util.Map)
176
	 */
177
	public String getVersionToFetch(String element, String type, Map entryInfos) {
178
		return (String) entryInfos.get(ROOT);
179
	}
180
181
	/*
182
	 * (non-Javadoc)
183
	 * 
184
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#processMapFileEntry(java.lang.String,
185
	 *      java.lang.String, java.lang.String[], java.lang.String,
186
	 *      java.util.Map)
187
	 */
188
	public void processMapFileEntry(String element, String type,
189
			String[] arguments, String fetchTag, Map entryInfos)
190
			throws CoreException {
191
192
		if (arguments.length < 1) {
193
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry,
194
					element); //$NON-NLS-1$
195
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD,
196
					EXCEPTION_ENTRY_MISSING, message, null));
197
		}
198
199
		entryInfos
200
				.put(
201
						ROOT,
202
						(null == fetchTag || fetchTag.trim().length() == 0) ? arguments[0]
203
								: fetchTag);
204
		entryInfos.put(PATH, (arguments.length > 1 && arguments[1].trim()
205
				.length() > 0) ? arguments[1] : null);
206
	}
207
208
}
(-)src/org/eclipse/pde/internal/build/fetch/CVSFetchScriptBuilder.java (+227 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 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
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.osgi.util.NLS;
23
import org.eclipse.pde.build.IFetchScriptBuilder;
24
import org.eclipse.pde.internal.build.IPDEBuildConstants;
25
import org.eclipse.pde.internal.build.Messages;
26
import org.eclipse.pde.internal.build.ant.AntScript;
27
import org.eclipse.pde.internal.build.ant.ITask;
28
29
/**
30
 * An <code>IFetchScriptBuilder</code> for building fetch scripts that will
31
 * fetch content from a CVS repository (id: <code>CVS</code>).
32
 * <p>
33
 * Map file arguments:
34
 * <code>&lt;TAG&gt;,&lt;CVSROOT&gt;[,&lt;PASSWORD&gt;[,&lt;PATH&gt;[,&lt;CVSPASSFILE&gt;]]]</code>
35
 * </p>
36
 */
37
public class CVSFetchScriptBuilder implements IFetchScriptBuilder,
38
		IPDEBuildConstants {
39
40
	private static final String CVSPASSFILE = "cvsPassFile"; //$NON-NLS-1$
41
42
	private static final String CVSROOT = "cvsRoot"; //$NON-NLS-1$
43
44
	private static final ITask GET_FROM_CVS_TASK = new ITask() {
45
46
		/*
47
		 * (non-Javadoc)
48
		 * 
49
		 * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
50
		 */
51
		public void print(AntScript script) {
52
			script
53
					.printCVSTask(
54
							"export -d ${destination} -r ${tag} ${package}", "${cvsRoot}", null, null, null, "${quiet}", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
55
		}
56
	};
57
58
	public static final String ID = "CVS"; //$NON-NLS-1$
59
60
	private static final String PASSWORD = "password"; //$NON-NLS-1$
61
62
	private static final String PATH = "path"; //$NON-NLS-1$
63
64
	private static final String TAG = "tag"; //$NON-NLS-1$
65
66
	/*
67
	 * (non-Javadoc)
68
	 * 
69
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateAuthentificationTask(java.lang.String,
70
	 *      java.lang.String, java.util.Map)
71
	 */
72
	public ITask generateAuthentificationTask(final String element,
73
			final String type, final Map entryInfos) {
74
75
		return new ITask() {
76
77
			/*
78
			 * (non-Javadoc)
79
			 * 
80
			 * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
81
			 */
82
			public void print(AntScript script) {
83
				String password = (String) entryInfos.get(PASSWORD);
84
				String cvsPassFileLocation = (String) entryInfos
85
						.get(CVSPASSFILE);
86
				if (password != null)
87
					script.printCVSPassTask((String) entryInfos.get(CVSROOT),
88
							password, cvsPassFileLocation);
89
			}
90
		};
91
	}
92
93
	/*
94
	 * (non-Javadoc)
95
	 * 
96
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generatePropertiesForFetchTask(java.lang.String,
97
	 *      java.lang.String, java.util.Map, java.lang.String, boolean)
98
	 */
99
	public Map generatePropertiesForFetchTask(String element, String type,
100
			Map entryInfos, String destination, boolean manifestFileOnly) {
101
		Map params = new HashMap(5);
102
103
		// we directly export the CVS content into the destination
104
		params.put("destination", destination); //$NON-NLS-1$
105
		params.put(TAG, entryInfos.get(TAG));
106
		params.put(CVSROOT, entryInfos.get(CVSROOT));
107
		params.put("quiet", "${quiet}"); //$NON-NLS-1$ //$NON-NLS-2$
108
109
		String cvsPackage = ((String) entryInfos.get(PATH) == null ? element
110
				: (String) entryInfos.get(PATH));
111
		if (type.equals(ELEMENT_TYPE_FEATURE)) {
112
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FEATURE_FILENAME_DESCRIPTOR
113
					: ""; //$NON-NLS-1$
114
		} else if (type.equals(ELEMENT_TYPE_PLUGIN)) {
115
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_PLUGIN_FILENAME_DESCRIPTOR
116
					: ""; //$NON-NLS-1$
117
		} else if (type.equals(ELEMENT_TYPE_FRAGMENT)) {
118
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_FRAGMENT_FILENAME_DESCRIPTOR
119
					: ""; //$NON-NLS-1$
120
		} else if (type.equals(ELEMENT_TYPE_BUNDLE)) {
121
			cvsPackage += manifestFileOnly ? '/' + DEFAULT_BUNDLE_FILENAME_DESCRIPTOR
122
					: "";//$NON-NLS-1$ 
123
		}
124
		params.put("package", cvsPackage); //$NON-NLS-1$
125
126
		return params;
127
	}
128
129
	/*
130
	 * (non-Javadoc)
131
	 * 
132
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#generateRetrieveFilesTask(java.lang.String,
133
	 *      java.lang.String, java.util.Map, java.lang.String,
134
	 *      java.lang.String[])
135
	 */
136
	public ITask generateRetrieveFilesTask(final String element,
137
			final String type, final Map entryInfos, final String destination,
138
			final String[] files) {
139
		return new ITask() {
140
141
			/*
142
			 * (non-Javadoc)
143
			 * 
144
			 * @see org.eclipse.pde.internal.build.ant.ITask#print(org.eclipse.pde.internal.build.ant.AntScript)
145
			 */
146
			public void print(AntScript script) {
147
				String cvsRoot = (String) entryInfos.get(CVSROOT);
148
				String tag = (String) entryInfos.get(TAG);
149
				String path = (String) entryInfos.get(PATH);
150
				String password = (String) entryInfos.get(PASSWORD);
151
				String cvsPassFileLocation = (String) entryInfos
152
						.get(CVSPASSFILE);
153
154
				if (password != null)
155
					script.printCVSPassTask(cvsRoot, password,
156
							cvsPassFileLocation);
157
158
				for (int i = 0; i < files.length; i++) {
159
					String file = files[i];
160
					IPath filePath;
161
					if (path != null) {
162
						filePath = new Path(path).append(file);
163
					} else {
164
						filePath = new Path(element).append(file);
165
					}
166
167
					script
168
							.printCVSTask(
169
									"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$
170
				}
171
			}
172
		};
173
	}
174
175
	/*
176
	 * (non-Javadoc)
177
	 * 
178
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getFetchTask()
179
	 */
180
	public ITask getFetchTask() {
181
		return GET_FROM_CVS_TASK;
182
	}
183
184
	/*
185
	 * (non-Javadoc)
186
	 * 
187
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#getVersionToFetch(java.lang.String,
188
	 *      java.lang.String, java.util.Map)
189
	 */
190
	public String getVersionToFetch(String element, String type, Map entryInfos) {
191
		return (String) entryInfos.get(TAG);
192
	}
193
194
	/*
195
	 * (non-Javadoc)
196
	 * 
197
	 * @see org.eclipse.pde.internal.build.IFetchScriptBuilder#processMapFileEntry(java.lang.String,
198
	 *      java.lang.String, java.lang.String[], java.lang.String,
199
	 *      java.util.Map)
200
	 */
201
	public void processMapFileEntry(String element, String type,
202
			String[] arguments, String fetchTag, Map entryInfos)
203
			throws CoreException {
204
205
		if (arguments.length < 2) {
206
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry,
207
					element);
208
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD,
209
					EXCEPTION_ENTRY_MISSING, message, null));
210
		}
211
212
		entryInfos
213
				.put(
214
						TAG,
215
						(null == fetchTag || fetchTag.trim().length() == 0) ? arguments[0]
216
								: fetchTag);
217
		entryInfos.put(CVSROOT, arguments[1]);
218
		entryInfos.put(PASSWORD, (arguments.length > 2 && !arguments[2]
219
				.equals("")) ? arguments[2] : null); //$NON-NLS-1$
220
		entryInfos
221
				.put(
222
						PATH,
223
						(arguments.length > 3 && !arguments[3].equals("")) ? arguments[3] : null); //$NON-NLS-1$ 
224
		entryInfos.put(CVSPASSFILE, (arguments.length > 4 && !arguments[4]
225
				.equals("")) ? arguments[4] : null); //$NON-NLS-1$
226
	}
227
}

Return to bug 34757