Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package org.eclipse.pde.ds.internal.annotations.tests;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.jar.Manifest;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
import org.junit.jupiter.api.Test;

@SuppressWarnings("restriction")
Expand Down Expand Up @@ -45,11 +43,14 @@ public void folderOSGIInfCreated() throws Exception {

@Test
public void manifestHeaderServiceComponentAdded() throws Exception {
IPluginModelBase pluginModel = PluginRegistry.findModel(testProject);
assertThat(pluginModel).isInstanceOf(IBundlePluginModelBase.class);
IBundleModel bundleModel = ((IBundlePluginModelBase) pluginModel).getBundleModel();
assertNotNull(bundleModel, "Missing bundle manifest!");
String serviceComponentHeader = bundleModel.getBundle().getHeader("Service-Component");
IFile manifestFile = testProject.getFile("META-INF/MANIFEST.MF");
manifestFile.refreshLocal(IResource.DEPTH_ZERO, null);
assertTrue(manifestFile.exists(), "Missing MANIFEST.MF!");
String serviceComponentHeader;
try (InputStream is = manifestFile.getContents(true)) {
Manifest manifest = new Manifest(is);
serviceComponentHeader = manifest.getMainAttributes().getValue("Service-Component");
}
assertNotNull(serviceComponentHeader, "Missing Service-Component header!");
String[] entries = serviceComponentHeader.split("\\s*,\\s*");
List<String> entryList = Arrays.asList(entries);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.eclipse.pde.ds.internal.annotations.tests;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -55,7 +54,8 @@ public void beforeAll(ExtensionContext context) throws Exception {
Job wsJob = new WorkspaceJob("Test Workspace Setup") {
@Override
public IStatus runInWorkspace(IProgressMonitor m) throws CoreException {
SubMonitor monitor = SubMonitor.convert(m, PROJECTS.size() * 8);
// Per project: create(1) + open(1) + 3*(build(2) + refresh(1)) = 11
SubMonitor monitor = SubMonitor.convert(m, PROJECTS.size() * 11);
// import test projects
Path wsRoot = ws.getRoot().getLocation().toPath();
for (Map.Entry<String, String> entry : PROJECTS.entrySet()) {
Expand All @@ -64,16 +64,17 @@ public IStatus runInWorkspace(IProgressMonitor m) throws CoreException {
Path projectLocation = Files.createDirectories(wsRoot.resolve(project.getName()));
copyResources(bundle, entry.getValue(), projectLocation);
Files.createDirectories(projectLocation.resolve("OSGI-INF"));
File projectFile = projectLocation.resolve("test.project").toFile();
if (projectFile.isFile()) {
projectFile.renameTo(projectLocation.resolve(".project").toFile());
Path projectFile = projectLocation.resolve("test.project");
if (Files.isRegularFile(projectFile)) {
Files.move(projectFile, projectLocation.resolve(".project"),
StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw new CoreException(Status.error("Error copying test project content.", e));
}
project.create(monitor.split(1));
project.open(monitor.split(1));
for (int i = 0; i < 2; i++) { // Build twice. Sometimes the setup is unstable
for (int i = 0; i < 3; i++) { // Annotation processor may need multiple builds to generate all outputs
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor.split(2));
project.refreshLocal(IResource.DEPTH_INFINITE, monitor.split(1));
}
Expand All @@ -84,6 +85,10 @@ public IStatus runInWorkspace(IProgressMonitor m) throws CoreException {

wsJob.schedule();
wsJob.join();
IStatus result = wsJob.getResult();
if (result != null && !result.isOK()) {
throw new CoreException(result);
}
}

@Override
Expand All @@ -97,7 +102,7 @@ public void afterAll(ExtensionContext context) throws Exception {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
for (String projectId : PROJECTS.keySet()) {
IProject project = wsRoot.getProject("ds.annotations." + projectId);
IProject project = wsRoot.getProject(projectId);
if (project.exists()) {
project.delete(true, true, monitor);
}
Expand Down
2 changes: 1 addition & 1 deletion ds/org.eclipse.pde.ds.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.pde.ds.core;singleton:=true
Bundle-Version: 1.3.900.qualifier
Bundle-Version: 1.3.1000.qualifier
Bundle-Activator: org.eclipse.pde.internal.ds.core.Activator
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.3.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public class DSComponent extends DSObject implements IDSComponent {
public DSComponent(DSModel model) {
super(model, ELEMENT_COMPONENT);
setAttributeName(IDSConstants.ELEMENT_COMPONENT);
setNamespace(IDSConstants.NAMESPACE); // hard code namespace to be 1.1
setNamespacePrefix("scr"); //$NON-NLS-1$
// Use super calls to set namespace defaults without firing property
// change events that would incorrectly mark the model as dirty
super.setNamespace(IDSConstants.NAMESPACE);
super.setNamespacePrefix("scr"); //$NON-NLS-1$
setInTheModel(true);
}

Expand Down
Loading