blob: 7cd4fb8fe3d258078d340ab06171cd8ea27e7380 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.8.1 at 2020-06-22
| Rendered using Apache Maven Fluido Skin 1.6
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Date-Revision-yyyymmdd" content="20200622" />
<meta http-equiv="Content-Language" content="en" />
<title>Apache Sling Scripting Bundle Maven Plugin &#x2013; Usage</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.6.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script type="text/javascript" src="./js/apache-maven-fluido-1.6.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left"><div id="bannerLeft"><h2>Apache Sling Scripting Bundle Maven Plugin</h2>
</div>
</div>
<div class="pull-right"></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2020-06-22<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 0.2.0</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Overview</li>
<li><a href="index.html" title="Introduction"><span class="none"></span>Introduction</a> </li>
<li><a href="plugin-info.html" title="Goals"><span class="none"></span>Goals</a> </li>
<li class="active"><a href="#"><span class="none"></span>Usage</a>
</li>
<li class="nav-header">Project Documentation</li>
<li><a href="project-info.html" title="Project Information"><span class="icon-chevron-right"></span>Project Information</a> </li>
<li><a href="project-reports.html" title="Project Reports"><span class="icon-chevron-right"></span>Project Reports</a> </li>
</ul>
<hr />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a>
</div>
</div>
</div>
<div id="bodyColumn" class="span10" >
<div class="section">
<h2><a name="Usage"></a>Usage</h2>
<p>The Scripting Bundle Maven Plugin will look for scripts in two project directories:</p>
<ol style="list-style-type: decimal">
<li><tt>src/main/scripts</tt> - this folder will contain scripts that will be pre-compiled</li>
<li><tt>src/main/resources/javax.script</tt> - this folder will contain scripts that will be embedded as is</li>
</ol>
<p>The structure in these source directories should then follow the normal way of structuring scripts in an Apache Sling application. For more details, check the <a class="externalLink" href="https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#script-locations">URL to Script Resolution</a> page. In addition to the normal way of structuring scripts in the file tree, the plugin provides some additional features:</p>
<ol style="list-style-type: decimal">
<li>
<p>Resource Type Versioning<br /> This works by putting the scripts in a folder that follows this simple naming convention: <tt>&lt;resourceType&gt;/&lt;version&gt;/</tt>. The <tt>&lt;version&gt;</tt> should be a valid semantic version (e.g. <tt>1.0.0</tt>)</p>
</li>
<li>
<p>Defining explicit extends relationships (similar to the <tt>sling:resourceSuperType</tt> property)<br /> An <tt>extends</tt> file in the resource type folder (versioned or not) allows defining this explicit relationship. This file must contain a single line with the <tt>resourceType</tt> used for the <tt>extends</tt> capability attribute followed by a <tt>;version=&lt;version-range&gt;</tt>; in this case, the plugin will set the <tt>extends</tt> attribute to the given <tt>resourceType</tt> and generate a <tt>Require-Capability</tt> for that <tt>resourceType</tt> with the given version range.</p>
</li>
<li>
<p>Defining an explicit requirement, without an inheritance relationship (e.g. delegation to another resource type)<br /> A <tt>requires</tt> file (assuming the same conventions and syntax as for the <tt>extends</tt> file) will generate a <tt>Require-Capability</tt> for each line based on the given <tt>resourceType</tt> and version range.</p>
</li>
<li>
<p>The Resource Type can have the form of a path or of a Java package name (e.g. <tt>com.mydomain.components.image</tt>). When the resource type is defined as a package name, the resource type label will be the last subpackage (i.e. for <tt>com.mydomain.components.image</tt>, the resource type label will be <tt>image</tt>).</p>
</li>
</ol>
<div class="section">
<h3><a name="Defining_scripts"></a>Defining scripts</h3>
<p>As an example, let&#x2019;s assume the following layout:</p>
<div>
<div>
<pre class="source">src/main/resources/javax.script/
org.foo/1.0.0
foo.POST.html
</pre></div></div>
<p>This will generate following <tt>Provide-Capability</tt>:</p>
<div>
<div>
<pre class="source">sling.servlet;
sling.servlet.resourceTypes:List&lt;String&gt;=&quot;org.foo&quot;;
sling.servlet.methods:List&lt;String&gt;=POST;
version:Version=&quot;1.0.0&quot;
</pre></div></div>
<p>For more complex examples head over to <a class="externalLink" href="https://github.com/apache/sling-org-apache-sling-scripting-bundle-tracker-it/tree/master/examples">https://github.com/apache/sling-org-apache-sling-scripting-bundle-tracker-it/tree/master/examples</a>.</p></div>
<div class="section">
<h3><a name="So_how_do_I_use_the_plugin.3F"></a>So how do I use the plugin?</h3>
<p>The plugin doesn&#x2019;t currently integrate with the <tt>maven-bundle-plugin</tt>, nor the <tt>bnd-maven-plugin</tt>. However, the generated <tt>Require-Capability</tt> and <tt>Provide-Capability</tt> headers values are simply made available via properties:</p>
<div>
<div>
<pre class="source">${org.apache.sling.scriptingbundle.maven.plugin.Require-Capability}
${org.apache.sling.scriptingbundle.maven.plugin.Require-Capability}
</pre></div></div>
<p>That makes it reasonable straightforward to use the plugin by just adding it into your build in the <tt>prepare-package</tt> phase and use the two properties in the manifest writing instructions of another plugin like the <tt>maven-bundle-plugin</tt>:</p>
<div>
<div>
<pre class="source">&lt;plugin&gt;
&lt;groupId&gt;org.apache.sling&lt;/groupId&gt;
&lt;artifactId&gt;scriptingbundle-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;0.2.0&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;prepare-package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;metadata&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.felix&lt;/groupId&gt;
&lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;
&lt;extensions&gt;true&lt;/extensions&gt;
&lt;configuration&gt;
&lt;instructions&gt;
&lt;Provide-Capability&gt;
${org.apache.sling.scriptingbundle.maven.plugin.Provide-Capability}
&lt;/Provide-Capability&gt;
&lt;Require-Capability&gt;
osgi.extender;filter:=&quot;(&amp;amp;(osgi.extender=sling.scripting)(version&gt;=1.0.0)(!(version&gt;=2.0.0)))&quot;,
${org.apache.sling.scriptingbundle.maven.plugin.Require-Capability}
&lt;/Require-Capability&gt;
&lt;/instructions&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
</pre></div></div></div></div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>Copyright &copy;2007&#x2013;2020
<a href="https://www.apache.org/">The Apache Software Foundation</a>.
All rights reserved.</p>
</div>
</div>
</footer>
</body>
</html>