Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 127736 Details for
Bug 258853
Provide a compare ant task
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Proposed fix
patch_258853.txt (text/plain), 37.82 KB, created by
Olivier Thomann
on 2009-03-05 20:59:44 EST
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2009-03-05 20:59:44 EST
Size:
37.82 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.api.tools.ui >Index: src/org/eclipse/pde/api/tools/ui/internal/actions/ActionMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/actions/ActionMessages.java,v >retrieving revision 1.1 >diff -u -r1.1 ActionMessages.java >--- src/org/eclipse/pde/api/tools/ui/internal/actions/ActionMessages.java 13 Feb 2008 19:59:11 -0000 1.1 >+++ src/org/eclipse/pde/api/tools/ui/internal/actions/ActionMessages.java 6 Mar 2009 01:59:08 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >+ * Copyright (c) 2008, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -18,6 +18,17 @@ > public class ActionMessages extends NLS { > private static final String BUNDLE_NAME = "org.eclipse.pde.api.tools.ui.internal.actions.actionmessages"; //$NON-NLS-1$ > public static String ApiToolingSetupObjectContribution_0; >+ public static String SelectABaseline; >+ public static String SetAsDefault; >+ public static String EnterFileName; >+ public static String SelectFileName; >+ public static String Browse; >+ public static String ConvertToHtml; >+ public static String CompareDialogTitle; >+ public static String CompareDialogCollectingElementTaskName; >+ public static String CompareDialogComputeDeltasTaskName; >+ public static String CompareDialogCreateReportTaskName; >+ > static { > // initialize resource bundle > NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class); >Index: src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties,v >retrieving revision 1.2 >diff -u -r1.2 actionmessages.properties >--- src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties 21 Feb 2008 20:30:43 -0000 1.2 >+++ src/org/eclipse/pde/api/tools/ui/internal/actions/actionmessages.properties 6 Mar 2009 01:59:08 -0000 >@@ -1,5 +1,5 @@ > ############################################################################### >-# Copyright (c) 2008 IBM Corporation and others. >+# Copyright (c) 2008, 2009 IBM Corporation and others. > # All rights reserved. This program and the accompanying materials > # are made available under the terms of the Eclipse Public License v1.0 > # which accompanies this distribution, and is available at >@@ -9,3 +9,13 @@ > # IBM Corporation - initial API and implementation > ############################################################################### > ApiToolingSetupObjectContribution_0=Set up API tooling >+SelectABaseline=Select a baseline: >+SetAsDefault={0} (default) >+EnterFileName=Enter a file name for the report >+SelectFileName=Select a file name >+Browse=Browse... >+ConvertToHtml=Convert to html >+CompareDialogTitle=Compare With Baseline >+CompareDialogCollectingElementTaskName=Collecting elements to compare >+CompareDialogComputeDeltasTaskName=Compute deltas >+CompareDialogCreateReportTaskName=Create report file >\ No newline at end of file >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/plugin.properties,v >retrieving revision 1.16 >diff -u -r1.16 plugin.properties >--- plugin.properties 14 Oct 2008 15:34:02 -0000 1.16 >+++ plugin.properties 6 Mar 2009 01:59:08 -0000 >@@ -1,5 +1,5 @@ > ############################################################################### >-# Copyright (c) 2007, 2008 IBM Corporation and others. >+# Copyright (c) 2007, 2009 IBM Corporation and others. > # All rights reserved. This program and the accompanying materials > # are made available under the terms of the Eclipse Public License v1.0 > # which accompanies this distribution, and is available at >@@ -42,4 +42,5 @@ > MarkerCategory.name = API Problems > ApiToolsJavadocProposals.name = API Tools Javadoc Proposals > MarkerGroupingEntryLabel=API Usage and Compatibility >-ApiToolsProposalCategory.name = PDE API Tools Proposals >\ No newline at end of file >+ApiToolsProposalCategory.name = PDE API Tools Proposals >+APICompare.name=Compare With... >\ No newline at end of file >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools.ui/plugin.xml,v >retrieving revision 1.20 >diff -u -r1.20 plugin.xml >--- plugin.xml 4 Dec 2008 17:18:18 -0000 1.20 >+++ plugin.xml 6 Mar 2009 01:59:08 -0000 >@@ -114,6 +114,25 @@ > value="org.eclipse.pde.api.tools.apiAnalysisNature"> > </filter> > </objectContribution> >+ <objectContribution >+ adaptable="false" >+ id="org.eclipse.pde.api.tools.ui.compare" >+ objectClass="org.eclipse.jdt.core.IJavaElement"> >+ <action >+ class="org.eclipse.pde.api.tools.ui.internal.actions.CompareWithAction" >+ enablesFor="+" >+ id="org.eclipse.pde.api.tools.ui.action.compare" >+ label="%APICompare.name" >+ menubarPath="org.eclipse.pde.ui.project.tools/group1"> >+ </action> >+ <menu >+ id="org.eclipse.pde.ui.project.tools" >+ label="%PdeTools.name"> >+ <separator >+ name="group1"> >+ </separator> >+ </menu> >+ </objectContribution> > </extension> > <extension > point="org.eclipse.ui.propertyPages"> >Index: src/org/eclipse/pde/api/tools/ui/internal/actions/CompareDialog.java >=================================================================== >RCS file: src/org/eclipse/pde/api/tools/ui/internal/actions/CompareDialog.java >diff -N src/org/eclipse/pde/api/tools/ui/internal/actions/CompareDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/api/tools/ui/internal/actions/CompareDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,161 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.api.tools.ui.internal.actions; >+ >+import java.io.File; >+import java.util.Arrays; >+ >+import org.eclipse.core.runtime.Path; >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.jface.window.IShellProvider; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; >+import org.eclipse.pde.api.tools.internal.provisional.IApiBaselineManager; >+import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; >+import org.eclipse.pde.api.tools.ui.internal.SWTFactory; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.FileDialog; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+ >+public class CompareDialog extends Dialog { >+ >+ public String baseline = null; >+ public String reportFileName = null; >+ private String title; >+ public boolean convertToHtml; >+ >+ public CompareDialog(IShellProvider provider, String title) { >+ super(provider); >+ this.title = title; >+ } >+ >+ protected void configureShell(Shell newShell) { >+ super.configureShell(newShell); >+ newShell.setText(this.title); >+ } >+ protected boolean isResizable() { >+ return true; >+ } >+ protected Control createDialogArea(Composite parent) { >+ Composite composite = (Composite) super.createDialogArea(parent); >+ // add controls to composite as necessary >+ Composite lcomp = new Composite(composite, SWT.NONE); >+ GridLayout layout = new GridLayout(4, false); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ lcomp.setLayout(layout); >+ lcomp.setFont(parent.getFont()); >+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); >+ gd.minimumWidth = 310; >+ gd.minimumHeight = 100; >+ lcomp.setLayoutData(gd); >+ >+ SWTFactory.createWrapLabel(lcomp, ActionMessages.SelectABaseline, 4); >+ IApiBaselineManager apiBaselineManager = ApiPlugin.getDefault().getApiBaselineManager(); >+ IApiBaseline defaultBaseline = apiBaselineManager.getDefaultApiBaseline(); >+ String defaultBaselineName = defaultBaseline != null ? defaultBaseline.getName() : null; >+ IApiBaseline[] baselines = apiBaselineManager.getApiBaselines(); >+ int length = baselines.length; >+ String[] baselinesItems = new String[length]; >+ String[] baselinesNames = new String[length]; >+ int index = 0; >+ // set the names >+ for (int i = 0; i < length; i++) { >+ String currentBaselineName = baselines[i].getName(); >+ baselinesNames[i] = currentBaselineName; >+ } >+ Arrays.sort(baselinesNames); >+ // set the labels >+ for (int i = 0; i < length; i++) { >+ String currentBaselineName = baselinesNames[i]; >+ if (defaultBaselineName != null && defaultBaselineName.equals(currentBaselineName)) { >+ baselinesItems[i] = NLS.bind(ActionMessages.SetAsDefault, currentBaselineName); >+ this.baseline = currentBaselineName; >+ index = i; >+ } else { >+ baselinesItems[i] = currentBaselineName; >+ } >+ } >+ Combo baselineCombo = new Combo(lcomp, SWT.BORDER | SWT.FLAT | SWT.READ_ONLY); >+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1); >+ baselineCombo.setLayoutData(gd); >+ baselineCombo.setItems(baselinesItems); >+ baselineCombo.setData(baselinesNames); >+ baselineCombo.select(index); >+ >+ baselineCombo.addSelectionListener(new SelectionAdapter(){ >+ public void widgetSelected(SelectionEvent e) { >+ Combo combo = (Combo) e.widget; >+ String[] baselineNames = (String[]) combo.getData(); >+ String selectedBaselineName = baselineNames[combo.getSelectionIndex()]; >+ CompareDialog.this.baseline = selectedBaselineName; >+ } >+ }); >+ SWTFactory.createWrapLabel(lcomp, ActionMessages.EnterFileName, 4); >+ final Text fileNameText = new Text(lcomp, SWT.BORDER); >+ fileNameText.setFont(lcomp.getFont()); >+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1); >+ fileNameText.setLayoutData(gd); >+ >+ Button browseButton = new Button(lcomp, SWT.PUSH); >+ browseButton.setFont(parent.getFont()); >+ browseButton.setText(ActionMessages.Browse); >+ gd = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1); >+ browseButton.setLayoutData(gd); >+ >+ browseButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ FileDialog dialog = new FileDialog(getShell()); >+ dialog.setText(ActionMessages.SelectFileName); >+ String loctext = fileNameText.getText().trim(); >+ if (loctext.length() > 0) { >+ File file = new File(loctext).getParentFile(); >+ if (file != null && file.exists()) { >+ dialog.setFilterPath(file.getAbsolutePath()); >+ } >+ } >+ String newPath = dialog.open(); >+ if (newPath != null && !new Path(loctext).equals(new Path(newPath))) { >+ /* >+ * If the path is identical, but there is no component loaded, we still >+ * want to reload. This might be the case if the combo is initialized by >+ * copy/paste with a path that points to a plugin directory >+ */ >+ fileNameText.setText(newPath); >+ CompareDialog.this.reportFileName = newPath; >+ } >+ } >+ }); >+ Button convertToHtmlButton = new Button(lcomp, SWT.CHECK); >+ convertToHtmlButton.setFont(parent.getFont()); >+ convertToHtmlButton.setText(ActionMessages.ConvertToHtml); >+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1); >+ convertToHtmlButton.setLayoutData(gd); >+ convertToHtmlButton.setSelection(this.convertToHtml); >+ convertToHtmlButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ CompareDialog.this.convertToHtml = !CompareDialog.this.convertToHtml; >+ } >+ }); >+ return composite; >+ } >+ >+ >+} >\ No newline at end of file >Index: src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java >=================================================================== >RCS file: src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java >diff -N src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/api/tools/ui/internal/actions/CompareWithAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,285 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.api.tools.ui.internal.actions; >+ >+import java.io.BufferedWriter; >+import java.io.File; >+import java.io.FileWriter; >+import java.io.IOException; >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.core.runtime.SubMonitor; >+import org.eclipse.jdt.core.IClassFile; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IPackageFragment; >+import org.eclipse.jdt.core.IPackageFragmentRoot; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.dialogs.ProgressMonitorDialog; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.window.Window; >+import org.eclipse.pde.api.tools.internal.ApiBaselineManager; >+import org.eclipse.pde.api.tools.internal.comparator.DeltaXmlVisitor; >+import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; >+import org.eclipse.pde.api.tools.internal.provisional.Factory; >+import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations; >+import org.eclipse.pde.api.tools.internal.provisional.IApiDescription; >+import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; >+import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator; >+import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiScope; >+import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta; >+import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; >+import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; >+import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope; >+import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot; >+import org.eclipse.pde.api.tools.internal.util.Util; >+import org.eclipse.pde.api.tools.ui.internal.ApiUIPlugin; >+import org.eclipse.ui.IObjectActionDelegate; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.IWorkbenchPartSite; >+ >+public class CompareWithAction implements IObjectActionDelegate { >+ >+ private IWorkbenchPartSite workbenchPartSite; >+ private ISelection selection = null; >+ >+ /** >+ * Constructor for Action1. >+ */ >+ public CompareWithAction() { >+ super(); >+ } >+ >+ /** >+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) >+ */ >+ public void setActivePart(IAction action, IWorkbenchPart targetPart) { >+ workbenchPartSite = targetPart.getSite(); >+ } >+ /** >+ * @see IActionDelegate#run(IAction) >+ */ >+ public void run(IAction action) { >+ if (this.selection instanceof IStructuredSelection) { >+ final IStructuredSelection structuredSelection=(IStructuredSelection) this.selection; >+ CompareDialog dialog = new CompareDialog(workbenchPartSite, ActionMessages.CompareDialogTitle); >+ int returnCode = dialog.open(); >+ if (returnCode == Window.CANCEL) return; >+ final String baselineName = dialog.baseline; >+ final String reportFileName = dialog.reportFileName; >+ final boolean convertToHtml = dialog.convertToHtml; >+ if (baselineName == null || reportFileName == null) return; >+ final IApiBaseline baseline = ApiBaselineManager.getManager().getApiBaseline(baselineName); >+ if (baseline == null) return; >+ final ProgressMonitorDialog progressDialog=new ProgressMonitorDialog(workbenchPartSite.getShell()); >+ try { >+ progressDialog.run(true, true, new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ // Convert the given monitor into a progress instance >+ SubMonitor progress = SubMonitor.convert(monitor, 100); >+ progress.subTask(ActionMessages.CompareDialogCollectingElementTaskName); >+ SubMonitor loopProgress = progress.newChild(10).setWorkRemaining(structuredSelection.size()); >+ final IApiScope scope = walkStructureSelection(structuredSelection, loopProgress); >+ try { >+ progress.subTask(ActionMessages.CompareDialogComputeDeltasTaskName); >+ SubMonitor compareProgress = progress.newChild(98).setWorkRemaining(scope.getApiElement().length); >+ IDelta delta = ApiComparator.compare(scope, baseline, VisibilityModifiers.API, compareProgress); >+ progress.worked(1); >+ progress.subTask(ActionMessages.CompareDialogCreateReportTaskName); >+ Util.checkCanceled(progress); >+ File outputFile = new File(reportFileName); >+ BufferedWriter writer = null; >+ try { >+ if (outputFile.exists()) { >+ outputFile.delete(); >+ } >+ writer = new BufferedWriter(new FileWriter(outputFile)); >+ DeltaXmlVisitor visitor = new DeltaXmlVisitor(); >+ delta.accept(visitor); >+ writer.write(visitor.getXML()); >+ writer.flush(); >+ } catch (IOException e) { >+ ApiPlugin.log(e); >+ } catch (CoreException e) { >+ ApiPlugin.log(e); >+ } catch(OperationCanceledException e) { >+ // ignore >+ } finally { >+ try { >+ if (writer != null) { >+ writer.close(); >+ } >+ } catch(IOException e) { >+ // ignore >+ } >+ } >+ progress.worked(1); >+ } finally { >+ monitor.done(); >+ } >+ if(convertToHtml) { >+ // remaining part is to convert the xml file to html using xslt >+ } >+ } >+ }); >+ } catch (InvocationTargetException e) { >+ ApiUIPlugin.log(e); >+ } catch (InterruptedException e) { >+ return; >+ } >+ return; >+ } >+ } >+ >+ public static ApiScope walkStructureSelection( >+ IStructuredSelection structuredSelection, >+ IProgressMonitor monitor) { >+ Object[] selected=structuredSelection.toArray(); >+ ApiScope scope = new ApiScope(); >+ IApiBaseline workspaceBaseline = ApiBaselineManager.getManager().getWorkspaceBaseline(); >+ if (workspaceBaseline == null) { >+ return scope; >+ } >+ for (int i=0, max = selected.length; i < max; i++) { >+ Object currentSelection = selected[i]; >+ if (currentSelection instanceof IJavaElement) { >+ monitor.worked(1); >+ IJavaElement element =(IJavaElement) currentSelection; >+ IJavaProject javaProject = element.getJavaProject(); >+ try { >+ switch (element.getElementType()) { >+ case IJavaElement.COMPILATION_UNIT: { >+ ICompilationUnit compilationUnit = (ICompilationUnit) element; >+ IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName()); >+ if (apiComponent != null) { >+ addElementFor(compilationUnit, apiComponent, scope); >+ } >+ break; >+ } >+ case IJavaElement.PACKAGE_FRAGMENT: { >+ IPackageFragment fragment = (IPackageFragment) element; >+ IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName()); >+ IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) fragment.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); >+ boolean isArchive = false; >+ if (packageFragmentRoot != null) { >+ isArchive = packageFragmentRoot.isArchive(); >+ } >+ if (apiComponent != null) { >+ addElementFor(fragment, isArchive, apiComponent, scope); >+ } >+ break; >+ } >+ case IJavaElement.PACKAGE_FRAGMENT_ROOT: { >+ IPackageFragmentRoot fragmentRoot = (IPackageFragmentRoot) element; >+ IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName()); >+ if (apiComponent != null) { >+ addElementFor(fragmentRoot, apiComponent, scope); >+ } >+ break; >+ } >+ case IJavaElement.JAVA_PROJECT: >+ IApiComponent apiComponent = workspaceBaseline.getApiComponent(javaProject.getElementName()); >+ IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); >+ for (int j = 0, max2 = roots.length; j < max2; j++) { >+ addElementFor(roots[j], apiComponent, scope); >+ } >+ break; >+ } >+ } catch (JavaModelException e) { >+ ApiPlugin.log(e); >+ } catch (CoreException e) { >+ ApiPlugin.log(e); >+ } >+ } >+ } >+ return scope; >+ } >+ >+ private static void addElementFor( >+ IPackageFragmentRoot fragmentRoot, IApiComponent apiComponent, >+ ApiScope scope) throws JavaModelException, CoreException { >+ boolean isArchive = fragmentRoot.isArchive(); >+ IJavaElement[] packageFragments = fragmentRoot.getChildren(); >+ for (int j = 0, max2 = packageFragments.length; j < max2; j++) { >+ IPackageFragment packageFragment = (IPackageFragment) packageFragments[j]; >+ addElementFor(packageFragment, isArchive, apiComponent, scope); >+ } >+ } >+ >+ private static void addElementFor( >+ IPackageFragment packageFragment, >+ boolean isArchive, >+ IApiComponent apiComponent, >+ ApiScope scope) >+ throws JavaModelException, CoreException { >+ >+ // add package fragment elements only if this is an API package >+ IApiDescription apiDescription = apiComponent.getApiDescription(); >+ IApiAnnotations annotations = apiDescription.resolveAnnotations(Factory.packageDescriptor(packageFragment.getElementName())); >+ if (annotations == null || !VisibilityModifiers.isAPI(annotations.getVisibility())) { >+ return; >+ } >+ if (isArchive) { >+ IClassFile[] classFiles = packageFragment.getClassFiles(); >+ for (int i = 0, max= classFiles.length; i < max; i++) { >+ addElementFor(classFiles[i], apiComponent, scope); >+ } >+ } else { >+ ICompilationUnit[] units = packageFragment.getCompilationUnits(); >+ for (int i = 0, max= units.length; i < max; i++) { >+ addElementFor(units[i], apiComponent, scope); >+ } >+ } >+ } >+ >+ private static void addElementFor(IClassFile classFile, >+ IApiComponent apiComponent, ApiScope scope) { >+ try { >+ IApiTypeRoot typeRoot = apiComponent.findTypeRoot(classFile.getType().getFullyQualifiedName()); >+ if (typeRoot != null) { >+ scope.add(typeRoot); >+ } >+ } catch (CoreException e) { >+ ApiPlugin.log(e); >+ } >+ } >+ >+ private static void addElementFor(ICompilationUnit compilationUnit, IApiComponent component, ApiScope scope) throws JavaModelException { >+ IType[] types = compilationUnit.getTypes(); >+ for (int i = 0, max = types.length; i < max; i++) { >+ try { >+ IApiTypeRoot typeRoot = component.findTypeRoot(types[i].getFullyQualifiedName()); >+ if (typeRoot != null) { >+ scope.add(typeRoot); >+ } >+ } catch (CoreException e) { >+ ApiPlugin.log(e); >+ } >+ } >+ } >+ >+ /** >+ * @see IActionDelegate#selectionChanged(IAction, ISelection) >+ */ >+ public void selectionChanged(IAction action, ISelection selection) { >+ this.selection = selection; >+ } >+ >+} >#P org.eclipse.pde.api.tools >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF,v >retrieving revision 1.25 >diff -u -r1.25 MANIFEST.MF >--- META-INF/MANIFEST.MF 4 Feb 2009 22:15:09 -0000 1.25 >+++ META-INF/MANIFEST.MF 6 Mar 2009 01:59:08 -0000 >@@ -20,7 +20,7 @@ > org.eclipse.core.filesystem;bundle-version="1.2.0" > Export-Package: org.eclipse.pde.api.tools.internal;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui", > org.eclipse.pde.api.tools.internal.builder;x-friends:="org.eclipse.pde.api.tools.ui", >- org.eclipse.pde.api.tools.internal.comparator;x-internal:=true, >+ org.eclipse.pde.api.tools.internal.comparator;x-friends:="org.eclipse.pde.api.tools.ui", > org.eclipse.pde.api.tools.internal.descriptors;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui", > org.eclipse.pde.api.tools.internal.model;x-friends:="org.eclipse.pde.api.tools.tests,org.eclipse.pde.api.tools.ui", > org.eclipse.pde.api.tools.internal.natures;x-internal:=true, >Index: src/org/eclipse/pde/api/tools/internal/util/Util.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java,v >retrieving revision 1.119 >diff -u -r1.119 Util.java >--- src/org/eclipse/pde/api/tools/internal/util/Util.java 4 Mar 2009 01:49:34 -0000 1.119 >+++ src/org/eclipse/pde/api/tools/internal/util/Util.java 6 Mar 2009 01:59:09 -0000 >@@ -2229,4 +2229,9 @@ > return 0; > } > }; >+ >+ public static void checkCanceled(IProgressMonitor monitor) { >+ if (monitor.isCanceled()) >+ throw new OperationCanceledException(); >+ } > } >Index: src_ant/org/eclipse/pde/api/tools/internal/tasks/CompareTask.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src_ant/org/eclipse/pde/api/tools/internal/tasks/CompareTask.java,v >retrieving revision 1.7 >diff -u -r1.7 CompareTask.java >--- src_ant/org/eclipse/pde/api/tools/internal/tasks/CompareTask.java 4 Mar 2009 02:08:35 -0000 1.7 >+++ src_ant/org/eclipse/pde/api/tools/internal/tasks/CompareTask.java 6 Mar 2009 01:59:10 -0000 >@@ -133,7 +133,7 @@ > scope.add(currentBaseline); > } > try { >- delta = ApiComparator.compare(scope, referenceBaseline, this.visibilityModifiers); >+ delta = ApiComparator.compare(scope, referenceBaseline, this.visibilityModifiers, null); > } finally { > referenceBaseline.dispose(); > currentBaseline.dispose(); >Index: src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java,v >retrieving revision 1.44 >diff -u -r1.44 ApiComparator.java >--- src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java 3 Mar 2009 15:35:08 -0000 1.44 >+++ src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java 6 Mar 2009 01:59:09 -0000 >@@ -15,7 +15,9 @@ > import java.util.Set; > > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.jdt.core.Flags; > import org.eclipse.pde.api.tools.internal.comparator.ClassFileComparator; > import org.eclipse.pde.api.tools.internal.comparator.Delta; >@@ -655,20 +657,30 @@ > * @param scope the given scope for the comparison > * @param baseline the given API baseline to compare with > * @param visibilityModifiers the given visibility that triggers what visibility should be used for the comparison >- * >+ * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility >+ * to call done() on the given monitor. Accepts null, indicating that no progress should be >+ * reported and that the operation cannot be canceled. >+ * > * @return a delta, an empty delta if no difference is found or null if the delta detection failed > * @throws IllegalArgumentException if one of the two baselines is null > */ > public static IDelta compare( > final IApiScope scope, > final IApiBaseline baseline, >- final int visibilityModifiers) { >+ final int visibilityModifiers, >+ final IProgressMonitor monitor) { > try { > if (scope == null || baseline == null) { > throw new IllegalArgumentException("None of the scope or the baseline must be null"); //$NON-NLS-1$ > } >+ IProgressMonitor currentMonitor = null; >+ if (monitor == null) { >+ currentMonitor = new NullProgressMonitor(); >+ } else { >+ currentMonitor = monitor; >+ } > final Set deltas = new HashSet(); >- final CompareApiScopeVisitor visitor = new CompareApiScopeVisitor(deltas, baseline, visibilityModifiers); >+ final CompareApiScopeVisitor visitor = new CompareApiScopeVisitor(deltas, baseline, visibilityModifiers, currentMonitor); > scope.accept(visitor); > if (visitor.containsError()) { > return null; >Index: src/org/eclipse/pde/api/tools/internal/provisional/comparator/CompareApiScopeVisitor.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/CompareApiScopeVisitor.java,v >retrieving revision 1.2 >diff -u -r1.2 CompareApiScopeVisitor.java >--- src/org/eclipse/pde/api/tools/internal/provisional/comparator/CompareApiScopeVisitor.java 10 Feb 2009 20:07:47 -0000 1.2 >+++ src/org/eclipse/pde/api/tools/internal/provisional/comparator/CompareApiScopeVisitor.java 6 Mar 2009 01:59:09 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008 IBM Corporation and others. >+ * Copyright (c) 2008, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -13,6 +13,8 @@ > import java.util.Set; > > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; > import org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor; > import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor; >@@ -20,6 +22,7 @@ > import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; > import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer; > import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot; >+import org.eclipse.pde.api.tools.internal.util.Util; > > /** > * ApiScope visitor implementation to run the comparison on all elements of the scope. >@@ -30,100 +33,125 @@ > IApiBaseline referenceBaseline; > int visibilityModifiers; > boolean containsErrors = false; >+ IProgressMonitor monitor; > >- public CompareApiScopeVisitor(final Set deltas, final IApiBaseline baseline, final int visibilityModifiers) { >+ public CompareApiScopeVisitor(final Set deltas, final IApiBaseline baseline, final int visibilityModifiers, >+ IProgressMonitor monitor) { > this.deltas = deltas; > this.referenceBaseline = baseline; > this.visibilityModifiers = visibilityModifiers; >+ this.monitor = monitor == null ? new NullProgressMonitor() : monitor; > } >- >+ > public boolean visit(IApiBaseline baseline) throws CoreException { >- IDelta delta = ApiComparator.compare(this.referenceBaseline, baseline, this.visibilityModifiers); >- if (delta != null) { >- delta.accept(new DeltaVisitor() { >- public void endVisit(IDelta localDelta) { >- if (localDelta.getChildren().length == 0) { >- CompareApiScopeVisitor.this.deltas.add(localDelta); >+ try { >+ Util.checkCanceled(this.monitor); >+ IDelta delta = ApiComparator.compare(this.referenceBaseline, baseline, this.visibilityModifiers); >+ if (delta != null) { >+ delta.accept(new DeltaVisitor() { >+ public void endVisit(IDelta localDelta) { >+ if (localDelta.getChildren().length == 0) { >+ CompareApiScopeVisitor.this.deltas.add(localDelta); >+ } > } >- } >- }); >- } else { >- this.containsErrors = true; >+ }); >+ } else { >+ this.containsErrors = true; >+ } >+ } finally { >+ monitor.worked(1); > } > return false; > } > > public boolean visit(IApiTypeContainer container) throws CoreException { >- container.accept(new ApiTypeContainerVisitor() { >- public void visit(String packageName, IApiTypeRoot typeroot) { >- try { >- CompareApiScopeVisitor.this.visit(typeroot); >- } catch (CoreException e) { >- ApiPlugin.log(e); >+ try { >+ Util.checkCanceled(this.monitor); >+ container.accept(new ApiTypeContainerVisitor() { >+ public void visit(String packageName, IApiTypeRoot typeroot) { >+ try { >+ CompareApiScopeVisitor.this.visit(typeroot); >+ } catch (CoreException e) { >+ ApiPlugin.log(e); >+ } > } >- } >- }); >+ }); >+ } catch (Exception e) { >+ monitor.worked(1); >+ } > return false; > } > > public boolean visit(IApiComponent component) throws CoreException { >- if (component.getErrors() != null) { >- this.containsErrors = true; >- return false; >- } >- IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(component.getId()); >- if (referenceComponent.getErrors() != null) { >- this.containsErrors = true; >- return false; >- } >- IDelta delta = ApiComparator.compare(referenceComponent, component, this.visibilityModifiers); >- if (delta != null) { >- delta.accept(new DeltaVisitor() { >- public void endVisit(IDelta localDelta) { >- if (localDelta.getChildren().length == 0) { >- CompareApiScopeVisitor.this.deltas.add(localDelta); >+ try { >+ if (component.getErrors() != null) { >+ this.containsErrors = true; >+ return false; >+ } >+ Util.checkCanceled(this.monitor); >+ IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(component.getId()); >+ if (referenceComponent.getErrors() != null) { >+ this.containsErrors = true; >+ return false; >+ } >+ Util.checkCanceled(this.monitor); >+ IDelta delta = ApiComparator.compare(referenceComponent, component, this.visibilityModifiers); >+ if (delta != null) { >+ delta.accept(new DeltaVisitor() { >+ public void endVisit(IDelta localDelta) { >+ if (localDelta.getChildren().length == 0) { >+ CompareApiScopeVisitor.this.deltas.add(localDelta); >+ } > } >- } >- }); >- } else { >- this.containsErrors = true; >+ }); >+ } else { >+ this.containsErrors = true; >+ } >+ } finally { >+ monitor.worked(1); > } > return false; > } > > public void visit(IApiTypeRoot root) throws CoreException { >- IApiComponent apiComponent = root.getApiComponent(); >- if (apiComponent == null) { >- return; >- } >- if (apiComponent.getErrors() != null) { >- this.containsErrors = true; >- return; >- } >- IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(apiComponent.getId()); >- if (referenceComponent == null) return; >- if (referenceComponent.getErrors() != null) { >- this.containsErrors = true; >- return; >- } >- IApiBaseline baseline = referenceComponent.getBaseline(); >- IDelta delta = ApiComparator.compare( >- root, >- apiComponent, >- referenceComponent, >- this.referenceBaseline, >- baseline, >- this.visibilityModifiers); >- if (delta != null) { >- delta.accept(new DeltaVisitor() { >- public void endVisit(IDelta localDelta) { >- if (localDelta.getChildren().length == 0) { >- CompareApiScopeVisitor.this.deltas.add(localDelta); >+ try { >+ IApiComponent apiComponent = root.getApiComponent(); >+ if (apiComponent == null) { >+ return; >+ } >+ if (apiComponent.getErrors() != null) { >+ this.containsErrors = true; >+ return; >+ } >+ Util.checkCanceled(this.monitor); >+ IApiComponent referenceComponent = this.referenceBaseline.getApiComponent(apiComponent.getId()); >+ if (referenceComponent == null) return; >+ if (referenceComponent.getErrors() != null) { >+ this.containsErrors = true; >+ return; >+ } >+ IApiBaseline baseline = referenceComponent.getBaseline(); >+ Util.checkCanceled(this.monitor); >+ IDelta delta = ApiComparator.compare( >+ root, >+ apiComponent, >+ referenceComponent, >+ this.referenceBaseline, >+ baseline, >+ this.visibilityModifiers); >+ if (delta != null) { >+ delta.accept(new DeltaVisitor() { >+ public void endVisit(IDelta localDelta) { >+ if (localDelta.getChildren().length == 0) { >+ CompareApiScopeVisitor.this.deltas.add(localDelta); >+ } > } >- } >- }); >- } else { >- this.containsErrors = true; >+ }); >+ } else { >+ this.containsErrors = true; >+ } >+ } finally { >+ monitor.worked(1); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 258853
:
127736
|
127838
|
132099
|
132259
|
132475