blob: 69952ff0b721f2d12d5032fe6fce034cd4a6024a [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
<title>Apache Felix - Apache Felix Manifest Generator (mangen)</title>
<link rel="icon" href="/res/favicon.ico">
<link rel="stylesheet" href="/res/site.css" type="text/css" media="all">
<link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<div class="title">
<div class="logo">
<a href="https://felix.apache.org/">
<img border="0" alt="Apache Felix" src="/res/logo.png">
</a>
</div>
<div class="header">
<a href="https://www.apache.org/">
<img border="0" alt="Apache" src="/res/apache.png">
</a>
</div>
</div>
<div class="menu">
<style type="text/css">
/* The following code is added by mdx_elementid.py
It was originally lifted from http://subversion.apache.org/style/site.css */
/*
* Hide class="elementid-permalink", except when an enclosing heading
* has the :hover property.
*/
.headerlink, .elementid-permalink {
visibility: hidden;
}
h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
<p><a href="/news.html">News</a> <br />
<a href="/license.html">License</a> <br />
<a href="/downloads.cgi">Downloads</a> <br />
<a href="/documentation.html">Documentation</a> <br />
<a href="/documentation/community/project-info.html">Project Info</a> <br />
<a href="/documentation/community/contributing.html">Contributing</a> <br />
<a href="/sitemap.html">Site Map</a> <br />
<a href="https://www.apache.org/">ASF</a> <br />
<a href="https://www.apache.org/security/">Security</a> <br />
<a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a> <br />
<a href="https://www.apache.org/foundation/thanks.html">Sponsors</a> </p>
<iframe
src="https://www.apache.org/ads/button.html"
style="border-width:0; float: left"
frameborder="0"
scrolling="no"
width="135"
height="135">
</iframe>
</div>
<div class="main">
<div class="breadcrump" style="font-size: 80%;">
<a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/documentation.html">Documentation</a>
</div>
<h1>Apache Felix Manifest Generator (mangen)</h1>
<style type="text/css">
/* The following code is added by mdx_elementid.py
It was originally lifted from http://subversion.apache.org/style/site.css */
/*
* Hide class="elementid-permalink", except when an enclosing heading
* has the :hover property.
*/
.headerlink, .elementid-permalink {
visibility: hidden;
}
h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
<h1 id="mangen-osgi-bundle-manifest-generator"><code>mangen</code> - <a href="http://www.osgi.org">OSGi</a> Bundle Manifest generator<a class="headerlink" href="#mangen-osgi-bundle-manifest-generator" title="Permanent link">&para;</a></h1>
<h1 id="introduction">Introduction<a class="headerlink" href="#introduction" title="Permanent link">&para;</a></h1>
<p>The <a href="http://www.osgi.org">OSGi</a> model provides a very powerful and flexible framework for developing Java applications in a modular fashion with a high degree of control over classloading inter-dependencies between modules. Projects such as [Oscar|http://oscar.objectweb.org/] and [Felix|http://incubator.apache.org/felix/] have recognised this power and implemented open source implementations of the framework. Adding to this is a growing availability of open source application bundles such as those offered via the [Oscar Bundle Repository|http://oscar-osgi.sourceforge.net/] (aka OBR).</p>
<p>As an active developer of OSGi based application, <a href="http://www.ascert.com/">Ascert's</a> technical staff grappled with the cumbersome task of manually creating OSGi Bundle Manifests. This task is never particularly interesting and only gets bigger and nastier as applications grow in size and the number of bundles present. To alleviate this chore the <code>mangen</code> tool has been created, with the following goals:</p>
<ul>
<li>Provide automatic scanning of an OSGi bundle JAR to detect references to external classes which require imports and possible export packages</li>
<li>Support scanning of multiple bundle JARs in a single pass, including any JAR files within a specified directory tree</li>
<li>Detect the majority of common import and export cases and provide manual override mechanisms to include cases that are not detected</li>
<li>Provide a simple, extensible, rule based mechansim to allow the required imports and possible exports sets to be refined e.g. removing un-needed packages, automatic resolving to packages in other JARs etc.</li>
<li>Provide a simple, extensible, reporting mechanism of actions taken</li>
<li>Automatic updating of each bundle JAR's Manifest, including a means to easily switch between either OSGi R3 or R4 compatible Manifest headers </li>
</ul>
<p>If you're not a Java developer, or you're not sure what OSGi is yet, then this tool is probably not for you!</p>
<h2 id="licensing">Licensing<a class="headerlink" href="#licensing" title="Permanent link">&para;</a></h2>
<p>The <code>mangen</code> utility was originally created as a copyrighted &copy; work of Ascert LLC, and released as <em>OSI Certified Open Source Software</em> for use under the under the terms of the <a href="http://www.opensource.org/licenses/cpl1.0.php">Common Public License</a></p>
<p>To promote wider use and enhancement, Ascert submitted version 1.0.1 of <code>mangen</code> to the <a href="http://incubator.apache.org/felix/">Apache Felix</a> project, where it will be actively developed and maintained by Felix project team. Availability is now under an [Apache 2.0 style license|http://www.apache.org/licenses/LICENSE-2.0]</p>
<p>Included third-party libraries and contributions are copyrighted &copy; works of their respective owners and are provided under the terms of their specified licenses. </p>
<h1 id="using-mangen">Using <code>mangen</code><a class="headerlink" href="#using-mangen" title="Permanent link">&para;</a></h1>
<h2 id="basic-operation">Basic operation<a class="headerlink" href="#basic-operation" title="Permanent link">&para;</a></h2>
<p>Using mangen is very simple. Unpack the distribution file to an installation directory, change to this directory and type the following command:</p>
<div class="codehilite"><pre> <span class="n">java</span> <span class="o">-</span><span class="n">jar</span> <span class="n">lib</span><span class="o">/</span><span class="n">mangen</span><span class="p">.</span><span class="n">jar</span> <span class="o">&lt;</span><span class="n">file</span><span class="o">-</span><span class="n">list</span><span class="o">&gt;</span>
</pre></div>
<p><em>Note: on Windows platforms you will need to use a '\' in place of the '/' file separator</em></p>
<p>Where:</p>
<ul>
<li><em><file-list></em> - is either a list of bundle JARs to be processed or a list of directories, or a mix of both. Each directory will be scanned and all JAR files in the directory, or any sub-directories will be included in the bundle JARs processed.</li>
</ul>
<p>The basic behaviour of <code>mangen</code> is to process the set of bundle JARs supplied and scan the classes within each JAR to build up a set of the possible exports and required imports for each JAR. Where inner jars are defined using the OSGi <code>Bundle-ClassPath</code> header the classes in these will also be scanned and the possible exports and required imports will be included in the sets generated for their enclosing JAR.</p>
<p>Two phases of process happen after JAR scanning has completed:</p>
<ul>
<li>Rule execution - typically rules will process the sets of imports and exports determined by <code>mangen</code> for each JAR, refining them according to the rule types being executed and the specific rule options</li>
<li>Report production - typically generating narrative reports on the bundles processed and the rules executed.</li>
</ul>
<p>Use of the word 'typically' is significant in the above descriptions. A basic set of <a href="">rules</a> and [reports|#MangenReports] are included with <code>mangen</code> to perform various useful tasks. This set is infinitely extensible, however, and <code>mangen</code> places no restriction on the types of tasks that rules and reports can perform.</p>
<p>The exact rules and reports to be run are entirely controlled by user configurable properties as described below. If no properties are supplied <code>mangen</code> will simply run, process the specified JAR files and exit.</p>
<h2 id="configuring-mangen-with-properties">Configuring <code>mangen</code> with Properties<a class="headerlink" href="#configuring-mangen-with-properties" title="Permanent link">&para;</a></h2>
<p>Properties to control <code>mangen</code> behaviour can either be supplied on the command line using the normal <code>-D</code> syntax or, for most cases in a <code>mangen.properties</code> file. If the same property name is specified in both then the <code>-D</code> command line property value will take precedence of the property file value.</p>
<p>For added flexibility a simple variable expansion syntax is provided to allow the value of one Property value to be used within another property. Every property value will be scanned for <code>$\{property-name\</code>} markers. Where these are found the marker will be replaced with the value of the associated <code>property-name</code>.</p>
<p><em>Example:</em></p>
<div class="codehilite"><pre> mangen.osgi.level=3
...
mangen.rulesets=mangen-rule-R<span class="cp">${</span><span class="n">mangen</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">level</span><span class="cp">}</span>-
</pre></div>
<h3 id="mangenproperties">mangen.properties<a class="headerlink" href="#mangenproperties" title="Permanent link">&para;</a></h3>
<p>The <code>mangen.properties</code> Property is used to instruct mangen where to find it's properties file. By default, <code>mangen</code> will look for a file named <code>mangen.properties</code> in the same directory in which <code>mangen.jar</code> was installed (i.e. <code>lib/mangen.properties</code>). By including a <code>-Dmangen.properties</code> setting on the command line a different properties file can be specified.</p>
<p><em>Example:</em></p>
<div class="codehilite"><pre> <span class="n">java</span> <span class="o">-</span><span class="n">jar</span> <span class="n">lib</span><span class="o">/</span><span class="n">mangen</span><span class="p">.</span><span class="n">jar</span> <span class="o">-</span><span class="n">Dmangen</span><span class="p">.</span><span class="k">properties</span><span class="p">=</span><span class="n">my_mangen</span><span class="p">.</span><span class="k">properties</span> <span class="n">my_app</span><span class="p">.</span><span class="n">jar</span>
</pre></div>
<h3 id="mangenosgilevel">mangen.osgi.level<a class="headerlink" href="#mangenosgilevel" title="Permanent link">&para;</a></h3>
<p>There are two places in which the <code>mangen.osgi.level</code> Property is used:</p>
<ul>
<li>internally within <code>mangen</code> to determine the correct format of Manifest headers to be processed and generated.</li>
<li>as a means to guide which rulesets are executed, using the <a href="">variable-expansion syntax</a></li>
</ul>
<p>At present, this Property should be set to a value of '3' or '4' (the default if not specified will be '3'); </p>
<h3 id="mangenrulesets">mangen.rulesets<a class="headerlink" href="#mangenrulesets" title="Permanent link">&para;</a></h3>
<p>Rules are the engine room of <code>mangen</code>, providing the basic means for refining the <code>mangen</code> detected import and export package sets e.g. removing un-needed or unused exports, supplying package version information, including undetectable package cases such as dynamic classloading.</p>
<p>Rulesets provide a simple means of organising the rules to be executed into groups of rule sets. The rulesets are specified as a list of comma-separated values, each value specifying the ruleset name prefix. The following example shows a ruleset definition for 2 rules:</p>
<div class="codehilite"><pre> <span class="n">mangen</span><span class="p">.</span><span class="n">rulesets</span><span class="p">=</span><span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">first</span><span class="o">-</span> <span class="p">,</span> <span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">final</span><span class="o">-</span>
<span class="p">...</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">first</span><span class="o">-</span>0<span class="p">=...</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">first</span><span class="o">-</span>1<span class="p">=...</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">first</span><span class="o">-</span>2<span class="p">=...</span>
<span class="p">...</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">final</span><span class="o">-</span>0<span class="p">=...</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span><span class="n">final</span><span class="o">-</span>1<span class="p">=...</span>
</pre></div>
<p>As shown in the example, <code>mangen</code> will take each ruleset name and look for sequentially numbered properties, starting from 0 and finishing when no property name is found. Each rule found will be executed to completion against the processed set of bundle JARs before the next rule property is processed.</p>
<p>Rulesets can be combined with <a href="">variable-expansion</a> to provide OSGi version dependent rules as shown the following example.</p>
<div class="codehilite"><pre> mangen.osgi.level=3
mangen.rulesets=mangen-rule-R<span class="cp">${</span><span class="n">mangen</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">level</span><span class="cp">}</span>-
...
mangen-rule-R3-0=...
...
mangen-rule-R4-0=...
</pre></div>
<p>Rules themselves are simply specified as a rule type followed by a space separate list of rule specific options e.g.</p>
<div class="codehilite"><pre> mangen.R4.syspackages=java\\..*
...
mangen-rule-basic-0=Ignore imports(<span class="cp">${</span><span class="n">mangen</span><span class="o">.</span><span class="n">R4</span><span class="o">.</span><span class="n">syspackages</span><span class="cp">}</span>)
mangen-rule-basic-1=DontImportOwnExports
</pre></div>
<p>See the <a href="">Rules</a> section for full details of the currently support rule types.</p>
<h3 id="mangen-report-">mangen-report-<a class="headerlink" href="#mangen-report-" title="Permanent link">&para;</a></h3>
<p>Reports in <code>mangen</code> work in a similar fashion to rules but without the ruleset concept. The set of sequentially numbered <code>mangen-report-</code> properties will be scanned to determine which reports should be run e.g.</p>
<div class="codehilite"><pre> <span class="n">mangen</span><span class="o">-</span><span class="n">report</span><span class="o">-</span>0<span class="p">=</span><span class="n">RuleReport</span> <span class="o">.*</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">report</span><span class="o">-</span>1<span class="p">=</span><span class="n">BundleReport</span> <span class="o">.*</span>
</pre></div>
<p>See the <a href="">Reports</a> section for full details of the currently support report types.</p>
<h3 id="mangenfailonerror">mangen.failonerror<a class="headerlink" href="#mangenfailonerror" title="Permanent link">&para;</a></h3>
<p>If set <code>on</code> will cause <code>mangen</code> to exit with a <code>System.exit()</code> error status of 3 if any errors occured. Typical usage is to allow an external build tool, such as Ant, detect that there were errors. Additionally, any error messages will also be sent to <code>stderr</code> as well as <code>stdout</code> if this property is set.</p>
<p>Default is <code>on</code>.</p>
<h3 id="mangenfailonwarning">mangen.failonwarning<a class="headerlink" href="#mangenfailonwarning" title="Permanent link">&para;</a></h3>
<p>If set <code>on</code> will cause <code>mangen</code> to exit with a <code>System.exit()</code> error status of 5 if any warnings occured. Typical usage is to allow an external build tool, such as Ant, detect that there were warnings. Additionally, any warning messages will also be sent to <code>stderr</code> as well as <code>stdout</code> if this property is set.</p>
<p>Default is <code>off</code>.</p>
<h2 id="rules">Rules<a class="headerlink" href="#rules" title="Permanent link">&para;</a></h2>
<p>The Rule concept in <code>mangen</code> was adopted to avoid hard-coding the types of post-processing steps that a user would be able to perform on the <code>mangen</code> generated set of package imports and exports. The rule syntax is as follows:</p>
<div class="codehilite"><pre> <span class="o">&lt;</span><span class="n">rule</span><span class="o">-</span><span class="n">type</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">rule</span><span class="o">-</span><span class="n">options</span><span class="o">&gt;</span>
</pre></div>
<p>Where:</p>
<ul>
<li><em><rule-type></em> - must be the name of a valid existing rule type, details of which can be found in this section.</li>
<li><em><rule-options></em> - will be a list of one or more of the standard options and/or rule specific options. The standard options are as follows:
<strong> <code>imports()</code> - a comma seperated list of package patterns, using the JDK regex format. These will be matched against a bundle's own import packages during rule processing, the specific handling undertaken for each match being dependent on the <em><rule-type></em>. <em>Note: each pattern must be separated from the next by a comma (,) and the list must not contain any space characters.</em></strong> <code>exports()</code> - a comma seperated list of package patterns, using the JDK regex format. These will be matched against a bundle's own export packages during rule processing, the specific handling undertaken for each match being dependent on the <em><rule-type></em>.
<em><em> <code>sys-packages()</code> - a comma seperated list of standard 'system package' patterns, using the JDK regex format. The specific handling undertaken for each match being dependent on the </em><rule-type></em></li>
</ul>
<p>Rules will can have either "global" scope, in which case every bundle JAR processed will have the rule appplied, or "local" scope meaning that they will only apply to a single bundle JAR. Global rules will be included in the <code>mangen.properties</code> file. Local rules are placed within the Manifest for the appropriate bundle in a special <code>mangen</code> attributes section e.g. </p>
<div class="codehilite"><pre> <span class="n">Bundle</span><span class="o">-</span><span class="n">Name</span><span class="p">:</span> <span class="n">Help</span> <span class="n">Component</span>
<span class="n">Bundle</span><span class="o">-</span><span class="n">ClassPath</span><span class="p">:</span> <span class="p">.,</span><span class="n">help4</span><span class="p">.</span><span class="n">jar</span><span class="p">,</span><span class="n">oracle_ice</span><span class="p">.</span><span class="n">jar</span><span class="p">,</span><span class="n">ohj</span><span class="o">-</span><span class="n">jewt</span><span class="p">.</span><span class="n">jar</span>
<span class="n">Metadata</span><span class="o">-</span><span class="n">Location</span><span class="p">:</span> <span class="n">metadata</span><span class="p">.</span><span class="n">xml</span>
<span class="n">Name</span><span class="p">:</span> <span class="n">com</span><span class="o">/</span><span class="n">ascert</span><span class="o">/</span><span class="n">openosgi</span><span class="o">/</span><span class="n">mangen</span>
<span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span>0<span class="p">:</span> <span class="n">Ignore</span> <span class="n">imports</span><span class="p">(</span><span class="n">com</span><span class="o">\</span><span class="p">.</span><span class="n">adobe</span><span class="o">\</span><span class="p">.</span><span class="n">acrobat</span><span class="o">.*</span><span class="p">,</span><span class="n">webeq</span><span class="o">\</span><span class="p">.</span><span class="o">.*</span><span class="p">,</span><span class="n">javax</span><span class="o">\</span><span class="p">.</span><span class="n">help</span><span class="p">,</span><span class="n">javax</span><span class="o">\</span><span class="p">.</span><span class="n">media</span><span class="p">)</span>
</pre></div>
<p>Details are included below showing whether a <em><rule-type></em> can be used in a global or a local context</p>
<h3 id="attributestamp">AttributeStamp<a class="headerlink" href="#attributestamp" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>yes</code> |
| <em>Standard options</em> | <code>imports</code>, <code>exports</code> |
| <em>Rule specific options</em> | |</p>
<p>When processing a bundle JAR <code>mangen</code> can only detect the name of a required import package or a possible export package. Within an OSGi environment it's possible to also include qualifying information on a package name, such as versioning information. The AttributeStamp rule allows this information to be "stamped" over a detected package name. </p>
<p>The rule may be supplied locally, in which case it will only apply to instances of a package name match with a specific bundle JAR, or globally in which case it will be applied to all instances of a package name match across all JARs.</p>
<p>The <code>imports</code> or <code>exports</code> options allow stamping of attributes to either imported or exported packages respectively. The rule will perform a regex package name match against each entry in the list and if the name matches, will augment the matched package name with any additional attributes suppled. The following shows an example of this.</p>
<p><em>Example:</em></p>
<div class="codehilite"><pre> <span class="n">mangen</span><span class="o">-</span><span class="n">rule</span><span class="o">-</span>1<span class="p">=</span><span class="n">AttributeStamp</span> <span class="n">imports</span><span class="p">(</span><span class="n">org</span><span class="o">\\</span><span class="p">.</span><span class="n">osgi</span><span class="o">\\</span><span class="p">.</span><span class="n">framework</span><span class="p">;</span><span class="n">version</span><span class="p">=</span>&quot;1<span class="p">.</span>2<span class="p">.</span>0&quot;<span class="p">)</span>
</pre></div>
<p>If the rule finds a package name pattern match and the package already has additional attributes an error will be thrown if the stamped attributes do not match the existing attributes. This could be the case as a result of either a previous AttributeStamp or Merge rule.</p>
<h3 id="dontimportownexports">DontImportOwnExports<a class="headerlink" href="#dontimportownexports" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>yes</code> |
| <em>Standard options</em> | |
| <em>Rule specific options</em> | |</p>
<p>In many application cases it's not necessary for a bundle JAR to import it' own exports. This rule may be used locally or globally to remove from a bundle's import list any package which it also exports.</p>
<h3 id="ignore">Ignore<a class="headerlink" href="#ignore" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>yes</code> |
| <em>Standard options</em> | <code>imports</code>, <code>exports</code> |
| <em>Rule specific options</em> | |</p>
<p>There are several cases where a <code>mangen</code> detected possible export or required import may not actually be desired:</p>
<ul>
<li>Standard JDK classes, particularly in an OSGi R3 environment where these packages are resolved without needing import statements</li>
<li>Packages which <code>mangen</code> detects as needing imports but won't actually be used in a running environment. One example of these is third party JARs which include Ant tasks for use in a development environment but which would probably never be instantiated in a running application.</li>
</ul>
<p>The Ignore rule will remove matching package entries from either the import or export lists, or both, as specified in the options.</p>
<p><em>Example:</em></p>
<div class="codehilite"><pre> mangen.R4.syspackages=java\\..*
mangen-rule-R4-0=Ignore imports(<span class="cp">${</span><span class="n">mangen</span><span class="o">.</span><span class="n">R4</span><span class="o">.</span><span class="n">syspackages</span><span class="cp">}</span>)
</pre></div>
<h3 id="merge">Merge<a class="headerlink" href="#merge" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>yes</code> |
| <em>Standard options</em> | <code>imports</code>, <code>exports</code> |
| <em>Rule specific options</em> | <code>existing</code>, <code>fixed</code> |</p>
<p>In some cases the simplest way to use <code>mangen</code> will be to provide a list of known imports and exports and then have <code>mangen</code> "merge" any remaining required imports and possible exports into these lists as needed. The Merge rule provides two mechanisms in which these known imports and exports can be supplied:</p>
<ul>
<li>
<p>Using <code>existing</code> Manifest entries - in which case <code>mangen</code> will take any current Import-Package and Export-Package headers and merge them into the detected import and export package sets</p>
</li>
<li>
<p>By specifying a set of <code>fixed</code> Manifest entries - allowing a limited set of pre-determined entries to be listed in the special <code>mangen</code> attributes of the Manifest which will be merged in.</p>
</li>
</ul>
<p><em>Example:</em></p>
<div class="codehilite"><pre> <span class="n">Manifest</span><span class="o">-</span><span class="n">Version</span><span class="p">:</span> 1<span class="p">.</span>0
<span class="n">Bundle</span><span class="o">-</span><span class="n">Name</span><span class="p">:</span> <span class="n">mybundle</span>
<span class="n">Export</span><span class="o">-</span><span class="n">Package</span><span class="p">:</span> <span class="n">my</span><span class="p">.</span><span class="n">bundle</span><span class="p">.</span><span class="n">package</span>
<span class="n">Name</span><span class="p">:</span> <span class="n">com</span><span class="o">/</span><span class="n">ascert</span><span class="o">/</span><span class="n">openosgi</span><span class="o">/</span><span class="n">mangen</span>
<span class="n">Import</span><span class="o">-</span><span class="n">Package</span><span class="p">:</span> <span class="n">some</span><span class="p">.</span><span class="n">other</span><span class="p">.</span><span class="n">package</span>
</pre></div>
<p>A <code>Merge existing</code> rule using the above example would ensure that <code>my.bundle.package</code> appeared in the list of packages to export. A <code>Merge fixed</code> would ensure that <code>some.other.package</code> appeared in the list of packages to import.</p>
<p>It's possible to use both <code>Merge existing</code> and <code>Merge fixed</code> within a given set of application rules although it's more likely that only one of these would be used to meet a given application build strategy.</p>
<p>The imports and exports options allow constraints on the packages to be merged based on regex package name pattern matches.</p>
<p>One other aspect to note with the Merge option is that it also provides an alternative way to "stamp" OSGi attributes on a <code>mangen</code> detected pakcage name, since if the package being merged was already in the set of <code>mangen</code> detected packages it's entry will be augmented with any additional attributes supplied from the package entry being merged.</p>
<h3 id="processbundles">ProcessBundles<a class="headerlink" href="#processbundles" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>no</code> |
| <em>Standard options</em> | |
| <em>Rule specific options</em> | |</p>
<p>By default, <code>mangen</code> will not actually process any of the JAR files specified, it will simply create objects to access them. </p>
<p>Being able to skip <code>mangen</code> processing of bundle JARs is useful behaviour in a small number of instances, such as the <a href="">ObrReport</a> that will generally be run against existing bundle Manifest headers rather than <code>mangen</code> generated sets of imports and exports.</p>
<p>For most cases, however, <code>mangen</code> import and export processing will be required and this Rule should be included.</p>
<p><em>Example:</em></p>
<div class="codehilite"><pre> mangen.rulesets=mangen-rule-initial- , mangen-rule-Ant- , mangen-rule-R<span class="cp">${</span><span class="n">mangen</span><span class="o">.</span><span class="n">osgi</span><span class="o">.</span><span class="n">level</span><span class="cp">}</span>- , mangen-rule- , mangen-rule-final-
mangen-rule-initial-0=ProcessBundles
...
</pre></div>
<h3 id="resolveimportstoexports">ResolveImportsToExports<a class="headerlink" href="#resolveimportstoexports" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>no</code> |
| <em>Standard options</em> | <code>sys-packages</code> |
| <em>Rule specific options</em> | |</p>
<p>Some OSGi developers use the framework as a basis for creating packaged applications, in fact it is just this usage which Ascert make of OSGi and Oscar and which motivated the creation of =mangen. In such cases, the simplest and possibly most powerful rule use case is simply to supply <code>mangen</code> with a complete set of application bundles and let it work out the matrix of imports and exports required to resolve every bundle dependency. This is exactly what the ResolveImportsToExports does. </p>
<p>ResolveImportsToExports can only be used globally and will prune down the set of possible exports and required imports to just those required to satisfy every bundle dependency. It will generate <code>*** WARNING ***</code> report lines for the following cases:</p>
<ul>
<li>duplicate exports where more than one bundle could be an exporter of the same package which is a necessary import of some other bundle. In these cases, at present, the first possible exporter found will be picked and all others removed and a warning generated </li>
<li>missing exports i.e. packages required by one or more bundles that are never exported. Erroneous warnings for standard JDK packages can be avoided using the <code>sys-packages</code> option.</li>
</ul>
<p>At present, the known cases where this rule may fail to create a consistent and resolved set of bundle Manifests are:</p>
<ul>
<li>cases of dynamic classloading</li>
<li>certain third party JARs, such as Xerces, which use the awkaward-to-handle OSGi case of <code>Thread.getContextClassLoader()</code> to determine the classloader for dynamic classloading.</li>
</ul>
<h3 id="updatebundles">UpdateBundles<a class="headerlink" href="#updatebundles" title="Permanent link">&para;</a></h3>
<p>| <em>Usable globally</em> | <code>yes</code> |
| <em>Usable locally</em> | <code>no</code> |
| <em>Standard options</em> | |
| <em>Rule specific options</em> | <code>overwrite</code> |</p>
<p>By default, <code>mangen</code> will only report on the generated list of imports and exports for each bundle processed. The UpdateBundles rule can be used to instruct <code>mangen</code> to update each bundle's Manifest wth the set of generated packages. </p>
<p>This rule can only be used globaly. If the <code>overwrite</code> option is specified, the bundle JAR will overwritten with a new bundle JAR containing the new Manifest. Without this option, the update will create new JARs of the same name as each existing JAR but with a suffix of <code>.new.jar</code>.</p>
<h2 id="reports">Reports<a class="headerlink" href="#reports" title="Permanent link">&para;</a></h2>
<p>Reports are really like a simplified case of rules. At present only a couple of simple reports are included.</p>
<p>All reports at present send their output to <code>System.out</code>, which can of course be redirected to a text file if a persistent copy is desired.</p>
<h3 id="rulereport">RuleReport<a class="headerlink" href="#rulereport" title="Permanent link">&para;</a></h3>
<p>This report will show any Rule generated output.</p>
<h3 id="bundlereport">BundleReport<a class="headerlink" href="#bundlereport" title="Permanent link">&para;</a></h3>
<p>| <em>Report options</em> | <code>show-differences</code> <code>show-local-rules</code> |</p>
<p>This report will create a simple overview of the refined set of a bundle's imports and exports, together with a report of any local rules which have been run for the bundle. The following options are supported:</p>
<ul>
<li><code>show-differences</code> - will show details of <em>ADDED</em> and <em>REMOVED</em> packages by comparing the generate set of import and export packages against the existing Import-Package and Export-Package attributes. If this option is omitted a simple list of generated imports and exports will be shown</li>
<li><code>show-local-rules</code> - will show report output from any local rules run for each bundle JAR</li>
</ul>
<h3 id="obrreport">ObrReport<a class="headerlink" href="#obrreport" title="Permanent link">&para;</a></h3>
<p>| <em>Report options</em> | <code>skip-jars</code> |</p>
<p>Produce a report for each bundle JAR that can be used as an OBR descriptor. </p>
<p>The <code>skip-jars</code> option can be used to specify a comma separated list of JAR name regex patterns for which OBR descriptors are not required (e.g. source JARs).</p>
<p>OBR descriptor production is a quite different aspect of <code>mangen</code> usage to import/export generation and so a separate example <code>obr.properties</code> file has been included to show typical settings for it's usage. The <code>-Dmangen.properties</code> setting can be used to run <code>mangen</code> with these settings e.g.</p>
<p><em>Example:</em></p>
<div class="codehilite"><pre> <span class="n">java</span> <span class="o">-</span><span class="n">Dmangen</span><span class="p">.</span><span class="k">properties</span><span class="p">=</span><span class="n">lib</span><span class="o">\</span><span class="n">obr</span><span class="p">.</span><span class="k">properties</span> <span class="o">-</span><span class="n">jar</span> <span class="n">lib</span><span class="o">\</span><span class="n">mangen</span><span class="p">.</span><span class="n">jar</span> <span class="n">e</span><span class="p">:</span><span class="o">\</span><span class="n">obr</span><span class="o">\</span><span class="n">repo</span><span class="o">\</span>
</pre></div>
<p>The example <code>obr.properties</code> includes a number of features:</p>
<ul>
<li>there is no <em>ProcessBundles</em> rule, meaning that <code>mangen</code> will not automatically generate imports and exports.</li>
<li>there is a <em>Merge existing</em> rule meaning <code>mangen</code> will use existing Manifest headers in each bundle JAR to generate the ObrReport</li>
<li>there is an <code>mangen.obr.ver</code> property that can be used to control the format of the OBR descriptors produced</li>
<li>text templates are included that allow the OBR version 1 and version 2 descriptors to be changed without needing to modify the ObrReport code.</li>
</ul>
<p>Whilst running, the ObrReport will look for a number of specific properties to aid it's processing:</p>
<ul>
<li><code>mangen.obr.ver</code> - to determine which format of OBR descriptor to produce</li>
<li><code>mangen.obr.descr.&lt;obr-ver&gt;</code> - the main text template used to produce the OBR descriptor for each bundle</li>
<li><code>mangen.obr.import.&lt;obr-ver&gt;</code> - the template used to produce the descriptor text for each import.</li>
<li><code>mangen.obr.export.&lt;obr-ver&gt;</code> - the template used to produce the descriptor text for each export.</li>
<li><code>mangen.obr.import.ver.&lt;obr-ver&gt;</code> - the template used to produce a "version" descriptor for an import which has an explicit version specified.</li>
<li><code>mangen.obr.export.ver.&lt;obr-ver&gt;</code> - the template used to produce a "version" descriptor for an export which has an explicit version specified.</li>
</ul>
<p>The templates include a simple "tag substitution" mechanism that will expand the following tags:</p>
<ul>
<li><code>@@hdr:&lt;header-name&gt;@@</code> - include the attribute value of <header-name> from the bundle's Manifest. The <code>mangen</code> attributes will be searched first, followed by the Main attributes</li>
<li><code>@@imports@@</code> - process the list of imports and generate descriptor text based on the <code>mangen.obr.import.&lt;obr-ver&gt;</code> template</li>
<li><code>@@exports@@</code> - process the list of exports and generate descriptor text based on the <code>mangen.obr.export.&lt;obr-ver&gt;</code> template</li>
<li><code>@@import-ver@@</code> - will be expanded using <code>mangen.obr.import.ver.&lt;obr-ver&gt;</code> if an explicit version was included for the import package</li>
<li><code>@@export-ver@@</code> - will be expanded using <code>mangen.obr.export.ver.&lt;obr-ver&gt;</code> if an explicit version was included for the export package</li>
<li><code>@@pkg:name@@</code> - name of the import or export package currently being processed</li>
<li><code>@@pkg:ver@@</code> - version of the import or export package currently being processed</li>
</ul>
<h2 id="contents-of-the-distribution-file">Contents of the distribution file<a class="headerlink" href="#contents-of-the-distribution-file" title="Permanent link">&para;</a></h2>
<p>The current <code>mangen</code> distribution includes the following:</p>
<ul>
<li>pre-compiled versions of <code>mangen</code> and libraries</li>
<li>full source code and Ant build files</li>
<li>this documentation in HTML format. The original documentation is maintained in TWiki format at Ascert's intranet set and a copy of the raw TWiki file is included. </li>
</ul>
<p>The following third party libraries are also included in the distribution:</p>
<ul>
<li><a href="http://incubator.apache.org/felix/">Felix</a> library JARs - required Felix library JARs, used by <code>mangen</code> in Manifest processing, and generation</li>
<li><a href="http://asm.objectweb.org/">ASM</a> - the ASM java bytecode parsing toolkit used by the <code>ASMClassScanner</code> class scanning implementation.</li>
<li><a href="http://jakarta.apache.org/bcel/">BCEL</a> - the BCEL java bytecode parsing toolkit used by the <code>BCELScanner</code> class scanning implementation. </li>
</ul>
<p>Thanks also go to the following contributors:</p>
<ul>
<li><a href="">Richard S. Hall</a> - both for his assistance in the development and testing of <code>mangen</code> and for his contribution of the ASM based class scanning implementation.</li>
</ul>
<h1 id="extending-mangen">Extending <code>mangen</code><a class="headerlink" href="#extending-mangen" title="Permanent link">&para;</a></h1>
<p>First things first. You need to be a reasonably proficient Java developer to undertake extending <code>mangen</code>. If you're not, then you should consider a Java programming course or tutorial of some kind.</p>
<p>Extensions to <code>mangen</code> can be performed in the following ways:</p>
<ul>
<li>creating new or enhanced Rules</li>
<li>creating new or enhanced Reports</li>
<li>supporting alternative class scanning implementations</li>
<li>Modifying the core source code</li>
</ul>
<p>The idea is that as <code>mangen</code> matures most extension cases will be possible via the first two means, with new class scanners and core modifications being the exception. </p>
<p>For detailed information, Javadoc API documentation for <code>mangen</code> can be found @@api-index-loc@@.</p>
<h2 id="creating-new-rule-types">Creating new Rule types<a class="headerlink" href="#creating-new-rule-types" title="Permanent link">&para;</a></h2>
<p>A rule type is in fact just a Java class which implements the <code>com.ascert.openosgi.Rule</code> interface. If no package name is specified, these will be assumed to be in the <code>com.ascert.openosgi.mangen.rules</code> package. Although somewhat less readable, a fully-qualified class name can be supplied for rule types in other packages.</p>
<p>At present, the simplest way to learn about creating new rules is to look at the source code for existing rules to understand how they're put together and what can be done in them.</p>
<h2 id="creating-new-report-types">Creating new Report types<a class="headerlink" href="#creating-new-report-types" title="Permanent link">&para;</a></h2>
<p>Reports are similar to rules. A Report type is a Java class which implements the <code>com.ascert.openosgi.Report</code> interface. Unqualified report types will be assumed to be in <code>com.ascert.openosgi.mangen.reports</code> package, with the option to use fully-qualified class names if desired. </p>
<p>As with rules, the source code for the existing reports is the best place to learn about creating new reports.</p>
<h2 id="alternative-class-scanners">Alternative class scanners<a class="headerlink" href="#alternative-class-scanners" title="Permanent link">&para;</a></h2>
<p>To parse the class files of an application <code>mangen</code> needs a class file bytecode scanning library. So that alternative scanning tools may be used <code>mangen</code> does not make direct usage of any library implementation. Instead a wrapper class is used which implements the <code>ClassScanner</code> interface, and hence insulates <code>mangen</code> from the specific details of different bytecode scanning tools. The <code>mangen.scanner.class</code> property can be used to control which scanner implementation class is used.</p>
<p>At present, implementations of the <code>ClassScanner</code> interface have been include for the ObjectWeb <a href="http://asm.objectweb.org/">ASM</a> toolkit and the [Apache BCEL|http://jakarta.apache.org/bcel/] toolkit. </p>
<h1 id="ongoing-development">Ongoing Development<a class="headerlink" href="#ongoing-development" title="Permanent link">&para;</a></h1>
<h2 id="change-log">Change Log<a class="headerlink" href="#change-log" title="Permanent link">&para;</a></h2>
<h3 id="version-101">Version 1.0.1<a class="headerlink" href="#version-101" title="Permanent link">&para;</a></h3>
<ul>
<li>Initial version submitted to Felix project.</li>
<li>Package names changed and license headers changed to Apache license</li>
<li><code>OsgiPackage</code> classes changed to use Felix manifest handling classes.</li>
<li>ASM and BCEL sources removed and maven dependencies created to pull these in from repositories.</li>
<li>Compiles and builds using normal maven build, but as yet doesn't create a standalone distribution which includes dependent jars and config <code>.properties</code> files.</li>
<li>No analysis work has been performed to determine enhancements and additional rules desirable to integrate with Felix build and take advantage of <code>mangen</code> class scanning.</li>
</ul>
<h3 id="01x-versions">0.1.x Versions<a class="headerlink" href="#01x-versions" title="Permanent link">&para;</a></h3>
<p>The 0.1.x versions of <code>mangen</code> are the original versions developed to work with Oscar. The versions and documentation can still be downloaded from the <a href="http://oscar-osgi.sourceforge.net/mangen/">OBR Sourceforge site</a>. The change history has been maintained here for completeness.</p>
<h4 id="version-012">Version 0.1.2<a class="headerlink" href="#version-012" title="Permanent link">&para;</a></h4>
<ul>
<li>Inclusion of <a href="">ObrReport</a> for generation of OBR descriptors <em>[ oscar-osgi-Feature Requests-1221468 ]</em> </li>
<li>Removed "default" processing of JARs. Now an explicit <a href="">ProcessBundles</a> must be included to force JAR processing to take place. This allows reports, such as the new ObrReport to skip <code>mangen</code> import/export processing and just work from existing manifests.</li>
<li>default <code>mangen.properties</code> now explicitly lists each non java.* package rather than using wildcards, proved safer and more reliable when creating OSGi R4 manifests</li>
</ul>
<h4 id="version-011">Version 0.1.1<a class="headerlink" href="#version-011" title="Permanent link">&para;</a></h4>
<ul>
<li>Support for errors and warnings to cause non-zero exit status to be returned</li>
<li>Fix for occasional failures to update bundle JARs <em><a href=""> oscar-osgi-Bugs-1218334 </a></em></li>
</ul>
<h4 id="version-010">Version 0.1.0<a class="headerlink" href="#version-010" title="Permanent link">&para;</a></h4>
<ul>
<li>First version</li>
<li>Support for current OSGi Release 3 (R3) manifest headers, and basic support for proposed upcoming R4 headers</li>
<li>Processing of JARs and directories containing JARs and parsing of contained classes using a subset of BCEL.</li>
<li>Simple but extensible rule based engine for import and export set manipulation.</li>
<li>Simple but extensible reporting engine</li>
<li>Updating of process bundle JARs via an UpdateBundles rule</li>
<li>Pluggable interface to allow alternative class byte code scanners to be used </li>
</ul>
<h2 id="possible-enhancements">Possible Enhancements<a class="headerlink" href="#possible-enhancements" title="Permanent link">&para;</a></h2>
<p>As with any piece of software, there are always more things you'd like to do than time available in which to work on them. This library is no exception. </p>
<p>In it's present form it <code>mangen</code> is simple, reasonably fast, and usable. Ideas on some of the more significant areas where it could be enhanced or improved are described in the sections below.</p>
<p>Most <code>mangen</code> enhancement ideas have now been created as issues in the <a href="https://issues.apache.org/jira/secure/IssueNavigator.jspa?component=12310910&amp;sorter/field=priority&amp;mode=hide&amp;reset=true&amp;pid=12310100&amp;sorter/order=ASC">Apache JIRA list</a>.</p>
<p>Those which are more speculative have been left below.</p>
<h3 id="online-usage-within-an-osgi-environment">Online usage within an OSGi environment<a class="headerlink" href="#online-usage-within-an-osgi-environment" title="Permanent link">&para;</a></h3>
<p>Extending the concept of <a href="">Manifest-less usage</a> comes an interesting possibility that a specific OSGi platform such as [Oscar|http://oscar.objectweb.org/] could be extended to load any JAR and automatically 'fix-up' a usable Manifest. This would require internal access/knowledge of the specific platform's implementation since the existing standard OSGi API would not supply sufficient details and access to the set of loaded bundle JARs. Additionally, it would probably need to be a "multi-step" process since until a largely complete set of bundle JARs were loaded it may not be possible to resolve all imports and exports. This perhaps implies some form of platform extension to allow a set of JARs to be passed to some form of "pre-load" mechanism capable of resolving their imports and exports within the JAR set, and possibly from existing loaded bundle JARs or even an external [OBR|http://oscar-osgi.sourceforge.net/]. </p>
<h1 id="acknowledgements">Acknowledgements<a class="headerlink" href="#acknowledgements" title="Permanent link">&para;</a></h1>
<p>Ascert is pleased to acknowledge the following projects, organisations and individuals whose tools have been used in the creation of this software:</p>
<ul>
<li><a href="http://asm.objectweb.org/">ASM</a> - ObjectWeb's bytecode scanning and manipulation toolkit.</li>
<li><a href="http://jakarta.apache.org/bcel/">BCEL</a> - Apache's bytecode scanning and manipulation toolkit.</li>
<li><a href="http://www.jedit.org">jEdit</a> - home of the powerful and flexible jEdit
editor</li>
<li><a href="http://ant.apache.org">Ant</a> - home of the Apache Ant build tool</li>
<li><a href="http://www.bluemarsh.com/">Blue Marsh Softworks</a> - authors of the excellent [JSwat|http://www.bluemarsh.com/java/jswat/index.html] Java debugger.</li>
<li><a href="http://subversion.tigris.org/">Subversion</a> - home of the Subversion (aka SVN) version control system, and [Regnis|http://www.regnis.de/] and [TortoiseSVN|http://tortoisesvn.tigris.org/], both of which are excellent SVN GUI clients</li>
<li><a href="http://java.sun.com">Sun Java</a> - home of all things Java and a place we love.</li>
</ul>
<div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
Rev. 1700393 by cziegeler on Tue, 1 Sep 2015 06:04:06 +0000
</div>
<div class="trademarkFooter">
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project
logo are trademarks of The Apache Software Foundation. All other marks mentioned
may be trademarks or registered trademarks of their respective owners.
</div>
</div>
</body>
</html>