1 /*******************************************************************************
2  * Copyright (c) 2000, 2017 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *    IBM - Initial API and implementation
13  *    G&H Softwareentwicklung GmbH - internationalization implementation (bug 150933)
14  *    Prosyst - create proper OSGi bundles (bug 174157)
15  *    Felix Riegger (SAP AG) - consolidation of publishers for PDE formats (bug 331974)
16  *    Rapicorp, Inc - Specify download stats URL and type of artifacts to monitor in category.xml (bug 436872)
17  *******************************************************************************/
18 package org.eclipse.pde.internal.build;
19 
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.*;
23 import java.util.jar.JarFile;
24 import org.eclipse.core.runtime.*;
25 import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;
26 import org.eclipse.osgi.service.resolver.BundleDescription;
27 import org.eclipse.pde.internal.build.ant.*;
28 import org.eclipse.pde.internal.build.builder.BuildDirector;
29 import org.eclipse.pde.internal.build.builder.ModelBuildScriptGenerator;
30 import org.eclipse.pde.internal.build.site.BuildTimeFeature;
31 import org.osgi.framework.Bundle;
32 import org.osgi.framework.Version;
33 
34 /**
35  * Generate an assemble script for a given feature and a given config. It
36  * generates all the instruction to zip the listed plugins and features.
37  */
38 public class AssembleConfigScriptGenerator extends AbstractScriptGenerator {
39 	protected String directory; // representing the directory where to generate the file
40 	protected String featureId;
41 	protected Config configInfo;
42 	protected BuildTimeFeature[] features; // the features that will be assembled
43 	protected BuildTimeFeature[] allFeatures; //the set of all the features that have been considered
44 	protected BundleDescription[] plugins;
45 	protected String filename;
46 	protected Collection<BuildTimeFeature> rootFileProviders;
47 	protected String rootFolder = null;
48 	protected ArrayList<String> addedByPermissions = new ArrayList<>(); //contains the list of files and folders that have been added to an archive by permission management
49 
50 	private static final String PROPERTY_SOURCE = "source"; //$NON-NLS-1$
51 	private static final String PROPERTY_ELEMENT_NAME = "elementName"; //$NON-NLS-1$
52 
53 	private static final byte BUNDLE_TYPE = 0;
54 	private static final byte FEATURE_TYPE = 1;
55 
56 	protected String PROPERTY_ECLIPSE_PLUGINS = "eclipse.plugins"; //$NON-NLS-1$
57 	protected String PROPERTY_ECLIPSE_FEATURES = "eclipse.features"; //$NON-NLS-1$
58 	protected boolean signJars;
59 	private boolean generateJnlp;
60 
61 	private String archiveFormat;
62 	private boolean groupConfigs = false;
63 	private String product;
64 	private ProductFile productFile = null;
65 	protected ShapeAdvisor shapeAdvisor = null;
66 	private Boolean p2Bundles = null;
67 
AssembleConfigScriptGenerator()68 	public AssembleConfigScriptGenerator() {
69 		super();
70 	}
71 
initialize(String directoryName, String feature, Config configurationInformation, Collection<BundleDescription> elementList, Collection<BuildTimeFeature> featureList, Collection<BuildTimeFeature> allFeaturesList, Collection<BuildTimeFeature> rootProviders)72 	public void initialize(String directoryName, String feature, Config configurationInformation, Collection<BundleDescription> elementList, Collection<BuildTimeFeature> featureList, Collection<BuildTimeFeature> allFeaturesList, Collection<BuildTimeFeature> rootProviders) throws CoreException {
73 		this.directory = directoryName;
74 		this.featureId = feature;
75 		this.configInfo = configurationInformation;
76 		this.rootFileProviders = rootProviders != null ? rootProviders : new ArrayList<>(0);
77 		this.rootFolder = Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER); //$NON-NLS-1$
78 		this.features = new BuildTimeFeature[featureList.size()];
79 		featureList.toArray(this.features);
80 
81 		this.allFeatures = new BuildTimeFeature[allFeaturesList.size()];
82 		allFeaturesList.toArray(this.allFeatures);
83 
84 		this.plugins = new BundleDescription[elementList.size()];
85 		this.plugins = elementList.toArray(this.plugins);
86 
87 		openScript(directoryName, getTargetName() + ".xml"); //$NON-NLS-1$
88 		shapeAdvisor = new ShapeAdvisor();
89 		shapeAdvisor.setForceUpdateJars(forceUpdateJarFormat);
90 	}
91 
computeIconsList()92 	protected String computeIconsList() {
93 		return computeIconsList(configInfo.getOs());
94 	}
95 
computeIconsList(String os)96 	protected String computeIconsList(String os) {
97 		String result = Utils.getPropertyFormat(PROPERTY_LAUNCHER_ICONS);
98 		if (getProductFile() == null)
99 			return result;
100 		String[] icons = os != null ? productFile.getIcons(os) : productFile.getIcons();
101 		for (int i = 0; i < icons.length; i++) {
102 
103 			String icon = Utils.makeRelative(new Path(icons[i]), new Path(productFile.getLocation().getParent())).toOSString();
104 
105 			String location = findFile(icon, true);
106 			if (location == null) {
107 				File iconFile = new File(productFile.getLocation().getParentFile(), icon);
108 				if (iconFile.exists())
109 					location = Utils.makeRelative(new Path(iconFile.getAbsolutePath()), new Path(workingDirectory)).toOSString();
110 			}
111 			if (location != null)
112 				result += ", " + Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + location; //$NON-NLS-1$
113 			else {
114 				result += ", " + Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + icon; //$NON-NLS-1$
115 				result += ", " + Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + DEFAULT_FEATURE_LOCATION + '/' + icon; //$NON-NLS-1$
116 			}
117 		}
118 		return result;
119 	}
120 
121 	@Override
generate()122 	public void generate() {
123 		try {
124 			// Note that we must pass the OS information in to load product
125 			// so that any icon files can be calculated for the
126 			// generateBrandingCalls.
127 			productFile = loadProduct(product, configInfo.getOs());
128 		} catch (CoreException e) {
129 			//ignore
130 		}
131 		generatePrologue();
132 
133 		generateMainBegin();
134 		generateInitializationSteps();
135 		if (BuildDirector.p2Gathering) {
136 			generateP2Assembling();
137 		} else {
138 			generateGatherCalls();
139 			generateProcessingCalls();
140 			generateBrandingCalls();
141 			generateP2Steps();
142 		}
143 		generateArchivingCalls();
144 		generateMainEnd();
145 
146 		generateEpilogue();
147 	}
148 
generateGatherCalls()149 	protected void generateGatherCalls() {
150 		script.printAntCallTask(TARGET_GATHER_BIN_PARTS, true, null);
151 
152 		if (embeddedSource)
153 			script.printAntCallTask(TARGET_GATHER_SOURCES, true, null);
154 
155 		printCustomAssemblyAntCall(PROPERTY_POST + TARGET_GATHER_BIN_PARTS, null);
156 		script.println();
157 	}
158 
generateP2Assembling()159 	protected void generateP2Assembling() {
160 		if (productFile != null) {
161 			script.printAntCallTask(TARGET_RUN_DIRECTOR, true, null);
162 			script.printAntCallTask(TARGET_MIRROR_PRODUCT, true, null);
163 		} else {
164 			script.printAntCallTask(TARGET_MIRROR_ARCHIVE, true, null);
165 		}
166 	}
167 
generateMirrorProductTask()168 	protected void generateMirrorProductTask() {
169 		Map<String, String> mirrorArgs = new HashMap<>();
170 		mirrorArgs.put(PROPERTY_P2_MIRROR_METADATA_DEST, Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO));
171 		mirrorArgs.put(PROPERTY_P2_MIRROR_ARTIFACT_DEST, Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO));
172 
173 		script.printTargetDeclaration(TARGET_MIRROR_PRODUCT, null, PROPERTY_P2_METADATA_REPO, PROPERTY_SKIP_MIRRORING, null);
174 		script.printAntCallTask(TARGET_MIRROR_ARCHIVE, true, mirrorArgs);
175 		script.printTargetEnd();
176 		script.println();
177 	}
178 
generateMirrorTask(boolean assembling)179 	protected void generateMirrorTask(boolean assembling) {
180 		script.printTargetDeclaration(TARGET_MIRROR_ARCHIVE, null, null, PROPERTY_SKIP_MIRRORING, null);
181 		script.printProperty(PROPERTY_P2_APPEND, "true"); //$NON-NLS-1$
182 		script.printProperty(PROPERTY_P2_MIRROR_METADATA_DEST, "file:" + Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); //$NON-NLS-1$
183 		script.printProperty(PROPERTY_P2_MIRROR_ARTIFACT_DEST, "file:" + Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); //$NON-NLS-1$
184 		if (features.length + plugins.length + rootFileProviders.size() > 0 || productFile != null) {
185 			script.printTab();
186 			script.print("<p2.mirror "); //$NON-NLS-1$
187 			script.printAttribute("source", Utils.getPropertyFormat(PROPERTY_P2_BUILD_REPO), true); //$NON-NLS-1$
188 			script.printAttribute("mirrorProperties", TRUE, true); //$NON-NLS-1$
189 			script.println(">"); //$NON-NLS-1$
190 			script.printTab();
191 			script.print("\t<destination "); //$NON-NLS-1$
192 			script.printAttribute("location", Utils.getPropertyFormat(PROPERTY_P2_MIRROR_METADATA_DEST), true); //$NON-NLS-1$
193 			script.printAttribute("name", Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO_NAME), true); //$NON-NLS-1$
194 			script.printAttribute("compressed", Utils.getPropertyFormat(PROPERTY_P2_COMPRESS), true); //$NON-NLS-1$
195 			script.printAttribute("append", assembling ? Utils.getPropertyFormat(PROPERTY_P2_APPEND) : TRUE, true); //$NON-NLS-1$
196 			script.printAttribute("kind", "metadata", true); //$NON-NLS-1$ //$NON-NLS-2$
197 			script.println("/>"); //$NON-NLS-1$
198 			script.printTab();
199 			script.print("\t<destination "); //$NON-NLS-1$
200 			script.printAttribute("location", Utils.getPropertyFormat(PROPERTY_P2_MIRROR_ARTIFACT_DEST), true); //$NON-NLS-1$
201 			script.printAttribute("name", Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO_NAME), true); //$NON-NLS-1$
202 			script.printAttribute("compressed", Utils.getPropertyFormat(PROPERTY_P2_COMPRESS), true); //$NON-NLS-1$
203 			script.printAttribute("append", assembling ? Utils.getPropertyFormat(PROPERTY_P2_APPEND) : TRUE, true); //$NON-NLS-1$
204 			script.printAttribute("kind", "artifact", true); //$NON-NLS-1$ //$NON-NLS-2$
205 			script.println("/>"); //$NON-NLS-1$
206 			script.printTab();
207 
208 			for (int i = 0; i < plugins.length; i++) {
209 				BundleDescription plugin = plugins[i];
210 				script.printTab();
211 				script.print("\t<iu "); //$NON-NLS-1$
212 				script.printAttribute(ID, plugin.getSymbolicName(), true);
213 				script.printAttribute(VERSION, plugin.getVersion().toString(), true);
214 				script.println("/>"); //$NON-NLS-1$
215 			}
216 
217 			for (int i = 0; i < features.length; i++) {
218 				BuildTimeFeature feature = features[i];
219 				script.printTab();
220 				script.print("\t<iu"); //$NON-NLS-1$
221 				script.printAttribute(ID, getFeatureGroupId(feature), true);
222 				script.printAttribute(VERSION, feature.getVersion(), true);
223 				script.println("/>"); //$NON-NLS-1$
224 			}
225 
226 			for (Iterator<BuildTimeFeature> iterator = rootFileProviders.iterator(); iterator.hasNext();) {
227 				BuildTimeFeature rootProvider = iterator.next();
228 				if (!(havePDEUIState() && rootProvider.getId().equals("org.eclipse.pde.container.feature"))) { //$NON-NLS-1$
229 					script.printTab();
230 					script.print("\t<iu"); //$NON-NLS-1$
231 					script.printAttribute(ID, getFeatureGroupId(rootProvider), true);
232 					script.printAttribute(VERSION, rootProvider.getVersion(), true);
233 					script.println("/>"); //$NON-NLS-1$
234 				}
235 			}
236 			if (productFile != null) {
237 				script.printTab();
238 				script.print("\t<iu"); //$NON-NLS-1$
239 				script.printAttribute(ID, productFile.getId(), true);
240 				script.printAttribute(VERSION, getReplacedProductVersion(), true);
241 				script.println("/>"); //$NON-NLS-1$
242 			}
243 			//categories
244 			script.printTab();
245 			script.println("<iu query=\"property[@name='org.eclipse.equinox.p2.type.category']\" required=\"false\" />"); //$NON-NLS-1$
246 			script.println("</p2.mirror>"); //$NON-NLS-1$
247 		}
248 		script.printTargetEnd();
249 		script.println();
250 	}
251 
getFeatureGroupId(BuildTimeFeature feature)252 	protected String getFeatureGroupId(BuildTimeFeature feature) {
253 		if (!feature.isBinary()) {
254 			Properties properties = getFeatureBuildProperties(feature);
255 			if (properties.containsKey(PROPERTY_P2_GROUP_ID))
256 				return properties.getProperty(PROPERTY_P2_GROUP_ID);
257 		}
258 		return feature.getId() + ".feature.group"; //$NON-NLS-1$
259 	}
260 
getReplacedProductVersion()261 	protected String getReplacedProductVersion() {
262 		String productVersion = productFile.getVersion();
263 		if (productVersion.endsWith(PROPERTY_QUALIFIER)) {
264 			Version version = new Version(productVersion);
265 			StringBuffer buffer = new StringBuffer();
266 			buffer.append(version.getMajor());
267 			buffer.append('.');
268 			buffer.append(version.getMinor());
269 			buffer.append('.');
270 			buffer.append(version.getMicro());
271 			buffer.append('.');
272 			buffer.append(Utils.getPropertyFormat(PROPERTY_P2_PRODUCT_QUALIFIER));
273 
274 			productVersion = buffer.toString();
275 		}
276 		return productVersion;
277 	}
278 
generateDirectorTarget(boolean assembling)279 	protected void generateDirectorTarget(boolean assembling) {
280 		if (assembling) {
281 			script.printTargetDeclaration(TARGET_RUN_DIRECTOR_CONDITION, null, null, null, null);
282 			script.printTab();
283 			script.print("<condition"); //$NON-NLS-1$
284 			script.printAttribute("property", TARGET_RUN_DIRECTOR_CONDITION, true); //$NON-NLS-1$
285 			script.printAttribute("value", TRUE, true); //$NON-NLS-1$
286 			script.println(">"); //$NON-NLS-1$
287 			script.println("\t<or>"); //$NON-NLS-1$
288 			script.println("\t\t<isset property=\"" + PROPERTY_RUN_PACKAGER + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
289 			script.println("\t\t<isset property=\"" + PROPERTY_SKIP_DIRECTOR + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
290 			script.println("\t</or>"); //$NON-NLS-1$
291 			script.printEndTag("condition"); //$NON-NLS-1$
292 			script.printTargetEnd();
293 		}
294 
295 		script.printTargetDeclaration(TARGET_RUN_DIRECTOR, assembling ? TARGET_RUN_DIRECTOR_CONDITION : null, null, assembling ? TARGET_RUN_DIRECTOR_CONDITION : PROPERTY_SKIP_DIRECTOR, null);
296 		Map<String, String> parameters = new HashMap<>();
297 		parameters.put(PROPERTY_OS, Utils.getPropertyFormat(PROPERTY_OS));
298 		parameters.put(PROPERTY_WS, Utils.getPropertyFormat(PROPERTY_WS));
299 		parameters.put(PROPERTY_ARCH, Utils.getPropertyFormat(PROPERTY_ARCH));
300 		parameters.put(PROPERTY_P2_REPO, Utils.getPropertyFormat(PROPERTY_P2_BUILD_REPO));
301 		parameters.put(PROPERTY_P2_DIRECTOR_IU, productFile != null ? productFile.getId() : Utils.getPropertyFormat(PROPERTY_P2_ROOT_NAME));
302 		parameters.put(PROPERTY_P2_DIRECTOR_VERSION, productFile != null ? getReplacedProductVersion() : Utils.getPropertyFormat(PROPERTY_P2_ROOT_VERSION));
303 		parameters.put(PROPERTY_P2_DIRECTOR_INSTALLPATH, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE));
304 		script.printAntTask(Utils.getPropertyFormat(PROPERTY_GENERIC_TARGETS), null, TARGET_RUN_DIRECTOR, null, TRUE, parameters);
305 		script.println();
306 		script.printTargetEnd();
307 		script.println();
308 	}
309 
generateProcessingCalls()310 	private void generateProcessingCalls() {
311 		script.printAntCallTask(TARGET_JAR_PROCESSING, true, null);
312 		script.println();
313 	}
314 
generateArchivingCalls()315 	private void generateArchivingCalls() {
316 		script.printAntCallTask(TARGET_ASSEMBLE_ARCHIVE, true, null);
317 	}
318 
generateMainBegin()319 	protected void generateMainBegin() {
320 		script.printTargetDeclaration(TARGET_MAIN, null, null, null, null);
321 	}
322 
generateMainEnd()323 	protected void generateMainEnd() {
324 		script.printAntCallTask(TARGET_CLEANUP_ASSEMBLY, true, null);
325 		script.printTargetEnd();
326 		script.println();
327 	}
328 
generateCleanupAssembly(boolean assembling)329 	protected void generateCleanupAssembly(boolean assembling) {
330 		String condition = (assembling && BuildDirector.p2Gathering) ? PROPERTY_RUN_PACKAGER : null;
331 		script.printTargetDeclaration(TARGET_CLEANUP_ASSEMBLY, null, null, condition, null);
332 		if (!FORMAT_FOLDER.equalsIgnoreCase(archiveFormat))
333 			script.printDeleteTask(Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP), null, null);
334 		script.printTargetEnd();
335 		script.println();
336 	}
337 
338 	/**
339 	 *
340 	 */
generateBrandingCalls()341 	protected void generateBrandingCalls() {
342 		script.printBrandTask(rootFolder, computeIconsList(), Utils.getPropertyFormat(PROPERTY_LAUNCHER_NAME), Utils.getPropertyFormat(PROPERTY_OS));
343 	}
344 
generateP2Steps()345 	private void generateP2Steps() {
346 		if (!haveP2Bundles())
347 			return;
348 		if (rootFileProviders.size() == 0 && features.length == 0 && plugins.length == 0)
349 			return;
350 		script.printAntCallTask(TARGET_P2_METADATA, true, null);
351 		script.println();
352 	}
353 
generateArchivingTarget(boolean assembling)354 	protected void generateArchivingTarget(boolean assembling) {
355 		boolean condition = assembling && BuildDirector.p2Gathering;
356 		if (condition) {
357 			script.printTargetDeclaration(TARGET_ASSEMBLE_ARCHIVE_CONDITION, null, null, null, null);
358 			script.printTab();
359 			script.print("<condition"); //$NON-NLS-1$
360 			script.printAttribute("property", TARGET_ASSEMBLE_ARCHIVE_CONDITION, true); //$NON-NLS-1$
361 			script.printAttribute("value", TRUE, true); //$NON-NLS-1$
362 			script.println(">"); //$NON-NLS-1$
363 			script.println("\t<or>"); //$NON-NLS-1$
364 			script.println("\t\t<isset property=\"" + PROPERTY_RUN_PACKAGER + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
365 			if (productFile != null)
366 				script.println("\t\t<isset property=\"" + PROPERTY_SKIP_DIRECTOR + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
367 			else
368 				script.println("\t\t<isset property=\"" + PROPERTY_SKIP_MIRRORING + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
369 			script.println("\t</or>"); //$NON-NLS-1$
370 			script.printEndTag("condition"); //$NON-NLS-1$
371 			script.printTargetEnd();
372 		}
373 
374 		// Only run the archive target if there is something there to archive.
375 		// if not p2Gathering, no conditions,
376 		// else, if assembling condition is (runPackager || skipDirector), if packaging condition is skipDirector
377 		String assemblyCondition = BuildDirector.p2Gathering ? TARGET_ASSEMBLE_ARCHIVE_CONDITION : null;
378 		String packageCondition = BuildDirector.p2Gathering ? (productFile != null ? PROPERTY_SKIP_DIRECTOR : PROPERTY_SKIP_MIRRORING) : null;
379 		script.printTargetDeclaration(TARGET_ASSEMBLE_ARCHIVE, condition ? TARGET_ASSEMBLE_ARCHIVE_CONDITION : null, null, assembling ? assemblyCondition : packageCondition, null);
380 		Map<String, String> properties = new HashMap<>();
381 		properties.put(PROPERTY_ROOT_FOLDER, rootFolder);
382 		printCustomAssemblyAntCall(PROPERTY_PRE + "archive", properties); //$NON-NLS-1$
383 
384 		if (FORMAT_FOLDER.equalsIgnoreCase(archiveFormat)) {
385 			generateMoveRootFiles();
386 		} else if (FORMAT_ZIP.equalsIgnoreCase(archiveFormat)) {
387 			generateZipTarget();
388 		} else if (FORMAT_ANTZIP.equalsIgnoreCase(archiveFormat)) {
389 			generateAntZipTarget();
390 		} else if (FORMAT_ANTTAR.equalsIgnoreCase(archiveFormat)) {
391 			generateAntTarTarget();
392 		} else if (FORMAT_TAR.equalsIgnoreCase(archiveFormat)) {
393 			generateTarGZTasks(true);
394 		}
395 		script.printTargetEnd();
396 		script.println();
397 	}
398 
generateMoveRootFiles()399 	private void generateMoveRootFiles() {
400 		if (rootFileProviders.size() == 0 || BuildDirector.p2Gathering)
401 			return;
402 
403 		for (Iterator<BuildTimeFeature> iter = rootFileProviders.iterator(); iter.hasNext();) {
404 			Properties featureProperties = getFeatureBuildProperties(iter.next());
405 			Utils.generatePermissions(featureProperties, configInfo, PROPERTY_ECLIPSE_BASE, script);
406 		}
407 
408 		if (Platform.getOS().equals("win32")) { //$NON-NLS-1$
409 			FileSet[] rootFiles = new FileSet[1];
410 			rootFiles[0] = new FileSet(rootFolder, null, "**/**", null, null, null, null); //$NON-NLS-1$
411 			script.printMoveTask(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), rootFiles, false);
412 			script.printDeleteTask(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING), null, null); //$NON-NLS-1$
413 		} else {
414 			List<String> params = new ArrayList<>(3);
415 			params.add("-R"); //$NON-NLS-1$
416 			params.add("."); //$NON-NLS-1$
417 			params.add('\'' + Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '\'');
418 			String rootFileFolder = Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING); //$NON-NLS-1$
419 			script.printExecTask("cp", rootFileFolder + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER), params, null); //$NON-NLS-1$
420 			script.printDeleteTask(rootFileFolder, null, null);
421 		}
422 	}
423 
getFeatureBuildProperties(BuildTimeFeature feature)424 	protected Properties getFeatureBuildProperties(BuildTimeFeature feature) {
425 		if (feature.isBinary())
426 			return null;
427 		try {
428 			return AbstractScriptGenerator.readProperties(new Path(feature.getRootLocation()).toOSString(), PROPERTIES_FILE, IStatus.OK);
429 		} catch (CoreException e) {
430 			return null;
431 		}
432 
433 	}
434 
generateGatherSourceTarget()435 	protected void generateGatherSourceTarget() {
436 		script.printTargetDeclaration(TARGET_GATHER_SOURCES, null, null, null, null);
437 		Map<String, String> properties = new HashMap<>(1);
438 		properties.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS));
439 
440 		for (int i = 0; i < plugins.length; i++) {
441 			BundleDescription plugin = plugins[i];
442 			String placeToGather = getLocation(plugin);
443 
444 			script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_SOURCES, null, null, properties);
445 
446 			Properties bundleProperties = (Properties) plugin.getUserObject();
447 			//Source code for plugins with . on the classpath must be put in a folder in the final jar.
448 			if (bundleProperties.get(WITH_DOT) == Boolean.TRUE) {
449 				String targetLocation = Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) + '/' + ModelBuildScriptGenerator.getNormalizedName(plugin);
450 				String targetLocationSrc = targetLocation + "/src"; //$NON-NLS-1$
451 
452 				//Find the source zip where it has been gathered and extract it in a folder
453 				script.println("<unzip dest=\"" + AntScript.getEscaped(targetLocationSrc) + "\">"); //$NON-NLS-1$//$NON-NLS-2$
454 				script.println("\t<fileset dir=\"" + AntScript.getEscaped(targetLocation) + "\" includes=\"**/*src.zip\" casesensitive=\"false\"/>"); //$NON-NLS-1$//$NON-NLS-2$
455 				script.println("</unzip>"); //$NON-NLS-1$
456 
457 				//	Delete the source zip where it has been gathered since we extracted it
458 				script.printDeleteTask(null, null, new FileSet[] {new FileSet(targetLocation, null, "**/*src.zip", null, null, null, "false")}); //$NON-NLS-1$ //$NON-NLS-2$//$NON-bNLS-3$
459 			}
460 		}
461 
462 		properties = new HashMap<>(1);
463 		properties.put(PROPERTY_FEATURE_BASE, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE));
464 		for (int i = 0; i < features.length; i++) {
465 			BuildTimeFeature feature = features[i];
466 			String placeToGather = feature.getRootLocation();
467 			script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), TARGET_GATHER_SOURCES, null, null, properties);
468 		}
469 
470 		script.printTargetEnd();
471 		script.println();
472 	}
473 
generatePackagingTargets()474 	protected void generatePackagingTargets() {
475 		String fileName = Utils.getPropertyFormat(PROPERTY_SOURCE) + '/' + Utils.getPropertyFormat(PROPERTY_ELEMENT_NAME);
476 		String fileExists = Utils.getPropertyFormat(PROPERTY_SOURCE) + '/' + Utils.getPropertyFormat(PROPERTY_ELEMENT_NAME) + "_exists"; //$NON-NLS-1$
477 
478 		script.printComment("Beginning of the jarUp task"); //$NON-NLS-1$
479 		script.printTargetDeclaration(TARGET_JARUP, null, null, null, Messages.assemble_jarUp);
480 		script.printAvailableTask(fileExists, fileName);
481 		Map<String, String> params = new HashMap<>(2);
482 		params.put(PROPERTY_SOURCE, Utils.getPropertyFormat(PROPERTY_SOURCE));
483 		params.put(PROPERTY_ELEMENT_NAME, Utils.getPropertyFormat(PROPERTY_ELEMENT_NAME));
484 		script.printAvailableTask(PROPERTY_JARING_MANIFEST, fileName + '/' + JarFile.MANIFEST_NAME);
485 		script.printConditionIsSet(PROPERTY_JARING_TASK, TARGET_JARING, PROPERTY_JARING_MANIFEST, TARGET_JARING + "_NoManifest"); //$NON-NLS-1$
486 		script.printAntCallTask(Utils.getPropertyFormat(PROPERTY_JARING_TASK), true, params);
487 		script.printTargetEnd();
488 		script.println();
489 
490 		script.printTargetDeclaration(TARGET_JARING, null, fileExists, null, null);
491 		script.printJarTask(fileName + ".jar", fileName, fileName + '/' + JarFile.MANIFEST_NAME, "skip"); //$NON-NLS-1$ //$NON-NLS-2$
492 		script.printDeleteTask(fileName, null, null);
493 		script.printTargetEnd();
494 		script.println();
495 
496 		script.printTargetDeclaration(TARGET_JARING + "_NoManifest", null, fileExists, null, null); //$NON-NLS-1$
497 		script.printJarTask(fileName + ".jar", fileName, null, "merge"); //$NON-NLS-1$ //$NON-NLS-2$
498 		script.printDeleteTask(fileName, null, null);
499 		script.printTargetEnd();
500 		script.printComment("End of the jarUp task"); //$NON-NLS-1$
501 		script.println();
502 
503 		script.printComment("Beginning of the jar signing  target"); //$NON-NLS-1$
504 		script.printTargetDeclaration(TARGET_JARSIGNING, null, null, null, Messages.sign_Jar);
505 		printCustomAssemblyAntCall(PROPERTY_PRE + TARGET_JARSIGNING, null);
506 		if (generateJnlp)
507 			script.printProperty(PROPERTY_UNSIGN, "true"); //$NON-NLS-1$
508 		script.println("<eclipse.jarProcessor sign=\"" + Utils.getPropertyFormat(PROPERTY_SIGN) + "\" pack=\"" + Utils.getPropertyFormat(PROPERTY_PACK) + "\" unsign=\"" + Utils.getPropertyFormat(PROPERTY_UNSIGN) + "\" jar=\"" + fileName + ".jar" + "\" alias=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_ALIAS) + "\" keystore=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_KEYSTORE) + "\" storepass=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_STOREPASS) + "\" keypass=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_KEYPASS) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
509 		script.printTargetEnd();
510 		script.printComment("End of the jarUp task"); //$NON-NLS-1$
511 		script.println();
512 	}
513 
generateGZipTarget(boolean assembling)514 	protected void generateGZipTarget(boolean assembling) {
515 		//during the assemble stage, only zip if we aren't running the packager
516 		script.printTargetDeclaration(TARGET_GZIP_RESULTS, null, null, assembling ? PROPERTY_RUN_PACKAGER : null, null);
517 		script.println("<move file=\"" //$NON-NLS-1$
518 				+ Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + "\" tofile=\"" //$NON-NLS-1$
519 				+ Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + "/tmp.tar\"/>"); //$NON-NLS-1$
520 		script.printGZip(Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + "/tmp.tar", //$NON-NLS-1$
521 				Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH));
522 		script.printTargetEnd();
523 	}
524 
generatePrologue()525 	protected void generatePrologue() {
526 		script.printProjectDeclaration("Assemble " + featureId, TARGET_MAIN, null); //$NON-NLS-1$
527 		script.printProperty(PROPERTY_ARCHIVE_NAME, computeArchiveName());
528 		script.printProperty(PROPERTY_OS, configInfo.getOs());
529 		script.printProperty(PROPERTY_WS, configInfo.getWs());
530 		script.printProperty(PROPERTY_ARCH, configInfo.getArch());
531 		script.printProperty(PROPERTY_SIGN, (signJars ? Boolean.TRUE : Boolean.FALSE).toString());
532 		script.printProperty(PROPERTY_ASSEMBLY_TMP, Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + "/tmp"); //$NON-NLS-1$
533 		script.printProperty(PROPERTY_ECLIPSE_BASE, Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER));
534 		script.printProperty(PROPERTY_ECLIPSE_PLUGINS, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_PLUGIN_LOCATION);
535 		script.printProperty(PROPERTY_ECLIPSE_FEATURES, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_FEATURE_LOCATION);
536 		script.printProperty(PROPERTY_ARCHIVE_FULLPATH, Utils.getPropertyFormat(PROPERTY_BASEDIR) + '/' + Utils.getPropertyFormat(PROPERTY_BUILD_LABEL) + '/' + Utils.getPropertyFormat(PROPERTY_ARCHIVE_NAME));
537 		printLauncherJarProperty();
538 		script.printProperty(PROPERTY_P2_BUILD_REPO, "file:" + Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + "/buildRepo"); //$NON-NLS-1$ //$NON-NLS-2$
539 		script.printProperty(PROPERTY_GENERIC_TARGETS, Utils.getPropertyFormat("eclipse.pdebuild.scripts") + '/' + "/genericTargets.xml"); //$NON-NLS-1$//$NON-NLS-2$
540 		script.printAvailableTask(PROPERTY_CUSTOM_ASSEMBLY, "${builder}/customAssembly.xml", "${builder}/customAssembly.xml"); //$NON-NLS-1$ //$NON-NLS-2$
541 		if (productQualifier != null)
542 			script.printProperty(PROPERTY_P2_PRODUCT_QUALIFIER, productQualifier);
543 
544 		if (productFile != null && productFile.getLauncherName() != null)
545 			script.printProperty(PROPERTY_LAUNCHER_NAME, productFile.getLauncherName());
546 		script.printProperty(PROPERTY_TAR_ARGS, ""); //$NON-NLS-1$
547 		script.println();
548 
549 		generateCustomGatherMacro();
550 		generatePackagingTargets();
551 	}
552 
printLauncherJarProperty()553 	protected void printLauncherJarProperty() {
554 		Bundle launcherBundle = Platform.getBundle(BUNDLE_EQUINOX_LAUNCHER);
555 		try {
556 			File bundleFile = FileLocator.getBundleFile(launcherBundle);
557 			script.printProperty(PROPERTY_LAUNCHER_JAR, bundleFile.getAbsolutePath());
558 		} catch (IOException e) {
559 			// what can we do with this?
560 		}
561 	}
562 
generateCustomGatherMacro()563 	protected void generateCustomGatherMacro() {
564 		List<String> attributes = new ArrayList<>(5);
565 		attributes.add("dir"); //$NON-NLS-1$
566 		attributes.add("propertyName"); //$NON-NLS-1$
567 		attributes.add("propertyValue"); //$NON-NLS-1$
568 		attributes.add("subFolder"); //$NON-NLS-1$
569 		attributes.add(PROPERTY_PROJECT_NAME);
570 		script.printMacroDef(PROPERTY_CUSTOM_GATHER, attributes);
571 
572 		Map<String, String> params = new HashMap<>();
573 		params.put("@{propertyName}", "@{propertyValue}"); //$NON-NLS-1$//$NON-NLS-2$
574 		script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME, "@{dir}", TARGET_GATHER_BIN_PARTS, null, null, params); //$NON-NLS-1$
575 
576 		params.put(PROPERTY_PROJECT_LOCATION, "${basedir}/@{dir}"); //$NON-NLS-1$
577 		params.put(PROPERTY_PROJECT_NAME, "@{projectName}"); //$NON-NLS-1$
578 		params.put(PROPERTY_TARGET_FOLDER, "@{propertyValue}@{subFolder}"); //$NON-NLS-1$
579 		printCustomAssemblyAntCall(TARGET_GATHER_BIN_PARTS, params);
580 
581 		script.printEndMacroDef();
582 		script.println();
583 	}
584 
printCustomGatherCall(String fullName, String dir, String propertyName, String propertyValue, String subFolder)585 	protected void printCustomGatherCall(String fullName, String dir, String propertyName, String propertyValue, String subFolder) {
586 		script.println("<" + PROPERTY_CUSTOM_GATHER + " dir=\"" + dir + "\" projectName=\"" + fullName + "\" propertyName=\"" + propertyName + "\" propertyValue=\"" + propertyValue + "\" subFolder=\"" + (subFolder != null ? subFolder : "") + "\" />"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
587 	}
588 
generateInitializationSteps()589 	private void generateInitializationSteps() {
590 		if (BundleHelper.getDefault().isDebugging()) {
591 			script.printEchoTask("basedir : " + Utils.getPropertyFormat(PROPERTY_BASEDIR)); //$NON-NLS-1$
592 			script.printEchoTask("assemblyTempDir : " + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP)); //$NON-NLS-1$
593 			script.printEchoTask("eclipse.base : " + Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE)); //$NON-NLS-1$
594 			script.printEchoTask("collectingFolder : " + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER)); //$NON-NLS-1$
595 			script.printEchoTask("archivePrefix : " + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX)); //$NON-NLS-1$
596 		}
597 
598 		script.println("<condition property=\"" + PROPERTY_PLUGIN_ARCHIVE_PREFIX + "\" value=\"" + DEFAULT_PLUGIN_LOCATION + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
599 		script.println("\t<equals arg1=\"" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + "\"  arg2=\"\" trim=\"true\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
600 		script.println("</condition>"); //$NON-NLS-1$
601 		script.printProperty(PROPERTY_PLUGIN_ARCHIVE_PREFIX, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + '/' + DEFAULT_PLUGIN_LOCATION);
602 
603 		script.println();
604 		script.println("<condition property=\"" + PROPERTY_FEATURE_ARCHIVE_PREFIX + "\" value=\"" + DEFAULT_FEATURE_LOCATION + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
605 		script.println("\t<equals arg1=\"" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + "\"  arg2=\"\" trim=\"true\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
606 		script.println("</condition>"); //$NON-NLS-1$
607 		script.printProperty(PROPERTY_FEATURE_ARCHIVE_PREFIX, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + '/' + DEFAULT_FEATURE_LOCATION);
608 
609 		script.println();
610 
611 		script.printDirName(PROPERTY_ARCHIVE_PARENT, Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH));
612 		script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_PARENT));
613 		script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP));
614 		script.printMkdirTask(Utils.getPropertyFormat(PROPERTY_BUILD_LABEL));
615 		script.println();
616 	}
617 
generatePostProcessingTarget()618 	protected void generatePostProcessingTarget() {
619 		script.printTargetDeclaration(TARGET_JAR_PROCESSING, null, null, null, null);
620 		for (int i = 0; i < plugins.length; i++) {
621 			BundleDescription plugin = plugins[i];
622 			generatePostProcessingSteps(plugin.getSymbolicName(), plugin.getVersion().toString(), (String) shapeAdvisor.getFinalShape(plugin)[1], BUNDLE_TYPE);
623 		}
624 
625 		for (int i = 0; i < features.length; i++) {
626 			BuildTimeFeature feature = features[i];
627 			generatePostProcessingSteps(feature.getId(), feature.getVersion(), (String) shapeAdvisor.getFinalShape(feature)[1], FEATURE_TYPE);
628 		}
629 		printCustomAssemblyAntCall(PROPERTY_POST + TARGET_JARUP, null);
630 		script.printTargetEnd();
631 		script.println();
632 	}
633 
generateGatherBinPartsTarget()634 	protected void generateGatherBinPartsTarget() {
635 		script.printTargetDeclaration(TARGET_GATHER_BIN_PARTS, null, null, null, null);
636 		for (int i = 0; i < plugins.length; i++) {
637 			BundleDescription plugin = plugins[i];
638 			String placeToGather = getLocation(plugin);
639 			printCustomGatherCall(ModelBuildScriptGenerator.getNormalizedName(plugin), Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), PROPERTY_DESTINATION_TEMP_FOLDER, Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS), null);
640 		}
641 
642 		Set<BuildTimeFeature> featureSet = new HashSet<>();
643 		for (int i = 0; i < features.length; i++) {
644 			BuildTimeFeature feature = features[i];
645 			String placeToGather = feature.getRootLocation();
646 			String featureFullName = feature.getId() + "_" + feature.getVersion(); //$NON-NLS-1$
647 			printCustomGatherCall(featureFullName, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), PROPERTY_FEATURE_BASE, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), '/' + DEFAULT_FEATURE_LOCATION);
648 			featureSet.add(feature);
649 		}
650 
651 		//This will generate gather.bin.parts call to features that provides files for the root
652 		for (Iterator<BuildTimeFeature> iter = rootFileProviders.iterator(); iter.hasNext();) {
653 			BuildTimeFeature feature = iter.next();
654 			if (featureSet.contains(feature))
655 				continue;
656 			String placeToGather = feature.getRootLocation();
657 			String featureFullName = feature.getId() + "_" + feature.getVersion(); //$NON-NLS-1$
658 			printCustomGatherCall(featureFullName, Utils.makeRelative(new Path(placeToGather), new Path(workingDirectory)).toOSString(), PROPERTY_FEATURE_BASE, Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), '/' + DEFAULT_FEATURE_LOCATION);
659 		}
660 		script.printTargetEnd();
661 		script.println();
662 	}
663 
generateSignJarCall(String name, String version, byte type)664 	private void generateSignJarCall(String name, String version, byte type) {
665 		if (!signJars)
666 			return;
667 		Map<String, String> properties = new HashMap<>(2);
668 		properties.put(PROPERTY_SOURCE, type == BUNDLE_TYPE ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) : Utils.getPropertyFormat(PROPERTY_ECLIPSE_FEATURES));
669 		properties.put(PROPERTY_ELEMENT_NAME, name + '_' + version);
670 		script.printAntCallTask(TARGET_JARSIGNING, true, properties);
671 	}
672 
673 	//generate the appropriate postProcessingCall
generatePostProcessingSteps(String name, String version, String style, byte type)674 	private void generatePostProcessingSteps(String name, String version, String style, byte type) {
675 		if (ShapeAdvisor.FOLDER.equalsIgnoreCase(style))
676 			return;
677 		if (ShapeAdvisor.FILE.equalsIgnoreCase(style)) {
678 			generateJarUpCall(name, version, type);
679 			generateSignJarCall(name, version, type);
680 			generateJNLPCall(name, version, type);
681 			return;
682 		}
683 	}
684 
generateJNLPCall(String name, String version, byte type)685 	private void generateJNLPCall(String name, String version, byte type) {
686 		if (generateJnlp == false)
687 			return;
688 		if (type != FEATURE_TYPE)
689 			return;
690 
691 		String dir = type == BUNDLE_TYPE ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) : Utils.getPropertyFormat(PROPERTY_ECLIPSE_FEATURES);
692 		String location = dir + '/' + name + '_' + version + ".jar"; //$NON-NLS-1$
693 		script.println("<eclipse.jnlpGenerator feature=\"" + AntScript.getEscaped(location) + "\"  codebase=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_CODEBASE) + "\" j2se=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_J2SE) + "\" locale=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_LOCALE) + "\" generateOfflineAllowed=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_GENOFFLINE) + "\" configInfo=\"" + Utils.getPropertyFormat(PROPERTY_JNLP_CONFIGS) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
694 	}
695 
generateJarUpCall(String name, String version, byte type)696 	private void generateJarUpCall(String name, String version, byte type) {
697 		Map<String, String> properties = new HashMap<>(2);
698 		properties.put(PROPERTY_SOURCE, type == BUNDLE_TYPE ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_PLUGINS) : Utils.getPropertyFormat(PROPERTY_ECLIPSE_FEATURES));
699 		properties.put(PROPERTY_ELEMENT_NAME, name + '_' + version);
700 		script.printAntCallTask(TARGET_JARUP, true, properties);
701 	}
702 
generateEpilogue()703 	private void generateEpilogue() {
704 		generateGatherBinPartsTarget();
705 		if (embeddedSource)
706 			generateGatherSourceTarget();
707 		generatePostProcessingTarget();
708 		generateArchivingTarget(true);
709 		generateCleanupAssembly(true);
710 		if (FORMAT_TAR.equalsIgnoreCase(archiveFormat))
711 			generateGZipTarget(true);
712 
713 		generateCustomAssemblyTarget();
714 		generateMetadataTarget();
715 		generateDirectorTarget(true);
716 		if (BuildDirector.p2Gathering) {
717 			generateMirrorTask(true);
718 			generateMirrorProductTask();
719 		}
720 
721 		script.printProjectEnd();
722 		script.close();
723 		script = null;
724 	}
725 
getTargetName()726 	public String getTargetName() {
727 		String config = getTargetConfig();
728 		return DEFAULT_ASSEMBLE_NAME + '.' + getTargetElement() + (config.length() > 0 ? "." : "") + config; //$NON-NLS-1$ //$NON-NLS-2$
729 	}
730 
getTargetConfig()731 	public String getTargetConfig() {
732 		return (configInfo.equals(Config.genericConfig()) ? "" : configInfo.toStringReplacingAny(".", ANY_STRING)); //$NON-NLS-1$ //$NON-NLS-2$
733 	}
734 
getTargetElement()735 	public String getTargetElement() {
736 		return (featureId.equals("") ? "" : featureId); //$NON-NLS-1$ //$NON-NLS-2$
737 	}
738 
printCustomAssemblyAntCall(String customTarget, Map<String, String> properties)739 	protected void printCustomAssemblyAntCall(String customTarget, Map<String, String> properties) {
740 		Map<String, String> params = (properties != null) ? new HashMap<>(properties) : new HashMap<>(1);
741 		params.put(PROPERTY_CUSTOM_TARGET, customTarget);
742 		script.printAntCallTask(TARGET_CUSTOM_ASSEMBLY, true, params);
743 	}
744 
generateCustomAssemblyTarget()745 	protected void generateCustomAssemblyTarget() {
746 		script.printTargetDeclaration(TARGET_CUSTOM_ASSEMBLY, null, PROPERTY_CUSTOM_ASSEMBLY, null, null);
747 		script.printAntTask(Utils.getPropertyFormat(PROPERTY_CUSTOM_ASSEMBLY), null, Utils.getPropertyFormat(PROPERTY_CUSTOM_TARGET), null, TRUE, null);
748 		script.printTargetEnd();
749 		script.println();
750 	}
751 
generateMetadataTarget()752 	private void generateMetadataTarget() {
753 		if (haveP2Bundles()) {
754 			script.printTargetDeclaration(TARGET_P2_METADATA, null, TARGET_P2_METADATA, null, null);
755 			script.printProperty(PROPERTY_P2_APPEND, "true"); //$NON-NLS-1$
756 			script.printProperty(PROPERTY_P2_COMPRESS, "false"); //$NON-NLS-1$
757 			script.printProperty(PROPERTY_P2_METADATA_REPO_NAME, ""); //$NON-NLS-1$
758 			script.printProperty(PROPERTY_P2_ARTIFACT_REPO_NAME, ""); //$NON-NLS-1$
759 
760 			if (havePDEUIState()) {
761 				//during feature export we need to override the "mode"
762 				printP2GenerationModeCondition();
763 			}
764 			if (!BuildDirector.p2Gathering) {
765 				script.printTab();
766 				script.print("<p2.generator "); //$NON-NLS-1$
767 				script.printAttribute("source", Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), true); //$NON-NLS-1$
768 				script.printAttribute("append", Utils.getPropertyFormat(PROPERTY_P2_APPEND), true); //$NON-NLS-1$
769 				script.printAttribute("flavor", Utils.getPropertyFormat(PROPERTY_P2_FLAVOR), true); //$NON-NLS-1$
770 				script.printAttribute("compress", Utils.getPropertyFormat(PROPERTY_P2_COMPRESS), true); //$NON-NLS-1$
771 				script.printAttribute("metadataRepository", Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO), true); //$NON-NLS-1$
772 				script.printAttribute("artifactRepository", Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO), true); //$NON-NLS-1$
773 				script.printAttribute("metadataRepositoryName", Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO_NAME), true); //$NON-NLS-1$
774 				script.printAttribute("artifactRepositoryName", Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO_NAME), true); //$NON-NLS-1$
775 				script.printAttribute("publishArtifacts", Utils.getPropertyFormat(PROPERTY_P2_PUBLISH_ARTIFACTS), true); //$NON-NLS-1$
776 				script.printAttribute("site", Utils.getPropertyFormat(PROPERTY_P2_CATEGORY_SITE), true); //$NON-NLS-1$
777 				script.printAttribute("siteVersion", Utils.getPropertyFormat(PROPERTY_P2_CATEGORY_VERSION), true); //$NON-NLS-1$
778 				script.printAttribute("p2OS", configInfo.getOs(), true); //$NON-NLS-1$
779 				if (!havePDEUIState() || rootFileProviders.size() > 0)
780 					script.printAttribute("mode", "incremental", true); //$NON-NLS-1$ //$NON-NLS-2$
781 				else
782 					script.printAttribute("mode", Utils.getPropertyFormat(PROPERTY_P2_GENERATION_MODE), true); //$NON-NLS-1$
783 				script.println("/>"); //$NON-NLS-1$
784 			}
785 			if (rootFileProviders.size() > 0) {
786 				if (productFile != null) {
787 					script.println();
788 					File modFile = productFile.getLocation();
789 					String modLocation = Utils.getPropertyFormat(PROPERTY_BUILD_DIRECTORY) + '/' + DEFAULT_FEATURE_LOCATION + '/' + CONTAINER_FEATURE + "/product/" + modFile.getName(); //$NON-NLS-1$
790 					script.printAvailableTask(PROPERTY_P2_PRODUCT_MOD, modLocation, modLocation);
791 					script.printProperty(PROPERTY_P2_PRODUCT_MOD, productFile.getLocation().getPath());
792 				}
793 				script.printTab();
794 				script.print("<p2.generator "); //$NON-NLS-1$
795 				script.printAttribute("config", rootFolder, true); //$NON-NLS-1$
796 				script.printAttribute("append", Utils.getPropertyFormat(PROPERTY_P2_APPEND), true); //$NON-NLS-1$
797 				script.printAttribute("flavor", Utils.getPropertyFormat(PROPERTY_P2_FLAVOR), true); //$NON-NLS-1$
798 				script.printAttribute("compress", Utils.getPropertyFormat(PROPERTY_P2_COMPRESS), true); //$NON-NLS-1$
799 				script.printAttribute("metadataRepository", Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO), true); //$NON-NLS-1$
800 				script.printAttribute("artifactRepository", Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO), true); //$NON-NLS-1$
801 				script.printAttribute("metadataRepositoryName", Utils.getPropertyFormat(PROPERTY_P2_METADATA_REPO_NAME), true); //$NON-NLS-1$
802 				script.printAttribute("artifactRepositoryName", Utils.getPropertyFormat(PROPERTY_P2_ARTIFACT_REPO_NAME), true); //$NON-NLS-1$
803 				script.printAttribute("launcherConfig", configInfo.toString(), true); //$NON-NLS-1$
804 				script.printAttribute("p2OS", configInfo.getOs(), true); //$NON-NLS-1$
805 				script.printAttribute("publishArtifacts", Utils.getPropertyFormat(PROPERTY_P2_PUBLISH_ARTIFACTS), true); //$NON-NLS-1$
806 				if (!havePDEUIState())
807 					script.printAttribute("mode", "incremental", true); //$NON-NLS-1$ //$NON-NLS-2$
808 				else
809 					script.printAttribute("mode", Utils.getPropertyFormat(PROPERTY_P2_GENERATION_MODE), true); //$NON-NLS-1$
810 				if (productFile != null) {
811 					script.printAttribute("exe", rootFolder + '/' + Utils.getPropertyFormat(PROPERTY_LAUNCHER_NAME), true); //$NON-NLS-1$
812 					script.printAttribute("productFile", Utils.getPropertyFormat(PROPERTY_P2_PRODUCT_MOD), true); //$NON-NLS-1$
813 				} else {
814 					script.printAttribute("root", Utils.getPropertyFormat(PROPERTY_P2_ROOT_NAME), true); //$NON-NLS-1$
815 					script.printAttribute("rootVersion", Utils.getPropertyFormat(PROPERTY_P2_ROOT_VERSION), true); //$NON-NLS-1$
816 				}
817 				script.println("/>"); //$NON-NLS-1$
818 			}
819 
820 			script.printTargetEnd();
821 			script.println();
822 		}
823 	}
824 
printP2GenerationModeCondition()825 	protected void printP2GenerationModeCondition() {
826 		// "final" if not running packager and we are overriding, else "incremental"
827 		script.print("<condition"); //$NON-NLS-1$
828 		script.printAttribute("property", PROPERTY_P2_GENERATION_MODE, true); //$NON-NLS-1$
829 		script.printAttribute("value", "final", true); //$NON-NLS-1$ //$NON-NLS-2$
830 		script.printAttribute("else", "incremental", false); //$NON-NLS-1$ //$NON-NLS-2$
831 		script.println(">"); //$NON-NLS-1$
832 		script.println("\t<and>"); //$NON-NLS-1$
833 		script.println("\t\t<not>"); //$NON-NLS-1$
834 		script.println("\t\t\t<isset property=\"runPackager\"/>"); //$NON-NLS-1$
835 		script.println("\t\t</not>"); //$NON-NLS-1$
836 		script.println("\t\t<isset property=\"" + PROPERTY_P2_FINAL_MODE_OVERRIDE + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
837 		script.println("\t</and>"); //$NON-NLS-1$
838 		script.printEndTag("condition"); //$NON-NLS-1$
839 	}
840 
haveP2Bundles()841 	public boolean haveP2Bundles() {
842 		if (p2Bundles != null)
843 			return p2Bundles.booleanValue();
844 
845 		p2Bundles = Boolean.valueOf(loadP2Class());
846 		return p2Bundles.booleanValue();
847 	}
848 
generateZipTarget()849 	private void generateZipTarget() {
850 		final int parameterSize = 15;
851 		List<String> parameters = new ArrayList<>(parameterSize + 1);
852 
853 		if (BuildDirector.p2Gathering) {
854 			parameters.add(Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX));
855 			createZipExecCommand(parameters);
856 			return;
857 		}
858 
859 		for (int i = 0; i < plugins.length; i++) {
860 			parameters.add(Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + (String) shapeAdvisor.getFinalShape(plugins[i])[0]);
861 			if (i % parameterSize == 0) {
862 				createZipExecCommand(parameters);
863 				parameters.clear();
864 			}
865 		}
866 		if (!parameters.isEmpty()) {
867 			createZipExecCommand(parameters);
868 			parameters.clear();
869 		}
870 
871 		if (!parameters.isEmpty()) {
872 			createZipExecCommand(parameters);
873 			parameters.clear();
874 		}
875 
876 		for (int i = 0; i < features.length; i++) {
877 			parameters.add(Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + (String) shapeAdvisor.getFinalShape(features[i])[0]);
878 			if (i % parameterSize == 0) {
879 				createZipExecCommand(parameters);
880 				parameters.clear();
881 			}
882 		}
883 		if (!parameters.isEmpty()) {
884 			createZipExecCommand(parameters);
885 			parameters.clear();
886 		}
887 
888 		createZipRootFileCommand();
889 	}
890 
891 	/**
892 	 *  Zip the root files
893 	 */
createZipRootFileCommand()894 	private void createZipRootFileCommand() {
895 		if (rootFileProviders.size() == 0)
896 			return;
897 
898 		List<String> parameters = new ArrayList<>(1);
899 		parameters.add("-r -q ${zipargs} '" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + "' . "); //$NON-NLS-1$ //$NON-NLS-2$
900 		script.printExecTask("zip", Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING), parameters, null); //$NON-NLS-1$ //$NON-NLS-2$
901 	}
902 
createZipExecCommand(List<String> parameters)903 	private void createZipExecCommand(List<String> parameters) {
904 		parameters.add(0, "-r -q " + Utils.getPropertyFormat(PROPERTY_ZIP_ARGS) + " '" + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + '\''); //$NON-NLS-1$ //$NON-NLS-2$
905 		script.printExecTask("zip", Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP), parameters, null); //$NON-NLS-1$
906 	}
907 
computeArchiveName()908 	protected String computeArchiveName() {
909 		String extension = (FORMAT_TAR.equalsIgnoreCase(archiveFormat) || FORMAT_ANTTAR.equalsIgnoreCase(archiveFormat)) ? ".tar.gz" : ".zip"; //$NON-NLS-1$ //$NON-NLS-2$
910 		return featureId + "-" + Utils.getPropertyFormat(PROPERTY_BUILD_ID_PARAM) + (configInfo.equals(Config.genericConfig()) ? "" : ("-" + configInfo.toStringReplacingAny(".", ANY_STRING))) + extension; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
911 	}
912 
generateTarGZTasks(boolean assembling)913 	public void generateTarGZTasks(boolean assembling) {
914 		//This task only supports creation of archive with eclipse at the root
915 		//Need to do the copy using cp because of the link
916 		List<String> parameters = new ArrayList<>(2);
917 		if (rootFileProviders.size() > 0) {
918 			parameters.add("-r '" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + "' '" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '\''); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
919 			script.printExecTask("cp", Utils.getPropertyFormat(PROPERTY_BASEDIR), parameters, null); //$NON-NLS-1$
920 
921 			parameters.clear();
922 			parameters.add("-rf '" + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '/' + Utils.getPropertyFormat(PROPERTY_COLLECTING_FOLDER) + '/' + configInfo.toStringReplacingAny(".", ANY_STRING) + '\''); //$NON-NLS-1$ //$NON-NLS-2$
923 			script.printExecTask("rm", Utils.getPropertyFormat(PROPERTY_BASEDIR), parameters, null); //$NON-NLS-1$
924 		}
925 		parameters.clear();
926 		String tarArgs = assembling ? "-cvf '" : "-rvf '"; //$NON-NLS-1$//$NON-NLS-2$
927 		parameters.add(Utils.getPropertyFormat(PROPERTY_TAR_ARGS) + tarArgs + Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH) + "' " + ((BuildDirector.p2Gathering && productFile == null) ? "." : Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX)) + ' '); //$NON-NLS-1$ //$NON-NLS-2$
928 		String folder = (BuildDirector.p2Gathering && productFile == null) ? Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) : Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP);
929 		script.printExecTask("tar", folder, parameters, null); //$NON-NLS-1$
930 
931 		script.printAntCallTask(TARGET_GZIP_RESULTS, true, null);
932 
933 		List<String> args = new ArrayList<>(2);
934 		args.add("-rf"); //$NON-NLS-1$
935 		args.add('\'' + Utils.getPropertyFormat(PROPERTY_ASSEMBLY_TMP) + '\'');
936 		script.printExecTask("rm", null, args, null); //$NON-NLS-1$
937 	}
938 
939 	//TODO this code and the generateAntTarTarget() should be refactored using a factory or something like that.
generateAntZipTarget()940 	protected void generateAntZipTarget() {
941 		List<FileSet> fileSets = new ArrayList<>();
942 
943 		if (BuildDirector.p2Gathering) {
944 			//TODO permissions
945 			FileSet[] permissions = generatePermissions(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), true);
946 			String toExcludeFromArchive = Utils.getStringFromCollection(this.addedByPermissions, ","); //$NON-NLS-1$
947 			fileSets.add(new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), false, null, "**/**", null, toExcludeFromArchive, null, productFile != null ? Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) : null, null, null)); //$NON-NLS-1$
948 			fileSets.addAll(Arrays.asList(permissions));
949 		} else {
950 			for (int i = 0; i < plugins.length; i++) {
951 				Object[] shape = shapeAdvisor.getFinalShape(plugins[i]);
952 				fileSets.add(new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + (String) shape[0], shape[1] == ShapeAdvisor.FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + (String) shape[0], null, null));
953 			}
954 
955 			for (int i = 0; i < features.length; i++) {
956 				Object[] shape = shapeAdvisor.getFinalShape(features[i]);
957 				fileSets.add(new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_FEATURE_LOCATION + '/' + (String) shape[0], shape[1] == ShapeAdvisor.FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + (String) shape[0], null, null));
958 			}
959 
960 			if (rootFileProviders.size() > 0) {
961 				if (groupConfigs) {
962 					List<Config> allConfigs = getConfigInfos();
963 					for (Iterator<Config> iter = allConfigs.iterator(); iter.hasNext();) {
964 						Config elt = iter.next();
965 						fileSets.add(new ZipFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + elt.toStringReplacingAny(".", ANY_STRING), false, null, "**/**", null, null, null, elt.toStringReplacingAny(".", ANY_STRING), null, null)); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
966 					}
967 				} else {
968 					FileSet[] permissions = generatePermissions(rootFolder, true);
969 					String toExcludeFromArchive = Utils.getStringFromCollection(this.addedByPermissions, ","); //$NON-NLS-1$
970 					fileSets.add(new ZipFileSet(rootFolder, false, null, "**/**", null, toExcludeFromArchive, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX), null, null)); //$NON-NLS-1$
971 					fileSets.addAll(Arrays.asList(permissions));
972 				}
973 			}
974 		}
975 		if (fileSets.size() > 0) {
976 			FileSet[] sets = fileSets.toArray(new FileSet[fileSets.size()]);
977 			script.printZipTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, sets);
978 		}
979 	}
980 
getArchiveRootFileProviders()981 	protected Collection<BuildTimeFeature> getArchiveRootFileProviders() {
982 		return rootFileProviders != null ? rootFileProviders : new ArrayList<>(0);
983 	}
984 
generatePermissions(String root, boolean zip)985 	protected FileSet[] generatePermissions(String root, boolean zip) {
986 		String configInfix = configInfo.toString("."); //$NON-NLS-1$
987 		String prefixPermissions = ROOT_PREFIX + configInfix + '.' + PERMISSIONS + '.';
988 		String commonPermissions = ROOT_PREFIX + PERMISSIONS + '.';
989 		ArrayList<ZipFileSet> fileSets = new ArrayList<>();
990 
991 		for (Iterator<BuildTimeFeature> iter = getArchiveRootFileProviders().iterator(); iter.hasNext();) {
992 			Properties featureProperties = getFeatureBuildProperties(iter.next());
993 			for (Iterator<Map.Entry<Object, Object>> iter2 = featureProperties.entrySet().iterator(); iter2.hasNext();) {
994 				Map.Entry<Object, Object> permission = iter2.next();
995 				String instruction = (String) permission.getKey();
996 				String parameters = (String) permission.getValue();
997 				String[] values = Utils.getArrayFromString(parameters);
998 				for (int i = 0; i < values.length; i++) {
999 					boolean isFile = !values[i].endsWith("/"); //$NON-NLS-1$
1000 					if (instruction.startsWith(prefixPermissions)) {
1001 						addedByPermissions.add(values[i]);
1002 						if (zip)
1003 							fileSets.add(new ZipFileSet(root + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(prefixPermissions.length()))); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
1004 						else
1005 							fileSets.add(new TarFileSet(root + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(prefixPermissions.length()))); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
1006 						continue;
1007 					}
1008 					if (instruction.startsWith(commonPermissions)) {
1009 						addedByPermissions.add(values[i]);
1010 						if (zip)
1011 							fileSets.add(new ZipFileSet(root + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(commonPermissions.length()))); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
1012 						else
1013 							fileSets.add(new TarFileSet(root + (isFile ? '/' + values[i] : ""), isFile, null, isFile ? null : values[i] + "/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) + (isFile ? '/' + values[i] : ""), null, instruction.substring(commonPermissions.length()))); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
1014 						continue;
1015 					}
1016 				}
1017 			}
1018 		}
1019 		return fileSets.toArray(new FileSet[fileSets.size()]);
1020 	}
1021 
1022 	//TODO this code andn the generateAntZipTarget() should be refactored using a factory or something like that.
generateAntTarTarget()1023 	private void generateAntTarTarget() {
1024 		List<Object> fileSets = new ArrayList<>();
1025 
1026 		if (BuildDirector.p2Gathering) {
1027 			FileSet[] permissions = generatePermissions(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), false);
1028 			String toExcludeFromArchive = Utils.getStringFromCollection(this.addedByPermissions, ","); //$NON-NLS-1$
1029 			fileSets.add(new TarFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE), false, null, "**/**", null, toExcludeFromArchive, null, productFile != null ? Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX) : null, null, null)); //$NON-NLS-1$
1030 			fileSets.addAll(Arrays.asList(permissions));
1031 		} else {
1032 			//FileSet[] filesPlugins = new FileSet[plugins.length];
1033 			for (int i = 0; i < plugins.length; i++) {
1034 				Object[] shape = shapeAdvisor.getFinalShape(plugins[i]);
1035 				fileSets.add(new TarFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_PLUGIN_LOCATION + '/' + (String) shape[0], shape[1] == ShapeAdvisor.FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_PLUGIN_ARCHIVE_PREFIX) + '/' + (String) shape[0], null, null));
1036 			}
1037 
1038 			for (int i = 0; i < features.length; i++) {
1039 				Object[] shape = shapeAdvisor.getFinalShape(features[i]);
1040 				fileSets.add(new TarFileSet(Utils.getPropertyFormat(PROPERTY_ECLIPSE_BASE) + '/' + DEFAULT_FEATURE_LOCATION + '/' + (String) shape[0], shape[1] == ShapeAdvisor.FILE, null, null, null, null, null, Utils.getPropertyFormat(PROPERTY_FEATURE_ARCHIVE_PREFIX) + '/' + (String) shape[0], null, null));
1041 			}
1042 
1043 			if (rootFileProviders.size() > 0) {
1044 				FileSet[] permissionSets = generatePermissions(rootFolder, false);
1045 				fileSets.add(new TarFileSet(rootFolder, false, null, "**/**", null, null, null, Utils.getPropertyFormat(PROPERTY_ARCHIVE_PREFIX), null, null)); //$NON-NLS-1$
1046 				fileSets.add(Arrays.asList(permissionSets));
1047 			}
1048 		}
1049 		if (fileSets.size() > 0) {
1050 			FileSet[] sets = fileSets.toArray(new FileSet[fileSets.size()]);
1051 			script.printTarTask(Utils.getPropertyFormat(PROPERTY_ARCHIVE_FULLPATH), null, false, true, sets);
1052 		}
1053 	}
1054 
setGenerateJnlp(boolean value)1055 	public void setGenerateJnlp(boolean value) {
1056 		generateJnlp = value;
1057 	}
1058 
setSignJars(boolean value)1059 	public void setSignJars(boolean value) {
1060 		signJars = value;
1061 	}
1062 
isSigning()1063 	public boolean isSigning() {
1064 		return signJars;
1065 	}
1066 
setProduct(String value)1067 	public void setProduct(String value) {
1068 		product = value;
1069 	}
1070 
setDirectory(String directory)1071 	public void setDirectory(String directory) {
1072 		this.directory = directory;
1073 	}
1074 
getProductFile()1075 	public ProductFile getProductFile() {
1076 		if (productFile == null && product != null) {
1077 			try {
1078 				// Note that we must pass the OS information in to load product
1079 				// so that any icon files can be calculated for the
1080 				// generateBrandingCalls.
1081 				productFile = loadProduct(product, configInfo != null ? configInfo.getOs() : null);
1082 			} catch (CoreException e) {
1083 				//ignore
1084 			}
1085 		}
1086 		return productFile;
1087 	}
1088 
setArchiveFormat(String archiveFormat)1089 	public void setArchiveFormat(String archiveFormat) {
1090 		this.archiveFormat = archiveFormat;
1091 	}
1092 
setGroupConfigs(boolean group)1093 	public void setGroupConfigs(boolean group) {
1094 		groupConfigs = group;
1095 	}
1096 }
1097