Skip to content

Commit 71af12b

Browse files
authored
Fix manifestHeaderServiceComponentAdded test on macOS and Windows
Fix manifestHeaderServiceComponentAdded test to read MANIFEST.MF directly The test was using PluginRegistry.findModel() which returns a cached in-memory model that may not reflect the updated MANIFEST.MF after the DS annotation builder writes the Service-Component header. On macOS and Windows, the model manager's resource change event processing can lag behind the file changes, causing the test to read stale data. Fix by reading the MANIFEST.MF file directly using java.util.jar.Manifest, with refreshLocal() before reading, consistent with how other DS annotation tests (AnnotationProcessorTest) read their test files.
1 parent ea4a2cf commit 71af12b

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

ds/org.eclipse.pde.ds.annotations.tests/src/org/eclipse/pde/ds/internal/annotations/tests/ManagedProjectTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
package org.eclipse.pde.ds.internal.annotations.tests;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
43
import static org.junit.jupiter.api.Assertions.assertEquals;
54
import static org.junit.jupiter.api.Assertions.assertNotNull;
65
import static org.junit.jupiter.api.Assertions.assertTrue;
76

7+
import java.io.InputStream;
88
import java.util.Arrays;
99
import java.util.List;
10+
import java.util.jar.Manifest;
1011

1112
import org.eclipse.core.resources.ICommand;
13+
import org.eclipse.core.resources.IFile;
1214
import org.eclipse.core.resources.IMarker;
1315
import org.eclipse.core.resources.IResource;
14-
import org.eclipse.pde.core.plugin.IPluginModelBase;
15-
import org.eclipse.pde.core.plugin.PluginRegistry;
1616
import org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant;
17-
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
18-
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
1917
import org.junit.jupiter.api.Test;
2018

2119
@SuppressWarnings("restriction")
@@ -45,11 +43,14 @@ public void folderOSGIInfCreated() throws Exception {
4543

4644
@Test
4745
public void manifestHeaderServiceComponentAdded() throws Exception {
48-
IPluginModelBase pluginModel = PluginRegistry.findModel(testProject);
49-
assertThat(pluginModel).isInstanceOf(IBundlePluginModelBase.class);
50-
IBundleModel bundleModel = ((IBundlePluginModelBase) pluginModel).getBundleModel();
51-
assertNotNull(bundleModel, "Missing bundle manifest!");
52-
String serviceComponentHeader = bundleModel.getBundle().getHeader("Service-Component");
46+
IFile manifestFile = testProject.getFile("META-INF/MANIFEST.MF");
47+
manifestFile.refreshLocal(IResource.DEPTH_ZERO, null);
48+
assertTrue(manifestFile.exists(), "Missing MANIFEST.MF!");
49+
String serviceComponentHeader;
50+
try (InputStream is = manifestFile.getContents(true)) {
51+
Manifest manifest = new Manifest(is);
52+
serviceComponentHeader = manifest.getMainAttributes().getValue("Service-Component");
53+
}
5354
assertNotNull(serviceComponentHeader, "Missing Service-Component header!");
5455
String[] entries = serviceComponentHeader.split("\\s*,\\s*");
5556
List<String> entryList = Arrays.asList(entries);

0 commit comments

Comments
 (0)