1 11 package org.eclipse.pde.internal.ui.wizards.tools; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.SubProgressMonitor; 20 import org.eclipse.jface.dialogs.IDialogSettings; 21 import org.eclipse.jface.operation.IRunnableWithProgress; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.pde.core.IBaseModel; 24 import org.eclipse.pde.core.plugin.IPluginModelBase; 25 import org.eclipse.pde.core.plugin.ISharedExtensionsModel; 26 import org.eclipse.pde.internal.core.ibundle.IBundle; 27 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 28 import org.eclipse.pde.internal.ui.PDEPlugin; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesOperation; 31 import org.eclipse.pde.internal.ui.search.dependencies.CalculateUsesOperation; 32 import org.eclipse.pde.internal.ui.search.dependencies.GatherUnusedDependenciesOperation; 33 import org.eclipse.pde.internal.ui.util.ModelModification; 34 import org.eclipse.pde.internal.ui.util.PDEModelUtility; 35 36 public class OrganizeManifestsOperation implements IRunnableWithProgress, IOrganizeManifestsSettings { 37 38 protected boolean fAddMissing = true; protected boolean fMarkInternal = true; protected String fPackageFilter = VALUE_DEFAULT_FILTER; 42 protected boolean fRemoveUnresolved = true; protected boolean fCalculateUses = false; protected boolean fModifyDep = true; protected boolean fRemoveDependencies = true; protected boolean fUnusedDependencies; protected boolean fRemoveLazy = true; protected boolean fPrefixIconNL; protected boolean fUnusedKeys; protected boolean fAddDependencies; 51 52 private ArrayList fProjectList; 53 private IProject fCurrentProject; 54 55 public OrganizeManifestsOperation(ArrayList projectList) { 56 fProjectList = projectList; 57 } 58 59 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 60 monitor.beginTask(PDEUIMessages.OrganizeManifestJob_taskName, fProjectList.size()); 61 for (int i = 0; i < fProjectList.size() && !monitor.isCanceled(); i++) 62 cleanProject((IProject)fProjectList.get(i), new SubProgressMonitor(monitor, 1)); 63 } 64 65 private void cleanProject(IProject project, IProgressMonitor monitor) { 66 fCurrentProject = project; 67 monitor.beginTask(fCurrentProject.getName(), getTotalTicksPerProject()); 68 69 final Exception [] ee = new Exception [1]; 70 ModelModification modification = new ModelModification(fCurrentProject) { 71 protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { 72 if (model instanceof IBundlePluginModelBase) 73 try { 74 runCleanup(monitor, (IBundlePluginModelBase)model); 75 } catch (InvocationTargetException e) { 76 ee[0] = e; 77 } catch (InterruptedException e) { 78 ee[0] = e; 79 } 80 } 81 }; 82 PDEModelUtility.modifyModel(modification, monitor); 83 if (ee[0] != null) 84 PDEPlugin.log(ee[0]); 85 } 86 87 88 private void runCleanup(IProgressMonitor monitor, IBundlePluginModelBase modelBase) throws InvocationTargetException , InterruptedException { 89 90 IBundle bundle = modelBase.getBundleModel().getBundle(); 91 ISharedExtensionsModel sharedExtensionsModel = modelBase.getExtensionsModel(); 92 IPluginModelBase extensionsModel = null; 93 if (sharedExtensionsModel instanceof IPluginModelBase) 94 extensionsModel = (IPluginModelBase)sharedExtensionsModel; 95 96 String projectName = fCurrentProject.getName(); 97 98 if (fAddMissing || fRemoveUnresolved) { 99 monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_export, projectName)); 100 if (!monitor.isCanceled()) 101 OrganizeManifest.organizeExportPackages(bundle, fCurrentProject, fAddMissing, fRemoveUnresolved); 102 if (fAddMissing) 103 monitor.worked(1); 104 if (fRemoveUnresolved) 105 monitor.worked(1); 106 } 107 108 if (fMarkInternal) { 109 monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_filterInternal, projectName)); 110 if (!monitor.isCanceled()) 111 OrganizeManifest.markPackagesInternal(bundle, fPackageFilter); 112 monitor.worked(1); 113 } 114 115 if (fModifyDep) { 116 String message = fRemoveDependencies ? 117 NLS.bind(PDEUIMessages.OrganizeManifestsOperation_removeUnresolved, projectName) : 118 NLS.bind(PDEUIMessages.OrganizeManifestsOperation_markOptionalUnresolved, projectName); 119 monitor.subTask(message); 120 if (!monitor.isCanceled()) 121 OrganizeManifest.organizeImportPackages(bundle, fRemoveDependencies); 122 monitor.worked(1); 123 124 if (!monitor.isCanceled()) 125 OrganizeManifest.organizeRequireBundles(bundle, fRemoveDependencies); 126 monitor.worked(1); 127 } 128 129 if (fCalculateUses) { 130 if (!monitor.isCanceled()) { 132 CalculateUsesOperation op = new CalculateUsesOperation(fCurrentProject, modelBase); 133 op.run(new SubProgressMonitor(monitor, 2)); 134 } 135 } 136 137 if (fAddDependencies) { 138 monitor.subTask(NLS.bind (PDEUIMessages.OrganizeManifestsOperation_additionalDeps, projectName)); 139 if (!monitor.isCanceled()) { 140 AddNewDependenciesOperation op = new AddNewDependenciesOperation(fCurrentProject, modelBase); 141 op.run(new SubProgressMonitor(monitor, 4)); 142 } 143 } 144 145 if (fUnusedDependencies) { 146 monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_unusedDeps, projectName)); 147 if (!monitor.isCanceled()) { 148 SubProgressMonitor submon = new SubProgressMonitor(monitor, 4); 149 GatherUnusedDependenciesOperation udo = new GatherUnusedDependenciesOperation(modelBase); 150 udo.run(submon); 151 GatherUnusedDependenciesOperation.removeDependencies(modelBase, udo.getList().toArray()); 152 submon.done(); 153 } 154 } 155 156 if (fRemoveLazy) { 157 monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_lazyStart, fCurrentProject.getName())); 158 if (!monitor.isCanceled()) 159 OrganizeManifest.removeUnneededLazyStart(bundle); 160 monitor.worked(1); 161 } 162 163 if (fPrefixIconNL) { 164 monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_nlIconPath, projectName)); 165 if (!monitor.isCanceled()) 166 OrganizeManifest.prefixIconPaths(extensionsModel); 167 monitor.worked(1); 168 } 169 170 if (fUnusedKeys) { 171 monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_unusedKeys, projectName)); 172 if (!monitor.isCanceled()) 173 OrganizeManifest.removeUnusedKeys(fCurrentProject, bundle, extensionsModel); 174 monitor.worked(1); 175 } 176 } 177 178 private int getTotalTicksPerProject() { 179 int ticks = 0; 180 if (fAddMissing) ticks += 1; 181 if (fMarkInternal) ticks += 1; 182 if (fRemoveUnresolved) ticks += 1; 183 if (fCalculateUses) ticks += 4; 184 if (fModifyDep) ticks += 2; 185 if (fUnusedDependencies)ticks += 4; 186 if (fAddDependencies) ticks += 4; 187 if (fRemoveLazy) ticks += 1; 188 if (fPrefixIconNL) ticks += 1; 189 if (fUnusedKeys) ticks += 1; 190 return ticks; 191 } 192 193 194 public void setOperations(IDialogSettings settings) { 195 fAddMissing = !settings.getBoolean(PROP_ADD_MISSING); 196 fMarkInternal = !settings.getBoolean(PROP_MARK_INTERNAL); 197 fPackageFilter = settings.get(PROP_INTERAL_PACKAGE_FILTER); 198 fRemoveUnresolved = !settings.getBoolean(PROP_REMOVE_UNRESOLVED_EX); 199 fCalculateUses = settings.getBoolean(PROP_CALCULATE_USES); 200 fModifyDep = !settings.getBoolean(PROP_MODIFY_DEP); 201 fRemoveDependencies = !settings.getBoolean(PROP_RESOLVE_IMP_MARK_OPT); 202 fUnusedDependencies = settings.getBoolean(PROP_UNUSED_DEPENDENCIES); 203 fRemoveLazy = !settings.getBoolean(PROP_REMOVE_LAZY); 204 fPrefixIconNL = settings.getBoolean(PROP_NLS_PATH); 205 fUnusedKeys = settings.getBoolean(PROP_UNUSED_KEYS); 206 fAddDependencies = settings.getBoolean(PROP_ADD_DEPENDENCIES); 207 } 208 } 209 | Popular Tags |