PR: MPJAR-36, MPJAR-39, MPJAR-49

Submitted by: Michael Gaffney
Jar plugin generates incorrect manifest file.


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@392483 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ltheussl
2006-04-08 05:49:07 +00:00
parent b8a586ff9e
commit 0e28086c28
5 changed files with 208 additions and 19 deletions

View File

@@ -83,9 +83,11 @@
</ant:metainf>
<ant:manifest>
<ant:attribute name="Built-By" value="${user.name}"/>
<ant:attribute name="Created-By" value="Apache Maven"/>
<ant:attribute name="Package" value="${pom.package}"/>
<ant:attribute name="Build-Jdk" value="${java.version}"/>
<j:set var="mavenVersion" value="${maven.application.version}"/>
<j:if test="${mavenVersion != null}">
<ant:attribute name="Maven-Version" value="${mavenVersion}"/>
</j:if>
<j:set var="jarClasspath" value="${maven.jar.manifest.classpath.add}"/>
<j:if test="${jarClasspath}">
@@ -94,20 +96,11 @@
<j:set var="maven.jar.classpath" value="${maven.jar.classpath} ${dep.artifact}" />
</j:if>
</j:forEach>
<j:if test="${maven.jar.classpath.length() != 0}">
<j:if test="${!empty(maven.jar.classpath)}">
<ant:attribute name="Class-Path" value="${maven.jar.classpath}"/>
</j:if>
</j:if>
<!-- added supplementary entries -->
<ant:attribute name="Extension-Name" value="${pom.artifactId}"/>
<ant:attribute name="Specification-Title" value="${specificationTitle}" />
<ant:attribute name="Specification-Vendor" value="${pom.organization.name}"/>
<!--
<ant:attribute name="Specification-Version" value="${pom.currentVersion}"/>
-->
<ant:attribute name="Implementation-Title" value="${pom.package}"/>
<ant:attribute name="Implementation-Vendor" value="${pom.organization.name}"/>
<ant:attribute name="Implementation-Version" value="${pom.currentVersion}"/>
<j:set var="mainclass" value="${maven.jar.mainclass}" />
<j:if test="${!empty(mainclass)}">
<ant:attribute name="Main-Class" value="${mainclass}"/>
@@ -146,14 +139,48 @@
</j:forEach>
</j:if>
<j:if test="${context.getVariable('maven.jar.manifest.attributes.list') != null}">
<!-- Remove SNAPSHOT -->
<j:choose>
<j:when test="${pom.currentVersion.endsWith('-SNAPSHOT')}">
<j:invokeStatic className="org.apache.commons.lang.StringUtils" method="substringBeforeLast" var="pomCurrentVersion">
<j:arg value="${pom.currentVersion}" type="java.lang.String"/>
<j:arg value="-SNAPSHOT" type="java.lang.String"/>
</j:invokeStatic>
</j:when>
<j:otherwise>
<j:set var="pomCurrentVersion" value="${pom.currentVersion}"/>
</j:otherwise>
</j:choose>
<util:tokenize var="versionItems" delim="." trim="true">${pomCurrentVersion}</util:tokenize>
<j:if test="${size(versionItems) > 0}">
<j:set var="specificationVersion" value="${versionItems[0]}" />
</j:if>
<j:if test="${size(versionItems) > 1}">
<j:set var="specificationVersion" value="${specificationVersion}.${versionItems[1]}" />
</j:if>
<j:if test="${size(versionItems) > 2}">
<j:set var="specificationVersion" value="${specificationVersion}.${versionItems[2]}" />
</j:if>
<util:replace var="packagePath" oldChar="." newChar="/" value="${pom.package}"/>
<ant:section name="${packagePath}">
<ant:attribute name="Extension-name" value="${pom.package}"/>
<ant:attribute name="Specification-Title" value="${specificationTitle}"/>
<ant:attribute name="Specification-Vendor" value="${pom.organization.name}"/>
<ant:attribute name="Specification-Version" value="${specificationVersion}"/>
<ant:attribute name="Implementation-Title" value="${pom.package}"/>
<ant:attribute name="Implementation-Vendor" value="${pom.organization.name}"/>
<ant:attribute name="Implementation-Version" value="${pom.currentVersion}"/>
<j:if test="${context.getVariable('maven.jar.manifest.attributes.list') != null}">
<util:tokenize var="attributeList" delim="," trim="true">${maven.jar.manifest.attributes.list}</util:tokenize>
<j:forEach var="attribute" items="${attributeList}">
<j:set var="name" value="maven.jar.manifest.attribute.${attribute}"/>
<j:set var="value" value="${context.findVariable(name)}"/>
<ant:attribute name="${attribute}" value="${value}"/>
<j:set var="name" value="maven.jar.manifest.attribute.${attribute}"/>
<j:set var="value" value="${context.findVariable(name)}"/>
<ant:attribute name="${attribute}" value="${value}"/>
</j:forEach>
</j:if>
</j:if>
</ant:section>
<j:if test="${context.getVariable('maven.jar.manifest.groups.list') != null}">
<util:tokenize var="groupList" delim="," trim="true">${maven.jar.manifest.groups.list}</util:tokenize>

View File

@@ -59,6 +59,15 @@
<artifactId>commons-jelly-tags-velocity</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.0</version>
<url>http://jakarta.apache.org/commons/lang/</url>
<properties>
<comment>This library is already loaded by maven's core. Be careful to use the same version number as in the core.</comment>
</properties>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>

View File

@@ -25,6 +25,13 @@
</properties>
<body>
<release version="1.8-SNAPSHOT" date="In SVN">
<action dev="ltheussl" type="add" issue="MPJAR-39">Support specificationVersion in manifest.</action>
<action dev="ltheussl" type="fix">
<description>Jar plugin generates incorrect manifest file.</description>
<fixes issue="MPJAR-36"/>
<fixes issue="MPJAR-49"/>
<dueto name="Michael Gaffney"/>
</action>
<action dev="aheritier" type="fix">java:compile and java:jar-resources should be called before the jar goal to create the good directory structure. It was done in test:test before but it's also a prerequisite for jar:jar.</action>
<action dev="ltheussl" type="update" issue="MPJAR-47">Remove unused properties from documentation.</action>
<action dev="ltheussl" type="update" issue="MPJAR-35" due-to="Dennis Lundberg">Document need for jar.manifest.classpath property.</action>

145
jar/xdocs/manifest.xml Normal file
View File

@@ -0,0 +1,145 @@
<?xml version="1.0"?>
<!--
/*
* Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed 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
*
* http://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.
*/
-->
<document>
<properties>
<title>The Manifest</title>
</properties>
<body>
<section name="The manifest file">
<p>
Here is a typical manifest file generated by the <code>maven-jar-plugin-1.8</code>:
</p>
<source>Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.4.2_10-b03 (Sun Microsystems Inc.)
Built-By: lukas
Maven-Version: 1.1-beta-3-SNAPSHOT
Name: org/apache/maven
Extension-name: org.apache.maven
Specification-Title: Create jar files
Specification-Vendor: Apache Software Foundation
Specification-Version: 1.8
Implementation-Title: org.apache.maven
Implementation-Vendor: Apache Software Foundation
Implementation-Version: 1.8-SNAPSHOT</source>
<p>
Note that the structure was different and probably not compatible in older versions
of the plugin, see <a href="http://jira.codehaus.org/browse/MPJAR-36">MPJAR-36</a>.
</p>
<subsection name="Default attributes">
<table>
<tr><th>Attribute</th><th>Default value</th></tr>
<tr>
<td><code>Created-By</code></td>
<td>The java version used to generate the manifest file</td>
</tr>
<tr>
<td><code>Built-By</code></td>
<td>${user.name}</td>
</tr>
<tr>
<td><code>Maven-Version</code></td>
<td>${maven.application.version}</td>
</tr>
<tr>
<td><code>Class-Path</code></td>
<td>
See the <code>maven.jar.manifest.classpath.add</code>
<a href="properties.html">property</a>.
</td>
</tr>
<tr>
<td><code>Main-Class</code></td>
<td>
See the <code>maven.jar.mainclass</code>
<a href="properties.html">property</a>.
</td>
</tr>
<tr>
<td><code>Extension-List</code></td>
<td>
See the <code>maven.jar.manifest.extensions.add</code>
<a href="properties.html">property</a>.
</td>
</tr>
<tr>
<td><code>Name</code></td>
<td>${pom.package} with "." (dot) replaced by "/" (slash)</td>
</tr>
<tr>
<td><code>Extension-name</code></td>
<td>${pom.package}</td>
</tr>
<tr>
<td><code>Specification-Title</code></td>
<td>${pom.shortDescription} (trimmed to 46 characters)</td>
</tr>
<tr>
<td><code>Specification-Vendor</code></td>
<td>${pom.organization.name}</td>
</tr>
<tr>
<td><code>Specification-Version</code></td>
<td>
This is constructed from ${pom.currentVersion} in the following way:
first any occurence of the string "<code>-SNAPSHOT</code>" is chopped off,
the rest is then tokenized with a delimiter "." (dot), and
up to three tokens are kept. <strong>Note</strong> that according to
<a href="http://java.sun.com/j2se/1.4.2/docs/guide/versioning/spec/versioning2.html">Sun's specification</a>
this must be a number to compare, so if your ${pom.currentVersion} contains any
non-digit character (apart from "."), the resulting manifest will not be valid.
You should then override this default (see below).
</td>
</tr>
<tr>
<td><code>Implementation-Title</code></td>
<td>${pom.package}</td>
</tr>
<tr>
<td><code>Implementation-Vendor</code></td>
<td>${pom.organization.name}</td>
</tr>
<tr>
<td><code>Implementation-Version</code></td>
<td>${pom.currentVersion}</td>
</tr>
</table>
</subsection>
<subsection name="Overriding default values">
<p>
Any of the above default values can be overridden by specifying
a custom manifest file via the <code>maven.jar.manifest</code>
<a href="properties.html">property</a>. Note that values in manifest
sections (separated from the main section by a blank line) can
only be overridden by also specifying the section name.
For instance, even if you only want to override the
<code>Specification-Version</code> in the example above,
you need at least the following in your custom manifest:
</p>
<source>Name: org/apache/maven
Specification-Version: 1.8.0</source>
</subsection>
</section>
</body>
</document>

View File

@@ -32,6 +32,7 @@
<menu name="Overview">
<item name="Goals" href="/goals.html"/>
<item name="Properties" href="/properties.html"/>
<item name="Manifest" href="/manifest.html"/>
</menu>
</body>
</project>