Skip to content

Commit ed4d191

Browse files
authored
Include bundled scripts - #765
* added support for precompiling and bundling the scripts from ui.apps into an OSGi bundle that get attached as a secondary artifact (fixes #765)
1 parent d84c9a5 commit ed4d191

File tree

21 files changed

+184
-2
lines changed

21 files changed

+184
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Name | Default | Description
9090
`amp` | `n` | Enable [AMP](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/amp.html) support for genenerated project templates.
9191
`enableDynamicMedia` | `n` | Enabled foundation DynamicMedia components in project policy settings and activates Dynamic Media features in Core Image component's policy.
9292
`enableSSR` | `n` | Option to enable SSR for the front-end project
93+
`precompiledScripts` | `n` | Option to [precompile](https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/archetype/precompiled-bundled-scripts.html) the server-side scripts from `ui.apps` and attach them to the build as a secondary bundle artifact in the `ui.apps` project. `aemVersion` should be set to `cloud`.
9394

9495
## System Requirements
9596

VERSIONS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ Archetype Version | AEM Version
1919
19 | 6.5, 6.4, 6.3 + SP3
2020
20, 21, 22 | 6.5, 6.4, 6.3 + SP3
2121
23 | 6.5, 6.4, 6.3 + SP3, AEM as a Cloud Service
22-
24,25,26, 27 | 6.5.5, 6.4.8.1, AEM as a Cloud Service
23-
28 | 6.5.5, AEM as a Cloud Service
22+
24, 25, 26, 27 | 6.5.5, 6.4.8.1, AEM as a Cloud Service
23+
28, 30, 31 | 6.5.5, AEM as a Cloud Service
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Sample AEM project template - Precompiled Scripts
2+
3+
This project was set-up so that the server-side scripts from the [`ui.apps`](./ui.apps) module
4+
are precompiled and bundled. A secondary JAR artifact will be attached by default to your build,
5+
which will also be added to your [`all`](./all) content-package.
6+
7+
## Development workflow
8+
9+
When deployed to a local SDK development instance, a bundled precompiled script will have priority
10+
over a script for the same resource type/selector combination. Therefore, your `/apps` script
11+
changes will not be picked up for rendering. If you prefer the development workflow where you
12+
edit your scripts on your local instance first, then build and deploy your modules using the
13+
generic build instructions, but provide the following option as well:
14+
15+
-DskipScriptPrecompilation=true
16+
17+
This option will not generate the bundle with your precompiled scripts.
18+
19+
For example:
20+
21+
```bash
22+
23+
mvn clean install -PautoInstallSinglePackage -DskipScriptPrecompilation=true
24+
25+
```
26+
27+
28+
If you have already deployed the precompiled scripts bundle on your local instance, but would like
29+
to make script changes in `/apps`, you can either 1) stop the bundle or 2) remove it using the Web Console.

src/main/archetype/all/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@
6060
<type>zip</type>
6161
<target>/apps/${appId}-packages/application/install</target>
6262
</embedded>
63+
#if ( $precompiledScripts == "y" and $aemVersion == "cloud" )
64+
<embedded>
65+
<groupId>${groupId}</groupId>
66+
<artifactId>${rootArtifactId}.ui.apps</artifactId>
67+
<classifier>precompiled-scripts</classifier>
68+
<type>jar</type>
69+
<target>/apps/${appId}-packages/application/install/21</target>
70+
</embedded>
71+
#end
6372
<embedded>
6473
<groupId>${groupId}</groupId>
6574
<artifactId>${rootArtifactId}.core</artifactId>
@@ -287,7 +296,26 @@
287296
<build.environment>:production</build.environment>
288297
</properties>
289298
#end
299+
</profile>
300+
#if ( $precompiledScripts == "y" and $aemVersion == "cloud" )
301+
<profile>
302+
<id>precompiledScripts</id>
303+
<activation>
304+
<property>
305+
<name>skipScriptPrecompilation</name>
306+
<value>!true</value>
307+
</property>
308+
</activation>
309+
<dependencies>
310+
<dependency>
311+
<groupId>${groupId}</groupId>
312+
<artifactId>${rootArtifactId}.ui.apps</artifactId>
313+
<version>${project.version}</version>
314+
<classifier>precompiled-scripts</classifier>
315+
</dependency>
316+
</dependencies>
290317
</profile>
318+
#end
291319
</profiles>
292320

293321
<!-- ====================================================================== -->

src/main/archetype/archetype.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ datalayer=${datalayer}
2222
amp=${amp}
2323
enableDynamicMedia=${enableDynamicMedia}
2424
enableSSR=${enableSSR}
25+
precompiledScripts=${precompiledScripts}

src/main/archetype/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ Bundle-DocURL:
248248
<artifactId>org.apache.sling.bnd.models</artifactId>
249249
<version>1.0.0</version>
250250
</dependency>
251+
<dependency>
252+
<groupId>org.apache.sling</groupId>
253+
<artifactId>scriptingbundle-maven-plugin</artifactId>
254+
<version>0.5.0</version>
255+
</dependency>
251256
</dependencies>
252257
</plugin>
253258
<plugin>

src/main/archetype/ui.apps/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@
114114
<phase>generate-sources</phase>
115115
<configuration>
116116
<generateJavaClasses>true</generateJavaClasses>
117+
#if ( $precompiledScripts == "n")
117118
<generatedJavaClassesPrefix>org.apache.sling.scripting.sightly</generatedJavaClassesPrefix>
119+
#end
118120
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
119121
<allowedExpressionOptions>
120122
<allowedExpressionOption>cssClassName</allowedExpressionOption>
@@ -129,6 +131,73 @@
129131
</plugins>
130132
</build>
131133

134+
#if ( $precompiledScripts == "y" and $aemVersion == "cloud" )
135+
<profiles>
136+
<profile>
137+
<id>precompiledScripts</id>
138+
<activation>
139+
<property>
140+
<name>skipScriptPrecompilation</name>
141+
<value>!true</value>
142+
</property>
143+
</activation>
144+
<build>
145+
<plugins>
146+
<plugin>
147+
<groupId>biz.aQute.bnd</groupId>
148+
<artifactId>bnd-maven-plugin</artifactId>
149+
<executions>
150+
<execution>
151+
<id>bnd-process</id>
152+
<goals>
153+
<goal>bnd-process</goal>
154+
</goals>
155+
<configuration>
156+
<packagingTypes>content-package</packagingTypes>
157+
<bnd><![CDATA[
158+
Bundle-Name: ${project.name} - precompiled scripts
159+
Bundle-SymbolicName: ${project.groupId}.${project.artifactId}.precompiled-scripts
160+
-plugin: org.apache.sling.scriptingbundle.plugin.bnd.BundledScriptsScannerPlugin; \
161+
sourceDirectories="src/main/content/jcr_root"; \
162+
includes="**/.content.xml,**/*.html"
163+
Require-Capability: osgi.extender;filter:="(&(osgi.extender=sling.scripting)(version>=1.0.0)(!(version>=2.0.0)))"
164+
]]>
165+
</bnd>
166+
</configuration>
167+
</execution>
168+
</executions>
169+
</plugin>
170+
<plugin>
171+
<groupId>org.apache.maven.plugins</groupId>
172+
<artifactId>maven-jar-plugin</artifactId>
173+
<executions>
174+
<execution>
175+
<phase>package</phase>
176+
<goals>
177+
<goal>jar</goal>
178+
</goals>
179+
<configuration>
180+
<classifier>precompiled-scripts</classifier>
181+
<archive>
182+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
183+
</archive>
184+
</configuration>
185+
</execution>
186+
</executions>
187+
</plugin>
188+
<plugin>
189+
<groupId>org.apache.sling</groupId>
190+
<artifactId>sling-maven-plugin</artifactId>
191+
<configuration>
192+
<bundleFileName>${project.build.directory}/${project.build.finalName}-precompiled-scripts.jar</bundleFileName>
193+
</configuration>
194+
</plugin>
195+
</plugins>
196+
</build>
197+
</profile>
198+
</profiles>
199+
#end
200+
132201
<!-- ====================================================================== -->
133202
<!-- D E P E N D E N C I E S -->
134203
<!-- ====================================================================== -->

src/main/resources/META-INF/archetype-post-generate.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def includeCommerce = request.getProperties().get("includeCommerce")
2727
def includeForms = request.getProperties().get("includeForms")
2828
def enableSSR = request.getProperties().get("enableSSR");
2929
def sdkFormsVersion = request.getProperties().get("sdkFormsVersion")
30+
def precompiledScripts = request.getProperties().get("precompiledScripts")
3031

3132
def appsFolder = new File("$uiAppsPackage/src/main/content/jcr_root/apps/$appId")
3233
def configFolder = new File("$uiConfigPackage/src/main/content/jcr_root/apps/$appId/osgiconfig")
@@ -201,6 +202,10 @@ if(new File("$configFolder/config.publish").list().length == 0) {
201202
assert new File("$configFolder/config.publish").deleteDir()
202203
}
203204

205+
if (precompiledScripts == "n") {
206+
assert new File(rootDir, "README-precompiled-scripts.md").delete()
207+
}
208+
204209
/**
205210
* Creates content skeleton based upon singleCountry, language and country input from user
206211
*/

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@
182182
<validationRegex>^(y|n)$</validationRegex>
183183
</requiredProperty>
184184

185+
<!--
186+
Option to precompile the server-side scripts from ui.apps and attach them to the build as a secondary bundle artifact in the ui.apps project. aemVersion should be set to "cloud".
187+
-->
188+
<requiredProperty key="precompiledScripts">
189+
<defaultValue>n</defaultValue>
190+
<validationRegex>^(y|n)$</validationRegex>
191+
</requiredProperty>
192+
185193
</requiredProperties>
186194

187195
<modules>
@@ -521,6 +529,7 @@
521529
<includes>
522530
<include>README.md</include>
523531
<include>README-CIF.md</include>
532+
<include>README-precompiled-scripts.md</include>
524533
<include>.gitignore</include>
525534
<include>LICENSE</include>
526535
</includes>

src/test/resources/projects/basic/archetype.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ datalayer=y
2121
amp=y
2222
enableDynamicMedia=y
2323
enableSSR=n
24+
precompiledScripts=n

0 commit comments

Comments
 (0)