Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a custom feature

Tags:

wso2

We would like to write our own custom extension (feature) for wso2 carbon. Is there some documentation for authoring features?

We did manage to just "hack" our way into writing a custom feature. But how do we host it? It seems Carbon is looking at some very specific repository descriptors - artifacts.jar and content.jar

How can we generate these descriptors without tying into the Carbon build. Is there some documentation describing how to setup a third party feature repository?

like image 625
puzz_10 Avatar asked Nov 13 '22 10:11

puzz_10


1 Answers

Creating-your-own-wso2-carbon-components webinar discusses creating carbon components, and a feature for those components. It covers quite a lot of basics, and best practices as well.

To host the created features you have written, you need to generate a p2-repository from those features. p2-repo concept comes from the underline Eclipse equinox project that WSO2 products use.

WSO2 have written its own maven plugin called carbon-p2-plugin that helps to generate a p2-repo. Here's how you can do that. Simply create a new maven project (packaging: pom), and then set the features you want to publish under the carbon-p2-plugin plugin configuration. Following is a sample pom.xml that you can use. This was copied from the p2-repo generation pom.xml of carbon 4.1.0, and I simplified it.

I have tested this pom file, it worked for me. There are two sample feature definitions. Replace those featureArtifactDef with your own feature definitions. The format is $groupId:$artifactId:$version.

When you build this via maven, maven creates the target/p2-repo directory. This contains the p2-repository which contains the complete p2-repo including artifacts.jar and content.jar. You can just use this folder to install features, or you can host it somewhere. There're no special requirements on hosting.

<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/maven-v4_0_0.xsd">

    <parent>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>carbon-features</artifactId>
        <version>4.1.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>mysample-feature-repository</artifactId>
    <version>4.1.0</version>
    <packaging>pom</packaging>
    <name>WSO2 Carbon - Feature Repository</name>

    <build>
      <plugins>
        <plugin>
          <groupId>org.wso2.maven</groupId>
            <artifactId>carbon-p2-plugin</artifactId>
            <version>1.5.2</version>
            <executions>
              <execution>
                <id>2-p2-repo-generation</id>
                <phase>package</phase>
                <goals>
                  <goal>p2-repo-gen</goal>
                 </goals>
                 <configuration>
                   <p2AgentLocation>${basedir}/target/p2-agent</p2AgentLocation>
                   <metadataRepository>file:${basedir}/target/p2-repo</metadataRepository>
                   <artifactRepository>file:${basedir}/target/p2-repo</artifactRepository>
                   <publishArtifacts>true</publishArtifacts>
                   <publishArtifactRepository>true</publishArtifactRepository>
                   <featureArtifacts> 

<!-- change the featureArtifactDef to match your needs -->

                      <featureArtifactDef>
                                    org.wso2.carbon:org.wso2.carbon.service.mgt.feature:4.1.0
                      </featureArtifactDef>
                      <featureArtifactDef>
                                    org.wso2.carbon:org.wso2.carbon.registry.core.feature:4.1.0
                      </featureArtifactDef>


               </featureArtifacts>
             </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
like image 182
Kasun Gajasinghe Avatar answered Dec 25 '22 23:12

Kasun Gajasinghe