Skip to content

Commit

Permalink
Add support for higher DS versions
Browse files Browse the repository at this point in the history
Currently PDE only support versions up to DS 1.3 but 1.4 has some major
improvements.

This adds the necessary support and the official TCK from the OSGi
specification to support DS 1.4 features in PDE.

See eclipse-pde#36
Fix eclipse-pde#191
Fix eclipse-pde#219
  • Loading branch information
laeubi committed Nov 29, 2023
1 parent 20bc28b commit 6af5b30
Show file tree
Hide file tree
Showing 29 changed files with 1,487 additions and 302 deletions.
1 change: 1 addition & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-Pbuild-individual-bundles
-Ptck
-Dcompare-version-with-baselines.skip=false
-DtrimStackTrace=false
--fail-at-end
12 changes: 11 additions & 1 deletion ds/org.eclipse.pde.ds.annotations/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="bin_test" path="src_test">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion ds/org.eclipse.pde.ds.annotations/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: %Bundle-Name
Bundle-SymbolicName: org.eclipse.pde.ds.annotations;singleton:=true
Bundle-Version: 1.3.100.qualifier
Bundle-Version: 1.3.200.qualifier
Bundle-Activator: org.eclipse.pde.ds.internal.annotations.Activator
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.ui;bundle-version="[3.105.0,4.0.0)",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2023 Christoph Läubrich and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.ds.internal.annotations;

import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;

/**
* This capture the context of an <code>@Activate</code> annotated method or
* field binding
*/
record ComponentActivationAnnotation(String activate, Annotation annotation, MethodDeclaration method,
IBinding binding) {

public boolean isMethod() {
if (binding instanceof IMethodBinding method) {
return !((IMethodBinding) binding).isConstructor();
}
return false;
}

public boolean isConstructor() {
if (binding instanceof IMethodBinding method) {
return ((IMethodBinding) binding).isConstructor();
}
return false;
}

public boolean isType() {
return binding instanceof ITypeBinding method;
}

public int parameterCount() {
if (binding instanceof IMethodBinding method) {
return method.getParameterNames().length;
}
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.pde.ds.internal.annotations;

import java.util.Arrays;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
Expand All @@ -27,9 +28,16 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.dialogs.ControlEnableState;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.layout.LayoutConstants;
import org.eclipse.jface.preference.IPreferencePageContainer;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
Expand Down Expand Up @@ -74,7 +82,7 @@ public class DSAnnotationPropertyPage extends PropertyPage implements IWorkbench

private Text pathText;

private Combo specVersionCombo;
private ComboViewer specVersionCombo;

private Combo errorLevelCombo;

Expand Down Expand Up @@ -232,12 +240,36 @@ public void widgetSelected(SelectionEvent e) {
specVersionLabel.setText(Messages.DSAnnotationPropertyPage_specVersionLabel_text);
specVersionLabel.setFont(JFaceResources.getDialogFont());

specVersionCombo = new Combo(optionBlockControl, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
specVersionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
specVersionCombo.setFont(JFaceResources.getDialogFont());
specVersionCombo.add("1.3"); //$NON-NLS-1$
specVersionCombo.add("1.2"); //$NON-NLS-1$
specVersionCombo.select(0);
specVersionCombo = new ComboViewer(optionBlockControl, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
specVersionCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
specVersionCombo.getControl().setFont(JFaceResources.getDialogFont());
specVersionCombo.setContentProvider(ArrayContentProvider.getInstance());
specVersionCombo.setInput(List.of(DSAnnotationVersion.V1_2, DSAnnotationVersion.V1_3, DSAnnotationVersion.V1_4,
DSAnnotationVersion.V1_4));
specVersionCombo.setSelection(new StructuredSelection(DSAnnotationVersion.V1_5));
specVersionCombo.addSelectionChangedListener(new ISelectionChangedListener() {

@Override
public void selectionChanged(SelectionChangedEvent event) {
DSAnnotationVersion version = (DSAnnotationVersion) event.getStructuredSelection().getFirstElement();
if (version == DSAnnotationVersion.V1_5) {
setMessage("Specification version " + version.getSpecificationVersion()
+ " is currently not fully supported.", DialogPage.WARNING);
} else {
setMessage(null);
}

}
});
specVersionCombo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof DSAnnotationVersion version) {
return version.getSpecificationVersion();
}
return "";
}
});

Label errorLevelLabel = new Label(optionBlockControl, SWT.LEFT);
errorLevelLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Expand Down Expand Up @@ -279,7 +311,7 @@ private void refreshWidgets() {

boolean enableValue = prefs.getBoolean(Activator.PREF_ENABLED, false);
String pathValue = prefs.get(Activator.PREF_PATH, Activator.DEFAULT_PATH);
String specVersion = prefs.get(Activator.PREF_SPEC_VERSION, DSAnnotationVersion.V1_3.name());
String specVersion = prefs.get(Activator.PREF_SPEC_VERSION, DSAnnotationVersion.V1_4.name());
String errorLevel = prefs.get(Activator.PREF_VALIDATION_ERROR_LEVEL, ValidationErrorLevel.error.name());
String missingUnbindMethodLevel = prefs.get(Activator.PREF_MISSING_UNBIND_METHOD_ERROR_LEVEL, errorLevel);
boolean generateBAPL = prefs.getBoolean(Activator.PREF_GENERATE_BAPL, true);
Expand All @@ -303,10 +335,10 @@ private void refreshWidgets() {
try {
specVersionEnum = DSAnnotationVersion.valueOf(specVersion);
} catch (IllegalArgumentException e) {
specVersionEnum = DSAnnotationVersion.V1_3;
specVersionEnum = DSAnnotationVersion.V1_4;
}

specVersionCombo.select(DSAnnotationVersion.V1_3.ordinal() - specVersionEnum.ordinal());
specVersionCombo.setSelection(new StructuredSelection(specVersionEnum));
errorLevelCombo.select(getEnumIndex(errorLevel, ValidationErrorLevel.values(), 0));
missingUnbindMethodCombo.select(getEnumIndex(missingUnbindMethodLevel, ValidationErrorLevel.values(), 0));
enableBAPLGeneration.setSelection(generateBAPL);
Expand Down Expand Up @@ -443,9 +475,9 @@ public boolean performOk() {
prefs.putBoolean(Activator.PREF_ENABLED, enableCheckbox.getSelection());
prefs.put(Activator.PREF_PATH, IPath.fromOSString(path).toString());

DSAnnotationVersion[] versions = DSAnnotationVersion.values();
int specVersionIndex = Math.max(Math.min(specVersionCombo.getSelectionIndex(), DSAnnotationVersion.V1_3.ordinal()), 0);
prefs.put(Activator.PREF_SPEC_VERSION, versions[DSAnnotationVersion.V1_3.ordinal() - specVersionIndex].name());
DSAnnotationVersion version = (DSAnnotationVersion) specVersionCombo.getStructuredSelection()
.getFirstElement();
prefs.put(Activator.PREF_SPEC_VERSION, version.name());

ValidationErrorLevel[] levels = ValidationErrorLevel.values();
int errorLevelIndex = errorLevelCombo.getSelectionIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
@SuppressWarnings("restriction")
public enum DSAnnotationVersion {

V1_1(IDSConstants.NAMESPACE),
V1_0("1.0", "http://www.osgi.org/xmlns/scr/v1.0.0"),

V1_2("http://www.osgi.org/xmlns/scr/v1.2.0"), //$NON-NLS-1$
V1_1("1.1", IDSConstants.NAMESPACE),

V1_3("http://www.osgi.org/xmlns/scr/v1.3.0"); //$NON-NLS-1$
V1_2("1.2", "http://www.osgi.org/xmlns/scr/v1.2.0"), //$NON-NLS-1$

V1_3("1.3", "http://www.osgi.org/xmlns/scr/v1.3.0"), //$NON-NLS-1$

V1_4("1.4", "http://www.osgi.org/xmlns/scr/v1.4.0"), //$NON-NLS-1$

V1_5("1.5", "http://www.osgi.org/xmlns/scr/v1.5.0"); //$NON-NLS-1$

private final String namespace;
private String version;

private DSAnnotationVersion(String namespace) {
private DSAnnotationVersion(String version, String namespace) {
this.version = version;
this.namespace = namespace;
}

Expand All @@ -42,6 +50,16 @@ public DSAnnotationVersion max(DSAnnotationVersion other) {
return this;
}

/**
* Compares this version with another one
*
* @param other
* @return true if this version is higher or equal to this version
*/
public boolean isEqualOrHigherThan(DSAnnotationVersion other) {
return other.compareTo(this) >= 0;
}

public static DSAnnotationVersion fromNamespace(String namespace) {
for (DSAnnotationVersion value : values()) {
if (value.namespace.equals(namespace)) {
Expand All @@ -51,4 +69,13 @@ public static DSAnnotationVersion fromNamespace(String namespace) {

return null;
}

public String getSpecificationVersion() {
return version;
}

@Override
public String toString() {
return version + " - " + namespace;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public class DSEnums {
"UPDATE", "update", //
"REPLACE", "replace");

public static final Map<String, String> COLLECTION_TYPE_OPTION = Map.of( //
"SERVICE", "service", //
"REFERENCE", "reference", //
"SERVICEOBJECTS", "serviceobjects", //
"PROPERTIES", "properties", //
"TUPLE", "tuple");

private DSEnums() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ public class Messages extends NLS {

public static String AnnotationProcessor_invalidComponentImplementationClass;

public static String AnnotationProcessor_invalidCompImplClass_compatibleConstructor;

public static String AnnotationProcessor_invalidComponentName;

public static String AnnotationProcessor_invalidActivate;

public static String AnnotationProcessor_invalidActivateField;

public static String AnnotationProcessor_invalidConstructorArgument;

public static String AnnotationProcessor_invalidComponentProperty_nameRequired;

public static String AnnotationProcessor_invalidComponentProperty_valueRequired;
Expand All @@ -73,6 +81,8 @@ public class Messages extends NLS {

public static String AnnotationProcessor_invalidComponentService;

public static String AnnotationProcessor_invalidLifecycleMethod_noMethod;

public static String AnnotationProcessor_invalidLifecycleMethod_static;

public static String AnnotationProcessor_invalidLifeCycleMethodParameterType;
Expand Down Expand Up @@ -115,6 +125,8 @@ public class Messages extends NLS {

public static String AnnotationProcessor_invalidReference_staticField;

public static String AnnotationProcessor_invalidActivate_staticField;

public static String AnnotationProcessor_invalidReference_serviceType;

public static String AnnotationProcessor_invalidReference_serviceUnknown;
Expand Down
Loading

0 comments on commit 6af5b30

Please sign in to comment.