blob: 15071f81a1fa3de7ad701557ccf7fdc154e282ae [file] [log] [blame]
<!--
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
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.
-->
<project name="org.apache.easyant.plugins#manifest" xmlns:ea="antlib:org.apache.easyant" xmlns:ac="antlib:net.sf.antcontrib">
<ea:core-version requiredrevision="[0.9,+]" />
<ea:plugin module="abstract-provisioning" revision="0.9" />
<target name="manifest:init">
<ea:parameter property="project.main.classname"
description="Used to define the project main class. The mainclass will then be used by many plugins (manifest, run-java, etc...)" />
<ea:parameter property="manifest.main.classname" default="${project.main.classname}">
If defined, Main-Class and Class-Path
attributes are added to produce an executable jar file.
By default this property take the same value as
'project.main.classname' property.
If you are looking for a way to reference your mainclass one time for all
plugins you should set project.main.classname
instead.
</ea:parameter>
<ea:parameter property="manifest.classpath" required="false"
description="If manifest.main.classname is defined, this will be used for the Class-Path attribute. by default this will be automatically computed from the Ivy dependencies of the target artifact." />
<ea:parameter property="target.main.classes" default="${target}/main/classes" description="destination directory for compiled classes" />
<mkdir dir="${target.main.classes}/META-INF" />
<ea:parameter property="manifest.file" default="${target}/MANIFEST.MF" description="the manifest-file to create/update." />
<ea:parameter property="version.properties.file" default="${target.main.classes}/META-INF/version.properties"
description="the version.properties file to create/update." />
<!--TODO: maybe it will be more generic if we doesn't use ivy.* properties -->
<ea:parameter property="ivy.module"
description="the name of the project, used to fill the Specification-Title and Implementation-Title in the manifest" />
<ea:parameter property="ivy.organisation"
description="the name of the organisation that is the owner of this module, used to fill the Specification-Vendor and Implementation-Vendor in the manifest" />
<ea:parameter property="ivy.revision"
description="the revision of the project, used to fill the Specification-Version and Implementation-Version in the manifest" />
<ea:parameter property="version" description="the full version of the project" />
<condition property="is.manifest.runnable">
<and>
<isset property="manifest.main.classname" />
<not>
<equals arg1="${manifest.main.classname}" arg2="$${project.main.classname}" />
</not>
</and>
</condition>
</target>
<target name="-manifest:generate-version-number" depends="manifest:init" unless="version">
<tstamp>
<format property="now" pattern="yyyyMMddHHmmss" />
</tstamp>
<property name="version" value="${ivy.revision}-build-${now}" />
</target>
<target name="manifest:manifest" depends="manifest:init,-manifest:generate-version-number" description="generate manifest file">
<manifest file="${manifest.file}">
<attribute name="Specification-Title" value="${ivy.module}" />
<attribute name="Specification-Version" value="${ivy.revision}" />
<attribute name="Specification-Vendor" value="${ivy.organisation}" />
<attribute name="Implementation-Title" value="${ivy.module}" />
<attribute name="Implementation-Version" value="${version}" />
<attribute name="Implementation-Vendor" value="${ivy.organisation}" />
</manifest>
<!--generate a version.properties file -->
<propertyfile file="${version.properties.file}" comment="Generated by easyant">
<entry key="APPLICATION-NAME" value="${ivy.module}" />
<entry key="SPEC-VERSION" value="${ivy.revision}" />
<entry key="APPLICATION_ORG" value="${ivy.organisation}" />
<entry key="VERSION" value="${version}" />
<entry key="DATE" type="date" value="now" />
</propertyfile>
</target>
<!-- currently this target is only available if we use retrieve.dependencies=true because manifestclasspath is excepting a relative based structure which is not really usable using the ivy cache for example -->
<target name="manifest:manifest-runnable" depends="manifest:manifest" description="add manifest attributes required for an executable jar"
if="is.manifest.runnable">
<fileset id="lib.main.fileset" dir="${lib.main}" erroronmissingdir="false">
<include name="*.jar" />
</fileset>
<ac:if>
<length length="0">
<fileset refid="lib.main.fileset" />
</length>
<ac:then>
<echo level="warn"
message="no dependencies found in ${lib.main}, will not be able to set Classpath attribute correctly" />
</ac:then>
</ac:if>
<path id="manifest.main.classpath">
<fileset refid="lib.main.fileset" />
</path>
<!-- create the target artifact dir if it does not exists -->
<dirname file="${target.main.artifact}" property="target.artifacts" />
<mkdir dir="${target.artifacts}" />
<manifestclasspath property="manifest.classpath" jarfile="${target.main.artifact}">
<classpath refid="manifest.main.classpath" />
</manifestclasspath>
<manifest file="${manifest.file}" mode="update">
<attribute name="Main-Class" value="${manifest.main.classname}" />
<attribute name="Class-Path" value="${manifest.classpath}" />
</manifest>
</target>
</project>