Skip to content

Commit

Permalink
Add BundlesAction.createBundleIU(File) for easy creation of IU
Browse files Browse the repository at this point in the history
It is often useful to get some information about a file and
BundlesAction is the P2 way to gather such data, but at the moment it is
really cumbersome and requires a lot of calls and handling of cases to
get to that point.

This now adds a new method BundlesAction.createBundleIU(File) that ease
this task.
  • Loading branch information
laeubi committed Feb 3, 2025
1 parent 22405a7 commit 49b9bf5
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,30 @@ static IInstallableUnit createBundleConfigurationUnit(String hostId, Version cuV
return MetadataFactory.createInstallableUnit(cu);
}

/**
* Attempts to read the given file (or folder) as a bundle and creates an
* {@link IInstallableUnit} describing it.
*
* @param file the file to read as a bundle
* @return an {@link Optional} describing the result, if anything goes wrong an
* empty optional is returned
*/
public static Optional<IInstallableUnit> createBundleIU(File file) {
try {
BundleDescription bundleDescription = BundlesAction.createBundleDescription(file);
if (bundleDescription != null) {
IArtifactKey key = BundlesAction.createBundleArtifactKey(bundleDescription.getSymbolicName(),
bundleDescription.getVersion().toString());
PublisherInfo publisherInfo = new PublisherInfo();
publisherInfo.setArtifactOptions(IPublisherInfo.A_INDEX);
return Optional.ofNullable(BundlesAction.createBundleIU(bundleDescription, key, publisherInfo));
}
} catch (BundleException | IOException | RuntimeException e) {
return Optional.empty();
}
return Optional.empty();
}

public static IInstallableUnit createBundleIU(BundleDescription bd, IArtifactKey key, IPublisherInfo info) {
return new BundlesAction(new BundleDescription[] { bd }).doCreateBundleIU(bd, key, info);
}
Expand Down

0 comments on commit 49b9bf5

Please sign in to comment.