From 35976cde5a7c58f42a4d6ea490327894d8f73c28 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 31 Jan 2024 01:03:19 +0100 Subject: [PATCH] Remove special treatment of org.eclipse.swt in API-Tools Fixes https://github.com/eclipse-pde/eclipse.pde/issues/1084 --- .../ui/internal/actions/DeltaSession.java | 24 +-- .../api/tools/internal/APIFileGenerator.java | 137 +++++++++--------- .../internal/builder/BaseApiAnalyzer.java | 25 +--- .../tools/internal/model/BundleComponent.java | 30 ++-- .../provisional/comparator/ApiComparator.java | 45 +----- .../pde/api/tools/internal/util/Util.java | 2 - 6 files changed, 93 insertions(+), 170 deletions(-) diff --git a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/actions/DeltaSession.java b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/actions/DeltaSession.java index 58d25175ea..1126307336 100644 --- a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/actions/DeltaSession.java +++ b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/actions/DeltaSession.java @@ -504,21 +504,13 @@ private int retrieveTypeModifiers(IDelta delta, String typeName, String componen IApiComponent p = providers[index]; if (!p.equals(apiComponent)) { String id2 = p.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id2)) { - typeRoot = p.findTypeRoot(typeName); - } else { - typeRoot = p.findTypeRoot(typeName, id2); - } + typeRoot = p.findTypeRoot(typeName, id2); } index++; } break; default: - if (Util.ORG_ECLIPSE_SWT.equals(id)) { - typeRoot = apiComponent.findTypeRoot(typeName); - } else { - typeRoot = apiComponent.findTypeRoot(typeName, id); - } + typeRoot = apiComponent.findTypeRoot(typeName, id); } if (typeRoot != null) { IApiType structure = typeRoot.getStructure(); @@ -554,21 +546,13 @@ private int retrieveTypeModifiers(IDelta delta, String typeName, String componen IApiComponent p = providers[index]; if (!p.equals(apiComponent)) { String id2 = p.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id2)) { - typeRoot = p.findTypeRoot(typeName); - } else { - typeRoot = p.findTypeRoot(typeName, id2); - } + typeRoot = p.findTypeRoot(typeName, id2); } index++; } break; default: - if (Util.ORG_ECLIPSE_SWT.equals(id)) { - typeRoot = apiComponent.findTypeRoot(typeName); - } else { - typeRoot = apiComponent.findTypeRoot(typeName, id); - } + typeRoot = apiComponent.findTypeRoot(typeName, id); } if (typeRoot != null) { IApiType structure = typeRoot.getStructure(); diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/APIFileGenerator.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/APIFileGenerator.java index 91f9dc24fa..6f256db666 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/APIFileGenerator.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/APIFileGenerator.java @@ -176,88 +176,85 @@ public void generateAPIFile() { } apiDescriptionFile.delete(); } - File[] allFiles = null; Map manifestMap = null; - IApiTypeContainer classFileContainer = null; - if (!this.projectLocation.endsWith(Util.ORG_ECLIPSE_SWT)) { - // create the directory class file container used to resolve - // signatures during tag scanning - String[] allBinaryLocations = this.binaryLocations.split(File.pathSeparator); - List allContainers = new ArrayList<>(); - IApiTypeContainer container = null; - for (String allBinaryLocation : allBinaryLocations) { - container = getContainer(allBinaryLocation); - if (container == null) { - throw new IllegalArgumentException( - NLS.bind(CoreMessages.api_generation_invalidBinaryLocation, allBinaryLocation)); - } - allContainers.add(container); - } - classFileContainer = new CompositeApiTypeContainer(null, allContainers); - File manifestFile = null; - File manifestDir = new File(root, "META-INF"); //$NON-NLS-1$ - if (manifestDir.exists() && manifestDir.isDirectory()) { - manifestFile = new File(manifestDir, "MANIFEST.MF"); //$NON-NLS-1$ + // create the directory class file container used to resolve + // signatures during tag scanning + String[] allBinaryLocations = this.binaryLocations.split(File.pathSeparator); + List allContainers = new ArrayList<>(); + IApiTypeContainer container = null; + for (String allBinaryLocation : allBinaryLocations) { + container = getContainer(allBinaryLocation); + if (container == null) { + throw new IllegalArgumentException( + NLS.bind(CoreMessages.api_generation_invalidBinaryLocation, allBinaryLocation)); } - if (manifestFile != null && manifestFile.exists()) { - try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(manifestFile));) { - manifestMap = ManifestElement.parseBundleManifest(inputStream, null); - this.apiPackages = collectApiPackageNames(manifestMap); - } catch (IOException | BundleException e) { - ApiPlugin.log(e); - } + allContainers.add(container); + } + IApiTypeContainer classFileContainer = new CompositeApiTypeContainer(null, allContainers); + File manifestFile = null; + File manifestDir = new File(root, "META-INF"); //$NON-NLS-1$ + if (manifestDir.exists() && manifestDir.isDirectory()) { + manifestFile = new File(manifestDir, "MANIFEST.MF"); //$NON-NLS-1$ + } + if (manifestFile != null && manifestFile.exists()) { + try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(manifestFile));) { + manifestMap = ManifestElement.parseBundleManifest(inputStream, null); + this.apiPackages = collectApiPackageNames(manifestMap); + } catch (IOException | BundleException e) { + ApiPlugin.log(e); } - if (this.manifests != null) { - String[] allManifestFiles = this.manifests.split(File.pathSeparator); - for (String allManifestFile : allManifestFiles) { - File currentManifest = new File(allManifestFile); - Set currentApiPackages = null; - if (currentManifest.exists()) { - try { - if (isZipJarFile(currentManifest.getName())) { - try (ZipFile zipFile = new ZipFile(currentManifest)) { - final ZipEntry entry = zipFile.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$ - if (entry != null) { - InputStream inputStream = zipFile.getInputStream(entry); - manifestMap = ManifestElement.parseBundleManifest(inputStream, null); - currentApiPackages = collectApiPackageNames(manifestMap); - - } - } - } else { - try (InputStream inputStream = new FileInputStream(currentManifest)) { + } + if (this.manifests != null) { + String[] allManifestFiles = this.manifests.split(File.pathSeparator); + for (String allManifestFile : allManifestFiles) { + File currentManifest = new File(allManifestFile); + Set currentApiPackages = null; + if (currentManifest.exists()) { + try { + if (isZipJarFile(currentManifest.getName())) { + try (ZipFile zipFile = new ZipFile(currentManifest)) { + final ZipEntry entry = zipFile.getEntry("META-INF/MANIFEST.MF"); //$NON-NLS-1$ + if (entry != null) { + InputStream inputStream = zipFile.getInputStream(entry); manifestMap = ManifestElement.parseBundleManifest(inputStream, null); currentApiPackages = collectApiPackageNames(manifestMap); + } } - } catch (IOException | BundleException e) { - ApiPlugin.log(e); - } - } - if (currentApiPackages != null) { - if (this.apiPackages == null) { - this.apiPackages = currentApiPackages; } else { - this.apiPackages.addAll(currentApiPackages); + try (InputStream inputStream = new FileInputStream(currentManifest)) { + manifestMap = ManifestElement.parseBundleManifest(inputStream, null); + currentApiPackages = collectApiPackageNames(manifestMap); + } } + } catch (IOException | BundleException e) { + ApiPlugin.log(e); + } + } + if (currentApiPackages != null) { + if (this.apiPackages == null) { + this.apiPackages = currentApiPackages; + } else { + this.apiPackages.addAll(currentApiPackages); } } } - FileFilter fileFilter = path -> (path.isFile() && Util.isJavaFileName(path.getName()) && isApi(path.getParent())) || path.isDirectory(); - allFiles = Util.getAllFiles(root, fileFilter); - if (this.sourceLocations != null) { - String[] allSourceLocations = this.sourceLocations.split(File.pathSeparator); - for (String currentSourceLocation : allSourceLocations) { - File[] allFiles2 = Util.getAllFiles(new File(currentSourceLocation), fileFilter); - if (allFiles2 != null) { - if (allFiles == null) { - allFiles = allFiles2; - } else { - int length = allFiles.length; - int length2 = allFiles2.length; - System.arraycopy(allFiles, 0, (allFiles = new File[length + length2]), 0, length); - System.arraycopy(allFiles2, 0, allFiles, length, length2); - } + } + FileFilter fileFilter = path -> (path.isFile() && Util.isJavaFileName(path.getName()) + && isApi(path.getParent())) || path.isDirectory(); + File[] allFiles = Util.getAllFiles(root, fileFilter); + if (this.sourceLocations != null) { + String[] allSourceLocations = this.sourceLocations.split(File.pathSeparator); + for (String currentSourceLocation : allSourceLocations) { + File[] allFiles2 = Util.getAllFiles(new File(currentSourceLocation), fileFilter); + if (allFiles2 != null) { + if (allFiles == null) { + allFiles = allFiles2; + } else { + int length = allFiles.length; + int length2 = allFiles2.length; + System.arraycopy(allFiles, 0, (allFiles = new File[length + length2]), 0, length); + System.arraycopy(allFiles2, 0, allFiles, length, length2); } } } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/BaseApiAnalyzer.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/BaseApiAnalyzer.java index 15e3beeb65..03cb66cf26 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/BaseApiAnalyzer.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/BaseApiAnalyzer.java @@ -1309,11 +1309,7 @@ private void checkCompatibility(final String typeName, final IApiComponent refer } IApiTypeRoot classFile = null; try { - if (Util.ORG_ECLIPSE_SWT.equals(id)) { - classFile = component.findTypeRoot(typeName); - } else { - classFile = component.findTypeRoot(typeName, id); - } + classFile = component.findTypeRoot(typeName, id); } catch (CoreException e) { ApiPlugin.log(e); } @@ -1331,11 +1327,7 @@ private void checkCompatibility(final String typeName, final IApiComponent refer IApiComponent p = providers[index]; if (!p.equals(component)) { String id2 = p.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id2)) { - classFile = p.findTypeRoot(typeName); - } else { - classFile = p.findTypeRoot(typeName, id2); - } + classFile = p.findTypeRoot(typeName, id2); if (classFile != null) { IRequiredComponentDescription[] components = component.getRequiredComponents(); for (IRequiredComponentDescription description : components) { @@ -1865,15 +1857,10 @@ private void processDelta(final IDelta delta, final IApiComponent reference, fin if (Flags.isProtected(modifiers)) { String typeName = delta.getTypeName(); if (typeName != null) { - IApiTypeRoot typeRoot = null; IApiType type = null; try { String id = component.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id)) { - typeRoot = component.findTypeRoot(typeName); - } else { - typeRoot = component.findTypeRoot(typeName, id); - } + IApiTypeRoot typeRoot = component.findTypeRoot(typeName, id); if (typeRoot == null) { String packageName = Signatures.getPackageName(typeName); // check if the type is provided by a @@ -1885,11 +1872,7 @@ private void processDelta(final IDelta delta, final IApiComponent reference, fin IApiComponent p = providers[index]; if (!p.equals(component)) { String id2 = p.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id2)) { - typeRoot = p.findTypeRoot(typeName); - } else { - typeRoot = p.findTypeRoot(typeName, id2); - } + typeRoot = p.findTypeRoot(typeName, id2); } index++; } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java index 5d28af61a9..6239af42c8 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/model/BundleComponent.java @@ -555,25 +555,17 @@ protected List createApiTypeContainers() throws CoreException List all = new ArrayList<>(); // build the classpath from bundle and all fragments all.add(this); - boolean considerFragments = true; - if (Util.ORG_ECLIPSE_SWT.equals(getSymbolicName())) { - // if SWT is a project to be built/analyzed don't consider its - // fragments - considerFragments = !isApiEnabled(); - } - if (considerFragments) { - BundleDescription[] fragments = getBundleDescription().getFragments(); - for (BundleDescription fragment : fragments) { - if (!fragment.isResolved()) { - continue; - } - IApiComponent component = getBaseline().getApiComponent(fragment.getSymbolicName()); - if (component != null) { - // force initialization of the fragment so we can - // retrieve its class file containers - component.getApiTypeContainers(); - all.add(component); - } + BundleDescription[] fragments = getBundleDescription().getFragments(); + for (BundleDescription fragment : fragments) { + if (!fragment.isResolved()) { + continue; + } + IApiComponent component = getBaseline().getApiComponent(fragment.getSymbolicName()); + if (component != null) { + // force initialization of the fragment so we can + // retrieve its class file containers + component.getApiTypeContainers(); + all.add(component); } } Iterator iterator = all.iterator(); diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java index 1cdcc8b837..b8303a8551 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/provisional/comparator/ApiComparator.java @@ -357,13 +357,8 @@ public static IDelta compare(final IApiTypeRoot typeRoot2, final IApiComponent c return NO_DELTA; } String typeName = typeRoot2.getTypeName(); - IApiTypeRoot typeRoot = null; String id = component.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id)) { - typeRoot = component.findTypeRoot(typeName); - } else { - typeRoot = component.findTypeRoot(typeName, id); - } + IApiTypeRoot typeRoot = component.findTypeRoot(typeName, id); final IApiDescription apiDescription2 = component2.getApiDescription(); IApiAnnotations elementDescription2 = apiDescription2.resolveAnnotations(typeDescriptor2.getHandle()); int visibility = 0; @@ -614,17 +609,9 @@ static boolean filterType(final int visibilityModifiers, IApiAnnotations element private static IDelta internalCompare(final IApiComponent component, final IApiComponent component2, final IApiBaseline referenceBaseline, final IApiBaseline baseline, final int visibilityModifiers, final Delta globalDelta, final IProgressMonitor monitor) throws CoreException { final Set typeRootBaseLineNames = new HashSet<>(); final String id = component.getSymbolicName(); - IApiTypeContainer[] typeRootContainers = null; - IApiTypeContainer[] typeRootContainers2 = null; final SubMonitor localmonitor = SubMonitor.convert(monitor, 4); - final boolean isSWT = Util.ORG_ECLIPSE_SWT.equals(id); - if (isSWT) { - typeRootContainers = component.getApiTypeContainers(); - typeRootContainers2 = component2.getApiTypeContainers(); - } else { - typeRootContainers = component.getApiTypeContainers(id); - typeRootContainers2 = component2.getApiTypeContainers(id); - } + IApiTypeContainer[] typeRootContainers = component.getApiTypeContainers(id); + IApiTypeContainer[] typeRootContainers2 = component2.getApiTypeContainers(id); final IApiDescription apiDescription = component.getApiDescription(); final IApiDescription apiDescription2 = component2.getApiDescription(); if (typeRootContainers != null) { @@ -652,12 +639,7 @@ public void visit(String packageName, IApiTypeRoot typeRoot) { // Annotation is missing, not an API? visibility = 0; } - IApiTypeRoot typeRoot2 = null; - if (isSWT) { - typeRoot2 = component2.findTypeRoot(typeName); - } else { - typeRoot2 = component2.findTypeRoot(typeName, id); - } + IApiTypeRoot typeRoot2 = component2.findTypeRoot(typeName, id); IApiComponent provider = null; IApiDescription providerApiDesc = null; boolean reexported = false; @@ -673,11 +655,7 @@ public void visit(String packageName, IApiTypeRoot typeRoot) { IApiComponent p = providers[index]; if (!p.equals(component2)) { String id2 = p.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id2)) { - typeRoot2 = p.findTypeRoot(typeName); - } else { - typeRoot2 = p.findTypeRoot(typeName, id2); - } + typeRoot2 = p.findTypeRoot(typeName, id2); if (typeRoot2 != null) { provider = p; providerApiDesc = p.getApiDescription(); @@ -813,12 +791,7 @@ public void visit(String packageName, IApiTypeRoot typeRoot) { if (elementDescription != null) { visibility = elementDescription.getVisibility(); } - IApiTypeRoot typeRoot2 = null; - if (isSWT) { - typeRoot2 = component2.findTypeRoot(typeName); - } else { - typeRoot2 = component2.findTypeRoot(typeName, id); - } + IApiTypeRoot typeRoot2 = component2.findTypeRoot(typeName, id); IApiDescription providerApiDesc = null; if (typeRoot2 == null) { // check if the type is provided @@ -831,11 +804,7 @@ public void visit(String packageName, IApiTypeRoot typeRoot) { IApiComponent p = providers[index]; if (!p.equals(component2)) { String id2 = p.getSymbolicName(); - if (Util.ORG_ECLIPSE_SWT.equals(id2)) { - typeRoot2 = p.findTypeRoot(typeName); - } else { - typeRoot2 = p.findTypeRoot(typeName, id2); - } + typeRoot2 = p.findTypeRoot(typeName, id2); if (typeRoot2 != null) { providerApiDesc = p.getApiDescription(); } diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java index 6a11d556ae..ee74670871 100644 --- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java +++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java @@ -307,8 +307,6 @@ private void cancelBuild(Object jobfamily) { public static final IPath MANIFEST_PROJECT_RELATIVE_PATH = IPath.fromOSString(JarFile.MANIFEST_NAME); - public static final String ORG_ECLIPSE_SWT = "org.eclipse.swt"; //$NON-NLS-1$ - public static final int LATEST_OPCODES_ASM = Opcodes.ASM9; /**