Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 258853 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/api/tools/ui/internal/actions/ActionMessages.java (-1 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
public class ActionMessages extends NLS {
18
public class ActionMessages extends NLS {
19
	private static final String BUNDLE_NAME = "org.eclipse.pde.api.tools.ui.internal.actions.actionmessages"; //$NON-NLS-1$
19
	private static final String BUNDLE_NAME = "org.eclipse.pde.api.tools.ui.internal.actions.actionmessages"; //$NON-NLS-1$
20
	public static String ApiToolingSetupObjectContribution_0;
20
	public static String ApiToolingSetupObjectContribution_0;
21
	public static String SelectABaseline;
22
	public static String SetAsDefault;
23
	public static String EnterFileName;
24
	public static String SelectFileName;
25
	public static String Browse;
26
	public static String ConvertToHtml;
27
	public static String CompareDialogTitle;
28
	public static String CompareDialogCollectingElementTaskName;
29
	public static String CompareDialogComputeDeltasTaskName;
30
	public static String CompareDialogCreateReportTaskName;
31
21
	static {
32
	static {
22
		// initialize resource bundle
33
		// initialize resource bundle
23
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
34
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties (-1 / +11 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2008 IBM Corporation and others.
2
# Copyright (c) 2008, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 9-11 Link Here
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
10
###############################################################################
11
ApiToolingSetupObjectContribution_0=Set up API tooling
11
ApiToolingSetupObjectContribution_0=Set up API tooling
12
SelectABaseline=Select a baseline:
13
SetAsDefault={0} (default)
14
EnterFileName=Enter a file name for the report
15
SelectFileName=Select a file name
16
Browse=Browse...
17
ConvertToHtml=Convert to html
18
CompareDialogTitle=Compare With Baseline
19
CompareDialogCollectingElementTaskName=Collecting elements to compare
20
CompareDialogComputeDeltasTaskName=Compute deltas
21
CompareDialogCreateReportTaskName=Create report file
(-)plugin.properties (-2 / +3 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2007, 2008 IBM Corporation and others.
2
# Copyright (c) 2007, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 42-45 Link Here
42
MarkerCategory.name = API Problems
42
MarkerCategory.name = API Problems
43
ApiToolsJavadocProposals.name = API Tools Javadoc Proposals
43
ApiToolsJavadocProposals.name = API Tools Javadoc Proposals
44
MarkerGroupingEntryLabel=API Usage and Compatibility
44
MarkerGroupingEntryLabel=API Usage and Compatibility
45
ApiToolsProposalCategory.name = PDE API Tools Proposals
45
ApiToolsProposalCategory.name = PDE API Tools Proposals
46
APICompare.name=Compare With...
(-)plugin.xml (+19 lines)
Lines 114-119 Link Here
114
               value="org.eclipse.pde.api.tools.apiAnalysisNature">
114
               value="org.eclipse.pde.api.tools.apiAnalysisNature">
115
         </filter>
115
         </filter>
116
      </objectContribution>
116
      </objectContribution>
117
      <objectContribution
118
            adaptable="false"
119
            id="org.eclipse.pde.api.tools.ui.compare"
120
            objectClass="org.eclipse.jdt.core.IJavaElement">
121
         <action
122
               class="org.eclipse.pde.api.tools.ui.internal.actions.CompareWithAction"
123
               enablesFor="+"
124
               id="org.eclipse.pde.api.tools.ui.action.compare"
125
               label="%APICompare.name"
126
               menubarPath="org.eclipse.pde.ui.project.tools/group1">
127
         </action>
128
         <menu
129
               id="org.eclipse.pde.ui.project.tools"
130
               label="%PdeTools.name">
131
            <separator
132
                  name="group1">
133
            </separator>
134
         </menu>
135
      </objectContribution>
117
   </extension>
136
   </extension>
118
   <extension
137
   <extension
119
         point="org.eclipse.ui.propertyPages">
138
         point="org.eclipse.ui.propertyPages">
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/CompareDialog.java (+161 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.api.tools.ui.internal.actions;
12
13
import java.io.File;
14
import java.util.Arrays;
15
16
import org.eclipse.core.runtime.Path;
17
import org.eclipse.jface.dialogs.Dialog;
18
import org.eclipse.jface.window.IShellProvider;
19
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
21
import org.eclipse.pde.api.tools.internal.provisional.IApiBaselineManager;
22
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
23
import org.eclipse.pde.api.tools.ui.internal.SWTFactory;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Button;
30
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.FileDialog;
34
import org.eclipse.swt.widgets.Shell;
35
import org.eclipse.swt.widgets.Text;
36
37
public class CompareDialog extends Dialog {
38
39
	public String baseline = null;
40
	public String reportFileName = null;
41
	private String title;
42
	public boolean convertToHtml;
43
44
	public CompareDialog(IShellProvider provider, String title) {
45
		super(provider);
46
		this.title = title;
47
	}
48
49
	protected void configureShell(Shell newShell) {
50
		super.configureShell(newShell);
51
		newShell.setText(this.title);
52
	}
53
	protected boolean isResizable() {
54
		return true;
55
	}
56
	protected Control createDialogArea(Composite parent) {
57
		Composite composite = (Composite) super.createDialogArea(parent);
58
		// add controls to composite as necessary
59
		Composite lcomp = new Composite(composite, SWT.NONE);
60
		GridLayout layout = new GridLayout(4, false);
61
		layout.marginWidth = 0;
62
		layout.marginHeight = 0;
63
		lcomp.setLayout(layout);
64
		lcomp.setFont(parent.getFont());
65
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
66
		gd.minimumWidth = 310;
67
		gd.minimumHeight = 100;
68
		lcomp.setLayoutData(gd);
69
70
		SWTFactory.createWrapLabel(lcomp, ActionMessages.SelectABaseline, 4);
71
		IApiBaselineManager apiBaselineManager = ApiPlugin.getDefault().getApiBaselineManager();
72
		IApiBaseline defaultBaseline = apiBaselineManager.getDefaultApiBaseline();
73
		String defaultBaselineName = defaultBaseline != null ? defaultBaseline.getName() : null;
74
		IApiBaseline[] baselines = apiBaselineManager.getApiBaselines();
75
		int length = baselines.length;
76
		String[] baselinesItems = new String[length];
77
		String[] baselinesNames = new String[length];
78
		int index = 0;
79
		// set the names
80
		for (int i = 0; i < length; i++) {
81
			String currentBaselineName = baselines[i].getName();
82
			baselinesNames[i] = currentBaselineName;
83
		}
84
		Arrays.sort(baselinesNames);
85
		// set the labels
86
		for (int i = 0; i < length; i++) {
87
			String currentBaselineName = baselinesNames[i];
88
			if (defaultBaselineName != null && defaultBaselineName.equals(currentBaselineName)) {
89
				baselinesItems[i] = NLS.bind(ActionMessages.SetAsDefault, currentBaselineName);
90
				this.baseline = currentBaselineName;
91
				index = i;
92
			} else {
93
				baselinesItems[i] = currentBaselineName;
94
			}
95
		}
96
		Combo baselineCombo = new Combo(lcomp, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY);
97
		gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
98
		baselineCombo.setLayoutData(gd);
99
		baselineCombo.setItems(baselinesItems);
100
		baselineCombo.setData(baselinesNames);
101
		baselineCombo.select(index);
102
103
		baselineCombo.addSelectionListener(new SelectionAdapter(){
104
			public void widgetSelected(SelectionEvent e) {
105
				Combo combo = (Combo) e.widget;
106
				String[] baselineNames = (String[]) combo.getData();
107
				String selectedBaselineName = baselineNames[combo.getSelectionIndex()];
108
				CompareDialog.this.baseline = selectedBaselineName;
109
			}
110
		});
111
		SWTFactory.createWrapLabel(lcomp, ActionMessages.EnterFileName, 4);
112
		final Text fileNameText = new Text(lcomp, SWT.BORDER);
113
		fileNameText.setFont(lcomp.getFont());
114
		gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
115
		fileNameText.setLayoutData(gd);
116
117
		Button browseButton = new Button(lcomp, SWT.PUSH);
118
		browseButton.setFont(parent.getFont());
119
		browseButton.setText(ActionMessages.Browse);
120
		gd = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
121
		browseButton.setLayoutData(gd);
122
123
		browseButton.addSelectionListener(new SelectionAdapter() {
124
			public void widgetSelected(SelectionEvent e) {
125
				FileDialog dialog = new FileDialog(getShell());
126
				dialog.setText(ActionMessages.SelectFileName);
127
				String loctext = fileNameText.getText().trim();
128
				if (loctext.length() > 0) {
129
					File file = new File(loctext).getParentFile();
130
					if (file != null && file.exists()) {
131
						dialog.setFilterPath(file.getAbsolutePath());
132
					}
133
				}
134
				String newPath = dialog.open();
135
				if (newPath != null && !new Path(loctext).equals(new Path(newPath))) {
136
					/*
137
					 * If the path is identical, but there is no component loaded, we still
138
					 * want to reload. This might be the case if the combo is initialized by
139
					 * copy/paste with a path that points to a plugin directory
140
					 */
141
					fileNameText.setText(newPath);
142
					CompareDialog.this.reportFileName = newPath;
143
				}
144
			}
145
		});
146
		Button convertToHtmlButton = new Button(lcomp, SWT.CHECK);
147
		convertToHtmlButton.setFont(parent.getFont());
148
		convertToHtmlButton.setText(ActionMessages.ConvertToHtml);
149
		gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
150
		convertToHtmlButton.setLayoutData(gd);
151
		convertToHtmlButton.setSelection(this.convertToHtml);
152
		convertToHtmlButton.addSelectionListener(new SelectionAdapter() {
153
			public void widgetSelected(SelectionEvent e) {
154
				CompareDialog.this.convertToHtml = !CompareDialog.this.convertToHtml;
155
			}
156
		});
157
		return composite;
158
	}
159
	
160
	
161
}
(-)src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java (+285 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.api.tools.ui.internal.actions;
12
13
import java.io.BufferedWriter;
14
import java.io.File;
15
import java.io.FileWriter;
16
import java.io.IOException;
17
import java.lang.reflect.InvocationTargetException;
18
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.core.runtime.SubMonitor;
23
import org.eclipse.jdt.core.IClassFile;
24
import org.eclipse.jdt.core.ICompilationUnit;
25
import org.eclipse.jdt.core.IJavaElement;
26
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.core.IPackageFragment;
28
import org.eclipse.jdt.core.IPackageFragmentRoot;
29
import org.eclipse.jdt.core.IType;
30
import org.eclipse.jdt.core.JavaModelException;
31
import org.eclipse.jface.action.IAction;
32
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
34
import org.eclipse.jface.viewers.ISelection;
35
import org.eclipse.jface.viewers.IStructuredSelection;
36
import org.eclipse.jface.window.Window;
37
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
38
import org.eclipse.pde.api.tools.internal.comparator.DeltaXmlVisitor;
39
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
40
import org.eclipse.pde.api.tools.internal.provisional.Factory;
41
import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
42
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
43
import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers;
44
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator;
45
import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiScope;
46
import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta;
47
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
48
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
49
import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope;
50
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
51
import org.eclipse.pde.api.tools.internal.util.Util;
52
import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin;
53
import org.eclipse.ui.IObjectActionDelegate;
54
import org.eclipse.ui.IWorkbenchPart;
55
import org.eclipse.ui.IWorkbenchPartSite;
56
57
public class CompareWithAction implements IObjectActionDelegate {
58
59
	private IWorkbenchPartSite workbenchPartSite;
60
	private ISelection selection = null;
61
	
62
	/**
63
	 * Constructor for Action1.
64
	 */
65
	public CompareWithAction() {
66
		super();
67
	}
68
69
	/**
70
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
71
	 */
72
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
73
		workbenchPartSite = targetPart.getSite();
74
	}
75
	/**
76
	 * @see IActionDelegate#run(IAction)
77
	 */
78
	public void run(IAction action) {
79
		if (this.selection instanceof IStructuredSelection) {
80
			final IStructuredSelection structuredSelection=(IStructuredSelection) this.selection;
81
			CompareDialog dialog = new CompareDialog(workbenchPartSite, ActionMessages.CompareDialogTitle);
82
			int returnCode = dialog.open();
83
			if (returnCode == Window.CANCEL) return;
84
			final String baselineName = dialog.baseline;
85
			final String reportFileName = dialog.reportFileName;
86
			final boolean convertToHtml = dialog.convertToHtml;
87
			if (baselineName == null || reportFileName == null) return;
88
			final IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(baselineName);
89
			if (baseline == null) return;
90
			final ProgressMonitorDialog progressDialog=new ProgressMonitorDialog(workbenchPartSite.getShell());
91
			try {
92
				progressDialog.run(true, true, new IRunnableWithProgress() {
93
					public void run(IProgressMonitor monitor)
94
							throws InvocationTargetException, InterruptedException {
95
						// Convert the given monitor into a progress instance 
96
						SubMonitor progress = SubMonitor.convert(monitor, 100);
97
						progress.subTask(ActionMessages.CompareDialogCollectingElementTaskName);
98
						SubMonitor loopProgress = progress.newChild(10).setWorkRemaining(structuredSelection.size());
99
						final IApiScope scope = walkStructureSelection(structuredSelection, loopProgress);
100
						try {
101
							progress.subTask(ActionMessages.CompareDialogComputeDeltasTaskName);
102
							SubMonitor compareProgress = progress.newChild(98).setWorkRemaining(scope.getApiElement().length);
103
							IDelta delta = ApiComparator.compare(scope, baseline, VisibilityModifiers.API, compareProgress);
104
							progress.worked(1);
105
							progress.subTask(ActionMessages.CompareDialogCreateReportTaskName);
106
							Util.checkCanceled(progress);
107
							File outputFile = new File(reportFileName);
108
							BufferedWriter writer = null;
109
							try {
110
								if (outputFile.exists()) {
111
									outputFile.delete();
112
								}
113
								writer = new BufferedWriter(new FileWriter(outputFile));
114
								DeltaXmlVisitor visitor = new DeltaXmlVisitor();
115
								delta.accept(visitor);
116
								writer.write(visitor.getXML());
117
								writer.flush();
118
							} catch (IOException e) {
119
								ApiPlugin.log(e);
120
							} catch (CoreException e) {
121
								ApiPlugin.log(e);
122
							} catch(OperationCanceledException e) {
123
								// ignore
124
							} finally {
125
								try {
126
									if (writer != null) {
127
										writer.close();
128
									}
129
								} catch(IOException e) {
130
									// ignore
131
								}
132
							}
133
							progress.worked(1);
134
						} finally {
135
							monitor.done();
136
						}
137
						if(convertToHtml) {
138
							// remaining part is to convert the xml file to html using xslt
139
						}
140
					}
141
				});
142
			} catch (InvocationTargetException e) {
143
				ApiUIPlugin.log(e);
144
			} catch (InterruptedException e) {
145
				return;
146
			}
147
			return;
148
		}
149
	}
150
151
	public static ApiScope walkStructureSelection(
152
			IStructuredSelection structuredSelection,
153
			IProgressMonitor monitor) {
154
		Object[] selected=structuredSelection.toArray();
155
		ApiScope scope = new ApiScope();
156
		IApiBaseline workspaceBaseline = ApiBaselineManager.getManager().getWorkspaceBaseline();
157
		if (workspaceBaseline == null) {
158
			return scope;
159
		}
160
		for (int i=0, max = selected.length; i < max; i++) {
161
			Object currentSelection = selected[i];
162
			if (currentSelection instanceof IJavaElement) {
163
				monitor.worked(1);
164
				IJavaElement element =(IJavaElement) currentSelection;
165
				IJavaProject javaProject = element.getJavaProject();
166
				try {
167
					switch (element.getElementType()) {
168
						case IJavaElement.COMPILATION_UNIT: {
169
							ICompilationUnit compilationUnit = (ICompilationUnit) element;
170
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
171
							if (apiComponent != null) {
172
								addElementFor(compilationUnit, apiComponent, scope);
173
							}
174
							break;
175
						}
176
						case IJavaElement.PACKAGE_FRAGMENT: {
177
							IPackageFragment fragment = (IPackageFragment) element;
178
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
179
							IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
180
							boolean isArchive = false;
181
							if (packageFragmentRoot != null) {
182
								isArchive = packageFragmentRoot.isArchive();
183
							}
184
							if (apiComponent != null) {
185
								addElementFor(fragment, isArchive, apiComponent, scope);
186
							}
187
							break;
188
						}
189
						case IJavaElement.PACKAGE_FRAGMENT_ROOT: {
190
							IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) element;
191
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
192
							if (apiComponent != null) {
193
								addElementFor(fragmentRoot, apiComponent, scope);
194
							}
195
							break;
196
						}
197
						case IJavaElement.JAVA_PROJECT:
198
							IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName());
199
							IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
200
							for (int j = 0, max2 = roots.length; j < max2; j++) {
201
								addElementFor(roots[j], apiComponent, scope);
202
							}
203
							break;
204
					}
205
				} catch (JavaModelException e) {
206
					ApiPlugin.log(e);
207
				} catch (CoreException e) {
208
					ApiPlugin.log(e);
209
				}
210
			}
211
		}
212
		return scope;
213
	}
214
215
	private static void addElementFor(
216
			IPackageFragmentRoot fragmentRoot, IApiComponent apiComponent,
217
			ApiScope scope) throws JavaModelException, CoreException {
218
		boolean isArchive = fragmentRoot.isArchive();
219
		IJavaElement[] packageFragments = fragmentRoot.getChildren();
220
		for (int j = 0, max2 = packageFragments.length; j < max2; j++) {
221
			IPackageFragment packageFragment = (IPackageFragment) packageFragments[j];
222
			addElementFor(packageFragment, isArchive, apiComponent, scope);
223
		}
224
	}
225
226
	private static void addElementFor(
227
			IPackageFragment packageFragment,
228
			boolean isArchive,
229
			IApiComponent apiComponent,
230
			ApiScope scope)
231
		throws JavaModelException, CoreException {
232
233
		// add package fragment elements only if this is an API package
234
		IApiDescription apiDescription = apiComponent.getApiDescription();
235
		IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName()));
236
		if (annotations == null || !VisibilityModifiers.isAPI(annotations.getVisibility())) {
237
			return;
238
		}
239
		if (isArchive) {
240
			IClassFile[] classFiles = packageFragment.getClassFiles();
241
			for (int i = 0, max= classFiles.length; i < max; i++) {
242
				addElementFor(classFiles[i], apiComponent, scope);
243
			}
244
		} else {
245
			ICompilationUnit[] units = packageFragment.getCompilationUnits();
246
			for (int i = 0, max= units.length; i < max; i++) {
247
				addElementFor(units[i], apiComponent, scope);
248
			}
249
		}
250
	}
251
252
	private static void addElementFor(IClassFile classFile,
253
			IApiComponent apiComponent, ApiScope scope) {
254
		try {
255
			IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName());
256
			if (typeRoot != null) {
257
				scope.add(typeRoot);
258
			}
259
		} catch (CoreException e) {
260
			ApiPlugin.log(e);
261
		}
262
	}
263
264
	private static void addElementFor(ICompilationUnit compilationUnit, IApiComponent component, ApiScope scope) throws JavaModelException {
265
		IType[] types = compilationUnit.getTypes();
266
		for (int i = 0, max = types.length; i < max; i++) {
267
			try {
268
				IApiTypeRoot typeRoot = component.findTypeRoot(types[i].getFullyQualifiedName());
269
				if (typeRoot != null) {
270
					scope.add(typeRoot);
271
				}
272
			} catch (CoreException e) {
273
				ApiPlugin.log(e);
274
			}
275
		}
276
	}
277
278
	/**
279
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
280
	 */
281
	public void selectionChanged(IAction action, ISelection selection) {
282
		this.selection = selection;
283
	}
284
285
}
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 20-26 Link Here
20
 org.eclipse.core.filesystem;bundle-version="1.2.0"
20
 org.eclipse.core.filesystem;bundle-version="1.2.0"
21
Export-Package: org.eclipse.pde.api.tools.internal;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
21
Export-Package: org.eclipse.pde.api.tools.internal;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
22
 org.eclipse.pde.api.tools.internal.builder;x-friends:="org.eclipse.pde.api.tools.ui",
22
 org.eclipse.pde.api.tools.internal.builder;x-friends:="org.eclipse.pde.api.tools.ui",
23
 org.eclipse.pde.api.tools.internal.comparator;x-internal:=true,
23
 org.eclipse.pde.api.tools.internal.comparator;x-friends:="org.eclipse.pde.api.tools.ui",
24
 org.eclipse.pde.api.tools.internal.descriptors;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
24
 org.eclipse.pde.api.tools.internal.descriptors;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
25
 org.eclipse.pde.api.tools.internal.model;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
25
 org.eclipse.pde.api.tools.internal.model;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui",
26
 org.eclipse.pde.api.tools.internal.natures;x-internal:=true,
26
 org.eclipse.pde.api.tools.internal.natures;x-internal:=true,
(-)src/org/eclipse/pde/api/tools/internal/util/Util.java (+5 lines)
Lines 2229-2232 Link Here
2229
			return 0;
2229
			return 0;
2230
		}
2230
		}
2231
	};
2231
	};
2232
2233
	public static void checkCanceled(IProgressMonitor monitor) {
2234
		if (monitor.isCanceled())
2235
			throw new OperationCanceledException();
2236
	}
2232
}
2237
}
(-)src_ant/org/eclipse/pde/api/tools/internal/tasks/CompareTask.java (-1 / +1 lines)
Lines 133-139 Link Here
133
			scope.add(currentBaseline);
133
			scope.add(currentBaseline);
134
		}
134
		}
135
		try {
135
		try {
136
			delta = ApiComparator.compare(scope, referenceBaseline, this.visibilityModifiers);
136
			delta = ApiComparator.compare(scope, referenceBaseline, this.visibilityModifiers, null);
137
		} finally {
137
		} finally {
138
			referenceBaseline.dispose();
138
			referenceBaseline.dispose();
139
			currentBaseline.dispose();
139
			currentBaseline.dispose();
(-)src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java (-3 / +15 lines)
Lines 15-21 Link Here
15
import java.util.Set;
15
import java.util.Set;
16
16
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.jdt.core.Flags;
21
import org.eclipse.jdt.core.Flags;
20
import org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator;
22
import org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator;
21
import org.eclipse.pde.api.tools.internal.comparator.Delta;
23
import org.eclipse.pde.api.tools.internal.comparator.Delta;
Lines 655-674 Link Here
655
	 * @param scope the given scope for the comparison
657
	 * @param scope the given scope for the comparison
656
	 * @param baseline the given API baseline to compare with
658
	 * @param baseline the given API baseline to compare with
657
	 * @param visibilityModifiers the given visibility that triggers what visibility should be used for the comparison
659
	 * @param visibilityModifiers the given visibility that triggers what visibility should be used for the comparison
658
	 *
660
	 * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility
661
	 * to call done() on the given monitor. Accepts null, indicating that no progress should be
662
	 * reported and that the operation cannot be canceled.
663
	 * 
659
	 * @return a delta, an empty delta if no difference is found or null if the delta detection failed
664
	 * @return a delta, an empty delta if no difference is found or null if the delta detection failed
660
	 * @throws IllegalArgumentException if one of the two baselines is null
665
	 * @throws IllegalArgumentException if one of the two baselines is null
661
	 */
666
	 */
662
	public static IDelta compare(
667
	public static IDelta compare(
663
			final IApiScope scope,
668
			final IApiScope scope,
664
			final IApiBaseline baseline,
669
			final IApiBaseline baseline,
665
			final int visibilityModifiers) {
670
			final int visibilityModifiers,
671
			final IProgressMonitor monitor) {
666
		try {
672
		try {
667
			if (scope == null || baseline == null) {
673
			if (scope == null || baseline == null) {
668
				throw new IllegalArgumentException("None of the scope or the baseline must be null"); //$NON-NLS-1$
674
				throw new IllegalArgumentException("None of the scope or the baseline must be null"); //$NON-NLS-1$
669
			}
675
			}
676
			IProgressMonitor currentMonitor = null;
677
			if (monitor == null) {
678
				currentMonitor = new NullProgressMonitor();
679
			} else {
680
				currentMonitor = monitor;
681
			}
670
			final Set deltas = new HashSet();
682
			final Set deltas = new HashSet();
671
			final CompareApiScopeVisitor visitor = new CompareApiScopeVisitor(deltas, baseline, visibilityModifiers);
683
			final CompareApiScopeVisitor visitor = new CompareApiScopeVisitor(deltas, baseline, visibilityModifiers, currentMonitor);
672
			scope.accept(visitor);
684
			scope.accept(visitor);
673
			if (visitor.containsError()) {
685
			if (visitor.containsError()) {
674
				return null;
686
				return null;
(-)src/org/eclipse/pde/api/tools/internal/provisional/comparator/CompareApiScopeVisitor.java (-71 / +99 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-18 Link Here
13
import java.util.Set;
13
import java.util.Set;
14
14
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
18
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
17
import org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor;
19
import org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor;
18
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
20
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
Lines 20-25 Link Here
20
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
22
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
21
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
23
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
22
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
24
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
25
import org.eclipse.pde.api.tools.internal.util.Util;
23
26
24
/**
27
/**
25
 * ApiScope visitor implementation to run the comparison on all elements of the scope.
28
 * ApiScope visitor implementation to run the comparison on all elements of the scope.
Lines 30-129 Link Here
30
	IApiBaseline referenceBaseline;
33
	IApiBaseline referenceBaseline;
31
	int visibilityModifiers;
34
	int visibilityModifiers;
32
	boolean containsErrors = false;
35
	boolean containsErrors = false;
36
	IProgressMonitor monitor;
33
37
34
	public CompareApiScopeVisitor(final Set deltas, final IApiBaseline baseline, final int visibilityModifiers) {
38
	public CompareApiScopeVisitor(final Set deltas, final IApiBaseline baseline, final int visibilityModifiers,
39
			IProgressMonitor monitor) {
35
		this.deltas = deltas;
40
		this.deltas = deltas;
36
		this.referenceBaseline = baseline;
41
		this.referenceBaseline = baseline;
37
		this.visibilityModifiers = visibilityModifiers;
42
		this.visibilityModifiers = visibilityModifiers;
43
		this.monitor = monitor == null ? new NullProgressMonitor() : monitor;
38
	}
44
	}
39
	
45
40
	public boolean visit(IApiBaseline baseline) throws CoreException {
46
	public boolean visit(IApiBaseline baseline) throws CoreException {
41
		IDelta delta = ApiComparator.compare(this.referenceBaseline, baseline, this.visibilityModifiers);
47
		try {
42
		if (delta != null) {
48
			Util.checkCanceled(this.monitor);
43
			delta.accept(new DeltaVisitor() {
49
			IDelta delta = ApiComparator.compare(this.referenceBaseline, baseline, this.visibilityModifiers);
44
				public void endVisit(IDelta localDelta) {
50
			if (delta != null) {
45
					if (localDelta.getChildren().length == 0) {
51
				delta.accept(new DeltaVisitor() {
46
						CompareApiScopeVisitor.this.deltas.add(localDelta);
52
					public void endVisit(IDelta localDelta) {
53
						if (localDelta.getChildren().length == 0) {
54
							CompareApiScopeVisitor.this.deltas.add(localDelta);
55
						}
47
					}
56
					}
48
				}
57
				});
49
			});
58
			} else {
50
		} else {
59
				this.containsErrors = true;
51
			this.containsErrors = true;
60
			}
61
		} finally {
62
			monitor.worked(1);
52
		}
63
		}
53
		return false;
64
		return false;
54
	}
65
	}
55
66
56
	public boolean visit(IApiTypeContainer container) throws CoreException {
67
	public boolean visit(IApiTypeContainer container) throws CoreException {
57
		container.accept(new ApiTypeContainerVisitor() {
68
		try {
58
			public void visit(String packageName, IApiTypeRoot typeroot) {
69
			Util.checkCanceled(this.monitor);
59
				try {
70
			container.accept(new ApiTypeContainerVisitor() {
60
					CompareApiScopeVisitor.this.visit(typeroot);
71
				public void visit(String packageName, IApiTypeRoot typeroot) {
61
				} catch (CoreException e) {
72
					try {
62
					ApiPlugin.log(e);
73
						CompareApiScopeVisitor.this.visit(typeroot);
74
					} catch (CoreException e) {
75
						ApiPlugin.log(e);
76
					}
63
				}
77
				}
64
			}
78
			});
65
		});
79
		} catch (Exception e) {
80
			monitor.worked(1);
81
		}
66
		return false;
82
		return false;
67
	}
83
	}
68
84
69
	public boolean visit(IApiComponent component) throws CoreException {
85
	public boolean visit(IApiComponent component) throws CoreException {
70
		if (component.getErrors() != null) {
86
		try {
71
			this.containsErrors = true;
87
			if (component.getErrors() != null) {
72
			return false;
88
				this.containsErrors = true;
73
		}
89
				return false;
74
		IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(component.getId());
90
			}
75
		if (referenceComponent.getErrors() != null) {
91
			Util.checkCanceled(this.monitor);
76
			this.containsErrors = true;
92
			IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(component.getId());
77
			return false;
93
			if (referenceComponent.getErrors() != null) {
78
		}
94
				this.containsErrors = true;
79
		IDelta delta = ApiComparator.compare(referenceComponent, component, this.visibilityModifiers);
95
				return false;
80
		if (delta != null) {
96
			}
81
			delta.accept(new DeltaVisitor() {
97
			Util.checkCanceled(this.monitor);
82
				public void endVisit(IDelta localDelta) {
98
			IDelta delta = ApiComparator.compare(referenceComponent, component, this.visibilityModifiers);
83
					if (localDelta.getChildren().length == 0) {
99
			if (delta != null) {
84
						CompareApiScopeVisitor.this.deltas.add(localDelta);
100
				delta.accept(new DeltaVisitor() {
101
					public void endVisit(IDelta localDelta) {
102
						if (localDelta.getChildren().length == 0) {
103
							CompareApiScopeVisitor.this.deltas.add(localDelta);
104
						}
85
					}
105
					}
86
				}
106
				});
87
			});
107
			} else {
88
		} else {
108
				this.containsErrors = true;
89
			this.containsErrors = true;
109
			}
110
		} finally {
111
			monitor.worked(1);
90
		}
112
		}
91
		return false;
113
		return false;
92
	}
114
	}
93
	
115
	
94
	public void visit(IApiTypeRoot root) throws CoreException {
116
	public void visit(IApiTypeRoot root) throws CoreException {
95
		IApiComponent apiComponent = root.getApiComponent();
117
		try {
96
		if (apiComponent == null) {
118
			IApiComponent apiComponent = root.getApiComponent();
97
			return;
119
			if (apiComponent == null) {
98
		}
120
				return;
99
		if (apiComponent.getErrors() != null) {
121
			}
100
			this.containsErrors = true;
122
			if (apiComponent.getErrors() != null) {
101
			return;
123
				this.containsErrors = true;
102
		}
124
				return;
103
		IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(apiComponent.getId());
125
			}
104
		if (referenceComponent == null) return;
126
			Util.checkCanceled(this.monitor);
105
		if (referenceComponent.getErrors() != null) {
127
			IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(apiComponent.getId());
106
			this.containsErrors = true;
128
			if (referenceComponent == null) return;
107
			return;
129
			if (referenceComponent.getErrors() != null) {
108
		}
130
				this.containsErrors = true;
109
		IApiBaseline baseline = referenceComponent.getBaseline();
131
				return;
110
		IDelta delta = ApiComparator.compare(
132
			}
111
				root,
133
			IApiBaseline baseline = referenceComponent.getBaseline();
112
				apiComponent,
134
			Util.checkCanceled(this.monitor);
113
				referenceComponent,
135
			IDelta delta = ApiComparator.compare(
114
				this.referenceBaseline,
136
					root,
115
				baseline,
137
					apiComponent,
116
				this.visibilityModifiers);
138
					referenceComponent,
117
		if (delta != null) {
139
					this.referenceBaseline,
118
			delta.accept(new DeltaVisitor() {
140
					baseline,
119
				public void endVisit(IDelta localDelta) {
141
					this.visibilityModifiers);
120
					if (localDelta.getChildren().length == 0) {
142
			if (delta != null) {
121
						CompareApiScopeVisitor.this.deltas.add(localDelta);
143
				delta.accept(new DeltaVisitor() {
144
					public void endVisit(IDelta localDelta) {
145
						if (localDelta.getChildren().length == 0) {
146
							CompareApiScopeVisitor.this.deltas.add(localDelta);
147
						}
122
					}
148
					}
123
				}
149
				});
124
			});
150
			} else {
125
		} else {
151
				this.containsErrors = true;
126
			this.containsErrors = true;
152
			}
153
		} finally {
154
			monitor.worked(1);
127
		}
155
		}
128
	}
156
	}
129
	
157
	

Return to bug 258853