Skip to content

Commit

Permalink
Modernize pde.project description interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Aug 6, 2024
1 parent 22f953a commit 61da170
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Bundle-Activator: org.eclipse.pde.api.tools.tests.ApiTestsPlugin
Bundle-ActivationPolicy: lazy
Eclipse-BundleShape: dir
Import-Package: junit.framework,
org.assertj.core.api;version="[3.26.0,4.0.0)",
org.eclipse.equinox.frameworkadmin,
org.junit,
org.junit.runner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public static void removeExportedPackage(IProject project, String packagename) t
if (exports != null) {
List<IPackageExportDescription> list = new ArrayList<>();
for (IPackageExportDescription export : exports) {
if (!packagename.equals(export.getName())) {
if (!packagename.equals(export.name())) {
list.add(export);
}
}
Expand All @@ -389,7 +389,8 @@ public static void removeExportedPackage(IProject project, String packagename) t
* @param friends a listing of friends for this exported package
* @throws CoreException if something bad happens
*/
public static void addExportedPackage(IProject project, String packagename, boolean internal, String[] friends) throws CoreException {
public static void addExportedPackage(IProject project, String packagename, boolean internal, List<String> friends)
throws CoreException {
if (!project.exists() || packagename == null) {
// do no work
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ public void testWPUPdateExportPackageDirectiveChangedToInternal() throws Excepti
assertTestPackage(project, IPath.fromOSString(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(), "export1"); //$NON-NLS-1$

// export the package
ProjectUtils.addExportedPackage(project.getProject(), "export1", true, null); //$NON-NLS-1$
ProjectUtils.addExportedPackage(project.getProject(), "export1", true, List.of()); //$NON-NLS-1$

// check the description
IApiAnnotations annot = getTestProjectApiDescription().resolveAnnotations(Factory.packageDescriptor("export1")); //$NON-NLS-1$
Expand Down Expand Up @@ -853,7 +853,7 @@ public void testWPUpdateExportPackageRemoved() throws Exception {
* sets the given package name to be an Exported-Package
*/
private void setPackageToApi(IJavaProject project, String name) throws CoreException {
ProjectUtils.addExportedPackage(project.getProject(), name, false, null);
ProjectUtils.addExportedPackage(project.getProject(), name, false, List.of());
}

IJavaProject getTestingProject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
*******************************************************************************/
package org.eclipse.pde.api.tools.util.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -137,7 +139,7 @@ public void testCreatePluginProject() throws CoreException {
private IPackageExportDescription getExport(IPackageExportDescription[] exports, String packageName) {
if (exports != null) {
for (IPackageExportDescription export : exports) {
if (export.getName().equals(packageName)) {
if (export.name().equals(packageName)) {
return export;
}
}
Expand All @@ -153,12 +155,12 @@ private IPackageExportDescription getExport(IPackageExportDescription[] exports,
* @param friendcount the desired friend count
*/
private void assertExportedPackage(IPackageExportDescription export, boolean internalstate, int friendcount) {
String packagename = export.getName();
String packagename = export.name();
assertTrue("the package " + packagename + " must not be internal", export.isApi() == !internalstate); //$NON-NLS-1$ //$NON-NLS-2$
if (friendcount == 0) {
assertNull("the package should not have any friends", export.getFriends()); //$NON-NLS-1$
assertThat(export.friends()).isEmpty();
} else {
assertEquals("the package " + packagename + " must not have friends", friendcount, export.getFriends().length); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals("the package " + packagename + " must not have friends", friendcount, export.friends().size()); //$NON-NLS-1$ //$NON-NLS-2$
}
}

Expand All @@ -170,7 +172,7 @@ public void testAddRawExportedPackage() throws CoreException {
String packagename = "org.eclipse.apitools.test"; //$NON-NLS-1$
IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, packagename, false, null);
ProjectUtils.addExportedPackage(project, packagename, false, List.of());
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
assertExportedPackage(getExport(exports, packagename), false, 0);
}
Expand All @@ -183,7 +185,7 @@ public void testAddInternalExportedPackage() throws CoreException {
String packagename = "org.eclipse.apitools.test.internal"; //$NON-NLS-1$
IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, packagename, true, null);
ProjectUtils.addExportedPackage(project, packagename, true, List.of());
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
assertExportedPackage(getExport(exports, packagename), true, 0);
}
Expand All @@ -196,8 +198,7 @@ public void testAddExternalPackageWithFriends() throws CoreException {
String packagename = "org.eclipse.apitools.test.4friends"; //$NON-NLS-1$
IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, packagename, false, new String[] {
"F1", "F2", "F3", "F4" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
ProjectUtils.addExportedPackage(project, packagename, false, List.of("F1", "F2", "F3", "F4")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
assertExportedPackage(getExport(exports, packagename), true, 4);
}
Expand All @@ -209,8 +210,9 @@ public void testAddExternalPackageWithFriends() throws CoreException {
public void testAddMultipleExportedPackages() throws CoreException {
IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.multi.friends", false, new String[] { "F1", "F2", "F3", "F4" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.multi.internal", true, null); //$NON-NLS-1$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.multi.friends", false, //$NON-NLS-1$
List.of("F1", "F2", "F3", "F4")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.multi.internal", true, List.of()); //$NON-NLS-1$
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
assertExportedPackage(getExport(exports, "org.eclipse.apitools.test.multi.friends"), true, 4); //$NON-NLS-1$
assertExportedPackage(getExport(exports, "org.eclipse.apitools.test.multi.internal"), true, 0); //$NON-NLS-1$
Expand All @@ -223,8 +225,8 @@ public void testAddMultipleExportedPackages() throws CoreException {
public void testRemoveExistingExportedPackage() throws CoreException {
IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.remove1", false, new String[] { "F1" }); //$NON-NLS-1$ //$NON-NLS-2$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.remove2", true, null); //$NON-NLS-1$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.remove1", false, List.of("F1")); //$NON-NLS-1$ //$NON-NLS-2$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.remove2", true, List.of()); //$NON-NLS-1$
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
assertExportedPackage(getExport(exports, "org.eclipse.apitools.test.remove1"), true, 1); //$NON-NLS-1$
assertExportedPackage(getExport(exports, "org.eclipse.apitools.test.remove2"), true, 0); //$NON-NLS-1$
Expand All @@ -241,7 +243,7 @@ public void testRemoveExistingExportedPackage() throws CoreException {
public void testRemoveNonExistingExportedPackage() throws CoreException {
IJavaProject jproject = getTestingJavaProject(TESTING_PROJECT_NAME);
IProject project = jproject.getProject();
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.removeA", false, new String[] { "F1" }); //$NON-NLS-1$ //$NON-NLS-2$
ProjectUtils.addExportedPackage(project, "org.eclipse.apitools.test.removeA", false, List.of("F1")); //$NON-NLS-1$ //$NON-NLS-2$
IPackageExportDescription[] exports = ProjectUtils.getExportedPackages(project);
assertExportedPackage(getExport(exports, "org.eclipse.apitools.test.removeA"), true, 1); //$NON-NLS-1$
ProjectUtils.removeExportedPackage(project, "org.eclipse.apitools.test.dont.exist"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected void checkRequiredBundles() {
descs.addAll(Arrays.asList(arTmp));
}
for (final IRequiredBundleDescription bd : descs) {
requiredBundles.remove(bd.getName());
requiredBundles.remove(bd.name());
}

if (requiredBundles.size() > 0) {
Expand All @@ -188,7 +188,7 @@ protected void checkRequiredBundles() {
imDescs.addAll(Arrays.asList(currentImportPacks));
}
for (final IPackageImportDescription ds : imDescs) {
requiredImportPacks.remove(ds.getName());
requiredImportPacks.remove(ds.name());
}
if (!requiredImportPacks.isEmpty()) {
for (final String i : requiredImportPacks) {
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.pde.doc.user/forceQualifierUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# To force a version qualifier update add the issue here
Fix deprecation tag 'since' value
Modernize pde.project description interfaces: https://github.com/eclipse-pde/eclipse.pde/pull/1341
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.pde.core.project;

import java.util.Collection;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -94,11 +97,22 @@ default IPackageImportDescription newPackageImport(String name,
* @param name fully qualified package name
* @param version version or <code>null</code>
* @param api whether the package is considered API
* @param friends symbolic names of bundles that are friends, or <code>null</code>; when
* @param friends symbolic names of bundles that are friends; when
* friends are specified the package will not be API
* @return package export description
* @since 3.19
*/
IPackageExportDescription newPackageExport(String name, Version version, boolean api, Collection<String> friends);

/**
* @deprecated Instead use
* {@link #newPackageExport(String, Version, boolean, Collection)}
*/
IPackageExportDescription newPackageExport(String name, Version version, boolean api, String[] friends);
@Deprecated(since = "3.19")
default IPackageExportDescription newPackageExport(String name, Version version, boolean api, String[] friends) {
return newPackageExport(name, version, api, friends != null ? List.of(friends) : List.of());
}


/**
* Creates and returns a new required bundle description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ public interface IHostDescription {
* Returns the symbolic name of the host.
*
* @return symbolic name of the host
* @since 3.19
*/
String getName();
String name();

/** @deprecated Instead use {@link #name()} */
@Deprecated(since = "3.19")
default String getName() {
return name();
}

/**
* Returns the version constraint of the host or <code>null</code>
Expand All @@ -39,12 +46,12 @@ public interface IHostDescription {
* @return version constraint or <code>null</code>
* @since 3.19
*/
VersionRange getVersion();
VersionRange version();

/** @deprecated Instead use {@link #getVersion()} */
/** @deprecated Instead use {@link #version()} */
@Deprecated(forRemoval = true, since = "3.19 (removal in 2026-09 or later)")
default org.eclipse.osgi.service.resolver.VersionRange getVersionRange() {
VersionRange version = getVersion();
VersionRange version = version();
return version != null ? new org.eclipse.osgi.service.resolver.VersionRange(version.toString()) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.pde.core.project;

import java.util.Set;
import java.util.SortedSet;

import org.osgi.framework.Version;

/**
Expand All @@ -29,28 +32,50 @@ public interface IPackageExportDescription {
* Returns the fully qualified name of the exported package.
*
* @return fully qualified name of the exported package
* @since 3.19
*/
public String getName();
String name();

/** @deprecated Instead use {@link #name()} */
@Deprecated(since = "3.19")
default String getName() {
return name();
}

/**
* Returns the version of the exported package or <code>null</code>
* if unspecified.
* Returns the version of the exported package or <code>null</code> if
* unspecified.
*
* @return version or <code>null</code>
* @since 3.19
*/
public Version getVersion();
Version version();

/** @deprecated Instead use {@link #version()} */
@Deprecated(since = "3.19")
default Version getVersion() {
return version();
}

/**
* Returns the declared friends of this package or <code>null</code> if none.
* Returns the declared friends of this package.
*
* @return friends as bundle symbolic names or <code>null</code>
* @return friends as bundle symbolic names, may be empty
* @since 3.19
*/
public String[] getFriends();
SortedSet<String> friends();

/** @deprecated Instead use {@link #friends()} */
@Deprecated(since = "3.19")
default String[] getFriends() {
Set<String> friends = friends();
return friends.isEmpty() ? null : friends.toArray(String[]::new);
}

/**
* Returns whether the package is exported as API, or is internal.
*
* @return whether the package is exported as API
*/
public boolean isApi();
boolean isApi();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ public interface IPackageImportDescription {
* Returns the fully qualified name of the imported package.
*
* @return fully qualified name of the imported package
* @since 3.19
*/
String getName();
String name();

/** @deprecated Instead use {@link #name()} */
@Deprecated(since = "3.19")
default String getName() {
return name();
}

/**
* Returns the version constraint of the imported package or <code>null</code>
Expand All @@ -39,12 +46,12 @@ public interface IPackageImportDescription {
* @return version constraint or <code>null</code>
* @since 3.19
*/
VersionRange getVersion();
VersionRange version();

/** @deprecated Instead use {@link #getVersion()} */
/** @deprecated Instead use {@link #version()} */
@Deprecated(forRemoval = true, since = "3.19 (removal in 2026-09 or later)")
default org.eclipse.osgi.service.resolver.VersionRange getVersionRange() {
VersionRange version = getVersion();
VersionRange version = version();
return version != null ? new org.eclipse.osgi.service.resolver.VersionRange(version.toString()) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ public interface IRequiredBundleDescription {
* Returns the symbolic name of the required bundle.
*
* @return symbolic name of the required bundle
* @since 3.19
*/
String getName();
String name();

/** @deprecated Instead use {@link #name()} */
@Deprecated(since = "3.19")
default String getName() {
return name();
}

/**
* Returns the version constraint of the required bundle or <code>null</code>
Expand All @@ -39,12 +46,12 @@ public interface IRequiredBundleDescription {
* @return version constraint or <code>null</code>
* @since 3.19
*/
VersionRange getVersion();
VersionRange version();

/** @deprecated Instead use {@link #getVersion()} */
/** @deprecated Instead use {@link #version()} */
@Deprecated(forRemoval = true, since = "3.19 (removal in 2026-09 or later)")
default org.eclipse.osgi.service.resolver.VersionRange getVersionRange() {
VersionRange version = getVersion();
VersionRange version = version();
return version != null ? new org.eclipse.osgi.service.resolver.VersionRange(version.toString()) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ private void initialize(IProject project) throws CoreException {
if (directive != null) {
friends = ManifestElement.getArrayFromList(directive);
}
exports[i] = getBundleProjectService().newPackageExport(exp.getValue(), getVersion(pv), !internal, friends);
exports[i] = getBundleProjectService().newPackageExport(exp.getValue(), getVersion(pv), !internal,
friends != null ? List.of(friends) : List.of());
}
setPackageExports(exports);
}
Expand Down
Loading

0 comments on commit 61da170

Please sign in to comment.