001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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 Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.build;
011:
012: import java.lang.reflect.InvocationTargetException;
013:
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.core.runtime.IProgressMonitor;
017: import org.eclipse.pde.core.plugin.IPluginModelBase;
018: import org.eclipse.pde.internal.build.AbstractScriptGenerator;
019: import org.eclipse.pde.internal.build.BuildScriptGenerator;
020: import org.eclipse.pde.internal.build.IXMLConstants;
021: import org.eclipse.pde.internal.core.ClasspathHelper;
022: import org.eclipse.pde.internal.core.PDECore;
023: import org.eclipse.pde.internal.core.TargetPlatformHelper;
024: import org.eclipse.pde.internal.core.feature.FeatureChild;
025: import org.eclipse.pde.internal.core.ifeature.IFeature;
026: import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
027: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
028: import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
029:
030: public class BuildFeatureAction extends BaseBuildAction {
031:
032: private IFeatureModel fFeatureModel;
033:
034: protected void makeScripts(IProgressMonitor monitor)
035: throws InvocationTargetException, CoreException {
036:
037: IFeatureModel[] models = PDECore.getDefault()
038: .getFeatureModelManager().getModels();
039: for (int i = 0; i < models.length; i++) {
040: if (models[i].getUnderlyingResource() != null) {
041: IResource underlying = models[i]
042: .getUnderlyingResource();
043: if (underlying.equals(fManifestFile)
044: || underlying.getProject().equals(
045: fManifestFile.getProject()))
046: fFeatureModel = models[i];
047: }
048: }
049:
050: BuildScriptGenerator generator = new BuildScriptGenerator();
051: generator.setBuildingOSGi(true);
052: generator.setChildren(true);
053: AbstractScriptGenerator
054: .setEmbeddedSource(AbstractScriptGenerator
055: .getDefaultEmbeddedSource());
056:
057: String url = ClasspathHelper.getDevEntriesProperties(
058: fManifestFile.getProject().getLocation()
059: .addTrailingSeparator().toString()
060: + "dev.properties", false); //$NON-NLS-1$
061: generator.setDevEntries(url);
062: generator.setWorkingDirectory(fManifestFile.getProject()
063: .getLocation().toOSString());
064: AbstractScriptGenerator.setConfigInfo(AbstractScriptGenerator
065: .getDefaultConfigInfos()); //This needs to be set before we set the format
066: generator.setArchivesFormat(AbstractScriptGenerator
067: .getDefaultConfigInfos()
068: + '-' + IXMLConstants.FORMAT_ANTZIP);
069: generator
070: .setElements(new String[] { "feature@" + fFeatureModel.getFeature().getId() + (fFeatureModel.getFeature().getVersion() == null ? "" : ":" + fFeatureModel.getFeature().getVersion()) }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
071: generator.setPluginPath(TargetPlatformHelper.getFeaturePaths());
072: generator.setPDEState(TargetPlatformHelper.getState());
073: generator.setNextId(TargetPlatformHelper.getPDEState()
074: .getNextId());
075: generator.setStateExtraData(
076: TargetPlatformHelper
077: .getBundleClasspaths(TargetPlatformHelper
078: .getPDEState()),
079: TargetPlatformHelper.getPatchMap(TargetPlatformHelper
080: .getPDEState()));
081: generator.setGenerateAssembleScript(false);
082: generator.generate();
083: }
084:
085: private void refreshLocal(IFeature feature, IProgressMonitor monitor)
086: throws CoreException {
087: IFeaturePlugin[] references = feature.getPlugins();
088: for (int i = 0; i < references.length; i++) {
089: IPluginModelBase refmodel = feature
090: .getReferencedModel(references[i]);
091: if (refmodel != null) {
092: IResource resource = refmodel.getUnderlyingResource();
093: if (resource != null)
094: resource.getProject().refreshLocal(
095: IResource.DEPTH_ONE, monitor);
096: }
097: }
098: IFeatureChild[] included = feature.getIncludedFeatures();
099: for (int i = 0; i < included.length; i++) {
100: IFeature child = ((FeatureChild) included[i])
101: .getReferencedFeature();
102: if (child != null && child != fFeatureModel.getFeature()) {
103: IFeatureModel refmodel = child.getModel();
104: if (refmodel != null
105: && refmodel.getUnderlyingResource() != null) {
106: refmodel.getUnderlyingResource().getProject()
107: .refreshLocal(IResource.DEPTH_ONE, monitor);
108: }
109: refreshLocal(child, monitor);
110:
111: }
112: }
113: }
114:
115: protected void refreshLocal(IProgressMonitor monitor)
116: throws CoreException {
117: super.refreshLocal(monitor);
118: refreshLocal(fFeatureModel.getFeature(), monitor);
119: }
120: }
|