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 Jul 14, 2024
1 parent 90a8087 commit cb8bc25
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.pde.core.project;

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 +96,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, List<String> friends);

/**
* @deprecated Instead use
* {@link #newPackageExport(String, Version, boolean, List)}
*/
IPackageExportDescription newPackageExport(String name, Version version, boolean api, String[] friends);
@Deprecated(since = "4.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 = "4.19")
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,8 @@
*******************************************************************************/
package org.eclipse.pde.core.project;

import java.util.List;

import org.osgi.framework.Version;

/**
Expand All @@ -29,28 +31,54 @@ 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
*/
Version version();

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

/**
* Returns the declared friends of this package.
*
* @return friends as bundle symbolic names, may be empty
* @since 3.19
*/
public Version getVersion();
List<String> friends();

/**
* Returns the declared friends of this package or <code>null</code> if none.
* Returns the declared friends of this package or <code>null</code> if
* none.
*
* @return friends as bundle symbolic names or <code>null</code>
*/
public String[] getFriends();
default String[] getFriends() {
List<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 = "4.19")
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 = "4.19")
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 @@ -113,35 +113,50 @@ public IBundleProjectDescription getDescription(IProject project) throws CoreExc
*/
@Override
public IHostDescription newHost(String name, VersionRange range) {
return new HostDescriptoin(name, range);
return new HostDescription(name, range);
}

private record HostDescription(String name, VersionRange version) implements IHostDescription {
}

/**
* Creates and returns a new package import description.
*
* @param name fully qualified name of imported package
* @param range version constraint or <code>null</code>
* @param optional whether the import is optional
* @return package import description
*/
@Override
public IPackageImportDescription newPackageImport(String name, VersionRange range, boolean optional) {
return new PackageImportDescription(name, range, optional);
}

/**
* Constructs a new package export description.
*
* @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
* friends are specified the package will not be API
* @return package export description
*/
public record PackageImportDescription(String name, VersionRange version, boolean isOptional)
implements IPackageImportDescription {
}

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

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

@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(name);
if (version != null) {
buf.append(";version="); //$NON-NLS-1$
buf.append(version.toString());
}
if (friends.isEmpty()) {
buf.append(";x-friends="); //$NON-NLS-1$
buf.append('"');
String friendsString = friends.toString();
buf.append(friendsString, 1, friendsString.length() - 1);
buf.append('"');
} else {
if (!isApi) {
buf.append(";x-internal=true"); //$NON-NLS-1$
}
}
return buf.toString();
}
}

/**
Expand All @@ -158,6 +173,10 @@ public IRequiredBundleDescription newRequiredBundle(String name, VersionRange ra
return new RequiredBundleDescription(name, range, export, optional);
}

public record RequiredBundleDescription(String name, VersionRange version, boolean isExported, boolean isOptional)
implements IRequiredBundleDescription {
}

/**
* Creates and returns a new bundle classpath entry defining the relationship
* between a source, binaries, and library on the Bundle-Classpath header.
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit cb8bc25

Please sign in to comment.