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 2b91541 commit 96e3986
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 232 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 @@ -96,25 +96,39 @@ 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 {
}

@Override
public IPackageImportDescription newPackageImport(String name, VersionRange range, boolean optional) {
return new PackageImportDescription(name, range, optional);
}

public record PackageImportDescription(String name, VersionRange version, boolean isOptional)
implements IPackageImportDescription {
}

@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, List<String> friends) {
return new PackageExportDescription(name, version, List.copyOf(friends), friends.isEmpty() ? api : false);
}

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

@Override
public IRequiredBundleDescription newRequiredBundle(String name, VersionRange range, boolean optional, boolean export) {
return new RequiredBundleDescription(name, range, export, optional);
}

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

@Override
public IBundleClasspathEntry newBundleClasspathEntry(IPath sourceFolder, IPath binaryFolder, IPath library) {
return new BundleClasspathSpecification(sourceFolder, binaryFolder, library);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 96e3986

Please sign in to comment.