Tuesday 12 November 2013

How can I get a list of all the implementations of an interface programmatically in Java?


Polymorphism



Polymorphism

When one action is performed by different ways i.e. known as polymorphism. For example: to convense the customer differently, to draw something e.g. shape or rectangle etc.
In java, we use method overloading and method overriding to achieve polymorphism.
Another example can be to speak something e.g. cat speaks meaw, dog barks woof etc.

Saturday 9 November 2013

How to know from where a Class was loaded in Java

import java.security.ProtectionDomain;
import java.io.*;
public class CodeLoc
{
    public void codeLoc()
    {
        ProtectionDomain protectionDomain = getClass().getProtectionDomain();
        File codeLoc = new File(protectionDomain.getCodeSource().getLocation().getFile());
        System.out.println("--------codeLoc="+codeLoc);
    }
    public static void main(String []args)
    {
        CodeLoc cl=new CodeLoc();
        cl.codeLoc();
    }
}

Sunday 3 November 2013

Apply liferay search indexer to custom portlets

Please follow the steps given below if you want , Your custom portlets data to be search by Liferay search portlet.

1.Create custom indexer class that extends BaseIndexer.

2.Make custom class indexer entry in liferay-portlet.xml for example,just beneath <icon> tag.

3.Write codes mentioned below in xxxabcLocalServiceImpl class methods ,for example add,delete .

Indexer indexer = IndexerRegistryUtil.getIndexer(xxxabc.class);

for add and update method

indexer.reindex(object of class);

for delete method you should write like

indexer.delete(object of class);

4.Now deploy your portlet and goto Liferay Portal.

5.Add search portlet to page.

6.Click on search portlet configuration.

7.Click on advance button.

8.Add your model name as already entered there, for example BlogsEntry,DLFileEntry.

Wednesday 23 October 2013

Liferay use custom data source instead of liferay default data source via spring-ext.xml updation

Please find the below sample code liferay to use our custom data source. Add/update spring-ext.xml file with below code:



<bean id="testDataSourceTarget" class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName">
<value>jdbc/test</value>
</property>
</bean>
<bean id="testDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
<property name="targetDataSource">
<ref bean="testDataSourceTarget" />
</property>
</bean>
<bean id="testSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
<property name="dataSource" ref="testDataSource" />
<property name="sessionFactoryClassLoader" ref="portletClassLoader" />
<property name="sessionFactoryImplementor" ref="testHibernateSessionFactory" />
</bean>
<bean id="testHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="testDataSource" />
</bean>
<bean id="testTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="dataSource">
<ref bean="testDataSource" />
</property>
<property name="sessionFactory">
<ref bean="testHibernateSessionFactory" />
</property>
</bean>

Monday 16 September 2013

Rebuild SOLR indexes in Alfresco 4.x

Steps to rebuild SOLR indexes:

1) Stop the Server.

2) Remove two folders named “index” and “spellchecker” in “ALFRESCO/alf_data/solr/workspace/SpacesStore/” path.

3) Remove two folders named “index” and “spellchecker” in “ALFRESCO/alf_data/solr/archive/SpacesStore/” path.

4) Start the Server.

By default, the SOLR indexes are stored in
“ALFRESCO/alf_data/solr/workspace/SpacesStore/” path for workspace-SpacesStore and “ALFRESCO/alf_data/solr/archive/SpacesStore/” path for archive-SpacesStore.

Each store has its own index directory defined by property ${data.dir.root}/${data.dir.store} in solrcore.properties file.

To change the index location for both stores, edit the
solrcore.properties file:
  • SOLR/workspace-SpacesStore/conf/solrcore.properties
  • SOLR/archive-SpacesStore/conf/solrcore.properties

Set the data.dir.root property to the location where the SOLR indexes will be stored. You can also set the same value for the both stores, and the stores will create the sub-directories.

Eg:
1)  For workspace-SpaceStore, edit SOLR/workspace-SpacesStore/conf/solrcore.properties file
data.dir.root=/mnt/data-store/solr-indexes
data.dir.store=workspace/SpacesStore

2) For archive-SpaceStore, edit SOLR/archive-SpacesStore/conf/solrcore.properties
data.dir.root=/mnt/data-store/solr-indexes
data.dir.store=archive/SpacesStore

NOTE: The index.recovery.mode=FULL property is not used by SOLR Engine.

Saturday 29 June 2013

To avoid resubmit of liferay action url

Problem: Click on an actionURL and action is successfully completed and page gets displayed on the browser. Click on refresh button again the same action gets called and performs the action again.
Resolution: set a tag value in liferay-portlet.xml
<action-url-redirect>true</action-url-redirect>
by default the value of this tag is false.
Note: it’s not a substitute to open another jsp page after completing the action.

Monday 27 May 2013

Device detection

Device device = DeviceDetectionUtil.detectDevice(request);

Sunday 5 May 2013

build multiple service xml files via build-common-pluginxml modification

To build multiple service xml files modify build-common-plugin.xml. Plz find modified build-common-plugin.xml of Liferay 6.1.20--ce-GA2.

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

<project name="build-common-plugin" xmlns:antelope="antlib:ise.antelope.tasks">
    <import file="build-common.xml" />
    <property name="service.dir" value="${basedir}/docroot/WEB-INF" />
    <if>
        <available file="docroot/WEB-INF/liferay-plugin-package.properties" />
        <then>
            <property file="docroot/WEB-INF/liferay-plugin-package.properties" prefix="plugin-package" />

            <property name="plugin.version" value="${plugin-package.module-incremental-version}" />
            <property name="plugin.jars" value="${plugin-package.portal-dependency-jars}" />
            <property name="plugin.tlds" value="${plugin-package.portal-dependency-tlds}" />
        </then>
    </if>

    <antelope:stringutil string="${basedir}" property="plugin.name.beginindex">
        <antelope:lastindexof string="${file.separator}" />
    </antelope:stringutil>

    <antelope:math
        datatype="int"
        operand1="${plugin.name.beginindex}"
        operand2="1"
        operation="+"
        result="plugin.name.beginindex"
    />

    <antelope:stringutil string="${basedir}" property="plugin.name">
        <antelope:substring beginindex="${plugin.name.beginindex}" />
    </antelope:stringutil>

    <if>
        <antelope:endswith string="${plugin.name}" with="-client" />
        <then>
            <property name="plugin.file" value="${project.dir}/dist/${plugin.name}-${lp.version}.${plugin.version}${lp.version.file.suffix}.jar" />
            <property name="plugin.src.file" value="${project.dir}/dist/${plugin.name}-src-${lp.version}.${plugin.version}${lp.version.file.suffix}.zip" />
        </then>
        <else>
            <property name="plugin.file" value="${project.dir}/dist/${plugin.name}-${lp.version}.${plugin.version}${lp.version.file.suffix}.war" />
            <property name="plugin.src.file" value="${project.dir}/dist/${plugin.name}-src-${lp.version}.${plugin.version}${lp.version.file.suffix}.zip" />
        </else>
    </if>

    <target name="all">
        <antcall target="clean" />
        <antcall target="deploy" />
    </target>

    <target name="build-client">
        <property name="client.url" value="http://localhost:8080/${plugin.name}/api/axis" />

        <echo message="Make sure the server is listening on ${client.url}." />
        <echo message="" />

        <mkdir dir="docroot/WEB-INF/client/src" />

        <java
            classname="com.liferay.portal.tools.PortalClientBuilder"
            classpathref="portal.classpath"
            failonerror="true"
            fork="true"
            newenvironment="true"
        >
            <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
            <arg value="docroot/WEB-INF/server-config.wsdd" />
            <arg value="docroot/WEB-INF/client/src" />
            <arg value="docroot/WEB-INF/client/namespace-mapping.properties" />
            <arg value="${client.url}" />
        </java>

        <mkdir dir="docroot/WEB-INF/client/classes" />

        <antcall target="compile-java">
            <param name="javac.classpathref" value="portal.classpath" />
            <param name="javac.destdir" value="docroot/WEB-INF/client/classes" />
            <param name="javac.srcdir" value="docroot/WEB-INF/client/src" />
        </antcall>

        <zip destfile="docroot/WEB-INF/client/${plugin.name}-client.jar">
            <fileset dir="docroot/WEB-INF/client/classes" />
            <fileset dir="docroot/WEB-INF/client/src" />
        </zip>

        <delete dir="docroot/WEB-INF/client/classes" />
        <delete dir="docroot/WEB-INF/client/src" />
    </target>

    <target name="build-db">
        <java
            classname="com.liferay.portal.tools.DBBuilder"
            classpathref="portal.classpath"
            fork="true"
            maxmemory="384m"
            newenvironment="true"
        >
            <arg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
            <arg value="db.database.name=${database.name}" />
            <arg value="db.database.types=${database.types}" />
            <arg value="db.sql.dir=docroot/WEB-INF/sql" />
        </java>

        <delete file="velocity.log" quiet="true" />
    </target>

    <target name="build-lang">
        <antcall target="build-lang-cmd">
            <param name="lang.dir" value="docroot/WEB-INF/src/content" />
            <param name="lang.file" value="Language" />
            <param name="lang.translate" value="true" />
        </antcall>
    </target>

    <target name="build-lang-cmd">
        <java
            classname="com.liferay.portal.tools.LangBuilder"
            classpathref="portal.classpath"
            fork="true"
            newenvironment="true"
        >
            <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
            <jvmarg value="-Dfile.encoding=UTF-8" />
            <jvmarg value="-Duser.country=US" />
            <jvmarg value="-Duser.language=en" />
            <arg value="lang.dir=${lang.dir}" />
            <arg value="lang.file=${lang.file}" />
            <arg value="lang.plugin=true" />
            <arg value="lang.translate=${lang.translate}" />
        </java>

        <copy file="${lang.dir}/${lang.file}.properties" tofile="${lang.dir}/${lang.file}_en.properties" />
    </target>
    <!-- Custom service build start here -->
    <target name="build-service">
        <foreach target="build-service-liferay" param="service.input.file" inheritall="true" inheritrefs="true">
            <path>   
                <fileset dir="${service.dir}" includes="**/service**.xml" excludes="**/classess**/service*.xml" erroronmissingdir="false"></fileset>
            </path>
        </foreach>
    </target>
    <!-- END -->
    <target name="build-service-liferay">
        <mkdir dir="docroot/WEB-INF/classes" />
        <mkdir dir="docroot/WEB-INF/lib" />
        <mkdir dir="docroot/WEB-INF/service" />
        <mkdir dir="docroot/WEB-INF/sql" />
        <mkdir dir="docroot/WEB-INF/src" />

        <copy todir="docroot/WEB-INF/classes">
            <fileset dir="docroot/WEB-INF/src" excludes="**/*.java" />
        </copy>

        <path id="service.classpath">
            <path refid="lib.classpath" />
            <path refid="portal.classpath" />
            <fileset dir="${app.server.lib.portal.dir}" includes="commons-digester.jar,commons-lang.jar,easyconf.jar" />
            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
            <pathelement location="docroot/WEB-INF/classes" />
        </path>

        <if>
            <not>
                <isset property="service.input.file" />
            </not>
            <then>
                <property name="service.input.file" value="${basedir}/docroot/WEB-INF/service.xml" />
            </then>
        </if>

        <java
            classname="com.liferay.portal.tools.servicebuilder.ServiceBuilder"
            classpathref="service.classpath"
            fork="true"
            newenvironment="true"
            outputproperty="service.test.output"
        >
            <jvmarg value="-Xms128m" />
            <jvmarg value="-Xmx512m" />
            <jvmarg value="-Xss2048k" />
            <jvmarg value="-XX:MaxPermSize=512m" />
            <arg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
            <arg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger" />
            <arg value="service.input.file=${service.input.file}" />
            <arg value="service.hbm.file=${basedir}/docroot/WEB-INF/src/META-INF/portlet-hbm.xml" />
            <arg value="service.orm.file=${basedir}/docroot/WEB-INF/src/META-INF/portlet-orm.xml" />
            <arg value="service.model.hints.file=${basedir}/docroot/WEB-INF/src/META-INF/portlet-model-hints.xml" />
            <arg value="service.spring.file=${basedir}/docroot/WEB-INF/src/META-INF/portlet-spring.xml" />
            <arg value="service.spring.base.file=${basedir}/docroot/WEB-INF/src/META-INF/base-spring.xml" />
            <arg value="service.spring.cluster.file=${basedir}/docroot/WEB-INF/src/META-INF/cluster-spring.xml" />
            <arg value="service.spring.dynamic.data.source.file=${basedir}/docroot/WEB-INF/src/META-INF/dynamic-data-source-spring.xml" />
            <arg value="service.spring.hibernate.file=${basedir}/docroot/WEB-INF/src/META-INF/hibernate-spring.xml" />
            <arg value="service.spring.infrastructure.file=${basedir}/docroot/WEB-INF/src/META-INF/infrastructure-spring.xml" />
            <arg value="service.spring.shard.data.source.file=${basedir}/docroot/WEB-INF/src/META-INF/shard-data-source-spring.xml" />
            <arg value="service.api.dir=${basedir}/docroot/WEB-INF/service" />
            <arg value="service.impl.dir=${basedir}/docroot/WEB-INF/src" />
            <arg value="service.json.file=${basedir}/docroot/js/service.js" />
            <arg value="service.sql.dir=${basedir}/docroot/WEB-INF/sql" />
            <arg value="service.sql.file=tables.sql" />
            <arg value="service.sql.indexes.file=indexes.sql" />
            <arg value="service.sql.indexes.properties.file=indexes.properties" />
            <arg value="service.sql.sequences.file=sequences.sql" />
            <arg value="service.auto.namespace.tables=true" />
            <arg value="service.bean.locator.util=com.liferay.util.bean.PortletBeanLocatorUtil" />
            <arg value="service.props.util=com.liferay.util.service.ServiceProps" />
            <arg value="service.plugin.name=${plugin.name}" />
            <arg value="service.target.entity.name=${service.target.entity.name}" />
        </java>

        <echo>${service.test.output}</echo>

        <if>
            <contains string="${service.test.output}" substring="Error" />
            <then>
                <fail>Service Builder generated exceptions.</fail>
            </then>
        </if>

        <delete file="ServiceBuilder.temp" />

        <mkdir dir="docroot/WEB-INF/service-classes" />

        <path id="service.classpath">
            <fileset dir="${app.server.lib.global.dir}" includes="*.jar" />
            <fileset dir="${project.dir}/lib" includes="activation.jar,jsp-api.jar,mail.jar,servlet-api.jar" />
            <fileset dir="docroot/WEB-INF/lib" excludes="${plugin.name}-service.jar" includes="*.jar" />
        </path>

        <antcall target="compile-java">
            <param name="javac.classpathref" value="service.classpath" />
            <param name="javac.destdir" value="docroot/WEB-INF/service-classes" />
            <param name="javac.srcdir" value="docroot/WEB-INF/service" />
            <reference refid="service.classpath" torefid="service.classpath" />
        </antcall>

        <zip
            basedir="docroot/WEB-INF/service-classes"
            destfile="docroot/WEB-INF/lib/${plugin.name}-service.jar"
        />

        <delete dir="docroot/WEB-INF/service-classes" />
    </target>

    <target name="build-wsdd" depends="compile">
        <path id="wsdd.classpath">
            <path refid="lib.classpath" />
            <path refid="portal.classpath" />
            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
            <pathelement location="docroot/WEB-INF/classes" />
        </path>

        <java
            classname="com.liferay.portal.tools.WSDDBuilder"
            classpathref="wsdd.classpath"
            fork="true"
            maxmemory="256m"
            newenvironment="true"
        >
            <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
            <jvmarg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger" />
            <arg value="wsdd.input.file=docroot/WEB-INF/service.xml" />
            <arg value="wsdd.server.config.file=docroot/WEB-INF/server-config.wsdd" />
            <arg value="wsdd.service.namespace=Plugin" />
            <arg value="wsdd.output.path=docroot/WEB-INF/src/" />
        </java>
    </target>

    <target name="build-wsdl">
        <for param="wsdl.full.path">
            <path>
                <fileset dir="." includes="docroot/WEB-INF/wsdl/*.wsdl" />
            </path>
            <sequential>
                <tstamp>
                    <format property="tstamp.value" pattern="yyyyMMddkkmmssSSS" />
                </tstamp>

                <mkdir dir="${tstamp.value}" />

                <taskdef classpathref="portal.classpath" resource="axis-tasks.properties" />

                <axis-wsdl2java
                    output="${tstamp.value}"
                    url="@{wsdl.full.path}"
                />

                <path id="plugin-lib.classpath">
                    <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                    <pathelement location="docroot/WEB-INF/classes" />
                </path>

                <antcall target="compile-java">
                    <param name="javac.classpathref" value="plugin.classpath" />
                    <param name="javac.destdir" value="${tstamp.value}" />
                    <param name="javac.srcdir" value="${tstamp.value}" />
                    <reference refid="plugin-lib.classpath" torefid="plugin-lib.classpath" />
                </antcall>

                <antelope:stringutil string="@{wsdl.full.path}" property="wsdl.name.beginindex">
                    <antelope:lastindexof string="${file.separator}" />
                </antelope:stringutil>

                <antelope:math
                    datatype="int"
                    operand1="${wsdl.name.beginindex}"
                    operand2="1"
                    operation="+"
                    result="wsdl.name.beginindex"
                />

                <antelope:stringutil string="@{wsdl.full.path}" property="wsdl.file">
                    <antelope:substring beginindex="${wsdl.name.beginindex}" />
                </antelope:stringutil>

                <antelope:stringutil string="@{wsdl.full.path}" property="wsdl.name.endindex">
                    <antelope:lastindexof string="." />
                </antelope:stringutil>

                <antelope:stringutil string="@{wsdl.full.path}" property="wsdl.name">
                    <antelope:substring beginindex="${wsdl.name.beginindex}" endindex="${wsdl.name.endindex}" />
                </antelope:stringutil>

                <jar
                    basedir="${tstamp.value}"
                    jarfile="docroot/WEB-INF/lib/${wsdl.name}-ws.jar"
                />

                <delete dir="${tstamp.value}" />
            </sequential>
        </for>
    </target>

    <target name="build-xsd">
        <tstamp>
            <format property="tstamp.value" pattern="yyyyMMddkkmmssSSS" />
        </tstamp>

        <mkdir dir="${tstamp.value}" />

        <path id="plugin-lib.classpath">
            <fileset dir="${app.server.lib.portal.dir}" includes="xbean.jar" />
            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
            <pathelement location="docroot/WEB-INF/classes" />
        </path>

        <taskdef classname="org.apache.xmlbeans.impl.tool.XMLBean" classpathref="portal.classpath" name="xmlbean" />

        <xmlbean
            classgendir="${tstamp.value}"
            classpathref="plugin-lib.classpath"
            srcgendir="${tstamp.value}"
        >
            <fileset dir="docroot/WEB-INF/xsd" includes="**/*.*" />
        </xmlbean>

        <zip
            basedir="${tstamp.value}"
            destfile="docroot/WEB-INF/lib/${plugin.name}-xbean.jar"
        />

        <delete dir="${tstamp.value}" />
    </target>

    <target name="clean" description="clean">
        <delete dir="docroot/WEB-INF/classes" />

        <if>
            <and>
                <available file="docroot/WEB-INF/.gitignore" />
            </and>
            <then>
                <loadfile property=".gitignore.content" srcFile="docroot/WEB-INF/.gitignore" />

                <if>
                    <contains string="${.gitignore.content}" substring="/lib" />
                    <then>
                        <delete dir="docroot/WEB-INF/lib" />
                    </then>
                </if>
            </then>
        </if>

        <if>
            <and>
                <available file="docroot/WEB-INF/.svn" />
                <not>
                    <available file="docroot/WEB-INF/lib/.svn" />
                </not>
            </and>
            <then>
                <delete dir="docroot/WEB-INF/lib" />
            </then>
        </if>

        <delete dir="test-classes" />
        <delete dir="test-results" />
        <delete dir="tmp" />
        <delete file="${plugin.file}" />
        <delete file="${plugin.src.file}" />

        <delete includeemptydirs="true">
            <fileset dir="docroot" includes="**/.sass-cache/**" />
            <fileset dir="docroot" includes="**/.sprite.png" />
            <fileset dir="docroot" includes="**/.sprite.properties" />
            <fileset dir="docroot" includes="**/Thumbs.db" />
        </delete>

        <antcall target="clean-portal-dependencies" />
    </target>

    <target name="clean-portal-dependencies">
        <if>
            <available file="docroot/WEB-INF/lib" />
            <then>
                <delete>
                    <fileset dir="docroot/WEB-INF/lib" includes="${required.portal.jars}" />
                    <fileset dir="docroot/WEB-INF/lib" includes="${plugin.jars}" />
                </delete>
            </then>
        </if>

        <if>
            <available file="docroot/WEB-INF/tld" />
            <then>
                <delete>
                    <fileset dir="docroot/WEB-INF/tld" includes="${plugin.tlds}" />
                </delete>
            </then>
        </if>

        <if>
            <available file="tmp/WEB-INF/lib" />
            <then>
                <delete>
                    <fileset dir="tmp/WEB-INF/lib" includes="${required.portal.jars}" />
                    <fileset dir="tmp/WEB-INF/lib" includes="${plugin.jars}" />
                </delete>
            </then>
        </if>

        <if>
            <available file="tmp/WEB-INF/tld" />
            <then>
                <delete>
                    <fileset dir="tmp/WEB-INF/tld" includes="${plugin.tlds}" />
                </delete>
            </then>
        </if>
    </target>

    <target name="compile">
        <antcall target="merge" />

        <mkdir dir="docroot/WEB-INF/classes" />
        <mkdir dir="docroot/WEB-INF/lib" />

        <copy todir="docroot/WEB-INF/lib">
            <fileset dir="${app.server.lib.portal.dir}" includes="${plugin.jars}" />
        </copy>

        <if>
            <isset property="plugin-package.required-deployment-contexts" />
            <then>
                <for list="${plugin-package.required-deployment-contexts}" param="required.deployment.context">
                    <sequential>
                        <if>
                            <available file="${project.dir}/hooks/@{required.deployment.context}/docroot/WEB-INF/lib/@{required.deployment.context}-service.jar" />
                            <then>
                                <copy
                                    file="${project.dir}/hooks/@{required.deployment.context}/docroot/WEB-INF/lib/@{required.deployment.context}-service.jar"
                                    todir="docroot/WEB-INF/lib"
                                    overwrite="true"
                                />
                            </then>
                            <elseif>
                                <available file="${project.dir}/portlets/@{required.deployment.context}/docroot/WEB-INF/lib/@{required.deployment.context}-service.jar" />
                                <then>
                                    <copy
                                        file="${project.dir}/portlets/@{required.deployment.context}/docroot/WEB-INF/lib/@{required.deployment.context}-service.jar"
                                        todir="docroot/WEB-INF/lib"
                                        overwrite="true"
                                    />
                                </then>
                            </elseif>
                            <elseif>
                                <available file="${project.dir}/webs/@{required.deployment.context}/docroot/WEB-INF/lib/@{required.deployment.context}-service.jar" />
                                <then>
                                    <copy
                                        file="${project.dir}/webs/@{required.deployment.context}/docroot/WEB-INF/lib/@{required.deployment.context}-service.jar"
                                        todir="docroot/WEB-INF/lib"
                                        overwrite="true"
                                    />
                                </then>
                            </elseif>
                        </if>
                    </sequential>
                </for>
            </then>
        </if>

        <copy todir="docroot/WEB-INF/tld">
            <fileset dir="${app.server.portal.dir}/WEB-INF/tld" includes="${plugin.tlds}" />
        </copy>

        <if>
            <available file="docroot/WEB-INF/src" />
            <then>
                <if>
                    <available file="tmp" />
                    <then>
                        <path id="plugin-lib.classpath">
                            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                            <fileset dir="tmp/WEB-INF/lib" includes="*.jar" />
                            <pathelement location="docroot/WEB-INF/classes" />
                            <pathelement location="tmp/WEB-INF/classes" />
                        </path>
                    </then>
                    <else>
                        <path id="plugin-lib.classpath">
                            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                            <pathelement location="docroot/WEB-INF/classes" />
                        </path>
                    </else>
                </if>

                <copy todir="docroot/WEB-INF/lib">
                    <fileset dir="${app.server.lib.portal.dir}" includes="${required.portal.jars}" />
                </copy>

                <if>
                    <available file="docroot/WEB-INF/lib/portal-impl.jar" />
                    <then>
                        <fail>
.

Detected inclusion of portal-impl.jar in WEB-INF/lib.

portal-impl.jar is designed with a large number of singleton classes which are
instantiated on the basis that they will exist alone in the application server.

While compile time issues may be resolved, portlets cannot be made to work by
simply adding portal-impl.jar, because doing so violates the above assumption,
and the resulting problems will be extremely difficult to debug.

Please find a solution that does not require portal-impl.jar.
                        </fail>
                    </then>
                </if>

                <antcall target="compile-java">
                    <param name="javac.classpathref" value="plugin.classpath" />
                    <param name="javac.destdir" value="docroot/WEB-INF/classes" />
                    <param name="javac.srcdir" value="docroot/WEB-INF/src" />
                    <reference refid="plugin-lib.classpath" torefid="plugin-lib.classpath" />
                </antcall>
            </then>
        </if>

        <antcall target="merge" />
    </target>

    <target name="compile-test">
        <antcall target="compile-test-integration" inheritall="false" />
        <antcall target="compile-test-unit" inheritall="false" />
    </target>

    <target name="compile-test-cmd">
        <if>
            <available file="test/${test.type}" type="dir" />
            <then>
                <mkdir dir="test-classes/${test.type}" />
                <mkdir dir="test-results/${test.type}" />

                <copy todir="test-classes/${test.type}">
                    <fileset dir="test" includes="*.properties" />
                    <fileset dir="test/${test.type}" includes="**/*.png,**/*.properties,**/*.xml" />
                </copy>

                <if>
                    <available file="tmp" />
                    <then>
                        <path id="plugin-lib.classpath">
                            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                            <fileset dir="tmp/WEB-INF/lib" includes="*.jar" />
                            <pathelement location="docroot/WEB-INF/classes" />
                            <pathelement location="tmp/WEB-INF/classes" />
                        </path>
                    </then>
                    <else>
                        <path id="plugin-lib.classpath">
                            <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                            <pathelement location="docroot/WEB-INF/classes" />
                        </path>
                    </else>
                </if>

                <antcall target="compile-java">
                    <param name="javac.classpathref" value="test.classpath" />
                    <param name="javac.destdir" value="test-classes/${test.type}" />
                    <param name="javac.srcdir" value="test/${test.type}" />
                    <reference refid="plugin-lib.classpath" torefid="plugin-lib.classpath" />
                </antcall>
            </then>
        </if>
    </target>

    <target name="compile-test-integration">
        <ant target="compile-test-cmd">
            <property name="test.type" value="integration" />
        </ant>
    </target>

    <target name="compile-test-unit">
        <ant target="compile-test-cmd">
            <property name="test.type" value="unit" />
        </ant>
    </target>

    <target name="deploy" depends="war">
        <copy file="${plugin.file}" todir="${auto.deploy.dir}" />
    </target>

    <target name="direct-deploy" depends="war">
        <if>
            <antelope:endswith string="${plugin.name}" with="-ext" />
            <then>
                <java
                    classname="com.liferay.portal.tools.deploy.ExtDeployer"
                    classpathref="portal.classpath"
                    fork="true"
                    newenvironment="true"
                >

                    <!-- Required Arguments -->

                    <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                    <jvmarg value="-Dliferay.lib.portal.dir=${app.server.lib.portal.dir}" />
                    <jvmarg value="-Ddeployer.base.dir=${project.dir}/dist" />
                    <jvmarg value="-Ddeployer.dest.dir=${app.server.deploy.dir}" />
                    <jvmarg value="-Ddeployer.app.server.type=${app.server.type}" />
                    <jvmarg value="-Ddeployer.unpack.war=${auto.deploy.unpack.war}" />
                    <jvmarg value="-Ddeployer.file.pattern=${plugin.name}-*.war" />

                    <!-- Optional Arguments -->

                    <jvmarg value="-Ddeployer.tomcat.lib.dir=${app.server.tomcat.lib.global.dir}" />

                    <!-- Dependent Libraries -->

                    <arg value="${app.server.lib.portal.dir}/util-java.jar" />
                </java>
            </then>
            <elseif>
                <antelope:endswith string="${plugin.name}" with="-hook" />
                <then>
                    <java
                        classname="com.liferay.portal.tools.deploy.HookDeployer"
                        classpathref="portal.classpath"
                        fork="true"
                        newenvironment="true"
                    >

                        <!-- Required Arguments -->

                        <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                        <jvmarg value="-Dliferay.lib.portal.dir=${app.server.lib.portal.dir}" />
                        <jvmarg value="-Ddeployer.base.dir=${project.dir}/dist" />
                        <jvmarg value="-Ddeployer.dest.dir=${app.server.deploy.dir}" />
                        <jvmarg value="-Ddeployer.app.server.type=${app.server.type}" />
                        <jvmarg value="-Ddeployer.unpack.war=${auto.deploy.unpack.war}" />
                        <jvmarg value="-Ddeployer.file.pattern=${plugin.name}-*.war" />

                        <!-- Optional Arguments -->

                        <jvmarg value="-Ddeployer.tomcat.lib.dir=${app.server.tomcat.lib.global.dir}" />

                        <!-- Dependent Libraries -->

                        <arg value="${app.server.lib.portal.dir}/util-java.jar" />
                    </java>
                </then>
            </elseif>
            <elseif>
                <antelope:endswith string="${plugin.name}" with="-layouttpl" />
                <then>
                    <java
                        classname="com.liferay.portal.tools.deploy.LayoutTemplateDeployer"
                        classpathref="portal.classpath"
                        fork="true"
                        newenvironment="true"
                    >

                        <!-- Required Arguments -->

                        <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                        <jvmarg value="-Dliferay.lib.portal.dir=${app.server.lib.portal.dir}" />
                        <jvmarg value="-Ddeployer.base.dir=${project.dir}/dist" />
                        <jvmarg value="-Ddeployer.dest.dir=${app.server.deploy.dir}" />
                        <jvmarg value="-Ddeployer.app.server.type=${app.server.type}" />
                        <jvmarg value="-Ddeployer.unpack.war=${auto.deploy.unpack.war}" />
                        <jvmarg value="-Ddeployer.file.pattern=${plugin.name}-*.war" />
                    </java>
                </then>
            </elseif>
            <elseif>
                <antelope:endswith string="${plugin.name}" with="-portlet" />
                <then>
                    <java
                        classname="com.liferay.portal.tools.deploy.PortletDeployer"
                        classpathref="portal.classpath"
                        fork="true"
                        newenvironment="true"
                    >

                        <!-- Required Arguments -->

                        <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                        <jvmarg value="-Dliferay.lib.portal.dir=${app.server.lib.portal.dir}" />
                        <jvmarg value="-Ddeployer.base.dir=${project.dir}/dist" />
                        <jvmarg value="-Ddeployer.dest.dir=${app.server.deploy.dir}" />
                        <jvmarg value="-Ddeployer.app.server.type=${app.server.type}" />
                        <jvmarg value="-Ddeployer.aui.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/aui.tld" />
                        <jvmarg value="-Ddeployer.portlet.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-portlet.tld" />
                        <jvmarg value="-Ddeployer.portlet-ext.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-portlet-ext.tld" />
                        <jvmarg value="-Ddeployer.security.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-security.tld" />
                        <jvmarg value="-Ddeployer.theme.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-theme.tld" />
                        <jvmarg value="-Ddeployer.ui.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-ui.tld" />
                        <jvmarg value="-Ddeployer.util.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-util.tld" />
                        <jvmarg value="-Ddeployer.unpack.war=${auto.deploy.unpack.war}" />
                        <jvmarg value="-Ddeployer.custom.portlet.xml=${auto.deploy.custom.portlet.xml}" />
                        <jvmarg value="-Ddeployer.file.pattern=${plugin.name}-*.war" />

                        <!-- Optional Arguments -->

                        <jvmarg value="-Ddeployer.tomcat.lib.dir=${app.server.tomcat.lib.global.dir}" />

                        <!-- Dependent Libraries -->

                        <arg value="${app.server.lib.portal.dir}/util-bridges.jar" />
                        <arg value="${app.server.lib.portal.dir}/util-java.jar" />
                        <arg value="${app.server.lib.portal.dir}/util-taglib.jar" />
                    </java>
                </then>
            </elseif>
            <elseif>
                <antelope:endswith string="${plugin.name}" with="-theme" />
                <then>
                    <java
                        classname="com.liferay.portal.tools.deploy.ThemeDeployer"
                        classpathref="portal.classpath"
                        fork="true"
                        newenvironment="true"
                    >

                        <!-- Required Arguments -->

                        <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                        <jvmarg value="-Dliferay.lib.portal.dir=${app.server.lib.portal.dir}" />
                        <jvmarg value="-Ddeployer.base.dir=${project.dir}/dist" />
                        <jvmarg value="-Ddeployer.dest.dir=${app.server.deploy.dir}" />
                        <jvmarg value="-Ddeployer.app.server.type=${app.server.type}" />
                        <jvmarg value="-Ddeployer.theme.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-theme.tld" />
                        <jvmarg value="-Ddeployer.util.taglib.dtd=${app.server.portal.dir}/WEB-INF/tld/liferay-util.tld" />
                        <jvmarg value="-Ddeployer.unpack.war=${auto.deploy.unpack.war}" />
                        <jvmarg value="-Ddeployer.file.pattern=${plugin.name}-*.war" />

                        <!-- Optional Arguments -->

                        <jvmarg value="-Ddeployer.tomcat.lib.dir=${app.server.tomcat.lib.global.dir}" />

                        <!-- Dependent Libraries -->

                        <arg value="${app.server.lib.portal.dir}/util-java.jar" />
                        <arg value="${app.server.lib.portal.dir}/util-taglib.jar" />
                    </java>
                </then>
            </elseif>
        </if>
    </target>

    <target name="format-wsdl">
        <for param="wsdl.full.path">
            <path>
                <fileset
                    dir="."
                    includes="docroot/WEB-INF/wsdl/*.wsdl,docroot/WEB-INF/wsdl/**/*.wsdl"
                />
            </path>
            <sequential>
                <java
                    classname="com.liferay.portal.tools.XMLFormatter"
                    classpathref="portal.classpath"
                    fork="true"
                    newenvironment="true"
                >
                    <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                    <jvmarg value="-Dxml.formatter.file=@{wsdl.full.path}" />
                    <jvmarg value="-Dxml.formatter.strip.comments=true" />
                </java>
            </sequential>
        </for>
    </target>

    <target name="format-xsd">
        <for param="xsd.full.path">
            <path>
                <fileset
                    dir="."
                    includes="docroot/WEB-INF/xsd/*.xsd,docroot/WEB-INF/xsd/**/*.xsd"
                />
            </path>
            <sequential>
                <java
                    classname="com.liferay.portal.tools.XMLFormatter"
                    classpathref="portal.classpath"
                    fork="true"
                    newenvironment="true"
                >
                    <jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
                    <jvmarg value="-Dxml.formatter.file=@{xsd.full.path}" />
                    <jvmarg value="-Dxml.formatter.strip.comments=true" />
                </java>
            </sequential>
        </for>
    </target>

    <target name="merge" if="original.war.file">
        <if>
            <not>
                <uptodate srcfile="${original.war.file}" targetfile="tmp" />
            </not>
            <then>
                <delete dir="tmp" />
                <mkdir dir="tmp" />

                <mkdir dir="tmp/WEB-INF/classes" />
                <mkdir dir="tmp/WEB-INF/lib" />

                <antcall target="merge-unzip" />

                <copy todir="tmp" overwrite="true">
                    <fileset dir="docroot" />
                </copy>
            </then>
        </if>

        <copy todir="tmp">
            <fileset dir="docroot" />
        </copy>
    </target>

    <target name="merge-unzip">
        <unzip dest="tmp" src="${original.war.file}" />
    </target>

    <target name="shrink-zip-cmd">
        <tstamp>
            <format property="tstamp.value" pattern="yyyyMMddkkmmssSSS" />
        </tstamp>

        <unzip
            dest="${tstamp.value}"
            src="${zip.file.name}"
        >
            <patternset
                excludes="${zip.excludes}"
                includes="${zip.includes}"
            />
        </unzip>

        <zip
            basedir="${tstamp.value}"
            destfile="${zip.file.name}"
        />

        <delete dir="${tstamp.value}" />
    </target>

    <target name="test">
        <delete dir="test-classes" />
        <delete dir="test-results" />

        <antcall target="compile" />
        <antcall target="compile-test" />

        <if>
            <available file="tmp" />
            <then>
                <path id="plugin-lib.classpath">
                    <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                    <fileset dir="tmp/WEB-INF/lib" includes="*.jar" />
                    <pathelement location="docroot/WEB-INF/classes" />
                    <pathelement location="tmp/WEB-INF/classes" />
                </path>
            </then>
            <else>
                <path id="plugin-lib.classpath">
                    <fileset dir="docroot/WEB-INF/lib" includes="*.jar" />
                    <pathelement location="docroot/WEB-INF/classes" />
                </path>
            </else>
        </if>

        <antcall target="test-integration" inheritrefs="true" />
        <antcall target="test-unit" inheritrefs="true" />
    </target>

    <target name="test-class" depends="compile,compile-test">
        <if>
            <available file="test/integration" type="dir" />
            <then>
                <resourcecount property="test.integration.count">
                    <fileset dir="test-classes/integration" includes="**/${class}.class" />
                </resourcecount>
            </then>
        </if>

        <if>
            <available file="test/unit" type="dir" />
            <then>
                <resourcecount property="test.unit.count">
                    <fileset dir="test-classes/unit" includes="**/${class}.class" />
                </resourcecount>
            </then>
        </if>

        <if>
            <equals arg1="${test.integration.count}" arg2="1" />
            <then>
                <var name="test.type" value="integration" />
            </then>
            <elseif>
                <equals arg1="${test.unit.count}" arg2="1" />
                <then>
                    <var name="test.type" value="unit" />
                </then>
            </elseif>
            <else>
                <var name="test.type" value="" />
            </else>
        </if>

        <ant target="test-cmd">
            <property name="test.type" value="${test.type}" />
        </ant>
    </target>

    <target name="test-cmd">
        <if>
            <available file="test/${test.type}" type="dir" />
            <then>
                <junit dir="${project.dir}" fork="on" forkmode="once" outputtoformatters="false" printsummary="on" showoutput="true">
                    <sysproperty key="net.sourceforge.cobertura.datafile" file="test-coverage/cobertura.ser" />
                    <jvmarg line="${junit.debug.jpda}" />
                    <jvmarg value="-Xmx1024m" />
                    <jvmarg value="-XX:MaxPermSize=256m" />
                    <jvmarg value="-Dexternal-properties=${test.properties}" />
                    <jvmarg value="-Dfile.encoding=UTF-8" />
                    <jvmarg value="-Djava.net.preferIPv4Stack=true" />
                    <jvmarg value="-Duser.timezone=GMT" />
                    <classpath location="test-coverage" />
                    <classpath refid="test.classpath" />
                    <formatter type="brief" usefile="false" />
                    <formatter type="xml" />
                    <batchtest todir="test-results/${test.type}">
                        <fileset dir="test-classes/${test.type}" includes="**/${class}.class" />
                    </batchtest>
                </junit>
            </then>
        </if>
    </target>

    <target name="test-integration" depends="compile,compile-test-integration">
        <property name="class" value="*Test" />

        <ant target="test-cmd" inheritrefs="true">
            <property name="test.type" value="integration" />
        </ant>
    </target>

    <target name="test-unit" depends="compile,compile-test-unit">
        <property name="class" value="*Test" />

        <ant target="test-cmd" inheritrefs="true">
            <property name="test.type" value="unit" />
        </ant>
    </target>

    <target name="war" depends="compile">
        <mkdir dir="${project.dir}/dist" />

        <if>
            <available file="tmp" />
            <then>
                <property name="docroot.dir" value="tmp" />
            </then>
            <else>
                <property name="docroot.dir" value="docroot" />
            </else>
        </if>

        <delete file="${plugin.file}" />

        <antcall target="clean-portal-dependencies" />

        <if>
            <contains string="${app.server.dir}" substring="glassfish" />
            <then>
                <zip
                    basedir="${docroot.dir}"
                    destfile="${plugin.file}"
                    excludes="**/META-INF/context.xml,${plugins.war.excludes}"
                />
            </then>
            <else>
                <zip
                    basedir="${docroot.dir}"
                    destfile="${plugin.file}"
                    excludes="${plugins.war.excludes}"
                />
            </else>
        </if>

        <if>
            <and>
                <equals arg1="${plugins.src.zip.enabled}" arg2="true" />
            </and>
            <then>
                <zip destfile="${plugin.src.file}">
                    <zipfileset
                        dir="${docroot.dir}"
                        prefix="${plugin.name}-src-${lp.version}.${plugin.version}${lp.version.file.suffix}"
                    />
                </zip>
            </then>
        </if>
    </target>
</project>