001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM - Initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.build;
011:
012: import java.util.*;
013: import org.eclipse.core.runtime.CoreException;
014:
015: public class AssembleScriptGenerator extends AbstractScriptGenerator {
016: protected String directory; // representing the directory where to generate the file
017: protected AssemblyInformation assemblageInformation;
018: protected String featureId;
019: protected HashMap archivesFormat;
020: protected boolean groupConfigs = false;
021:
022: protected AssembleConfigScriptGenerator configScriptGenerator;
023:
024: public AssembleScriptGenerator(String directory,
025: AssemblyInformation assemblageInformation, String featureId) {
026: this .directory = directory;
027: this .assemblageInformation = assemblageInformation;
028: this .featureId = featureId;
029: configScriptGenerator = getConfigScriptGenerator();
030: }
031:
032: protected String getScriptName() {
033: return DEFAULT_ASSEMBLE_NAME
034: + '.'
035: + (featureId.equals("") ? "" : featureId + '.') + DEFAULT_ASSEMBLE_ALL; //$NON-NLS-1$//$NON-NLS-2$
036: }
037:
038: protected AssembleConfigScriptGenerator getConfigScriptGenerator() {
039: return new AssembleConfigScriptGenerator();
040: }
041:
042: public void generate() throws CoreException {
043: try {
044: openScript(directory, getScriptName());
045: printProjectDeclaration();
046: generateMainTarget();
047: script.printProjectEnd();
048: } finally {
049: script.close();
050: script = null;
051: }
052: }
053:
054: protected void printProjectDeclaration() {
055: script
056: .printProjectDeclaration(
057: "Assemble All Config of " + featureId, TARGET_MAIN, null); //$NON-NLS-1$
058: }
059:
060: protected void generateMainTarget() throws CoreException {
061: script.printTargetDeclaration(TARGET_MAIN, null, null, null,
062: null);
063:
064: if (groupConfigs) {
065: Collection allPlugins = new HashSet();
066: Collection allFeatures = new HashSet();
067: Collection features = new HashSet();
068: Collection rootFiles = new HashSet();
069: for (Iterator allConfigs = getConfigInfos().iterator(); allConfigs
070: .hasNext();) {
071: Collection[] configInfo = getConfigInfos((Config) allConfigs
072: .next());
073: allPlugins.addAll(configInfo[0]);
074: allFeatures.addAll(configInfo[1]);
075: features.addAll(configInfo[2]);
076: rootFiles.addAll(configInfo[3]);
077: }
078: basicGenerateAssembleConfigFileTargetCall(new Config(
079: "group", "group", "group"), allPlugins,
080: allFeatures, features, rootFiles);
081: } else {
082: for (Iterator allConfigs = getConfigInfos().iterator(); allConfigs
083: .hasNext();) {
084: Config current = (Config) allConfigs.next();
085: Collection[] configInfo = getConfigInfos(current);
086: basicGenerateAssembleConfigFileTargetCall(current,
087: configInfo[0], configInfo[1], configInfo[2],
088: configInfo[3]);
089: }
090: }
091: script.printTargetEnd();
092: }
093:
094: protected Collection[] getConfigInfos(Config aConfig) {
095: return new Collection[] {
096: assemblageInformation.getCompiledPlugins(aConfig),
097: assemblageInformation.getCompiledFeatures(aConfig),
098: assemblageInformation.getFeatures(aConfig),
099: assemblageInformation.getRootFileProviders(aConfig) };
100: }
101:
102: protected void basicGenerateAssembleConfigFileTargetCall(
103: Config aConfig, Collection binaryPlugins,
104: Collection binaryFeatures, Collection allFeatures,
105: Collection rootFiles) throws CoreException {
106: // generate the script for a configuration
107: configScriptGenerator.initialize(directory, featureId, aConfig,
108: binaryPlugins, binaryFeatures, allFeatures, rootFiles);
109: configScriptGenerator.setArchiveFormat((String) archivesFormat
110: .get(aConfig));
111: configScriptGenerator.setBuildSiteFactory(siteFactory);
112: configScriptGenerator.setGroupConfigs(groupConfigs);
113: configScriptGenerator.generate();
114:
115: Map params = new HashMap(1);
116: params
117: .put(
118: "assembleScriptName", configScriptGenerator.getTargetName() + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
119: script.printAntTask(Utils
120: .getPropertyFormat(DEFAULT_CUSTOM_TARGETS), null,
121: configScriptGenerator.getTargetName(), null, null,
122: params);
123: }
124:
125: public void setSignJars(boolean value) {
126: configScriptGenerator.setSignJars(value);
127: }
128:
129: public void setProduct(String value) {
130: configScriptGenerator.setProduct(value);
131: }
132:
133: public void setGenerateJnlp(boolean value) {
134: configScriptGenerator.setGenerateJnlp(value);
135: }
136:
137: public void setArchivesFormat(HashMap outputFormat) {
138: archivesFormat = outputFormat;
139: }
140:
141: public void setGroupConfigs(boolean group) {
142: groupConfigs = group;
143: }
144: }
|