Tuesday, July 03, 2012

Liferay Hooks

Liferay Hook Basic
 ----------------------------------------------------------------------------
To view it require latest version of firefox and adobe flash player.
----------------------------------------------------------------------------



----------------------------------------------------------------------------
Hooks are used to override/extends liferay core functionalities.
Hooks are hot-deployable.
Hooks are created within liferay-plug-in-sdk/hooks folder.
Hooks are preferred over Ext-plugins whenever possible.
-------------------------------------------------------------------------
Uses of Hook:
Performing custom actions on portal startup or user login
Overriding or extend portal JSPs
Modifying portal properties
Replacing portal services with your own implementation
----------------------------------------------------------------------------
Example :
Some custom hook available for download
By Liferay Community
By Liferay Official :
From Liferay Source :
----------------------------------------------------------------------------
Creating Hooks :
Hooks are created in plugin-sdk/hook folder.
Open plugin-sdk/hook folder from command prompt.(Recommended to use drop-to-dos utility.)
Write the command :

create .bat myfirsthook “My First Hook”
----------------------------------------------------------------------------
Command Prompt Console :

D:\liferay-plugins-sdk-6.1\hooks>create.bat myfirsthook "My First Hook"
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: D: \liferay-plugins-sdk-6.1\hooks\build.xml create:
[copy] Copying 3 files to D: \liferay-plugins-sdk-6.1\hooks\myfirsthook-hook
BUILD SUCCESSFUL
Total time: 1 second

--------------------------------------------------------------------

Now Plugin-sdk/hook folder has new myfirshthook-hook available.




Plugin-SDK append –hook to name of hook automatically.
----------------------------------------------------------------------------

Deploy myfirsthook-hook :
Open folder plugin-sdk/hooks/myfirsthook-hook using command prompt.
Enter command "ant deploy"

command Prompt Console :
----------------------------------------------------------------------------- 
D:\liferay-plugins-sdk-6.1\hooks\myfirsthook-hook>ant deploy

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: D:\Liferay Portal 6.1 CE Plugin SDK\liferay-plugins-sdk-6.1\hooks\myfirsthook-hook\build.xml compile: merge: [mkdir] Created dir: D:\liferay-plugins-sdk-6.1\hooks\myfirsthook-hook\docroot\WEB-INF\classes

[mkdir] Created dir: D: \liferay-plugins-sdk-6.1\hooks\myfirsthook-hook\docroot\WEB-INF\lib

merge: war:

clean-portal -dependencies:

[zip] Building zip: D: \liferay-plugins-sdk-6.1\dist\myfirsthook-hook-6.1.0.1.war deploy: [copy] Copying 1 file to D:\Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\deploy BUILD SUCCESSFUL

Total time: 1 second
----------------------------------------------------------------------------

Once Hook get deployed successfully tomcat-console show following messages :

ñ 07:42:25,575 INFO [AutoDeployDir:167] Processing myfirsthook-hook-6.1.0.1.war

ñ 07:42:25,598 INFO [HookAutoDeployListener:43] Copying hook plugin for

ñ D:\Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\deploy\myfirsthook-hook 6.1.0.1.war

ñ Expanding: D:\Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce ga1\deploy\myfirsthook-hook-6.1.0.1.war into D:\Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674

ñ Copying 1 file to D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674\WEB-INF

ñ Copying 1 file to D:\Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674\WEB-INF\classes Copying 1 file to D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674\WEB-INF\classes

ñ Copying 1 file to D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674\WEB-INF

ñ Copying 1 file to D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674\META-INF

ñ Warning: WEB-INF\liferay-plugin-package.properties modified in the future.

ñ Copying 10 files to D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps\myfirsthook-hook

ñ Copying 1 file to D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps\myfirsthook-hook

ñ Deleting directory D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\temp\20120703074225674 07:42:28,298 INFO [HookAutoDeployListener:49] Hook for D: \Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\deploy\myfirsthook-hook-6.1.0.1.war copied successfully.

ñ Deployment will start in a few seconds. Jul 3, 2012 7:42:35 AM org.apache.catalina.startup.HostConfig deployDirectory

ñ INFO: Deploying web application directory D:\Liferay Portal 6.1 CE tomcat Bundle\liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps\myfirsthook-hook 07:42:36,261 INFO [PluginPackageUtil:1099] Reading plugin package for myfirsthook-hook

ñ 07:42:36,337 INFO [HookHotDeployListener:1901] Registering hook for myfirsthook-hook 07:42:36,339 INFO [HookHotDeployListener:978] Hook for myfirsthook-hook is available for use
----------------------------------------------------------------------------

What is happing during deployment :
ant clean deploy

- Clean the source files
- Compiles updated files
- Create a war file of Hook
- Copy war file into plugin-sdk/dist folder for distribution purpose.
- Copy war file into tomcat/deploy folder of liferay.

HookHotDeployListener

- It detects war file for hook in tomcat/deploy folder.
- It extracts war file.
- It removes /update old hook .
- It deploys hook.

Deployed Hook is get available within liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps.
This hook is just empty hook not overriding/extending anything in liferay.
----------------------------------------------------------------------------  
How to undeploy hook.
There is no ant command is available to remove hook.
Remove it manually by just deleting it from liferay-portal-6.1.0-ce-ga1\tomcat-7.0.23\webapps.
Hook will get unregister.
Overriding /extending functionality will get removed.
----------------------------------------------------------------------------   
Summary :
What are Hooks in Liferay ?
Hooks creation
Hooks deployment
Hooks updeploymet

Next .. Hooks in Action ...

Hook to Override JSP

Hooks to Override Portal Properties File

Hooks to override language Properties Files

Hooks to override user Login and Landing Page-PerLogin and Postlogin

Hooks To override Struts Actions

Hooks to override dockbar Portlet

No comments:

Junit 5 Architecture

Modules in JUnit 5 : •         junit-jupiter-api: This module defines the API that you need to write your tests. •         ...