Skip to content

Commit 63c3b29

Browse files
committed
extract command from incubator
Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
1 parent 042bfaf commit 63c3b29

122 files changed

Lines changed: 9969 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

converter.bundle/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
/generated/

converter.bundle/pom.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project xmlns="http://maven.apache.org/POM/4.0.0"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<parent>
18+
<groupId>org.eclipse.osgi-technology.command</groupId>
19+
<artifactId>command</artifactId>
20+
<version>0.0.1-SNAPSHOT</version>
21+
</parent>
22+
<artifactId>converter.bundle</artifactId>
23+
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.slf4j</groupId>
28+
<artifactId>slf4j-api</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.osgi</groupId>
32+
<artifactId>org.osgi.util.tracker</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.apache.felix</groupId>
36+
<artifactId>org.apache.felix.gogo.runtime</artifactId>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.osgi</groupId>
41+
<artifactId>org.osgi.resource</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.osgi</groupId>
45+
<artifactId>org.osgi.dto</artifactId>
46+
<version>1.1.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.osgi</groupId>
50+
<artifactId>org.osgi.framework</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.osgi</groupId>
55+
<artifactId>org.osgi.annotation.bundle</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.osgi</groupId>
60+
<artifactId>org.osgi.annotation.versioning</artifactId>
61+
<version>1.1.2</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.eclipse.osgi-technology.command</groupId>
65+
<artifactId>util</artifactId>
66+
<version>0.0.1-SNAPSHOT</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.eclipse.osgi-technology.console</groupId>
70+
<artifactId>plain</artifactId>
71+
<version>0.0.1-SNAPSHOT</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.junit.jupiter</groupId>
76+
<artifactId>junit-jupiter</artifactId>
77+
<version>5.12.1</version>
78+
<scope>test</scope>
79+
</dependency>
80+
81+
</dependencies>
82+
83+
<build>
84+
85+
<plugins>
86+
<plugin>
87+
<groupId>biz.aQute.bnd</groupId>
88+
<artifactId>bnd-maven-plugin</artifactId>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
</project>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
* All rights reserved.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Stefan Bischof - initial
13+
*/
14+
package org.eclipse.osgi.technology.command.converter.bundle;
15+
16+
import java.util.Hashtable;
17+
18+
import org.apache.felix.service.command.Converter;
19+
import org.osgi.annotation.bundle.Header;
20+
import org.osgi.framework.BundleActivator;
21+
import org.osgi.framework.BundleContext;
22+
import org.osgi.framework.Constants;
23+
import org.osgi.framework.ServiceRegistration;
24+
25+
@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
26+
@org.osgi.annotation.bundle.Capability(namespace = "org.apache.felix.gogo", name = "command.implementation", version = "1.0.0")
27+
@org.osgi.annotation.bundle.Requirement(effective = "active", namespace = "org.apache.felix.gogo", name = "runtime.implementation", version = "1.0.0")
28+
public class Activator implements BundleActivator {
29+
30+
private ServiceRegistration<Converter> reg;
31+
32+
@Override
33+
public void start(BundleContext context) throws Exception {
34+
var properties = new Hashtable<String, Object>();
35+
properties.put(Constants.SERVICE_RANKING, 10000);
36+
reg = context.registerService(Converter.class, new BundleConverter(context), properties);
37+
}
38+
39+
@Override
40+
public void stop(BundleContext context) throws Exception {
41+
if (reg != null) {
42+
reg.unregister();
43+
}
44+
}
45+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
* All rights reserved.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Stefan Bischof - initial
13+
*/
14+
15+
package org.eclipse.osgi.technology.command.converter.bundle;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
20+
import org.apache.felix.service.command.Converter;
21+
import org.eclipse.osgi.technology.command.util.GlobFilter;
22+
import org.osgi.framework.Bundle;
23+
import org.osgi.framework.BundleContext;
24+
25+
26+
@org.osgi.annotation.bundle.Capability(
27+
namespace = "osgi.commands",
28+
name = "converter.bundle",
29+
version = "1.0.0"
30+
)
31+
public class BundleConverter implements Converter {
32+
33+
private BundleContext context;
34+
35+
public BundleConverter(BundleContext context) {
36+
this.context = context;
37+
}
38+
39+
@Override
40+
public Object convert(Class<?> desiredType, Object sourceObject) throws Exception {
41+
if (desiredType == Bundle.class) {
42+
if (sourceObject instanceof Number n) {
43+
var bundle = context.getBundle(n.longValue());
44+
if (bundle != null) {
45+
return bundle;
46+
}
47+
} else if (sourceObject instanceof String sourceString) {
48+
try {
49+
var bundleId = Long.parseLong(sourceString);
50+
return context.getBundle(bundleId);
51+
} catch (Exception e) {
52+
53+
}
54+
55+
for (Bundle b : context.getBundles()) {
56+
57+
if (b.getSymbolicName().equals(sourceString)) {
58+
return b;
59+
}
60+
}
61+
62+
GlobFilter glob = new GlobFilter(sourceString);
63+
List<Bundle> matchingBundles = new ArrayList<>();
64+
for (Bundle b : context.getBundles()) {
65+
if (glob.matches(b.getSymbolicName())) {
66+
matchingBundles.add(b);
67+
}
68+
}
69+
70+
if (matchingBundles.size() == 1) {
71+
return matchingBundles.get(0);
72+
}
73+
}
74+
75+
}
76+
return null;
77+
}
78+
79+
@Override
80+
public CharSequence format(Object target, int level, Converter escape) throws Exception {
81+
return null;
82+
}
83+
84+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
* All rights reserved.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Stefan Bischof - initial
13+
*/
14+
package org.eclipse.osgi.technology.command.converter.bundle;
15+
16+
public class Test {
17+
18+
@org.junit.jupiter.api.Test
19+
void testName() throws Exception {
20+
21+
}
22+
}

converter.file/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
/generated/

converter.file/pom.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project xmlns="http://maven.apache.org/POM/4.0.0"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<parent>
18+
<groupId>org.eclipse.osgi-technology.command</groupId>
19+
<artifactId>command</artifactId>
20+
<version>0.0.1-SNAPSHOT</version>
21+
</parent>
22+
<artifactId>converter.file</artifactId>
23+
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.slf4j</groupId>
28+
<artifactId>slf4j-api</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.osgi</groupId>
32+
<artifactId>org.osgi.util.tracker</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.apache.felix</groupId>
36+
<artifactId>org.apache.felix.gogo.runtime</artifactId>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.osgi</groupId>
41+
<artifactId>org.osgi.resource</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.osgi</groupId>
45+
<artifactId>org.osgi.dto</artifactId>
46+
<version>1.1.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.osgi</groupId>
50+
<artifactId>org.osgi.framework</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.osgi</groupId>
55+
<artifactId>org.osgi.annotation.bundle</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.osgi</groupId>
60+
<artifactId>org.osgi.annotation.versioning</artifactId>
61+
<version>1.1.2</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.eclipse.osgi-technology.command</groupId>
65+
<artifactId>util</artifactId>
66+
<version>0.0.1-SNAPSHOT</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.eclipse.osgi-technology.console</groupId>
70+
<artifactId>plain</artifactId>
71+
<version>0.0.1-SNAPSHOT</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.junit.jupiter</groupId>
76+
<artifactId>junit-jupiter</artifactId>
77+
<version>5.12.1</version>
78+
<scope>test</scope>
79+
</dependency>
80+
81+
</dependencies>
82+
83+
<build>
84+
85+
<plugins>
86+
<plugin>
87+
<groupId>biz.aQute.bnd</groupId>
88+
<artifactId>bnd-maven-plugin</artifactId>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
* All rights reserved.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Stefan Bischof - initial
13+
*/
14+
package org.eclipse.osgi.technology.command.converter.file;
15+
16+
import java.util.Hashtable;
17+
18+
import org.apache.felix.service.command.Converter;
19+
import org.osgi.annotation.bundle.Header;
20+
import org.osgi.framework.BundleActivator;
21+
import org.osgi.framework.BundleContext;
22+
import org.osgi.framework.Constants;
23+
import org.osgi.framework.ServiceRegistration;
24+
25+
@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
26+
@org.osgi.annotation.bundle.Capability(namespace = "org.apache.felix.gogo", name = "command.implementation", version = "1.0.0")
27+
@org.osgi.annotation.bundle.Requirement(effective = "active", namespace = "org.apache.felix.gogo", name = "runtime.implementation", version = "1.0.0")
28+
public class Activator implements BundleActivator {
29+
30+
private ServiceRegistration<Converter> reg;
31+
32+
@Override
33+
public void start(BundleContext context) throws Exception {
34+
35+
var properties = new Hashtable<String, Object>();
36+
properties.put(Constants.SERVICE_RANKING, 10000);
37+
reg = context.registerService(Converter.class, new FileConverter(), properties);
38+
}
39+
40+
@Override
41+
public void stop(BundleContext context) throws Exception {
42+
if (reg != null) {
43+
reg.unregister();
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)