Skip to content

Commit 9b98d92

Browse files
fix(kura-addon-archetype): Fixed target-platform and added unit test example. (#5767)
* fixed target platform and added unit test * fix all * fixed copyright plate * fixed copyright plate * copytighy * removed unecessary required bundle * Added mock example * fixed kura.service.pid
1 parent 9828224 commit 9b98d92

File tree

18 files changed

+550
-52
lines changed

18 files changed

+550
-52
lines changed

kura/tools/kura-addon-archetype/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3+
34
Copyright (c) 2025 Eurotech and/or its affiliates and others
4-
5+
56
This program and the accompanying materials are made
67
available under the terms of the Eclipse Public License 2.0
78
which is available at https://www.eclipse.org/legal/epl-2.0/
8-
9+
910
SPDX-License-Identifier: EPL-2.0
1011
1112
Contributors:
1213
Eurotech
14+
1315
-->
14-
<project xmlns="http://maven.apache.org/POM/4.0.0"
15-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1717
<modelVersion>4.0.0</modelVersion>
1818

1919
<parent>
@@ -42,7 +42,6 @@
4242
</resource>
4343
<resource>
4444
<directory>src/main/resources</directory>
45-
<filtering>false</filtering>
4645
<excludes>
4746
<exclude>archetype-resources/test/test-env/framework/kura.properties</exclude>
4847
<exclude>META-INF/maven/archetype-metadata.xml</exclude>
@@ -106,6 +105,7 @@
106105
</execution>
107106
</executions>
108107
</plugin>
108+
109109
</plugins>
110110
</build>
111111

kura/tools/kura-addon-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<excludes>
5959
<exclude>**/*.java</exclude>
6060
<exclude>**/src/main/java/test</exclude>
61+
<exclude>**/src/test/java/test</exclude>
6162
</excludes>
6263
</fileSet>
6364
<fileSet filtered="true" packaged="true">
@@ -66,6 +67,9 @@
6667
<fileSet filtered="true" packaged="true">
6768
<directory>tests/__artifactId__.bundle.test/src/main/java</directory>
6869
</fileSet>
70+
<fileSet filtered="true" packaged="true">
71+
<directory>tests/__artifactId__.bundle.test/src/test/java</directory>
72+
</fileSet>
6973
<fileSet encoding="UTF-8">
7074
<directory></directory>
7175
<includes>

kura/tools/kura-addon-archetype/src/main/resources/archetype-resources/bundles/__artifactId__.bundle/src/main/java/ExampleComponent.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,30 @@
2020
import org.osgi.service.component.annotations.ConfigurationPolicy;
2121
import org.osgi.service.component.annotations.Deactivate;
2222
import org.osgi.service.component.annotations.Modified;
23+
import org.osgi.service.component.annotations.Reference;
2324
import org.osgi.service.metatype.annotations.Designate;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
2627

2728
@Component(immediate = true, //
28-
configurationPolicy = ConfigurationPolicy.REQUIRE, //
29-
property = {"kura.service.pid=${package}.ExampleComponent"} //
29+
configurationPolicy = ConfigurationPolicy.REQUIRE, //
30+
property = { "kura.service.pid=${package}.ExampleComponent" } //
3031
)
3132
@Designate(ocd = ExampleComponentOCD.class, factory = false)
3233
public class ExampleComponent implements ConfigurableComponent {
3334

3435
private static final Logger logger = LoggerFactory.getLogger(ExampleComponent.class);
3536

37+
private ExampleComponentOptions options;
38+
39+
@Reference
40+
private ExampleDependencyService exampleDependencyService;
41+
42+
@Reference
43+
public void setExampleDependencyService(ExampleDependencyService exampleDependencyService) {
44+
this.exampleDependencyService = exampleDependencyService;
45+
}
46+
3647
/*
3748
* In the in activate, modified, deactivate methods it is possible to provide
3849
* the ComponentContext and the ExampleComponentOCD as parameters.
@@ -42,8 +53,9 @@ public class ExampleComponent implements ConfigurableComponent {
4253
* Examples:
4354
*
4455
* public void activate()
45-
* public void activate(ExampleComponentOCD configuration)
46-
* public void activate(ComponentContext componentContext, final Map<String, Object> properties, final ExampleComponentOCD configuration)
56+
* public void activate(ExampleComponentOCD configuration)
57+
* public void activate(ComponentContext componentContext, final Map<String, Object> properties, final
58+
* ExampleComponentOCD configuration)
4759
*/
4860
@Activate
4961
public void activate(final Map<String, Object> properties) {
@@ -59,7 +71,9 @@ public void updated(final Map<String, Object> properties) {
5971
logger.info("Updating");
6072

6173
logger.debug("Updating with properties: {}", properties);
62-
ExampleComponentOptions options = new ExampleComponentOptions(properties);
74+
this.options = new ExampleComponentOptions(properties);
75+
76+
this.exampleDependencyService.run();
6377

6478
logger.info("Updated");
6579
}
@@ -70,4 +84,8 @@ public synchronized void deactivate() {
7084
logger.info("Deactivated");
7185
}
7286

87+
public ExampleComponentOptions getOptions() {
88+
return this.options;
89+
}
90+
7391
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/*******************************************************************************
22
* Copyright (c) 2025 Eurotech and/or its affiliates and others
3-
*
3+
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
66
* which is available at https://www.eclipse.org/legal/epl-2.0/
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
9-
*
9+
*
1010
* Contributors:
1111
* Eurotech
1212
*******************************************************************************/
1313
package ${package};
1414

1515
import java.util.Map;
1616

17-
class ExampleComponentOptions {
17+
public class ExampleComponentOptions {
1818

1919
private static final Property<String> EXAMPLE_PROPERTY = new Property<>("example.property", "example");
2020

@@ -25,7 +25,7 @@ public ExampleComponentOptions(final Map<String, Object> properties) {
2525
}
2626

2727
public String getExampleProperty() {
28-
return exampleProperty;
28+
return this.exampleProperty;
2929
}
3030

3131
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Eurotech and/or its affiliates and others
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Eurotech
12+
*******************************************************************************/
13+
package ${package};
14+
15+
public interface ExampleDependencyService {
16+
17+
public void run();
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Eurotech and/or its affiliates and others
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Eurotech
12+
*******************************************************************************/
13+
package ${package};
14+
15+
import org.osgi.service.component.annotations.Component;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
@Component(service = ExampleDependencyService.class, immediate = true)
20+
public class ExampleDependencyServiceComponent implements ExampleDependencyService {
21+
22+
private static final Logger logger = LoggerFactory.getLogger(ExampleDependencyServiceComponent.class);
23+
24+
@Override
25+
public void run() {
26+
logger.info("Running ExampleDependencyServiceComponent");
27+
}
28+
29+
}

kura/tools/kura-addon-archetype/src/main/resources/archetype-resources/bundles/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<tycho-version>4.0.11</tycho-version>
3939
<bnd-version>7.1.0</bnd-version>
4040
<maven-resources-version>3.1.0</maven-resources-version>
41+
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
4142
<maven-deploy-version>2.8.2</maven-deploy-version>
4243
<antrun-version>1.8</antrun-version>
4344
<exists-version>0.0.6</exists-version>

0 commit comments

Comments
 (0)