View | Details | Raw Unified | Return to bug 173793 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifest.java (-3 / +4 lines)
Lines 27-32 Link Here
27
import org.eclipse.jdt.core.IPackageFragmentRoot;
27
import org.eclipse.jdt.core.IPackageFragmentRoot;
28
import org.eclipse.jdt.core.JavaModelException;
28
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jface.text.IDocument;
29
import org.eclipse.jface.text.IDocument;
30
import org.eclipse.ltk.core.refactoring.TextFileChange;
30
import org.eclipse.osgi.service.resolver.BundleDescription;
31
import org.eclipse.osgi.service.resolver.BundleDescription;
31
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
32
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
32
import org.eclipse.osgi.service.resolver.HostSpecification;
33
import org.eclipse.osgi.service.resolver.HostSpecification;
Lines 225-231 Link Here
225
		
226
		
226
	}
227
	}
227
	
228
	
228
	public static void removeUnusedKeys(
229
	public static TextFileChange[] removeUnusedKeys(
229
			final IProject project,
230
			final IProject project,
230
			final IBundle bundle, 
231
			final IBundle bundle, 
231
			final IPluginModelBase modelBase) {
232
			final IPluginModelBase modelBase) {
Lines 234-242 Link Here
234
			localization = "plugin"; //$NON-NLS-1$
235
			localization = "plugin"; //$NON-NLS-1$
235
		IFile propertiesFile = project.getFile(localization + ".properties"); //$NON-NLS-1$
236
		IFile propertiesFile = project.getFile(localization + ".properties"); //$NON-NLS-1$
236
		if (!propertiesFile.exists())
237
		if (!propertiesFile.exists())
237
			return;
238
			return new TextFileChange[0];
238
		
239
		
239
		PDEModelUtility.modifyModel(new ModelModification(propertiesFile) {
240
		return PDEModelUtility.changesForModelModication(new ModelModification(propertiesFile) {
240
			protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException {
241
			protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException {
241
				if (!(model instanceof IBuildModel))
242
				if (!(model instanceof IBuildModel))
242
					return;
243
					return;
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsWizard.java (-23 / +10 lines)
Lines 10-54 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.wizards.tools;
11
package org.eclipse.pde.internal.ui.wizards.tools;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
14
import java.util.ArrayList;
15
16
import org.eclipse.jface.wizard.Wizard;
17
import org.eclipse.pde.internal.ui.PDEPlugin;
14
import org.eclipse.pde.internal.ui.PDEPlugin;
18
import org.eclipse.pde.internal.ui.PDEPluginImages;
15
import org.eclipse.pde.internal.ui.PDEPluginImages;
19
import org.eclipse.pde.internal.ui.PDEUIMessages;
16
import org.eclipse.pde.internal.ui.PDEUIMessages;
20
17
21
public class OrganizeManifestsWizard extends Wizard {
18
public class OrganizeManifestsWizard extends RefactoringWizard {
22
19
23
	private OrganizeManifestsWizardPage fMainPage;
20
	private OrganizeManifestsWizardPage fMainPage;
24
	private ArrayList fProjects;
21
	private OrganizeManifestsRefactor fRefactoring;
25
	
22
	
26
	public OrganizeManifestsWizard(ArrayList projects) {
23
	public OrganizeManifestsWizard(OrganizeManifestsRefactor refactoring) {
27
		fProjects = projects;
24
		super(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE);
25
		fRefactoring = refactoring;
28
		setNeedsProgressMonitor(true);
26
		setNeedsProgressMonitor(true);
29
		setWindowTitle(PDEUIMessages.OrganizeManifestsWizard_title);
27
		setWindowTitle(PDEUIMessages.OrganizeManifestsWizard_title);
30
		setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
28
		setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
31
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_ORGANIZE_MANIFESTS);
29
		setDefaultPageImageDescriptor(PDEPluginImages.DESC_ORGANIZE_MANIFESTS);
32
	}
30
	}
33
34
	public boolean performFinish() {
31
	public boolean performFinish() {
35
		fMainPage.preformOk();
32
		fMainPage.preformOk();
36
		try {
33
		return super.performFinish();
37
			OrganizeManifestsOperation op = new OrganizeManifestsOperation(fProjects);
38
			op.setOperations(fMainPage.getSettings());
39
			getContainer().run(false, true, op);
40
		} catch (InvocationTargetException e) {
41
			PDEPlugin.log(e);
42
			return false;
43
		} catch (InterruptedException e) {
44
			PDEPlugin.log(e);
45
			return false;
46
		}
47
		return true;
48
	}
34
	}
49
	
35
	protected void addUserInputPages() {
50
	public void addPages() {
36
		setDefaultPageTitle( getRefactoring().getName() );
51
		fMainPage = new OrganizeManifestsWizardPage();
37
		fMainPage = new OrganizeManifestsWizardPage();
38
		fMainPage.setProcessor((OrganizeManifestsProcessor)fRefactoring.getProcessor());
52
		addPage(fMainPage);
39
		addPage(fMainPage);
53
	}
40
	}
54
}
41
}
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsWizardPage.java (-2 / +40 lines)
Lines 12-18 Link Here
12
12
13
import org.eclipse.jface.dialogs.Dialog;
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.jface.dialogs.IDialogSettings;
14
import org.eclipse.jface.dialogs.IDialogSettings;
15
import org.eclipse.jface.wizard.WizardPage;
15
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
16
import org.eclipse.pde.internal.ui.IHelpContextIds;
16
import org.eclipse.pde.internal.ui.IHelpContextIds;
17
import org.eclipse.pde.internal.ui.IPreferenceConstants;
17
import org.eclipse.pde.internal.ui.IPreferenceConstants;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
Lines 28-34 Link Here
28
import org.eclipse.swt.widgets.Text;
28
import org.eclipse.swt.widgets.Text;
29
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.PlatformUI;
30
30
31
public class OrganizeManifestsWizardPage extends WizardPage implements IPreferenceConstants, IOrganizeManifestsSettings {
31
public class OrganizeManifestsWizardPage extends UserInputWizardPage implements IPreferenceConstants, IOrganizeManifestsSettings {
32
	
32
	
33
	private Button fRemoveUnresolved;
33
	private Button fRemoveUnresolved;
34
	private Button fCalculateUses;
34
	private Button fCalculateUses;
Lines 48-53 Link Here
48
	private Button[] fTopLevelButtons; // used for setting page complete state
48
	private Button[] fTopLevelButtons; // used for setting page complete state
49
	private Button[] fParentButtons; // parents with children that need to be dis/enabled
49
	private Button[] fParentButtons; // parents with children that need to be dis/enabled
50
	
50
	
51
	private OrganizeManifestsProcessor fProcessor;
52
	
51
	
53
	
52
	private static String title = PDEUIMessages.OrganizeManifestsWizardPage_title;
54
	private static String title = PDEUIMessages.OrganizeManifestsWizardPage_title;
53
	protected OrganizeManifestsWizardPage() {
55
	protected OrganizeManifestsWizardPage() {
Lines 248-261 Link Here
248
		hookListener(fParentButtons, new SelectionAdapter() {
250
		hookListener(fParentButtons, new SelectionAdapter() {
249
			public void widgetSelected(SelectionEvent e) {
251
			public void widgetSelected(SelectionEvent e) {
250
				setEnabledStates();
252
				setEnabledStates();
253
				doProcessorSetting(e.getSource());
251
			}
254
			}
252
		});
255
		});
253
		hookListener(fTopLevelButtons, new SelectionAdapter() {
256
		hookListener(fTopLevelButtons, new SelectionAdapter() {
254
			public void widgetSelected(SelectionEvent e) {
257
			public void widgetSelected(SelectionEvent e) {
255
				setPageComplete();
258
				setPageComplete();
259
				doProcessorSetting(e.getSource());
256
			}
260
			}
257
		});
261
		});
258
	}
262
	}
263
264
	private void doProcessorSetting(Object source) {
265
		if (fAddMissing.equals(source))
266
			fProcessor.setAddMissing(fAddMissing.getSelection());
267
		else if (fMarkInternal.equals(source))
268
			fProcessor.setMarkInternal(fMarkInternal.getSelection());
269
		else if (fPackageFilter.equals(source))
270
			fProcessor.setPackageFilter(fPackageFilter.getText());
271
		else if (fRemoveUnresolved.equals(source))
272
			fProcessor.setRemoveUnresolved(fRemoveUnresolved.getSelection());
273
		else if (fCalculateUses.equals(source))
274
			fProcessor.setCalculateUses(fCalculateUses.getSelection());
275
276
		else if (fModifyDependencies.equals(source))
277
			fProcessor.setModifyDep(fModifyDependencies.getSelection());
278
		else if (fOptionalImport.equals(source))
279
			fProcessor.setRemoveDependencies(fOptionalImport.getSelection());
280
		else if (fUnusedDependencies.equals(source))
281
			fProcessor.setUnusedDependencies(fUnusedDependencies.getSelection());
282
		else if (fAdditonalDependencies.equals(source))
283
			fProcessor.setAddDependencies(fAdditonalDependencies.getSelection());
284
285
		else if (fRemoveLazy.equals(source))
286
			fProcessor.setRemoveLazy(fRemoveLazy.getSelection());
287
288
		else if (fFixIconNLSPaths.equals(source))
289
			fProcessor.setPrefixIconNL(fFixIconNLSPaths.getSelection());
290
		else if (fRemovedUnusedKeys.equals(source))
291
			fProcessor.setRemoveUnresolved(fRemovedUnusedKeys.getSelection());
292
	}
259
	
293
	
260
	private void hookListener(Button[] buttons, SelectionAdapter adapter) {
294
	private void hookListener(Button[] buttons, SelectionAdapter adapter) {
261
		for (int i = 0; i < buttons.length; i++) {
295
		for (int i = 0; i < buttons.length; i++) {
Lines 266-269 Link Here
266
	protected IDialogSettings getSettings() {
300
	protected IDialogSettings getSettings() {
267
		return getDialogSettings();
301
		return getDialogSettings();
268
	}
302
	}
303
304
	protected void setProcessor(OrganizeManifestsProcessor processor) {
305
		fProcessor = processor;
306
	}
269
}
307
}
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsAction.java (-11 / +11 lines)
Lines 19-29 Link Here
19
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.wizard.WizardDialog;
22
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
23
import org.eclipse.pde.internal.core.ICoreConstants;
23
import org.eclipse.pde.internal.core.ICoreConstants;
24
import org.eclipse.pde.internal.ui.PDEPlugin;
24
import org.eclipse.pde.internal.ui.PDEPlugin;
25
import org.eclipse.pde.internal.ui.PDEUIMessages;
25
import org.eclipse.pde.internal.ui.PDEUIMessages;
26
import org.eclipse.swt.custom.BusyIndicator;
27
import org.eclipse.ui.IWorkbenchWindow;
26
import org.eclipse.ui.IWorkbenchWindow;
28
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
27
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
29
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
Lines 62-76 Link Here
62
					projects.add(proj);
61
					projects.add(proj);
63
			}
62
			}
64
			if (projects.size() > 0) {
63
			if (projects.size() > 0) {
65
				OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(projects);
64
				OrganizeManifestsProcessor processor = new OrganizeManifestsProcessor(projects);
66
				final WizardDialog dialog = new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard);
65
				OrganizeManifestsRefactor refactor = new OrganizeManifestsRefactor(processor);
67
				BusyIndicator.showWhile(
66
				OrganizeManifestsWizard wizard = new OrganizeManifestsWizard(refactor);
68
						PDEPlugin.getActiveWorkbenchShell().getDisplay(), 
67
				processor.initSettings(wizard.getDialogSettings());
69
						new Runnable() {
68
				RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation( wizard );
70
					public void run() {
69
				
71
						dialog.open();
70
			    try {
72
					}
71
			      op.run( PDEPlugin.getActiveWorkbenchShell(), "" ); //$NON-NLS-1$
73
				});
72
			    } catch( final InterruptedException irex ) {
73
			    }
74
			} else
74
			} else
75
				MessageDialog.openInformation(
75
				MessageDialog.openInformation(
76
						PDEPlugin.getActiveWorkbenchShell(),
76
						PDEPlugin.getActiveWorkbenchShell(),
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsOperation.java (-208 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 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.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
	// if operation is executed without setting operations, these defaults will be used
39
	protected boolean fAddMissing = true; // add all packages to export-package
40
	protected boolean fMarkInternal = true; // mark export-package as internal
41
	protected String fPackageFilter = VALUE_DEFAULT_FILTER;
42
	protected boolean fRemoveUnresolved = true; // remove unresolved export-package
43
	protected boolean fCalculateUses = false; // calculate the 'uses' directive for exported packages
44
	protected boolean fModifyDep = true; // modify import-package / require-bundle
45
	protected boolean fRemoveDependencies = true; // if true: remove, else mark optional
46
	protected boolean fUnusedDependencies; // find/remove unused dependencies - long running op
47
	protected boolean fRemoveLazy = true; // remove lazy/auto start if no activator
48
	protected boolean fPrefixIconNL; // prefix icon paths with $nl$
49
	protected boolean fUnusedKeys; // remove unused <bundle-localization>.properties keys
50
	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
			// we don't set the subTask because it is done in the CalculateUsesOperation, for each package it scans
131
			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
}
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (-8 / +4 lines)
Lines 73-78 Link Here
73
73
74
	public static String JavaArgumentsTab_appendLauncherIni;
74
	public static String JavaArgumentsTab_appendLauncherIni;
75
75
76
	public static String OrganizeManifestsProcessor_invalidParam;
77
78
	public static String OrganizeManifestsProcessor_rootMessage;
79
76
	public static String PDEWizardNewFileCreationPage_errorMsgStartsWithDot;
80
	public static String PDEWizardNewFileCreationPage_errorMsgStartsWithDot;
77
81
78
	public static String CommandComposerPart_formTitle;
82
	public static String CommandComposerPart_formTitle;
Lines 283-292 Link Here
283
287
284
	public static String PluginsTabToolBar_auto_validate;
288
	public static String PluginsTabToolBar_auto_validate;
285
289
286
	public static String PluginsTabToolBar_filter_disabled;
287
288
	public static String PluginsTabToolBar_filter_options;
289
290
	public static String PluginsTabToolBar_validate;
290
	public static String PluginsTabToolBar_validate;
291
291
292
	public static String PointSelectionPage_cannotFindTemplate;
292
	public static String PointSelectionPage_cannotFindTemplate;
Lines 1642-1654 Link Here
1642
	public static String DependencyAnalysisSection_title;
1642
	public static String DependencyAnalysisSection_title;
1643
	public static String DependencyAnalysisSection_loops;
1643
	public static String DependencyAnalysisSection_loops;
1644
	public static String DependencyAnalysisSection_noCycles;
1644
	public static String DependencyAnalysisSection_noCycles;
1645
	public static String DependencyAnalysisSection_references;
1646
	public static String DependencyExtentOperation_searching;
1645
	public static String DependencyExtentOperation_searching;
1647
	public static String DependencyExtentOperation_inspecting;
1646
	public static String DependencyExtentOperation_inspecting;
1648
	public static String DependencyExtentSearchResult_dependency;
1647
	public static String DependencyExtentSearchResult_dependency;
1649
	public static String DependencyExtentSearchResult_dependencies;
1648
	public static String DependencyExtentSearchResult_dependencies;
1650
	public static String DependencyAnalysisSection_fragment_editable;
1649
	public static String DependencyAnalysisSection_fragment_editable;
1651
	public static String DependencyAnalysisSection_noReferencesFound;
1652
	public static String DependencyAnalysisSection_fragment_notEditable;
1650
	public static String DependencyAnalysisSection_fragment_notEditable;
1653
	public static String DependencyAnalysisSection_plugin_editable;
1651
	public static String DependencyAnalysisSection_plugin_editable;
1654
	public static String DependencyAnalysisSection_plugin_notEditable;
1652
	public static String DependencyAnalysisSection_plugin_notEditable;
Lines 2422-2429 Link Here
2422
2420
2423
	public static String SchemaAttributeDetails_use;
2421
	public static String SchemaAttributeDetails_use;
2424
2422
2425
	public static String SchemaAttributeDetails_defaultValue;
2426
2427
	public static String SchemaAttributeDetails_type;
2423
	public static String SchemaAttributeDetails_type;
2428
2424
2429
	public static String SchemaAttributeDetails_restrictions;
2425
	public static String SchemaAttributeDetails_restrictions;
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (-5 / +2 lines)
Lines 403-409 Link Here
403
SchemaElementReferenceDetails_reference=Reference:
403
SchemaElementReferenceDetails_reference=Reference:
404
SchemaAttributeDetails_removeRestButton=Remove
404
SchemaAttributeDetails_removeRestButton=Remove
405
SchemaElementReferenceDetails_title=Element Reference Details
405
SchemaElementReferenceDetails_title=Element Reference Details
406
SchemaAttributeDetails_defaultValue=Default Value:
407
SchemaDetails_translatable=Translatable:
406
SchemaDetails_translatable=Translatable:
408
SchemaAttributeDetails_restrictions=Restrictions:
407
SchemaAttributeDetails_restrictions=Restrictions:
409
SchemaAttributeDetails_browseButton=Browse...
408
SchemaAttributeDetails_browseButton=Browse...
Lines 1257-1263 Link Here
1257
DependencyAnalysisSection_noCycles=The dependency graph of this plug-in does not contain cycles.
1256
DependencyAnalysisSection_noCycles=The dependency graph of this plug-in does not contain cycles.
1258
DependencyPropertiesDialog_version=Version:
1257
DependencyPropertiesDialog_version=Version:
1259
DependencyPropertiesDialog_versionRangeError=Minimum version must be less than or equal to maximum version
1258
DependencyPropertiesDialog_versionRangeError=Minimum version must be less than or equal to maximum version
1260
DependencyAnalysisSection_references=References
1261
DependencyPropertiesDialog_properties=Properties
1259
DependencyPropertiesDialog_properties=Properties
1262
DependencyExtentOperation_searching=Searching for dependencies on
1260
DependencyExtentOperation_searching=Searching for dependencies on
1263
DependencyPropertiesDialog_optional=&Optional
1261
DependencyPropertiesDialog_optional=&Optional
Lines 1271-1277 Link Here
1271
<p><img href="dependencies"/> <a href="references">Find this fragment's host plug-in</a></p>\
1269
<p><img href="dependencies"/> <a href="references">Find this fragment's host plug-in</a></p>\
1272
<p><img href="search"/> <a href="unused">Find unused dependencies</a></p>\
1270
<p><img href="search"/> <a href="unused">Find unused dependencies</a></p>\
1273
</form>
1271
</form>
1274
DependencyAnalysisSection_noReferencesFound=No plug-ins reference this fragment.
1275
DependencyAnalysisSection_fragment_notEditable=<form>\
1272
DependencyAnalysisSection_fragment_notEditable=<form>\
1276
<p><img href="dependencies"/> <a href="references">Find this fragment's host plug-in</a></p>\
1273
<p><img href="dependencies"/> <a href="references">Find this fragment's host plug-in</a></p>\
1277
</form>
1274
</form>
Lines 1326-1332 Link Here
1326
PluginsTabToolBar_auto_validate=Validate {0} automatically prior to launching
1323
PluginsTabToolBar_auto_validate=Validate {0} automatically prior to launching
1327
PluginsView_addToJavaSearch=&Add to Java Search
1324
PluginsView_addToJavaSearch=&Add to Java Search
1328
PluginsView_removeFromJavaSearch=Remove &from Java Search
1325
PluginsView_removeFromJavaSearch=Remove &from Java Search
1329
PluginsTabToolBar_filter_options=Filtering Options
1330
PluginWorkingSet_setContent=Working set content:
1326
PluginWorkingSet_setContent=Working set content:
1331
PluginWorkingSet_selectAll_label=Select &All
1327
PluginWorkingSet_selectAll_label=Select &All
1332
PluginDevelopmentPage_extensions=&Always show the Extensions and Extension Points tabs
1328
PluginDevelopmentPage_extensions=&Always show the Extensions and Extension Points tabs
Lines 1351-1357 Link Here
1351
PluginsView_CollapseAllAction_tooltip = Collapse All
1347
PluginsView_CollapseAllAction_tooltip = Collapse All
1352
# Select all is part of a submenu "Select" hence the label is not "Select all"
1348
# Select all is part of a submenu "Select" hence the label is not "Select all"
1353
PluginsView_SelectAllAction_label = &All
1349
PluginsView_SelectAllAction_label = &All
1354
PluginsTabToolBar_filter_disabled=Filter disabled target {0}
1355
1350
1356
1351
1357
PluginSection_open=Open
1352
PluginSection_open=Open
Lines 2034-2045 Link Here
2034
OrganizeManifestsOperation_nlIconPath=checking icon paths for missing $nl$ segments... {0}
2029
OrganizeManifestsOperation_nlIconPath=checking icon paths for missing $nl$ segments... {0}
2035
OrganizeManifestsOperation_unusedKeys=checking for unused keys... {0} 
2030
OrganizeManifestsOperation_unusedKeys=checking for unused keys... {0} 
2036
OrganizeManifestsWizardPage_addMissing=&Ensure that all packages appear in the MANIFEST.MF
2031
OrganizeManifestsWizardPage_addMissing=&Ensure that all packages appear in the MANIFEST.MF
2032
OrganizeManifestsProcessor_rootMessage=Organize Manifest for {0}
2037
OrganizeManifestsWizardPage_lazyStart=Remove unnecessary Eclipse-La&zyStart headers
2033
OrganizeManifestsWizardPage_lazyStart=Remove unnecessary Eclipse-La&zyStart headers
2038
OrganizeRequireBundleResolution_Description=Organize Require Bundle Header
2034
OrganizeRequireBundleResolution_Description=Organize Require Bundle Header
2039
OrganizeImportPackageResolution_Description=Organize Import Package Header
2035
OrganizeImportPackageResolution_Description=Organize Import Package Header
2040
OrganizeExportPackageResolution_Description=Organize Export Package Header
2036
OrganizeExportPackageResolution_Description=Organize Export Package Header
2041
OrganizeManifestsOperation_filterInternal=marking export packages matching filter as internal... {0}
2037
OrganizeManifestsOperation_filterInternal=marking export packages matching filter as internal... {0}
2042
OrganizeManifestsWizardPage_description=Organize and clean up plug-in projects.
2038
OrganizeManifestsWizardPage_description=Organize and clean up plug-in projects.
2039
OrganizeManifestsProcessor_invalidParam=Invalid parameter passed to organize manifests processor
2043
OrganizeManifestsWizardPage_exportedGroup=Exported Packages
2040
OrganizeManifestsWizardPage_exportedGroup=Exported Packages
2044
OrganizeManifestsWizardPage_markInternal=Mark as &internal all packages that match the following filter:
2041
OrganizeManifestsWizardPage_markInternal=Mark as &internal all packages that match the following filter:
2045
OrganizeManifestsWizardPage_packageFilter=Package &filter:
2042
OrganizeManifestsWizardPage_packageFilter=Package &filter:
(-)src/org/eclipse/pde/internal/ui/launcher/LauncherUtils.java (-7 / +9 lines)
Lines 14-20 Link Here
14
import java.io.FileInputStream;
14
import java.io.FileInputStream;
15
import java.io.FileOutputStream;
15
import java.io.FileOutputStream;
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.lang.reflect.InvocationTargetException;
18
import java.util.ArrayList;
17
import java.util.ArrayList;
19
import java.util.HashSet;
18
import java.util.HashSet;
20
import java.util.Iterator;
19
import java.util.Iterator;
Lines 30-35 Link Here
30
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IPath;
31
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.IStatus;
32
import org.eclipse.core.runtime.OperationCanceledException;
33
import org.eclipse.core.runtime.Path;
33
import org.eclipse.core.runtime.Path;
34
import org.eclipse.core.runtime.Status;
34
import org.eclipse.core.runtime.Status;
35
import org.eclipse.debug.core.ILaunchConfiguration;
35
import org.eclipse.debug.core.ILaunchConfiguration;
Lines 44-49 Link Here
44
import org.eclipse.jface.dialogs.IDialogSettings;
44
import org.eclipse.jface.dialogs.IDialogSettings;
45
import org.eclipse.jface.dialogs.MessageDialog;
45
import org.eclipse.jface.dialogs.MessageDialog;
46
import org.eclipse.jface.preference.IPreferenceStore;
46
import org.eclipse.jface.preference.IPreferenceStore;
47
import org.eclipse.ltk.core.refactoring.Change;
47
import org.eclipse.osgi.util.NLS;
48
import org.eclipse.osgi.util.NLS;
48
import org.eclipse.pde.core.plugin.IPluginModelBase;
49
import org.eclipse.pde.core.plugin.IPluginModelBase;
49
import org.eclipse.pde.core.plugin.PluginRegistry;
50
import org.eclipse.pde.core.plugin.PluginRegistry;
Lines 56-62 Link Here
56
import org.eclipse.pde.internal.ui.PDEPlugin;
57
import org.eclipse.pde.internal.ui.PDEPlugin;
57
import org.eclipse.pde.internal.ui.PDEUIMessages;
58
import org.eclipse.pde.internal.ui.PDEUIMessages;
58
import org.eclipse.pde.internal.ui.wizards.tools.IOrganizeManifestsSettings;
59
import org.eclipse.pde.internal.ui.wizards.tools.IOrganizeManifestsSettings;
59
import org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsOperation;
60
import org.eclipse.pde.internal.ui.wizards.tools.OrganizeManifestsProcessor;
60
import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
61
import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
61
import org.eclipse.swt.widgets.Display;
62
import org.eclipse.swt.widgets.Display;
62
import org.eclipse.swt.widgets.Shell;
63
import org.eclipse.swt.widgets.Shell;
Lines 178-195 Link Here
178
			if (!projects.isEmpty())
179
			if (!projects.isEmpty())
179
				Display.getDefault().syncExec(new Runnable() {
180
				Display.getDefault().syncExec(new Runnable() {
180
					public void run() {
181
					public void run() {
181
						OrganizeManifestsOperation op = new OrganizeManifestsOperation(projects);
182
						OrganizeManifestsProcessor op = new OrganizeManifestsProcessor(projects);
182
						op.setOperations(getSettings());
183
						op.initSettings(getSettings());
183
						try {
184
						try {
184
							op.run(monitor);
185
							Change change = op.createChange(monitor);
186
							change.perform(monitor);
185
							// update table for each project with current time stamp
187
							// update table for each project with current time stamp
186
							Properties table = getLastRun();
188
							Properties table = getLastRun();
187
							String ts = Long.toString(System.currentTimeMillis());
189
							String ts = Long.toString(System.currentTimeMillis());
188
							Iterator it = projects.iterator();
190
							Iterator it = projects.iterator();
189
							while (it.hasNext()) 
191
							while (it.hasNext()) 
190
								table.put(((IProject)it.next()).getName(), ts);
192
								table.put(((IProject)it.next()).getName(), ts);
191
						} catch (InvocationTargetException e) {
193
						} catch (OperationCanceledException e) {
192
						} catch (InterruptedException e) {
194
						} catch (CoreException e) {
193
						} 
195
						} 
194
					}
196
					}
195
				});
197
				});
(-)src/org/eclipse/pde/internal/ui/util/PDEModelUtility.java (-61 / +79 lines)
Lines 17-28 Link Here
17
import org.eclipse.core.filebuffers.FileBuffers;
17
import org.eclipse.core.filebuffers.FileBuffers;
18
import org.eclipse.core.filebuffers.ITextFileBuffer;
18
import org.eclipse.core.filebuffers.ITextFileBuffer;
19
import org.eclipse.core.filebuffers.ITextFileBufferManager;
19
import org.eclipse.core.filebuffers.ITextFileBufferManager;
20
import org.eclipse.core.filebuffers.LocationKind;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.jface.text.BadLocationException;
25
import org.eclipse.jface.text.BadLocationException;
25
import org.eclipse.jface.text.IDocument;
26
import org.eclipse.jface.text.IDocument;
27
import org.eclipse.ltk.core.refactoring.TextFileChange;
26
import org.eclipse.pde.core.IBaseModel;
28
import org.eclipse.pde.core.IBaseModel;
27
import org.eclipse.pde.core.plugin.IPluginModelBase;
29
import org.eclipse.pde.core.plugin.IPluginModelBase;
28
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
30
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
Lines 302-376 Link Here
302
			// open editor found, should have underlying text listeners -> apply modification
304
			// open editor found, should have underlying text listeners -> apply modification
303
			modifyEditorModel(modification, editor, model, monitor);
305
			modifyEditorModel(modification, editor, model, monitor);
304
		} else {
306
		} else {
305
			// create own model, attach listeners and grab text edits
307
			generateModelEdits(modification, monitor, true);
306
			ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
308
		}
307
			IFile[] files;
309
	}
308
			if (modification.isFullBundleModification()) {
310
	
309
				files = new IFile[2];
311
	public static TextFileChange[] changesForModelModication (final ModelModification modification, final IProgressMonitor monitor) {
310
				files[F_Bi] = modification.getManifestFile();
312
		return generateModelEdits(modification, monitor, false);
311
				files[F_Xi] = modification.getXMLFile();
313
	}
312
			} else {
314
	
313
				files = new IFile[] { modification.getFile() };
315
	private static TextFileChange[] generateModelEdits (final ModelModification modification, final IProgressMonitor monitor,
316
			boolean performEdits) {
317
		ArrayList edits = new ArrayList();
318
		// create own model, attach listeners and grab text edits
319
		ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
320
		IFile[] files;
321
		if (modification.isFullBundleModification()) {
322
			files = new IFile[2];
323
			files[F_Bi] = modification.getManifestFile();
324
			files[F_Xi] = modification.getXMLFile();
325
		} else {
326
			files = new IFile[] { modification.getFile() };
327
		}
328
		// need to monitor number of successfull buffer connections for disconnection purposes
329
		// @see } finally { statement
330
		int sc = 0;
331
		try {
332
			ITextFileBuffer[] buffers = new ITextFileBuffer[files.length];
333
			IDocument[] documents = new IDocument[files.length];
334
			for (int i = 0; i < files.length; i++) {
335
				if (files[i] == null || !files[i].exists())
336
					continue;
337
				manager.connect(files[i].getFullPath(), LocationKind.IFILE, monitor);
338
				sc++;
339
				buffers[i] = manager.getTextFileBuffer(files[i].getFullPath(), LocationKind.IFILE);
340
				if (buffers[i].isDirty())
341
					buffers[i].commit(monitor, true);
342
				documents[i] = buffers[i].getDocument();
314
			}
343
			}
315
			// need to monitor number of successfull buffer connections for disconnection purposes
344
			
316
			// @see } finally { statement
345
			IBaseModel editModel;
317
			int sc = 0;
346
			if (modification.isFullBundleModification())
318
			try {
347
				editModel = prepareBundlePluginModel(files, documents);
319
				ITextFileBuffer[] buffers = new ITextFileBuffer[files.length];
348
			else
320
				IDocument[] documents = new IDocument[files.length];
349
				editModel = prepareAbstractEditingModel(files[0], documents[0]);
321
				for (int i = 0; i < files.length; i++) {
350
			
322
					if (files[i] == null || !files[i].exists())
351
			modification.modifyModel(editModel, monitor);
323
						continue;
352
			
324
					manager.connect(files[i].getFullPath(), monitor);
353
			IModelTextChangeListener[] listeners = gatherListeners(editModel);
325
					sc++;
354
			for (int i = 0; i < listeners.length; i++) {
326
					buffers[i] = manager.getTextFileBuffer(files[i].getFullPath());
355
				if (listeners[i] == null)
327
					if (buffers[i].isDirty())
356
					continue;
328
						buffers[i].commit(monitor, true);
357
				TextEdit[] currentEdits = listeners[i].getTextOperations();
329
					documents[i] = buffers[i].getDocument();
358
				if (currentEdits.length > 0) {
330
				}
359
					MultiTextEdit multi = new MultiTextEdit();
331
				
360
					multi.addChildren(currentEdits);
332
				IBaseModel editModel;
361
					if (performEdits) {
333
				if (modification.isFullBundleModification())
334
					editModel = prepareBundlePluginModel(files, documents);
335
				else
336
					editModel = prepareAbstractEditingModel(files[0], documents[0]);
337
				
338
				modification.modifyModel(editModel, monitor);
339
				
340
				IModelTextChangeListener[] listeners = gatherListeners(editModel);
341
				for (int i = 0; i < listeners.length; i++) {
342
					if (listeners[i] == null)
343
						continue;
344
					TextEdit[] edits = listeners[i].getTextOperations();
345
					if (edits.length > 0) {
346
						MultiTextEdit multi = new MultiTextEdit();
347
						multi.addChildren(edits);
348
						multi.apply(documents[i]);
362
						multi.apply(documents[i]);
349
						buffers[i].commit(monitor, true);
363
						buffers[i].commit(monitor, true);
350
					}
364
					}
365
					TextFileChange change = new TextFileChange(files[i].getName(), files[i]);
366
					change.setEdit(multi);
367
					edits.add(change);
351
				}
368
				}
352
			} catch (CoreException e) {
369
			}
353
				PDEPlugin.log(e);
370
		} catch (CoreException e) {
354
			} catch (MalformedTreeException e) {
371
			PDEPlugin.log(e);
355
				PDEPlugin.log(e);
372
		} catch (MalformedTreeException e) {
356
			} catch (BadLocationException e) {
373
			PDEPlugin.log(e);
357
				PDEPlugin.log(e);
374
		} catch (BadLocationException e) {
358
			} finally {
375
			PDEPlugin.log(e);
359
				// don't want to over-disconnect in case we ran into an exception during connections
376
		} finally {
360
				// dc <= sc stops this from happening
377
			// don't want to over-disconnect in case we ran into an exception during connections
361
				int dc = 0;
378
			// dc <= sc stops this from happening
362
				for (int i = 0; i < files.length && dc <= sc; i++) {
379
			int dc = 0;
363
					if (files[i] == null || !files[i].exists())
380
			for (int i = 0; i < files.length && dc <= sc; i++) {
364
						continue;
381
				if (files[i] == null || !files[i].exists())
365
					try {
382
					continue;
366
						manager.disconnect(files[i].getFullPath(), monitor);
383
				try {
367
						dc++;
384
					manager.disconnect(files[i].getFullPath(), LocationKind.IFILE, monitor);
368
					} catch (CoreException e) {
385
					dc++;
369
						PDEPlugin.log(e);
386
				} catch (CoreException e) {
370
					}
387
					PDEPlugin.log(e);
371
				}
388
				}
372
			}
389
			}
373
		}
390
		}
391
		return (TextFileChange[])edits.toArray(new TextFileChange[edits.size()]);
374
	}
392
	}
375
	
393
	
376
	private static void modifyEditorModel(
394
	private static void modifyEditorModel(
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsProcessor.java (+292 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.wizards.tools;
2
3
import java.lang.reflect.InvocationTargetException;
4
import java.util.ArrayList;
5
import java.util.Iterator;
6
7
import org.eclipse.core.resources.IProject;
8
import org.eclipse.core.runtime.CoreException;
9
import org.eclipse.core.runtime.IProgressMonitor;
10
import org.eclipse.core.runtime.OperationCanceledException;
11
import org.eclipse.core.runtime.SubProgressMonitor;
12
import org.eclipse.jface.dialogs.IDialogSettings;
13
import org.eclipse.ltk.core.refactoring.Change;
14
import org.eclipse.ltk.core.refactoring.CompositeChange;
15
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
16
import org.eclipse.ltk.core.refactoring.TextFileChange;
17
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
18
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
19
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
20
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
21
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.pde.core.IBaseModel;
23
import org.eclipse.pde.core.plugin.IPluginModelBase;
24
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
25
import org.eclipse.pde.internal.core.ibundle.IBundle;
26
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
27
import org.eclipse.pde.internal.ui.PDEPlugin;
28
import org.eclipse.pde.internal.ui.PDEUIMessages;
29
import org.eclipse.pde.internal.ui.search.dependencies.AddNewDependenciesOperation;
30
import org.eclipse.pde.internal.ui.search.dependencies.CalculateUsesOperation;
31
import org.eclipse.pde.internal.ui.search.dependencies.GatherUnusedDependenciesOperation;
32
import org.eclipse.pde.internal.ui.util.ModelModification;
33
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
34
35
public class OrganizeManifestsProcessor extends RefactoringProcessor implements IOrganizeManifestsSettings {
36
	
37
	// if operation is executed without setting operations, these defaults will be used
38
	protected boolean fAddMissing = true; // add all packages to export-package
39
	protected boolean fMarkInternal = true; // mark export-package as internal
40
	protected String fPackageFilter = VALUE_DEFAULT_FILTER;
41
	protected boolean fRemoveUnresolved = true; // remove unresolved export-package
42
	protected boolean fCalculateUses = false; // calculate the 'uses' directive for exported packages
43
	protected boolean fModifyDep = true; // modify import-package / require-bundle
44
	protected boolean fRemoveDependencies = true; // if true: remove, else mark optional
45
	protected boolean fUnusedDependencies; // find/remove unused dependencies - long running op
46
	protected boolean fRemoveLazy = true; // remove lazy/auto start if no activator
47
	protected boolean fPrefixIconNL; // prefix icon paths with $nl$
48
	protected boolean fUnusedKeys; // remove unused <bundle-localization>.properties keys
49
	protected boolean fAddDependencies;
50
	
51
	ArrayList fProjectList;
52
	private IProject fCurrentProject;
53
	private IBundle fCurrentBundle;
54
	private IPluginModelBase fCurrentExtensionsModel;
55
	
56
	public OrganizeManifestsProcessor(ArrayList projects) {
57
		fProjectList = projects;
58
	}
59
	
60
	public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
61
			CheckConditionsContext context) throws CoreException,
62
			OperationCanceledException {
63
		RefactoringStatus status = new RefactoringStatus();
64
		for (Iterator i = fProjectList.iterator(); i.hasNext();) {
65
			if (!(i.next() instanceof IProject))
66
				status.addFatalError(PDEUIMessages.OrganizeManifestsProcessor_invalidParam);
67
		}
68
		return status;
69
	}
70
71
	public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
72
			throws CoreException, OperationCanceledException {
73
		return null;
74
	}
75
76
	public Change createChange(IProgressMonitor pm) throws CoreException,
77
			OperationCanceledException {
78
		CompositeChange change = new CompositeChange(PDEUIMessages.OrganizeManifestsWizardPage_title);
79
		pm.beginTask(PDEUIMessages.OrganizeManifestJob_taskName, fProjectList.size());
80
		for (Iterator i = fProjectList.iterator(); i.hasNext() && !pm.isCanceled();)
81
			change.add(cleanProject((IProject)i.next(), new SubProgressMonitor(pm, 1)));
82
		return change;
83
	}
84
	
85
	private Change cleanProject(IProject project, IProgressMonitor monitor) {
86
		fCurrentProject = project;
87
		fCurrentBundle = null;
88
		fCurrentExtensionsModel = null;
89
		CompositeChange change = new CompositeChange(NLS.bind(PDEUIMessages.OrganizeManifestsProcessor_rootMessage, new String[] {fCurrentProject.getName()}));
90
		monitor.beginTask(NLS.bind(PDEUIMessages.OrganizeManifestsProcessor_rootMessage, new String[] {fCurrentProject.getName()}), getTotalTicksPerProject());
91
		
92
		final Exception[] ee = new Exception[1];
93
		ModelModification modification = new ModelModification(fCurrentProject) {
94
			protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException {
95
				if (model instanceof IBundlePluginModelBase)
96
					try {
97
						runCleanup(monitor, (IBundlePluginModelBase)model);
98
					} catch (InvocationTargetException e) {
99
						ee[0] = e;
100
					} catch (InterruptedException e) {
101
						ee[0] = e;
102
					}
103
			}
104
		};
105
		TextFileChange[] changes = PDEModelUtility.changesForModelModication(modification, monitor);
106
		for (int i = 0; i < changes.length; i++)
107
			change.add(changes[i]);
108
		changes = null;
109
		if (fUnusedKeys && fCurrentBundle != null && fCurrentExtensionsModel != null) {
110
			monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_unusedKeys, fCurrentProject.getName()));
111
			if (!monitor.isCanceled())
112
				changes = OrganizeManifest.removeUnusedKeys(fCurrentProject, fCurrentBundle, fCurrentExtensionsModel);
113
			monitor.worked(1);
114
			if (changes != null)
115
				for (int i = 0; i < changes.length; i++)
116
					change.add(changes[i]);
117
		}
118
		if (ee[0] != null)
119
			PDEPlugin.log(ee[0]);
120
		return change;
121
	}
122
	
123
	private void runCleanup(IProgressMonitor monitor, IBundlePluginModelBase modelBase) throws InvocationTargetException, InterruptedException {
124
		
125
		fCurrentBundle = modelBase.getBundleModel().getBundle();
126
		ISharedExtensionsModel sharedExtensionsModel = modelBase.getExtensionsModel();
127
		fCurrentExtensionsModel = null;
128
		if (sharedExtensionsModel instanceof IPluginModelBase)
129
			fCurrentExtensionsModel = (IPluginModelBase)sharedExtensionsModel;
130
		
131
		String projectName = fCurrentProject.getName();
132
		
133
		if (fAddMissing || fRemoveUnresolved) {
134
			monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_export, projectName));
135
			if (!monitor.isCanceled())
136
				OrganizeManifest.organizeExportPackages(fCurrentBundle, fCurrentProject, fAddMissing, fRemoveUnresolved);
137
			if (fAddMissing)
138
				monitor.worked(1);
139
			if (fRemoveUnresolved)
140
				monitor.worked(1);
141
		}
142
		
143
		if (fMarkInternal) {
144
			monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_filterInternal, projectName));
145
			if (!monitor.isCanceled())
146
				OrganizeManifest.markPackagesInternal(fCurrentBundle, fPackageFilter);
147
			monitor.worked(1);
148
		}
149
		
150
		if (fModifyDep) {
151
			String message = fRemoveDependencies ?
152
					NLS.bind(PDEUIMessages.OrganizeManifestsOperation_removeUnresolved, projectName) :
153
						NLS.bind(PDEUIMessages.OrganizeManifestsOperation_markOptionalUnresolved, projectName);
154
			monitor.subTask(message);
155
			if (!monitor.isCanceled())
156
				OrganizeManifest.organizeImportPackages(fCurrentBundle, fRemoveDependencies);
157
			monitor.worked(1);
158
			
159
			if (!monitor.isCanceled())
160
				OrganizeManifest.organizeRequireBundles(fCurrentBundle, fRemoveDependencies);
161
			monitor.worked(1);
162
		}
163
		
164
		if (fCalculateUses) {
165
			// we don't set the subTask because it is done in the CalculateUsesOperation, for each package it scans
166
			if (!monitor.isCanceled()) {
167
				CalculateUsesOperation op = new CalculateUsesOperation(fCurrentProject, modelBase);
168
				op.run(new SubProgressMonitor(monitor, 2));
169
			}
170
		}
171
		
172
		if (fAddDependencies) {
173
			monitor.subTask(NLS.bind (PDEUIMessages.OrganizeManifestsOperation_additionalDeps, projectName));
174
			if (!monitor.isCanceled()) {
175
				AddNewDependenciesOperation op = new AddNewDependenciesOperation(fCurrentProject, modelBase);
176
				op.run(new SubProgressMonitor(monitor, 4));
177
			}
178
		}
179
		
180
		if (fUnusedDependencies) {
181
			monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_unusedDeps, projectName));
182
			if (!monitor.isCanceled()) {
183
				SubProgressMonitor submon = new SubProgressMonitor(monitor, 4);
184
				GatherUnusedDependenciesOperation udo = new GatherUnusedDependenciesOperation(modelBase);
185
				udo.run(submon);
186
				GatherUnusedDependenciesOperation.removeDependencies(modelBase, udo.getList().toArray());
187
				submon.done();
188
			}
189
		}
190
	
191
		if (fRemoveLazy) {
192
			monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_lazyStart, fCurrentProject.getName()));
193
			if (!monitor.isCanceled())
194
				OrganizeManifest.removeUnneededLazyStart(fCurrentBundle);
195
			monitor.worked(1);
196
		}
197
		
198
		if (fPrefixIconNL) {
199
			monitor.subTask(NLS.bind(PDEUIMessages.OrganizeManifestsOperation_nlIconPath, projectName));
200
			if (!monitor.isCanceled())
201
				OrganizeManifest.prefixIconPaths(fCurrentExtensionsModel);
202
			monitor.worked(1);
203
		}
204
	}
205
206
	public Object[] getElements() {
207
		return fProjectList.toArray();
208
	}
209
210
	public String getIdentifier() {
211
		return getClass().getName();
212
	}
213
214
	public String getProcessorName() {
215
		return PDEUIMessages.OrganizeManifestsWizardPage_title;
216
	}
217
218
	public boolean isApplicable() throws CoreException {
219
		return true;
220
	}
221
222
	public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
223
			SharableParticipants sharedParticipants) throws CoreException {
224
		return new RefactoringParticipant[0];
225
	}
226
227
	private int getTotalTicksPerProject() {
228
		int ticks = 0;
229
		if (fAddMissing)		ticks += 1;
230
		if (fMarkInternal)		ticks += 1;
231
		if (fRemoveUnresolved)	ticks += 1;
232
		if (fCalculateUses)		ticks += 4;
233
		if (fModifyDep)			ticks += 2;
234
		if (fUnusedDependencies)ticks += 4;
235
		if (fAddDependencies)	ticks += 4;
236
		if (fRemoveLazy)		ticks += 1;
237
		if (fPrefixIconNL)		ticks += 1;
238
		if (fUnusedKeys)		ticks += 1;
239
		return ticks;
240
	}
241
	
242
	public void initSettings(IDialogSettings settings) {
243
		fAddMissing = !settings.getBoolean(PROP_ADD_MISSING);
244
		fMarkInternal = !settings.getBoolean(PROP_MARK_INTERNAL);
245
		fPackageFilter = settings.get(PROP_INTERAL_PACKAGE_FILTER);
246
		fRemoveUnresolved = !settings.getBoolean(PROP_REMOVE_UNRESOLVED_EX);
247
		fCalculateUses = settings.getBoolean(PROP_CALCULATE_USES);
248
		fModifyDep = !settings.getBoolean(PROP_MODIFY_DEP);
249
		fRemoveDependencies = !settings.getBoolean(PROP_RESOLVE_IMP_MARK_OPT);
250
		fUnusedDependencies = settings.getBoolean(PROP_UNUSED_DEPENDENCIES);
251
		fRemoveLazy = !settings.getBoolean(PROP_REMOVE_LAZY);
252
		fPrefixIconNL = settings.getBoolean(PROP_NLS_PATH);
253
		fUnusedKeys = settings.getBoolean(PROP_UNUSED_KEYS);
254
		fAddDependencies = settings.getBoolean(PROP_ADD_DEPENDENCIES);
255
	}
256
	protected void setAddMissing(boolean addMissing) {
257
		fAddMissing = addMissing;
258
	}
259
	protected void setMarkInternal(boolean markInternal) {
260
		fMarkInternal = markInternal;
261
	}
262
	protected void setPackageFilter(String packageFilter) {
263
		fPackageFilter = packageFilter;
264
	}
265
	protected void setRemoveUnresolved(boolean removeUnresolved) {
266
		fRemoveUnresolved = removeUnresolved;
267
	}
268
	protected void setCalculateUses(boolean calculateUses) {
269
		fCalculateUses = calculateUses;
270
	}
271
	protected void setModifyDep(boolean modifyDep) {
272
		fModifyDep = modifyDep;
273
	}
274
	protected void setRemoveDependencies(boolean removeDependencies) {
275
		fRemoveDependencies = removeDependencies;
276
	}
277
	protected void setUnusedDependencies(boolean unusedDependencies) {
278
		fUnusedDependencies = unusedDependencies;
279
	}
280
	protected void setRemoveLazy(boolean removeLazy) {
281
		fRemoveLazy = removeLazy;
282
	}
283
	protected void setPrefixIconNL(boolean prefixIconNL) {
284
		fPrefixIconNL = prefixIconNL;
285
	}
286
	protected void setUnusedKeys(boolean unusedKeys) {
287
		fUnusedKeys = unusedKeys;
288
	}
289
	protected void setAddDependencies(boolean addDependencies) {
290
		fAddDependencies = addDependencies;
291
	}
292
}
(-)src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsRefactor.java (+18 lines)
Added Link Here
1
package org.eclipse.pde.internal.ui.wizards.tools;
2
3
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
4
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
5
6
public class OrganizeManifestsRefactor extends ProcessorBasedRefactoring {
7
8
	OrganizeManifestsProcessor fProcessor;
9
	
10
	public OrganizeManifestsRefactor(OrganizeManifestsProcessor processor) {
11
		super(processor);
12
		fProcessor = processor;
13
	}
14
15
	public RefactoringProcessor getProcessor() {
16
		return fProcessor;
17
	}
18
}

Return to bug 173793