KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > build > BuildFeatureAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.build;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.pde.core.plugin.IPluginModelBase;
19 import org.eclipse.pde.internal.build.AbstractScriptGenerator;
20 import org.eclipse.pde.internal.build.BuildScriptGenerator;
21 import org.eclipse.pde.internal.build.IXMLConstants;
22 import org.eclipse.pde.internal.core.ClasspathHelper;
23 import org.eclipse.pde.internal.core.PDECore;
24 import org.eclipse.pde.internal.core.TargetPlatformHelper;
25 import org.eclipse.pde.internal.core.feature.FeatureChild;
26 import org.eclipse.pde.internal.core.ifeature.IFeature;
27 import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
28 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
29 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
30
31 public class BuildFeatureAction extends BaseBuildAction {
32     
33     private IFeatureModel fFeatureModel;
34
35     protected void makeScripts(IProgressMonitor monitor)
36         throws InvocationTargetException JavaDoc, CoreException {
37         
38         IFeatureModel[] models = PDECore.getDefault().getFeatureModelManager().getModels();
39         for (int i = 0; i < models.length; i++) {
40             if (models[i].getUnderlyingResource() != null) {
41                 IResource underlying = models[i].getUnderlyingResource();
42                 if (underlying.equals(fManifestFile) || underlying.getProject().equals(fManifestFile.getProject()))
43                     fFeatureModel = models[i];
44             }
45         }
46         
47         BuildScriptGenerator generator = new BuildScriptGenerator();
48         generator.setBuildingOSGi(true);
49         generator.setChildren(true);
50         AbstractScriptGenerator.setEmbeddedSource(AbstractScriptGenerator.getDefaultEmbeddedSource());
51
52         String JavaDoc url = ClasspathHelper.getDevEntriesProperties(fManifestFile.getProject().getLocation().addTrailingSeparator().toString() + "dev.properties", false); //$NON-NLS-1$
53
generator.setDevEntries(url);
54         generator.setWorkingDirectory(fManifestFile.getProject().getLocation().toOSString());
55         AbstractScriptGenerator.setConfigInfo(AbstractScriptGenerator.getDefaultConfigInfos()); //This needs to be set before we set the format
56
generator.setArchivesFormat(AbstractScriptGenerator.getDefaultConfigInfos() + '-' + IXMLConstants.FORMAT_ANTZIP);
57         generator.setElements(new String JavaDoc[] { "feature@" + fFeatureModel.getFeature().getId() + (fFeatureModel.getFeature().getVersion() == null ? "" : ":" + fFeatureModel.getFeature().getVersion()) }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
58
generator.setPluginPath(TargetPlatformHelper.getFeaturePaths());
59         generator.setPDEState(TargetPlatformHelper.getState());
60         generator.setNextId(TargetPlatformHelper.getPDEState().getNextId());
61         generator.setStateExtraData(TargetPlatformHelper.getBundleClasspaths(TargetPlatformHelper.getPDEState()), TargetPlatformHelper.getPatchMap(TargetPlatformHelper.getPDEState()));
62         generator.setGenerateAssembleScript(false);
63         generator.generate();
64     }
65     
66     private void refreshLocal(IFeature feature, IProgressMonitor monitor)
67         throws CoreException {
68         IFeaturePlugin[] references = feature.getPlugins();
69         for (int i = 0; i < references.length; i++) {
70             IPluginModelBase refmodel = feature.getReferencedModel(references[i]);
71             if (refmodel != null) {
72                 IResource resource = refmodel.getUnderlyingResource();
73                 if (resource != null)
74                     resource.getProject().refreshLocal(IResource.DEPTH_ONE, monitor);
75             }
76         }
77         IFeatureChild[] included = feature.getIncludedFeatures();
78         for (int i = 0; i < included.length; i++) {
79             IFeature child = ((FeatureChild) included[i])
80                     .getReferencedFeature();
81             if (child != null && child != fFeatureModel.getFeature()) {
82                 IFeatureModel refmodel = child.getModel();
83                 if (refmodel != null && refmodel.getUnderlyingResource() != null) {
84                     refmodel.getUnderlyingResource().getProject().refreshLocal(
85                             IResource.DEPTH_ONE, monitor);
86                 }
87                 refreshLocal(child, monitor);
88
89             }
90         }
91     }
92     
93     protected void refreshLocal(IProgressMonitor monitor)
94         throws CoreException {
95         super.refreshLocal(monitor);
96         refreshLocal(fFeatureModel.getFeature(), monitor);
97     }
98 }
99
Popular Tags