maven-plugins/plugin/plugin.jelly
2007-04-23 21:28:38 +00:00

560 lines
22 KiB
XML

<?xml version="1.0"?>
<!--
/*
* 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
xmlns:artifact="artifact"
xmlns:ant="jelly:ant"
xmlns:define="jelly:define"
xmlns:i="jelly:interaction"
xmlns:j="jelly:core"
xmlns:maven="jelly:maven"
xmlns:plugin="plugin"
xmlns:u="jelly:util"
xmlns:x="jelly:xml"
xmlns:assert="assert">
<define:taglib uri="plugin">
<!-- We can't use it in the bootstrap phase because classes aren't yet build for the plugin -->
<j:if test="${bootstrapping == null}">
<define:jellybean
name="validate-xml"
className="org.apache.maven.JaxpMsvBean"
method="validate">
<!-- @schema : The schema to validate against (full path) -->
<!-- @file : The file to be validated (full path) -->
</define:jellybean>
</j:if>
<define:tag name="uninstall">
<ant:delete verbose="false" failonerror="false">
<ant:fileset dir="${maven.plugin.dir}">
<ant:include name="${name}-*.jar" />
</ant:fileset>
<ant:fileset dir="${maven.plugin.user.dir}">
<ant:include name="${name}-*.jar" />
</ant:fileset>
</ant:delete>
<ant:delete includeEmptyDirs="true" verbose="false" failonerror="false">
<ant:fileset dir="${maven.plugin.unpacked.dir}">
<ant:include name="${name}-*/**" />
</ant:fileset>
</ant:delete>
</define:tag>
<define:tag name="clearCache">
<ant:delete includeEmptyDirs="true" verbose="false" failonerror="false">
<ant:fileset dir="${maven.plugin.unpacked.dir}">
<ant:include name="*.cache"/>
<ant:include name="**/.processed" />
</ant:fileset>
</ant:delete>
</define:tag>
</define:taglib>
<define:taglib uri="assert">
<define:tag name="assertFileExists">
<!-- @file : Full file path -->
<!-- @msg : optional message to be displayed -->
<u:file var="fileAsFile" name="${file}"/>
<j:if test="${!(fileAsFile.exists())}">
<ant:fail>${file} does not exist.${msg}</ant:fail>
</j:if>
</define:tag>
<define:tag name="assertFileContains">
<!-- @file : Full file path -->
<!-- @match: the matching value expected -->
<!-- @msg : optional message to be displayed -->
<assert:assertFileExists file="${file}" msg="${msg}"/>
<u:loadText var="fileContent" file="${file}"/>
<j:if test="${fileContent.indexOf(match) lt 0}">
<ant:fail>${file} does not contain string [${match}].${msg}</ant:fail>
</j:if>
</define:tag>
<define:tag name="assertFileNotFound">
<!-- @file : Full file path -->
<!-- @msg : optional message to be displayed -->
<u:file var="fileAsFile" name="${file}"/>
<j:if test="${fileAsFile.exists()}">
<ant:fail>${file} found and not expected.${msg}</ant:fail>
</j:if>
</define:tag>
<define:tag name="assertEquals">
<!-- @expected : the expected value -->
<!-- @value : the actual value -->
<!-- @msg : optional message to be displayed -->
<j:if test="${not(expected.equals(value))}">
<ant:fail>Expected [${expected}] but got [${value}].${msg}</ant:fail>
</j:if>
</define:tag>
<define:tag name="assertPluginAvailable">
<j:if test="${bootstrapping == null}">
<!-- Check parameters -->
<maven:param-check value="${groupId}" fail="true" message="'groupId' must be specified"/>
<maven:param-check value="${artifactId}" fail="true" message="'artifactId' must be specified"/>
<maven:param-check value="${minRelease}" fail="true" message="'minRelease' must be specified"/>
<maven:param-check value="${neededBy}" fail="true" message="'neededBy' must be specified"/>
<j:set var="pluginToTest" value="${artifactId}"/>
<!-- Remove SNAPSHOT -->
<j:choose>
<j:when test="${minRelease.endsWith('-SNAPSHOT')}">
<j:invokeStatic className="org.apache.commons.lang.StringUtils" method="substringBeforeLast" var="minReleaseToHave">
<j:arg value="${minRelease}" type="java.lang.String"/>
<j:arg value="-SNAPSHOT" type="java.lang.String"/>
</j:invokeStatic>
</j:when>
<j:otherwise>
<j:set var="minReleaseToHave" value="${minRelease}"/>
</j:otherwise>
</j:choose>
<!-- A workaround to force maven to load the plugin if it's not already done -->
<maven:set plugin="${pluginToTest}" property="myFakePropertyUsedToLoadThePlugin" value="XXXX" />
<!-- maven:get don't want to do it -->
<maven:get plugin="${pluginToTest}" property="plugin" var="installedPlugin" />
<!-- Check if the plugin is installed -->
<j:choose>
<j:when test="${!empty(installedPlugin)}">
<!-- Remove SNAPSHOT -->
<j:choose>
<j:when test="${installedPlugin.currentVersion.endsWith('-SNAPSHOT')}">
<j:invokeStatic className="org.apache.commons.lang.StringUtils" method="substringBeforeLast" var="installedRelease">
<j:arg value="${installedPlugin.currentVersion}" type="java.lang.String"/>
<j:arg value="-SNAPSHOT" type="java.lang.String"/>
</j:invokeStatic>
</j:when>
<j:otherwise>
<j:set var="installedRelease" value="${installedPlugin.currentVersion}"/>
</j:otherwise>
</j:choose>
<j:set var="testOk" value="false"/>
<j:set var="testFailed" value="false"/>
<!-- Test strings comparaison -->
<j:choose>
<j:when test="${!installedRelease.equals(minReleaseToHave)}">
<!-- If not equals we use a more complex algorithm -->
<!-- Tokenify -->
<u:tokenize var="installedReleaseTokens" delim=".">${installedRelease}</u:tokenize>
<u:tokenize var="minReleaseToHaveTokens" delim=".">${minReleaseToHave}</u:tokenize>
<j:set var="minReleaseToHaveTokensIter" value="${minReleaseToHaveTokens.iterator()}"/>
<j:forEach var="numberInstalled" items="${installedReleaseTokens}">
<j:if test="${!minReleaseToHaveTokensIter.hasNext()}">
<!-- There are more elements in the installed version than in the version to have -->
<!-- For example 1.7.1 and 1.7 -->
<!-- We are in the case where previous versions numbers are already tested -->
<!-- Thus it's a minor increment -->
<j:set var="testOk" value="true"/>
<j:break/>
</j:if>
<j:set var="numberToHave" value="${minReleaseToHaveTokensIter.next()}"/>
<j:invokeStatic var="numberInstalledInteger" className="java.lang.Integer" method="valueOf">
<j:arg value="${numberInstalled}"/>
</j:invokeStatic>
<j:invokeStatic var="numberToHaveInteger" className="java.lang.Integer" method="valueOf">
<j:arg value="${numberToHave}"/>
</j:invokeStatic>
<j:choose>
<j:when test="${numberInstalledInteger.compareTo(numberToHaveInteger) lt 0}">
<j:set var="errorSentence" value="Currently the plugin ${pluginToTest} v${installedRelease} is installed."/>
<j:set var="testFailed" value="true"/>
<j:break/>
</j:when>
<j:when test="${numberInstalledInteger.compareTo(numberToHaveInteger) eq 0}">
</j:when>
<j:when test="${numberInstalledInteger.compareTo(numberToHaveInteger) gt 0}">
<j:set var="testOk" value="true"/>
<j:break/>
</j:when>
</j:choose>
</j:forEach>
</j:when>
<j:otherwise>
<j:set var="testOk" value="true"/>
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise>
<j:set var="errorSentence" value="Currently the plugin ${pluginToTest} isn't installed."/>
<j:set var="testFailed" value="true"/>
</j:otherwise>
</j:choose>
<j:if test="${!testFailed and !testOk and minReleaseToHaveTokensIter.hasNext()}">
<!-- A minor release is missing. For example : 1.10 < 1.10.2 -->
<j:set var="errorSentence" value="Currently the plugin ${pluginToTest} v${installedRelease} is installed."/>
<j:set var="testFailed" value="true"/>
</j:if>
<j:if test="${testFailed}">
<ant:fail>
-
===============================================================================
Must have the plugin ${pluginToTest} v${minReleaseToHave} installed to use this version of ${neededBy}.
${errorSentence}
Try: maven plugin:download -DgroupId=maven -DartifactId=${pluginToTest} -Dversion=${minReleaseToHave}
===============================================================================
</ant:fail>
</j:if>
</j:if>
<j:if test="${bootstrapping != null}">
<ant:echo>
-
===============================================================================
BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP
===============================================================================
Can't check that you have the plugin ${pluginToTest} v${minReleaseToHave} required by ${neededBy}.
===============================================================================
BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP BOOTSTRAP
===============================================================================
</ant:echo>
</j:if>
</define:tag>
</define:taglib>
<goal name="plugin" prereqs="plugin:plugin" description="Build a plugin jar" />
<goal name="plugin:plugin" description="Build a plugin jar">
<!-- For some reason a prereq on this causes an internal error... -->
<attainGoal name="jar:jar" />
<!-- We can't use it in the bootstrap phase because classes aren't yet build in the artifact plugin -->
<j:if test="${bootstrapping == null}">
<assert:assertPluginAvailable groupId="maven" artifactId="maven-artifact-plugin" minRelease="1.7" neededBy="${plugin.artifactId}"/>
<artifact:rewritePOM path="${maven.build.dir}/project.xml"/>
<ant:jar
jarfile="${maven.build.dir}/${maven.final.name}.jar"
basedir="${maven.build.dir}"
update="true">
<ant:setProperty name="includes" value="project.xml" />
</ant:jar>
<ant:delete file="${maven.build.dir}/project.xml" quiet="true"/>
</j:if>
</goal>
<goal name="plugin:install" prereqs="plugin:plugin"
description="Install the plugin jar, prepare Maven to expand it locally next run">
<plugin:uninstall name="${pom.artifactId}" />
<!-- Don't clear the cache. Maven will do this if we happened to clean up an additional version -->
<copy file="${maven.build.dir}/${maven.final.name}.jar"
todir="${maven.plugin.dir}" />
</goal>
<goal name="plugin:install-now" prereqs="plugin:plugin"
description="Build a plugin and load it into the currently running instance of Maven.">
<!-- The cache should remain intact through these operations -->
<plugin:uninstall name="${pom.artifactId}" />
<maven:uninstallPlugin artifactId="${pom.artifactId}" />
<maven:installPlugin file="${maven.build.dir}/${maven.final.name}.jar" cache="true" />
</goal>
<goal name="plugin:uninstall"
description="Uninstall all versions of the plugin">
<plugin:uninstall name="${pom.artifactId}" />
<plugin:clearCache />
</goal>
<goal name="plugin:uninstall-now" prereqs="plugin:uninstall"
description="Uninstall all versions of the plugin, including those in the currently running instance of Maven">
<maven:uninstallPlugin artifactId="${pom.artifactId}" />
</goal>
<!-- generate documentation -->
<!-- generate docs that are usually missing -->
<goal name="plugin:generate-docs"
description="Generate navigation, goals and properties docs">
<attainGoal name="plugin:generate-navigation" />
<attainGoal name="plugin:generate-goals" />
<attainGoal name="plugin:generate-properties" />
<attainGoal name="plugin:generate-tags" />
</goal>
<!-- generate a skeletal navigation.xml for the plugin specified
by the 'plugin' variable -->
<goal name="plugin:generate-navigation"
description="Generate navigation.xml for the plugin">
<j:set var="skip" value="false" />
<j:set var="fileName">${maven.docs.src}/navigation.xml</j:set>
<u:available file="${fileName}">
<echo>Skipping file as '${fileName}' already exists</echo>
<j:set var="skip" value="true" />
</u:available>
<j:if test="${!skip}">
<mkdir dir="${maven.docs.src}" />
<echo>Generating file '${fileName}'</echo>
<j:file name="${fileName}" prettyPrint="true">
<j:import file="${plugin.resources}/templates/navigation.jelly" inherit="true"/>
</j:file>
</j:if>
</goal>
<!-- generate a skeletal goals.xml for the plugin specified -->
<goal name="plugin:generate-goals"
description="Generate goals.xml for the plugin">
<j:set var="skip" value="false" />
<j:set var="fileName">${maven.docs.src}/goals.xml</j:set>
<u:available file="${fileName}">
<echo>Skipping file as '${fileName}' already exists</echo>
<j:set var="skip" value="true" />
</u:available>
<j:if test="${!skip}">
<j:set var="pluginScript" value="false" />
<u:available file="${basedir}/plugin.jelly">
<j:set var="pluginScript" value="true" />
</u:available>
<mkdir dir="${maven.docs.src}" />
<j:if test="${!pluginScript}">
<!-- no plugin.jelly - generate a file for empty goals -->
<echo>Generating 'empty' goals file '${fileName}'</echo>
<j:set var="template" value="${plugin.resources}/templates/goals-empty.jelly" />
</j:if>
<j:if test="${pluginScript}">
<!-- generate docs based on plugin.jelly -->
<u:file name="${basedir}/plugin.jelly" var="script" />
<x:parse xml="${script}" var="def"/>
<echo>Generating file '${fileName}'</echo>
<j:set var="template" value="${plugin.resources}/templates/goals.jelly"/>
</j:if>
<j:file name="${fileName}" prettyPrint="true">
<j:import file="${template}" inherit="true"/>
</j:file>
</j:if>
</goal>
<!-- generate properties documentation -->
<goal name="plugin:generate-properties"
description="Generate properties.xml for the plugin">
<j:set var="skip" value="false" />
<j:set var="fileName">${maven.docs.src}/properties.xml</j:set>
<u:available file="${fileName}">
<echo>Skipping file as '${fileName}' already exists</echo>
<j:set var="skip" value="true" />
</u:available>
<j:if test="${!skip}">
<j:set var="props" value="false"/>
<j:set var="propsFileName">${basedir}/plugin.properties</j:set>
<u:available file="${propsFileName}">
<j:set var="props" value="true" />
</u:available>
<j:if test="${!props}">
<echo>Generating 'empty' properties file '${fileName}'</echo>
<j:set var="template" value="${plugin.resources}/templates/properties-empty.jelly"/>
</j:if>
<j:if test="${props}">
<echo>Generating file '${fileName}'</echo>
<j:scope>
<u:properties file="${propsFileName}" />
<j:set var="vars" value="${context.variables}" scope="parent"/>
</j:scope>
<j:set var="template" value="${plugin.resources}/templates/properties.jelly"/>
</j:if>
<mkdir dir="${maven.docs.src}" />
<j:file name="${fileName}" prettyPrint="true">
<j:import file="${template}" inherit="true"/>
</j:file>
</j:if>
</goal>
<!-- generate a skeletal tags.xml for the plugin specified -->
<goal name="plugin:generate-tags"
description="Generate tags.xml for the plugin">
<j:set var="skip" value="false" />
<j:set var="fileName">${maven.docs.src}/tags.xml</j:set>
<u:available file="${fileName}">
<echo>Skipping file as '${fileName}' already exists</echo>
<j:set var="skip" value="true" />
</u:available>
<j:if test="${!skip}">
<j:set var="pluginScript" value="false" />
<u:available file="${basedir}/plugin.jelly">
<j:set var="pluginScript" value="true" />
</u:available>
<mkdir dir="${maven.docs.src}" />
<j:if test="${!pluginScript}">
<!-- no plugin.jelly - generate a file for empty goals -->
<echo>No plugin.jelly, not generating tags.xml</echo>
</j:if>
<j:if test="${pluginScript}">
<echo>Generating file '${fileName}'</echo>
<!-- generate docs based on plugin.jelly -->
<j:useBean class="org.apache.maven.plugin.PluginToTags"
pluginScript="${basedir}/plugin.jelly"
xdoc="${fileName}"
var="xformer"/>
${xformer.transform()}
</j:if>
</j:if>
</goal>
<goal name="plugin:download" description="download and install a plugin from a remote repo" prereqs="plugin:download-artifact">
<plugin:uninstall name="${artifactId}" />
<u:file var="localPlugin" name="${maven.plugin.dir}/${artifactId}-${version}.jar" />
<ant:copy file="${localPluginFile}" tofile="${localPlugin}" />
</goal>
<!-- download a plugin from a remote repo -->
<goal name="plugin:download-artifact" description="download a plugin from a remote repo">
<j:if test="${empty(artifactId)}">
<i:ask question="What is the artifactId of the plugin to download (e.g. maven-java-plugin)?"
answer="artifactId"/>
</j:if>
<maven:param-check value="${artifactId}" fail="true" message="'artifactId' must be specified"/>
<j:if test="${empty(groupId)}">
<i:ask question="What is the groupId of the plugin to download?"
answer="groupId"
default="maven"/>
</j:if>
<maven:param-check value="${groupId}" fail="true" message="'groupId' must be specified"/>
<j:if test="${empty(version)}">
<i:ask question="What is the version of the plugin to download?"
answer="version"/>
</j:if>
<maven:param-check value="${version}" fail="true" message="'version' must be specified"/>
<u:file var="localPluginFile"
name="${maven.repo.local}/${groupId}/plugins/${artifactId}-${version}.jar" />
<j:if test="${(!localPluginFile.exists()) or (localPluginFile.name.indexOf('SNAPSHOT') != '-1')}">
<ant:mkdir dir="${maven.repo.local}/${groupId}/plugins" />
<j:set var="repoList">${maven.repo.remote}</j:set>
<u:tokenize var="repos" delim=",">${repoList.trim()}</u:tokenize>
<j:forEach var="repo" items="${repos}">
<echo>repo is '${repo}'</echo>
<j:set var="remoteFile"
value="${repo}/${groupId}/plugins/${artifactId}-${version}.jar" />
<echo>trying to download ${remoteFile}</echo>
<j:catch var="ex">
<j:invokeStatic var="dummy" method="getFile"
className="org.apache.maven.util.HttpUtils">
<j:arg type="java.lang.String" value="${remoteFile}" />
<j:arg type="java.io.File" value="${localPluginFile}"/>
<j:arg type="boolean" value="false"/>
<j:arg type="boolean" value="true"/>
<j:arg type="java.lang.String" value="${maven.proxy.host}" />
<j:arg type="java.lang.String" value="${maven.proxy.port}" />
<j:arg type="java.lang.String" value="${maven.proxy.username}" />
<j:arg type="java.lang.String" value="${maven.proxy.password}" />
<j:arg type="java.lang.String" value="${maven.proxy.ntlm.host}" />
<j:arg type="java.lang.String" value="${maven.proxy.ntlm.domain}" />
<j:arg type="boolean" value="false"/>
</j:invokeStatic>
</j:catch>
<j:break test="${localPluginFile.exists() and (localPluginFile.name.indexOf('SNAPSHOT') == '-1')}"/>
</j:forEach>
</j:if>
<j:set var="downloaded" value="${localPluginFile.exists()}"/>
<j:if test="${!downloaded}">
<ant:fail message="Unable to find plug-in" />
</j:if>
</goal>
<!--
========================================================================
Goals and tags used for testing Maven plugins.
========================================================================
-->
<!-- test a plugin -->
<goal name="plugin:test" description="Run a plugin's test project">
<u:available file="${basedir}/${maven.plugin.test.dir}/project.xml">
<maven:maven
descriptor="${basedir}/${maven.plugin.test.dir}/project.xml"
goals="testPlugin"
ignoreFailures="false" />
</u:available>
</goal>
<goal name="plugin:repository-install" prereqs="plugin:plugin"
description="install a plugin into the local repository">
<artifact:install
artifact="${maven.build.dir}/${maven.final.name}.jar"
type="plugin"
project="${pom}"
/>
</goal>
<goal name="plugin:repository-install-snapshot" prereqs="plugin:plugin"
description="install a plugin snapshot into the local repository">
<artifact:install-snapshot
artifact="${maven.build.dir}/${maven.final.name}.jar"
type="plugin"
project="${pom}"
/>
</goal>
<goal name="plugin:repository-deploy" prereqs="plugin:plugin"
description="deploy a plugin into the remote repository">
<artifact:deploy
artifact="${maven.build.dir}/${maven.final.name}.jar"
type="plugin"
project="${pom}"
/>
</goal>
<goal name="plugin:repository-deploy-snapshot" prereqs="plugin:plugin"
description="deploy a plugin snapshot into the remote repository">
<artifact:deploy-snapshot
artifact="${maven.build.dir}/${maven.final.name}.jar"
type="plugin"
project="${pom}"
/>
</goal>
</project>