Customize Liferay SDK plugins(portlet) to Maven project

In our case, we use maven portlet instead of default ant portlet, every time we need to modify. What I do is to create our own template and read properties file to create the project.

Here is my example:

build.xml

<?xml version="1.0"?>
<!DOCTYPE project>


<project name="portlets" basedir="." default="deploy" xmlns:antelope="antlib:ise.antelope.tasks">
	<property name="project.dir" value=".." />


	<import file="../build-common-plugins.xml" />


	<target name="create">
		<if>
			
			<not>
				<isset property="properties.file.name" />
			</not>
			<then>
				<echo message="This task must be called by create.bat." />
			</then>
			<else>
				<if>
					<not>
						<available file="${properties.file.name}"/>
					</not>
					<then>
						<fail>${properties.file.name} doesn't exist.</fail>
					</then>
				</if>


				<property file="${properties.file.name}"/>
				
				<if>
					<or>
						<equals arg1="${portlet.name}" arg2="" />
						<equals arg1="${portlet.display.name}" arg2="" />
					</or>
					<then>
						<fail>portlet.name or portlet.display.name isn't set</fail>
					</then>
				</if>
				
				<if>
					<not>
						<isset property="portlet.parent.dir" />
					</not>
					<then>
						<property name="portlet.parent.dir" value="${basedir}" />
					</then>
				</if>
				
				<property name="portlet.dir" value="${portlet.parent.dir}/${portlet.name}-portlet" />


				<if>
					<available file="${portlet.dir}" />
					<then>
						<fail>${portlet.dir} already exists.</fail>
					</then>
				</if>
				<!-- my_portlet_tmpl is a spring maven tmpl -->
				<copy todir="${portlet.dir}">
					<fileset dir="${project.dir}/tools/my_portlet_tmpl" />
				</copy>
				
				<antelope:stringutil string="${portlet.display.name}" property="portlet.java.class.name">
					<antelope:replace regex="\s+" replacement="" />
					<antelope:trim />
				</antelope:stringutil>


				<antelope:stringutil string="${portlet.name}" property="portlet.java.package.name">
					<antelope:replace regex="-" replacement="" />
					<antelope:trim />
				</antelope:stringutil>
				<replace dir="${portlet.dir}">
					<replacefilter token="@portlet.name@" value="${portlet.name}" />
					<replacefilter token="@portlet.display.name@" value="${portlet.display.name}" />
					<replacefilter token="@portlet.java.class.name@" value="${portlet.java.class.name}" />
					<replacefilter token="@portlet.java.package.name@" value="${portlet.java.package.name}" />
				</replace>
				
				<mkdir dir="${portlet.dir}/src/main/webapp/WEB-INF/tld" />


				<copy todir="${portlet.dir}/src/main/webapp/WEB-INF/tld">
					<fileset dir="${app.server.portal.dir}/WEB-INF/tld">
						<include name="aui.tld" />
						<include name="liferay-faces.tld" />
						<include name="liferay-portlet.tld" />
						<include name="liferay-portlet-ext.tld" />
						<include name="liferay-security.tld" />
						<include name="liferay-theme.tld" />
						<include name="liferay-ui.tld" />
						<include name="liferay-util.tld" />
					</fileset>
				</copy>
			</else>
		</if>
	</target>
</project>

create.bat

@echo off

if "" == "%1" goto errorCreate

call ant -Dproperties.file.name=%1 create

rem call ant deploy

goto end

:errorCreate
	echo.
	echo Usage: create.bat build.properties
	echo e.g. build.properties
	echo portlet.name=First
	echo portlet.display.name=First Portlet
	echo.
	echo The first hello-world is your portlet id. A new directory will be created based
	echo on the portlet id.
	echo.

:end



你可能感兴趣的:(maven,maven,ant,ant,ant,liferay,liferay,portlet,tmpl)