Skip to content

Commit

Permalink
Remove unused distinction between Plug-ins and Fragments in products
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Nov 5, 2023
1 parent 3734726 commit b8b4f9d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,15 @@ public interface IProductDescriptor {
/**
* Returns the bundles listed in this product. Note: These bundles are only part of
* the product if {@link #useFeatures()} returns <code>false</code>.
* @param includeFragments whether or not to include the fragments in the return value
* @return the list of bundles in this product.
*/
public List<IVersionedId> getBundles(boolean includeFragments);
public List<IVersionedId> getBundles();

/**
* Returns <code>true</code> when <code>getBundles(includeFragments)</code> returns a non-empty list.
* Returns <code>true</code> when {@link #getBundles()} returns a non-empty
* list.
*/
public boolean hasBundles(boolean includeFragments);

/**
* Returns the fragments listed in the product.
* @see #useFeatures()
*/
public List<IVersionedId> getFragments();
public boolean hasBundles();

/**
* Returns the features listed in the product. Same as <code>getFeatures(INCLUDED_FEATURES)</code>. Note: These features are only part of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ public class ProductFile extends DefaultHandler implements IProductDescriptor {
private String uid = null;
private ProductContentType productContentType = null;
protected List<FeatureEntry> plugins = new ArrayList<>();
protected List<FeatureEntry> fragments = new ArrayList<>();
private final List<FeatureEntry> features = new ArrayList<>();
private final List<FeatureEntry> rootFeatures = new ArrayList<>();
private String splashLocation = null;
Expand Down Expand Up @@ -343,38 +342,20 @@ public Map<String, String> getConfigurationProperties(String os, String arch) {

/**
* Returns a List<VersionedName> for each bundle that makes up this product.
* @param includeFragments Indicates whether or not fragments should
* be included in the list
*/
@Override
public List<IVersionedId> getBundles(boolean includeFragments) {
List<IVersionedId> result = new LinkedList<>();

public List<IVersionedId> getBundles() {
List<IVersionedId> result = new ArrayList<>();
for (FeatureEntry plugin : plugins) {
result.add(new VersionedId(plugin.getId(), plugin.getVersion()));
}

if (includeFragments) {
for (FeatureEntry fragment : fragments) {
result.add(new VersionedId(fragment.getId(), fragment.getVersion()));
}
}

return result;
}

@Override
public boolean hasBundles(boolean includeFragments) {
public boolean hasBundles() {
// implement directly; don't call the potentially overridden getBundles
return !plugins.isEmpty() || (includeFragments && !fragments.isEmpty());
}

private List<FeatureEntry> getBundleEntries(boolean includeFragments) {
List<FeatureEntry> result = new LinkedList<>();
result.addAll(plugins);
if (includeFragments)
result.addAll(fragments);
return result;
return !plugins.isEmpty();
}

/**
Expand All @@ -387,20 +368,6 @@ public List<BundleInfo> getBundleInfos() {
return bundleInfos != null ? bundleInfos : Collections.emptyList();
}

/**
* Returns a list<VersionedName> of fragments that constitute this product.
*/
@Override
public List<IVersionedId> getFragments() {
List<IVersionedId> result = new LinkedList<>();

for (FeatureEntry fragment : fragments) {
result.add(new VersionedId(fragment.getId(), fragment.getVersion()));
}

return result;
}

/**
* Returns a List<VersionedName> of features that constitute this product.
*/
Expand All @@ -417,7 +384,7 @@ public boolean hasFeatures() {

@Override
public List<IVersionedId> getFeatures(int options) {
List<IVersionedId> result = new LinkedList<>();
List<IVersionedId> result = new ArrayList<>();

if ((options & INCLUDED_FEATURES) != 0) {
for (FeatureEntry feature : features) {
Expand All @@ -435,13 +402,13 @@ public List<IVersionedId> getFeatures(int options) {

public List<FeatureEntry> getProductEntries() {
if (useFeatures()) {
return features;
return Collections.unmodifiableList(features);
}
return getBundleEntries(true);
return Collections.unmodifiableList(plugins);
}

public boolean containsPlugin(String plugin) {
List<IVersionedId> bundles = getBundles(true);
List<IVersionedId> bundles = getBundles();
for (IVersionedId versionedId : bundles) {
if (versionedId.getId().equals(plugin)) {
return true;
Expand Down Expand Up @@ -1274,12 +1241,7 @@ protected void processPlugin(Attributes attributes) {

FeatureEntry entry = new FeatureEntry(pluginId, pluginVersion != null ? pluginVersion : GENERIC_VERSION_NUMBER, true);
entry.setFragment(Boolean.parseBoolean(fragment));

if (fragment != null && Boolean.parseBoolean(fragment)) {
fragments.add(entry);
} else {
plugins.add(entry);
}
plugins.add(entry);
}

private void processFeature(Attributes attributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,17 @@ private void createRootAdvice() {
switch (product.getProductContentType()) { // add new case for each new content type included in product
case MIXED : // include all content types
list = versionElements(listElements(product.getFeatures(), ".feature.group"), IInstallableUnit.NAMESPACE_IU_ID); //$NON-NLS-1$
list.addAll(versionElements(listElements(product.getBundles(true), null), IInstallableUnit.NAMESPACE_IU_ID));
list.addAll(versionElements(listElements(product.getBundles(), null), IInstallableUnit.NAMESPACE_IU_ID));
break;
case FEATURES : // include features only
list = versionElements(listElements(product.getFeatures(), ".feature.group"), IInstallableUnit.NAMESPACE_IU_ID); //$NON-NLS-1$

if (product.hasBundles(true)) {
if (product.hasBundles()) {
finalStatus.add(new Status(IStatus.INFO, Activator.ID, Messages.bundlesInProductFileIgnored));
}
break;
case BUNDLES : // include bundles only
list = versionElements(listElements(product.getBundles(true), null), IInstallableUnit.NAMESPACE_IU_ID);
list = versionElements(listElements(product.getBundles(), null), IInstallableUnit.NAMESPACE_IU_ID);

if (product.hasFeatures()) {
finalStatus.add(new Status(IStatus.INFO, Activator.ID, Messages.featuresInProductFileIgnored));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void addProductFileBundles(ProductConfigData productConfigData) {
if (product.useFeatures()) {
return;
}
List<IVersionedId> bundles = product.getBundles(true);
List<IVersionedId> bundles = product.getBundles();
Set<BundleInfo> set = new HashSet<>();
set.addAll(Arrays.asList(productConfigData.data.getBundles()));

Expand All @@ -247,7 +247,7 @@ private ConfigData generateConfigData() {

// Add all the bundles here. We replace / update them later
// if we find configuration information
List<IVersionedId> bundles = product.getBundles(true);
List<IVersionedId> bundles = product.getBundles();
for (IVersionedId vid : bundles) {
BundleInfo bundleInfo = new BundleInfo();
bundleInfo.setSymbolicName(vid.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public void testGetConfigurationProperties() {
*/
@Test
public void testGetBundles() {
List<IVersionedId> bundles = productFile.getBundles(false);
assertEquals("1.0", 1, bundles.size());
assertEquals("1.1", "org.eclipse.core.runtime", bundles.get(0).getId());
assertEquals("1.2", Version.createOSGi(1, 0, 4), bundles.get(0).getVersion());
bundles = productFile.getBundles(true);
assertEquals("1.3", 2, bundles.size());
List<IVersionedId> bundles = productFile.getBundles();
assertEquals(2, bundles.size());
assertEquals("org.eclipse.core.runtime", bundles.get(0).getId());
assertEquals(Version.createOSGi(1, 0, 4), bundles.get(0).getVersion());
assertEquals("org.eclipse.swt.win32.win32.x86", bundles.get(1).getId());
assertEquals(Version.emptyVersion, bundles.get(1).getVersion());
}

/**
Expand All @@ -120,17 +120,6 @@ public void testGetBundleInfos() {
assertTrue("1.3", info.isMarkedAsStarted());
}

/**
* Test method for
* {@link org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile#getFragments()}.
*/
@Test
public void testGetFragments() {
List<IVersionedId> fragments = productFile.getFragments();
assertEquals("1.0", 1, fragments.size());
assertEquals("1.1", "org.eclipse.swt.win32.win32.x86", fragments.get(0).getId());
}

/**
* Test method for
* {@link org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile#getFeatures()}.
Expand Down Expand Up @@ -168,24 +157,21 @@ public void testGetFeaturesOnlyReturnsIncludedFeatures() {
public void testHasFeatures() throws Exception {
ProductFile featuresOnly = new ProductFile(TestData.getFile("ProductActionTest", "onlyFeatures.product").toString());
assertTrue(featuresOnly.hasFeatures());
assertFalse(featuresOnly.hasBundles(false));
assertFalse(featuresOnly.hasBundles(true));
assertFalse(featuresOnly.hasBundles());
}

@Test
public void testHasBundles() throws Exception {
ProductFile bundlesOnly = new ProductFile(TestData.getFile("ProductActionTest", "onlyBundles.product").toString());
assertFalse(bundlesOnly.hasFeatures());
assertTrue(bundlesOnly.hasBundles(false));
assertTrue(bundlesOnly.hasBundles(true));
assertTrue(bundlesOnly.hasBundles());
}

@Test
public void testHasFragments() throws Exception {
ProductFile bundlesOnly = new ProductFile(TestData.getFile("ProductActionTest", "onlyFragments.product").toString());
assertFalse(bundlesOnly.hasFeatures());
assertFalse(bundlesOnly.hasBundles(false));
assertTrue(bundlesOnly.hasBundles(true));
assertTrue(bundlesOnly.hasBundles());
}

/**
Expand Down

0 comments on commit b8b4f9d

Please sign in to comment.