How to Embed wcm.io Context-Aware Configuration Editor

This blog article serves as your guide to seamlessly integrate and deploy the wcm.io Context-Aware Configuration Editor – a powerful tool that streamlines configuration management within AEM projects.

Throughout this article, we will delve into the step-by-step process of configuring, installing, embedding, and deploying the wcm.io Context-Aware Configuration Editor. By following these instructions, you’ll be able to harness the capabilities of this editor to automatically install configuration changes across all environments when your code is built via Maven and deployed to AEM. When it comes to deploying the wcm.io Context-Aware Configuration Editor, automation is key.


1. Add dependencies to parent pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<dependencyManagement>
  <dependencies>
    ...
    <dependency>
      <groupId>io.wcm</groupId>
      <artifactId>io.wcm.caconfig.editor.package</artifactId>
      <version>1.8.0</version>
      <type>zip</type>
    </dependency>
    <dependency>
      <groupId>io.wcm</groupId>
      <artifactId>io.wcm.caconfig.extensions</artifactId>
      <version>1.8.0</version>
    </dependency>
  </dependencies>

2. Add dependencies to your target maven module

In this example, we will target all/pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
<dependencies>
    ...
    <dependency>
        <groupId>io.wcm</groupId>
        <artifactId>io.wcm.caconfig.editor.package</artifactId>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>io.wcm</groupId>
        <artifactId>io.wcm.caconfig.extensions</artifactId>
    </dependency>
</dependencies>

3. Configure com.day.jcr.vault’s <embeded> to target maven module

In this example, we will target all/pom.xml, and yes, step 2 and 3 are configuration added to the same file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<plugins>
    <plugin>
        ...
        <groupId>com.day.jcr.vault</groupId>
        <artifactId>content-package-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <group>sourcedcode-packages</group>
            <filterSource>src/main/content/META-INF/vault/filter.xml</filterSource>
            <embeddeds>
                <embedded>
                    <groupId>io.wcm</groupId>
                    <artifactId>io.wcm.caconfig.editor.package</artifactId>
                    <type>zip</type>
                    <target>/apps/sourcedcode/install</target>
                </embedded>
                <embedded>
                    <groupId>io.wcm</groupId>
                    <artifactId>io.wcm.caconfig.extensions</artifactId>
                    <target>/apps/sourcedcode/install</target>
                </embedded>
            </embeddeds>
            <targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL>
        </configuration>
    </plugin>
</plugins>

4. Add template to create and manage wcm.io caConfigs

./ui.apps/src/main/content/jcr_root/apps/sourcedcode/templates/caconfig-template/content.xml

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
          jcr:primaryType="cq:Template"
          jcr:title="Context-Aware Configuration Page"
          allowedPaths="[^/content/sourcedcode(/.*)?$]"
          ranking="{Long}110">
    <jcr:content
            jcr:primaryType="cq:PageContent"
            sling:resourceType="wcm-io/caconfig/editor/components/page/editor"/>
</jcr:root>

5. Context-Aware Configuration bnd plugin

A bnd plugin is provided that scans the classpath of a bundle Maven project at build time and automatically generates a Sling-ContextAware-Configuration-Classes bundle header for all annotation classes annotated with @Configuration. It can be used by both maven-bundle-plugin and bnd-maven-plugin, as both use the bnd library internally.

Standard Configuration
Place the configuration from the root pom.xml as such:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <!-- Generate bundle header containing all configuration annotation classes -->
            <_plugin>org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin</_plugin>
        </instructions>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
            <version>1.0.2</version>
        </dependency>
    </dependencies>
</plugin>

If you use the bnd-maven-plugin and raw bnd statements, you have to configure it with this bnd statement:
Place the configuration from the root pom.xml as such:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<plugin>
    <groupId>biz.aQute.bnd</groupId>
    <artifactId>bnd-maven-plugin</artifactId>
    <configuration>
      <bnd><![CDATA[
            ...
          -plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin
      ]]></bnd>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
            <version>1.0.2</version>
        </dependency>
    </dependencies>
</plugin>

Sling Context Aware Configuration context-aware-configuration-bnd-plugin not working as expected
If both installations from the top are not working as expected, please try the configuration as below. Place the configuration from the root pom.xml as such. Take a look at line 21, where you can see we have kept org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin, org.apache.sling.bnd.models.ModelsScannerPlugin in one line of code, with a comma as the delimiter.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<plugin>
    <groupId>biz.aQute.bnd</groupId>
    <artifactId>bnd-maven-plugin</artifactId>
    <version>${bnd.version}</version>
    <executions>
        <execution>
            <id>bnd-process</id>
            <goals>
                <goal>bnd-process</goal>
            </goals>
            <configuration>
                <bnd><![CDATA[
Bundle-Category: ${componentGroupName}

# export all versioned packages except for conditional ones (https://github.com/bndtools/bnd/issues/3721#issuecomment-579026778)
-exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}}

...

Bundle-DocURL:
-plugin org.apache.sling.caconfig.bndplugin.ConfigurationClassScannerPlugin, org.apache.sling.bnd.models.ModelsScannerPlugin
                ]]>
                </bnd>
            </configuration>
        </execution>
    </executions>
    ...
</plugin>

Looking for Help? Or need a mentor?

If you need help to super drive your AEM career road map, you can hire me for a one-hour session on codementor.io; We can work together on a price works just for you. https://www.codementor.io/@briankasingli. I'd be happy to help you along your way to becoming a high-quality AEM full-stack engineer.

Was this post helpful?

Hello, I am an enthusiastic Adobe Community Advisor and a seasoned Lead AEM Developer. I am currently serving as an AEM Technical Lead at MNPDigital.ca, bringing over a decade of extensive web engineering experience and more than eight years of practical AEM experience to the table. My goal is to give back to the AEM Full Stack Development community by sharing my wealth of knowledge with others. You can connect with me on LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top