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 1, 2024
1 parent 22f953a commit 3f8f07d
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 118 deletions.
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 Down Expand Up @@ -403,7 +403,8 @@ public static void addExportedPackage(IProject project, String packagename, bool
list.add(export);
}
}
list.add(service.newPackageExport(packagename, null, !internal, friends));
list.add(
service.newPackageExport(packagename, null, !internal, friends != null ? List.of(friends) : List.of()));
description.setPackageExports(list.toArray(new IPackageExportDescription[list.size()]));
description.apply(null);
AbstractApiTest.waitForAutoBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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 +153,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$
assertTrue("the package should not have any friends", export.friends().isEmpty()); //$NON-NLS-1$
} 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 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -100,15 +103,6 @@ public IHostDescription newHost(String name, VersionRange range) {
}

record HostDescription(String name, VersionRange version) implements IHostDescription {
@Override
public String getName() {
return name();
}

@Override
public VersionRange getVersion() {
return version();
}
}

@Override
Expand All @@ -118,39 +112,18 @@ public IPackageImportDescription newPackageImport(String name, VersionRange rang

record PackageImportDescription(String name, VersionRange version, boolean isOptional)
implements IPackageImportDescription {
@Override
public String getName() {
return name();
}

@Override
public VersionRange getVersion() {
return version();
}
}

@Override
public IPackageExportDescription newPackageExport(String name, Version version, boolean api, String[] friends) {
List<String> friendsList = friends != null ? List.of(friends) : List.of();
return new PackageExportDescription(name, version, friendsList, friendsList.isEmpty() ? api : false);
public IPackageExportDescription newPackageExport(String name, Version version, boolean api,
Collection<String> friends) {
return new PackageExportDescription(name, version, friends, friends.isEmpty() ? api : false);
}

record PackageExportDescription(String name, Version version, List<String> friends, boolean isApi)
record PackageExportDescription(String name, Version version, SortedSet<String> friends, boolean isApi)
implements IPackageExportDescription {

@Override
public String getName() {
return name();
}

@Override
public Version getVersion() {
return version();
}

@Override
public String[] getFriends() {
return friends.isEmpty() ? null : friends.toArray(String[]::new);
public PackageExportDescription(String name, Version version, Collection<String> friends, boolean isApi) {
this(name, version, Collections.unmodifiableSortedSet(new TreeSet<>(friends)), isApi);
}
}

Expand All @@ -161,15 +134,6 @@ public IRequiredBundleDescription newRequiredBundle(String name, VersionRange ra

record RequiredBundleDescription(String name, VersionRange version, boolean isExported, boolean isOptional)
implements IRequiredBundleDescription {
@Override
public String getName() {
return name();
}

@Override
public VersionRange getVersion() {
return version();
}
}

@Override
Expand Down
Loading

0 comments on commit 3f8f07d

Please sign in to comment.