KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > AssembleScriptGenerator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build;
12
13 import java.util.*;
14 import org.eclipse.core.runtime.CoreException;
15
16 public class AssembleScriptGenerator extends AbstractScriptGenerator {
17     protected String JavaDoc directory; // representing the directory where to generate the file
18
protected AssemblyInformation assemblageInformation;
19     protected String JavaDoc featureId;
20     protected HashMap archivesFormat;
21     protected boolean groupConfigs = false;
22
23     protected AssembleConfigScriptGenerator configScriptGenerator;
24
25     public AssembleScriptGenerator(String JavaDoc directory, AssemblyInformation assemblageInformation, String JavaDoc featureId) {
26         this.directory = directory;
27         this.assemblageInformation = assemblageInformation;
28         this.featureId = featureId;
29         configScriptGenerator = getConfigScriptGenerator();
30     }
31
32     protected String JavaDoc getScriptName() {
33         return DEFAULT_ASSEMBLE_NAME + '.' + (featureId.equals("") ? "" : featureId + '.') + DEFAULT_ASSEMBLE_ALL; //$NON-NLS-1$//$NON-NLS-2$
34
}
35
36     protected AssembleConfigScriptGenerator getConfigScriptGenerator() {
37         return new AssembleConfigScriptGenerator();
38     }
39
40     public void generate() throws CoreException {
41         try {
42             openScript(directory, getScriptName());
43             printProjectDeclaration();
44             generateMainTarget();
45             script.printProjectEnd();
46         } finally {
47             script.close();
48             script = null;
49         }
50     }
51
52     protected void printProjectDeclaration() {
53         script.printProjectDeclaration("Assemble All Config of " + featureId, TARGET_MAIN, null); //$NON-NLS-1$
54
}
55     
56     protected void generateMainTarget() throws CoreException {
57         script.printTargetDeclaration(TARGET_MAIN, null, null, null, null);
58         
59         if (groupConfigs) {
60             Collection allPlugins = new HashSet();
61             Collection allFeatures = new HashSet();
62             Collection features = new HashSet();
63             Collection rootFiles = new HashSet();
64             for (Iterator allConfigs = getConfigInfos().iterator(); allConfigs.hasNext();) {
65                 Collection[] configInfo = getConfigInfos((Config) allConfigs.next());
66                 allPlugins.addAll(configInfo[0]);
67                 allFeatures.addAll(configInfo[1]);
68                 features.addAll(configInfo[2]);
69                 rootFiles.addAll(configInfo[3]);
70             }
71             basicGenerateAssembleConfigFileTargetCall(new Config("group","group","group") , allPlugins, allFeatures, features, rootFiles);
72         } else {
73             for (Iterator allConfigs = getConfigInfos().iterator(); allConfigs.hasNext();) {
74                 Config current = (Config) allConfigs.next();
75                 Collection[] configInfo = getConfigInfos(current);
76                 basicGenerateAssembleConfigFileTargetCall(current, configInfo[0], configInfo[1], configInfo[2], configInfo[3]);
77             }
78         }
79         script.printTargetEnd();
80     }
81     
82     protected Collection[] getConfigInfos(Config aConfig) {
83         return new Collection[] { assemblageInformation.getCompiledPlugins(aConfig), assemblageInformation.getCompiledFeatures(aConfig), assemblageInformation.getFeatures(aConfig), assemblageInformation.getRootFileProviders(aConfig) };
84     }
85
86     protected void basicGenerateAssembleConfigFileTargetCall(Config aConfig, Collection binaryPlugins, Collection binaryFeatures, Collection allFeatures, Collection rootFiles) throws CoreException {
87         // generate the script for a configuration
88
configScriptGenerator.initialize(directory, featureId, aConfig, binaryPlugins, binaryFeatures, allFeatures, rootFiles);
89         configScriptGenerator.setArchiveFormat((String JavaDoc) archivesFormat.get(aConfig));
90         configScriptGenerator.setBuildSiteFactory(siteFactory);
91         configScriptGenerator.setGroupConfigs(groupConfigs);
92         configScriptGenerator.generate();
93
94         Map params = new HashMap(1);
95         params.put("assembleScriptName", configScriptGenerator.getTargetName() + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$
96
script.printAntTask(Utils.getPropertyFormat(DEFAULT_CUSTOM_TARGETS), null, configScriptGenerator.getTargetName(), null, null, params);
97     }
98
99     public void setSignJars(boolean value) {
100         configScriptGenerator.setSignJars(value);
101     }
102
103     public void setProduct(String JavaDoc value) {
104         configScriptGenerator.setProduct(value);
105     }
106
107     public void setGenerateJnlp(boolean value) {
108         configScriptGenerator.setGenerateJnlp(value);
109     }
110
111     public void setArchivesFormat(HashMap outputFormat) {
112         archivesFormat = outputFormat;
113     }
114     
115     public void setGroupConfigs(boolean group) {
116         groupConfigs = group;
117     }
118 }
119
Popular Tags