0001: /*******************************************************************************
0002: * Copyright (c) 2000, 2007 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Eclipse Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/epl-v10.html
0007: *
0008: * Contributors:
0009: * IBM - Initial API and implementation
0010: * Prosyst - create proper OSGi bundles (bug 174157)
0011: *******************************************************************************/package org.eclipse.pde.internal.build.builder;
0012:
0013: import java.io.*;
0014: import java.util.*;
0015: import org.eclipse.core.runtime.*;
0016: import org.eclipse.osgi.service.resolver.BundleDescription;
0017: import org.eclipse.osgi.util.NLS;
0018: import org.eclipse.pde.internal.build.*;
0019: import org.eclipse.pde.internal.build.ant.*;
0020: import org.eclipse.pde.internal.build.builder.ClasspathComputer3_0.ClasspathElement;
0021: import org.eclipse.update.core.IPluginEntry;
0022:
0023: /**
0024: * Generic class for generating scripts for plug-ins and fragments.
0025: */
0026: public class ModelBuildScriptGenerator extends
0027: AbstractBuildScriptGenerator {
0028: private static final String SRC_ZIP = "src.zip"; //$NON-NLS-1$
0029: public static final String EXPANDED_DOT = "@dot"; //$NON-NLS-1$
0030: public static final String DOT = "."; //$NON-NLS-1$
0031:
0032: /**
0033: * Represents a entry that must be compiled and which is listed in the build.properties file.
0034: */
0035: protected class CompiledEntry {
0036: static final byte JAR = 0;
0037: static final byte FOLDER = 1;
0038: private String name;
0039: private String resolvedName;
0040: private String[] source;
0041: private String[] output;
0042: private String[] extraClasspath;
0043: private String excludedFromJar;
0044: byte type;
0045:
0046: protected CompiledEntry(String entryName, String[] entrySource,
0047: String[] entryOutput, String[] entryExtraClasspath,
0048: String excludedFromJar, byte entryType) {
0049: this .name = entryName;
0050: this .source = entrySource;
0051: this .output = entryOutput;
0052: this .extraClasspath = entryExtraClasspath;
0053: this .type = entryType;
0054: this .excludedFromJar = excludedFromJar;
0055: }
0056:
0057: protected String getName(boolean resolved) {
0058: if (!resolved)
0059: return name;
0060:
0061: if (resolvedName == null)
0062: resolvedName = replaceVariables(name, true);
0063:
0064: return resolvedName;
0065: }
0066:
0067: protected String[] getSource() {
0068: return source;
0069: }
0070:
0071: public String[] getOutput() {
0072: return output;
0073: }
0074:
0075: public String[] getExtraClasspath() {
0076: return extraClasspath;
0077: }
0078:
0079: public byte getType() {
0080: return type;
0081: }
0082:
0083: public String getExcludedFromJar() {
0084: return excludedFromJar;
0085: }
0086: }
0087:
0088: /**
0089: * Bundle for which we are generating the script.
0090: */
0091: protected BundleDescription model;
0092: /**
0093: * PluginEntry corresponding to the bundle
0094: */
0095: private IPluginEntry associatedEntry;
0096:
0097: protected String fullName;
0098: protected String pluginZipDestination;
0099: protected String pluginUpdateJarDestination;
0100:
0101: private FeatureBuildScriptGenerator featureGenerator;
0102:
0103: /** constants */
0104: protected final String PLUGIN_DESTINATION = Utils
0105: .getPropertyFormat(PROPERTY_PLUGIN_DESTINATION);
0106:
0107: private Properties permissionProperties;
0108:
0109: private String propertiesFileName = PROPERTIES_FILE;
0110: private String buildScriptFileName = DEFAULT_BUILD_SCRIPT_FILENAME;
0111: private String customBuildCallbacks = null;
0112: private String customCallbacksBuildpath = null;
0113: private String customCallbacksFailOnError = null;
0114: private String customCallbacksInheritAll = null;
0115: //This list is initialized by the generateBuildJarsTarget
0116: private ArrayList compiledJarNames;
0117: private boolean dotOnTheClasspath = false;
0118: private boolean binaryPlugin = false;
0119: private boolean signJars = false;
0120:
0121: /**
0122: * @see AbstractScriptGenerator#generate()
0123: */
0124: public void generate() throws CoreException {
0125: //If it is a binary plugin, then we don't generate scripts
0126: if (binaryPlugin)
0127: return;
0128:
0129: if (model == null) {
0130: throw new CoreException(new Status(IStatus.ERROR,
0131: PI_PDEBUILD, EXCEPTION_ELEMENT_MISSING,
0132: Messages.error_missingElement, null));
0133: }
0134:
0135: // If the the plugin we want to generate is a source plugin, and the feature that required the generation of this plugin is not being asked to build the source
0136: // we want to leave. This is particularly usefull for the case of the pde.source building (at least for now since the source of pde is not in a feature)
0137: if (featureGenerator != null
0138: && featureGenerator.isSourceFeatureGeneration() == false
0139: && featureGenerator.getBuildProperties().containsKey(
0140: GENERATION_SOURCE_PLUGIN_PREFIX
0141: + model.getSymbolicName()))
0142: return;
0143:
0144: if (!AbstractScriptGenerator.isBuildingOSGi())
0145: checkBootAndRuntime();
0146:
0147: initializeVariables();
0148: if (BundleHelper.getDefault().isDebugging())
0149: System.out
0150: .println("Generating plugin " + model.getSymbolicName()); //$NON-NLS-1$
0151:
0152: String custom = (String) getBuildProperties().get(
0153: PROPERTY_CUSTOM);
0154: if (custom != null && custom.equalsIgnoreCase("true")) { //$NON-NLS-1$
0155: updateExistingScript();
0156: return;
0157: }
0158:
0159: openScript(getLocation(model), buildScriptFileName);
0160: try {
0161: generateBuildScript();
0162: } finally {
0163: closeScript();
0164: }
0165: }
0166:
0167: /**
0168: * Check that boot and runtime are available, otherwise throws an exception because the build will fail.
0169: */
0170: private void checkBootAndRuntime() throws CoreException {
0171: if (getSite(false).getRegistry().getResolvedBundle(PI_BOOT) == null) {
0172: IStatus status = new Status(IStatus.ERROR, PI_PDEBUILD,
0173: EXCEPTION_PLUGIN_MISSING, NLS.bind(
0174: Messages.exception_missingPlugin, PI_BOOT),
0175: null);
0176: throw new CoreException(status);
0177: }
0178: if (getSite(false).getRegistry().getResolvedBundle(PI_RUNTIME) == null) {
0179: IStatus status = new Status(IStatus.ERROR, PI_PDEBUILD,
0180: EXCEPTION_PLUGIN_MISSING, NLS.bind(
0181: Messages.exception_missingPlugin,
0182: PI_RUNTIME), null);
0183: throw new CoreException(status);
0184: }
0185: }
0186:
0187: public static String getNormalizedName(BundleDescription bundle) {
0188: return bundle.getSymbolicName() + '_' + bundle.getVersion();
0189: }
0190:
0191: private void initializeVariables() throws CoreException {
0192: fullName = getNormalizedName(model);
0193: pluginZipDestination = PLUGIN_DESTINATION + '/' + fullName
0194: + ".zip"; //$NON-NLS-1$
0195: pluginUpdateJarDestination = PLUGIN_DESTINATION + '/'
0196: + fullName + ".jar"; //$NON-NLS-1$
0197: String[] classpathInfo = getClasspathEntries(model);
0198: dotOnTheClasspath = specialDotProcessing(getBuildProperties(),
0199: classpathInfo);
0200:
0201: //Persist this information for use in the assemble script generation
0202: Properties bundleProperties = (Properties) model
0203: .getUserObject();
0204: bundleProperties.put(WITH_DOT, Boolean
0205: .valueOf(dotOnTheClasspath));
0206:
0207: Properties properties = getBuildProperties();
0208: customBuildCallbacks = properties
0209: .getProperty(PROPERTY_CUSTOM_BUILD_CALLBACKS);
0210: if (TRUE.equalsIgnoreCase(customBuildCallbacks))
0211: customBuildCallbacks = DEFAULT_CUSTOM_BUILD_CALLBACKS_FILE;
0212: else if (FALSE.equalsIgnoreCase(customBuildCallbacks))
0213: customBuildCallbacks = null;
0214:
0215: customCallbacksBuildpath = properties.getProperty(
0216: PROPERTY_CUSTOM_CALLBACKS_BUILDPATH, "."); //$NON-NLS-1$
0217: customCallbacksFailOnError = properties.getProperty(
0218: PROPERTY_CUSTOM_CALLBACKS_FAILONERROR, FALSE);
0219: customCallbacksInheritAll = properties
0220: .getProperty(PROPERTY_CUSTOM_CALLBACKS_INHERITALL);
0221: }
0222:
0223: protected static boolean findAndReplaceDot(String[] classpathInfo) {
0224: for (int i = 0; i < classpathInfo.length; i++) {
0225: if (DOT.equals(classpathInfo[i])) {
0226: classpathInfo[i] = EXPANDED_DOT;
0227: return true;
0228: }
0229: }
0230: return false;
0231: }
0232:
0233: public static boolean specialDotProcessing(Properties properties,
0234: String[] classpathInfo) {
0235: findAndReplaceDot(classpathInfo);
0236: String sourceFolder = properties
0237: .getProperty(PROPERTY_SOURCE_PREFIX + DOT);
0238: if (sourceFolder != null) {
0239: properties.setProperty(PROPERTY_SOURCE_PREFIX
0240: + EXPANDED_DOT, sourceFolder);
0241: properties.remove(PROPERTY_SOURCE_PREFIX + DOT);
0242:
0243: String outputValue = properties
0244: .getProperty(PROPERTY_OUTPUT_PREFIX + DOT);
0245: if (outputValue != null) {
0246: properties.setProperty(PROPERTY_OUTPUT_PREFIX
0247: + EXPANDED_DOT, outputValue);
0248: properties.remove(PROPERTY_OUTPUT_PREFIX + DOT);
0249: }
0250: String excludedFromJar = properties
0251: .getProperty(PROPERTY_EXCLUDE_PREFIX + DOT);
0252: if (excludedFromJar != null) {
0253: properties.setProperty(PROPERTY_EXCLUDE_PREFIX
0254: + EXPANDED_DOT, excludedFromJar);
0255: properties.remove(PROPERTY_EXCLUDE_PREFIX + DOT);
0256: }
0257: String buildOrder = properties
0258: .getProperty(PROPERTY_JAR_ORDER);
0259: if (buildOrder != null) {
0260: String[] order = Utils.getArrayFromString(buildOrder);
0261: for (int i = 0; i < order.length; i++)
0262: if (order[i].equals(DOT))
0263: order[i] = EXPANDED_DOT;
0264: properties.setProperty(PROPERTY_JAR_ORDER, Utils
0265: .getStringFromArray(order, ",")); //$NON-NLS-1$
0266: }
0267:
0268: String extraEntries = properties
0269: .getProperty(PROPERTY_EXTRAPATH_PREFIX + '.');
0270: if (extraEntries != null) {
0271: properties.setProperty(PROPERTY_EXTRAPATH_PREFIX
0272: + EXPANDED_DOT, extraEntries);
0273: }
0274:
0275: String includeString = properties
0276: .getProperty(PROPERTY_BIN_INCLUDES);
0277: if (includeString != null) {
0278: String[] includes = Utils
0279: .getArrayFromString(includeString);
0280: for (int i = 0; i < includes.length; i++)
0281: if (includes[i].equals(DOT))
0282: includes[i] = EXPANDED_DOT + '/';
0283: properties.setProperty(PROPERTY_BIN_INCLUDES, Utils
0284: .getStringFromArray(includes, ",")); //$NON-NLS-1$
0285: }
0286: return true;
0287: }
0288: return false;
0289: }
0290:
0291: /**
0292: * Main call for generating the script.
0293: *
0294: * @throws CoreException
0295: */
0296: private void generateBuildScript() throws CoreException {
0297: generatePrologue();
0298: generateBuildUpdateJarTarget();
0299:
0300: if (getBuildProperties().getProperty(SOURCE_PLUGIN, null) == null) {
0301: generateBuildJarsTarget(model);
0302: } else {
0303: generateBuildJarsTargetForSourceGathering();
0304: generateEmptyBuildSourcesTarget();
0305: }
0306: generateGatherBinPartsTarget();
0307: generateBuildZipsTarget();
0308: generateGatherSourcesTarget();
0309: generateGatherLogTarget();
0310: generateCleanTarget();
0311: generateRefreshTarget();
0312: generateZipPluginTarget();
0313: generateEpilogue();
0314: }
0315:
0316: /**
0317: * Method generateEmptyBuildSourceTarget.
0318: */
0319: private void generateEmptyBuildSourcesTarget() {
0320: script.printTargetDeclaration(TARGET_BUILD_SOURCES, null, null,
0321: null, null);
0322: script.printTargetEnd();
0323: }
0324:
0325: /**
0326: * Method generateBuildJarsTargetForSourceGathering.
0327: */
0328: private void generateBuildJarsTargetForSourceGathering() {
0329: script.printTargetDeclaration(TARGET_BUILD_JARS, null, null,
0330: null, null);
0331: compiledJarNames = new ArrayList(0);
0332:
0333: Config configInfo;
0334: if (associatedEntry.getOS() == null
0335: && associatedEntry.getWS() == null
0336: && associatedEntry.getOSArch() == null)
0337: configInfo = Config.genericConfig();
0338: else
0339: configInfo = new Config(associatedEntry.getOS(),
0340: associatedEntry.getWS(), associatedEntry
0341: .getOSArch());
0342:
0343: Set pluginsToGatherSourceFrom = (Set) featureGenerator.sourceToGather
0344: .getElementEntries().get(configInfo);
0345: if (pluginsToGatherSourceFrom != null) {
0346: for (Iterator iter = pluginsToGatherSourceFrom.iterator(); iter
0347: .hasNext();) {
0348: BundleDescription plugin = (BundleDescription) iter
0349: .next();
0350: if (plugin.getSymbolicName().equals(
0351: model.getSymbolicName())) // We are not trying to gather the source from ourself since we are generated and we know we don't have source...
0352: continue;
0353:
0354: // The two steps are required, because some plugins (xerces, junit, ...) don't build their source: the source already comes zipped
0355: IPath location = Utils.makeRelative(new Path(
0356: getLocation(plugin)), new Path(
0357: getLocation(model)));
0358: script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME,
0359: location.toOSString(), TARGET_BUILD_SOURCES,
0360: null, null, null);
0361: HashMap params = new HashMap(1);
0362: params.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils
0363: .getPropertyFormat(PROPERTY_BASEDIR)
0364: + "/src"); //$NON-NLS-1$
0365: script.printAntTask(DEFAULT_BUILD_SCRIPT_FILENAME,
0366: location.toOSString(), TARGET_GATHER_SOURCES,
0367: null, null, params);
0368: }
0369: }
0370: script.printTargetEnd();
0371: }
0372:
0373: /**
0374: * Add the <code>clean</code> target to the given Ant script.
0375: *
0376: * @throws CoreException
0377: */
0378: private void generateCleanTarget() throws CoreException {
0379: script.println();
0380: Properties properties = getBuildProperties();
0381: CompiledEntry[] availableJars = extractEntriesToCompile(properties);
0382: script.printTargetDeclaration(TARGET_CLEAN, TARGET_INIT, null,
0383: null, NLS.bind(Messages.build_plugin_clean, model
0384: .getSymbolicName()));
0385:
0386: Map params = null;
0387: if (customBuildCallbacks != null) {
0388: params = new HashMap(3);
0389: params.put(PROPERTY_PLUGIN_DESTINATION, PLUGIN_DESTINATION);
0390: params.put(PROPERTY_TEMP_FOLDER, Utils
0391: .getPropertyFormat(PROPERTY_TEMP_FOLDER));
0392: params.put(PROPERTY_BUILD_RESULT_FOLDER, Utils
0393: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER));
0394: script
0395: .printSubantTask(
0396: Utils
0397: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0398: PROPERTY_PRE + TARGET_CLEAN,
0399: customCallbacksBuildpath,
0400: customCallbacksFailOnError,
0401: customCallbacksInheritAll, params, null);
0402: }
0403: for (int i = 0; i < availableJars.length; i++) {
0404: String jarName = availableJars[i].getName(true);
0405: String jarLocation = getJARLocation(jarName);
0406: //avoid destructive cleans
0407: if (jarLocation.equals("") || jarLocation.startsWith(DOT + DOT) || jarLocation.equals(Utils.getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER))) //$NON-NLS-1$
0408: continue;
0409: if (availableJars[i].type == CompiledEntry.JAR) {
0410: script.printDeleteTask(null, jarLocation, null);
0411: } else {
0412: script.printDeleteTask(jarLocation, null, null);
0413: }
0414: script.printDeleteTask(null, getSRCLocation(jarName), null);
0415: }
0416: script.printDeleteTask(null, pluginUpdateJarDestination, null);
0417: script.printDeleteTask(null, pluginZipDestination, null);
0418: script.printDeleteTask(Utils
0419: .getPropertyFormat(IXMLConstants.PROPERTY_TEMP_FOLDER),
0420: null, null);
0421:
0422: if (customBuildCallbacks != null) {
0423: script
0424: .printSubantTask(
0425: Utils
0426: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0427: PROPERTY_POST + TARGET_CLEAN,
0428: customCallbacksBuildpath,
0429: customCallbacksFailOnError,
0430: customCallbacksInheritAll, params, null);
0431: }
0432: script.printTargetEnd();
0433: }
0434:
0435: /**
0436: * Add the <code>gather.logs</code> target to the given Ant script.
0437: *
0438: * @throws CoreException
0439: */
0440: private void generateGatherLogTarget() throws CoreException {
0441: script.println();
0442: script.printTargetDeclaration(TARGET_GATHER_LOGS, TARGET_INIT,
0443: PROPERTY_DESTINATION_TEMP_FOLDER, null, null);
0444: IPath baseDestination = new Path(Utils
0445: .getPropertyFormat(PROPERTY_DESTINATION_TEMP_FOLDER));
0446: baseDestination = baseDestination.append(fullName);
0447: Map params = null;
0448: if (customBuildCallbacks != null) {
0449: params = new HashMap(1);
0450: params.put(PROPERTY_DESTINATION_TEMP_FOLDER,
0451: baseDestination.toString());
0452: script
0453: .printSubantTask(
0454: Utils
0455: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0456: PROPERTY_PRE + TARGET_GATHER_LOGS,
0457: customCallbacksBuildpath,
0458: customCallbacksFailOnError,
0459: customCallbacksInheritAll, params, null);
0460: }
0461: List destinations = new ArrayList(5);
0462: Properties properties = getBuildProperties();
0463: CompiledEntry[] availableJars = extractEntriesToCompile(properties);
0464: for (int i = 0; i < availableJars.length; i++) {
0465: String name = availableJars[i].getName(true);
0466: IPath destination = baseDestination.append(name)
0467: .removeLastSegments(1); // remove the jar name
0468: if (!destinations.contains(destination)) {
0469: script.printMkdirTask(destination.toString());
0470: destinations.add(destination);
0471: }
0472: Path logPath = new Path(getTempJARFolderLocation(name)
0473: + Utils.getPropertyFormat(PROPERTY_LOG_EXTENSION));
0474: FileSet logSet = new FileSet(logPath.removeLastSegments(1)
0475: .toString(), null, logPath.lastSegment(), null,
0476: null, null, null);
0477: script.printCopyTask(null, destination.toString(),
0478: new FileSet[] { logSet }, false, false);
0479: }
0480:
0481: if (customBuildCallbacks != null) {
0482: script
0483: .printSubantTask(
0484: Utils
0485: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0486: PROPERTY_POST + TARGET_GATHER_LOGS,
0487: customCallbacksBuildpath,
0488: customCallbacksFailOnError,
0489: customCallbacksInheritAll, params, null);
0490: }
0491: script.printTargetEnd();
0492: }
0493:
0494: /**
0495: *
0496: * @param zipName
0497: * @param source
0498: */
0499: private void generateZipIndividualTarget(String zipName,
0500: String source) {
0501: script.println();
0502: script.printTargetDeclaration(zipName, TARGET_INIT, null, null,
0503: null);
0504: IPath root = new Path(Utils
0505: .getPropertyFormat(IXMLConstants.PROPERTY_BASEDIR));
0506: script.printZipTask(root.append(zipName).toString(), root
0507: .append(source).toString(), false, false, null);
0508: script.printTargetEnd();
0509: }
0510:
0511: /**
0512: * Add the <code>gather.sources</code> target to the given Ant script.
0513: *
0514: * @throws CoreException
0515: */
0516: private void generateGatherSourcesTarget() throws CoreException {
0517: script.println();
0518: script.printTargetDeclaration(TARGET_GATHER_SOURCES,
0519: TARGET_INIT, PROPERTY_DESTINATION_TEMP_FOLDER, null,
0520: null);
0521:
0522: IPath baseDestination = new Path(Utils
0523: .getPropertyFormat(PROPERTY_DESTINATION_TEMP_FOLDER));
0524: baseDestination = baseDestination.append(fullName);
0525: Map params = null;
0526: if (customBuildCallbacks != null) {
0527: params = new HashMap(1);
0528: params.put(PROPERTY_TARGET_FOLDER, baseDestination
0529: .toString());
0530: script
0531: .printSubantTask(
0532: Utils
0533: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0534: PROPERTY_PRE + TARGET_GATHER_SOURCES,
0535: customCallbacksBuildpath,
0536: customCallbacksFailOnError,
0537: customCallbacksInheritAll, params, null);
0538: }
0539: List destinations = new ArrayList(5);
0540: Properties properties = getBuildProperties();
0541: CompiledEntry[] availableJars = extractEntriesToCompile(properties);
0542: for (int i = 0; i < availableJars.length; i++) {
0543: String jar = availableJars[i].getName(true);
0544: IPath destination = baseDestination.append(jar)
0545: .removeLastSegments(1); // remove the jar name
0546: if (!destinations.contains(destination)) {
0547: script.printMkdirTask(destination.toString());
0548: destinations.add(destination);
0549: }
0550: script.printCopyTask(getSRCLocation(jar), destination
0551: .toString(), null, false, false);
0552: }
0553: String include = (String) getBuildProperties().get(
0554: PROPERTY_SRC_INCLUDES);
0555: String exclude = (String) getBuildProperties().get(
0556: PROPERTY_SRC_EXCLUDES);
0557: if (include != null || exclude != null) {
0558: FileSet fileSet = new FileSet(Utils
0559: .getPropertyFormat(PROPERTY_BASEDIR), null,
0560: include, null, exclude, null, null);
0561: script.printCopyTask(null, baseDestination.toString(),
0562: new FileSet[] { fileSet }, false, false);
0563: }
0564:
0565: if (customBuildCallbacks != null) {
0566: script
0567: .printSubantTask(
0568: Utils
0569: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0570: PROPERTY_POST + TARGET_GATHER_SOURCES,
0571: customCallbacksBuildpath,
0572: customCallbacksFailOnError,
0573: customCallbacksInheritAll, params, null);
0574: }
0575: script.printTargetEnd();
0576: }
0577:
0578: /**
0579: * Add the <code>gather.bin.parts</code> target to the given Ant script.
0580: *
0581: * @throws CoreException
0582: */
0583: private void generateGatherBinPartsTarget() throws CoreException {
0584: script.println();
0585: script.printTargetDeclaration(TARGET_GATHER_BIN_PARTS,
0586: TARGET_INIT, PROPERTY_DESTINATION_TEMP_FOLDER, null,
0587: null);
0588: IPath destination = new Path(Utils
0589: .getPropertyFormat(PROPERTY_DESTINATION_TEMP_FOLDER));
0590: destination = destination.append(fullName);
0591: String root = destination.toString();
0592: script.printMkdirTask(root);
0593:
0594: Map params = null;
0595: if (customBuildCallbacks != null) {
0596: params = new HashMap(3);
0597: params.put(PROPERTY_TARGET_FOLDER, root);
0598: params.put(PROPERTY_BUILD_RESULT_FOLDER, Utils
0599: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER));
0600: script
0601: .printSubantTask(
0602: Utils
0603: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0604: PROPERTY_PRE + TARGET_GATHER_BIN_PARTS,
0605: customCallbacksBuildpath,
0606: customCallbacksFailOnError,
0607: customCallbacksInheritAll, params, null);
0608: }
0609:
0610: List destinations = new ArrayList(5);
0611: destinations.add(destination);
0612: String include = (String) getBuildProperties().get(
0613: PROPERTY_BIN_INCLUDES);
0614: String exclude = (String) getBuildProperties().get(
0615: PROPERTY_BIN_EXCLUDES);
0616:
0617: //Copy only the jars that has been compiled and are listed in the includes
0618: String[] splitIncludes = Utils.getArrayFromString(include);
0619: String[] fileSetValues = new String[compiledJarNames.size()];
0620: int count = 0;
0621:
0622: boolean dotIncluded = false; //This flag indicates if . should be gathered
0623: int pos = Utils.isStringIn(splitIncludes, EXPANDED_DOT + '/');
0624: if (pos != -1) {
0625: splitIncludes[pos] = null;
0626: dotIncluded = true;
0627: }
0628:
0629: //Iterate over the classpath
0630: for (Iterator iter = compiledJarNames.iterator(); iter
0631: .hasNext();) {
0632: CompiledEntry entry = (CompiledEntry) iter.next();
0633: String formatedName = entry.getName(false)
0634: + (entry.getType() == CompiledEntry.FOLDER ? "/" : ""); //$NON-NLS-1$//$NON-NLS-2$
0635: if (dotOnTheClasspath
0636: && formatedName.startsWith(EXPANDED_DOT)) {
0637: dotIncluded = dotIncluded & true;
0638: continue;
0639: }
0640: fileSetValues[count++] = formatedName;
0641: continue;
0642: }
0643: if (count != 0) {
0644: FileSet fileSet = new FileSet(
0645: Utils
0646: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER),
0647: null,
0648: Utils.getStringFromArray(fileSetValues, ","), null, replaceVariables(exclude, true), null, null); //$NON-NLS-1$
0649: script.printCopyTask(null, root, new FileSet[] { fileSet },
0650: true, false);
0651: }
0652: //Dot on the classpath need to be copied in a special way
0653: if (dotIncluded) {
0654: FileSet fileSet = new FileSet(
0655: Utils
0656: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER)
0657: + '/' + EXPANDED_DOT,
0658: null,
0659: "**", null, replaceVariables(exclude, true), null, null); //$NON-NLS-1$
0660: script.printCopyTask(null, root, new FileSet[] { fileSet },
0661: true, false);
0662: }
0663: //General copy of the files listed in the includes
0664: if (include != null || exclude != null) {
0665: String includeSet = replaceVariables(Utils
0666: .getStringFromArray(splitIncludes, ","), true); //$NON-NLS-1$
0667: if (includeSet != null && includeSet.length() > 0) {
0668: FileSet fileSet = new FileSet(Utils
0669: .getPropertyFormat(PROPERTY_BASEDIR), null,
0670: includeSet, null, replaceVariables(exclude,
0671: true), null, null);
0672: script.printCopyTask(null, root,
0673: new FileSet[] { fileSet }, true, false);
0674: }
0675: }
0676: generatePermissionProperties(root);
0677: genarateIdReplacementCall(destination.toString());
0678:
0679: if (customBuildCallbacks != null) {
0680: script
0681: .printSubantTask(
0682: Utils
0683: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
0684: PROPERTY_POST + TARGET_GATHER_BIN_PARTS,
0685: customCallbacksBuildpath,
0686: customCallbacksFailOnError,
0687: customCallbacksInheritAll, params, null);
0688: }
0689:
0690: script.printTargetEnd();
0691: }
0692:
0693: private void genarateIdReplacementCall(String location) {
0694: Properties bundleProperties = (Properties) model
0695: .getUserObject();
0696: if (bundleProperties == null)
0697: return;
0698:
0699: String qualifier = bundleProperties
0700: .getProperty(PROPERTY_QUALIFIER);
0701: if (qualifier == null)
0702: return;
0703: script
0704: .println("<eclipse.versionReplacer path=\"" + AntScript.getEscaped(location) + "\" version=\"" + model.getVersion() + "\"/>"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
0705: }
0706:
0707: private void generatePermissionProperties(String directory)
0708: throws CoreException {
0709: getPermissionProperties();
0710: for (Iterator iter = permissionProperties.entrySet().iterator(); iter
0711: .hasNext();) {
0712: Map.Entry permission = (Map.Entry) iter.next();
0713: String instruction = (String) permission.getKey();
0714: String parameters = (String) permission.getValue();
0715: int index;
0716: if ((index = instruction.indexOf(PERMISSIONS)) != -1) {
0717: generateChmodInstruction(directory, instruction
0718: .substring(index + PERMISSIONS.length() + 1),
0719: parameters);
0720: continue;
0721: }
0722: if (instruction.startsWith(LINK)) {
0723: generateLinkInstruction(directory, parameters);
0724: }
0725: }
0726: }
0727:
0728: private void generateChmodInstruction(String dir, String rights,
0729: String files) {
0730: // TO CHECK We only consider rights specified with numbers
0731: if (rights.equals(EXECUTABLE)) {
0732: rights = "755"; //$NON-NLS-1$
0733: }
0734: script.printChmod(dir, rights, files);
0735: }
0736:
0737: private void generateLinkInstruction(String dir, String files) {
0738: String[] links = Utils.getArrayFromString(files, ","); //$NON-NLS-1$
0739: List arguments = new ArrayList(2);
0740: for (int i = 0; i < links.length; i += 2) {
0741: arguments.add(links[i]);
0742: arguments.add(links[i + 1]);
0743: script.printExecTask("ln -s", dir, arguments, "Linux"); //$NON-NLS-1$ //$NON-NLS-2$
0744: arguments.clear();
0745: }
0746: }
0747:
0748: protected Properties getPermissionProperties() throws CoreException {
0749: if (permissionProperties == null) {
0750: permissionProperties = readProperties(getLocation(model),
0751: PERMISSIONS_FILE, IStatus.INFO);
0752: }
0753: return permissionProperties;
0754: }
0755:
0756: /**
0757: * Add the <code>zip.plugin</code> target to the given Ant script.
0758: */
0759: private void generateZipPluginTarget() {
0760: script.println();
0761: script.printTargetDeclaration(TARGET_ZIP_PLUGIN, TARGET_INIT,
0762: null, null, NLS.bind(Messages.build_plugin_zipPlugin,
0763: model.getSymbolicName()));
0764: script.printDeleteTask(Utils
0765: .getPropertyFormat(PROPERTY_TEMP_FOLDER), null, null);
0766: script.printMkdirTask(Utils
0767: .getPropertyFormat(PROPERTY_TEMP_FOLDER));
0768: script.printAntCallTask(TARGET_BUILD_JARS, true, null);
0769: script.printAntCallTask(TARGET_BUILD_SOURCES, true, null);
0770: Map params = new HashMap(1);
0771: params.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils
0772: .getPropertyFormat(PROPERTY_TEMP_FOLDER) + '/');
0773: script.printAntCallTask(TARGET_GATHER_BIN_PARTS, true, params);
0774: script.printAntCallTask(TARGET_GATHER_SOURCES, true, params);
0775: FileSet fileSet = new FileSet(
0776: Utils.getPropertyFormat(PROPERTY_TEMP_FOLDER),
0777: null,
0778: "**/*.bin" + Utils.getPropertyFormat(PROPERTY_LOG_EXTENSION), null, null, null, null); //$NON-NLS-1$
0779: script.printDeleteTask(null, null, new FileSet[] { fileSet });
0780: script.printZipTask(pluginZipDestination, Utils
0781: .getPropertyFormat(PROPERTY_TEMP_FOLDER), true, false,
0782: null);
0783: script.printDeleteTask(Utils
0784: .getPropertyFormat(PROPERTY_TEMP_FOLDER), null, null);
0785: script.printTargetEnd();
0786: }
0787:
0788: /**
0789: * Add the <code>build.update.jar</code> target to the given Ant script.
0790: */
0791: private void generateBuildUpdateJarTarget() {
0792: script.println();
0793: script.printTargetDeclaration(TARGET_BUILD_UPDATE_JAR,
0794: TARGET_INIT, null, null, NLS.bind(
0795: Messages.build_plugin_buildUpdateJar, model
0796: .getSymbolicName()));
0797: script.printDeleteTask(Utils
0798: .getPropertyFormat(PROPERTY_TEMP_FOLDER), null, null);
0799: script.printMkdirTask(Utils
0800: .getPropertyFormat(PROPERTY_TEMP_FOLDER));
0801: script.printAntCallTask(TARGET_BUILD_JARS, true, null);
0802: Map params = new HashMap(1);
0803: params.put(PROPERTY_DESTINATION_TEMP_FOLDER, Utils
0804: .getPropertyFormat(PROPERTY_TEMP_FOLDER) + '/');
0805: script.printAntCallTask(TARGET_GATHER_BIN_PARTS, true, params);
0806: script.printJarTask(pluginUpdateJarDestination, Utils
0807: .getPropertyFormat(PROPERTY_TEMP_FOLDER)
0808: + '/' + fullName, null, "merge"); //$NON-NLS-1$
0809: script.printDeleteTask(Utils
0810: .getPropertyFormat(PROPERTY_TEMP_FOLDER), null, null);
0811: if (signJars)
0812: script
0813: .println("<eclipse.jarProcessor sign=\"" + Utils.getPropertyFormat(PROPERTY_SIGN) + "\" pack=\"" + Utils.getPropertyFormat(PROPERTY_PACK) + "\" unsign=\"" + Utils.getPropertyFormat(PROPERTY_UNSIGN) + "\" jar=\"" + AntScript.getEscaped(pluginUpdateJarDestination) + "\" alias=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_ALIAS) + "\" keystore=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_KEYSTORE) + "\" storepass=\"" + Utils.getPropertyFormat(PROPERTY_SIGN_STOREPASS) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
0814: script.printTargetEnd();
0815: }
0816:
0817: /**
0818: * Add the <code>refresh</code> target to the given Ant script.
0819: */
0820: private void generateRefreshTarget() {
0821: script.println();
0822: script.printTargetDeclaration(TARGET_REFRESH, TARGET_INIT,
0823: PROPERTY_ECLIPSE_RUNNING, null,
0824: Messages.build_plugin_refresh);
0825: script.printConvertPathTask(new Path(getLocation(model))
0826: .removeLastSegments(0).toOSString().replace('\\', '/'),
0827: PROPERTY_RESOURCE_PATH, false);
0828: script.printRefreshLocalTask(Utils
0829: .getPropertyFormat(PROPERTY_RESOURCE_PATH), "infinite"); //$NON-NLS-1$
0830: script.printTargetEnd();
0831: }
0832:
0833: /**
0834: * End the script by closing the project element.
0835: */
0836: private void generateEpilogue() {
0837: script.println();
0838: script.printProjectEnd();
0839: }
0840:
0841: /**
0842: * Defines, the XML declaration, Ant project and targets init and initTemplate.
0843: */
0844: private void generatePrologue() {
0845: script.printProjectDeclaration(model.getSymbolicName(),
0846: TARGET_BUILD_JARS, DOT);
0847: script.println();
0848:
0849: script.printProperty(PROPERTY_BASE_WS, Utils
0850: .getPropertyFormat(PROPERTY_WS));
0851: script.printProperty(PROPERTY_BASE_OS, Utils
0852: .getPropertyFormat(PROPERTY_OS));
0853: script.printProperty(PROPERTY_BASE_ARCH, Utils
0854: .getPropertyFormat(PROPERTY_ARCH));
0855: script.printProperty(PROPERTY_BASE_NL, Utils
0856: .getPropertyFormat(PROPERTY_NL));
0857: script.printProperty(PROPERTY_BUNDLE_ID, model
0858: .getSymbolicName());
0859: script.printProperty(PROPERTY_BUNDLE_VERSION, model
0860: .getVersion().toString());
0861: script.println();
0862:
0863: if (customBuildCallbacks != null
0864: && !customBuildCallbacks.equals(FALSE)) {
0865: script.printAvailableTask(PROPERTY_CUSTOM_BUILD_CALLBACKS,
0866: customCallbacksBuildpath + '/'
0867: + customBuildCallbacks,
0868: customBuildCallbacks);
0869: script.println();
0870: }
0871:
0872: generateCompilerSettings();
0873:
0874: script.printTargetDeclaration(TARGET_INIT, TARGET_PROPERTIES,
0875: null, null, null);
0876: script.printConditionIsSet(PROPERTY_PLUGIN_TEMP, Utils
0877: .getPropertyFormat(PROPERTY_BUILD_TEMP)
0878: + '/' + DEFAULT_PLUGIN_LOCATION, PROPERTY_BUILD_TEMP);
0879: script.printProperty(PROPERTY_PLUGIN_TEMP, Utils
0880: .getPropertyFormat(PROPERTY_BASEDIR));
0881: script.printConditionIsSet(PROPERTY_BUILD_RESULT_FOLDER, Utils
0882: .getPropertyFormat(PROPERTY_PLUGIN_TEMP)
0883: + '/'
0884: + model.getSymbolicName()
0885: + '_'
0886: + model.getVersion(), PROPERTY_BUILD_TEMP);
0887: script.printProperty(PROPERTY_BUILD_RESULT_FOLDER, Utils
0888: .getPropertyFormat(PROPERTY_BASEDIR));
0889:
0890: script.printProperty(PROPERTY_TEMP_FOLDER, Utils
0891: .getPropertyFormat(PROPERTY_BASEDIR)
0892: + '/' + PROPERTY_TEMP_FOLDER);
0893: script.printProperty(PROPERTY_PLUGIN_DESTINATION, Utils
0894: .getPropertyFormat(PROPERTY_BASEDIR));
0895: script.printTargetEnd();
0896: script.println();
0897: script.printTargetDeclaration(TARGET_PROPERTIES, null,
0898: PROPERTY_ECLIPSE_RUNNING, null, null);
0899: script.printProperty(PROPERTY_BUILD_COMPILER,
0900: JDT_COMPILER_ADAPTER);
0901: script.println();
0902:
0903: script.printTargetEnd();
0904: }
0905:
0906: private void generateCompilerSettings() {
0907: String javacSource = null;
0908: String javacTarget = null;
0909: String bootClasspath = null;
0910: String jreProfile = null;
0911: try {
0912: Properties properties = getBuildProperties();
0913: javacSource = properties
0914: .getProperty(IBuildPropertiesConstants.PROPERTY_JAVAC_SOURCE);
0915: javacTarget = properties
0916: .getProperty(IBuildPropertiesConstants.PROPERTY_JAVAC_TARGET);
0917: bootClasspath = properties
0918: .getProperty(IBuildPropertiesConstants.PROPERTY_BOOT_CLASSPATH);
0919: jreProfile = properties
0920: .getProperty(IBuildPropertiesConstants.PROPERTY_JRE_COMPILATION_PROFILE);
0921: } catch (CoreException e) {
0922: //ignore
0923: }
0924:
0925: script.printComment(Messages.build_compilerSetting);
0926: script.printProperty(PROPERTY_JAVAC_FAIL_ON_ERROR, "false"); //$NON-NLS-1$
0927: script.printProperty(PROPERTY_JAVAC_DEBUG_INFO, "on"); //$NON-NLS-1$
0928: script.printProperty(PROPERTY_JAVAC_VERBOSE, "false"); //$NON-NLS-1$
0929: script.printProperty(PROPERTY_LOG_EXTENSION, ".log"); //$NON-NLS-1$
0930: script.printProperty(PROPERTY_JAVAC_COMPILERARG, ""); //$NON-NLS-1$
0931:
0932: if (javacSource == null)
0933: script.printProperty(IXMLConstants.PROPERTY_JAVAC_SOURCE,
0934: "1.3"); //$NON-NLS-1$
0935: if (javacTarget == null)
0936: script.printProperty(IXMLConstants.PROPERTY_JAVAC_TARGET,
0937: "1.2"); //$NON-NLS-1$
0938: if (bootClasspath == null) {
0939: script
0940: .println("<condition property=\"dir_bootclasspath\" value=\"${java.home}/../Classes\">");//$NON-NLS-1$
0941: script.println("\t<os family=\"mac\"/>");//$NON-NLS-1$
0942: script.println("</condition>");//$NON-NLS-1$
0943: script
0944: .println("<property name=\"dir_bootclasspath\" value=\"${java.home}/lib\"/>");//$NON-NLS-1$
0945: script.println("<path id=\"path_bootclasspath\">");//$NON-NLS-1$
0946: script.println("\t<fileset dir=\"${dir_bootclasspath}\">");//$NON-NLS-1$
0947: script.println("\t\t<include name=\"*.jar\"/>");//$NON-NLS-1$
0948: script.println("\t</fileset>");//$NON-NLS-1$
0949: script.println("</path>");//$NON-NLS-1$
0950: script.printPropertyRefid(PROPERTY_BOOTCLASSPATH,
0951: "path_bootclasspath"); //$NON-NLS-1$
0952: }
0953:
0954: Properties environmentMappings = getExecutionEnvironmentMappings();
0955: if (jreProfile != null
0956: && !environmentMappings.containsKey(jreProfile + '.'
0957: + IXMLConstants.PROPERTY_JAVAC_SOURCE)) {
0958: if (reportResolutionErrors) {
0959: IStatus status = new Status(IStatus.ERROR, model
0960: .getSymbolicName(), IStatus.ERROR, NLS.bind(
0961: Messages.build_plugin_unrecognizedJRE,
0962: jreProfile), null);
0963: BundleHelper.getDefault().getLog().log(status);
0964: }
0965: jreProfile = null;
0966: }
0967:
0968: if (javacSource != null)
0969: script.printProperty(PROPERTY_BUNDLE_JAVAC_SOURCE,
0970: javacSource);
0971: if (javacTarget != null)
0972: script.printProperty(PROPERTY_BUNDLE_JAVAC_TARGET,
0973: javacTarget);
0974: if (bootClasspath != null)
0975: script.printProperty(PROPERTY_BUNDLE_BOOTCLASSPATH,
0976: bootClasspath);
0977:
0978: String source, target = null;
0979: String[] modelEnvironments = model.getExecutionEnvironments();
0980: String[] environments = null;
0981: if (jreProfile != null) {
0982: environments = new String[modelEnvironments.length + 1];
0983: environments[0] = jreProfile;
0984: System.arraycopy(modelEnvironments, 0, environments, 1,
0985: modelEnvironments.length);
0986: } else {
0987: environments = modelEnvironments;
0988: }
0989: for (int i = 0; i < environments.length; i++) {
0990: if (bootClasspath == null)
0991: script.printConditionIsSet(
0992: PROPERTY_BUNDLE_BOOTCLASSPATH, Utils
0993: .getPropertyFormat(environments[i]),
0994: environments[i]);
0995:
0996: source = (String) environmentMappings.get(environments[i]
0997: + '.' + IXMLConstants.PROPERTY_JAVAC_SOURCE);
0998: target = (String) environmentMappings.get(environments[i]
0999: + '.' + IXMLConstants.PROPERTY_JAVAC_TARGET);
1000: if (javacSource == null && source != null)
1001: script.printConditionIsSet(
1002: PROPERTY_BUNDLE_JAVAC_SOURCE, source,
1003: environments[i]);
1004: if (javacTarget == null && target != null)
1005: script.printConditionIsSet(
1006: PROPERTY_BUNDLE_JAVAC_TARGET, target,
1007: environments[i]);
1008: }
1009:
1010: if (javacSource == null)
1011: script
1012: .printProperty(
1013: PROPERTY_BUNDLE_JAVAC_SOURCE,
1014: Utils
1015: .getPropertyFormat(IXMLConstants.PROPERTY_JAVAC_SOURCE));
1016: if (javacTarget == null)
1017: script
1018: .printProperty(
1019: PROPERTY_BUNDLE_JAVAC_TARGET,
1020: Utils
1021: .getPropertyFormat(IXMLConstants.PROPERTY_JAVAC_TARGET));
1022: if (bootClasspath == null)
1023: script.printProperty(PROPERTY_BUNDLE_BOOTCLASSPATH, Utils
1024: .getPropertyFormat(PROPERTY_BOOTCLASSPATH));
1025: script.println();
1026: }
1027:
1028: /**
1029: * Sets the PluginModel to generate script from.
1030: *
1031: * @param model
1032: * @throws CoreException
1033: */
1034: public void setModel(BundleDescription model) throws CoreException {
1035: if (model == null) {
1036: throw new CoreException(new Status(IStatus.ERROR,
1037: PI_PDEBUILD, EXCEPTION_ELEMENT_MISSING,
1038: Messages.error_missingElement, null));
1039: }
1040: model = getSite(false).getRegistry().getVersionReplacement(
1041: model);
1042: this .model = model;
1043: if (getBuildProperties() == AbstractScriptGenerator.MissingProperties
1044: .getInstance()) {
1045: //if there were no build.properties, then it is a binary plugin
1046: binaryPlugin = true;
1047: } else {
1048: getCompiledElements().add(model.getSymbolicName());
1049: }
1050: Properties bundleProperties = (Properties) model
1051: .getUserObject();
1052: if (bundleProperties == null) {
1053: bundleProperties = new Properties();
1054: model.setUserObject(bundleProperties);
1055: }
1056: bundleProperties.put(IS_COMPILED, binaryPlugin ? Boolean.FALSE
1057: : Boolean.TRUE);
1058: }
1059:
1060: /**
1061: * Sets model to generate scripts from.
1062: *
1063: * @param modelId
1064: * @throws CoreException
1065: */
1066: public void setModelId(String modelId, String modelVersion)
1067: throws CoreException {
1068: BundleDescription newModel = getModel(modelId, modelVersion);
1069: if (newModel == null) {
1070: String message = NLS.bind(
1071: Messages.exception_missingElement, modelId);
1072: throw new CoreException(new Status(IStatus.ERROR,
1073: PI_PDEBUILD, EXCEPTION_ELEMENT_MISSING, message,
1074: null));
1075: }
1076: setModel(newModel);
1077: }
1078:
1079: /**
1080: * Add the <code>build.zips</code> target to the given Ant script.
1081: *
1082: * @throws CoreException
1083: */
1084: private void generateBuildZipsTarget() throws CoreException {
1085: StringBuffer zips = new StringBuffer();
1086: Properties props = getBuildProperties();
1087: for (Iterator iterator = props.entrySet().iterator(); iterator
1088: .hasNext();) {
1089: Map.Entry entry = (Map.Entry) iterator.next();
1090: String key = (String) entry.getKey();
1091: if (key.startsWith(PROPERTY_SOURCE_PREFIX)
1092: && key.endsWith(PROPERTY_ZIP_SUFFIX)) {
1093: String zipName = key.substring(PROPERTY_SOURCE_PREFIX
1094: .length());
1095: zips.append(',');
1096: zips.append(zipName);
1097: generateZipIndividualTarget(zipName, (String) entry
1098: .getValue());
1099: }
1100: }
1101: script.println();
1102: script.printTargetDeclaration(TARGET_BUILD_ZIPS, TARGET_INIT
1103: + zips.toString(), null, null, null);
1104: script.printTargetEnd();
1105: }
1106:
1107: /**
1108: * Sets the featureGenerator.
1109: * @param featureGenerator The featureGenerator to set
1110: */
1111: public void setFeatureGenerator(
1112: FeatureBuildScriptGenerator featureGenerator) {
1113: this .featureGenerator = featureGenerator;
1114: }
1115:
1116: /**
1117: * Add the "build.jars" target to the given Ant script using the specified plug-in model.
1118: *
1119: * @param pluginModel the plug-in model to reference
1120: * @throws CoreException
1121: */
1122: private void generateBuildJarsTarget(BundleDescription pluginModel)
1123: throws CoreException {
1124: Properties properties = getBuildProperties();
1125: CompiledEntry[] availableJars = extractEntriesToCompile(properties);
1126: compiledJarNames = new ArrayList(availableJars.length);
1127: Map jars = new HashMap(availableJars.length);
1128: for (int i = 0; i < availableJars.length; i++)
1129: jars.put(availableJars[i].getName(false), availableJars[i]);
1130:
1131: // Put the jars in a correct compile order
1132: String jarOrder = (String) getBuildProperties().get(
1133: PROPERTY_JAR_ORDER);
1134: IClasspathComputer classpath;
1135: if (AbstractScriptGenerator.isBuildingOSGi())
1136: classpath = new ClasspathComputer3_0(this );
1137: else
1138: classpath = new ClasspathComputer2_1(this );
1139:
1140: if (jarOrder != null) {
1141: String[] order = Utils.getArrayFromString(jarOrder);
1142: for (int i = 0; i < order.length; i++) {
1143: CompiledEntry jar = (CompiledEntry) jars.get(order[i]);
1144: if (jar == null)
1145: continue;
1146:
1147: compiledJarNames.add(jar);
1148: generateCompilationTarget(classpath.getClasspath(
1149: pluginModel, jar), jar);
1150: generateSRCTarget(jar);
1151: jars.remove(order[i]);
1152: }
1153: }
1154: for (Iterator iterator = jars.values().iterator(); iterator
1155: .hasNext();) {
1156: CompiledEntry jar = (CompiledEntry) iterator.next();
1157: compiledJarNames.add(jar);
1158: generateCompilationTarget(classpath.getClasspath(
1159: pluginModel, jar), jar);
1160: generateSRCTarget(jar);
1161: }
1162: script.println();
1163: script.printTargetDeclaration(TARGET_BUILD_JARS, TARGET_INIT,
1164: null, null, NLS.bind(Messages.build_plugin_buildJars,
1165: pluginModel.getSymbolicName()));
1166: Map params = null;
1167: if (customBuildCallbacks != null) {
1168: params = new HashMap(1);
1169: params.put(PROPERTY_BUILD_RESULT_FOLDER, Utils
1170: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER));
1171: script
1172: .printSubantTask(
1173: Utils
1174: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1175: PROPERTY_PRE + TARGET_BUILD_JARS,
1176: customCallbacksBuildpath,
1177: customCallbacksFailOnError,
1178: customCallbacksInheritAll, params, null);
1179: }
1180: for (Iterator iter = compiledJarNames.iterator(); iter
1181: .hasNext();) {
1182: String name = ((CompiledEntry) iter.next()).getName(false);
1183: script.printAvailableTask(name, replaceVariables(
1184: getJARLocation(name), true));
1185: script.printAntCallTask(name, true, null);
1186: }
1187: if (customBuildCallbacks != null) {
1188: script
1189: .printSubantTask(
1190: Utils
1191: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1192: PROPERTY_POST + TARGET_BUILD_JARS,
1193: customCallbacksBuildpath,
1194: customCallbacksFailOnError,
1195: customCallbacksInheritAll, params, null);
1196: }
1197: script.printTargetEnd();
1198:
1199: script.println();
1200: script.printTargetDeclaration(TARGET_BUILD_SOURCES,
1201: TARGET_INIT, null, null, null);
1202: if (customBuildCallbacks != null) {
1203: script
1204: .printSubantTask(
1205: Utils
1206: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1207: PROPERTY_PRE + TARGET_BUILD_SOURCES,
1208: customCallbacksBuildpath,
1209: customCallbacksFailOnError,
1210: customCallbacksInheritAll, params, null);
1211: }
1212: for (Iterator iter = compiledJarNames.iterator(); iter
1213: .hasNext();) {
1214: String jarName = ((CompiledEntry) iter.next())
1215: .getName(false);
1216: String srcName = getSRCName(jarName);
1217: script.printAvailableTask(srcName, getSRCLocation(jarName));
1218: script.printAntCallTask(srcName, true, null);
1219: }
1220: if (customBuildCallbacks != null) {
1221: script
1222: .printSubantTask(
1223: Utils
1224: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1225: PROPERTY_POST + TARGET_BUILD_SOURCES,
1226: customCallbacksBuildpath,
1227: customCallbacksFailOnError,
1228: customCallbacksInheritAll, params, null);
1229: }
1230: script.printTargetEnd();
1231: }
1232:
1233: /**
1234: * generate compile settings for compiling this entry
1235: * warning levels, default encoding, custom encodings
1236: * @param javac
1237: * @param entry
1238: */
1239: private void generateCompilerSettings(JavacTask javac,
1240: CompiledEntry entry, List classpath) {
1241: final String ADAPTER_ENCODING = "#ADAPTER#ENCODING#"; //$NON-NLS-1$
1242: final String ADAPTER_ACCESS = "#ADAPTER#ACCESS#"; //$NON-NLS-1$
1243:
1244: Properties properties = null;
1245: try {
1246: properties = getBuildProperties();
1247: } catch (CoreException e) {
1248: return;
1249: }
1250: if (properties == null && classpath.size() == 0)
1251: return;
1252:
1253: String name = entry.getName(false);
1254: if (name.equals(EXPANDED_DOT))
1255: name = DOT;
1256:
1257: String defaultEncodingVal = properties
1258: .getProperty(PROPERTY_JAVAC_DEFAULT_ENCODING_PREFIX
1259: + name);
1260: if (defaultEncodingVal != null)
1261: javac.setEncoding(defaultEncodingVal);
1262:
1263: String customEncodingsVal = properties
1264: .getProperty(PROPERTY_JAVAC_CUSTOM_ENCODINGS_PREFIX
1265: + name);
1266: String warningLevels = properties
1267: .getProperty(PROPERTY_JAVAC_WARNINGS_PREFIX + name);
1268:
1269: if (customEncodingsVal == null && warningLevels == null
1270: && classpath.size() == 0) {
1271: return;
1272: }
1273:
1274: String root = getLocation(model);
1275: File file = new File(
1276: root,
1277: "javaCompiler." + name.replaceAll("[\\\\/]", "_") + ".args"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1278: if (file.exists()) {
1279: file.delete();
1280: }
1281: Writer writer = null;
1282: try {
1283: try {
1284: //only create the file if we are going to write something in it
1285: if (warningLevels != null || customEncodingsVal != null)
1286: writer = new BufferedWriter(new FileWriter(file));
1287:
1288: if (warningLevels != null) {
1289: writer.write("-warn:" + warningLevels + "\n"); //$NON-NLS-1$//$NON-NLS-2$
1290: }
1291:
1292: if (customEncodingsVal != null) {
1293: String[] encodings = customEncodingsVal.split(","); //$NON-NLS-1$
1294: if (encodings.length > 0) {
1295: for (int i = 0; i < encodings.length; i++) {
1296: writer.write(ADAPTER_ENCODING
1297: + encodings[i] + "\n"); //$NON-NLS-1$
1298: }
1299: }
1300: }
1301: //handle access rules if we are using ClasspathComputer3_0
1302: if (classpath.size() > 0
1303: && classpath.get(0) instanceof ClasspathElement) {
1304: for (Iterator iterator = classpath.iterator(); iterator
1305: .hasNext();) {
1306: ClasspathElement element = (ClasspathElement) iterator
1307: .next();
1308: if (element.getPath() != null
1309: && element.getPath().length() > 0
1310: && element.getAccessRules().length() > 0) {
1311: String path = element.getPath();
1312: if (path
1313: .startsWith(Utils
1314: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER))) {
1315: //remove leading ${build.result.folder}/
1316: path = path
1317: .substring(Utils
1318: .getPropertyFormat(
1319: PROPERTY_BUILD_RESULT_FOLDER)
1320: .length() + 1);
1321: }
1322: //remove leading ../../..
1323: path = path.replaceFirst(
1324: "^(\\.\\.[\\\\/])*", ""); //$NON-NLS-1$//$NON-NLS-2$
1325: if (writer == null)
1326: writer = new BufferedWriter(
1327: new FileWriter(file));
1328: writer.write(ADAPTER_ACCESS + path
1329: + element.getAccessRules() + "\n"); //$NON-NLS-1$
1330: }
1331: }
1332: }
1333: if (writer != null)
1334: javac.setCompileArgsFile(Utils
1335: .getPropertyFormat(PROPERTY_BASEDIR)
1336: + "/" + file.getName()); //$NON-NLS-1$
1337: } finally {
1338: if (writer != null)
1339: writer.close();
1340: }
1341: } catch (IOException e1) {
1342: //ignore
1343: }
1344: }
1345:
1346: /**
1347: * Add the "jar" target to the given Ant script using the given classpath and
1348: * jar as parameters.
1349: *
1350: * @param classpath the classpath for the jar command
1351: * @param entry
1352: */
1353: private void generateCompilationTarget(List classpath,
1354: CompiledEntry entry) {
1355: script.println();
1356: String name = entry.getName(false);
1357: script.printTargetDeclaration(name, TARGET_INIT, null, entry
1358: .getName(true), NLS.bind(Messages.build_plugin_jar,
1359: model.getSymbolicName() + ' ' + name));
1360: String destdir = getTempJARFolderLocation(entry.getName(true));
1361: script.printDeleteTask(destdir, null, null);
1362: script.printMkdirTask(destdir);
1363: script.printPathStructure(
1364: "path", name + PROPERTY_CLASSPATH, classpath); //$NON-NLS-1$
1365:
1366: String[] sources = entry.getSource();
1367: Map params = null, references = null;
1368: if (customBuildCallbacks != null) {
1369: params = new HashMap(2);
1370: params.put(PROPERTY_TARGET_FOLDER, destdir);
1371: for (int i = 1; i <= sources.length; i++) {
1372: params.put(PROPERTY_SOURCE_FOLDER + i, sources[i - 1]);
1373: }
1374:
1375: references = new HashMap(1);
1376: references.put(name + PROPERTY_CLASSPATH, null);
1377: script
1378: .printSubantTask(
1379: Utils
1380: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1381: PROPERTY_PRE + name,
1382: customCallbacksBuildpath,
1383: customCallbacksFailOnError,
1384: customCallbacksInheritAll, params,
1385: references);
1386: }
1387:
1388: script.printComment("compile the source code"); //$NON-NLS-1$
1389: JavacTask javac = new JavacTask();
1390: javac.setClasspathId(name + PROPERTY_CLASSPATH);
1391: javac.setBootClasspath(Utils
1392: .getPropertyFormat(PROPERTY_BUNDLE_BOOTCLASSPATH));
1393: javac.setDestdir(destdir);
1394: javac.setFailOnError(Utils
1395: .getPropertyFormat(PROPERTY_JAVAC_FAIL_ON_ERROR));
1396: javac.setDebug(Utils
1397: .getPropertyFormat(PROPERTY_JAVAC_DEBUG_INFO));
1398: javac.setVerbose(Utils
1399: .getPropertyFormat(PROPERTY_JAVAC_VERBOSE));
1400: javac.setIncludeAntRuntime("no"); //$NON-NLS-1$
1401: javac.setSource(Utils
1402: .getPropertyFormat(PROPERTY_BUNDLE_JAVAC_SOURCE));
1403: javac.setTarget(Utils
1404: .getPropertyFormat(PROPERTY_BUNDLE_JAVAC_TARGET));
1405: javac.setCompileArgs(Utils
1406: .getPropertyFormat(PROPERTY_JAVAC_COMPILERARG));
1407: javac.setSrcdir(sources);
1408: javac.setLogExtension(Utils
1409: .getPropertyFormat(PROPERTY_LOG_EXTENSION));
1410: generateCompilerSettings(javac, entry, classpath);
1411:
1412: script.print(javac);
1413: script.printComment("Copy necessary resources"); //$NON-NLS-1$
1414: FileSet[] fileSets = new FileSet[sources.length];
1415: for (int i = 0; i < sources.length; i++) {
1416: String excludes = "**/*.java, **/package.htm*"; //$NON-NLS-1$
1417: String excludedFromJar = entry.getExcludedFromJar();
1418: if (excludedFromJar != null)
1419: excludes += ',' + excludedFromJar;
1420:
1421: fileSets[i] = new FileSet(sources[i], null, null, null,
1422: excludes, null, null);
1423: }
1424:
1425: script.printCopyTask(null, destdir, fileSets, true, false);
1426:
1427: if (customBuildCallbacks != null) {
1428: script
1429: .printSubantTask(
1430: Utils
1431: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1432: PROPERTY_POST_COMPILE + name,
1433: customCallbacksBuildpath,
1434: customCallbacksFailOnError,
1435: customCallbacksInheritAll, params,
1436: references);
1437: }
1438:
1439: String jarLocation = getJARLocation(entry.getName(true));
1440: script.printMkdirTask(new Path(jarLocation).removeLastSegments(
1441: 1).toString());
1442:
1443: if (entry.getType() == CompiledEntry.FOLDER) {
1444: FileSet[] binFolder = new FileSet[] { new FileSet(destdir,
1445: null, null, null, null, null, null) };
1446: script.printCopyTask(null, jarLocation, binFolder, true,
1447: false);
1448: } else {
1449: script.printJarTask(jarLocation, destdir,
1450: getEmbeddedManifestFile(entry, destdir));
1451: }
1452: script.printDeleteTask(destdir, null, null);
1453:
1454: if (customBuildCallbacks != null) {
1455: params.clear();
1456: params.put(PROPERTY_JAR_LOCATION, jarLocation);
1457: script
1458: .printSubantTask(
1459: Utils
1460: .getPropertyFormat(PROPERTY_CUSTOM_BUILD_CALLBACKS),
1461: PROPERTY_POST + name,
1462: customCallbacksBuildpath,
1463: customCallbacksFailOnError,
1464: customCallbacksInheritAll, params,
1465: references);
1466: }
1467: script.printTargetEnd();
1468: }
1469:
1470: private String getEmbeddedManifestFile(CompiledEntry jarEntry,
1471: String destdir) {
1472: try {
1473: String manifestName = getBuildProperties().getProperty(
1474: PROPERTY_MANIFEST_PREFIX + jarEntry.getName(true));
1475: if (manifestName == null)
1476: return null;
1477: return destdir + '/' + manifestName;
1478: } catch (CoreException e) {
1479: return null;
1480: }
1481: }
1482:
1483: /**
1484: *
1485: * @param properties
1486: * @return JAR[]
1487: */
1488: protected CompiledEntry[] extractEntriesToCompile(
1489: Properties properties) throws CoreException {
1490: List result = new ArrayList(5);
1491: int prefixLength = PROPERTY_SOURCE_PREFIX.length();
1492: for (Iterator iterator = properties.entrySet().iterator(); iterator
1493: .hasNext();) {
1494: Map.Entry entry = (Map.Entry) iterator.next();
1495: String key = (String) entry.getKey();
1496: if (!(key.startsWith(PROPERTY_SOURCE_PREFIX)))
1497: continue;
1498: key = key.substring(prefixLength);
1499: String[] source = Utils.getArrayFromString((String) entry
1500: .getValue());
1501: if (source.length == 0) {
1502: String message = NLS.bind(
1503: Messages.error_missingSourceFolder, model
1504: .getSymbolicName(), entry.getKey());
1505: throw new CoreException(new Status(IStatus.ERROR,
1506: PI_PDEBUILD, EXCEPTION_GENERIC, message, null));
1507: }
1508: String[] output = Utils.getArrayFromString(properties
1509: .getProperty(PROPERTY_OUTPUT_PREFIX + key));
1510: String[] extraClasspath = Utils
1511: .getArrayFromString(properties
1512: .getProperty(PROPERTY_EXTRAPATH_PREFIX
1513: + key));
1514: String excludedFromJar = properties
1515: .getProperty(PROPERTY_EXCLUDE_PREFIX + key);
1516: CompiledEntry newEntry = new CompiledEntry(
1517: key,
1518: source,
1519: output,
1520: extraClasspath,
1521: excludedFromJar,
1522: key.endsWith(PROPERTY_JAR_SUFFIX) ? CompiledEntry.JAR
1523: : CompiledEntry.FOLDER);
1524: result.add(newEntry);
1525: }
1526: return (CompiledEntry[]) result
1527: .toArray(new CompiledEntry[result.size()]);
1528: }
1529:
1530: /**
1531: * Add the "src" target to the given Ant script.
1532: *
1533: * @param jar
1534: */
1535: private void generateSRCTarget(CompiledEntry jar) {
1536: script.println();
1537: String name = jar.getName(false);
1538: String srcName = getSRCName(name);
1539: script.printTargetDeclaration(srcName, TARGET_INIT, null,
1540: srcName, null);
1541: String[] sources = jar.getSource();
1542: filterNonExistingSourceFolders(sources);
1543: FileSet[] fileSets = new FileSet[sources.length];
1544: int count = 0;
1545: for (int i = 0; i < sources.length; i++) {
1546: if (sources[i] != null)
1547: fileSets[count++] = new FileSet(sources[i], null,
1548: "**/*.java", null, null, null, null); //$NON-NLS-1$
1549: }
1550:
1551: String srcLocation = getSRCLocation(name);
1552: script.printMkdirTask(new Path(srcLocation).removeLastSegments(
1553: 1).toString());
1554:
1555: if (count != 0)
1556: script.printZipTask(srcLocation, null, false, false,
1557: fileSets);
1558:
1559: script.printTargetEnd();
1560: }
1561:
1562: private void filterNonExistingSourceFolders(String[] sources) {
1563: File pluginRoot;
1564: pluginRoot = new File(getLocation(model));
1565: for (int i = 0; i < sources.length; i++) {
1566: File file = new File(pluginRoot, sources[i]);
1567: if (!file.exists()) {
1568: sources[i] = null;
1569: IStatus status = new Status(IStatus.WARNING,
1570: PI_PDEBUILD, EXCEPTION_SOURCE_LOCATION_MISSING,
1571: NLS.bind(Messages.warning_cannotLocateSource,
1572: file.getAbsolutePath()), null);
1573: BundleHelper.getDefault().getLog().log(status);
1574: }
1575: }
1576: }
1577:
1578: /**
1579: * Return the name of the zip file for the source for the jar with
1580: * the given name.
1581: *
1582: * @param jarName the name of the jar file
1583: * @return String
1584: */
1585: protected String getSRCLocation(String jarName) {
1586: return getJARLocation(getSRCName(jarName));
1587: }
1588:
1589: /**
1590: * Return the location for a temporary file for the jar file with
1591: * the given name.
1592: *
1593: * @param jarName the name of the jar file
1594: * @return String
1595: */
1596: protected String getTempJARFolderLocation(String jarName) {
1597: IPath destination = new Path(Utils
1598: .getPropertyFormat(PROPERTY_TEMP_FOLDER));
1599: destination = destination.append(jarName + ".bin"); //$NON-NLS-1$
1600: return destination.toString();
1601: }
1602:
1603: /**
1604: * Return the full location of the jar file.
1605: *
1606: * @param jarName the name of the jar file
1607: * @return String
1608: */
1609: protected String getJARLocation(String jarName) {
1610: return new Path(Utils
1611: .getPropertyFormat(PROPERTY_BUILD_RESULT_FOLDER))
1612: .append(jarName).toString();
1613: }
1614:
1615: protected String[] getClasspathEntries(
1616: BundleDescription lookedUpModel) throws CoreException {
1617: return (String[]) getSite(false).getRegistry().getExtraData()
1618: .get(new Long(lookedUpModel.getBundleId()));
1619: }
1620:
1621: protected Properties getBuildProperties() throws CoreException {
1622: if (buildProperties == null)
1623: return buildProperties = readProperties(
1624: model.getLocation(), propertiesFileName,
1625: isIgnoreMissingPropertiesFile() ? IStatus.OK
1626: : IStatus.WARNING);
1627:
1628: return buildProperties;
1629: }
1630:
1631: /**
1632: * Return the name of the zip file for the source from the given jar name.
1633: *
1634: * @param jarName the name of the jar file
1635: * @return String
1636: */
1637: protected String getSRCName(String jarName) {
1638: if (jarName.endsWith(".jar")) { //$NON-NLS-1$
1639: return jarName.substring(0, jarName.length() - 4) + SRC_ZIP;
1640: }
1641: if (jarName.equals(EXPANDED_DOT))
1642: return SRC_ZIP;
1643: return jarName.replace('/', '.') + SRC_ZIP;
1644: }
1645:
1646: /**
1647: * If the model defines its own custom script, we do not generate a new one
1648: * but we do try to update the version number.
1649: */
1650: private void updateExistingScript() throws CoreException {
1651: String root = getLocation(model);
1652: File buildFile = new File(root, buildScriptFileName);
1653: if (!buildFile.exists()) {
1654: String message = NLS.bind(
1655: Messages.error_missingCustomBuildFile, buildFile);
1656: throw new CoreException(new Status(IStatus.ERROR,
1657: PI_PDEBUILD, EXCEPTION_WRITING_SCRIPT, message,
1658: null));
1659: }
1660: try {
1661: updateVersion(buildFile, PROPERTY_VERSION_SUFFIX, model
1662: .getVersion().toString());
1663: } catch (IOException e) {
1664: String message = NLS.bind(Messages.exception_writeScript,
1665: buildFile);
1666: throw new CoreException(new Status(IStatus.ERROR,
1667: PI_PDEBUILD, EXCEPTION_WRITING_SCRIPT, message, e));
1668: }
1669: return;
1670: }
1671:
1672: /**
1673: * Substitute the value of an element description variable (variables that
1674: * are found in files like plugin.xml, e.g. $ws$) by an Ant property.
1675: *
1676: * @param sourceString
1677: * @return String
1678: */
1679: protected String replaceVariables(String sourceString,
1680: boolean compiledElement) {
1681: if (sourceString == null)
1682: return null;
1683:
1684: int i = -1;
1685: String result = sourceString;
1686: while ((i = result.indexOf(DESCRIPTION_VARIABLE_WS)) >= 0)
1687: result = result.substring(0, i)
1688: + "ws/" + Utils.getPropertyFormat(compiledElement ? PROPERTY_WS : PROPERTY_BASE_WS) + result.substring(i + DESCRIPTION_VARIABLE_WS.length()); //$NON-NLS-1$
1689: while ((i = result.indexOf(DESCRIPTION_VARIABLE_OS)) >= 0)
1690: result = result.substring(0, i)
1691: + "os/" + Utils.getPropertyFormat(compiledElement ? PROPERTY_OS : PROPERTY_BASE_OS) + result.substring(i + DESCRIPTION_VARIABLE_OS.length()); //$NON-NLS-1$
1692: while ((i = result.indexOf(DESCRIPTION_VARIABLE_ARCH)) >= 0)
1693: result = result.substring(0, i)
1694: + "arch/" + Utils.getPropertyFormat(compiledElement ? PROPERTY_ARCH : PROPERTY_BASE_ARCH) + result.substring(i + DESCRIPTION_VARIABLE_OS.length()); //$NON-NLS-1$
1695: while ((i = result.indexOf(DESCRIPTION_VARIABLE_NL)) >= 0)
1696: result = result.substring(0, i)
1697: + "nl/" + Utils.getPropertyFormat(compiledElement ? PROPERTY_NL : PROPERTY_BASE_NL) + result.substring(i + DESCRIPTION_VARIABLE_NL.length()); //$NON-NLS-1$
1698: return result;
1699: }
1700:
1701: public BundleDescription getModel() {
1702: return model;
1703: }
1704:
1705: public String getPropertiesFileName() {
1706: return propertiesFileName;
1707: }
1708:
1709: public void setPropertiesFileName(String propertyFileName) {
1710: this .propertiesFileName = propertyFileName;
1711: }
1712:
1713: public String getBuildScriptFileName() {
1714: return buildScriptFileName;
1715: }
1716:
1717: public void setBuildScriptFileName(String buildScriptFileName) {
1718: this .buildScriptFileName = buildScriptFileName;
1719: }
1720:
1721: /**
1722: * Sets whether or not to sign any constructed jars.
1723: *
1724: * @param value whether or not to sign any constructed JARs
1725: */
1726: public void setSignJars(boolean value) {
1727: signJars = value;
1728: }
1729:
1730: /**
1731: * Returns the model object which is associated with the given identifier.
1732: * Returns <code>null</code> if the model object cannot be found.
1733: *
1734: * @param modelId the identifier of the model object to lookup
1735: * @return the model object or <code>null</code>
1736: */
1737: protected BundleDescription getModel(String modelId,
1738: String modelVersion) throws CoreException {
1739: if (modelVersion == null)
1740: return getSite(false).getRegistry().getResolvedBundle(
1741: modelId);
1742: return getSite(false).getRegistry().getResolvedBundle(modelId,
1743: modelVersion);
1744: }
1745:
1746: public IPluginEntry getAssociatedEntry() {
1747: return associatedEntry;
1748: }
1749:
1750: public void setAssociatedEntry(IPluginEntry associatedEntry) {
1751: this.associatedEntry = associatedEntry;
1752: }
1753: }
|