1 11 package org.eclipse.pde.internal.ui.wizards.exports; 12 13 import java.io.File ; 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.ArrayList ; 16 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.osgi.service.resolver.BundleDescription; 21 import org.eclipse.osgi.service.resolver.State; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.PluginRegistry; 25 import org.eclipse.pde.internal.core.FeatureModelManager; 26 import org.eclipse.pde.internal.core.PDECore; 27 import org.eclipse.pde.internal.core.TargetPlatformHelper; 28 import org.eclipse.pde.internal.core.exports.FeatureExportInfo; 29 import org.eclipse.pde.internal.core.ifeature.IFeatureModel; 30 import org.eclipse.pde.internal.core.iproduct.IProductFeature; 31 import org.eclipse.pde.internal.core.iproduct.IProductPlugin; 32 import org.eclipse.pde.internal.core.product.WorkspaceProductModel; 33 import org.eclipse.pde.internal.ui.PDEPluginImages; 34 import org.eclipse.pde.internal.ui.PDEUIMessages; 35 import org.eclipse.pde.internal.ui.build.ProductExportJob; 36 import org.eclipse.pde.internal.ui.wizards.product.SynchronizationOperation; 37 import org.eclipse.ui.progress.IProgressConstants; 38 39 40 public class ProductExportWizard extends BaseExportWizard { 41 42 private static final String STORE_SECTION = "ProductExportWizard"; private WorkspaceProductModel fProductModel; 44 private CrossPlatformExportPage fPage2; 45 private ProductExportWizardPage fPage; 46 private IProject fProject; 47 48 public ProductExportWizard() { 49 this(null); 50 } 51 52 public ProductExportWizard(IProject project) { 53 setDefaultPageImageDescriptor(PDEPluginImages.DESC_PRODUCT_EXPORT_WIZ); 54 fProject = project; 55 } 56 57 public void addPages() { 58 fPage = new ProductExportWizardPage(getSelection()); 59 addPage(fPage); 60 61 IFeatureModel model = PDECore.getDefault().getFeatureModelManager().getDeltaPackFeature(); 62 if (model != null) { 63 fPage2 = new CrossPlatformExportPage("environment", model); addPage(fPage2); 65 } 66 } 67 68 protected String getSettingsSectionName() { 69 return STORE_SECTION; 70 } 71 72 protected void scheduleExportJob() { 73 FeatureExportInfo info = new FeatureExportInfo(); 74 info.toDirectory = fPage.doExportToDirectory(); 75 info.exportSource = fPage.doExportSource(); 76 info.destinationDirectory = fPage.getDestination(); 77 info.zipFileName = fPage.getFileName(); 78 if (fPage2 != null && fPage.doMultiPlatform()) 79 info.targets = fPage2.getTargets(); 80 if (fProductModel.getProduct().useFeatures()) 81 info.items = getFeatureModels(); 82 else 83 info.items = getPluginModels(); 84 85 String rootDirectory = fPage.getRootDirectory(); 86 if ("".equals(rootDirectory.trim())) rootDirectory = "."; ProductExportJob job = new ProductExportJob(info, fProductModel, rootDirectory); 89 job.setUser(true); 90 job.schedule(); 91 job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_FEATURE_OBJ); 92 } 93 94 private IFeatureModel[] getFeatureModels() { 95 ArrayList list = new ArrayList (); 96 FeatureModelManager manager = PDECore.getDefault() 97 .getFeatureModelManager(); 98 IProductFeature[] features = fProductModel.getProduct().getFeatures(); 99 for (int i = 0; i < features.length; i++) { 100 IFeatureModel model = manager.findFeatureModel(features[i].getId(), 101 features[i].getVersion()); 102 if (model != null) 103 list.add(model); 104 } 105 return (IFeatureModel[]) list.toArray(new IFeatureModel[list.size()]); 106 } 107 108 private BundleDescription[] getPluginModels() { 109 ArrayList list = new ArrayList (); 110 State state = TargetPlatformHelper.getState(); 111 IProductPlugin[] plugins = fProductModel.getProduct().getPlugins(); 112 for (int i = 0; i < plugins.length; i++) { 113 BundleDescription bundle = state.getBundle(plugins[i].getId(), null); 114 if (bundle != null) 115 list.add(bundle); 116 } 117 IPluginModelBase launcherPlugin = PluginRegistry.findModel("org.eclipse.equinox.launcher"); if (launcherPlugin != null) { 121 BundleDescription bundle = launcherPlugin.getBundleDescription(); 122 if (bundle != null && !list.contains(bundle)) { 123 list.add(bundle); 124 BundleDescription[] fragments = bundle.getFragments(); 125 for (int i = 0; i < fragments.length; i++) { 126 if (!list.contains(fragments[i])) { 127 list.add(fragments[i]); 128 } 129 } 130 } 131 } 132 return (BundleDescription[]) list.toArray(new BundleDescription[list.size()]); 133 } 134 135 protected boolean performPreliminaryChecks() { 136 fProductModel = new WorkspaceProductModel(fPage.getProductFile(), false); 137 try { 138 fProductModel.load(); 139 if (!fProductModel.isLoaded()) { 140 MessageDialog.openError(getContainer().getShell(), PDEUIMessages.ProductExportWizard_error, PDEUIMessages.ProductExportWizard_corrupt); return false; 142 } 143 } catch (CoreException e) { 144 MessageDialog.openError(getContainer().getShell(), PDEUIMessages.ProductExportWizard_error, PDEUIMessages.ProductExportWizard_corrupt); return false; 146 } 147 148 if (fPage.doSync()) { 149 try { 150 getContainer().run(false, false, new SynchronizationOperation(fProductModel.getProduct(), getContainer().getShell(), fProject)); 151 } catch (InvocationTargetException e) { 152 MessageDialog.openError(getContainer().getShell(), PDEUIMessages.ProductExportWizard_syncTitle, e.getTargetException().getMessage()); 153 return false; 154 } catch (InterruptedException e) { 155 return false; 156 } 157 } 158 return true; 159 } 160 161 protected boolean confirmDelete() { 162 if (!fPage.doExportToDirectory()) { 163 File zipFile = new File (fPage.getDestination(), fPage.getFileName()); 164 if (zipFile.exists()) { 165 if (!MessageDialog.openQuestion(getContainer().getShell(), 166 PDEUIMessages.BaseExportWizard_confirmReplace_title, 167 NLS.bind(PDEUIMessages.BaseExportWizard_confirmReplace_desc, zipFile.getAbsolutePath()))) 168 return false; 169 zipFile.delete(); 170 } 171 } 172 return true; 173 } 174 175 public boolean canFinish() { 176 return (fPage.getNextPage() != null) ? super.canFinish() : fPage.isPageComplete(); 177 } 178 179 } 180 | Popular Tags |