Skip to content
Merged
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
2 changes: 2 additions & 0 deletions converter.bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/generated/
93 changes: 93 additions & 0 deletions converter.bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*********************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.osgi-technology.command</groupId>
<artifactId>command</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>converter.bundle</artifactId>


<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.tracker</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.resource</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.dto</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.framework</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.bundle</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgi-technology.command</groupId>
<artifactId>util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgi-technology.console</groupId>
<artifactId>plain</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stefan Bischof - initial
*/
package org.eclipse.osgi.technology.command.converter.bundle;

import java.util.Hashtable;

import org.apache.felix.service.command.Converter;
import org.osgi.annotation.bundle.Header;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;

@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
@org.osgi.annotation.bundle.Capability(namespace = "org.apache.felix.gogo", name = "command.implementation", version = "1.0.0")
@org.osgi.annotation.bundle.Requirement(effective = "active", namespace = "org.apache.felix.gogo", name = "runtime.implementation", version = "1.0.0")
public class Activator implements BundleActivator {

private ServiceRegistration<Converter> reg;

@Override
public void start(BundleContext context) throws Exception {
var properties = new Hashtable<String, Object>();
properties.put(Constants.SERVICE_RANKING, 10000);
reg = context.registerService(Converter.class, new BundleConverter(context), properties);
}

@Override
public void stop(BundleContext context) throws Exception {
if (reg != null) {
reg.unregister();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stefan Bischof - initial
*/

package org.eclipse.osgi.technology.command.converter.bundle;

import java.util.ArrayList;
import java.util.List;

import org.apache.felix.service.command.Converter;
import org.eclipse.osgi.technology.command.util.GlobFilter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;


@org.osgi.annotation.bundle.Capability(
namespace = "osgi.commands",
name = "converter.bundle",
version = "1.0.0"
)
public class BundleConverter implements Converter {

private BundleContext context;

public BundleConverter(BundleContext context) {
this.context = context;
}

@Override
public Object convert(Class<?> desiredType, Object sourceObject) throws Exception {
if (desiredType == Bundle.class) {
if (sourceObject instanceof Number n) {
var bundle = context.getBundle(n.longValue());
if (bundle != null) {
return bundle;
}
} else if (sourceObject instanceof String sourceString) {
try {
var bundleId = Long.parseLong(sourceString);
return context.getBundle(bundleId);
} catch (Exception e) {

}

for (Bundle b : context.getBundles()) {

if (b.getSymbolicName().equals(sourceString)) {
return b;
}
}

GlobFilter glob = new GlobFilter(sourceString);
List<Bundle> matchingBundles = new ArrayList<>();
for (Bundle b : context.getBundles()) {
if (glob.matches(b.getSymbolicName())) {
matchingBundles.add(b);
}
}

if (matchingBundles.size() == 1) {
return matchingBundles.get(0);
}
}

}
return null;
}

@Override
public CharSequence format(Object target, int level, Converter escape) throws Exception {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stefan Bischof - initial
*/
package org.eclipse.osgi.technology.command.converter.bundle;

public class Test {

@org.junit.jupiter.api.Test
void testName() throws Exception {

}
}
2 changes: 2 additions & 0 deletions converter.file/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/generated/
93 changes: 93 additions & 0 deletions converter.file/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*********************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.osgi-technology.command</groupId>
<artifactId>command</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>converter.file</artifactId>


<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.util.tracker</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.resource</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.dto</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.framework</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.bundle</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgi-technology.command</groupId>
<artifactId>util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.osgi-technology.console</groupId>
<artifactId>plain</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2025 Contributors to the Eclipse Foundation
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stefan Bischof - initial
*/
package org.eclipse.osgi.technology.command.converter.file;

import java.util.Hashtable;

import org.apache.felix.service.command.Converter;
import org.osgi.annotation.bundle.Header;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;

@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
@org.osgi.annotation.bundle.Capability(namespace = "org.apache.felix.gogo", name = "command.implementation", version = "1.0.0")
@org.osgi.annotation.bundle.Requirement(effective = "active", namespace = "org.apache.felix.gogo", name = "runtime.implementation", version = "1.0.0")
public class Activator implements BundleActivator {

private ServiceRegistration<Converter> reg;

@Override
public void start(BundleContext context) throws Exception {

var properties = new Hashtable<String, Object>();
properties.put(Constants.SERVICE_RANKING, 10000);
reg = context.registerService(Converter.class, new FileConverter(), properties);
}

@Override
public void stop(BundleContext context) throws Exception {
if (reg != null) {
reg.unregister();
}
}
}
Loading
Loading