Skip to content

Commit 3cef3f3

Browse files
committed
Add ISystemInformation.Section OSGi component property type
This annotation simplifies the specification of the 'section' service property for ISystemInformation implementations and makes it more robust: ''' @component(service = ISystemInformation.class) @ISystemInformation.Section(AboutSections.SECTION_SYSTEM_PROPERTIES) public class ExampleInformation implements ISystemInformation { '''
1 parent 9fb5a7d commit 3cef3f3

File tree

8 files changed

+44
-30
lines changed

8 files changed

+44
-30
lines changed

runtime/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bundle-SymbolicName: org.eclipse.e4.core.services;singleton:=true
44
Bundle-Name: %pluginName
55
Bundle-Vendor: %providerName
66
Bundle-Localization: plugin
7-
Bundle-Version: 2.4.500.qualifier
7+
Bundle-Version: 2.5.0.qualifier
88
Bundle-ActivationPolicy: lazy
99
Bundle-RequiredExecutionEnvironment: JavaSE-17
1010
Import-Package: jakarta.annotation;version="[2.0.0,3.0.0)",

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/about/InstalledBundles.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2020 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -27,7 +27,8 @@
2727
import org.osgi.framework.FrameworkUtil;
2828
import org.osgi.service.component.annotations.Component;
2929

30-
@Component(service = { ISystemInformation.class }, property = { AboutSections.SECTION + '=' + AboutSections.SECTION_INSTALLED_BUNDLES })
30+
@Component(service = ISystemInformation.class)
31+
@ISystemInformation.Section(AboutSections.SECTION_INSTALLED_BUNDLES)
3132
public class InstalledBundles implements ISystemInformation {
3233

3334
@Override
@@ -71,21 +72,14 @@ private Comparator<Bundle> createComparator(Map<String, String> names) {
7172
}
7273

7374
private String getStateName(int state) {
74-
switch (state) {
75-
case Bundle.INSTALLED:
76-
return AboutMessages.bundleStateInstalled;
77-
case Bundle.RESOLVED:
78-
return AboutMessages.bundleStateResolved;
79-
case Bundle.STARTING:
80-
return AboutMessages.bundleStateStarting;
81-
case Bundle.STOPPING:
82-
return AboutMessages.bundleStateStopping;
83-
case Bundle.UNINSTALLED:
84-
return AboutMessages.bundleStateUninstalled;
85-
case Bundle.ACTIVE:
86-
return AboutMessages.bundleStateActive;
87-
default:
88-
return AboutMessages.bundleStateUnknown;
89-
}
75+
return switch (state) {
76+
case Bundle.INSTALLED -> AboutMessages.bundleStateInstalled;
77+
case Bundle.RESOLVED -> AboutMessages.bundleStateResolved;
78+
case Bundle.STARTING -> AboutMessages.bundleStateStarting;
79+
case Bundle.STOPPING -> AboutMessages.bundleStateStopping;
80+
case Bundle.UNINSTALLED -> AboutMessages.bundleStateUninstalled;
81+
case Bundle.ACTIVE -> AboutMessages.bundleStateActive;
82+
default -> AboutMessages.bundleStateUnknown;
83+
};
9084
}
9185
}

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/about/InstalledFeatures.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -29,7 +29,8 @@
2929
import org.osgi.service.component.annotations.Reference;
3030
import org.osgi.service.component.annotations.ReferenceCardinality;
3131

32-
@Component(service = { ISystemInformation.class }, property = { AboutSections.SECTION + '=' + AboutSections.SECTION_INSTALLED_FEATURES })
32+
@Component(service = ISystemInformation.class)
33+
@ISystemInformation.Section(AboutSections.SECTION_INSTALLED_FEATURES)
3334
public class InstalledFeatures implements ISystemInformation {
3435

3536
private final List<IBundleGroupProvider> providers = new ArrayList<>();

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/about/SystemEnvironment.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,7 +18,8 @@
1818
import org.eclipse.e4.core.services.about.ISystemInformation;
1919
import org.osgi.service.component.annotations.Component;
2020

21-
@Component(service = { ISystemInformation.class }, property = { AboutSections.SECTION + '=' + AboutSections.SECTION_SYSTEM_ENVIRONMENT })
21+
@Component(service = ISystemInformation.class)
22+
@ISystemInformation.Section(AboutSections.SECTION_SYSTEM_ENVIRONMENT)
2223
public class SystemEnvironment extends PrintedMap {
2324

2425
@Override

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/about/SystemProperties.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -19,7 +19,8 @@
1919
import org.eclipse.e4.core.services.about.ISystemInformation;
2020
import org.osgi.service.component.annotations.Component;
2121

22-
@Component(service = { ISystemInformation.class }, property = { AboutSections.SECTION + '=' + AboutSections.SECTION_SYSTEM_PROPERTIES })
22+
@Component(service = ISystemInformation.class)
23+
@ISystemInformation.Section(AboutSections.SECTION_SYSTEM_PROPERTIES)
2324
public class SystemProperties extends PrintedMap {
2425

2526
@Override

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/about/UserPreferences.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -28,7 +28,8 @@
2828
import org.osgi.service.component.annotations.Component;
2929
import org.osgi.service.component.annotations.Reference;
3030

31-
@Component(service = { ISystemInformation.class }, property = { AboutSections.SECTION + '=' + AboutSections.SECTION_USER_PREFERENCES })
31+
@Component(service = ISystemInformation.class)
32+
@ISystemInformation.Section(AboutSections.SECTION_USER_PREFERENCES)
3233
public class UserPreferences implements ISystemInformation {
3334

3435
private IPreferencesService preferencesService;

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/about/AboutSections.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -69,7 +69,7 @@ public final class AboutSections {
6969
* @return the section filter string
7070
*/
7171
public static String createSectionFilter(String section) {
72-
return new StringBuilder().append('(').append(SECTION).append('=').append(section).append(')').toString();
72+
return '(' + SECTION + '=' + section + ')';
7373
}
7474

7575
}

runtime/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/about/ISystemInformation.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 ArSysOp and others.
2+
* Copyright (c) 2019, 2024 ArSysOp and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,9 @@
1414
package org.eclipse.e4.core.services.about;
1515

1616
import java.io.PrintWriter;
17+
import java.lang.annotation.ElementType;
18+
import java.lang.annotation.Target;
19+
import org.osgi.service.component.annotations.ComponentPropertyType;
1720

1821
/**
1922
* Collects the system information for the "about"-related functionality.
@@ -31,4 +34,17 @@ public interface ISystemInformation {
3134
*/
3235
void append(PrintWriter writer);
3336

37+
/**
38+
* An OSGi service component property type to define the information to be
39+
* related with the specified section.
40+
*
41+
* @since 2.5
42+
* @see #SECTION
43+
*/
44+
@ComponentPropertyType
45+
@Target(ElementType.TYPE)
46+
public @interface Section {
47+
String value();
48+
}
49+
3450
}

0 commit comments

Comments
 (0)